diff options
Diffstat (limited to 'drivers/net/wireless/iwlwifi')
27 files changed, 14934 insertions, 9024 deletions
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig index 8d52a26c248..d1af938b9aa 100644 --- a/drivers/net/wireless/iwlwifi/Kconfig +++ b/drivers/net/wireless/iwlwifi/Kconfig @@ -1,24 +1,64 @@ -config IWLWIFI - bool "Intel Wireless WiFi Link Drivers" +config IWL4965 + tristate "Intel Wireless WiFi 4965AGN" depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL select FW_LOADER - default n ---help--- - Select to enable drivers based on the iwlwifi project. This - project provides a common foundation for Intel's wireless - drivers designed to use the mac80211 subsystem. - - See <file:Documentation/networking/README.iwlwifi> for - information on the capabilities currently enabled in this - driver and for tips for debugging issues and problems. - -config IWLWIFI_DEBUG - bool "Enable full debugging output in iwlwifi drivers" - depends on IWLWIFI - default y + Select to build the driver supporting the: + + Intel Wireless WiFi Link 4965AGN + + This driver uses the kernel's mac80211 subsystem. + + In order to use this driver, you will need a microcode (uCode) + image for it. You can obtain the microcode from: + + <http://intellinuxwireless.org/>. + + The microcode is typically installed in /lib/firmware. You can + look in the hotplug script /etc/hotplug/firmware.agent to + determine which directory FIRMWARE_DIR is set to when the script + runs. + + If you want to compile the driver as a module ( = code which can be + inserted in and remvoed from the running kernel whenever you want), + say M here and read <file:Documentation/kbuild/modules.txt>. The + module will be called iwl4965.ko. + +config IWL4965_QOS + bool "Enable Wireless QoS in iwl4965 driver" + depends on IWL4965 ---help--- - This option will enable debug tracing output for the iwlwifi - drivers. + This option will enable wireless quality of service (QoS) for the + iwl4965 driver. + +config IWL4965_HT + bool "Enable 802.11n HT features in iwl4965 driver" + depends on EXPERIMENTAL + depends on IWL4965 && IWL4965_QOS + depends on n + ---help--- + This option enables IEEE 802.11n High Throughput features + for the iwl4965 driver. + +config IWL4965_SPECTRUM_MEASUREMENT + bool "Enable Spectrum Measurement in iwl4965 driver" + depends on IWL4965 + ---help--- + This option will enable spectrum measurement for the iwl4965 driver. + +config IWL4965_SENSITIVITY + bool "Enable Sensitivity Calibration in iwl4965 driver" + depends on IWL4965 + ---help--- + This option will enable sensitivity calibration for the iwl4965 + driver. + +config IWL4965_DEBUG + bool "Enable full debugging output in iwl4965 driver" + depends on IWL4965 + ---help--- + This option will enable debug tracing output for the iwl4965 + driver. This will result in the kernel module being ~100k larger. You can control which debug output is sent to the kernel log by setting the @@ -33,96 +73,74 @@ config IWLWIFI_DEBUG % echo 0x43fff > /sys/bus/pci/drivers/${DRIVER}/debug_level You can find the list of debug mask values in: - drivers/net/wireless/mac80211/iwlwifi/iwl-debug.h + drivers/net/wireless/iwlwifi/iwl-4965-debug.h If this is your first time using this driver, you should say Y here as the debug information can assist others in helping you resolve any problems you may encounter. -config IWLWIFI_SENSITIVITY - bool "Enable Sensitivity Calibration in iwlwifi drivers" - depends on IWLWIFI - default y - ---help--- - This option will enable sensitivity calibration for the iwlwifi - drivers. - -config IWLWIFI_SPECTRUM_MEASUREMENT - bool "Enable Spectrum Measurement in iwlwifi drivers" - depends on IWLWIFI - default y - ---help--- - This option will enable spectrum measurement for the iwlwifi drivers. - -config IWLWIFI_QOS - bool "Enable Wireless QoS in iwlwifi drivers" - depends on IWLWIFI - default y - ---help--- - This option will enable wireless quality of service (QoS) for the - iwlwifi drivers. - -config IWLWIFI_HT - bool "Enable 802.11n HT features in iwlwifi drivers" - depends on EXPERIMENTAL - depends on IWLWIFI && MAC80211_HT - default n - ---help--- - This option enables IEEE 802.11n High Throughput features - for the iwlwifi drivers. - -config IWL4965 - tristate "Intel Wireless WiFi 4965AGN" - depends on m && IWLWIFI && EXPERIMENTAL - default m +config IWL3945 + tristate "Intel PRO/Wireless 3945ABG/BG Network Connection" + depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL + select FW_LOADER ---help--- Select to build the driver supporting the: - Intel Wireless WiFi Link 4965AGN + Intel PRO/Wireless 3945ABG/BG Network Connection This driver uses the kernel's mac80211 subsystem. - See <file:Documentation/networking/README.iwlwifi> for - information on the capabilities currently enabled in this - driver and for tips for debugging any issues or problems. - In order to use this driver, you will need a microcode (uCode) image for it. You can obtain the microcode from: <http://intellinuxwireless.org/>. - See the above referenced README.iwlwifi for information on where - to install the microcode images. + The microcode is typically installed in /lib/firmware. You can + look in the hotplug script /etc/hotplug/firmware.agent to + determine which directory FIRMWARE_DIR is set to when the script + runs. If you want to compile the driver as a module ( = code which can be inserted in and remvoed from the running kernel whenever you want), say M here and read <file:Documentation/kbuild/modules.txt>. The - module will be called iwl4965.ko. + module will be called iwl3945.ko. -config IWL3945 - tristate "Intel PRO/Wireless 3945ABG/BG Network Connection" - depends on m && IWLWIFI && EXPERIMENTAL - default m +config IWL3945_QOS + bool "Enable Wireless QoS in iwl3945 driver" + depends on IWL3945 ---help--- - Select to build the driver supporting the: + This option will enable wireless quality of service (QoS) for the + iwl3945 driver. - Intel PRO/Wireless 3945ABG/BG Network Connection +config IWL3945_SPECTRUM_MEASUREMENT + bool "Enable Spectrum Measurement in iwl3945 drivers" + depends on IWL3945 + ---help--- + This option will enable spectrum measurement for the iwl3945 driver. - This driver uses the kernel's mac80211 subsystem. +config IWL3945_DEBUG + bool "Enable full debugging output in iwl3945 driver" + depends on IWL3945 + ---help--- + This option will enable debug tracing output for the iwl3945 + driver. + + This will result in the kernel module being ~100k larger. You can + control which debug output is sent to the kernel log by setting the + value in - See <file:Documentation/networking/README.iwlwifi> for - information on the capabilities currently enabled in this - driver and for tips for debugging any issues or problems. + /sys/bus/pci/drivers/${DRIVER}/debug_level - In order to use this driver, you will need a microcode (uCode) - image for it. You can obtain the microcode from: + This entry will only exist if this option is enabled. - <http://intellinuxwireless.org/>. + To set a value, simply echo an 8-byte hex value to the same file: + + % echo 0x43fff > /sys/bus/pci/drivers/${DRIVER}/debug_level - See the above referenced README.iwlwifi for information on where - to install the microcode images. + You can find the list of debug mask values in: + drivers/net/wireless/iwlwifi/iwl-3945-debug.h + + If this is your first time using this driver, you should say Y here + as the debug information can assist others in helping you resolve + any problems you may encounter. - If you want to compile the driver as a module ( = code which can be - inserted in and remvoed from the running kernel whenever you want), - say M here and read <file:Documentation/kbuild/modules.txt>. The - module will be called iwl3945.ko. diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-3945-commands.h index 9de8d7f6efa..46bb2c7d11d 100644 --- a/drivers/net/wireless/iwlwifi/iwl-commands.h +++ b/drivers/net/wireless/iwlwifi/iwl-3945-commands.h @@ -8,7 +8,7 @@ * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU Geeral Public License as + * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but @@ -60,9 +60,14 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *****************************************************************************/ +/* + * Please use this file (iwl-3945-commands.h) only for uCode API definitions. + * Please use iwl-3945-hw.h for hardware-related definitions. + * Please use iwl-3945.h for driver implementation definitions. + */ -#ifndef __iwl_commands_h__ -#define __iwl_commands_h__ +#ifndef __iwl_3945_commands_h__ +#define __iwl_3945_commands_h__ enum { REPLY_ALIVE = 0x1, @@ -80,9 +85,7 @@ enum { REPLY_REMOVE_ALL_STA = 0x1a, /* not used */ /* RX, TX, LEDs */ -#if IWL == 3945 REPLY_3945_RX = 0x1b, /* 3945 only */ -#endif REPLY_TX = 0x1c, REPLY_RATE_SCALE = 0x47, /* 3945 only */ REPLY_LEDS_CMD = 0x48, @@ -118,10 +121,10 @@ enum { REPLY_TX_PWR_TABLE_CMD = 0x97, MEASURE_ABORT_NOTIFICATION = 0x99, /* not used */ - /* BT config command */ + /* Bluetooth device coexistance config command */ REPLY_BT_CONFIG = 0x9b, - /* 4965 Statistics */ + /* Statistics */ REPLY_STATISTICS_CMD = 0x9c, STATISTICS_NOTIFICATION = 0x9d, @@ -132,46 +135,85 @@ enum { /* Missed beacons notification */ MISSED_BEACONS_NOTIFICATION = 0xa2, -#if IWL == 4965 - REPLY_CT_KILL_CONFIG_CMD = 0xa4, - SENSITIVITY_CMD = 0xa8, - REPLY_PHY_CALIBRATION_CMD = 0xb0, - REPLY_RX_PHY_CMD = 0xc0, - REPLY_RX_MPDU_CMD = 0xc1, - REPLY_4965_RX = 0xc3, - REPLY_COMPRESSED_BA = 0xc5, -#endif REPLY_MAX = 0xff }; /****************************************************************************** * (0) - * Header + * Commonly used structures and definitions: + * Command header, txpower * *****************************************************************************/ +/* iwl3945_cmd_header flags value */ #define IWL_CMD_FAILED_MSK 0x40 -struct iwl_cmd_header { - u8 cmd; - u8 flags; - /* We have 15 LSB to use as we please (MSB indicates - * a frame Rx'd from the HW). We encode the following - * information into the sequence field: +/** + * struct iwl3945_cmd_header + * + * This header format appears in the beginning of each command sent from the + * driver, and each response/notification received from uCode. + */ +struct iwl3945_cmd_header { + u8 cmd; /* Command ID: REPLY_RXON, etc. */ + u8 flags; /* IWL_CMD_* */ + /* + * The driver sets up the sequence number to values of its chosing. + * uCode does not use this value, but passes it back to the driver + * when sending the response to each driver-originated command, so + * the driver can match the response to the command. Since the values + * don't get used by uCode, the driver may set up an arbitrary format. * - * 0:7 index in fifo - * 8:13 fifo selection - * 14:14 bit indicating if this packet references the 'extra' - * storage at the end of the memory queue - * 15:15 (Rx indication) + * There is one exception: uCode sets bit 15 when it originates + * the response/notification, i.e. when the response/notification + * is not a direct response to a command sent by the driver. For + * example, uCode issues REPLY_3945_RX when it sends a received frame + * to the driver; it is not a direct response to any driver command. * + * The Linux driver uses the following format: + * + * 0:7 index/position within Tx queue + * 8:13 Tx queue selection + * 14:14 driver sets this to indicate command is in the 'huge' + * storage at the end of the command buffers, i.e. scan cmd + * 15:15 uCode sets this in uCode-originated response/notification */ __le16 sequence; - /* command data follows immediately */ + /* command or response/notification data follows immediately */ u8 data[0]; } __attribute__ ((packed)); +/** + * struct iwl3945_tx_power + * + * Used in REPLY_TX_PWR_TABLE_CMD, REPLY_SCAN_CMD, REPLY_CHANNEL_SWITCH + * + * Each entry contains two values: + * 1) DSP gain (or sometimes called DSP attenuation). This is a fine-grained + * linear value that multiplies the output of the digital signal processor, + * before being sent to the analog radio. + * 2) Radio gain. This sets the analog gain of the radio Tx path. + * It is a coarser setting, and behaves in a logarithmic (dB) fashion. + * + * Driver obtains values from struct iwl3945_tx_power power_gain_table[][]. + */ +struct iwl3945_tx_power { + u8 tx_gain; /* gain for analog radio */ + u8 dsp_atten; /* gain for DSP */ +} __attribute__ ((packed)); + +/** + * struct iwl3945_power_per_rate + * + * Used in REPLY_TX_PWR_TABLE_CMD, REPLY_CHANNEL_SWITCH + */ +struct iwl3945_power_per_rate { + u8 rate; /* plcp */ + struct iwl3945_tx_power tpc; + u8 reserved; +} __attribute__ ((packed)); + /****************************************************************************** * (0a) * Alive and Error Commands & Responses: @@ -182,15 +224,22 @@ struct iwl_cmd_header { #define INITIALIZE_SUBTYPE (9) /* - * REPLY_ALIVE = 0x1 (response only, not a command) + * ("Initialize") REPLY_ALIVE = 0x1 (response only, not a command) + * + * uCode issues this "initialize alive" notification once the initialization + * uCode image has completed its work, and is ready to load the runtime image. + * This is the *first* "alive" notification that the driver will receive after + * rebooting uCode; the "initialize" alive is indicated by subtype field == 9. + * + * See comments documenting "BSM" (bootstrap state machine). */ -struct iwl_alive_resp { +struct iwl3945_init_alive_resp { u8 ucode_minor; u8 ucode_major; __le16 reserved1; u8 sw_rev[8]; u8 ver_type; - u8 ver_subtype; + u8 ver_subtype; /* "9" for initialize alive */ __le16 reserved2; __le32 log_event_table_ptr; __le32 error_event_table_ptr; @@ -198,29 +247,41 @@ struct iwl_alive_resp { __le32 is_valid; } __attribute__ ((packed)); -struct iwl_init_alive_resp { + +/** + * REPLY_ALIVE = 0x1 (response only, not a command) + * + * uCode issues this "alive" notification once the runtime image is ready + * to receive commands from the driver. This is the *second* "alive" + * notification that the driver will receive after rebooting uCode; + * this "alive" is indicated by subtype field != 9. + * + * See comments documenting "BSM" (bootstrap state machine). + * + * This response includes two pointers to structures within the device's + * data SRAM (access via HBUS_TARG_MEM_* regs) that are useful for debugging: + * + * 1) log_event_table_ptr indicates base of the event log. This traces + * a 256-entry history of uCode execution within a circular buffer. + * + * 2) error_event_table_ptr indicates base of the error log. This contains + * information about any uCode error that occurs. + * + * The Linux driver can print both logs to the system log when a uCode error + * occurs. + */ +struct iwl3945_alive_resp { u8 ucode_minor; u8 ucode_major; __le16 reserved1; u8 sw_rev[8]; u8 ver_type; - u8 ver_subtype; + u8 ver_subtype; /* not "9" for runtime alive */ __le16 reserved2; - __le32 log_event_table_ptr; - __le32 error_event_table_ptr; + __le32 log_event_table_ptr; /* SRAM address for event log */ + __le32 error_event_table_ptr; /* SRAM address for error log */ __le32 timestamp; __le32 is_valid; - -#if IWL == 4965 - /* calibration values from "initialize" uCode */ - __le32 voltage; /* signed */ - __le32 therm_r1[2]; /* signed 1st for normal, 2nd for FAT channel */ - __le32 therm_r2[2]; /* signed */ - __le32 therm_r3[2]; /* signed */ - __le32 therm_r4[2]; /* signed */ - __le32 tx_atten[5][2]; /* signed MIMO gain comp, 5 freq groups, - * 2 Tx chains */ -#endif } __attribute__ ((packed)); union tsf { @@ -232,14 +293,12 @@ union tsf { /* * REPLY_ERROR = 0x2 (response only, not a command) */ -struct iwl_error_resp { +struct iwl3945_error_resp { __le32 error_type; u8 cmd_id; u8 reserved1; __le16 bad_cmd_seq_num; -#if IWL == 3945 __le16 reserved2; -#endif __le32 error_info; union tsf timestamp; } __attribute__ ((packed)); @@ -300,10 +359,24 @@ enum { /* transfer to host non bssid beacons in associated state */ #define RXON_FILTER_BCON_AWARE_MSK __constant_cpu_to_le32(1 << 6) -/* +/** * REPLY_RXON = 0x10 (command, has simple generic response) + * + * RXON tunes the radio tuner to a service channel, and sets up a number + * of parameters that are used primarily for Rx, but also for Tx operations. + * + * NOTE: When tuning to a new channel, driver must set the + * RXON_FILTER_ASSOC_MSK to 0. This will clear station-dependent + * info within the device, including the station tables, tx retry + * rate tables, and txpower tables. Driver must build a new station + * table and txpower table before transmitting anything on the RXON + * channel. + * + * NOTE: All RXONs wipe clean the internal txpower table. Driver must + * issue a new REPLY_TX_PWR_TABLE_CMD after each REPLY_RXON (0x10), + * regardless of whether RXON_FILTER_ASSOC_MSK is set. */ -struct iwl_rxon_cmd { +struct iwl3945_rxon_cmd { u8 node_addr[6]; __le16 reserved1; u8 bssid_addr[6]; @@ -312,45 +385,31 @@ struct iwl_rxon_cmd { __le16 reserved3; u8 dev_type; u8 air_propagation; -#if IWL == 3945 __le16 reserved4; -#elif IWL == 4965 - __le16 rx_chain; -#endif u8 ofdm_basic_rates; u8 cck_basic_rates; __le16 assoc_id; __le32 flags; __le32 filter_flags; __le16 channel; -#if IWL == 3945 __le16 reserved5; -#elif IWL == 4965 - u8 ofdm_ht_single_stream_basic_rates; - u8 ofdm_ht_dual_stream_basic_rates; -#endif } __attribute__ ((packed)); /* * REPLY_RXON_ASSOC = 0x11 (command, has simple generic response) */ -struct iwl_rxon_assoc_cmd { +struct iwl3945_rxon_assoc_cmd { __le32 flags; __le32 filter_flags; u8 ofdm_basic_rates; u8 cck_basic_rates; -#if IWL == 4965 - u8 ofdm_ht_single_stream_basic_rates; - u8 ofdm_ht_dual_stream_basic_rates; - __le16 rx_chain_select_flags; -#endif __le16 reserved; } __attribute__ ((packed)); /* * REPLY_RXON_TIMING = 0x14 (command, has simple generic response) */ -struct iwl_rxon_time_cmd { +struct iwl3945_rxon_time_cmd { union tsf timestamp; __le16 beacon_interval; __le16 atim_window; @@ -359,52 +418,23 @@ struct iwl_rxon_time_cmd { __le16 reserved; } __attribute__ ((packed)); -struct iwl_tx_power { - u8 tx_gain; /* gain for analog radio */ - u8 dsp_atten; /* gain for DSP */ -} __attribute__ ((packed)); - -#if IWL == 3945 -struct iwl_power_per_rate { - u8 rate; /* plcp */ - struct iwl_tx_power tpc; - u8 reserved; -} __attribute__ ((packed)); - -#elif IWL == 4965 -#define POWER_TABLE_NUM_ENTRIES 33 -#define POWER_TABLE_NUM_HT_OFDM_ENTRIES 32 -#define POWER_TABLE_CCK_ENTRY 32 -struct tx_power_dual_stream { - __le32 dw; -} __attribute__ ((packed)); - -struct iwl_tx_power_db { - struct tx_power_dual_stream power_tbl[POWER_TABLE_NUM_ENTRIES]; -} __attribute__ ((packed)); -#endif - /* * REPLY_CHANNEL_SWITCH = 0x72 (command, has simple generic response) */ -struct iwl_channel_switch_cmd { +struct iwl3945_channel_switch_cmd { u8 band; u8 expect_beacon; __le16 channel; __le32 rxon_flags; __le32 rxon_filter_flags; __le32 switch_time; -#if IWL == 3945 - struct iwl_power_per_rate power[IWL_MAX_RATES]; -#elif IWL == 4965 - struct iwl_tx_power_db tx_power; -#endif + struct iwl3945_power_per_rate power[IWL_MAX_RATES]; } __attribute__ ((packed)); /* * CHANNEL_SWITCH_NOTIFICATION = 0x73 (notification only, not a command) */ -struct iwl_csa_notification { +struct iwl3945_csa_notification { __le16 band; __le16 channel; __le32 status; /* 0 - OK, 1 - fail */ @@ -415,7 +445,24 @@ struct iwl_csa_notification { * Quality-of-Service (QOS) Commands & Responses: * *****************************************************************************/ -struct iwl_ac_qos { + +/** + * struct iwl_ac_qos -- QOS timing params for REPLY_QOS_PARAM + * One for each of 4 EDCA access categories in struct iwl_qosparam_cmd + * + * @cw_min: Contention window, start value in numbers of slots. + * Should be a power-of-2, minus 1. Device's default is 0x0f. + * @cw_max: Contention window, max value in numbers of slots. + * Should be a power-of-2, minus 1. Device's default is 0x3f. + * @aifsn: Number of slots in Arbitration Interframe Space (before + * performing random backoff timing prior to Tx). Device default 1. + * @edca_txop: Length of Tx opportunity, in uSecs. Device default is 0. + * + * Device will automatically increase contention window by (2*CW) + 1 for each + * transmission retry. Device uses cw_max as a bit mask, ANDed with new CW + * value, to cap the CW value. + */ +struct iwl3945_ac_qos { __le16 cw_min; __le16 cw_max; u8 aifsn; @@ -428,18 +475,18 @@ struct iwl_ac_qos { #define QOS_PARAM_FLG_TGN_MSK __constant_cpu_to_le32(0x02) #define QOS_PARAM_FLG_TXOP_TYPE_MSK __constant_cpu_to_le32(0x10) -/* - * TXFIFO Queue number defines - */ -/* number of Access categories (AC) (EDCA), queues 0..3 */ +/* Number of Access Categories (AC) (EDCA), queues 0..3 */ #define AC_NUM 4 /* * REPLY_QOS_PARAM = 0x13 (command, has simple generic response) + * + * This command sets up timings for each of the 4 prioritized EDCA Tx FIFOs + * 0: Background, 1: Best Effort, 2: Video, 3: Voice. */ -struct iwl_qosparam_cmd { +struct iwl3945_qosparam_cmd { __le32 qos_flags; - struct iwl_ac_qos ac[AC_NUM]; + struct iwl3945_ac_qos ac[AC_NUM]; } __attribute__ ((packed)); /****************************************************************************** @@ -450,24 +497,21 @@ struct iwl_qosparam_cmd { /* * Multi station support */ + +/* Special, dedicated locations within device's station table */ #define IWL_AP_ID 0 #define IWL_MULTICAST_ID 1 #define IWL_STA_ID 2 - #define IWL3945_BROADCAST_ID 24 #define IWL3945_STATION_COUNT 25 -#define IWL4965_BROADCAST_ID 31 -#define IWL4965_STATION_COUNT 32 - #define IWL_STATION_COUNT 32 /* MAX(3945,4965)*/ #define IWL_INVALID_STATION 255 -#if IWL == 3945 -#define STA_FLG_TX_RATE_MSK __constant_cpu_to_le32(1<<2); -#endif -#define STA_FLG_PWR_SAVE_MSK __constant_cpu_to_le32(1<<8); +#define STA_FLG_TX_RATE_MSK __constant_cpu_to_le32(1 << 2); +#define STA_FLG_PWR_SAVE_MSK __constant_cpu_to_le32(1 << 8); +/* Use in mode field. 1: modify existing entry, 0: add new station entry */ #define STA_CONTROL_MODIFY_MSK 0x01 /* key flags __le16*/ @@ -480,13 +524,10 @@ struct iwl_qosparam_cmd { #define STA_KEY_FLG_KEYID_POS 8 #define STA_KEY_FLG_INVALID __constant_cpu_to_le16(0x0800) -/* modify flags */ +/* Flags indicate whether to modify vs. don't change various station params */ #define STA_MODIFY_KEY_MASK 0x01 #define STA_MODIFY_TID_DISABLE_TX 0x02 #define STA_MODIFY_TX_RATE_MSK 0x04 -#define STA_MODIFY_ADDBA_TID_MSK 0x08 -#define STA_MODIFY_DELBA_TID_MSK 0x10 -#define BUILD_RAxTID(sta_id, tid) (((sta_id) << 4) + (tid)) /* * Antenna masks: @@ -500,7 +541,7 @@ struct iwl_qosparam_cmd { #define RATE_MCS_ANT_B_MSK 0x8000 #define RATE_MCS_ANT_AB_MSK 0xc000 -struct iwl_keyinfo { +struct iwl3945_keyinfo { __le16 key_flags; u8 tkip_rx_tsc_byte2; /* TSC[2] for key mix ph1 detection */ u8 reserved1; @@ -509,6 +550,18 @@ struct iwl_keyinfo { u8 key[16]; /* 16-byte unicast decryption key */ } __attribute__ ((packed)); +/** + * struct sta_id_modify + * @addr[ETH_ALEN]: station's MAC address + * @sta_id: index of station in uCode's station table + * @modify_mask: STA_MODIFY_*, 1: modify, 0: don't change + * + * Driver selects unused table index when adding new station, + * or the index to a pre-existing station entry when modifying that station. + * Some indexes have special purposes (IWL_AP_ID, index 0, is for AP). + * + * modify_mask flags select which parameters to modify vs. leave alone. + */ struct sta_id_modify { u8 addr[ETH_ALEN]; __le16 reserved1; @@ -519,36 +572,67 @@ struct sta_id_modify { /* * REPLY_ADD_STA = 0x18 (command) + * + * The device contains an internal table of per-station information, + * with info on security keys, aggregation parameters, and Tx rates for + * initial Tx attempt and any retries (4965 uses REPLY_TX_LINK_QUALITY_CMD, + * 3945 uses REPLY_RATE_SCALE to set up rate tables). + * + * REPLY_ADD_STA sets up the table entry for one station, either creating + * a new entry, or modifying a pre-existing one. + * + * NOTE: RXON command (without "associated" bit set) wipes the station table + * clean. Moving into RF_KILL state does this also. Driver must set up + * new station table before transmitting anything on the RXON channel + * (except active scans or active measurements; those commands carry + * their own txpower/rate setup data). + * + * When getting started on a new channel, driver must set up the + * IWL_BROADCAST_ID entry (last entry in the table). For a client + * station in a BSS, once an AP is selected, driver sets up the AP STA + * in the IWL_AP_ID entry (1st entry in the table). BROADCAST and AP + * are all that are needed for a BSS client station. If the device is + * used as AP, or in an IBSS network, driver must set up station table + * entries for all STAs in network, starting with index IWL_STA_ID. */ -struct iwl_addsta_cmd { - u8 mode; +struct iwl3945_addsta_cmd { + u8 mode; /* 1: modify existing, 0: add new station */ u8 reserved[3]; struct sta_id_modify sta; - struct iwl_keyinfo key; - __le32 station_flags; - __le32 station_flags_msk; + struct iwl3945_keyinfo key; + __le32 station_flags; /* STA_FLG_* */ + __le32 station_flags_msk; /* STA_FLG_* */ + + /* bit field to disable (1) or enable (0) Tx for Traffic ID (TID) + * corresponding to bit (e.g. bit 5 controls TID 5). + * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */ __le16 tid_disable_tx; -#if IWL == 3945 + __le16 rate_n_flags; -#else - __le16 reserved1; -#endif + + /* TID for which to add block-ack support. + * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */ u8 add_immediate_ba_tid; + + /* TID for which to remove block-ack support. + * Set modify_mask bit STA_MODIFY_DELBA_TID_MSK to use this field. */ u8 remove_immediate_ba_tid; + + /* Starting Sequence Number for added block-ack support. + * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */ __le16 add_immediate_ba_ssn; -#if IWL == 4965 - __le32 reserved2; -#endif } __attribute__ ((packed)); +#define ADD_STA_SUCCESS_MSK 0x1 +#define ADD_STA_NO_ROOM_IN_TABLE 0x2 +#define ADD_STA_NO_BLOCK_ACK_RESOURCE 0x4 /* * REPLY_ADD_STA = 0x18 (response) */ -struct iwl_add_sta_resp { - u8 status; +struct iwl3945_add_sta_resp { + u8 status; /* ADD_STA_* */ } __attribute__ ((packed)); -#define ADD_STA_SUCCESS_MSK 0x1 /****************************************************************************** * (4) @@ -556,7 +640,7 @@ struct iwl_add_sta_resp { * *****************************************************************************/ -struct iwl_rx_frame_stats { +struct iwl3945_rx_frame_stats { u8 phy_count; u8 id; u8 rssi; @@ -566,7 +650,7 @@ struct iwl_rx_frame_stats { u8 payload[0]; } __attribute__ ((packed)); -struct iwl_rx_frame_hdr { +struct iwl3945_rx_frame_hdr { __le16 channel; __le16 phy_flags; u8 reserved1; @@ -596,7 +680,7 @@ struct iwl_rx_frame_hdr { #define RX_RES_STATUS_BAD_ICV_MIC (0x1 << 11) #define RX_RES_STATUS_BAD_KEY_TTAK (0x2 << 11) -struct iwl_rx_frame_end { +struct iwl3945_rx_frame_end { __le32 status; __le64 timestamp; __le32 beacon_timestamp; @@ -610,10 +694,10 @@ struct iwl_rx_frame_end { * The actual offsets of the hdr and end are dynamic based on * stats.phy_count */ -struct iwl_rx_frame { - struct iwl_rx_frame_stats stats; - struct iwl_rx_frame_hdr hdr; - struct iwl_rx_frame_end end; +struct iwl3945_rx_frame { + struct iwl3945_rx_frame_stats stats; + struct iwl3945_rx_frame_hdr hdr; + struct iwl3945_rx_frame_end end; } __attribute__ ((packed)); /* Fixed (non-configurable) rx data from phy */ @@ -659,36 +743,86 @@ struct iwl4965_rx_mpdu_res_start { * (5) * Tx Commands & Responses: * + * Driver must place each REPLY_TX command into one of the prioritized Tx + * queues in host DRAM, shared between driver and device. When the device's + * Tx scheduler and uCode are preparing to transmit, the device pulls the + * Tx command over the PCI bus via one of the device's Tx DMA channels, + * to fill an internal FIFO from which data will be transmitted. + * + * uCode handles all timing and protocol related to control frames + * (RTS/CTS/ACK), based on flags in the Tx command. + * + * uCode handles retrying Tx when an ACK is expected but not received. + * This includes trying lower data rates than the one requested in the Tx + * command, as set up by the REPLY_RATE_SCALE (for 3945) or + * REPLY_TX_LINK_QUALITY_CMD (4965). + * + * Driver sets up transmit power for various rates via REPLY_TX_PWR_TABLE_CMD. + * This command must be executed after every RXON command, before Tx can occur. *****************************************************************************/ -/* Tx flags */ +/* REPLY_TX Tx flags field */ + +/* 1: Use Request-To-Send protocol before this frame. + * Mutually exclusive vs. TX_CMD_FLG_CTS_MSK. */ #define TX_CMD_FLG_RTS_MSK __constant_cpu_to_le32(1 << 1) + +/* 1: Transmit Clear-To-Send to self before this frame. + * Driver should set this for AUTH/DEAUTH/ASSOC-REQ/REASSOC mgmnt frames. + * Mutually exclusive vs. TX_CMD_FLG_RTS_MSK. */ #define TX_CMD_FLG_CTS_MSK __constant_cpu_to_le32(1 << 2) + +/* 1: Expect ACK from receiving station + * 0: Don't expect ACK (MAC header's duration field s/b 0) + * Set this for unicast frames, but not broadcast/multicast. */ #define TX_CMD_FLG_ACK_MSK __constant_cpu_to_le32(1 << 3) + +/* 1: Use rate scale table (see REPLY_TX_LINK_QUALITY_CMD). + * Tx command's initial_rate_index indicates first rate to try; + * uCode walks through table for additional Tx attempts. + * 0: Use Tx rate/MCS from Tx command's rate_n_flags field. + * This rate will be used for all Tx attempts; it will not be scaled. */ #define TX_CMD_FLG_STA_RATE_MSK __constant_cpu_to_le32(1 << 4) + +/* 1: Expect immediate block-ack. + * Set when Txing a block-ack request frame. Also set TX_CMD_FLG_ACK_MSK. */ #define TX_CMD_FLG_IMM_BA_RSP_MASK __constant_cpu_to_le32(1 << 6) + +/* 1: Frame requires full Tx-Op protection. + * Set this if either RTS or CTS Tx Flag gets set. */ #define TX_CMD_FLG_FULL_TXOP_PROT_MSK __constant_cpu_to_le32(1 << 7) + +/* Tx antenna selection field; used only for 3945, reserved (0) for 4965. + * Set field to "0" to allow 3945 uCode to select antenna (normal usage). */ #define TX_CMD_FLG_ANT_SEL_MSK __constant_cpu_to_le32(0xf00) #define TX_CMD_FLG_ANT_A_MSK __constant_cpu_to_le32(1 << 8) #define TX_CMD_FLG_ANT_B_MSK __constant_cpu_to_le32(1 << 9) -/* ucode ignores BT priority for this frame */ +/* 1: Ignore Bluetooth priority for this frame. + * 0: Delay Tx until Bluetooth device is done (normal usage). */ #define TX_CMD_FLG_BT_DIS_MSK __constant_cpu_to_le32(1 << 12) -/* ucode overrides sequence control */ +/* 1: uCode overrides sequence control field in MAC header. + * 0: Driver provides sequence control field in MAC header. + * Set this for management frames, non-QOS data frames, non-unicast frames, + * and also in Tx command embedded in REPLY_SCAN_CMD for active scans. */ #define TX_CMD_FLG_SEQ_CTL_MSK __constant_cpu_to_le32(1 << 13) -/* signal that this frame is non-last MPDU */ +/* 1: This frame is non-last MPDU; more fragments are coming. + * 0: Last fragment, or not using fragmentation. */ #define TX_CMD_FLG_MORE_FRAG_MSK __constant_cpu_to_le32(1 << 14) -/* calculate TSF in outgoing frame */ +/* 1: uCode calculates and inserts Timestamp Function (TSF) in outgoing frame. + * 0: No TSF required in outgoing frame. + * Set this for transmitting beacons and probe responses. */ #define TX_CMD_FLG_TSF_MSK __constant_cpu_to_le32(1 << 16) -/* activate TX calibration. */ -#define TX_CMD_FLG_CALIB_MSK __constant_cpu_to_le32(1 << 17) - -/* signals that 2 bytes pad was inserted - after the MAC header */ +/* 1: Driver inserted 2 bytes pad after the MAC header, for (required) dword + * alignment of frame's payload data field. + * 0: No pad + * Set this for MAC headers with 26 or 30 bytes, i.e. those with QOS or ADDR4 + * field (but not both). Driver must align frame data (i.e. data following + * MAC header) to DWORD boundary. */ #define TX_CMD_FLG_MH_PAD_MSK __constant_cpu_to_le32(1 << 20) /* HCCA-AP - disable duration overwriting. */ @@ -705,68 +839,65 @@ struct iwl4965_rx_mpdu_res_start { #define TX_CMD_SEC_KEY128 0x08 /* - * TX command Frame life time - */ - -struct iwl_dram_scratch { - u8 try_cnt; - u8 bt_kill_cnt; - __le16 reserved; -} __attribute__ ((packed)); - -/* * REPLY_TX = 0x1c (command) */ -struct iwl_tx_cmd { +struct iwl3945_tx_cmd { + /* + * MPDU byte count: + * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size, + * + 8 byte IV for CCM or TKIP (not used for WEP) + * + Data payload + * + 8-byte MIC (not used for CCM/WEP) + * NOTE: Does not include Tx command bytes, post-MAC pad bytes, + * MIC (CCM) 8 bytes, ICV (WEP/TKIP/CKIP) 4 bytes, CRC 4 bytes.i + * Range: 14-2342 bytes. + */ __le16 len; + + /* + * MPDU or MSDU byte count for next frame. + * Used for fragmentation and bursting, but not 11n aggregation. + * Same as "len", but for next frame. Set to 0 if not applicable. + */ __le16 next_frame_len; - __le32 tx_flags; -#if IWL == 3945 + + __le32 tx_flags; /* TX_CMD_FLG_* */ + u8 rate; + + /* Index of recipient station in uCode's station table */ u8 sta_id; u8 tid_tspec; -#elif IWL == 4965 - struct iwl_dram_scratch scratch; - __le32 rate_n_flags; - u8 sta_id; -#endif u8 sec_ctl; -#if IWL == 4965 - u8 initial_rate_index; - u8 reserved; -#endif u8 key[16]; -#if IWL == 3945 union { u8 byte[8]; __le16 word[4]; __le32 dw[2]; } tkip_mic; __le32 next_frame_info; -#elif IWL == 4965 - __le16 next_frame_flags; - __le16 reserved2; -#endif union { __le32 life_time; __le32 attempt; } stop_time; -#if IWL == 3945 u8 supp_rates[2]; -#elif IWL == 4965 - __le32 dram_lsb_ptr; - u8 dram_msb_ptr; -#endif u8 rts_retry_limit; /*byte 50 */ u8 data_retry_limit; /*byte 51 */ -#if IWL == 4965 - u8 tid_tspec; -#endif union { __le16 pm_frame_timeout; __le16 attempt_duration; } timeout; + + /* + * Duration of EDCA burst Tx Opportunity, in 32-usec units. + * Set this if txop time is not specified by HCCA protocol (e.g. by AP). + */ __le16 driver_txop; + + /* + * MAC header goes here, followed by 2 bytes padding if MAC header + * length is 26 or 30 bytes, followed by payload data + */ u8 payload[0]; struct ieee80211_hdr hdr[0]; } __attribute__ ((packed)); @@ -838,104 +969,36 @@ enum { TX_ABORT_REQUIRED_MSK = 0x80000000, /* bits 31:31 */ }; -/* ******************************* - * TX aggregation state - ******************************* */ - -enum { - AGG_TX_STATE_TRANSMITTED = 0x00, - AGG_TX_STATE_UNDERRUN_MSK = 0x01, - AGG_TX_STATE_BT_PRIO_MSK = 0x02, - AGG_TX_STATE_FEW_BYTES_MSK = 0x04, - AGG_TX_STATE_ABORT_MSK = 0x08, - AGG_TX_STATE_LAST_SENT_TTL_MSK = 0x10, - AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK = 0x20, - AGG_TX_STATE_LAST_SENT_BT_KILL_MSK = 0x40, - AGG_TX_STATE_SCD_QUERY_MSK = 0x80, - AGG_TX_STATE_TEST_BAD_CRC32_MSK = 0x100, - AGG_TX_STATE_RESPONSE_MSK = 0x1ff, - AGG_TX_STATE_DUMP_TX_MSK = 0x200, - AGG_TX_STATE_DELAY_TX_MSK = 0x400 -}; - -#define AGG_TX_STATE_LAST_SENT_MSK \ -(AGG_TX_STATE_LAST_SENT_TTL_MSK | \ - AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK | \ - AGG_TX_STATE_LAST_SENT_BT_KILL_MSK) - -#define AGG_TX_STATE_TRY_CNT_POS 12 -#define AGG_TX_STATE_TRY_CNT_MSK 0xf000 - -#define AGG_TX_STATE_SEQ_NUM_POS 16 -#define AGG_TX_STATE_SEQ_NUM_MSK 0xffff0000 - /* * REPLY_TX = 0x1c (response) */ -#if IWL == 4965 -struct iwl_tx_resp { - u8 frame_count; /* 1 no aggregation, >1 aggregation */ - u8 bt_kill_count; - u8 failure_rts; - u8 failure_frame; - __le32 rate_n_flags; - __le16 wireless_media_time; - __le16 reserved; - __le32 pa_power1; - __le32 pa_power2; - __le32 status; /* TX status (for aggregation status of 1st frame) */ -} __attribute__ ((packed)); - -#elif IWL == 3945 -struct iwl_tx_resp { +struct iwl3945_tx_resp { u8 failure_rts; u8 failure_frame; u8 bt_kill_count; u8 rate; __le32 wireless_media_time; - __le32 status; /* TX status (for aggregation status of 1st frame) */ -} __attribute__ ((packed)); -#endif - -/* - * REPLY_COMPRESSED_BA = 0xc5 (response only, not a command) - */ -struct iwl_compressed_ba_resp { - __le32 sta_addr_lo32; - __le16 sta_addr_hi16; - __le16 reserved; - u8 sta_id; - u8 tid; - __le16 ba_seq_ctl; - __le32 ba_bitmap0; - __le32 ba_bitmap1; - __le16 scd_flow; - __le16 scd_ssn; + __le32 status; /* TX status */ } __attribute__ ((packed)); /* * REPLY_TX_PWR_TABLE_CMD = 0x97 (command, has simple generic response) */ -struct iwl_txpowertable_cmd { +struct iwl3945_txpowertable_cmd { u8 band; /* 0: 5 GHz, 1: 2.4 GHz */ u8 reserved; __le16 channel; -#if IWL == 3945 - struct iwl_power_per_rate power[IWL_MAX_RATES]; -#elif IWL == 4965 - struct iwl_tx_power_db tx_power; -#endif + struct iwl3945_power_per_rate power[IWL_MAX_RATES]; } __attribute__ ((packed)); -#if IWL == 3945 -struct iwl_rate_scaling_info { +struct iwl3945_rate_scaling_info { __le16 rate_n_flags; u8 try_cnt; u8 next_rate_index; } __attribute__ ((packed)); /** - * struct iwl_rate_scaling_cmd - Rate Scaling Command & Response + * struct iwl3945_rate_scaling_cmd - Rate Scaling Command & Response * * REPLY_RATE_SCALE = 0x47 (command, has simple generic response) * @@ -947,61 +1010,22 @@ struct iwl_rate_scaling_info { * For example, if you set 9MB (PLCP 0x0f) as the first * rate in the rate table, the bit mask for that rate * when passed through ofdm_basic_rates on the REPLY_RXON - * command would be bit 0 (1<<0) + * command would be bit 0 (1 << 0) */ -struct iwl_rate_scaling_cmd { +struct iwl3945_rate_scaling_cmd { u8 table_id; u8 reserved[3]; - struct iwl_rate_scaling_info table[IWL_MAX_RATES]; -} __attribute__ ((packed)); - -#elif IWL == 4965 - -/*RS_NEW_API: only TLC_RTS remains and moved to bit 0 */ -#define LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK (1<<0) - -#define LINK_QUAL_AC_NUM AC_NUM -#define LINK_QUAL_MAX_RETRY_NUM 16 - -#define LINK_QUAL_ANT_A_MSK (1<<0) -#define LINK_QUAL_ANT_B_MSK (1<<1) -#define LINK_QUAL_ANT_MSK (LINK_QUAL_ANT_A_MSK|LINK_QUAL_ANT_B_MSK) - -struct iwl_link_qual_general_params { - u8 flags; - u8 mimo_delimiter; - u8 single_stream_ant_msk; - u8 dual_stream_ant_msk; - u8 start_rate_index[LINK_QUAL_AC_NUM]; -} __attribute__ ((packed)); - -struct iwl_link_qual_agg_params { - __le16 agg_time_limit; - u8 agg_dis_start_th; - u8 agg_frame_cnt_limit; - __le32 reserved; -} __attribute__ ((packed)); - -/* - * REPLY_TX_LINK_QUALITY_CMD = 0x4e (command, has simple generic response) - */ -struct iwl_link_quality_cmd { - u8 sta_id; - u8 reserved1; - __le16 control; - struct iwl_link_qual_general_params general_params; - struct iwl_link_qual_agg_params agg_params; - struct { - __le32 rate_n_flags; - } rs_table[LINK_QUAL_MAX_RETRY_NUM]; - __le32 reserved2; + struct iwl3945_rate_scaling_info table[IWL_MAX_RATES]; } __attribute__ ((packed)); -#endif /* * REPLY_BT_CONFIG = 0x9b (command, has simple generic response) + * + * 3945 and 4965 support hardware handshake with Bluetooth device on + * same platform. Bluetooth device alerts wireless device when it will Tx; + * wireless device can delay or kill its own Tx to accomodate. */ -struct iwl_bt_cmd { +struct iwl3945_bt_cmd { u8 flags; u8 lead_time; u8 max_kill; @@ -1027,18 +1051,18 @@ struct iwl_bt_cmd { RXON_FILTER_ASSOC_MSK | \ RXON_FILTER_BCON_AWARE_MSK) -struct iwl_measure_channel { +struct iwl3945_measure_channel { __le32 duration; /* measurement duration in extended beacon * format */ u8 channel; /* channel to measure */ - u8 type; /* see enum iwl_measure_type */ + u8 type; /* see enum iwl3945_measure_type */ __le16 reserved; } __attribute__ ((packed)); /* * REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74 (command) */ -struct iwl_spectrum_cmd { +struct iwl3945_spectrum_cmd { __le16 len; /* number of bytes starting from token */ u8 token; /* token id */ u8 id; /* measurement id -- 0 or 1 */ @@ -1051,13 +1075,13 @@ struct iwl_spectrum_cmd { __le32 filter_flags; /* rxon filter flags */ __le16 channel_count; /* minimum 1, maximum 10 */ __le16 reserved3; - struct iwl_measure_channel channels[10]; + struct iwl3945_measure_channel channels[10]; } __attribute__ ((packed)); /* * REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74 (response) */ -struct iwl_spectrum_resp { +struct iwl3945_spectrum_resp { u8 token; u8 id; /* id of the prior command replaced, or 0xff */ __le16 status; /* 0 - command will be handled @@ -1065,12 +1089,12 @@ struct iwl_spectrum_resp { * measurement) */ } __attribute__ ((packed)); -enum iwl_measurement_state { +enum iwl3945_measurement_state { IWL_MEASUREMENT_START = 0, IWL_MEASUREMENT_STOP = 1, }; -enum iwl_measurement_status { +enum iwl3945_measurement_status { IWL_MEASUREMENT_OK = 0, IWL_MEASUREMENT_CONCURRENT = 1, IWL_MEASUREMENT_CSA_CONFLICT = 2, @@ -1083,18 +1107,18 @@ enum iwl_measurement_status { #define NUM_ELEMENTS_IN_HISTOGRAM 8 -struct iwl_measurement_histogram { +struct iwl3945_measurement_histogram { __le32 ofdm[NUM_ELEMENTS_IN_HISTOGRAM]; /* in 0.8usec counts */ __le32 cck[NUM_ELEMENTS_IN_HISTOGRAM]; /* in 1usec counts */ } __attribute__ ((packed)); /* clear channel availability counters */ -struct iwl_measurement_cca_counters { +struct iwl3945_measurement_cca_counters { __le32 ofdm; __le32 cck; } __attribute__ ((packed)); -enum iwl_measure_type { +enum iwl3945_measure_type { IWL_MEASURE_BASIC = (1 << 0), IWL_MEASURE_CHANNEL_LOAD = (1 << 1), IWL_MEASURE_HISTOGRAM_RPI = (1 << 2), @@ -1107,7 +1131,7 @@ enum iwl_measure_type { /* * SPECTRUM_MEASURE_NOTIFICATION = 0x75 (notification only, not a command) */ -struct iwl_spectrum_notification { +struct iwl3945_spectrum_notification { u8 id; /* measurement id -- 0 or 1 */ u8 token; u8 channel_index; /* index in measurement channel list */ @@ -1115,7 +1139,7 @@ struct iwl_spectrum_notification { __le32 start_time; /* lower 32-bits of TSF */ u8 band; /* 0 - 5.2GHz, 1 - 2.4GHz */ u8 channel; - u8 type; /* see enum iwl_measurement_type */ + u8 type; /* see enum iwl3945_measurement_type */ u8 reserved1; /* NOTE: cca_ofdm, cca_cck, basic_type, and histogram are only only * valid if applicable for measurement type requested. */ @@ -1125,9 +1149,9 @@ struct iwl_spectrum_notification { u8 basic_type; /* 0 - bss, 1 - ofdm preamble, 2 - * unidentified */ u8 reserved2[3]; - struct iwl_measurement_histogram histogram; + struct iwl3945_measurement_histogram histogram; __le32 stop_time; /* lower 32-bits of TSF */ - __le32 status; /* see iwl_measurement_status */ + __le32 status; /* see iwl3945_measurement_status */ } __attribute__ ((packed)); /****************************************************************************** @@ -1137,7 +1161,7 @@ struct iwl_spectrum_notification { *****************************************************************************/ /** - * struct iwl_powertable_cmd - Power Table Command + * struct iwl3945_powertable_cmd - Power Table Command * @flags: See below: * * POWER_TABLE_CMD = 0x77 (command, has simple generic response) @@ -1166,41 +1190,21 @@ struct iwl_spectrum_notification { */ #define IWL_POWER_VEC_SIZE 5 - -#if IWL == 3945 - -#define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK __constant_cpu_to_le32(1<<0) -#define IWL_POWER_SLEEP_OVER_DTIM_MSK __constant_cpu_to_le32(1<<2) -#define IWL_POWER_PCI_PM_MSK __constant_cpu_to_le32(1<<3) -struct iwl_powertable_cmd { +#define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK __constant_cpu_to_le32(1 << 0) +#define IWL_POWER_SLEEP_OVER_DTIM_MSK __constant_cpu_to_le32(1 << 2) +#define IWL_POWER_PCI_PM_MSK __constant_cpu_to_le32(1 << 3) +struct iwl3945_powertable_cmd { __le32 flags; __le32 rx_data_timeout; __le32 tx_data_timeout; __le32 sleep_interval[IWL_POWER_VEC_SIZE]; } __attribute__((packed)); -#elif IWL == 4965 - -#define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK __constant_cpu_to_le16(1<<0) -#define IWL_POWER_SLEEP_OVER_DTIM_MSK __constant_cpu_to_le16(1<<2) -#define IWL_POWER_PCI_PM_MSK __constant_cpu_to_le16(1<<3) - -struct iwl_powertable_cmd { - __le16 flags; - u8 keep_alive_seconds; - u8 debug_flags; - __le32 rx_data_timeout; - __le32 tx_data_timeout; - __le32 sleep_interval[IWL_POWER_VEC_SIZE]; - __le32 keep_alive_beacons; -} __attribute__ ((packed)); -#endif - /* * PM_SLEEP_NOTIFICATION = 0x7A (notification only, not a command) * 3945 and 4965 identical. */ -struct iwl_sleep_notification { +struct iwl3945_sleep_notification { u8 pm_sleep_mode; u8 pm_wakeup_src; __le16 reserved; @@ -1230,14 +1234,14 @@ enum { #define CARD_STATE_CMD_DISABLE 0x00 /* Put card to sleep */ #define CARD_STATE_CMD_ENABLE 0x01 /* Wake up card */ #define CARD_STATE_CMD_HALT 0x02 /* Power down permanently */ -struct iwl_card_state_cmd { +struct iwl3945_card_state_cmd { __le32 status; /* CARD_STATE_CMD_* request new power state */ } __attribute__ ((packed)); /* * CARD_STATE_NOTIFICATION = 0xa1 (notification only, not a command) */ -struct iwl_card_state_notif { +struct iwl3945_card_state_notif { __le32 flags; } __attribute__ ((packed)); @@ -1246,7 +1250,7 @@ struct iwl_card_state_notif { #define RF_CARD_DISABLED 0x04 #define RXON_CARD_DISABLED 0x10 -struct iwl_ct_kill_config { +struct iwl3945_ct_kill_config { __le32 reserved; __le32 critical_temperature_M; __le32 critical_temperature_R; @@ -1258,21 +1262,48 @@ struct iwl_ct_kill_config { * *****************************************************************************/ -struct iwl_scan_channel { - /* type is defined as: - * 0:0 active (0 - passive) - * 1:4 SSID direct - * If 1 is set then corresponding SSID IE is transmitted in probe +/** + * struct iwl3945_scan_channel - entry in REPLY_SCAN_CMD channel table + * + * One for each channel in the scan list. + * Each channel can independently select: + * 1) SSID for directed active scans + * 2) Txpower setting (for rate specified within Tx command) + * 3) How long to stay on-channel (behavior may be modified by quiet_time, + * quiet_plcp_th, good_CRC_th) + * + * To avoid uCode errors, make sure the following are true (see comments + * under struct iwl3945_scan_cmd about max_out_time and quiet_time): + * 1) If using passive_dwell (i.e. passive_dwell != 0): + * active_dwell <= passive_dwell (< max_out_time if max_out_time != 0) + * 2) quiet_time <= active_dwell + * 3) If restricting off-channel time (i.e. max_out_time !=0): + * passive_dwell < max_out_time + * active_dwell < max_out_time + */ +struct iwl3945_scan_channel { + /* + * type is defined as: + * 0:0 1 = active, 0 = passive + * 1:4 SSID direct bit map; if a bit is set, then corresponding + * SSID IE is transmitted in probe request. * 5:7 reserved */ u8 type; - u8 channel; - struct iwl_tx_power tpc; - __le16 active_dwell; - __le16 passive_dwell; + u8 channel; /* band is selected by iwl3945_scan_cmd "flags" field */ + struct iwl3945_tx_power tpc; + __le16 active_dwell; /* in 1024-uSec TU (time units), typ 5-50 */ + __le16 passive_dwell; /* in 1024-uSec TU (time units), typ 20-500 */ } __attribute__ ((packed)); -struct iwl_ssid_ie { +/** + * struct iwl3945_ssid_ie - directed scan network information element + * + * Up to 4 of these may appear in REPLY_SCAN_CMD, selected by "type" field + * in struct iwl3945_scan_channel; each channel may select different ssids from + * among the 4 entries. SSID IEs get transmitted in reverse order of entry. + */ +struct iwl3945_ssid_ie { u8 id; u8 len; u8 ssid[32]; @@ -1285,44 +1316,98 @@ struct iwl_ssid_ie { /* * REPLY_SCAN_CMD = 0x80 (command) + * + * The hardware scan command is very powerful; the driver can set it up to + * maintain (relatively) normal network traffic while doing a scan in the + * background. The max_out_time and suspend_time control the ratio of how + * long the device stays on an associated network channel ("service channel") + * vs. how long it's away from the service channel, tuned to other channels + * for scanning. + * + * max_out_time is the max time off-channel (in usec), and suspend_time + * is how long (in "extended beacon" format) that the scan is "suspended" + * after returning to the service channel. That is, suspend_time is the + * time that we stay on the service channel, doing normal work, between + * scan segments. The driver may set these parameters differently to support + * scanning when associated vs. not associated, and light vs. heavy traffic + * loads when associated. + * + * After receiving this command, the device's scan engine does the following; + * + * 1) Sends SCAN_START notification to driver + * 2) Checks to see if it has time to do scan for one channel + * 3) Sends NULL packet, with power-save (PS) bit set to 1, + * to tell AP that we're going off-channel + * 4) Tunes to first channel in scan list, does active or passive scan + * 5) Sends SCAN_RESULT notification to driver + * 6) Checks to see if it has time to do scan on *next* channel in list + * 7) Repeats 4-6 until it no longer has time to scan the next channel + * before max_out_time expires + * 8) Returns to service channel + * 9) Sends NULL packet with PS=0 to tell AP that we're back + * 10) Stays on service channel until suspend_time expires + * 11) Repeats entire process 2-10 until list is complete + * 12) Sends SCAN_COMPLETE notification + * + * For fast, efficient scans, the scan command also has support for staying on + * a channel for just a short time, if doing active scanning and getting no + * responses to the transmitted probe request. This time is controlled by + * quiet_time, and the number of received packets below which a channel is + * considered "quiet" is controlled by quiet_plcp_threshold. + * + * For active scanning on channels that have regulatory restrictions against + * blindly transmitting, the scan can listen before transmitting, to make sure + * that there is already legitimate activity on the channel. If enough + * packets are cleanly received on the channel (controlled by good_CRC_th, + * typical value 1), the scan engine starts transmitting probe requests. + * + * Driver must use separate scan commands for 2.4 vs. 5 GHz bands. + * + * To avoid uCode errors, see timing restrictions described under + * struct iwl3945_scan_channel. */ -struct iwl_scan_cmd { +struct iwl3945_scan_cmd { __le16 len; u8 reserved0; - u8 channel_count; - __le16 quiet_time; /* dwell only this long on quiet chnl - * (active scan) */ - __le16 quiet_plcp_th; /* quiet chnl is < this # pkts (typ. 1) */ - __le16 good_CRC_th; /* passive -> active promotion threshold */ -#if IWL == 3945 + u8 channel_count; /* # channels in channel list */ + __le16 quiet_time; /* dwell only this # millisecs on quiet channel + * (only for active scan) */ + __le16 quiet_plcp_th; /* quiet chnl is < this # pkts (typ. 1) */ + __le16 good_CRC_th; /* passive -> active promotion threshold */ __le16 reserved1; -#elif IWL == 4965 - __le16 rx_chain; -#endif - __le32 max_out_time; /* max usec to be out of associated (service) - * chnl */ - __le32 suspend_time; /* pause scan this long when returning to svc - * chnl. - * 3945 -- 31:24 # beacons, 19:0 additional usec, - * 4965 -- 31:22 # beacons, 21:0 additional usec. - */ - __le32 flags; - __le32 filter_flags; + __le32 max_out_time; /* max usec to be away from associated (service) + * channel */ + __le32 suspend_time; /* pause scan this long (in "extended beacon + * format") when returning to service channel: + * 3945; 31:24 # beacons, 19:0 additional usec, + * 4965; 31:22 # beacons, 21:0 additional usec. + */ + __le32 flags; /* RXON_FLG_* */ + __le32 filter_flags; /* RXON_FILTER_* */ + + /* For active scans (set to all-0s for passive scans). + * Does not include payload. Must specify Tx rate; no rate scaling. */ + struct iwl3945_tx_cmd tx_cmd; + + /* For directed active scans (set to all-0s otherwise) */ + struct iwl3945_ssid_ie direct_scan[PROBE_OPTION_MAX]; - struct iwl_tx_cmd tx_cmd; - struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX]; - - u8 data[0]; /* - * The channels start after the probe request payload and are of type: + * Probe request frame, followed by channel list. * - * struct iwl_scan_channel channels[0]; + * Size of probe request frame is specified by byte count in tx_cmd. + * Channel list follows immediately after probe request frame. + * Number of channels in list is specified by channel_count. + * Each channel in list is of type: * - * NOTE: Only one band of channels can be scanned per pass. You - * can not mix 2.4GHz channels and 5.2GHz channels and must - * request a scan multiple times (not concurrently) + * struct iwl3945_scan_channel channels[0]; * + * NOTE: Only one band of channels can be scanned per pass. You + * must not mix 2.4GHz channels and 5.2GHz channels, and you must wait + * for one scan to complete (i.e. receive SCAN_COMPLETE_NOTIFICATION) + * before requesting another scan. */ + u8 data[0]; } __attribute__ ((packed)); /* Can abort will notify by complete notification with abort status. */ @@ -1333,14 +1418,14 @@ struct iwl_scan_cmd { /* * REPLY_SCAN_CMD = 0x80 (response) */ -struct iwl_scanreq_notification { +struct iwl3945_scanreq_notification { __le32 status; /* 1: okay, 2: cannot fulfill request */ } __attribute__ ((packed)); /* * SCAN_START_NOTIFICATION = 0x82 (notification only, not a command) */ -struct iwl_scanstart_notification { +struct iwl3945_scanstart_notification { __le32 tsf_low; __le32 tsf_high; __le32 beacon_timer; @@ -1357,7 +1442,7 @@ struct iwl_scanstart_notification { /* * SCAN_RESULTS_NOTIFICATION = 0x83 (notification only, not a command) */ -struct iwl_scanresults_notification { +struct iwl3945_scanresults_notification { u8 channel; u8 band; u8 reserved[2]; @@ -1369,7 +1454,7 @@ struct iwl_scanresults_notification { /* * SCAN_COMPLETE_NOTIFICATION = 0x84 (notification only, not a command) */ -struct iwl_scancomplete_notification { +struct iwl3945_scancomplete_notification { u8 scanned_channels; u8 status; u8 reserved; @@ -1388,8 +1473,8 @@ struct iwl_scancomplete_notification { /* * BEACON_NOTIFICATION = 0x90 (notification only, not a command) */ -struct iwl_beacon_notif { - struct iwl_tx_resp beacon_notify_hdr; +struct iwl3945_beacon_notif { + struct iwl3945_tx_resp beacon_notify_hdr; __le32 low_tsf; __le32 high_tsf; __le32 ibss_mgr_status; @@ -1398,8 +1483,8 @@ struct iwl_beacon_notif { /* * REPLY_TX_BEACON = 0x91 (command, has simple generic response) */ -struct iwl_tx_beacon_cmd { - struct iwl_tx_cmd tx; +struct iwl3945_tx_beacon_cmd { + struct iwl3945_tx_cmd tx; __le16 tim_idx; u8 tim_size; u8 reserved1; @@ -1450,30 +1535,8 @@ struct statistics_rx_phy { __le32 rxe_frame_limit_overrun; __le32 sent_ack_cnt; __le32 sent_cts_cnt; -#if IWL == 4965 - __le32 sent_ba_rsp_cnt; - __le32 dsp_self_kill; - __le32 mh_format_err; - __le32 re_acq_main_rssi_sum; - __le32 reserved3; -#endif } __attribute__ ((packed)); -#if IWL == 4965 -struct statistics_rx_ht_phy { - __le32 plcp_err; - __le32 overrun_err; - __le32 early_overrun_err; - __le32 crc32_good; - __le32 crc32_err; - __le32 mh_format_err; - __le32 agg_crc32_good; - __le32 agg_mpdu_cnt; - __le32 agg_cnt; - __le32 reserved2; -} __attribute__ ((packed)); -#endif - struct statistics_rx_non_phy { __le32 bogus_cts; /* CTS received when not expecting CTS */ __le32 bogus_ack; /* ACK received when not expecting ACK */ @@ -1483,57 +1546,13 @@ struct statistics_rx_non_phy { * filtering process */ __le32 non_channel_beacons; /* beacons with our bss id but not on * our serving channel */ -#if IWL == 4965 - __le32 channel_beacons; /* beacons with our bss id and in our - * serving channel */ - __le32 num_missed_bcon; /* number of missed beacons */ - __le32 adc_rx_saturation_time; /* count in 0.8us units the time the - * ADC was in saturation */ - __le32 ina_detection_search_time;/* total time (in 0.8us) searched - * for INA */ - __le32 beacon_silence_rssi_a; /* RSSI silence after beacon frame */ - __le32 beacon_silence_rssi_b; /* RSSI silence after beacon frame */ - __le32 beacon_silence_rssi_c; /* RSSI silence after beacon frame */ - __le32 interference_data_flag; /* flag for interference data - * availability. 1 when data is - * available. */ - __le32 channel_load; /* counts RX Enable time */ - __le32 dsp_false_alarms; /* DSP false alarm (both OFDM - * and CCK) counter */ - __le32 beacon_rssi_a; - __le32 beacon_rssi_b; - __le32 beacon_rssi_c; - __le32 beacon_energy_a; - __le32 beacon_energy_b; - __le32 beacon_energy_c; -#endif } __attribute__ ((packed)); struct statistics_rx { struct statistics_rx_phy ofdm; struct statistics_rx_phy cck; struct statistics_rx_non_phy general; -#if IWL == 4965 - struct statistics_rx_ht_phy ofdm_ht; -#endif -} __attribute__ ((packed)); - -#if IWL == 4965 -struct statistics_tx_non_phy_agg { - __le32 ba_timeout; - __le32 ba_reschedule_frames; - __le32 scd_query_agg_frame_cnt; - __le32 scd_query_no_agg; - __le32 scd_query_agg; - __le32 scd_query_mismatch; - __le32 frame_not_ready; - __le32 underrun; - __le32 bt_prio_kill; - __le32 rx_ba_rsp_cnt; - __le32 reserved2; - __le32 reserved3; } __attribute__ ((packed)); -#endif struct statistics_tx { __le32 preamble_cnt; @@ -1545,14 +1564,6 @@ struct statistics_tx { __le32 ack_timeout; __le32 expected_ack_cnt; __le32 actual_ack_cnt; -#if IWL == 4965 - __le32 dump_msdu_cnt; - __le32 burst_abort_next_frame_mismatch_cnt; - __le32 burst_abort_missing_next_frame_cnt; - __le32 cts_timeout_collision; - __le32 ack_or_ba_timeout_collision; - struct statistics_tx_non_phy_agg agg; -#endif } __attribute__ ((packed)); struct statistics_dbg { @@ -1566,29 +1577,16 @@ struct statistics_div { __le32 tx_on_b; __le32 exec_time; __le32 probe_time; -#if IWL == 4965 - __le32 reserved1; - __le32 reserved2; -#endif } __attribute__ ((packed)); struct statistics_general { __le32 temperature; -#if IWL == 4965 - __le32 temperature_m; -#endif struct statistics_dbg dbg; __le32 sleep_time; __le32 slots_out; __le32 slots_idle; __le32 ttl_timestamp; struct statistics_div div; -#if IWL == 4965 - __le32 rx_enable_counter; - __le32 reserved1; - __le32 reserved2; - __le32 reserved3; -#endif } __attribute__ ((packed)); /* @@ -1608,7 +1606,7 @@ struct statistics_general { */ #define IWL_STATS_CONF_CLEAR_STATS __constant_cpu_to_le32(0x1) /* see above */ #define IWL_STATS_CONF_DISABLE_NOTIF __constant_cpu_to_le32(0x2)/* see above */ -struct iwl_statistics_cmd { +struct iwl3945_statistics_cmd { __le32 configuration_flags; /* IWL_STATS_CONF_* */ } __attribute__ ((packed)); @@ -1629,7 +1627,7 @@ struct iwl_statistics_cmd { */ #define STATISTICS_REPLY_FLG_BAND_24G_MSK __constant_cpu_to_le32(0x2) #define STATISTICS_REPLY_FLG_FAT_MODE_MSK __constant_cpu_to_le32(0x8) -struct iwl_notif_statistics { +struct iwl3945_notif_statistics { __le32 flag; struct statistics_rx rx; struct statistics_tx tx; @@ -1644,7 +1642,7 @@ struct iwl_notif_statistics { * then this notification will be sent. */ #define CONSECUTIVE_MISSED_BCONS_TH 20 -struct iwl_missed_beacon_notif { +struct iwl3945_missed_beacon_notif { __le32 consequtive_missed_beacons; __le32 total_missed_becons; __le32 num_expected_beacons; @@ -1660,12 +1658,12 @@ struct iwl_missed_beacon_notif { #define PHY_CALIBRATE_DIFF_GAIN_CMD (7) #define HD_TABLE_SIZE (11) -struct iwl_sensitivity_cmd { +struct iwl3945_sensitivity_cmd { __le16 control; __le16 table[HD_TABLE_SIZE]; } __attribute__ ((packed)); -struct iwl_calibration_cmd { +struct iwl3945_calibration_cmd { u8 opCode; u8 flags; __le16 reserved; @@ -1688,7 +1686,7 @@ struct iwl_calibration_cmd { * For each of 3 possible LEDs (Activity/Link/Tech, selected by "id" field), * this command turns it on or off, or sets up a periodic blinking cycle. */ -struct iwl_led_cmd { +struct iwl3945_led_cmd { __le32 interval; /* "interval" in uSec */ u8 id; /* 1: Activity, 2: Link, 3: Tech */ u8 off; /* # intervals off while blinking; @@ -1704,31 +1702,27 @@ struct iwl_led_cmd { * *****************************************************************************/ -struct iwl_rx_packet { +struct iwl3945_rx_packet { __le32 len; - struct iwl_cmd_header hdr; + struct iwl3945_cmd_header hdr; union { - struct iwl_alive_resp alive_frame; - struct iwl_rx_frame rx_frame; - struct iwl_tx_resp tx_resp; - struct iwl_spectrum_notification spectrum_notif; - struct iwl_csa_notification csa_notif; - struct iwl_error_resp err_resp; - struct iwl_card_state_notif card_state_notif; - struct iwl_beacon_notif beacon_status; - struct iwl_add_sta_resp add_sta; - struct iwl_sleep_notification sleep_notif; - struct iwl_spectrum_resp spectrum; - struct iwl_notif_statistics stats; -#if IWL == 4965 - struct iwl_compressed_ba_resp compressed_ba; - struct iwl_missed_beacon_notif missed_beacon; -#endif + struct iwl3945_alive_resp alive_frame; + struct iwl3945_rx_frame rx_frame; + struct iwl3945_tx_resp tx_resp; + struct iwl3945_spectrum_notification spectrum_notif; + struct iwl3945_csa_notification csa_notif; + struct iwl3945_error_resp err_resp; + struct iwl3945_card_state_notif card_state_notif; + struct iwl3945_beacon_notif beacon_status; + struct iwl3945_add_sta_resp add_sta; + struct iwl3945_sleep_notification sleep_notif; + struct iwl3945_spectrum_resp spectrum; + struct iwl3945_notif_statistics stats; __le32 status; u8 raw[0]; } u; } __attribute__ ((packed)); -#define IWL_RX_FRAME_SIZE (4 + sizeof(struct iwl_rx_frame)) +#define IWL_RX_FRAME_SIZE (4 + sizeof(struct iwl3945_rx_frame)) -#endif /* __iwl_commands_h__ */ +#endif /* __iwl3945_3945_commands_h__ */ diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-3945-debug.h index 72318d78957..f853c6b9f76 100644 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h +++ b/drivers/net/wireless/iwlwifi/iwl-3945-debug.h @@ -26,18 +26,18 @@ * *****************************************************************************/ -#ifndef __iwl_debug_h__ -#define __iwl_debug_h__ +#ifndef __iwl3945_debug_h__ +#define __iwl3945_debug_h__ -#ifdef CONFIG_IWLWIFI_DEBUG -extern u32 iwl_debug_level; +#ifdef CONFIG_IWL3945_DEBUG +extern u32 iwl3945_debug_level; #define IWL_DEBUG(level, fmt, args...) \ -do { if (iwl_debug_level & (level)) \ +do { if (iwl3945_debug_level & (level)) \ printk(KERN_ERR DRV_NAME": %c %s " fmt, \ in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0) #define IWL_DEBUG_LIMIT(level, fmt, args...) \ -do { if ((iwl_debug_level & (level)) && net_ratelimit()) \ +do { if ((iwl3945_debug_level & (level)) && net_ratelimit()) \ printk(KERN_ERR DRV_NAME": %c %s " fmt, \ in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0) #else @@ -47,7 +47,7 @@ static inline void IWL_DEBUG(int level, const char *fmt, ...) static inline void IWL_DEBUG_LIMIT(int level, const char *fmt, ...) { } -#endif /* CONFIG_IWLWIFI_DEBUG */ +#endif /* CONFIG_IWL3945_DEBUG */ /* * To use the debug system; @@ -68,51 +68,51 @@ static inline void IWL_DEBUG_LIMIT(int level, const char *fmt, ...) * * % cat /proc/net/iwl/debug_level * - * you simply need to add your entry to the iwl_debug_levels array. + * you simply need to add your entry to the iwl3945_debug_levels array. * * If you do not see debug_level in /proc/net/iwl then you do not have - * CONFIG_IWLWIFI_DEBUG defined in your kernel configuration + * CONFIG_IWL3945_DEBUG defined in your kernel configuration * */ -#define IWL_DL_INFO (1<<0) -#define IWL_DL_MAC80211 (1<<1) -#define IWL_DL_HOST_COMMAND (1<<2) -#define IWL_DL_STATE (1<<3) +#define IWL_DL_INFO (1 << 0) +#define IWL_DL_MAC80211 (1 << 1) +#define IWL_DL_HOST_COMMAND (1 << 2) +#define IWL_DL_STATE (1 << 3) -#define IWL_DL_RADIO (1<<7) -#define IWL_DL_POWER (1<<8) -#define IWL_DL_TEMP (1<<9) +#define IWL_DL_RADIO (1 << 7) +#define IWL_DL_POWER (1 << 8) +#define IWL_DL_TEMP (1 << 9) -#define IWL_DL_NOTIF (1<<10) -#define IWL_DL_SCAN (1<<11) -#define IWL_DL_ASSOC (1<<12) -#define IWL_DL_DROP (1<<13) +#define IWL_DL_NOTIF (1 << 10) +#define IWL_DL_SCAN (1 << 11) +#define IWL_DL_ASSOC (1 << 12) +#define IWL_DL_DROP (1 << 13) -#define IWL_DL_TXPOWER (1<<14) +#define IWL_DL_TXPOWER (1 << 14) -#define IWL_DL_AP (1<<15) +#define IWL_DL_AP (1 << 15) -#define IWL_DL_FW (1<<16) -#define IWL_DL_RF_KILL (1<<17) -#define IWL_DL_FW_ERRORS (1<<18) +#define IWL_DL_FW (1 << 16) +#define IWL_DL_RF_KILL (1 << 17) +#define IWL_DL_FW_ERRORS (1 << 18) -#define IWL_DL_LED (1<<19) +#define IWL_DL_LED (1 << 19) -#define IWL_DL_RATE (1<<20) +#define IWL_DL_RATE (1 << 20) -#define IWL_DL_CALIB (1<<21) -#define IWL_DL_WEP (1<<22) -#define IWL_DL_TX (1<<23) -#define IWL_DL_RX (1<<24) -#define IWL_DL_ISR (1<<25) -#define IWL_DL_HT (1<<26) -#define IWL_DL_IO (1<<27) -#define IWL_DL_11H (1<<28) +#define IWL_DL_CALIB (1 << 21) +#define IWL_DL_WEP (1 << 22) +#define IWL_DL_TX (1 << 23) +#define IWL_DL_RX (1 << 24) +#define IWL_DL_ISR (1 << 25) +#define IWL_DL_HT (1 << 26) +#define IWL_DL_IO (1 << 27) +#define IWL_DL_11H (1 << 28) -#define IWL_DL_STATS (1<<29) -#define IWL_DL_TX_REPLY (1<<30) -#define IWL_DL_QOS (1<<31) +#define IWL_DL_STATS (1 << 29) +#define IWL_DL_TX_REPLY (1 << 30) +#define IWL_DL_QOS (1 << 31) #define IWL_ERROR(f, a...) printk(KERN_ERR DRV_NAME ": " f, ## a) #define IWL_WARNING(f, a...) printk(KERN_WARNING DRV_NAME ": " f, ## a) diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-hw.h b/drivers/net/wireless/iwlwifi/iwl-3945-hw.h index fb5f0649f4f..6e0187393af 100644 --- a/drivers/net/wireless/iwlwifi/iwl-3945-hw.h +++ b/drivers/net/wireless/iwlwifi/iwl-3945-hw.h @@ -8,7 +8,7 @@ * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU Geeral Public License as + * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but @@ -60,58 +60,646 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *****************************************************************************/ +/* + * Please use this file (iwl-3945-hw.h) only for hardware-related definitions. + * Please use iwl-3945-commands.h for uCode API definitions. + * Please use iwl-3945.h for driver implementation definitions. + */ #ifndef __iwl_3945_hw__ #define __iwl_3945_hw__ -#define IWL_RX_BUF_SIZE 3000 -/* card static random access memory (SRAM) for processor data and instructs */ +/* + * uCode queue management definitions ... + * Queue #4 is the command queue for 3945 and 4965. + */ +#define IWL_CMD_QUEUE_NUM 4 + +/* Tx rates */ +#define IWL_CCK_RATES 4 +#define IWL_OFDM_RATES 8 +#define IWL_HT_RATES 0 +#define IWL_MAX_RATES (IWL_CCK_RATES+IWL_OFDM_RATES+IWL_HT_RATES) + +/* Time constants */ +#define SHORT_SLOT_TIME 9 +#define LONG_SLOT_TIME 20 + +/* RSSI to dBm */ +#define IWL_RSSI_OFFSET 95 + +/* + * EEPROM related constants, enums, and structures. + */ + +/* + * EEPROM access time values: + * + * Driver initiates EEPROM read by writing byte address << 1 to CSR_EEPROM_REG, + * then clearing (with subsequent read/modify/write) CSR_EEPROM_REG bit + * CSR_EEPROM_REG_BIT_CMD (0x2). + * Driver then polls CSR_EEPROM_REG for CSR_EEPROM_REG_READ_VALID_MSK (0x1). + * When polling, wait 10 uSec between polling loops, up to a maximum 5000 uSec. + * Driver reads 16-bit value from bits 31-16 of CSR_EEPROM_REG. + */ +#define IWL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */ +#define IWL_EEPROM_ACCESS_DELAY 10 /* uSec */ + +/* + * Regulatory channel usage flags in EEPROM struct iwl_eeprom_channel.flags. + * + * IBSS and/or AP operation is allowed *only* on those channels with + * (VALID && IBSS && ACTIVE && !RADAR). This restriction is in place because + * RADAR detection is not supported by the 3945 driver, but is a + * requirement for establishing a new network for legal operation on channels + * requiring RADAR detection or restricting ACTIVE scanning. + * + * NOTE: "WIDE" flag indicates that 20 MHz channel is supported; + * 3945 does not support FAT 40 MHz-wide channels. + * + * NOTE: Using a channel inappropriately will result in a uCode error! + */ +enum { + EEPROM_CHANNEL_VALID = (1 << 0), /* usable for this SKU/geo */ + EEPROM_CHANNEL_IBSS = (1 << 1), /* usable as an IBSS channel */ + /* Bit 2 Reserved */ + EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */ + EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */ + EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */ + EEPROM_CHANNEL_NARROW = (1 << 6), /* 10 MHz channel (not used) */ + EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */ +}; + +/* SKU Capabilities */ +#define EEPROM_SKU_CAP_SW_RF_KILL_ENABLE (1 << 0) +#define EEPROM_SKU_CAP_HW_RF_KILL_ENABLE (1 << 1) +#define EEPROM_SKU_CAP_OP_MODE_MRC (1 << 7) + +/* *regulatory* channel data from eeprom, one for each channel */ +struct iwl3945_eeprom_channel { + u8 flags; /* flags copied from EEPROM */ + s8 max_power_avg; /* max power (dBm) on this chnl, limit 31 */ +} __attribute__ ((packed)); + +/* + * Mapping of a Tx power level, at factory calibration temperature, + * to a radio/DSP gain table index. + * One for each of 5 "sample" power levels in each band. + * v_det is measured at the factory, using the 3945's built-in power amplifier + * (PA) output voltage detector. This same detector is used during Tx of + * long packets in normal operation to provide feedback as to proper output + * level. + * Data copied from EEPROM. + * DO NOT ALTER THIS STRUCTURE!!! + */ +struct iwl3945_eeprom_txpower_sample { + u8 gain_index; /* index into power (gain) setup table ... */ + s8 power; /* ... for this pwr level for this chnl group */ + u16 v_det; /* PA output voltage */ +} __attribute__ ((packed)); + +/* + * Mappings of Tx power levels -> nominal radio/DSP gain table indexes. + * One for each channel group (a.k.a. "band") (1 for BG, 4 for A). + * Tx power setup code interpolates between the 5 "sample" power levels + * to determine the nominal setup for a requested power level. + * Data copied from EEPROM. + * DO NOT ALTER THIS STRUCTURE!!! + */ +struct iwl3945_eeprom_txpower_group { + struct iwl3945_eeprom_txpower_sample samples[5]; /* 5 power levels */ + s32 a, b, c, d, e; /* coefficients for voltage->power + * formula (signed) */ + s32 Fa, Fb, Fc, Fd, Fe; /* these modify coeffs based on + * frequency (signed) */ + s8 saturation_power; /* highest power possible by h/w in this + * band */ + u8 group_channel; /* "representative" channel # in this band */ + s16 temperature; /* h/w temperature at factory calib this band + * (signed) */ +} __attribute__ ((packed)); + +/* + * Temperature-based Tx-power compensation data, not band-specific. + * These coefficients are use to modify a/b/c/d/e coeffs based on + * difference between current temperature and factory calib temperature. + * Data copied from EEPROM. + */ +struct iwl3945_eeprom_temperature_corr { + u32 Ta; + u32 Tb; + u32 Tc; + u32 Td; + u32 Te; +} __attribute__ ((packed)); + +/* + * EEPROM map + */ +struct iwl3945_eeprom { + u8 reserved0[16]; +#define EEPROM_DEVICE_ID (2*0x08) /* 2 bytes */ + u16 device_id; /* abs.ofs: 16 */ + u8 reserved1[2]; +#define EEPROM_PMC (2*0x0A) /* 2 bytes */ + u16 pmc; /* abs.ofs: 20 */ + u8 reserved2[20]; +#define EEPROM_MAC_ADDRESS (2*0x15) /* 6 bytes */ + u8 mac_address[6]; /* abs.ofs: 42 */ + u8 reserved3[58]; +#define EEPROM_BOARD_REVISION (2*0x35) /* 2 bytes */ + u16 board_revision; /* abs.ofs: 106 */ + u8 reserved4[11]; +#define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1) /* 9 bytes */ + u8 board_pba_number[9]; /* abs.ofs: 119 */ + u8 reserved5[8]; +#define EEPROM_VERSION (2*0x44) /* 2 bytes */ + u16 version; /* abs.ofs: 136 */ +#define EEPROM_SKU_CAP (2*0x45) /* 1 bytes */ + u8 sku_cap; /* abs.ofs: 138 */ +#define EEPROM_LEDS_MODE (2*0x45+1) /* 1 bytes */ + u8 leds_mode; /* abs.ofs: 139 */ +#define EEPROM_OEM_MODE (2*0x46) /* 2 bytes */ + u16 oem_mode; +#define EEPROM_WOWLAN_MODE (2*0x47) /* 2 bytes */ + u16 wowlan_mode; /* abs.ofs: 142 */ +#define EEPROM_LEDS_TIME_INTERVAL (2*0x48) /* 2 bytes */ + u16 leds_time_interval; /* abs.ofs: 144 */ +#define EEPROM_LEDS_OFF_TIME (2*0x49) /* 1 bytes */ + u8 leds_off_time; /* abs.ofs: 146 */ +#define EEPROM_LEDS_ON_TIME (2*0x49+1) /* 1 bytes */ + u8 leds_on_time; /* abs.ofs: 147 */ +#define EEPROM_ALMGOR_M_VERSION (2*0x4A) /* 1 bytes */ + u8 almgor_m_version; /* abs.ofs: 148 */ +#define EEPROM_ANTENNA_SWITCH_TYPE (2*0x4A+1) /* 1 bytes */ + u8 antenna_switch_type; /* abs.ofs: 149 */ + u8 reserved6[42]; +#define EEPROM_REGULATORY_SKU_ID (2*0x60) /* 4 bytes */ + u8 sku_id[4]; /* abs.ofs: 192 */ + +/* + * Per-channel regulatory data. + * + * Each channel that *might* be supported by 3945 or 4965 has a fixed location + * in EEPROM containing EEPROM_CHANNEL_* usage flags (LSB) and max regulatory + * txpower (MSB). + * + * Entries immediately below are for 20 MHz channel width. FAT (40 MHz) + * channels (only for 4965, not supported by 3945) appear later in the EEPROM. + * + * 2.4 GHz channels 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 + */ +#define EEPROM_REGULATORY_BAND_1 (2*0x62) /* 2 bytes */ + u16 band_1_count; /* abs.ofs: 196 */ +#define EEPROM_REGULATORY_BAND_1_CHANNELS (2*0x63) /* 28 bytes */ + struct iwl3945_eeprom_channel band_1_channels[14]; /* abs.ofs: 196 */ + +/* + * 4.9 GHz channels 183, 184, 185, 187, 188, 189, 192, 196, + * 5.0 GHz channels 7, 8, 11, 12, 16 + * (4915-5080MHz) (none of these is ever supported) + */ +#define EEPROM_REGULATORY_BAND_2 (2*0x71) /* 2 bytes */ + u16 band_2_count; /* abs.ofs: 226 */ +#define EEPROM_REGULATORY_BAND_2_CHANNELS (2*0x72) /* 26 bytes */ + struct iwl3945_eeprom_channel band_2_channels[13]; /* abs.ofs: 228 */ + +/* + * 5.2 GHz channels 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 + * (5170-5320MHz) + */ +#define EEPROM_REGULATORY_BAND_3 (2*0x7F) /* 2 bytes */ + u16 band_3_count; /* abs.ofs: 254 */ +#define EEPROM_REGULATORY_BAND_3_CHANNELS (2*0x80) /* 24 bytes */ + struct iwl3945_eeprom_channel band_3_channels[12]; /* abs.ofs: 256 */ + +/* + * 5.5 GHz channels 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 + * (5500-5700MHz) + */ +#define EEPROM_REGULATORY_BAND_4 (2*0x8C) /* 2 bytes */ + u16 band_4_count; /* abs.ofs: 280 */ +#define EEPROM_REGULATORY_BAND_4_CHANNELS (2*0x8D) /* 22 bytes */ + struct iwl3945_eeprom_channel band_4_channels[11]; /* abs.ofs: 282 */ + +/* + * 5.7 GHz channels 145, 149, 153, 157, 161, 165 + * (5725-5825MHz) + */ +#define EEPROM_REGULATORY_BAND_5 (2*0x98) /* 2 bytes */ + u16 band_5_count; /* abs.ofs: 304 */ +#define EEPROM_REGULATORY_BAND_5_CHANNELS (2*0x99) /* 12 bytes */ + struct iwl3945_eeprom_channel band_5_channels[6]; /* abs.ofs: 306 */ + + u8 reserved9[194]; + +/* + * 3945 Txpower calibration data. + */ +#define EEPROM_TXPOWER_CALIB_GROUP0 0x200 +#define EEPROM_TXPOWER_CALIB_GROUP1 0x240 +#define EEPROM_TXPOWER_CALIB_GROUP2 0x280 +#define EEPROM_TXPOWER_CALIB_GROUP3 0x2c0 +#define EEPROM_TXPOWER_CALIB_GROUP4 0x300 +#define IWL_NUM_TX_CALIB_GROUPS 5 + struct iwl3945_eeprom_txpower_group groups[IWL_NUM_TX_CALIB_GROUPS]; +/* abs.ofs: 512 */ +#define EEPROM_CALIB_TEMPERATURE_CORRECT 0x340 + struct iwl3945_eeprom_temperature_corr corrections; /* abs.ofs: 832 */ + u8 reserved16[172]; /* fill out to full 1024 byte block */ +} __attribute__ ((packed)); + +#define IWL_EEPROM_IMAGE_SIZE 1024 + +/* End of EEPROM */ + + +#include "iwl-3945-commands.h" + +#define PCI_LINK_CTRL 0x0F0 +#define PCI_POWER_SOURCE 0x0C8 +#define PCI_REG_WUM8 0x0E8 +#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000) + +/*=== CSR (control and status registers) ===*/ +#define CSR_BASE (0x000) + +#define CSR_SW_VER (CSR_BASE+0x000) +#define CSR_HW_IF_CONFIG_REG (CSR_BASE+0x000) /* hardware interface config */ +#define CSR_INT_COALESCING (CSR_BASE+0x004) /* accum ints, 32-usec units */ +#define CSR_INT (CSR_BASE+0x008) /* host interrupt status/ack */ +#define CSR_INT_MASK (CSR_BASE+0x00c) /* host interrupt enable */ +#define CSR_FH_INT_STATUS (CSR_BASE+0x010) /* busmaster int status/ack*/ +#define CSR_GPIO_IN (CSR_BASE+0x018) /* read external chip pins */ +#define CSR_RESET (CSR_BASE+0x020) /* busmaster enable, NMI, etc*/ +#define CSR_GP_CNTRL (CSR_BASE+0x024) + +/* + * Hardware revision info + * Bit fields: + * 31-8: Reserved + * 7-4: Type of device: 0x0 = 4965, 0xd = 3945 + * 3-2: Revision step: 0 = A, 1 = B, 2 = C, 3 = D + * 1-0: "Dash" value, as in A-1, etc. + */ +#define CSR_HW_REV (CSR_BASE+0x028) + +/* EEPROM reads */ +#define CSR_EEPROM_REG (CSR_BASE+0x02c) +#define CSR_EEPROM_GP (CSR_BASE+0x030) +#define CSR_GP_UCODE (CSR_BASE+0x044) +#define CSR_UCODE_DRV_GP1 (CSR_BASE+0x054) +#define CSR_UCODE_DRV_GP1_SET (CSR_BASE+0x058) +#define CSR_UCODE_DRV_GP1_CLR (CSR_BASE+0x05c) +#define CSR_UCODE_DRV_GP2 (CSR_BASE+0x060) +#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100) + +/* Analog phase-lock-loop configuration (3945 only) + * Set bit 24. */ +#define CSR_ANA_PLL_CFG (CSR_BASE+0x20c) + +/* Bits for CSR_HW_IF_CONFIG_REG */ +#define CSR_HW_IF_CONFIG_REG_BIT_ALMAGOR_MB (0x00000100) +#define CSR_HW_IF_CONFIG_REG_BIT_ALMAGOR_MM (0x00000200) +#define CSR_HW_IF_CONFIG_REG_BIT_SKU_MRC (0x00000400) +#define CSR_HW_IF_CONFIG_REG_BIT_BOARD_TYPE (0x00000800) +#define CSR_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_A (0x00000000) +#define CSR_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_B (0x00001000) +#define CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM (0x00200000) + +/* interrupt flags in INTA, set by uCode or hardware (e.g. dma), + * acknowledged (reset) by host writing "1" to flagged bits. */ +#define CSR_INT_BIT_FH_RX (1 << 31) /* Rx DMA, cmd responses, FH_INT[17:16] */ +#define CSR_INT_BIT_HW_ERR (1 << 29) /* DMA hardware error FH_INT[31] */ +#define CSR_INT_BIT_DNLD (1 << 28) /* uCode Download */ +#define CSR_INT_BIT_FH_TX (1 << 27) /* Tx DMA FH_INT[1:0] */ +#define CSR_INT_BIT_MAC_CLK_ACTV (1 << 26) /* NIC controller's clock toggled on/off */ +#define CSR_INT_BIT_SW_ERR (1 << 25) /* uCode error */ +#define CSR_INT_BIT_RF_KILL (1 << 7) /* HW RFKILL switch GP_CNTRL[27] toggled */ +#define CSR_INT_BIT_CT_KILL (1 << 6) /* Critical temp (chip too hot) rfkill */ +#define CSR_INT_BIT_SW_RX (1 << 3) /* Rx, command responses, 3945 */ +#define CSR_INT_BIT_WAKEUP (1 << 1) /* NIC controller waking up (pwr mgmt) */ +#define CSR_INT_BIT_ALIVE (1 << 0) /* uCode interrupts once it initializes */ + +#define CSR_INI_SET_MASK (CSR_INT_BIT_FH_RX | \ + CSR_INT_BIT_HW_ERR | \ + CSR_INT_BIT_FH_TX | \ + CSR_INT_BIT_SW_ERR | \ + CSR_INT_BIT_RF_KILL | \ + CSR_INT_BIT_SW_RX | \ + CSR_INT_BIT_WAKEUP | \ + CSR_INT_BIT_ALIVE) + +/* interrupt flags in FH (flow handler) (PCI busmaster DMA) */ +#define CSR_FH_INT_BIT_ERR (1 << 31) /* Error */ +#define CSR_FH_INT_BIT_HI_PRIOR (1 << 30) /* High priority Rx, bypass coalescing */ +#define CSR_FH_INT_BIT_RX_CHNL2 (1 << 18) /* Rx channel 2 (3945 only) */ +#define CSR_FH_INT_BIT_RX_CHNL1 (1 << 17) /* Rx channel 1 */ +#define CSR_FH_INT_BIT_RX_CHNL0 (1 << 16) /* Rx channel 0 */ +#define CSR_FH_INT_BIT_TX_CHNL6 (1 << 6) /* Tx channel 6 (3945 only) */ +#define CSR_FH_INT_BIT_TX_CHNL1 (1 << 1) /* Tx channel 1 */ +#define CSR_FH_INT_BIT_TX_CHNL0 (1 << 0) /* Tx channel 0 */ + +#define CSR_FH_INT_RX_MASK (CSR_FH_INT_BIT_HI_PRIOR | \ + CSR_FH_INT_BIT_RX_CHNL2 | \ + CSR_FH_INT_BIT_RX_CHNL1 | \ + CSR_FH_INT_BIT_RX_CHNL0) + +#define CSR_FH_INT_TX_MASK (CSR_FH_INT_BIT_TX_CHNL6 | \ + CSR_FH_INT_BIT_TX_CHNL1 | \ + CSR_FH_INT_BIT_TX_CHNL0) + + +/* RESET */ +#define CSR_RESET_REG_FLAG_NEVO_RESET (0x00000001) +#define CSR_RESET_REG_FLAG_FORCE_NMI (0x00000002) +#define CSR_RESET_REG_FLAG_SW_RESET (0x00000080) +#define CSR_RESET_REG_FLAG_MASTER_DISABLED (0x00000100) +#define CSR_RESET_REG_FLAG_STOP_MASTER (0x00000200) + +/* GP (general purpose) CONTROL */ +#define CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY (0x00000001) +#define CSR_GP_CNTRL_REG_FLAG_INIT_DONE (0x00000004) +#define CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ (0x00000008) +#define CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP (0x00000010) + +#define CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN (0x00000001) + +#define CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE (0x07000000) +#define CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE (0x04000000) +#define CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW (0x08000000) + + +/* EEPROM REG */ +#define CSR_EEPROM_REG_READ_VALID_MSK (0x00000001) +#define CSR_EEPROM_REG_BIT_CMD (0x00000002) + +/* EEPROM GP */ +#define CSR_EEPROM_GP_VALID_MSK (0x00000006) +#define CSR_EEPROM_GP_BAD_SIGNATURE (0x00000000) +#define CSR_EEPROM_GP_IF_OWNER_MSK (0x00000180) + +/* UCODE DRV GP */ +#define CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP (0x00000001) +#define CSR_UCODE_SW_BIT_RFKILL (0x00000002) +#define CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED (0x00000004) +#define CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT (0x00000008) + +/* GPIO */ +#define CSR_GPIO_IN_BIT_AUX_POWER (0x00000200) +#define CSR_GPIO_IN_VAL_VAUX_PWR_SRC (0x00000000) +#define CSR_GPIO_IN_VAL_VMAIN_PWR_SRC CSR_GPIO_IN_BIT_AUX_POWER + +/* GI Chicken Bits */ +#define CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX (0x00800000) +#define CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER (0x20000000) + +/* CSR_ANA_PLL_CFG */ +#define CSR_ANA_PLL_CFG_SH (0x00880300) + +/*=== HBUS (Host-side Bus) ===*/ +#define HBUS_BASE (0x400) + +/* + * Registers for accessing device's internal SRAM memory (e.g. SCD SRAM + * structures, error log, event log, verifying uCode load). + * First write to address register, then read from or write to data register + * to complete the job. Once the address register is set up, accesses to + * data registers auto-increment the address by one dword. + * Bit usage for address registers (read or write): + * 0-31: memory address within device + */ +#define HBUS_TARG_MEM_RADDR (HBUS_BASE+0x00c) +#define HBUS_TARG_MEM_WADDR (HBUS_BASE+0x010) +#define HBUS_TARG_MEM_WDAT (HBUS_BASE+0x018) +#define HBUS_TARG_MEM_RDAT (HBUS_BASE+0x01c) + +/* + * Registers for accessing device's internal peripheral registers + * (e.g. SCD, BSM, etc.). First write to address register, + * then read from or write to data register to complete the job. + * Bit usage for address registers (read or write): + * 0-15: register address (offset) within device + * 24-25: (# bytes - 1) to read or write (e.g. 3 for dword) + */ +#define HBUS_TARG_PRPH_WADDR (HBUS_BASE+0x044) +#define HBUS_TARG_PRPH_RADDR (HBUS_BASE+0x048) +#define HBUS_TARG_PRPH_WDAT (HBUS_BASE+0x04c) +#define HBUS_TARG_PRPH_RDAT (HBUS_BASE+0x050) + +/* + * Per-Tx-queue write pointer (index, really!) (3945 and 4965). + * Indicates index to next TFD that driver will fill (1 past latest filled). + * Bit usage: + * 0-7: queue write index + * 11-8: queue selector + */ +#define HBUS_TARG_WRPTR (HBUS_BASE+0x060) + +/* SCD (3945 Tx Frame Scheduler) */ +#define SCD_BASE (CSR_BASE + 0x2E00) + +#define SCD_MODE_REG (SCD_BASE + 0x000) +#define SCD_ARASTAT_REG (SCD_BASE + 0x004) +#define SCD_TXFACT_REG (SCD_BASE + 0x010) +#define SCD_TXF4MF_REG (SCD_BASE + 0x014) +#define SCD_TXF5MF_REG (SCD_BASE + 0x020) +#define SCD_SBYP_MODE_1_REG (SCD_BASE + 0x02C) +#define SCD_SBYP_MODE_2_REG (SCD_BASE + 0x030) + +/*=== FH (data Flow Handler) ===*/ +#define FH_BASE (0x800) + +#define FH_CBCC_TABLE (FH_BASE+0x140) +#define FH_TFDB_TABLE (FH_BASE+0x180) +#define FH_RCSR_TABLE (FH_BASE+0x400) +#define FH_RSSR_TABLE (FH_BASE+0x4c0) +#define FH_TCSR_TABLE (FH_BASE+0x500) +#define FH_TSSR_TABLE (FH_BASE+0x680) + +/* TFDB (Transmit Frame Buffer Descriptor) */ +#define FH_TFDB(_channel, buf) \ + (FH_TFDB_TABLE+((_channel)*2+(buf))*0x28) +#define ALM_FH_TFDB_CHNL_BUF_CTRL_REG(_channel) \ + (FH_TFDB_TABLE + 0x50 * _channel) +/* CBCC _channel is [0,2] */ +#define FH_CBCC(_channel) (FH_CBCC_TABLE+(_channel)*0x8) +#define FH_CBCC_CTRL(_channel) (FH_CBCC(_channel)+0x00) +#define FH_CBCC_BASE(_channel) (FH_CBCC(_channel)+0x04) + +/* RCSR _channel is [0,2] */ +#define FH_RCSR(_channel) (FH_RCSR_TABLE+(_channel)*0x40) +#define FH_RCSR_CONFIG(_channel) (FH_RCSR(_channel)+0x00) +#define FH_RCSR_RBD_BASE(_channel) (FH_RCSR(_channel)+0x04) +#define FH_RCSR_WPTR(_channel) (FH_RCSR(_channel)+0x20) +#define FH_RCSR_RPTR_ADDR(_channel) (FH_RCSR(_channel)+0x24) + +#define FH_RSCSR_CHNL0_WPTR (FH_RCSR_WPTR(0)) + +/* RSSR */ +#define FH_RSSR_CTRL (FH_RSSR_TABLE+0x000) +#define FH_RSSR_STATUS (FH_RSSR_TABLE+0x004) +/* TCSR */ +#define FH_TCSR(_channel) (FH_TCSR_TABLE+(_channel)*0x20) +#define FH_TCSR_CONFIG(_channel) (FH_TCSR(_channel)+0x00) +#define FH_TCSR_CREDIT(_channel) (FH_TCSR(_channel)+0x04) +#define FH_TCSR_BUFF_STTS(_channel) (FH_TCSR(_channel)+0x08) +/* TSSR */ +#define FH_TSSR_CBB_BASE (FH_TSSR_TABLE+0x000) +#define FH_TSSR_MSG_CONFIG (FH_TSSR_TABLE+0x008) +#define FH_TSSR_TX_STATUS (FH_TSSR_TABLE+0x010) + + +/* DBM */ + +#define ALM_FH_SRVC_CHNL (6) + +#define ALM_FH_RCSR_RX_CONFIG_REG_POS_RBDC_SIZE (20) +#define ALM_FH_RCSR_RX_CONFIG_REG_POS_IRQ_RBTH (4) + +#define ALM_FH_RCSR_RX_CONFIG_REG_BIT_WR_STTS_EN (0x08000000) + +#define ALM_FH_RCSR_RX_CONFIG_REG_VAL_DMA_CHNL_EN_ENABLE (0x80000000) + +#define ALM_FH_RCSR_RX_CONFIG_REG_VAL_RDRBD_EN_ENABLE (0x20000000) + +#define ALM_FH_RCSR_RX_CONFIG_REG_VAL_MAX_FRAG_SIZE_128 (0x01000000) + +#define ALM_FH_RCSR_RX_CONFIG_REG_VAL_IRQ_DEST_INT_HOST (0x00001000) + +#define ALM_FH_RCSR_RX_CONFIG_REG_VAL_MSG_MODE_FH (0x00000000) + +#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF (0x00000000) +#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_DRIVER (0x00000001) + +#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL (0x00000000) +#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL (0x00000008) + +#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD (0x00200000) + +#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT (0x00000000) + +#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000) +#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000) + +#define ALM_FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID (0x00004000) + +#define ALM_FH_TCSR_CHNL_TX_BUF_STS_REG_BIT_TFDB_WPTR (0x00000001) + +#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TXPD_ON (0xFF000000) +#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_TXPD_ON (0x00FF0000) + +#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_128B (0x00000400) + +#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TFD_ON (0x00000100) +#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_CBB_ON (0x00000080) + +#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RSP_WAIT_TH (0x00000020) +#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_RSP_WAIT_TH (0x00000005) + +#define ALM_TB_MAX_BYTES_COUNT (0xFFF0) + +#define ALM_FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_channel) \ + ((1LU << _channel) << 24) +#define ALM_FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_channel) \ + ((1LU << _channel) << 16) + +#define ALM_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_channel) \ + (ALM_FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_channel) | \ + ALM_FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_channel)) +#define PCI_CFG_REV_ID_BIT_BASIC_SKU (0x40) /* bit 6 */ +#define PCI_CFG_REV_ID_BIT_RTP (0x80) /* bit 7 */ + +#define TFD_QUEUE_MIN 0 +#define TFD_QUEUE_MAX 6 +#define TFD_QUEUE_SIZE_MAX (256) + +#define IWL_NUM_SCAN_RATES (2) + +#define IWL_DEFAULT_TX_RETRY 15 + +/*********************************************/ + +#define RFD_SIZE 4 +#define NUM_TFD_CHUNKS 4 + +#define RX_QUEUE_SIZE 256 +#define RX_QUEUE_MASK 255 +#define RX_QUEUE_SIZE_LOG 8 + +#define U32_PAD(n) ((4-(n))&0x3) + +#define TFD_CTL_COUNT_SET(n) (n << 24) +#define TFD_CTL_COUNT_GET(ctl) ((ctl >> 24) & 7) +#define TFD_CTL_PAD_SET(n) (n << 28) +#define TFD_CTL_PAD_GET(ctl) (ctl >> 28) + +#define TFD_TX_CMD_SLOTS 256 +#define TFD_CMD_SLOTS 32 + +#define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl3945_cmd) - \ + sizeof(struct iwl3945_cmd_meta)) + +/* + * RX related structures and functions + */ +#define RX_FREE_BUFFERS 64 +#define RX_LOW_WATERMARK 8 + +/* Sizes and addresses for instruction and data memory (SRAM) in + * 3945's embedded processor. Driver access is via HBUS_TARG_MEM_* regs. */ +#define RTC_INST_LOWER_BOUND (0x000000) #define ALM_RTC_INST_UPPER_BOUND (0x014000) + +#define RTC_DATA_LOWER_BOUND (0x800000) #define ALM_RTC_DATA_UPPER_BOUND (0x808000) #define ALM_RTC_INST_SIZE (ALM_RTC_INST_UPPER_BOUND - RTC_INST_LOWER_BOUND) #define ALM_RTC_DATA_SIZE (ALM_RTC_DATA_UPPER_BOUND - RTC_DATA_LOWER_BOUND) -#define IWL_MAX_BSM_SIZE ALM_RTC_INST_SIZE #define IWL_MAX_INST_SIZE ALM_RTC_INST_SIZE #define IWL_MAX_DATA_SIZE ALM_RTC_DATA_SIZE + +/* Size of uCode instruction memory in bootstrap state machine */ +#define IWL_MAX_BSM_SIZE ALM_RTC_INST_SIZE + #define IWL_MAX_NUM_QUEUES 8 -static inline int iwl_hw_valid_rtc_data_addr(u32 addr) +static inline int iwl3945_hw_valid_rtc_data_addr(u32 addr) { return (addr >= RTC_DATA_LOWER_BOUND) && (addr < ALM_RTC_DATA_UPPER_BOUND); } -/* Base physical address of iwl_shared is provided to FH_TSSR_CBB_BASE - * and &iwl_shared.rx_read_ptr[0] is provided to FH_RCSR_RPTR_ADDR(0) */ -struct iwl_shared { +/* Base physical address of iwl3945_shared is provided to FH_TSSR_CBB_BASE + * and &iwl3945_shared.rx_read_ptr[0] is provided to FH_RCSR_RPTR_ADDR(0) */ +struct iwl3945_shared { __le32 tx_base_ptr[8]; __le32 rx_read_ptr[3]; } __attribute__ ((packed)); -struct iwl_tfd_frame_data { +struct iwl3945_tfd_frame_data { __le32 addr; __le32 len; } __attribute__ ((packed)); -struct iwl_tfd_frame { +struct iwl3945_tfd_frame { __le32 control_flags; - struct iwl_tfd_frame_data pa[4]; + struct iwl3945_tfd_frame_data pa[4]; u8 reserved[28]; } __attribute__ ((packed)); -static inline u8 iwl_hw_get_rate(__le16 rate_n_flags) +static inline u8 iwl3945_hw_get_rate(__le16 rate_n_flags) { return le16_to_cpu(rate_n_flags) & 0xFF; } -static inline u16 iwl_hw_get_rate_n_flags(__le16 rate_n_flags) +static inline u16 iwl3945_hw_get_rate_n_flags(__le16 rate_n_flags) { return le16_to_cpu(rate_n_flags); } -static inline __le16 iwl_hw_set_rate_n_flags(u8 rate, u16 flags) +static inline __le16 iwl3945_hw_set_rate_n_flags(u8 rate, u16 flags) { return cpu_to_le16((u16)rate|flags); } diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-io.h b/drivers/net/wireless/iwlwifi/iwl-3945-io.h new file mode 100644 index 00000000000..75e20d0a20d --- /dev/null +++ b/drivers/net/wireless/iwlwifi/iwl-3945-io.h @@ -0,0 +1,431 @@ +/****************************************************************************** + * + * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. + * + * Portions of this file are derived from the ipw3945 project. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * James P. Ketrenos <ipw2100-admin@linux.intel.com> + * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 + * + *****************************************************************************/ + +#ifndef __iwl3945_io_h__ +#define __iwl3945_io_h__ + +#include <linux/io.h> + +#include "iwl-3945-debug.h" + +/* + * IO, register, and NIC memory access functions + * + * NOTE on naming convention and macro usage for these + * + * A single _ prefix before a an access function means that no state + * check or debug information is printed when that function is called. + * + * A double __ prefix before an access function means that state is checked + * and the current line number is printed in addition to any other debug output. + * + * The non-prefixed name is the #define that maps the caller into a + * #define that provides the caller's __LINE__ to the double prefix version. + * + * If you wish to call the function without any debug or state checking, + * you should use the single _ prefix version (as is used by dependent IO + * routines, for example _iwl3945_read_direct32 calls the non-check version of + * _iwl3945_read32.) + * + * These declarations are *extremely* useful in quickly isolating code deltas + * which result in misconfiguring of the hardware I/O. In combination with + * git-bisect and the IO debug level you can quickly determine the specific + * commit which breaks the IO sequence to the hardware. + * + */ + +#define _iwl3945_write32(iwl, ofs, val) writel((val), (iwl)->hw_base + (ofs)) +#ifdef CONFIG_IWL3945_DEBUG +static inline void __iwl3945_write32(const char *f, u32 l, struct iwl3945_priv *iwl, + u32 ofs, u32 val) +{ + IWL_DEBUG_IO("write32(0x%08X, 0x%08X) - %s %d\n", ofs, val, f, l); + _iwl3945_write32(iwl, ofs, val); +} +#define iwl3945_write32(iwl, ofs, val) \ + __iwl3945_write32(__FILE__, __LINE__, iwl, ofs, val) +#else +#define iwl3945_write32(iwl, ofs, val) _iwl3945_write32(iwl, ofs, val) +#endif + +#define _iwl3945_read32(iwl, ofs) readl((iwl)->hw_base + (ofs)) +#ifdef CONFIG_IWL3945_DEBUG +static inline u32 __iwl3945_read32(char *f, u32 l, struct iwl3945_priv *iwl, u32 ofs) +{ + IWL_DEBUG_IO("read_direct32(0x%08X) - %s %d\n", ofs, f, l); + return _iwl3945_read32(iwl, ofs); +} +#define iwl3945_read32(iwl, ofs) __iwl3945_read32(__FILE__, __LINE__, iwl, ofs) +#else +#define iwl3945_read32(p, o) _iwl3945_read32(p, o) +#endif + +static inline int _iwl3945_poll_bit(struct iwl3945_priv *priv, u32 addr, + u32 bits, u32 mask, int timeout) +{ + int i = 0; + + do { + if ((_iwl3945_read32(priv, addr) & mask) == (bits & mask)) + return i; + mdelay(10); + i += 10; + } while (i < timeout); + + return -ETIMEDOUT; +} +#ifdef CONFIG_IWL3945_DEBUG +static inline int __iwl3945_poll_bit(const char *f, u32 l, + struct iwl3945_priv *priv, u32 addr, + u32 bits, u32 mask, int timeout) +{ + int ret = _iwl3945_poll_bit(priv, addr, bits, mask, timeout); + if (unlikely(ret == -ETIMEDOUT)) + IWL_DEBUG_IO + ("poll_bit(0x%08X, 0x%08X, 0x%08X) - timedout - %s %d\n", + addr, bits, mask, f, l); + else + IWL_DEBUG_IO + ("poll_bit(0x%08X, 0x%08X, 0x%08X) = 0x%08X - %s %d\n", + addr, bits, mask, ret, f, l); + return ret; +} +#define iwl3945_poll_bit(iwl, addr, bits, mask, timeout) \ + __iwl3945_poll_bit(__FILE__, __LINE__, iwl, addr, bits, mask, timeout) +#else +#define iwl3945_poll_bit(p, a, b, m, t) _iwl3945_poll_bit(p, a, b, m, t) +#endif + +static inline void _iwl3945_set_bit(struct iwl3945_priv *priv, u32 reg, u32 mask) +{ + _iwl3945_write32(priv, reg, _iwl3945_read32(priv, reg) | mask); +} +#ifdef CONFIG_IWL3945_DEBUG +static inline void __iwl3945_set_bit(const char *f, u32 l, + struct iwl3945_priv *priv, u32 reg, u32 mask) +{ + u32 val = _iwl3945_read32(priv, reg) | mask; + IWL_DEBUG_IO("set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); + _iwl3945_write32(priv, reg, val); +} +#define iwl3945_set_bit(p, r, m) __iwl3945_set_bit(__FILE__, __LINE__, p, r, m) +#else +#define iwl3945_set_bit(p, r, m) _iwl3945_set_bit(p, r, m) +#endif + +static inline void _iwl3945_clear_bit(struct iwl3945_priv *priv, u32 reg, u32 mask) +{ + _iwl3945_write32(priv, reg, _iwl3945_read32(priv, reg) & ~mask); +} +#ifdef CONFIG_IWL3945_DEBUG +static inline void __iwl3945_clear_bit(const char *f, u32 l, + struct iwl3945_priv *priv, u32 reg, u32 mask) +{ + u32 val = _iwl3945_read32(priv, reg) & ~mask; + IWL_DEBUG_IO("clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); + _iwl3945_write32(priv, reg, val); +} +#define iwl3945_clear_bit(p, r, m) __iwl3945_clear_bit(__FILE__, __LINE__, p, r, m) +#else +#define iwl3945_clear_bit(p, r, m) _iwl3945_clear_bit(p, r, m) +#endif + +static inline int _iwl3945_grab_nic_access(struct iwl3945_priv *priv) +{ + int ret; + u32 gp_ctl; + +#ifdef CONFIG_IWL3945_DEBUG + if (atomic_read(&priv->restrict_refcnt)) + return 0; +#endif + if (test_bit(STATUS_RF_KILL_HW, &priv->status) || + test_bit(STATUS_RF_KILL_SW, &priv->status)) { + IWL_WARNING("WARNING: Requesting MAC access during RFKILL " + "wakes up NIC\n"); + + /* 10 msec allows time for NIC to complete its data save */ + gp_ctl = _iwl3945_read32(priv, CSR_GP_CNTRL); + if (gp_ctl & CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY) { + IWL_DEBUG_RF_KILL("Wait for complete power-down, " + "gpctl = 0x%08x\n", gp_ctl); + mdelay(10); + } else + IWL_DEBUG_RF_KILL("power-down complete, " + "gpctl = 0x%08x\n", gp_ctl); + } + + /* this bit wakes up the NIC */ + _iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + ret = _iwl3945_poll_bit(priv, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN, + (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY | + CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 50); + if (ret < 0) { + IWL_ERROR("MAC is in deep sleep!\n"); + return -EIO; + } + +#ifdef CONFIG_IWL3945_DEBUG + atomic_inc(&priv->restrict_refcnt); +#endif + return 0; +} + +#ifdef CONFIG_IWL3945_DEBUG +static inline int __iwl3945_grab_nic_access(const char *f, u32 l, + struct iwl3945_priv *priv) +{ + if (atomic_read(&priv->restrict_refcnt)) + IWL_DEBUG_INFO("Grabbing access while already held at " + "line %d.\n", l); + + IWL_DEBUG_IO("grabbing nic access - %s %d\n", f, l); + return _iwl3945_grab_nic_access(priv); +} +#define iwl3945_grab_nic_access(priv) \ + __iwl3945_grab_nic_access(__FILE__, __LINE__, priv) +#else +#define iwl3945_grab_nic_access(priv) \ + _iwl3945_grab_nic_access(priv) +#endif + +static inline void _iwl3945_release_nic_access(struct iwl3945_priv *priv) +{ +#ifdef CONFIG_IWL3945_DEBUG + if (atomic_dec_and_test(&priv->restrict_refcnt)) +#endif + _iwl3945_clear_bit(priv, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); +} +#ifdef CONFIG_IWL3945_DEBUG +static inline void __iwl3945_release_nic_access(const char *f, u32 l, + struct iwl3945_priv *priv) +{ + if (atomic_read(&priv->restrict_refcnt) <= 0) + IWL_ERROR("Release unheld nic access at line %d.\n", l); + + IWL_DEBUG_IO("releasing nic access - %s %d\n", f, l); + _iwl3945_release_nic_access(priv); +} +#define iwl3945_release_nic_access(priv) \ + __iwl3945_release_nic_access(__FILE__, __LINE__, priv) +#else +#define iwl3945_release_nic_access(priv) \ + _iwl3945_release_nic_access(priv) +#endif + +static inline u32 _iwl3945_read_direct32(struct iwl3945_priv *priv, u32 reg) +{ + return _iwl3945_read32(priv, reg); +} +#ifdef CONFIG_IWL3945_DEBUG +static inline u32 __iwl3945_read_direct32(const char *f, u32 l, + struct iwl3945_priv *priv, u32 reg) +{ + u32 value = _iwl3945_read_direct32(priv, reg); + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access not held from %s %d\n", f, l); + IWL_DEBUG_IO("read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value, + f, l); + return value; +} +#define iwl3945_read_direct32(priv, reg) \ + __iwl3945_read_direct32(__FILE__, __LINE__, priv, reg) +#else +#define iwl3945_read_direct32 _iwl3945_read_direct32 +#endif + +static inline void _iwl3945_write_direct32(struct iwl3945_priv *priv, + u32 reg, u32 value) +{ + _iwl3945_write32(priv, reg, value); +} +#ifdef CONFIG_IWL3945_DEBUG +static void __iwl3945_write_direct32(u32 line, + struct iwl3945_priv *priv, u32 reg, u32 value) +{ + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access not held from line %d\n", line); + _iwl3945_write_direct32(priv, reg, value); +} +#define iwl3945_write_direct32(priv, reg, value) \ + __iwl3945_write_direct32(__LINE__, priv, reg, value) +#else +#define iwl3945_write_direct32 _iwl3945_write_direct32 +#endif + +static inline void iwl3945_write_reg_buf(struct iwl3945_priv *priv, + u32 reg, u32 len, u32 *values) +{ + u32 count = sizeof(u32); + + if ((priv != NULL) && (values != NULL)) { + for (; 0 < len; len -= count, reg += count, values++) + _iwl3945_write_direct32(priv, reg, *values); + } +} + +static inline int _iwl3945_poll_direct_bit(struct iwl3945_priv *priv, + u32 addr, u32 mask, int timeout) +{ + int i = 0; + + do { + if ((_iwl3945_read_direct32(priv, addr) & mask) == mask) + return i; + mdelay(10); + i += 10; + } while (i < timeout); + + return -ETIMEDOUT; +} + +#ifdef CONFIG_IWL3945_DEBUG +static inline int __iwl3945_poll_direct_bit(const char *f, u32 l, + struct iwl3945_priv *priv, + u32 addr, u32 mask, int timeout) +{ + int ret = _iwl3945_poll_direct_bit(priv, addr, mask, timeout); + + if (unlikely(ret == -ETIMEDOUT)) + IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) - " + "timedout - %s %d\n", addr, mask, f, l); + else + IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) = 0x%08X " + "- %s %d\n", addr, mask, ret, f, l); + return ret; +} +#define iwl3945_poll_direct_bit(iwl, addr, mask, timeout) \ + __iwl3945_poll_direct_bit(__FILE__, __LINE__, iwl, addr, mask, timeout) +#else +#define iwl3945_poll_direct_bit _iwl3945_poll_direct_bit +#endif + +static inline u32 _iwl3945_read_prph(struct iwl3945_priv *priv, u32 reg) +{ + _iwl3945_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24)); + return _iwl3945_read_direct32(priv, HBUS_TARG_PRPH_RDAT); +} +#ifdef CONFIG_IWL3945_DEBUG +static inline u32 __iwl3945_read_prph(u32 line, struct iwl3945_priv *priv, u32 reg) +{ + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access not held from line %d\n", line); + return _iwl3945_read_prph(priv, reg); +} + +#define iwl3945_read_prph(priv, reg) \ + __iwl3945_read_prph(__LINE__, priv, reg) +#else +#define iwl3945_read_prph _iwl3945_read_prph +#endif + +static inline void _iwl3945_write_prph(struct iwl3945_priv *priv, + u32 addr, u32 val) +{ + _iwl3945_write_direct32(priv, HBUS_TARG_PRPH_WADDR, + ((addr & 0x0000FFFF) | (3 << 24))); + _iwl3945_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val); +} +#ifdef CONFIG_IWL3945_DEBUG +static inline void __iwl3945_write_prph(u32 line, struct iwl3945_priv *priv, + u32 addr, u32 val) +{ + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access from line %d\n", line); + _iwl3945_write_prph(priv, addr, val); +} + +#define iwl3945_write_prph(priv, addr, val) \ + __iwl3945_write_prph(__LINE__, priv, addr, val); +#else +#define iwl3945_write_prph _iwl3945_write_prph +#endif + +#define _iwl3945_set_bits_prph(priv, reg, mask) \ + _iwl3945_write_prph(priv, reg, (_iwl3945_read_prph(priv, reg) | mask)) +#ifdef CONFIG_IWL3945_DEBUG +static inline void __iwl3945_set_bits_prph(u32 line, struct iwl3945_priv *priv, + u32 reg, u32 mask) +{ + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access not held from line %d\n", line); + + _iwl3945_set_bits_prph(priv, reg, mask); +} +#define iwl3945_set_bits_prph(priv, reg, mask) \ + __iwl3945_set_bits_prph(__LINE__, priv, reg, mask) +#else +#define iwl3945_set_bits_prph _iwl3945_set_bits_prph +#endif + +#define _iwl3945_set_bits_mask_prph(priv, reg, bits, mask) \ + _iwl3945_write_prph(priv, reg, ((_iwl3945_read_prph(priv, reg) & mask) | bits)) + +#ifdef CONFIG_IWL3945_DEBUG +static inline void __iwl3945_set_bits_mask_prph(u32 line, + struct iwl3945_priv *priv, u32 reg, u32 bits, u32 mask) +{ + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access not held from line %d\n", line); + _iwl3945_set_bits_mask_prph(priv, reg, bits, mask); +} +#define iwl3945_set_bits_mask_prph(priv, reg, bits, mask) \ + __iwl3945_set_bits_mask_prph(__LINE__, priv, reg, bits, mask) +#else +#define iwl3945_set_bits_mask_prph _iwl3945_set_bits_mask_prph +#endif + +static inline void iwl3945_clear_bits_prph(struct iwl3945_priv + *priv, u32 reg, u32 mask) +{ + u32 val = _iwl3945_read_prph(priv, reg); + _iwl3945_write_prph(priv, reg, (val & ~mask)); +} + +static inline u32 iwl3945_read_targ_mem(struct iwl3945_priv *priv, u32 addr) +{ + iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr); + return iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT); +} + +static inline void iwl3945_write_targ_mem(struct iwl3945_priv *priv, u32 addr, u32 val) +{ + iwl3945_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr); + iwl3945_write_direct32(priv, HBUS_TARG_MEM_WDAT, val); +} + +static inline void iwl3945_write_targ_mem_buf(struct iwl3945_priv *priv, u32 addr, + u32 len, u32 *values) +{ + iwl3945_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr); + for (; 0 < len; len -= sizeof(u32), values++) + iwl3945_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values); +} +#endif diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c index c48b1b537d2..80d31ae51e7 100644 --- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c +++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c @@ -37,15 +37,13 @@ #include <linux/workqueue.h> -#define IWL 3945 - #include "../net/mac80211/ieee80211_rate.h" -#include "iwlwifi.h" +#include "iwl-3945.h" #define RS_NAME "iwl-3945-rs" -struct iwl_rate_scale_data { +struct iwl3945_rate_scale_data { u64 data; s32 success_counter; s32 success_ratio; @@ -54,7 +52,7 @@ struct iwl_rate_scale_data { unsigned long stamp; }; -struct iwl_rate_scale_priv { +struct iwl3945_rs_sta { spinlock_t lock; s32 *expected_tpt; unsigned long last_partial_flush; @@ -67,31 +65,31 @@ struct iwl_rate_scale_priv { u8 start_rate; u8 ibss_sta_added; struct timer_list rate_scale_flush; - struct iwl_rate_scale_data win[IWL_RATE_COUNT]; + struct iwl3945_rate_scale_data win[IWL_RATE_COUNT]; }; -static s32 iwl_expected_tpt_g[IWL_RATE_COUNT] = { +static s32 iwl3945_expected_tpt_g[IWL_RATE_COUNT] = { 7, 13, 35, 58, 0, 0, 76, 104, 130, 168, 191, 202 }; -static s32 iwl_expected_tpt_g_prot[IWL_RATE_COUNT] = { +static s32 iwl3945_expected_tpt_g_prot[IWL_RATE_COUNT] = { 7, 13, 35, 58, 0, 0, 0, 80, 93, 113, 123, 125 }; -static s32 iwl_expected_tpt_a[IWL_RATE_COUNT] = { +static s32 iwl3945_expected_tpt_a[IWL_RATE_COUNT] = { 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186 }; -static s32 iwl_expected_tpt_b[IWL_RATE_COUNT] = { +static s32 iwl3945_expected_tpt_b[IWL_RATE_COUNT] = { 7, 13, 35, 58, 0, 0, 0, 0, 0, 0, 0, 0 }; -struct iwl_tpt_entry { +struct iwl3945_tpt_entry { s8 min_rssi; u8 index; }; -static struct iwl_tpt_entry iwl_tpt_table_a[] = { +static struct iwl3945_tpt_entry iwl3945_tpt_table_a[] = { {-60, IWL_RATE_54M_INDEX}, {-64, IWL_RATE_48M_INDEX}, {-72, IWL_RATE_36M_INDEX}, @@ -102,7 +100,7 @@ static struct iwl_tpt_entry iwl_tpt_table_a[] = { {-89, IWL_RATE_6M_INDEX} }; -static struct iwl_tpt_entry iwl_tpt_table_b[] = { +static struct iwl3945_tpt_entry iwl3945_tpt_table_b[] = { {-86, IWL_RATE_11M_INDEX}, {-88, IWL_RATE_5M_INDEX}, {-90, IWL_RATE_2M_INDEX}, @@ -110,7 +108,7 @@ static struct iwl_tpt_entry iwl_tpt_table_b[] = { }; -static struct iwl_tpt_entry iwl_tpt_table_g[] = { +static struct iwl3945_tpt_entry iwl3945_tpt_table_g[] = { {-60, IWL_RATE_54M_INDEX}, {-64, IWL_RATE_48M_INDEX}, {-68, IWL_RATE_36M_INDEX}, @@ -131,30 +129,30 @@ static struct iwl_tpt_entry iwl_tpt_table_g[] = { #define IWL_RATE_MIN_SUCCESS_TH 8 #define IWL_RATE_DECREASE_TH 1920 -static u8 iwl_get_rate_index_by_rssi(s32 rssi, u8 mode) +static u8 iwl3945_get_rate_index_by_rssi(s32 rssi, u8 mode) { u32 index = 0; u32 table_size = 0; - struct iwl_tpt_entry *tpt_table = NULL; + struct iwl3945_tpt_entry *tpt_table = NULL; if ((rssi < IWL_MIN_RSSI_VAL) || (rssi > IWL_MAX_RSSI_VAL)) rssi = IWL_MIN_RSSI_VAL; switch (mode) { case MODE_IEEE80211G: - tpt_table = iwl_tpt_table_g; - table_size = ARRAY_SIZE(iwl_tpt_table_g); + tpt_table = iwl3945_tpt_table_g; + table_size = ARRAY_SIZE(iwl3945_tpt_table_g); break; case MODE_IEEE80211A: - tpt_table = iwl_tpt_table_a; - table_size = ARRAY_SIZE(iwl_tpt_table_a); + tpt_table = iwl3945_tpt_table_a; + table_size = ARRAY_SIZE(iwl3945_tpt_table_a); break; default: case MODE_IEEE80211B: - tpt_table = iwl_tpt_table_b; - table_size = ARRAY_SIZE(iwl_tpt_table_b); + tpt_table = iwl3945_tpt_table_b; + table_size = ARRAY_SIZE(iwl3945_tpt_table_b); break; } @@ -166,7 +164,7 @@ static u8 iwl_get_rate_index_by_rssi(s32 rssi, u8 mode) return tpt_table[index].index; } -static void iwl_clear_window(struct iwl_rate_scale_data *window) +static void iwl3945_clear_window(struct iwl3945_rate_scale_data *window) { window->data = 0; window->success_counter = 0; @@ -177,13 +175,13 @@ static void iwl_clear_window(struct iwl_rate_scale_data *window) } /** - * iwl_rate_scale_flush_windows - flush out the rate scale windows + * iwl3945_rate_scale_flush_windows - flush out the rate scale windows * * Returns the number of windows that have gathered data but were * not flushed. If there were any that were not flushed, then * reschedule the rate flushing routine. */ -static int iwl_rate_scale_flush_windows(struct iwl_rate_scale_priv *rs_priv) +static int iwl3945_rate_scale_flush_windows(struct iwl3945_rs_sta *rs_sta) { int unflushed = 0; int i; @@ -195,19 +193,19 @@ static int iwl_rate_scale_flush_windows(struct iwl_rate_scale_priv *rs_priv) * since we flushed, clear out the gathered statistics */ for (i = 0; i < IWL_RATE_COUNT; i++) { - if (!rs_priv->win[i].counter) + if (!rs_sta->win[i].counter) continue; - spin_lock_irqsave(&rs_priv->lock, flags); - if (time_after(jiffies, rs_priv->win[i].stamp + + spin_lock_irqsave(&rs_sta->lock, flags); + if (time_after(jiffies, rs_sta->win[i].stamp + IWL_RATE_WIN_FLUSH)) { IWL_DEBUG_RATE("flushing %d samples of rate " "index %d\n", - rs_priv->win[i].counter, i); - iwl_clear_window(&rs_priv->win[i]); + rs_sta->win[i].counter, i); + iwl3945_clear_window(&rs_sta->win[i]); } else unflushed++; - spin_unlock_irqrestore(&rs_priv->lock, flags); + spin_unlock_irqrestore(&rs_sta->lock, flags); } return unflushed; @@ -216,30 +214,30 @@ static int iwl_rate_scale_flush_windows(struct iwl_rate_scale_priv *rs_priv) #define IWL_RATE_FLUSH_MAX 5000 /* msec */ #define IWL_RATE_FLUSH_MIN 50 /* msec */ -static void iwl_bg_rate_scale_flush(unsigned long data) +static void iwl3945_bg_rate_scale_flush(unsigned long data) { - struct iwl_rate_scale_priv *rs_priv = (void *)data; + struct iwl3945_rs_sta *rs_sta = (void *)data; int unflushed = 0; unsigned long flags; u32 packet_count, duration, pps; IWL_DEBUG_RATE("enter\n"); - unflushed = iwl_rate_scale_flush_windows(rs_priv); + unflushed = iwl3945_rate_scale_flush_windows(rs_sta); - spin_lock_irqsave(&rs_priv->lock, flags); + spin_lock_irqsave(&rs_sta->lock, flags); - rs_priv->flush_pending = 0; + rs_sta->flush_pending = 0; /* Number of packets Rx'd since last time this timer ran */ - packet_count = (rs_priv->tx_packets - rs_priv->last_tx_packets) + 1; + packet_count = (rs_sta->tx_packets - rs_sta->last_tx_packets) + 1; - rs_priv->last_tx_packets = rs_priv->tx_packets + 1; + rs_sta->last_tx_packets = rs_sta->tx_packets + 1; if (unflushed) { duration = - jiffies_to_msecs(jiffies - rs_priv->last_partial_flush); -/* duration = jiffies_to_msecs(rs_priv->flush_time); */ + jiffies_to_msecs(jiffies - rs_sta->last_partial_flush); +/* duration = jiffies_to_msecs(rs_sta->flush_time); */ IWL_DEBUG_RATE("Tx'd %d packets in %dms\n", packet_count, duration); @@ -257,36 +255,36 @@ static void iwl_bg_rate_scale_flush(unsigned long data) } else duration = IWL_RATE_FLUSH_MAX; - rs_priv->flush_time = msecs_to_jiffies(duration); + rs_sta->flush_time = msecs_to_jiffies(duration); IWL_DEBUG_RATE("new flush period: %d msec ave %d\n", duration, packet_count); - mod_timer(&rs_priv->rate_scale_flush, jiffies + - rs_priv->flush_time); + mod_timer(&rs_sta->rate_scale_flush, jiffies + + rs_sta->flush_time); - rs_priv->last_partial_flush = jiffies; + rs_sta->last_partial_flush = jiffies; } /* If there weren't any unflushed entries, we don't schedule the timer * to run again */ - rs_priv->last_flush = jiffies; + rs_sta->last_flush = jiffies; - spin_unlock_irqrestore(&rs_priv->lock, flags); + spin_unlock_irqrestore(&rs_sta->lock, flags); IWL_DEBUG_RATE("leave\n"); } /** - * iwl_collect_tx_data - Update the success/failure sliding window + * iwl3945_collect_tx_data - Update the success/failure sliding window * * We keep a sliding window of the last 64 packets transmitted * at this rate. window->data contains the bitmask of successful * packets. */ -static void iwl_collect_tx_data(struct iwl_rate_scale_priv *rs_priv, - struct iwl_rate_scale_data *window, +static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta, + struct iwl3945_rate_scale_data *window, int success, int retries) { unsigned long flags; @@ -297,7 +295,7 @@ static void iwl_collect_tx_data(struct iwl_rate_scale_priv *rs_priv, } while (retries--) { - spin_lock_irqsave(&rs_priv->lock, flags); + spin_lock_irqsave(&rs_sta->lock, flags); /* If we have filled up the window then subtract one from the * success counter if the high-bit is counting toward @@ -325,7 +323,7 @@ static void iwl_collect_tx_data(struct iwl_rate_scale_priv *rs_priv, /* Tag this window as having been updated */ window->stamp = jiffies; - spin_unlock_irqrestore(&rs_priv->lock, flags); + spin_unlock_irqrestore(&rs_sta->lock, flags); } } @@ -362,7 +360,7 @@ static void *rs_alloc(struct ieee80211_local *local) return local->hw.priv; } -/* rate scale requires free function to be implmented */ +/* rate scale requires free function to be implemented */ static void rs_free(void *priv) { return; @@ -375,49 +373,49 @@ static void rs_clear(void *priv) static void *rs_alloc_sta(void *priv, gfp_t gfp) { - struct iwl_rate_scale_priv *rs_priv; + struct iwl3945_rs_sta *rs_sta; int i; IWL_DEBUG_RATE("enter\n"); - rs_priv = kzalloc(sizeof(struct iwl_rate_scale_priv), gfp); - if (!rs_priv) { + rs_sta = kzalloc(sizeof(struct iwl3945_rs_sta), gfp); + if (!rs_sta) { IWL_DEBUG_RATE("leave: ENOMEM\n"); return NULL; } - spin_lock_init(&rs_priv->lock); + spin_lock_init(&rs_sta->lock); - rs_priv->start_rate = IWL_RATE_INVALID; + rs_sta->start_rate = IWL_RATE_INVALID; /* default to just 802.11b */ - rs_priv->expected_tpt = iwl_expected_tpt_b; + rs_sta->expected_tpt = iwl3945_expected_tpt_b; - rs_priv->last_partial_flush = jiffies; - rs_priv->last_flush = jiffies; - rs_priv->flush_time = IWL_RATE_FLUSH; - rs_priv->last_tx_packets = 0; - rs_priv->ibss_sta_added = 0; + rs_sta->last_partial_flush = jiffies; + rs_sta->last_flush = jiffies; + rs_sta->flush_time = IWL_RATE_FLUSH; + rs_sta->last_tx_packets = 0; + rs_sta->ibss_sta_added = 0; - init_timer(&rs_priv->rate_scale_flush); - rs_priv->rate_scale_flush.data = (unsigned long)rs_priv; - rs_priv->rate_scale_flush.function = &iwl_bg_rate_scale_flush; + init_timer(&rs_sta->rate_scale_flush); + rs_sta->rate_scale_flush.data = (unsigned long)rs_sta; + rs_sta->rate_scale_flush.function = &iwl3945_bg_rate_scale_flush; for (i = 0; i < IWL_RATE_COUNT; i++) - iwl_clear_window(&rs_priv->win[i]); + iwl3945_clear_window(&rs_sta->win[i]); IWL_DEBUG_RATE("leave\n"); - return rs_priv; + return rs_sta; } static void rs_free_sta(void *priv, void *priv_sta) { - struct iwl_rate_scale_priv *rs_priv = priv_sta; + struct iwl3945_rs_sta *rs_sta = priv_sta; IWL_DEBUG_RATE("enter\n"); - del_timer_sync(&rs_priv->rate_scale_flush); - kfree(rs_priv); + del_timer_sync(&rs_sta->rate_scale_flush); + kfree(rs_sta); IWL_DEBUG_RATE("leave\n"); } @@ -427,9 +425,9 @@ static void rs_free_sta(void *priv, void *priv_sta) * for A and B mode we need to overright prev * value */ -static int rs_adjust_next_rate(struct iwl_priv *priv, int rate) +static int rs_adjust_next_rate(struct iwl3945_priv *priv, int rate) { - int next_rate = iwl_get_prev_ieee_rate(rate); + int next_rate = iwl3945_get_prev_ieee_rate(rate); switch (priv->phymode) { case MODE_IEEE80211A: @@ -451,7 +449,7 @@ static int rs_adjust_next_rate(struct iwl_priv *priv, int rate) /** * rs_tx_status - Update rate control values based on Tx results * - * NOTE: Uses iwl_priv->retry_rate for the # of retries attempted by + * NOTE: Uses iwl3945_priv->retry_rate for the # of retries attempted by * the hardware for each rate. */ static void rs_tx_status(void *priv_rate, @@ -464,9 +462,9 @@ static void rs_tx_status(void *priv_rate, unsigned long flags; struct sta_info *sta; struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; - struct iwl_priv *priv = (struct iwl_priv *)priv_rate; + struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate; struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); - struct iwl_rate_scale_priv *rs_priv; + struct iwl3945_rs_sta *rs_sta; IWL_DEBUG_RATE("enter\n"); @@ -487,9 +485,9 @@ static void rs_tx_status(void *priv_rate, return; } - rs_priv = (void *)sta->rate_ctrl_priv; + rs_sta = (void *)sta->rate_ctrl_priv; - rs_priv->tx_packets++; + rs_sta->tx_packets++; scale_rate_index = first_index; last_index = first_index; @@ -516,8 +514,8 @@ static void rs_tx_status(void *priv_rate, /* Update this rate accounting for as many retries * as was used for it (per current_count) */ - iwl_collect_tx_data(rs_priv, - &rs_priv->win[scale_rate_index], + iwl3945_collect_tx_data(rs_sta, + &rs_sta->win[scale_rate_index], 0, current_count); IWL_DEBUG_RATE("Update rate %d for %d retries.\n", scale_rate_index, current_count); @@ -535,25 +533,25 @@ static void rs_tx_status(void *priv_rate, last_index, (tx_resp->flags & IEEE80211_TX_STATUS_ACK) ? "success" : "failure"); - iwl_collect_tx_data(rs_priv, - &rs_priv->win[last_index], + iwl3945_collect_tx_data(rs_sta, + &rs_sta->win[last_index], tx_resp->flags & IEEE80211_TX_STATUS_ACK, 1); /* We updated the rate scale window -- if its been more than * flush_time since the last run, schedule the flush * again */ - spin_lock_irqsave(&rs_priv->lock, flags); + spin_lock_irqsave(&rs_sta->lock, flags); - if (!rs_priv->flush_pending && - time_after(jiffies, rs_priv->last_partial_flush + - rs_priv->flush_time)) { + if (!rs_sta->flush_pending && + time_after(jiffies, rs_sta->last_partial_flush + + rs_sta->flush_time)) { - rs_priv->flush_pending = 1; - mod_timer(&rs_priv->rate_scale_flush, - jiffies + rs_priv->flush_time); + rs_sta->flush_pending = 1; + mod_timer(&rs_sta->rate_scale_flush, + jiffies + rs_sta->flush_time); } - spin_unlock_irqrestore(&rs_priv->lock, flags); + spin_unlock_irqrestore(&rs_sta->lock, flags); sta_info_put(sta); @@ -562,29 +560,13 @@ static void rs_tx_status(void *priv_rate, return; } -static struct ieee80211_rate *iwl_get_lowest_rate(struct ieee80211_local - *local) -{ - struct ieee80211_hw_mode *mode = local->oper_hw_mode; - int i; - - for (i = 0; i < mode->num_rates; i++) { - struct ieee80211_rate *rate = &mode->rates[i]; - - if (rate->flags & IEEE80211_RATE_SUPPORTED) - return rate; - } - - return &mode->rates[0]; -} - -static u16 iwl_get_adjacent_rate(struct iwl_rate_scale_priv *rs_priv, +static u16 iwl3945_get_adjacent_rate(struct iwl3945_rs_sta *rs_sta, u8 index, u16 rate_mask, int phymode) { u8 high = IWL_RATE_INVALID; u8 low = IWL_RATE_INVALID; - /* 802.11A walks to the next literal adjascent rate in + /* 802.11A walks to the next literal adjacent rate in * the rate table */ if (unlikely(phymode == MODE_IEEE80211A)) { int i; @@ -613,10 +595,10 @@ static u16 iwl_get_adjacent_rate(struct iwl_rate_scale_priv *rs_priv, low = index; while (low != IWL_RATE_INVALID) { - if (rs_priv->tgg) - low = iwl_rates[low].prev_rs_tgg; + if (rs_sta->tgg) + low = iwl3945_rates[low].prev_rs_tgg; else - low = iwl_rates[low].prev_rs; + low = iwl3945_rates[low].prev_rs; if (low == IWL_RATE_INVALID) break; if (rate_mask & (1 << low)) @@ -626,10 +608,10 @@ static u16 iwl_get_adjacent_rate(struct iwl_rate_scale_priv *rs_priv, high = index; while (high != IWL_RATE_INVALID) { - if (rs_priv->tgg) - high = iwl_rates[high].next_rs_tgg; + if (rs_sta->tgg) + high = iwl3945_rates[high].next_rs_tgg; else - high = iwl_rates[high].next_rs; + high = iwl3945_rates[high].next_rs; if (high == IWL_RATE_INVALID) break; if (rate_mask & (1 << high)) @@ -656,17 +638,16 @@ static u16 iwl_get_adjacent_rate(struct iwl_rate_scale_priv *rs_priv, * rate table and must reference the driver allocated rate table * */ -static struct ieee80211_rate *rs_get_rate(void *priv_rate, - struct net_device *dev, - struct sk_buff *skb, - struct rate_control_extra *extra) +static void rs_get_rate(void *priv_rate, struct net_device *dev, + struct ieee80211_hw_mode *mode, struct sk_buff *skb, + struct rate_selection *sel) { u8 low = IWL_RATE_INVALID; u8 high = IWL_RATE_INVALID; u16 high_low; int index; - struct iwl_rate_scale_priv *rs_priv; - struct iwl_rate_scale_data *window = NULL; + struct iwl3945_rs_sta *rs_sta; + struct iwl3945_rate_scale_data *window = NULL; int current_tpt = IWL_INVALID_VALUE; int low_tpt = IWL_INVALID_VALUE; int high_tpt = IWL_INVALID_VALUE; @@ -677,31 +658,24 @@ static struct ieee80211_rate *rs_get_rate(void *priv_rate, struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; struct sta_info *sta; u16 fc, rate_mask; - struct iwl_priv *priv = (struct iwl_priv *)priv_rate; + struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate; DECLARE_MAC_BUF(mac); IWL_DEBUG_RATE("enter\n"); - memset(extra, 0, sizeof(*extra)); + sta = sta_info_get(local, hdr->addr1); + /* Send management frames and broadcast/multicast data using lowest + * rate. */ fc = le16_to_cpu(hdr->frame_control); - if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || - (is_multicast_ether_addr(hdr->addr1))) { - /* Send management frames and broadcast/multicast data using - * lowest rate. */ - /* TODO: this could probably be improved.. */ - IWL_DEBUG_RATE("leave: lowest rate (not data or is " - "multicast)\n"); - - return iwl_get_lowest_rate(local); - } - - sta = sta_info_get(local, hdr->addr1); - if (!sta || !sta->rate_ctrl_priv) { + if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || + is_multicast_ether_addr(hdr->addr1) || + !sta || !sta->rate_ctrl_priv) { IWL_DEBUG_RATE("leave: No STA priv data to update!\n"); + sel->rate = rate_lowest(local, local->oper_hw_mode, sta); if (sta) sta_info_put(sta); - return NULL; + return; } rate_mask = sta->supp_rates; @@ -710,37 +684,37 @@ static struct ieee80211_rate *rs_get_rate(void *priv_rate, if (priv->phymode == (u8) MODE_IEEE80211A) rate_mask = rate_mask << IWL_FIRST_OFDM_RATE; - rs_priv = (void *)sta->rate_ctrl_priv; + rs_sta = (void *)sta->rate_ctrl_priv; if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && - !rs_priv->ibss_sta_added) { - u8 sta_id = iwl_hw_find_station(priv, hdr->addr1); + !rs_sta->ibss_sta_added) { + u8 sta_id = iwl3945_hw_find_station(priv, hdr->addr1); if (sta_id == IWL_INVALID_STATION) { IWL_DEBUG_RATE("LQ: ADD station %s\n", print_mac(mac, hdr->addr1)); - sta_id = iwl_add_station(priv, + sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC); } if (sta_id != IWL_INVALID_STATION) - rs_priv->ibss_sta_added = 1; + rs_sta->ibss_sta_added = 1; } - spin_lock_irqsave(&rs_priv->lock, flags); + spin_lock_irqsave(&rs_sta->lock, flags); - if (rs_priv->start_rate != IWL_RATE_INVALID) { - index = rs_priv->start_rate; - rs_priv->start_rate = IWL_RATE_INVALID; + if (rs_sta->start_rate != IWL_RATE_INVALID) { + index = rs_sta->start_rate; + rs_sta->start_rate = IWL_RATE_INVALID; } - window = &(rs_priv->win[index]); + window = &(rs_sta->win[index]); fail_count = window->counter - window->success_counter; if (((fail_count <= IWL_RATE_MIN_FAILURE_TH) && (window->success_counter < IWL_RATE_MIN_SUCCESS_TH))) { window->average_tpt = IWL_INVALID_VALUE; - spin_unlock_irqrestore(&rs_priv->lock, flags); + spin_unlock_irqrestore(&rs_sta->lock, flags); IWL_DEBUG_RATE("Invalid average_tpt on rate %d: " "counter: %d, success_counter: %d, " @@ -748,27 +722,27 @@ static struct ieee80211_rate *rs_get_rate(void *priv_rate, index, window->counter, window->success_counter, - rs_priv->expected_tpt ? "not " : ""); + rs_sta->expected_tpt ? "not " : ""); goto out; } window->average_tpt = ((window->success_ratio * - rs_priv->expected_tpt[index] + 64) / 128); + rs_sta->expected_tpt[index] + 64) / 128); current_tpt = window->average_tpt; - high_low = iwl_get_adjacent_rate(rs_priv, index, rate_mask, + high_low = iwl3945_get_adjacent_rate(rs_sta, index, rate_mask, local->hw.conf.phymode); low = high_low & 0xff; high = (high_low >> 8) & 0xff; if (low != IWL_RATE_INVALID) - low_tpt = rs_priv->win[low].average_tpt; + low_tpt = rs_sta->win[low].average_tpt; if (high != IWL_RATE_INVALID) - high_tpt = rs_priv->win[high].average_tpt; + high_tpt = rs_sta->win[high].average_tpt; - spin_unlock_irqrestore(&rs_priv->lock, flags); + spin_unlock_irqrestore(&rs_sta->lock, flags); scale_action = 1; @@ -846,7 +820,7 @@ static struct ieee80211_rate *rs_get_rate(void *priv_rate, IWL_DEBUG_RATE("leave: %d\n", index); - return &priv->ieee_rates[index]; + sel->rate = &priv->ieee_rates[index]; } static struct rate_control_ops rs_ops = { @@ -862,11 +836,11 @@ static struct rate_control_ops rs_ops = { .free_sta = rs_free_sta, }; -int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) +int iwl3945_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) { struct ieee80211_local *local = hw_to_local(hw); - struct iwl_priv *priv = hw->priv; - struct iwl_rate_scale_priv *rs_priv; + struct iwl3945_priv *priv = hw->priv; + struct iwl3945_rs_sta *rs_sta; struct sta_info *sta; unsigned long flags; int count = 0, i; @@ -884,28 +858,29 @@ int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) return sprintf(buf, "station %d not found\n", sta_id); } - rs_priv = (void *)sta->rate_ctrl_priv; - spin_lock_irqsave(&rs_priv->lock, flags); + rs_sta = (void *)sta->rate_ctrl_priv; + spin_lock_irqsave(&rs_sta->lock, flags); i = IWL_RATE_54M_INDEX; while (1) { u64 mask; int j; count += - sprintf(&buf[count], " %2dMbs: ", iwl_rates[i].ieee / 2); + sprintf(&buf[count], " %2dMbs: ", iwl3945_rates[i].ieee / 2); mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1)); for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1) buf[count++] = - (rs_priv->win[i].data & mask) ? '1' : '0'; + (rs_sta->win[i].data & mask) ? '1' : '0'; - samples += rs_priv->win[i].counter; - good += rs_priv->win[i].success_counter; - success += rs_priv->win[i].success_counter * iwl_rates[i].ieee; + samples += rs_sta->win[i].counter; + good += rs_sta->win[i].success_counter; + success += rs_sta->win[i].success_counter * + iwl3945_rates[i].ieee; - if (rs_priv->win[i].stamp) { + if (rs_sta->win[i].stamp) { int delta = - jiffies_to_msecs(now - rs_priv->win[i].stamp); + jiffies_to_msecs(now - rs_sta->win[i].stamp); if (delta > max_time) max_time = delta; @@ -914,18 +889,18 @@ int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) } else buf[count++] = '\n'; - j = iwl_get_prev_ieee_rate(i); + j = iwl3945_get_prev_ieee_rate(i); if (j == i) break; i = j; } - spin_unlock_irqrestore(&rs_priv->lock, flags); + spin_unlock_irqrestore(&rs_sta->lock, flags); sta_info_put(sta); /* Display the average rate of all samples taken. * * NOTE: We multiple # of samples by 2 since the IEEE measurement - * added from iwl_rates is actually 2X the rate */ + * added from iwl3945_rates is actually 2X the rate */ if (samples) count += sprintf( &buf[count], @@ -939,13 +914,13 @@ int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) return count; } -void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) +void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; s32 rssi = 0; unsigned long flags; struct ieee80211_local *local = hw_to_local(hw); - struct iwl_rate_scale_priv *rs_priv; + struct iwl3945_rs_sta *rs_sta; struct sta_info *sta; IWL_DEBUG_RATE("enter\n"); @@ -965,33 +940,33 @@ void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) return; } - rs_priv = (void *)sta->rate_ctrl_priv; + rs_sta = (void *)sta->rate_ctrl_priv; - spin_lock_irqsave(&rs_priv->lock, flags); + spin_lock_irqsave(&rs_sta->lock, flags); - rs_priv->tgg = 0; + rs_sta->tgg = 0; switch (priv->phymode) { case MODE_IEEE80211G: if (priv->active_rxon.flags & RXON_FLG_TGG_PROTECT_MSK) { - rs_priv->tgg = 1; - rs_priv->expected_tpt = iwl_expected_tpt_g_prot; + rs_sta->tgg = 1; + rs_sta->expected_tpt = iwl3945_expected_tpt_g_prot; } else - rs_priv->expected_tpt = iwl_expected_tpt_g; + rs_sta->expected_tpt = iwl3945_expected_tpt_g; break; case MODE_IEEE80211A: - rs_priv->expected_tpt = iwl_expected_tpt_a; + rs_sta->expected_tpt = iwl3945_expected_tpt_a; break; default: IWL_WARNING("Invalid phymode. Defaulting to 802.11b\n"); case MODE_IEEE80211B: - rs_priv->expected_tpt = iwl_expected_tpt_b; + rs_sta->expected_tpt = iwl3945_expected_tpt_b; break; } sta_info_put(sta); - spin_unlock_irqrestore(&rs_priv->lock, flags); + spin_unlock_irqrestore(&rs_sta->lock, flags); rssi = priv->last_rx_rssi; if (rssi == 0) @@ -999,19 +974,20 @@ void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) IWL_DEBUG(IWL_DL_INFO | IWL_DL_RATE, "Network RSSI: %d\n", rssi); - rs_priv->start_rate = iwl_get_rate_index_by_rssi(rssi, priv->phymode); + rs_sta->start_rate = + iwl3945_get_rate_index_by_rssi(rssi, priv->phymode); IWL_DEBUG_RATE("leave: rssi %d assign rate index: " - "%d (plcp 0x%x)\n", rssi, rs_priv->start_rate, - iwl_rates[rs_priv->start_rate].plcp); + "%d (plcp 0x%x)\n", rssi, rs_sta->start_rate, + iwl3945_rates[rs_sta->start_rate].plcp); } -void iwl_rate_control_register(struct ieee80211_hw *hw) +void iwl3945_rate_control_register(struct ieee80211_hw *hw) { ieee80211_rate_control_register(&rs_ops); } -void iwl_rate_control_unregister(struct ieee80211_hw *hw) +void iwl3945_rate_control_unregister(struct ieee80211_hw *hw) { ieee80211_rate_control_unregister(&rs_ops); } diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.h b/drivers/net/wireless/iwlwifi/iwl-3945-rs.h index bec4d3ffca1..d5e9220f871 100644 --- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.h +++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.h @@ -27,9 +27,9 @@ #ifndef __iwl_3945_rs_h__ #define __iwl_3945_rs_h__ -struct iwl_rate_info { - u8 plcp; - u8 ieee; +struct iwl3945_rate_info { + u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */ + u8 ieee; /* MAC header: IWL_RATE_6M_IEEE, etc. */ u8 prev_ieee; /* previous rate in IEEE speeds */ u8 next_ieee; /* next rate in IEEE speeds */ u8 prev_rs; /* previous rate used in rs algo */ @@ -38,9 +38,12 @@ struct iwl_rate_info { u8 next_rs_tgg; /* next rate used in TGG rs algo */ u8 table_rs_index; /* index in rate scale table cmd */ u8 prev_table_rs; /* prev in rate table cmd */ - }; +/* + * These serve as indexes into + * struct iwl3945_rate_info iwl3945_rates[IWL_RATE_COUNT]; + */ enum { IWL_RATE_1M_INDEX = 0, IWL_RATE_2M_INDEX, @@ -83,19 +86,20 @@ enum { }; /* #define vs. enum to keep from defaulting to 'large integer' */ -#define IWL_RATE_6M_MASK (1<<IWL_RATE_6M_INDEX) -#define IWL_RATE_9M_MASK (1<<IWL_RATE_9M_INDEX) -#define IWL_RATE_12M_MASK (1<<IWL_RATE_12M_INDEX) -#define IWL_RATE_18M_MASK (1<<IWL_RATE_18M_INDEX) -#define IWL_RATE_24M_MASK (1<<IWL_RATE_24M_INDEX) -#define IWL_RATE_36M_MASK (1<<IWL_RATE_36M_INDEX) -#define IWL_RATE_48M_MASK (1<<IWL_RATE_48M_INDEX) -#define IWL_RATE_54M_MASK (1<<IWL_RATE_54M_INDEX) -#define IWL_RATE_1M_MASK (1<<IWL_RATE_1M_INDEX) -#define IWL_RATE_2M_MASK (1<<IWL_RATE_2M_INDEX) -#define IWL_RATE_5M_MASK (1<<IWL_RATE_5M_INDEX) -#define IWL_RATE_11M_MASK (1<<IWL_RATE_11M_INDEX) - +#define IWL_RATE_6M_MASK (1 << IWL_RATE_6M_INDEX) +#define IWL_RATE_9M_MASK (1 << IWL_RATE_9M_INDEX) +#define IWL_RATE_12M_MASK (1 << IWL_RATE_12M_INDEX) +#define IWL_RATE_18M_MASK (1 << IWL_RATE_18M_INDEX) +#define IWL_RATE_24M_MASK (1 << IWL_RATE_24M_INDEX) +#define IWL_RATE_36M_MASK (1 << IWL_RATE_36M_INDEX) +#define IWL_RATE_48M_MASK (1 << IWL_RATE_48M_INDEX) +#define IWL_RATE_54M_MASK (1 << IWL_RATE_54M_INDEX) +#define IWL_RATE_1M_MASK (1 << IWL_RATE_1M_INDEX) +#define IWL_RATE_2M_MASK (1 << IWL_RATE_2M_INDEX) +#define IWL_RATE_5M_MASK (1 << IWL_RATE_5M_INDEX) +#define IWL_RATE_11M_MASK (1 << IWL_RATE_11M_INDEX) + +/* 3945 uCode API values for (legacy) bit rates, both OFDM and CCK */ enum { IWL_RATE_6M_PLCP = 13, IWL_RATE_9M_PLCP = 15, @@ -111,6 +115,7 @@ enum { IWL_RATE_11M_PLCP = 110, }; +/* MAC header values for bit rates */ enum { IWL_RATE_6M_IEEE = 12, IWL_RATE_9M_IEEE = 18, @@ -152,18 +157,18 @@ enum { (IWL_OFDM_BASIC_RATES_MASK | \ IWL_CCK_BASIC_RATES_MASK) -#define IWL_RATES_MASK ((1<<IWL_RATE_COUNT)-1) +#define IWL_RATES_MASK ((1 << IWL_RATE_COUNT) - 1) #define IWL_INVALID_VALUE -1 #define IWL_MIN_RSSI_VAL -100 #define IWL_MAX_RSSI_VAL 0 -extern const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT]; +extern const struct iwl3945_rate_info iwl3945_rates[IWL_RATE_COUNT]; -static inline u8 iwl_get_prev_ieee_rate(u8 rate_index) +static inline u8 iwl3945_get_prev_ieee_rate(u8 rate_index) { - u8 rate = iwl_rates[rate_index].prev_ieee; + u8 rate = iwl3945_rates[rate_index].prev_ieee; if (rate == IWL_RATE_INVALID) rate = rate_index; @@ -171,40 +176,40 @@ static inline u8 iwl_get_prev_ieee_rate(u8 rate_index) } /** - * iwl_fill_rs_info - Fill an output text buffer with the rate representation + * iwl3945_fill_rs_info - Fill an output text buffer with the rate representation * * NOTE: This is provided as a quick mechanism for a user to visualize - * the performance of the rate control alogirthm and is not meant to be + * the performance of the rate control algorithm and is not meant to be * parsed software. */ -extern int iwl_fill_rs_info(struct ieee80211_hw *, char *buf, u8 sta_id); +extern int iwl3945_fill_rs_info(struct ieee80211_hw *, char *buf, u8 sta_id); /** - * iwl_rate_scale_init - Initialize the rate scale table based on assoc info + * iwl3945_rate_scale_init - Initialize the rate scale table based on assoc info * - * The specific througput table used is based on the type of network + * The specific throughput table used is based on the type of network * the associated with, including A, B, G, and G w/ TGG protection */ -extern void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id); +extern void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id); /** - * iwl_rate_control_register - Register the rate control algorithm callbacks + * iwl3945_rate_control_register - Register the rate control algorithm callbacks * * Since the rate control algorithm is hardware specific, there is no need * or reason to place it as a stand alone module. The driver can call - * iwl_rate_control_register in order to register the rate control callbacks + * iwl3945_rate_control_register in order to register the rate control callbacks * with the mac80211 subsystem. This should be performed prior to calling * ieee80211_register_hw * */ -extern void iwl_rate_control_register(struct ieee80211_hw *hw); +extern void iwl3945_rate_control_register(struct ieee80211_hw *hw); /** - * iwl_rate_control_unregister - Unregister the rate control callbacks + * iwl3945_rate_control_unregister - Unregister the rate control callbacks * * This should be called after calling ieee80211_unregister_hw, but before * the driver is unloaded. */ -extern void iwl_rate_control_unregister(struct ieee80211_hw *hw); +extern void iwl3945_rate_control_unregister(struct ieee80211_hw *hw); #endif diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c index 3a45fe99a83..76c4ed1135f 100644 --- a/drivers/net/wireless/iwlwifi/iwl-3945.c +++ b/drivers/net/wireless/iwlwifi/iwl-3945.c @@ -35,15 +35,12 @@ #include <linux/netdevice.h> #include <linux/wireless.h> #include <linux/firmware.h> -#include <net/mac80211.h> - #include <linux/etherdevice.h> +#include <asm/unaligned.h> +#include <net/mac80211.h> -#define IWL 3945 - -#include "iwlwifi.h" -#include "iwl-helpers.h" #include "iwl-3945.h" +#include "iwl-helpers.h" #include "iwl-3945-rs.h" #define IWL_DECLARE_RATE_INFO(r, ip, in, rp, rn, pp, np) \ @@ -66,7 +63,7 @@ * maps to IWL_RATE_INVALID * */ -const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = { +const struct iwl3945_rate_info iwl3945_rates[IWL_RATE_COUNT] = { IWL_DECLARE_RATE_INFO(1, INV, 2, INV, 2, INV, 2), /* 1mbps */ IWL_DECLARE_RATE_INFO(2, 1, 5, 1, 5, 1, 5), /* 2mbps */ IWL_DECLARE_RATE_INFO(5, 2, 6, 2, 11, 2, 11), /*5.5mbps */ @@ -81,12 +78,12 @@ const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = { IWL_DECLARE_RATE_INFO(54, 48, INV, 48, INV, 48, INV),/* 54mbps */ }; -/* 1 = enable the iwl_disable_events() function */ +/* 1 = enable the iwl3945_disable_events() function */ #define IWL_EVT_DISABLE (0) #define IWL_EVT_DISABLE_SIZE (1532/32) /** - * iwl_disable_events - Disable selected events in uCode event log + * iwl3945_disable_events - Disable selected events in uCode event log * * Disable an event by writing "1"s into "disable" * bitmap in SRAM. Bit position corresponds to Event # (id/type). @@ -94,9 +91,9 @@ const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = { * Use for only special debugging. This function is just a placeholder as-is, * you'll need to provide the special bits! ... * ... and set IWL_EVT_DISABLE to 1. */ -void iwl_disable_events(struct iwl_priv *priv) +void iwl3945_disable_events(struct iwl3945_priv *priv) { - int rc; + int ret; int i; u32 base; /* SRAM address of event log header */ u32 disable_ptr; /* SRAM address of event-disable bitmap array */ @@ -152,32 +149,31 @@ void iwl_disable_events(struct iwl_priv *priv) }; base = le32_to_cpu(priv->card_alive.log_event_table_ptr); - if (!iwl_hw_valid_rtc_data_addr(base)) { + if (!iwl3945_hw_valid_rtc_data_addr(base)) { IWL_ERROR("Invalid event log pointer 0x%08X\n", base); return; } - rc = iwl_grab_restricted_access(priv); - if (rc) { + ret = iwl3945_grab_nic_access(priv); + if (ret) { IWL_WARNING("Can not read from adapter at this time.\n"); return; } - disable_ptr = iwl_read_restricted_mem(priv, base + (4 * sizeof(u32))); - array_size = iwl_read_restricted_mem(priv, base + (5 * sizeof(u32))); - iwl_release_restricted_access(priv); + disable_ptr = iwl3945_read_targ_mem(priv, base + (4 * sizeof(u32))); + array_size = iwl3945_read_targ_mem(priv, base + (5 * sizeof(u32))); + iwl3945_release_nic_access(priv); if (IWL_EVT_DISABLE && (array_size == IWL_EVT_DISABLE_SIZE)) { IWL_DEBUG_INFO("Disabling selected uCode log events at 0x%x\n", disable_ptr); - rc = iwl_grab_restricted_access(priv); + ret = iwl3945_grab_nic_access(priv); for (i = 0; i < IWL_EVT_DISABLE_SIZE; i++) - iwl_write_restricted_mem(priv, - disable_ptr + - (i * sizeof(u32)), - evt_disable[i]); + iwl3945_write_targ_mem(priv, + disable_ptr + (i * sizeof(u32)), + evt_disable[i]); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); } else { IWL_DEBUG_INFO("Selected uCode log events may be disabled\n"); IWL_DEBUG_INFO(" by writing \"1\"s into disable bitmap\n"); @@ -198,7 +194,7 @@ void iwl_disable_events(struct iwl_priv *priv) * IWL_ANTENNA_MAIN - Force MAIN antenna * IWL_ANTENNA_AUX - Force AUX antenna */ -__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv) +__le32 iwl3945_get_antenna_flags(const struct iwl3945_priv *priv) { switch (priv->antenna) { case IWL_ANTENNA_DIVERSITY: @@ -230,11 +226,11 @@ __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv) * *****************************************************************************/ -void iwl_hw_rx_statistics(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) +void iwl3945_hw_rx_statistics(struct iwl3945_priv *priv, struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n", - (int)sizeof(struct iwl_notif_statistics), + (int)sizeof(struct iwl3945_notif_statistics), le32_to_cpu(pkt->len)); memcpy(&priv->statistics, pkt->u.raw, sizeof(priv->statistics)); @@ -242,15 +238,107 @@ void iwl_hw_rx_statistics(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) priv->last_statistics_time = jiffies; } -static void iwl3945_handle_data_packet(struct iwl_priv *priv, int is_data, - struct iwl_rx_mem_buffer *rxb, - struct ieee80211_rx_status *stats, - u16 phy_flags) +void iwl3945_add_radiotap(struct iwl3945_priv *priv, struct sk_buff *skb, + struct iwl3945_rx_frame_hdr *rx_hdr, + struct ieee80211_rx_status *stats) +{ + /* First cache any information we need before we overwrite + * the information provided in the skb from the hardware */ + s8 signal = stats->ssi; + s8 noise = 0; + int rate = stats->rate; + u64 tsf = stats->mactime; + __le16 phy_flags_hw = rx_hdr->phy_flags; + + struct iwl3945_rt_rx_hdr { + struct ieee80211_radiotap_header rt_hdr; + __le64 rt_tsf; /* TSF */ + u8 rt_flags; /* radiotap packet flags */ + u8 rt_rate; /* rate in 500kb/s */ + __le16 rt_channelMHz; /* channel in MHz */ + __le16 rt_chbitmask; /* channel bitfield */ + s8 rt_dbmsignal; /* signal in dBm, kluged to signed */ + s8 rt_dbmnoise; + u8 rt_antenna; /* antenna number */ + } __attribute__ ((packed)) *iwl3945_rt; + + if (skb_headroom(skb) < sizeof(*iwl3945_rt)) { + if (net_ratelimit()) + printk(KERN_ERR "not enough headroom [%d] for " + "radiotap head [%zd]\n", + skb_headroom(skb), sizeof(*iwl3945_rt)); + return; + } + + /* put radiotap header in front of 802.11 header and data */ + iwl3945_rt = (void *)skb_push(skb, sizeof(*iwl3945_rt)); + + /* initialise radiotap header */ + iwl3945_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; + iwl3945_rt->rt_hdr.it_pad = 0; + + /* total header + data */ + put_unaligned(cpu_to_le16(sizeof(*iwl3945_rt)), + &iwl3945_rt->rt_hdr.it_len); + + /* Indicate all the fields we add to the radiotap header */ + put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) | + (1 << IEEE80211_RADIOTAP_FLAGS) | + (1 << IEEE80211_RADIOTAP_RATE) | + (1 << IEEE80211_RADIOTAP_CHANNEL) | + (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | + (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | + (1 << IEEE80211_RADIOTAP_ANTENNA)), + &iwl3945_rt->rt_hdr.it_present); + + /* Zero the flags, we'll add to them as we go */ + iwl3945_rt->rt_flags = 0; + + put_unaligned(cpu_to_le64(tsf), &iwl3945_rt->rt_tsf); + + iwl3945_rt->rt_dbmsignal = signal; + iwl3945_rt->rt_dbmnoise = noise; + + /* Convert the channel frequency and set the flags */ + put_unaligned(cpu_to_le16(stats->freq), &iwl3945_rt->rt_channelMHz); + if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK)) + put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM | + IEEE80211_CHAN_5GHZ), + &iwl3945_rt->rt_chbitmask); + else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK) + put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK | + IEEE80211_CHAN_2GHZ), + &iwl3945_rt->rt_chbitmask); + else /* 802.11g */ + put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM | + IEEE80211_CHAN_2GHZ), + &iwl3945_rt->rt_chbitmask); + + rate = iwl3945_rate_index_from_plcp(rate); + if (rate == -1) + iwl3945_rt->rt_rate = 0; + else + iwl3945_rt->rt_rate = iwl3945_rates[rate].ieee; + + /* antenna number */ + iwl3945_rt->rt_antenna = + le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4; + + /* set the preamble flag if we have it */ + if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) + iwl3945_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; + + stats->flag |= RX_FLAG_RADIOTAP; +} + +static void iwl3945_handle_data_packet(struct iwl3945_priv *priv, int is_data, + struct iwl3945_rx_mem_buffer *rxb, + struct ieee80211_rx_status *stats) { struct ieee80211_hdr *hdr; - struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; - struct iwl_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); - struct iwl_rx_frame_end *rx_end = IWL_RX_END(pkt); + struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data; + struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); + struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt); short len = le16_to_cpu(rx_hdr->len); /* We received data from the HW, so stop the watchdog */ @@ -265,15 +353,6 @@ static void iwl3945_handle_data_packet(struct iwl_priv *priv, int is_data, ("Dropping packet while interface is not open.\n"); return; } - if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { - if (iwl_param_hwcrypto) - iwl_set_decrypted_flag(priv, rxb->skb, - le32_to_cpu(rx_end->status), - stats); - iwl_handle_data_packet_monitor(priv, rxb, IWL_RX_DATA(pkt), - len, stats, phy_flags); - return; - } skb_reserve(rxb->skb, (void *)rx_hdr->payload - (void *)pkt); /* Set the size of the skb to the size of the frame */ @@ -281,23 +360,27 @@ static void iwl3945_handle_data_packet(struct iwl_priv *priv, int is_data, hdr = (void *)rxb->skb->data; - if (iwl_param_hwcrypto) - iwl_set_decrypted_flag(priv, rxb->skb, + if (iwl3945_param_hwcrypto) + iwl3945_set_decrypted_flag(priv, rxb->skb, le32_to_cpu(rx_end->status), stats); + if (priv->add_radiotap) + iwl3945_add_radiotap(priv, rxb->skb, rx_hdr, stats); + ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); rxb->skb = NULL; } -static void iwl3945_rx_reply_rx(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) + +static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); - struct iwl_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); - struct iwl_rx_frame_end *rx_end = IWL_RX_END(pkt); + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); + struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); + struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt); struct ieee80211_hdr *header; - u16 phy_flags = le16_to_cpu(rx_hdr->phy_flags); u16 rx_stats_sig_avg = le16_to_cpu(rx_stats->sig_avg); u16 rx_stats_noise_diff = le16_to_cpu(rx_stats->noise_diff); struct ieee80211_rx_status stats = { @@ -327,7 +410,7 @@ static void iwl3945_rx_reply_rx(struct iwl_priv *priv, } if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { - iwl3945_handle_data_packet(priv, 1, rxb, &stats, phy_flags); + iwl3945_handle_data_packet(priv, 1, rxb, &stats); return; } @@ -351,14 +434,14 @@ static void iwl3945_rx_reply_rx(struct iwl_priv *priv, * Calculate stats.signal (quality indicator in %) based on SNR. */ if (rx_stats_noise_diff) { snr = rx_stats_sig_avg / rx_stats_noise_diff; - stats.noise = stats.ssi - iwl_calc_db_from_ratio(snr); - stats.signal = iwl_calc_sig_qual(stats.ssi, stats.noise); + stats.noise = stats.ssi - iwl3945_calc_db_from_ratio(snr); + stats.signal = iwl3945_calc_sig_qual(stats.ssi, stats.noise); /* If noise info not available, calculate signal quality indicator (%) * using just the dBm signal level. */ } else { stats.noise = priv->last_rx_noise; - stats.signal = iwl_calc_sig_qual(stats.ssi, 0); + stats.signal = iwl3945_calc_sig_qual(stats.ssi, 0); } @@ -368,24 +451,24 @@ static void iwl3945_rx_reply_rx(struct iwl_priv *priv, stats.freq = ieee80211chan2mhz(stats.channel); - /* can be covered by iwl_report_frame() in most cases */ + /* can be covered by iwl3945_report_frame() in most cases */ /* IWL_DEBUG_RX("RX status: 0x%08X\n", rx_end->status); */ header = (struct ieee80211_hdr *)IWL_RX_DATA(pkt); - network_packet = iwl_is_network_packet(priv, header); + network_packet = iwl3945_is_network_packet(priv, header); -#ifdef CONFIG_IWLWIFI_DEBUG - if (iwl_debug_level & IWL_DL_STATS && net_ratelimit()) +#ifdef CONFIG_IWL3945_DEBUG + if (iwl3945_debug_level & IWL_DL_STATS && net_ratelimit()) IWL_DEBUG_STATS ("[%c] %d RSSI: %d Signal: %u, Noise: %u, Rate: %u\n", network_packet ? '*' : ' ', stats.channel, stats.ssi, stats.ssi, stats.ssi, stats.rate); - if (iwl_debug_level & (IWL_DL_RX)) + if (iwl3945_debug_level & (IWL_DL_RX)) /* Set "1" to report good data frames in groups of 100 */ - iwl_report_frame(priv, pkt, header, 1); + iwl3945_report_frame(priv, pkt, header, 1); #endif if (network_packet) { @@ -437,15 +520,20 @@ static void iwl3945_rx_reply_rx(struct iwl_priv *priv, break; /* - * TODO: There is no callback function from upper - * stack to inform us when associated status. this - * work around to sniff assoc_resp management frame - * and finish the association process. + * TODO: Use the new callback function from + * mac80211 instead of sniffing these packets. */ case IEEE80211_STYPE_ASSOC_RESP: case IEEE80211_STYPE_REASSOC_RESP:{ struct ieee80211_mgmt *mgnt = (struct ieee80211_mgmt *)header; + + /* We have just associated, give some + * time for the 4-way handshake if + * any. Don't start scan too early. */ + priv->next_scan_jiffies = jiffies + + IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; + priv->assoc_id = (~((1 << 15) | (1 << 14)) & le16_to_cpu(mgnt->u. assoc_resp.aid)); @@ -474,7 +562,7 @@ static void iwl3945_rx_reply_rx(struct iwl_priv *priv, } } - iwl3945_handle_data_packet(priv, 0, rxb, &stats, phy_flags); + iwl3945_handle_data_packet(priv, 0, rxb, &stats); break; case IEEE80211_FTYPE_CTL: @@ -485,25 +573,24 @@ static void iwl3945_rx_reply_rx(struct iwl_priv *priv, DECLARE_MAC_BUF(mac2); DECLARE_MAC_BUF(mac3); - if (unlikely(is_duplicate_packet(priv, header))) + if (unlikely(iwl3945_is_duplicate_packet(priv, header))) IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n", print_mac(mac1, header->addr1), print_mac(mac2, header->addr2), print_mac(mac3, header->addr3)); else - iwl3945_handle_data_packet(priv, 1, rxb, &stats, - phy_flags); + iwl3945_handle_data_packet(priv, 1, rxb, &stats); break; } } } -int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr, +int iwl3945_hw_txq_attach_buf_to_tfd(struct iwl3945_priv *priv, void *ptr, dma_addr_t addr, u16 len) { int count; u32 pad; - struct iwl_tfd_frame *tfd = (struct iwl_tfd_frame *)ptr; + struct iwl3945_tfd_frame *tfd = (struct iwl3945_tfd_frame *)ptr; count = TFD_CTL_COUNT_GET(le32_to_cpu(tfd->control_flags)); pad = TFD_CTL_PAD_GET(le32_to_cpu(tfd->control_flags)); @@ -526,14 +613,14 @@ int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr, } /** - * iwl_hw_txq_free_tfd - Free one TFD, those at index [txq->q.last_used] + * iwl3945_hw_txq_free_tfd - Free one TFD, those at index [txq->q.read_ptr] * * Does NOT advance any indexes */ -int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq) +int iwl3945_hw_txq_free_tfd(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq) { - struct iwl_tfd_frame *bd_tmp = (struct iwl_tfd_frame *)&txq->bd[0]; - struct iwl_tfd_frame *bd = &bd_tmp[txq->q.last_used]; + struct iwl3945_tfd_frame *bd_tmp = (struct iwl3945_tfd_frame *)&txq->bd[0]; + struct iwl3945_tfd_frame *bd = &bd_tmp[txq->q.read_ptr]; struct pci_dev *dev = priv->pci_dev; int i; int counter; @@ -556,19 +643,19 @@ int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq) for (i = 1; i < counter; i++) { pci_unmap_single(dev, le32_to_cpu(bd->pa[i].addr), le32_to_cpu(bd->pa[i].len), PCI_DMA_TODEVICE); - if (txq->txb[txq->q.last_used].skb[0]) { - struct sk_buff *skb = txq->txb[txq->q.last_used].skb[0]; - if (txq->txb[txq->q.last_used].skb[0]) { + if (txq->txb[txq->q.read_ptr].skb[0]) { + struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[0]; + if (txq->txb[txq->q.read_ptr].skb[0]) { /* Can be called from interrupt context */ dev_kfree_skb_any(skb); - txq->txb[txq->q.last_used].skb[0] = NULL; + txq->txb[txq->q.read_ptr].skb[0] = NULL; } } } return 0; } -u8 iwl_hw_find_station(struct iwl_priv *priv, const u8 *addr) +u8 iwl3945_hw_find_station(struct iwl3945_priv *priv, const u8 *addr) { int i; int ret = IWL_INVALID_STATION; @@ -592,11 +679,11 @@ u8 iwl_hw_find_station(struct iwl_priv *priv, const u8 *addr) } /** - * iwl_hw_build_tx_cmd_rate - Add rate portion to TX_CMD: + * iwl3945_hw_build_tx_cmd_rate - Add rate portion to TX_CMD: * */ -void iwl_hw_build_tx_cmd_rate(struct iwl_priv *priv, - struct iwl_cmd *cmd, +void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv, + struct iwl3945_cmd *cmd, struct ieee80211_tx_control *ctrl, struct ieee80211_hdr *hdr, int sta_id, int tx_id) { @@ -609,7 +696,7 @@ void iwl_hw_build_tx_cmd_rate(struct iwl_priv *priv, __le32 tx_flags; u16 fc = le16_to_cpu(hdr->frame_control); - rate = iwl_rates[rate_index].plcp; + rate = iwl3945_rates[rate_index].plcp; tx_flags = cmd->cmd.tx.tx_flags; /* We need to figure out how to get the sta->supp_rates while @@ -676,10 +763,10 @@ void iwl_hw_build_tx_cmd_rate(struct iwl_priv *priv, cmd->cmd.tx.supp_rates[1], cmd->cmd.tx.supp_rates[0]); } -u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id, u16 tx_rate, u8 flags) +u8 iwl3945_sync_sta(struct iwl3945_priv *priv, int sta_id, u16 tx_rate, u8 flags) { unsigned long flags_spin; - struct iwl_station_entry *station; + struct iwl3945_station_entry *station; if (sta_id == IWL_INVALID_STATION) return IWL_INVALID_STATION; @@ -694,34 +781,19 @@ u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id, u16 tx_rate, u8 flags) spin_unlock_irqrestore(&priv->sta_lock, flags_spin); - iwl_send_add_station(priv, &station->sta, flags); + iwl3945_send_add_station(priv, &station->sta, flags); IWL_DEBUG_RATE("SCALE sync station %d to rate %d\n", sta_id, tx_rate); return sta_id; } -void iwl_hw_card_show_info(struct iwl_priv *priv) -{ - IWL_DEBUG_INFO("3945ABG HW Version %u.%u.%u\n", - ((priv->eeprom.board_revision >> 8) & 0x0F), - ((priv->eeprom.board_revision >> 8) >> 4), - (priv->eeprom.board_revision & 0x00FF)); - - IWL_DEBUG_INFO("3945ABG PBA Number %.*s\n", - (int)sizeof(priv->eeprom.board_pba_number), - priv->eeprom.board_pba_number); - - IWL_DEBUG_INFO("EEPROM_ANTENNA_SWITCH_TYPE is 0x%02X\n", - priv->eeprom.antenna_switch_type); -} - -static int iwl3945_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max) +static int iwl3945_nic_set_pwr_src(struct iwl3945_priv *priv, int pwr_max) { int rc; unsigned long flags; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; @@ -733,23 +805,23 @@ static int iwl3945_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max) rc = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE, &val); if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) { - iwl_set_bits_mask_restricted_reg(priv, APMG_PS_CTRL_REG, + iwl3945_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_PWR_SRC_VAUX, ~APMG_PS_CTRL_MSK_PWR_SRC); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); - iwl_poll_bit(priv, CSR_GPIO_IN, + iwl3945_poll_bit(priv, CSR_GPIO_IN, CSR_GPIO_IN_VAL_VAUX_PWR_SRC, CSR_GPIO_IN_BIT_AUX_POWER, 5000); } else - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); } else { - iwl_set_bits_mask_restricted_reg(priv, APMG_PS_CTRL_REG, + iwl3945_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_PWR_SRC_VMAIN, ~APMG_PS_CTRL_MSK_PWR_SRC); - iwl_release_restricted_access(priv); - iwl_poll_bit(priv, CSR_GPIO_IN, CSR_GPIO_IN_VAL_VMAIN_PWR_SRC, + iwl3945_release_nic_access(priv); + iwl3945_poll_bit(priv, CSR_GPIO_IN, CSR_GPIO_IN_VAL_VMAIN_PWR_SRC, CSR_GPIO_IN_BIT_AUX_POWER, 5000); /* uS */ } spin_unlock_irqrestore(&priv->lock, flags); @@ -757,24 +829,24 @@ static int iwl3945_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max) return rc; } -static int iwl3945_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq) +static int iwl3945_rx_init(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq) { int rc; unsigned long flags; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } - iwl_write_restricted(priv, FH_RCSR_RBD_BASE(0), rxq->dma_addr); - iwl_write_restricted(priv, FH_RCSR_RPTR_ADDR(0), + iwl3945_write_direct32(priv, FH_RCSR_RBD_BASE(0), rxq->dma_addr); + iwl3945_write_direct32(priv, FH_RCSR_RPTR_ADDR(0), priv->hw_setting.shared_phys + - offsetof(struct iwl_shared, rx_read_ptr[0])); - iwl_write_restricted(priv, FH_RCSR_WPTR(0), 0); - iwl_write_restricted(priv, FH_RCSR_CONFIG(0), + offsetof(struct iwl3945_shared, rx_read_ptr[0])); + iwl3945_write_direct32(priv, FH_RCSR_WPTR(0), 0); + iwl3945_write_direct32(priv, FH_RCSR_CONFIG(0), ALM_FH_RCSR_RX_CONFIG_REG_VAL_DMA_CHNL_EN_ENABLE | ALM_FH_RCSR_RX_CONFIG_REG_VAL_RDRBD_EN_ENABLE | ALM_FH_RCSR_RX_CONFIG_REG_BIT_WR_STTS_EN | @@ -785,44 +857,44 @@ static int iwl3945_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq) ALM_FH_RCSR_RX_CONFIG_REG_VAL_MSG_MODE_FH); /* fake read to flush all prev I/O */ - iwl_read_restricted(priv, FH_RSSR_CTRL); + iwl3945_read_direct32(priv, FH_RSSR_CTRL); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); return 0; } -static int iwl3945_tx_reset(struct iwl_priv *priv) +static int iwl3945_tx_reset(struct iwl3945_priv *priv) { int rc; unsigned long flags; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } /* bypass mode */ - iwl_write_restricted_reg(priv, SCD_MODE_REG, 0x2); + iwl3945_write_prph(priv, ALM_SCD_MODE_REG, 0x2); /* RA 0 is active */ - iwl_write_restricted_reg(priv, SCD_ARASTAT_REG, 0x01); + iwl3945_write_prph(priv, ALM_SCD_ARASTAT_REG, 0x01); /* all 6 fifo are active */ - iwl_write_restricted_reg(priv, SCD_TXFACT_REG, 0x3f); + iwl3945_write_prph(priv, ALM_SCD_TXFACT_REG, 0x3f); - iwl_write_restricted_reg(priv, SCD_SBYP_MODE_1_REG, 0x010000); - iwl_write_restricted_reg(priv, SCD_SBYP_MODE_2_REG, 0x030002); - iwl_write_restricted_reg(priv, SCD_TXF4MF_REG, 0x000004); - iwl_write_restricted_reg(priv, SCD_TXF5MF_REG, 0x000005); + iwl3945_write_prph(priv, ALM_SCD_SBYP_MODE_1_REG, 0x010000); + iwl3945_write_prph(priv, ALM_SCD_SBYP_MODE_2_REG, 0x030002); + iwl3945_write_prph(priv, ALM_SCD_TXF4MF_REG, 0x000004); + iwl3945_write_prph(priv, ALM_SCD_TXF5MF_REG, 0x000005); - iwl_write_restricted(priv, FH_TSSR_CBB_BASE, + iwl3945_write_direct32(priv, FH_TSSR_CBB_BASE, priv->hw_setting.shared_phys); - iwl_write_restricted(priv, FH_TSSR_MSG_CONFIG, + iwl3945_write_direct32(priv, FH_TSSR_MSG_CONFIG, ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TXPD_ON | ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_TXPD_ON | ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_128B | @@ -831,7 +903,7 @@ static int iwl3945_tx_reset(struct iwl_priv *priv) ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RSP_WAIT_TH | ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_RSP_WAIT_TH); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); return 0; @@ -842,12 +914,12 @@ static int iwl3945_tx_reset(struct iwl_priv *priv) * * Destroys all DMA structures and initialize them again */ -static int iwl3945_txq_ctx_reset(struct iwl_priv *priv) +static int iwl3945_txq_ctx_reset(struct iwl3945_priv *priv) { int rc; int txq_id, slots_num; - iwl_hw_txq_ctx_free(priv); + iwl3945_hw_txq_ctx_free(priv); /* Tx CMD queue */ rc = iwl3945_tx_reset(priv); @@ -858,7 +930,7 @@ static int iwl3945_txq_ctx_reset(struct iwl_priv *priv) for (txq_id = 0; txq_id < TFD_QUEUE_MAX; txq_id++) { slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ? TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; - rc = iwl_tx_queue_init(priv, &priv->txq[txq_id], slots_num, + rc = iwl3945_tx_queue_init(priv, &priv->txq[txq_id], slots_num, txq_id); if (rc) { IWL_ERROR("Tx %d queue init failed\n", txq_id); @@ -869,26 +941,26 @@ static int iwl3945_txq_ctx_reset(struct iwl_priv *priv) return rc; error: - iwl_hw_txq_ctx_free(priv); + iwl3945_hw_txq_ctx_free(priv); return rc; } -int iwl_hw_nic_init(struct iwl_priv *priv) +int iwl3945_hw_nic_init(struct iwl3945_priv *priv) { u8 rev_id; int rc; unsigned long flags; - struct iwl_rx_queue *rxq = &priv->rxq; + struct iwl3945_rx_queue *rxq = &priv->rxq; - iwl_power_init_handle(priv); + iwl3945_power_init_handle(priv); spin_lock_irqsave(&priv->lock, flags); - iwl_set_bit(priv, CSR_ANA_PLL_CFG, (1 << 24)); - iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, + iwl3945_set_bit(priv, CSR_ANA_PLL_CFG, (1 << 24)); + iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS, CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX); - iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); - rc = iwl_poll_bit(priv, CSR_GP_CNTRL, + iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); + rc = iwl3945_poll_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); if (rc < 0) { @@ -897,18 +969,18 @@ int iwl_hw_nic_init(struct iwl_priv *priv) return rc; } - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } - iwl_write_restricted_reg(priv, APMG_CLK_EN_REG, + iwl3945_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT); udelay(20); - iwl_set_bits_restricted_reg(priv, APMG_PCIDEV_STT_REG, + iwl3945_set_bits_prph(priv, APMG_PCIDEV_STT_REG, APMG_PCIDEV_STT_VAL_L1_ACT_DIS); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); /* Determine HW type */ @@ -924,25 +996,17 @@ int iwl_hw_nic_init(struct iwl_priv *priv) IWL_DEBUG_INFO("RTP type \n"); else if (rev_id & PCI_CFG_REV_ID_BIT_BASIC_SKU) { IWL_DEBUG_INFO("ALM-MB type\n"); - iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, + iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_BIT_ALMAGOR_MB); } else { IWL_DEBUG_INFO("ALM-MM type\n"); - iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, + iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_BIT_ALMAGOR_MM); } - spin_unlock_irqrestore(&priv->lock, flags); - - /* Initialize the EEPROM */ - rc = iwl_eeprom_init(priv); - if (rc) - return rc; - - spin_lock_irqsave(&priv->lock, flags); if (EEPROM_SKU_CAP_OP_MODE_MRC == priv->eeprom.sku_cap) { IWL_DEBUG_INFO("SKU OP mode is mrc\n"); - iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, + iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_BIT_SKU_MRC); } else IWL_DEBUG_INFO("SKU OP mode is basic\n"); @@ -950,24 +1014,24 @@ int iwl_hw_nic_init(struct iwl_priv *priv) if ((priv->eeprom.board_revision & 0xF0) == 0xD0) { IWL_DEBUG_INFO("3945ABG revision is 0x%X\n", priv->eeprom.board_revision); - iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, + iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_BIT_BOARD_TYPE); } else { IWL_DEBUG_INFO("3945ABG revision is 0x%X\n", priv->eeprom.board_revision); - iwl_clear_bit(priv, CSR_HW_IF_CONFIG_REG, + iwl3945_clear_bit(priv, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_BIT_BOARD_TYPE); } if (priv->eeprom.almgor_m_version <= 1) { - iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, + iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_A); IWL_DEBUG_INFO("Card M type A version is 0x%X\n", priv->eeprom.almgor_m_version); } else { IWL_DEBUG_INFO("Card M type B version is 0x%X\n", priv->eeprom.almgor_m_version); - iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, + iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_B); } spin_unlock_irqrestore(&priv->lock, flags); @@ -980,15 +1044,15 @@ int iwl_hw_nic_init(struct iwl_priv *priv) /* Allocate the RX queue, or reset if it is already allocated */ if (!rxq->bd) { - rc = iwl_rx_queue_alloc(priv); + rc = iwl3945_rx_queue_alloc(priv); if (rc) { IWL_ERROR("Unable to initialize Rx queue\n"); return -ENOMEM; } } else - iwl_rx_queue_reset(priv, rxq); + iwl3945_rx_queue_reset(priv, rxq); - iwl_rx_replenish(priv); + iwl3945_rx_replenish(priv); iwl3945_rx_init(priv, rxq); @@ -996,16 +1060,16 @@ int iwl_hw_nic_init(struct iwl_priv *priv) /* Look at using this instead: rxq->need_update = 1; - iwl_rx_queue_update_write_ptr(priv, rxq); + iwl3945_rx_queue_update_write_ptr(priv, rxq); */ - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } - iwl_write_restricted(priv, FH_RCSR_WPTR(0), rxq->write & ~7); - iwl_release_restricted_access(priv); + iwl3945_write_direct32(priv, FH_RCSR_WPTR(0), rxq->write & ~7); + iwl3945_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); @@ -1019,49 +1083,49 @@ int iwl_hw_nic_init(struct iwl_priv *priv) } /** - * iwl_hw_txq_ctx_free - Free TXQ Context + * iwl3945_hw_txq_ctx_free - Free TXQ Context * * Destroy all TX DMA queues and structures */ -void iwl_hw_txq_ctx_free(struct iwl_priv *priv) +void iwl3945_hw_txq_ctx_free(struct iwl3945_priv *priv) { int txq_id; /* Tx queues */ for (txq_id = 0; txq_id < TFD_QUEUE_MAX; txq_id++) - iwl_tx_queue_free(priv, &priv->txq[txq_id]); + iwl3945_tx_queue_free(priv, &priv->txq[txq_id]); } -void iwl_hw_txq_ctx_stop(struct iwl_priv *priv) +void iwl3945_hw_txq_ctx_stop(struct iwl3945_priv *priv) { int queue; unsigned long flags; spin_lock_irqsave(&priv->lock, flags); - if (iwl_grab_restricted_access(priv)) { + if (iwl3945_grab_nic_access(priv)) { spin_unlock_irqrestore(&priv->lock, flags); - iwl_hw_txq_ctx_free(priv); + iwl3945_hw_txq_ctx_free(priv); return; } /* stop SCD */ - iwl_write_restricted_reg(priv, SCD_MODE_REG, 0); + iwl3945_write_prph(priv, ALM_SCD_MODE_REG, 0); /* reset TFD queues */ for (queue = TFD_QUEUE_MIN; queue < TFD_QUEUE_MAX; queue++) { - iwl_write_restricted(priv, FH_TCSR_CONFIG(queue), 0x0); - iwl_poll_restricted_bit(priv, FH_TSSR_TX_STATUS, + iwl3945_write_direct32(priv, FH_TCSR_CONFIG(queue), 0x0); + iwl3945_poll_direct_bit(priv, FH_TSSR_TX_STATUS, ALM_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(queue), 1000); } - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); - iwl_hw_txq_ctx_free(priv); + iwl3945_hw_txq_ctx_free(priv); } -int iwl_hw_nic_stop_master(struct iwl_priv *priv) +int iwl3945_hw_nic_stop_master(struct iwl3945_priv *priv) { int rc = 0; u32 reg_val; @@ -1070,16 +1134,16 @@ int iwl_hw_nic_stop_master(struct iwl_priv *priv) spin_lock_irqsave(&priv->lock, flags); /* set stop master bit */ - iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); + iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); - reg_val = iwl_read32(priv, CSR_GP_CNTRL); + reg_val = iwl3945_read32(priv, CSR_GP_CNTRL); if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE == (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE)) IWL_DEBUG_INFO("Card in power save, master is already " "stopped\n"); else { - rc = iwl_poll_bit(priv, CSR_RESET, + rc = iwl3945_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED, CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); if (rc < 0) { @@ -1094,47 +1158,47 @@ int iwl_hw_nic_stop_master(struct iwl_priv *priv) return rc; } -int iwl_hw_nic_reset(struct iwl_priv *priv) +int iwl3945_hw_nic_reset(struct iwl3945_priv *priv) { int rc; unsigned long flags; - iwl_hw_nic_stop_master(priv); + iwl3945_hw_nic_stop_master(priv); spin_lock_irqsave(&priv->lock, flags); - iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); + iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); - rc = iwl_poll_bit(priv, CSR_GP_CNTRL, + rc = iwl3945_poll_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (!rc) { - iwl_write_restricted_reg(priv, APMG_CLK_CTRL_REG, + iwl3945_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_BSM_CLK_RQT); udelay(10); - iwl_set_bit(priv, CSR_GP_CNTRL, + iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); - iwl_write_restricted_reg(priv, APMG_RTC_INT_MSK_REG, 0x0); - iwl_write_restricted_reg(priv, APMG_RTC_INT_STT_REG, + iwl3945_write_prph(priv, APMG_RTC_INT_MSK_REG, 0x0); + iwl3945_write_prph(priv, APMG_RTC_INT_STT_REG, 0xFFFFFFFF); /* enable DMA */ - iwl_write_restricted_reg(priv, APMG_CLK_EN_REG, + iwl3945_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT); udelay(10); - iwl_set_bits_restricted_reg(priv, APMG_PS_CTRL_REG, + iwl3945_set_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ); udelay(5); - iwl_clear_bits_restricted_reg(priv, APMG_PS_CTRL_REG, + iwl3945_clear_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); } /* Clear the 'host command active' bit... */ @@ -1147,41 +1211,43 @@ int iwl_hw_nic_reset(struct iwl_priv *priv) } /** - * iwl_hw_reg_adjust_power_by_temp - return index delta into power gain settings table - */ -static int iwl_hw_reg_adjust_power_by_temp(int new_reading, int old_reading) + * iwl3945_hw_reg_adjust_power_by_temp + * return index delta into power gain settings table +*/ +static int iwl3945_hw_reg_adjust_power_by_temp(int new_reading, int old_reading) { return (new_reading - old_reading) * (-11) / 100; } /** - * iwl_hw_reg_temp_out_of_range - Keep temperature in sane range + * iwl3945_hw_reg_temp_out_of_range - Keep temperature in sane range */ -static inline int iwl_hw_reg_temp_out_of_range(int temperature) +static inline int iwl3945_hw_reg_temp_out_of_range(int temperature) { return (((temperature < -260) || (temperature > 25)) ? 1 : 0); } -int iwl_hw_get_temperature(struct iwl_priv *priv) +int iwl3945_hw_get_temperature(struct iwl3945_priv *priv) { - return iwl_read32(priv, CSR_UCODE_DRV_GP2); + return iwl3945_read32(priv, CSR_UCODE_DRV_GP2); } /** - * iwl_hw_reg_txpower_get_temperature - get current temperature by reading from NIC - */ -static int iwl_hw_reg_txpower_get_temperature(struct iwl_priv *priv) + * iwl3945_hw_reg_txpower_get_temperature + * get the current temperature by reading from NIC +*/ +static int iwl3945_hw_reg_txpower_get_temperature(struct iwl3945_priv *priv) { int temperature; - temperature = iwl_hw_get_temperature(priv); + temperature = iwl3945_hw_get_temperature(priv); /* driver's okay range is -260 to +25. * human readable okay range is 0 to +285 */ IWL_DEBUG_INFO("Temperature: %d\n", temperature + IWL_TEMP_CONVERT); /* handle insane temp reading */ - if (iwl_hw_reg_temp_out_of_range(temperature)) { + if (iwl3945_hw_reg_temp_out_of_range(temperature)) { IWL_ERROR("Error bad temperature value %d\n", temperature); /* if really really hot(?), @@ -1206,11 +1272,11 @@ static int iwl_hw_reg_txpower_get_temperature(struct iwl_priv *priv) * records new temperature in tx_mgr->temperature. * replaces tx_mgr->last_temperature *only* if calib needed * (assumes caller will actually do the calibration!). */ -static int is_temp_calib_needed(struct iwl_priv *priv) +static int is_temp_calib_needed(struct iwl3945_priv *priv) { int temp_diff; - priv->temperature = iwl_hw_reg_txpower_get_temperature(priv); + priv->temperature = iwl3945_hw_reg_txpower_get_temperature(priv); temp_diff = priv->temperature - priv->last_temperature; /* get absolute value */ @@ -1242,7 +1308,7 @@ static int is_temp_calib_needed(struct iwl_priv *priv) /* radio and DSP power table, each step is 1/2 dB. * 1st number is for RF analog gain, 2nd number is for DSP pre-DAC gain. */ -static struct iwl_tx_power power_gain_table[2][IWL_MAX_GAIN_ENTRIES] = { +static struct iwl3945_tx_power power_gain_table[2][IWL_MAX_GAIN_ENTRIES] = { { {251, 127}, /* 2.4 GHz, highest power */ {251, 127}, @@ -1403,7 +1469,7 @@ static struct iwl_tx_power power_gain_table[2][IWL_MAX_GAIN_ENTRIES] = { {3, 120} } /* 5.x GHz, lowest power */ }; -static inline u8 iwl_hw_reg_fix_power_index(int index) +static inline u8 iwl3945_hw_reg_fix_power_index(int index) { if (index < 0) return 0; @@ -1416,17 +1482,17 @@ static inline u8 iwl_hw_reg_fix_power_index(int index) #define REG_RECALIB_PERIOD (60) /** - * iwl_hw_reg_set_scan_power - Set Tx power for scan probe requests + * iwl3945_hw_reg_set_scan_power - Set Tx power for scan probe requests * * Set (in our channel info database) the direct scan Tx power for 1 Mbit (CCK) * or 6 Mbit (OFDM) rates. */ -static void iwl_hw_reg_set_scan_power(struct iwl_priv *priv, u32 scan_tbl_index, +static void iwl3945_hw_reg_set_scan_power(struct iwl3945_priv *priv, u32 scan_tbl_index, s32 rate_index, const s8 *clip_pwrs, - struct iwl_channel_info *ch_info, + struct iwl3945_channel_info *ch_info, int band_index) { - struct iwl_scan_power_info *scan_power_info; + struct iwl3945_scan_power_info *scan_power_info; s8 power; u8 power_index; @@ -1462,7 +1528,7 @@ static void iwl_hw_reg_set_scan_power(struct iwl_priv *priv, u32 scan_tbl_index, * of the table. */ /* don't exceed table bounds for "real" setting */ - power_index = iwl_hw_reg_fix_power_index(power_index); + power_index = iwl3945_hw_reg_fix_power_index(power_index); scan_power_info->power_table_index = power_index; scan_power_info->tpc.tx_gain = @@ -1472,21 +1538,21 @@ static void iwl_hw_reg_set_scan_power(struct iwl_priv *priv, u32 scan_tbl_index, } /** - * iwl_hw_reg_send_txpower - fill in Tx Power command with gain settings + * iwl3945_hw_reg_send_txpower - fill in Tx Power command with gain settings * * Configures power settings for all rates for the current channel, * using values from channel info struct, and send to NIC */ -int iwl_hw_reg_send_txpower(struct iwl_priv *priv) +int iwl3945_hw_reg_send_txpower(struct iwl3945_priv *priv) { int rate_idx, i; - const struct iwl_channel_info *ch_info = NULL; - struct iwl_txpowertable_cmd txpower = { + const struct iwl3945_channel_info *ch_info = NULL; + struct iwl3945_txpowertable_cmd txpower = { .channel = priv->active_rxon.channel, }; txpower.band = (priv->phymode == MODE_IEEE80211A) ? 0 : 1; - ch_info = iwl_get_channel_info(priv, + ch_info = iwl3945_get_channel_info(priv, priv->phymode, le16_to_cpu(priv->active_rxon.channel)); if (!ch_info) { @@ -1508,7 +1574,7 @@ int iwl_hw_reg_send_txpower(struct iwl_priv *priv) rate_idx <= IWL_LAST_OFDM_RATE; rate_idx++, i++) { txpower.power[i].tpc = ch_info->power_info[i].tpc; - txpower.power[i].rate = iwl_rates[rate_idx].plcp; + txpower.power[i].rate = iwl3945_rates[rate_idx].plcp; IWL_DEBUG_POWER("ch %d:%d rf %d dsp %3d rate code 0x%02x\n", le16_to_cpu(txpower.channel), @@ -1521,7 +1587,7 @@ int iwl_hw_reg_send_txpower(struct iwl_priv *priv) for (rate_idx = IWL_FIRST_CCK_RATE; rate_idx <= IWL_LAST_CCK_RATE; rate_idx++, i++) { txpower.power[i].tpc = ch_info->power_info[i].tpc; - txpower.power[i].rate = iwl_rates[rate_idx].plcp; + txpower.power[i].rate = iwl3945_rates[rate_idx].plcp; IWL_DEBUG_POWER("ch %d:%d rf %d dsp %3d rate code 0x%02x\n", le16_to_cpu(txpower.channel), @@ -1531,13 +1597,13 @@ int iwl_hw_reg_send_txpower(struct iwl_priv *priv) txpower.power[i].rate); } - return iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, - sizeof(struct iwl_txpowertable_cmd), &txpower); + return iwl3945_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, + sizeof(struct iwl3945_txpowertable_cmd), &txpower); } /** - * iwl_hw_reg_set_new_power - Configures power tables at new levels + * iwl3945_hw_reg_set_new_power - Configures power tables at new levels * @ch_info: Channel to update. Uses power_info.requested_power. * * Replace requested_power and base_power_index ch_info fields for @@ -1552,10 +1618,10 @@ int iwl_hw_reg_send_txpower(struct iwl_priv *priv) * properly fill out the scan powers, and actual h/w gain settings, * and send changes to NIC */ -static int iwl_hw_reg_set_new_power(struct iwl_priv *priv, - struct iwl_channel_info *ch_info) +static int iwl3945_hw_reg_set_new_power(struct iwl3945_priv *priv, + struct iwl3945_channel_info *ch_info) { - struct iwl_channel_power_info *power_info; + struct iwl3945_channel_power_info *power_info; int power_changed = 0; int i; const s8 *clip_pwrs; @@ -1595,7 +1661,7 @@ static int iwl_hw_reg_set_new_power(struct iwl_priv *priv, ch_info->power_info[IWL_RATE_12M_INDEX_TABLE]. requested_power + IWL_CCK_FROM_OFDM_POWER_DIFF; - /* do all CCK rates' iwl_channel_power_info structures */ + /* do all CCK rates' iwl3945_channel_power_info structures */ for (i = IWL_RATE_1M_INDEX_TABLE; i <= IWL_RATE_11M_INDEX_TABLE; i++) { power_info->requested_power = power; power_info->base_power_index = @@ -1609,13 +1675,13 @@ static int iwl_hw_reg_set_new_power(struct iwl_priv *priv, } /** - * iwl_hw_reg_get_ch_txpower_limit - returns new power limit for channel + * iwl3945_hw_reg_get_ch_txpower_limit - returns new power limit for channel * * NOTE: Returned power limit may be less (but not more) than requested, * based strictly on regulatory (eeprom and spectrum mgt) limitations * (no consideration for h/w clipping limitations). */ -static int iwl_hw_reg_get_ch_txpower_limit(struct iwl_channel_info *ch_info) +static int iwl3945_hw_reg_get_ch_txpower_limit(struct iwl3945_channel_info *ch_info) { s8 max_power; @@ -1634,7 +1700,7 @@ static int iwl_hw_reg_get_ch_txpower_limit(struct iwl_channel_info *ch_info) } /** - * iwl_hw_reg_comp_txpower_temp - Compensate for temperature + * iwl3945_hw_reg_comp_txpower_temp - Compensate for temperature * * Compensate txpower settings of *all* channels for temperature. * This only accounts for the difference between current temperature @@ -1643,9 +1709,9 @@ static int iwl_hw_reg_get_ch_txpower_limit(struct iwl_channel_info *ch_info) * * If RxOn is "associated", this sends the new Txpower to NIC! */ -static int iwl_hw_reg_comp_txpower_temp(struct iwl_priv *priv) +static int iwl3945_hw_reg_comp_txpower_temp(struct iwl3945_priv *priv) { - struct iwl_channel_info *ch_info = NULL; + struct iwl3945_channel_info *ch_info = NULL; int delta_index; const s8 *clip_pwrs; /* array of h/w max power levels for each rate */ u8 a_band; @@ -1666,7 +1732,7 @@ static int iwl_hw_reg_comp_txpower_temp(struct iwl_priv *priv) /* get power index adjustment based on curr and factory * temps */ - delta_index = iwl_hw_reg_adjust_power_by_temp(temperature, + delta_index = iwl3945_hw_reg_adjust_power_by_temp(temperature, ref_temp); /* set tx power value for all rates, OFDM and CCK */ @@ -1679,7 +1745,7 @@ static int iwl_hw_reg_comp_txpower_temp(struct iwl_priv *priv) power_idx += delta_index; /* stay within table range */ - power_idx = iwl_hw_reg_fix_power_index(power_idx); + power_idx = iwl3945_hw_reg_fix_power_index(power_idx); ch_info->power_info[rate_index]. power_table_index = (u8) power_idx; ch_info->power_info[rate_index].tpc = @@ -1694,19 +1760,19 @@ static int iwl_hw_reg_comp_txpower_temp(struct iwl_priv *priv) scan_tbl_index < IWL_NUM_SCAN_RATES; scan_tbl_index++) { s32 actual_index = (scan_tbl_index == 0) ? IWL_RATE_1M_INDEX_TABLE : IWL_RATE_6M_INDEX_TABLE; - iwl_hw_reg_set_scan_power(priv, scan_tbl_index, + iwl3945_hw_reg_set_scan_power(priv, scan_tbl_index, actual_index, clip_pwrs, ch_info, a_band); } } /* send Txpower command for current channel to ucode */ - return iwl_hw_reg_send_txpower(priv); + return iwl3945_hw_reg_send_txpower(priv); } -int iwl_hw_reg_set_txpower(struct iwl_priv *priv, s8 power) +int iwl3945_hw_reg_set_txpower(struct iwl3945_priv *priv, s8 power) { - struct iwl_channel_info *ch_info; + struct iwl3945_channel_info *ch_info; s8 max_power; u8 a_band; u8 i; @@ -1728,26 +1794,26 @@ int iwl_hw_reg_set_txpower(struct iwl_priv *priv, s8 power) /* find minimum power of all user and regulatory constraints * (does not consider h/w clipping limitations) */ - max_power = iwl_hw_reg_get_ch_txpower_limit(ch_info); + max_power = iwl3945_hw_reg_get_ch_txpower_limit(ch_info); max_power = min(power, max_power); if (max_power != ch_info->curr_txpow) { ch_info->curr_txpow = max_power; /* this considers the h/w clipping limitations */ - iwl_hw_reg_set_new_power(priv, ch_info); + iwl3945_hw_reg_set_new_power(priv, ch_info); } } /* update txpower settings for all channels, * send to NIC if associated. */ is_temp_calib_needed(priv); - iwl_hw_reg_comp_txpower_temp(priv); + iwl3945_hw_reg_comp_txpower_temp(priv); return 0; } /* will add 3945 channel switch cmd handling later */ -int iwl_hw_channel_switch(struct iwl_priv *priv, u16 channel) +int iwl3945_hw_channel_switch(struct iwl3945_priv *priv, u16 channel) { return 0; } @@ -1762,26 +1828,26 @@ int iwl_hw_channel_switch(struct iwl_priv *priv, u16 channel) * -- send new set of gain settings to NIC * NOTE: This should continue working, even when we're not associated, * so we can keep our internal table of scan powers current. */ -void iwl3945_reg_txpower_periodic(struct iwl_priv *priv) +void iwl3945_reg_txpower_periodic(struct iwl3945_priv *priv) { /* This will kick in the "brute force" - * iwl_hw_reg_comp_txpower_temp() below */ + * iwl3945_hw_reg_comp_txpower_temp() below */ if (!is_temp_calib_needed(priv)) goto reschedule; /* Set up a new set of temp-adjusted TxPowers, send to NIC. * This is based *only* on current temperature, * ignoring any previous power measurements */ - iwl_hw_reg_comp_txpower_temp(priv); + iwl3945_hw_reg_comp_txpower_temp(priv); reschedule: queue_delayed_work(priv->workqueue, &priv->thermal_periodic, REG_RECALIB_PERIOD * HZ); } -void iwl3945_bg_reg_txpower_periodic(struct work_struct *work) +static void iwl3945_bg_reg_txpower_periodic(struct work_struct *work) { - struct iwl_priv *priv = container_of(work, struct iwl_priv, + struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, thermal_periodic.work); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) @@ -1793,7 +1859,7 @@ void iwl3945_bg_reg_txpower_periodic(struct work_struct *work) } /** - * iwl_hw_reg_get_ch_grp_index - find the channel-group index (0-4) + * iwl3945_hw_reg_get_ch_grp_index - find the channel-group index (0-4) * for the channel. * * This function is used when initializing channel-info structs. @@ -1803,10 +1869,10 @@ void iwl3945_bg_reg_txpower_periodic(struct work_struct *work) * on A-band, EEPROM's "group frequency" entries represent the top * channel in each group 1-4. Group 5 All B/G channels are in group 0. */ -static u16 iwl_hw_reg_get_ch_grp_index(struct iwl_priv *priv, - const struct iwl_channel_info *ch_info) +static u16 iwl3945_hw_reg_get_ch_grp_index(struct iwl3945_priv *priv, + const struct iwl3945_channel_info *ch_info) { - struct iwl_eeprom_txpower_group *ch_grp = &priv->eeprom.groups[0]; + struct iwl3945_eeprom_txpower_group *ch_grp = &priv->eeprom.groups[0]; u8 group; u16 group_index = 0; /* based on factory calib frequencies */ u8 grp_channel; @@ -1832,20 +1898,20 @@ static u16 iwl_hw_reg_get_ch_grp_index(struct iwl_priv *priv, } /** - * iwl_hw_reg_get_matched_power_index - Interpolate to get nominal index + * iwl3945_hw_reg_get_matched_power_index - Interpolate to get nominal index * * Interpolate to get nominal (i.e. at factory calibration temperature) index * into radio/DSP gain settings table for requested power. */ -static int iwl_hw_reg_get_matched_power_index(struct iwl_priv *priv, +static int iwl3945_hw_reg_get_matched_power_index(struct iwl3945_priv *priv, s8 requested_power, s32 setting_index, s32 *new_index) { - const struct iwl_eeprom_txpower_group *chnl_grp = NULL; + const struct iwl3945_eeprom_txpower_group *chnl_grp = NULL; s32 index0, index1; s32 power = 2 * requested_power; s32 i; - const struct iwl_eeprom_txpower_sample *samples; + const struct iwl3945_eeprom_txpower_sample *samples; s32 gains0, gains1; s32 res; s32 denominator; @@ -1885,11 +1951,11 @@ static int iwl_hw_reg_get_matched_power_index(struct iwl_priv *priv, return 0; } -static void iwl_hw_reg_init_channel_groups(struct iwl_priv *priv) +static void iwl3945_hw_reg_init_channel_groups(struct iwl3945_priv *priv) { u32 i; s32 rate_index; - const struct iwl_eeprom_txpower_group *group; + const struct iwl3945_eeprom_txpower_group *group; IWL_DEBUG_POWER("Initializing factory calib info from EEPROM\n"); @@ -1965,10 +2031,10 @@ static void iwl_hw_reg_init_channel_groups(struct iwl_priv *priv) * * This does *not* write values to NIC, just sets up our internal table. */ -int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv) +int iwl3945_txpower_set_from_eeprom(struct iwl3945_priv *priv) { - struct iwl_channel_info *ch_info = NULL; - struct iwl_channel_power_info *pwr_info; + struct iwl3945_channel_info *ch_info = NULL; + struct iwl3945_channel_power_info *pwr_info; int delta_index; u8 rate_index; u8 scan_tbl_index; @@ -1981,10 +2047,10 @@ int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv) /* save temperature reference, * so we can determine next time to calibrate */ - temperature = iwl_hw_reg_txpower_get_temperature(priv); + temperature = iwl3945_hw_reg_txpower_get_temperature(priv); priv->last_temperature = temperature; - iwl_hw_reg_init_channel_groups(priv); + iwl3945_hw_reg_init_channel_groups(priv); /* initialize Tx power info for each and every channel, 2.4 and 5.x */ for (i = 0, ch_info = priv->channel_info; i < priv->channel_count; @@ -1995,14 +2061,14 @@ int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv) /* find this channel's channel group (*not* "band") index */ ch_info->group_index = - iwl_hw_reg_get_ch_grp_index(priv, ch_info); + iwl3945_hw_reg_get_ch_grp_index(priv, ch_info); /* Get this chnlgrp's rate->max/clip-powers table */ clip_pwrs = priv->clip_groups[ch_info->group_index].clip_powers; /* calculate power index *adjustment* value according to * diff between current temperature and factory temperature */ - delta_index = iwl_hw_reg_adjust_power_by_temp(temperature, + delta_index = iwl3945_hw_reg_adjust_power_by_temp(temperature, priv->eeprom.groups[ch_info->group_index]. temperature); @@ -2025,7 +2091,7 @@ int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv) /* get base (i.e. at factory-measured temperature) * power table index for this rate's power */ - rc = iwl_hw_reg_get_matched_power_index(priv, pwr, + rc = iwl3945_hw_reg_get_matched_power_index(priv, pwr, ch_info->group_index, &power_idx); if (rc) { @@ -2038,9 +2104,9 @@ int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv) power_idx += delta_index; /* stay within range of gain table */ - power_idx = iwl_hw_reg_fix_power_index(power_idx); + power_idx = iwl3945_hw_reg_fix_power_index(power_idx); - /* fill 1 OFDM rate's iwl_channel_power_info struct */ + /* fill 1 OFDM rate's iwl3945_channel_power_info struct */ pwr_info->requested_power = pwr; pwr_info->power_table_index = (u8) power_idx; pwr_info->tpc.tx_gain = @@ -2059,11 +2125,11 @@ int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv) IWL_CCK_FROM_OFDM_INDEX_DIFF; /* stay within table range */ - pwr_index = iwl_hw_reg_fix_power_index(pwr_index); + pwr_index = iwl3945_hw_reg_fix_power_index(pwr_index); gain = power_gain_table[a_band][pwr_index].tx_gain; dsp_atten = power_gain_table[a_band][pwr_index].dsp_atten; - /* fill each CCK rate's iwl_channel_power_info structure + /* fill each CCK rate's iwl3945_channel_power_info structure * NOTE: All CCK-rate Txpwrs are the same for a given chnl! * NOTE: CCK rates start at end of OFDM rates! */ for (rate_index = 0; @@ -2081,7 +2147,7 @@ int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv) scan_tbl_index < IWL_NUM_SCAN_RATES; scan_tbl_index++) { s32 actual_index = (scan_tbl_index == 0) ? IWL_RATE_1M_INDEX_TABLE : IWL_RATE_6M_INDEX_TABLE; - iwl_hw_reg_set_scan_power(priv, scan_tbl_index, + iwl3945_hw_reg_set_scan_power(priv, scan_tbl_index, actual_index, clip_pwrs, ch_info, a_band); } } @@ -2089,66 +2155,66 @@ int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv) return 0; } -int iwl_hw_rxq_stop(struct iwl_priv *priv) +int iwl3945_hw_rxq_stop(struct iwl3945_priv *priv) { int rc; unsigned long flags; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } - iwl_write_restricted(priv, FH_RCSR_CONFIG(0), 0); - rc = iwl_poll_restricted_bit(priv, FH_RSSR_STATUS, (1 << 24), 1000); + iwl3945_write_direct32(priv, FH_RCSR_CONFIG(0), 0); + rc = iwl3945_poll_direct_bit(priv, FH_RSSR_STATUS, (1 << 24), 1000); if (rc < 0) IWL_ERROR("Can't stop Rx DMA.\n"); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); return 0; } -int iwl_hw_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq) +int iwl3945_hw_tx_queue_init(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq) { int rc; unsigned long flags; int txq_id = txq->q.id; - struct iwl_shared *shared_data = priv->hw_setting.shared_virt; + struct iwl3945_shared *shared_data = priv->hw_setting.shared_virt; shared_data->tx_base_ptr[txq_id] = cpu_to_le32((u32)txq->q.dma_addr); spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } - iwl_write_restricted(priv, FH_CBCC_CTRL(txq_id), 0); - iwl_write_restricted(priv, FH_CBCC_BASE(txq_id), 0); + iwl3945_write_direct32(priv, FH_CBCC_CTRL(txq_id), 0); + iwl3945_write_direct32(priv, FH_CBCC_BASE(txq_id), 0); - iwl_write_restricted(priv, FH_TCSR_CONFIG(txq_id), + iwl3945_write_direct32(priv, FH_TCSR_CONFIG(txq_id), ALM_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT | ALM_FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF | ALM_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD | ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL | ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); /* fake read to flush all prev. writes */ - iwl_read32(priv, FH_TSSR_CBB_BASE); + iwl3945_read32(priv, FH_TSSR_CBB_BASE); spin_unlock_irqrestore(&priv->lock, flags); return 0; } -int iwl_hw_get_rx_read(struct iwl_priv *priv) +int iwl3945_hw_get_rx_read(struct iwl3945_priv *priv) { - struct iwl_shared *shared_data = priv->hw_setting.shared_virt; + struct iwl3945_shared *shared_data = priv->hw_setting.shared_virt; return le32_to_cpu(shared_data->rx_read_ptr[0]); } @@ -2156,22 +2222,22 @@ int iwl_hw_get_rx_read(struct iwl_priv *priv) /** * iwl3945_init_hw_rate_table - Initialize the hardware rate fallback table */ -int iwl3945_init_hw_rate_table(struct iwl_priv *priv) +int iwl3945_init_hw_rate_table(struct iwl3945_priv *priv) { int rc, i, index, prev_index; - struct iwl_rate_scaling_cmd rate_cmd = { + struct iwl3945_rate_scaling_cmd rate_cmd = { .reserved = {0, 0, 0}, }; - struct iwl_rate_scaling_info *table = rate_cmd.table; + struct iwl3945_rate_scaling_info *table = rate_cmd.table; - for (i = 0; i < ARRAY_SIZE(iwl_rates); i++) { - index = iwl_rates[i].table_rs_index; + for (i = 0; i < ARRAY_SIZE(iwl3945_rates); i++) { + index = iwl3945_rates[i].table_rs_index; table[index].rate_n_flags = - iwl_hw_set_rate_n_flags(iwl_rates[i].plcp, 0); + iwl3945_hw_set_rate_n_flags(iwl3945_rates[i].plcp, 0); table[index].try_cnt = priv->retry_rate; - prev_index = iwl_get_prev_ieee_rate(i); - table[index].next_rate_index = iwl_rates[prev_index].table_rs_index; + prev_index = iwl3945_get_prev_ieee_rate(i); + table[index].next_rate_index = iwl3945_rates[prev_index].table_rs_index; } switch (priv->phymode) { @@ -2180,14 +2246,14 @@ int iwl3945_init_hw_rate_table(struct iwl_priv *priv) /* If one of the following CCK rates is used, * have it fall back to the 6M OFDM rate */ for (i = IWL_RATE_1M_INDEX_TABLE; i <= IWL_RATE_11M_INDEX_TABLE; i++) - table[i].next_rate_index = iwl_rates[IWL_FIRST_OFDM_RATE].table_rs_index; + table[i].next_rate_index = iwl3945_rates[IWL_FIRST_OFDM_RATE].table_rs_index; /* Don't fall back to CCK rates */ table[IWL_RATE_12M_INDEX_TABLE].next_rate_index = IWL_RATE_9M_INDEX_TABLE; /* Don't drop out of OFDM rates */ table[IWL_RATE_6M_INDEX_TABLE].next_rate_index = - iwl_rates[IWL_FIRST_OFDM_RATE].table_rs_index; + iwl3945_rates[IWL_FIRST_OFDM_RATE].table_rs_index; break; case MODE_IEEE80211B: @@ -2195,7 +2261,7 @@ int iwl3945_init_hw_rate_table(struct iwl_priv *priv) /* If an OFDM rate is used, have it fall back to the * 1M CCK rates */ for (i = IWL_RATE_6M_INDEX_TABLE; i <= IWL_RATE_54M_INDEX_TABLE; i++) - table[i].next_rate_index = iwl_rates[IWL_FIRST_CCK_RATE].table_rs_index; + table[i].next_rate_index = iwl3945_rates[IWL_FIRST_CCK_RATE].table_rs_index; /* CCK shouldn't fall back to OFDM... */ table[IWL_RATE_11M_INDEX_TABLE].next_rate_index = IWL_RATE_5M_INDEX_TABLE; @@ -2208,25 +2274,26 @@ int iwl3945_init_hw_rate_table(struct iwl_priv *priv) /* Update the rate scaling for control frame Tx */ rate_cmd.table_id = 0; - rc = iwl_send_cmd_pdu(priv, REPLY_RATE_SCALE, sizeof(rate_cmd), + rc = iwl3945_send_cmd_pdu(priv, REPLY_RATE_SCALE, sizeof(rate_cmd), &rate_cmd); if (rc) return rc; /* Update the rate scaling for data frame Tx */ rate_cmd.table_id = 1; - return iwl_send_cmd_pdu(priv, REPLY_RATE_SCALE, sizeof(rate_cmd), + return iwl3945_send_cmd_pdu(priv, REPLY_RATE_SCALE, sizeof(rate_cmd), &rate_cmd); } -int iwl_hw_set_hw_setting(struct iwl_priv *priv) +/* Called when initializing driver */ +int iwl3945_hw_set_hw_setting(struct iwl3945_priv *priv) { memset((void *)&priv->hw_setting, 0, - sizeof(struct iwl_driver_hw_info)); + sizeof(struct iwl3945_driver_hw_info)); priv->hw_setting.shared_virt = pci_alloc_consistent(priv->pci_dev, - sizeof(struct iwl_shared), + sizeof(struct iwl3945_shared), &priv->hw_setting.shared_phys); if (!priv->hw_setting.shared_virt) { @@ -2236,31 +2303,31 @@ int iwl_hw_set_hw_setting(struct iwl_priv *priv) } priv->hw_setting.ac_queue_count = AC_NUM; - priv->hw_setting.rx_buffer_size = IWL_RX_BUF_SIZE; - priv->hw_setting.tx_cmd_len = sizeof(struct iwl_tx_cmd); + priv->hw_setting.rx_buf_size = IWL_RX_BUF_SIZE; + priv->hw_setting.max_pkt_size = 2342; + priv->hw_setting.tx_cmd_len = sizeof(struct iwl3945_tx_cmd); priv->hw_setting.max_rxq_size = RX_QUEUE_SIZE; priv->hw_setting.max_rxq_log = RX_QUEUE_SIZE_LOG; - priv->hw_setting.cck_flag = 0; priv->hw_setting.max_stations = IWL3945_STATION_COUNT; priv->hw_setting.bcast_sta_id = IWL3945_BROADCAST_ID; return 0; } -unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv, - struct iwl_frame *frame, u8 rate) +unsigned int iwl3945_hw_get_beacon_cmd(struct iwl3945_priv *priv, + struct iwl3945_frame *frame, u8 rate) { - struct iwl_tx_beacon_cmd *tx_beacon_cmd; + struct iwl3945_tx_beacon_cmd *tx_beacon_cmd; unsigned int frame_size; - tx_beacon_cmd = (struct iwl_tx_beacon_cmd *)&frame->u; + tx_beacon_cmd = (struct iwl3945_tx_beacon_cmd *)&frame->u; memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd)); tx_beacon_cmd->tx.sta_id = IWL3945_BROADCAST_ID; tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; - frame_size = iwl_fill_beacon_frame(priv, + frame_size = iwl3945_fill_beacon_frame(priv, tx_beacon_cmd->frame, - BROADCAST_ADDR, + iwl3945_broadcast_addr, sizeof(frame->u) - sizeof(*tx_beacon_cmd)); BUG_ON(frame_size > MAX_MPDU_SIZE); @@ -2277,35 +2344,43 @@ unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv, tx_beacon_cmd->tx.supp_rates[1] = (IWL_CCK_BASIC_RATES_MASK & 0xF); - return (sizeof(struct iwl_tx_beacon_cmd) + frame_size); + return (sizeof(struct iwl3945_tx_beacon_cmd) + frame_size); } -void iwl_hw_rx_handler_setup(struct iwl_priv *priv) +void iwl3945_hw_rx_handler_setup(struct iwl3945_priv *priv) { priv->rx_handlers[REPLY_3945_RX] = iwl3945_rx_reply_rx; } -void iwl_hw_setup_deferred_work(struct iwl_priv *priv) +void iwl3945_hw_setup_deferred_work(struct iwl3945_priv *priv) { INIT_DELAYED_WORK(&priv->thermal_periodic, iwl3945_bg_reg_txpower_periodic); } -void iwl_hw_cancel_deferred_work(struct iwl_priv *priv) +void iwl3945_hw_cancel_deferred_work(struct iwl3945_priv *priv) { cancel_delayed_work(&priv->thermal_periodic); } -struct pci_device_id iwl_hw_card_ids[] = { - {0x8086, 0x4222, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, - {0x8086, 0x4227, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, +struct pci_device_id iwl3945_hw_card_ids[] = { + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4222)}, + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4227)}, {0} }; -inline int iwl_eeprom_aqcuire_semaphore(struct iwl_priv *priv) +/* + * Clear the OWNER_MSK, to establish driver (instead of uCode running on + * embedded controller) as EEPROM reader; each read is a series of pulses + * to/from the EEPROM chip, not a single event, so even reads could conflict + * if they weren't arbitrated by some ownership mechanism. Here, the driver + * simply claims ownership, which should be safe when this function is called + * (i.e. before loading uCode!). + */ +inline int iwl3945_eeprom_acquire_semaphore(struct iwl3945_priv *priv) { - _iwl_clear_bit(priv, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK); + _iwl3945_clear_bit(priv, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK); return 0; } -MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); +MODULE_DEVICE_TABLE(pci, iwl3945_hw_card_ids); diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h index 813902e9f8c..20b925f57e3 100644 --- a/drivers/net/wireless/iwlwifi/iwl-3945.h +++ b/drivers/net/wireless/iwlwifi/iwl-3945.h @@ -23,19 +23,955 @@ * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 * *****************************************************************************/ +/* + * Please use this file (iwl-3945.h) for driver implementation definitions. + * Please use iwl-3945-commands.h for uCode API definitions. + * Please use iwl-3945-hw.h for hardware-related definitions. + */ #ifndef __iwl_3945_h__ #define __iwl_3945_h__ +#include <linux/pci.h> /* for struct pci_device_id */ +#include <linux/kernel.h> +#include <net/ieee80211_radiotap.h> + +/* Hardware specific file defines the PCI IDs table for that hardware module */ +extern struct pci_device_id iwl3945_hw_card_ids[]; + +#define DRV_NAME "iwl3945" +#include "iwl-3945-hw.h" +#include "iwl-prph.h" +#include "iwl-3945-debug.h" + +/* Default noise level to report when noise measurement is not available. + * This may be because we're: + * 1) Not associated (4965, no beacon statistics being sent to driver) + * 2) Scanning (noise measurement does not apply to associated channel) + * 3) Receiving CCK (3945 delivers noise info only for OFDM frames) + * Use default noise value of -127 ... this is below the range of measurable + * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user. + * Also, -127 works better than 0 when averaging frames with/without + * noise info (e.g. averaging might be done in app); measured dBm values are + * always negative ... using a negative value as the default keeps all + * averages within an s8's (used in some apps) range of negative values. */ +#define IWL_NOISE_MEAS_NOT_AVAILABLE (-127) + +/* Module parameters accessible from iwl-*.c */ +extern int iwl3945_param_hwcrypto; +extern int iwl3945_param_queues_num; + +enum iwl3945_antenna { + IWL_ANTENNA_DIVERSITY, + IWL_ANTENNA_MAIN, + IWL_ANTENNA_AUX +}; + +/* + * RTS threshold here is total size [2347] minus 4 FCS bytes + * Per spec: + * a value of 0 means RTS on all data/management packets + * a value > max MSDU size means no RTS + * else RTS for data/management frames where MPDU is larger + * than RTS value. + */ +#define IWL_RX_BUF_SIZE 3000U +#define DEFAULT_RTS_THRESHOLD 2347U +#define MIN_RTS_THRESHOLD 0U +#define MAX_RTS_THRESHOLD 2347U +#define MAX_MSDU_SIZE 2304U +#define MAX_MPDU_SIZE 2346U +#define DEFAULT_BEACON_INTERVAL 100U +#define DEFAULT_SHORT_RETRY_LIMIT 7U +#define DEFAULT_LONG_RETRY_LIMIT 4U + +struct iwl3945_rx_mem_buffer { + dma_addr_t dma_addr; + struct sk_buff *skb; + struct list_head list; +}; + +/* + * Generic queue structure + * + * Contains common data for Rx and Tx queues + */ +struct iwl3945_queue { + int n_bd; /* number of BDs in this queue */ + int write_ptr; /* 1-st empty entry (index) host_w*/ + int read_ptr; /* last used entry (index) host_r*/ + dma_addr_t dma_addr; /* physical addr for BD's */ + int n_window; /* safe queue window */ + u32 id; + int low_mark; /* low watermark, resume queue if free + * space more than this */ + int high_mark; /* high watermark, stop queue if free + * space less than this */ +} __attribute__ ((packed)); + +#define MAX_NUM_OF_TBS (20) + +/* One for each TFD */ +struct iwl3945_tx_info { + struct ieee80211_tx_status status; + struct sk_buff *skb[MAX_NUM_OF_TBS]; +}; + +/** + * struct iwl3945_tx_queue - Tx Queue for DMA + * @q: generic Rx/Tx queue descriptor + * @bd: base of circular buffer of TFDs + * @cmd: array of command/Tx buffers + * @dma_addr_cmd: physical address of cmd/tx buffer array + * @txb: array of per-TFD driver data + * @need_update: indicates need to update read/write index + * + * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame + * descriptors) and required locking structures. + */ +struct iwl3945_tx_queue { + struct iwl3945_queue q; + struct iwl3945_tfd_frame *bd; + struct iwl3945_cmd *cmd; + dma_addr_t dma_addr_cmd; + struct iwl3945_tx_info *txb; + int need_update; + int active; +}; + +#define IWL_NUM_SCAN_RATES (2) + +struct iwl3945_channel_tgd_info { + u8 type; + s8 max_power; +}; + +struct iwl3945_channel_tgh_info { + s64 last_radar_time; +}; + +/* current Tx power values to use, one for each rate for each channel. + * requested power is limited by: + * -- regulatory EEPROM limits for this channel + * -- hardware capabilities (clip-powers) + * -- spectrum management + * -- user preference (e.g. iwconfig) + * when requested power is set, base power index must also be set. */ +struct iwl3945_channel_power_info { + struct iwl3945_tx_power tpc; /* actual radio and DSP gain settings */ + s8 power_table_index; /* actual (compenst'd) index into gain table */ + s8 base_power_index; /* gain index for power at factory temp. */ + s8 requested_power; /* power (dBm) requested for this chnl/rate */ +}; + +/* current scan Tx power values to use, one for each scan rate for each + * channel. */ +struct iwl3945_scan_power_info { + struct iwl3945_tx_power tpc; /* actual radio and DSP gain settings */ + s8 power_table_index; /* actual (compenst'd) index into gain table */ + s8 requested_power; /* scan pwr (dBm) requested for chnl/rate */ +}; + +/* + * One for each channel, holds all channel setup data + * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant + * with one another! + */ +#define IWL4965_MAX_RATE (33) + +struct iwl3945_channel_info { + struct iwl3945_channel_tgd_info tgd; + struct iwl3945_channel_tgh_info tgh; + struct iwl3945_eeprom_channel eeprom; /* EEPROM regulatory limit */ + struct iwl3945_eeprom_channel fat_eeprom; /* EEPROM regulatory limit for + * FAT channel */ + + u8 channel; /* channel number */ + u8 flags; /* flags copied from EEPROM */ + s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */ + s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) */ + s8 min_power; /* always 0 */ + s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */ + + u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */ + u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */ + u8 phymode; /* MODE_IEEE80211{A,B,G} */ + + /* Radio/DSP gain settings for each "normal" data Tx rate. + * These include, in addition to RF and DSP gain, a few fields for + * remembering/modifying gain settings (indexes). */ + struct iwl3945_channel_power_info power_info[IWL4965_MAX_RATE]; + + /* Radio/DSP gain settings for each scan rate, for directed scans. */ + struct iwl3945_scan_power_info scan_pwr_info[IWL_NUM_SCAN_RATES]; +}; + +struct iwl3945_clip_group { + /* maximum power level to prevent clipping for each rate, derived by + * us from this band's saturation power in EEPROM */ + const s8 clip_powers[IWL_MAX_RATES]; +}; + +#include "iwl-3945-rs.h" + +#define IWL_TX_FIFO_AC0 0 +#define IWL_TX_FIFO_AC1 1 +#define IWL_TX_FIFO_AC2 2 +#define IWL_TX_FIFO_AC3 3 +#define IWL_TX_FIFO_HCCA_1 5 +#define IWL_TX_FIFO_HCCA_2 6 +#define IWL_TX_FIFO_NONE 7 + +/* Minimum number of queues. MAX_NUM is defined in hw specific files */ +#define IWL_MIN_NUM_QUEUES 4 + +/* Power management (not Tx power) structures */ + +struct iwl3945_power_vec_entry { + struct iwl3945_powertable_cmd cmd; + u8 no_dtim; +}; +#define IWL_POWER_RANGE_0 (0) +#define IWL_POWER_RANGE_1 (1) + +#define IWL_POWER_MODE_CAM 0x00 /* Continuously Aware Mode, always on */ +#define IWL_POWER_INDEX_3 0x03 +#define IWL_POWER_INDEX_5 0x05 +#define IWL_POWER_AC 0x06 +#define IWL_POWER_BATTERY 0x07 +#define IWL_POWER_LIMIT 0x07 +#define IWL_POWER_MASK 0x0F +#define IWL_POWER_ENABLED 0x10 +#define IWL_POWER_LEVEL(x) ((x) & IWL_POWER_MASK) + +struct iwl3945_power_mgr { + spinlock_t lock; + struct iwl3945_power_vec_entry pwr_range_0[IWL_POWER_AC]; + struct iwl3945_power_vec_entry pwr_range_1[IWL_POWER_AC]; + u8 active_index; + u32 dtim_val; +}; + +#define IEEE80211_DATA_LEN 2304 +#define IEEE80211_4ADDR_LEN 30 +#define IEEE80211_HLEN (IEEE80211_4ADDR_LEN) +#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN) + +struct iwl3945_frame { + union { + struct ieee80211_hdr frame; + struct iwl3945_tx_beacon_cmd beacon; + u8 raw[IEEE80211_FRAME_LEN]; + u8 cmd[360]; + } u; + struct list_head list; +}; + +#define SEQ_TO_QUEUE(x) ((x >> 8) & 0xbf) +#define QUEUE_TO_SEQ(x) ((x & 0xbf) << 8) +#define SEQ_TO_INDEX(x) (x & 0xff) +#define INDEX_TO_SEQ(x) (x & 0xff) +#define SEQ_HUGE_FRAME (0x4000) +#define SEQ_RX_FRAME __constant_cpu_to_le16(0x8000) +#define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4) +#define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ) +#define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4) + +enum { + /* CMD_SIZE_NORMAL = 0, */ + CMD_SIZE_HUGE = (1 << 0), + /* CMD_SYNC = 0, */ + CMD_ASYNC = (1 << 1), + /* CMD_NO_SKB = 0, */ + CMD_WANT_SKB = (1 << 2), +}; + +struct iwl3945_cmd; +struct iwl3945_priv; + +struct iwl3945_cmd_meta { + struct iwl3945_cmd_meta *source; + union { + struct sk_buff *skb; + int (*callback)(struct iwl3945_priv *priv, + struct iwl3945_cmd *cmd, struct sk_buff *skb); + } __attribute__ ((packed)) u; + + /* The CMD_SIZE_HUGE flag bit indicates that the command + * structure is stored at the end of the shared queue memory. */ + u32 flags; + +} __attribute__ ((packed)); + +/** + * struct iwl3945_cmd + * + * For allocation of the command and tx queues, this establishes the overall + * size of the largest command we send to uCode, except for a scan command + * (which is relatively huge; space is allocated separately). + */ +struct iwl3945_cmd { + struct iwl3945_cmd_meta meta; + struct iwl3945_cmd_header hdr; + union { + struct iwl3945_addsta_cmd addsta; + struct iwl3945_led_cmd led; + u32 flags; + u8 val8; + u16 val16; + u32 val32; + struct iwl3945_bt_cmd bt; + struct iwl3945_rxon_time_cmd rxon_time; + struct iwl3945_powertable_cmd powertable; + struct iwl3945_qosparam_cmd qosparam; + struct iwl3945_tx_cmd tx; + struct iwl3945_tx_beacon_cmd tx_beacon; + struct iwl3945_rxon_assoc_cmd rxon_assoc; + u8 *indirect; + u8 payload[360]; + } __attribute__ ((packed)) cmd; +} __attribute__ ((packed)); + +struct iwl3945_host_cmd { + u8 id; + u16 len; + struct iwl3945_cmd_meta meta; + const void *data; +}; + +#define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl3945_cmd) - \ + sizeof(struct iwl3945_cmd_meta)) + +/* + * RX related structures and functions + */ +#define RX_FREE_BUFFERS 64 +#define RX_LOW_WATERMARK 8 + +#define SUP_RATE_11A_MAX_NUM_CHANNELS 8 +#define SUP_RATE_11B_MAX_NUM_CHANNELS 4 +#define SUP_RATE_11G_MAX_NUM_CHANNELS 12 + +/** + * struct iwl3945_rx_queue - Rx queue + * @processed: Internal index to last handled Rx packet + * @read: Shared index to newest available Rx buffer + * @write: Shared index to oldest written Rx packet + * @free_count: Number of pre-allocated buffers in rx_free + * @rx_free: list of free SKBs for use + * @rx_used: List of Rx buffers with no SKB + * @need_update: flag to indicate we need to update read/write index + * + * NOTE: rx_free and rx_used are used as a FIFO for iwl3945_rx_mem_buffers + */ +struct iwl3945_rx_queue { + __le32 *bd; + dma_addr_t dma_addr; + struct iwl3945_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS]; + struct iwl3945_rx_mem_buffer *queue[RX_QUEUE_SIZE]; + u32 processed; + u32 read; + u32 write; + u32 free_count; + struct list_head rx_free; + struct list_head rx_used; + int need_update; + spinlock_t lock; +}; + +#define IWL_SUPPORTED_RATES_IE_LEN 8 + +#define SCAN_INTERVAL 100 + +#define MAX_A_CHANNELS 252 +#define MIN_A_CHANNELS 7 + +#define MAX_B_CHANNELS 14 +#define MIN_B_CHANNELS 1 + +#define STATUS_HCMD_ACTIVE 0 /* host command in progress */ +#define STATUS_INT_ENABLED 1 +#define STATUS_RF_KILL_HW 2 +#define STATUS_RF_KILL_SW 3 +#define STATUS_INIT 4 +#define STATUS_ALIVE 5 +#define STATUS_READY 6 +#define STATUS_TEMPERATURE 7 +#define STATUS_GEO_CONFIGURED 8 +#define STATUS_EXIT_PENDING 9 +#define STATUS_IN_SUSPEND 10 +#define STATUS_STATISTICS 11 +#define STATUS_SCANNING 12 +#define STATUS_SCAN_ABORTING 13 +#define STATUS_SCAN_HW 14 +#define STATUS_POWER_PMI 15 +#define STATUS_FW_ERROR 16 +#define STATUS_CONF_PENDING 17 + +#define MAX_TID_COUNT 9 + +#define IWL_INVALID_RATE 0xFF +#define IWL_INVALID_VALUE -1 + +struct iwl3945_tid_data { + u16 seq_number; +}; + +struct iwl3945_hw_key { + enum ieee80211_key_alg alg; + int keylen; + u8 key[32]; +}; + +union iwl3945_ht_rate_supp { + u16 rates; + struct { + u8 siso_rate; + u8 mimo_rate; + }; +}; + +#ifdef CONFIG_IWL3945_QOS + +union iwl3945_qos_capabity { + struct { + u8 edca_count:4; /* bit 0-3 */ + u8 q_ack:1; /* bit 4 */ + u8 queue_request:1; /* bit 5 */ + u8 txop_request:1; /* bit 6 */ + u8 reserved:1; /* bit 7 */ + } q_AP; + struct { + u8 acvo_APSD:1; /* bit 0 */ + u8 acvi_APSD:1; /* bit 1 */ + u8 ac_bk_APSD:1; /* bit 2 */ + u8 ac_be_APSD:1; /* bit 3 */ + u8 q_ack:1; /* bit 4 */ + u8 max_len:2; /* bit 5-6 */ + u8 more_data_ack:1; /* bit 7 */ + } q_STA; + u8 val; +}; + +/* QoS structures */ +struct iwl3945_qos_info { + int qos_enable; + int qos_active; + union iwl3945_qos_capabity qos_cap; + struct iwl3945_qosparam_cmd def_qos_parm; +}; +#endif /*CONFIG_IWL3945_QOS */ + +#define STA_PS_STATUS_WAKE 0 +#define STA_PS_STATUS_SLEEP 1 + +struct iwl3945_station_entry { + struct iwl3945_addsta_cmd sta; + struct iwl3945_tid_data tid[MAX_TID_COUNT]; + union { + struct { + u8 rate; + u8 flags; + } s; + u16 rate_n_flags; + } current_rate; + u8 used; + u8 ps_status; + struct iwl3945_hw_key keyinfo; +}; + +/* one for each uCode image (inst/data, boot/init/runtime) */ +struct fw_desc { + void *v_addr; /* access by driver */ + dma_addr_t p_addr; /* access by card's busmaster DMA */ + u32 len; /* bytes */ +}; + +/* uCode file layout */ +struct iwl3945_ucode { + __le32 ver; /* major/minor/subminor */ + __le32 inst_size; /* bytes of runtime instructions */ + __le32 data_size; /* bytes of runtime data */ + __le32 init_size; /* bytes of initialization instructions */ + __le32 init_data_size; /* bytes of initialization data */ + __le32 boot_size; /* bytes of bootstrap instructions */ + u8 data[0]; /* data in same order as "size" elements */ +}; + +#define IWL_IBSS_MAC_HASH_SIZE 32 + +struct iwl3945_ibss_seq { + u8 mac[ETH_ALEN]; + u16 seq_num; + u16 frag_num; + unsigned long packet_time; + struct list_head list; +}; + +/** + * struct iwl3945_driver_hw_info + * @max_txq_num: Max # Tx queues supported + * @ac_queue_count: # Tx queues for EDCA Access Categories (AC) + * @tx_cmd_len: Size of Tx command (but not including frame itself) + * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2) + * @rx_buf_size: + * @max_pkt_size: + * @max_rxq_log: Log-base-2 of max_rxq_size + * @max_stations: + * @bcast_sta_id: + * @shared_virt: Pointer to driver/uCode shared Tx Byte Counts and Rx status + * @shared_phys: Physical Pointer to Tx Byte Counts and Rx status + */ +struct iwl3945_driver_hw_info { + u16 max_txq_num; + u16 ac_queue_count; + u16 tx_cmd_len; + u16 max_rxq_size; + u32 rx_buf_size; + u32 max_pkt_size; + u16 max_rxq_log; + u8 max_stations; + u8 bcast_sta_id; + void *shared_virt; + dma_addr_t shared_phys; +}; + +#define IWL_RX_HDR(x) ((struct iwl3945_rx_frame_hdr *)(\ + x->u.rx_frame.stats.payload + \ + x->u.rx_frame.stats.phy_count)) +#define IWL_RX_END(x) ((struct iwl3945_rx_frame_end *)(\ + IWL_RX_HDR(x)->payload + \ + le16_to_cpu(IWL_RX_HDR(x)->len))) +#define IWL_RX_STATS(x) (&x->u.rx_frame.stats) +#define IWL_RX_DATA(x) (IWL_RX_HDR(x)->payload) + + +/****************************************************************************** + * + * Functions implemented in iwl-base.c which are forward declared here + * for use by iwl-*.c + * + *****************************************************************************/ +struct iwl3945_addsta_cmd; +extern int iwl3945_send_add_station(struct iwl3945_priv *priv, + struct iwl3945_addsta_cmd *sta, u8 flags); +extern u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *bssid, + int is_ap, u8 flags); +extern int iwl3945_is_network_packet(struct iwl3945_priv *priv, + struct ieee80211_hdr *header); +extern int iwl3945_power_init_handle(struct iwl3945_priv *priv); +extern int iwl3945_eeprom_init(struct iwl3945_priv *priv); +#ifdef CONFIG_IWL3945_DEBUG +extern void iwl3945_report_frame(struct iwl3945_priv *priv, + struct iwl3945_rx_packet *pkt, + struct ieee80211_hdr *header, int group100); +#else +static inline void iwl3945_report_frame(struct iwl3945_priv *priv, + struct iwl3945_rx_packet *pkt, + struct ieee80211_hdr *header, + int group100) {} +#endif +extern void iwl3945_handle_data_packet_monitor(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb, + void *data, short len, + struct ieee80211_rx_status *stats, + u16 phy_flags); +extern int iwl3945_is_duplicate_packet(struct iwl3945_priv *priv, + struct ieee80211_hdr *header); +extern int iwl3945_rx_queue_alloc(struct iwl3945_priv *priv); +extern void iwl3945_rx_queue_reset(struct iwl3945_priv *priv, + struct iwl3945_rx_queue *rxq); +extern int iwl3945_calc_db_from_ratio(int sig_ratio); +extern int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm); +extern int iwl3945_tx_queue_init(struct iwl3945_priv *priv, + struct iwl3945_tx_queue *txq, int count, u32 id); +extern void iwl3945_rx_replenish(void *data); +extern void iwl3945_tx_queue_free(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq); +extern int iwl3945_send_cmd_pdu(struct iwl3945_priv *priv, u8 id, u16 len, + const void *data); +extern int __must_check iwl3945_send_cmd(struct iwl3945_priv *priv, + struct iwl3945_host_cmd *cmd); +extern unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv *priv, + struct ieee80211_hdr *hdr, + const u8 *dest, int left); +extern int iwl3945_rx_queue_update_write_ptr(struct iwl3945_priv *priv, + struct iwl3945_rx_queue *q); +extern int iwl3945_send_statistics_request(struct iwl3945_priv *priv); +extern void iwl3945_set_decrypted_flag(struct iwl3945_priv *priv, struct sk_buff *skb, + u32 decrypt_res, + struct ieee80211_rx_status *stats); +extern const u8 iwl3945_broadcast_addr[ETH_ALEN]; + +/* + * Currently used by iwl-3945-rs... look at restructuring so that it doesn't + * call this... todo... fix that. +*/ +extern u8 iwl3945_sync_station(struct iwl3945_priv *priv, int sta_id, + u16 tx_rate, u8 flags); + +/****************************************************************************** + * + * Functions implemented in iwl-[34]*.c which are forward declared here + * for use by iwl-base.c + * + * NOTE: The implementation of these functions are hardware specific + * which is why they are in the hardware specific files (vs. iwl-base.c) + * + * Naming convention -- + * iwl3945_ <-- Its part of iwlwifi (should be changed to iwl3945_) + * iwl3945_hw_ <-- Hardware specific (implemented in iwl-XXXX.c by all HW) + * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX) + * iwl3945_bg_ <-- Called from work queue context + * iwl3945_mac_ <-- mac80211 callback + * + ****************************************************************************/ +extern void iwl3945_hw_rx_handler_setup(struct iwl3945_priv *priv); +extern void iwl3945_hw_setup_deferred_work(struct iwl3945_priv *priv); +extern void iwl3945_hw_cancel_deferred_work(struct iwl3945_priv *priv); +extern int iwl3945_hw_rxq_stop(struct iwl3945_priv *priv); +extern int iwl3945_hw_set_hw_setting(struct iwl3945_priv *priv); +extern int iwl3945_hw_nic_init(struct iwl3945_priv *priv); +extern int iwl3945_hw_nic_stop_master(struct iwl3945_priv *priv); +extern void iwl3945_hw_txq_ctx_free(struct iwl3945_priv *priv); +extern void iwl3945_hw_txq_ctx_stop(struct iwl3945_priv *priv); +extern int iwl3945_hw_nic_reset(struct iwl3945_priv *priv); +extern int iwl3945_hw_txq_attach_buf_to_tfd(struct iwl3945_priv *priv, void *tfd, + dma_addr_t addr, u16 len); +extern int iwl3945_hw_txq_free_tfd(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq); +extern int iwl3945_hw_get_temperature(struct iwl3945_priv *priv); +extern int iwl3945_hw_tx_queue_init(struct iwl3945_priv *priv, + struct iwl3945_tx_queue *txq); +extern unsigned int iwl3945_hw_get_beacon_cmd(struct iwl3945_priv *priv, + struct iwl3945_frame *frame, u8 rate); +extern int iwl3945_hw_get_rx_read(struct iwl3945_priv *priv); +extern void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv, + struct iwl3945_cmd *cmd, + struct ieee80211_tx_control *ctrl, + struct ieee80211_hdr *hdr, + int sta_id, int tx_id); +extern int iwl3945_hw_reg_send_txpower(struct iwl3945_priv *priv); +extern int iwl3945_hw_reg_set_txpower(struct iwl3945_priv *priv, s8 power); +extern void iwl3945_hw_rx_statistics(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb); +extern void iwl3945_disable_events(struct iwl3945_priv *priv); +extern int iwl4965_get_temperature(const struct iwl3945_priv *priv); + +/** + * iwl3945_hw_find_station - Find station id for a given BSSID + * @bssid: MAC address of station ID to find + * + * NOTE: This should not be hardware specific but the code has + * not yet been merged into a single common layer for managing the + * station tables. + */ +extern u8 iwl3945_hw_find_station(struct iwl3945_priv *priv, const u8 *bssid); + +extern int iwl3945_hw_channel_switch(struct iwl3945_priv *priv, u16 channel); + /* * Forward declare iwl-3945.c functions for iwl-base.c */ -extern int iwl_eeprom_aqcuire_semaphore(struct iwl_priv *priv); -extern __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv); -extern int iwl3945_init_hw_rate_table(struct iwl_priv *priv); -extern void iwl3945_reg_txpower_periodic(struct iwl_priv *priv); -extern void iwl3945_bg_reg_txpower_periodic(struct work_struct *work); -extern int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv); -extern u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id, +extern int iwl3945_eeprom_acquire_semaphore(struct iwl3945_priv *priv); +extern __le32 iwl3945_get_antenna_flags(const struct iwl3945_priv *priv); +extern int iwl3945_init_hw_rate_table(struct iwl3945_priv *priv); +extern void iwl3945_reg_txpower_periodic(struct iwl3945_priv *priv); +extern int iwl3945_txpower_set_from_eeprom(struct iwl3945_priv *priv); +extern u8 iwl3945_sync_sta(struct iwl3945_priv *priv, int sta_id, u16 tx_rate, u8 flags); + + +#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT + +enum { + MEASUREMENT_READY = (1 << 0), + MEASUREMENT_ACTIVE = (1 << 1), +}; + +#endif + +struct iwl3945_priv { + + /* ieee device used by generic ieee processing code */ + struct ieee80211_hw *hw; + struct ieee80211_channel *ieee_channels; + struct ieee80211_rate *ieee_rates; + + /* temporary frame storage list */ + struct list_head free_frames; + int frames_count; + + u8 phymode; + int alloc_rxb_skb; + bool add_radiotap; + + void (*rx_handlers[REPLY_MAX])(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb); + + const struct ieee80211_hw_mode *modes; + +#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT + /* spectrum measurement report caching */ + struct iwl3945_spectrum_notification measure_report; + u8 measurement_status; +#endif + /* ucode beacon time */ + u32 ucode_beacon_time; + + /* we allocate array of iwl3945_channel_info for NIC's valid channels. + * Access via channel # using indirect index array */ + struct iwl3945_channel_info *channel_info; /* channel info array */ + u8 channel_count; /* # of channels */ + + /* each calibration channel group in the EEPROM has a derived + * clip setting for each rate. */ + const struct iwl3945_clip_group clip_groups[5]; + + /* thermal calibration */ + s32 temperature; /* degrees Kelvin */ + s32 last_temperature; + + /* Scan related variables */ + unsigned long last_scan_jiffies; + unsigned long next_scan_jiffies; + unsigned long scan_start; + unsigned long scan_pass_start; + unsigned long scan_start_tsf; + int scan_bands; + int one_direct_scan; + u8 direct_ssid_len; + u8 direct_ssid[IW_ESSID_MAX_SIZE]; + struct iwl3945_scan_cmd *scan; + u8 only_active_channel; + + /* spinlock */ + spinlock_t lock; /* protect general shared data */ + spinlock_t hcmd_lock; /* protect hcmd */ + struct mutex mutex; + + /* basic pci-network driver stuff */ + struct pci_dev *pci_dev; + + /* pci hardware address support */ + void __iomem *hw_base; + + /* uCode images, save to reload in case of failure */ + struct fw_desc ucode_code; /* runtime inst */ + struct fw_desc ucode_data; /* runtime data original */ + struct fw_desc ucode_data_backup; /* runtime data save/restore */ + struct fw_desc ucode_init; /* initialization inst */ + struct fw_desc ucode_init_data; /* initialization data */ + struct fw_desc ucode_boot; /* bootstrap inst */ + + + struct iwl3945_rxon_time_cmd rxon_timing; + + /* We declare this const so it can only be + * changed via explicit cast within the + * routines that actually update the physical + * hardware */ + const struct iwl3945_rxon_cmd active_rxon; + struct iwl3945_rxon_cmd staging_rxon; + + int error_recovering; + struct iwl3945_rxon_cmd recovery_rxon; + + /* 1st responses from initialize and runtime uCode images. + * 4965's initialize alive response contains some calibration data. */ + struct iwl3945_init_alive_resp card_alive_init; + struct iwl3945_alive_resp card_alive; + +#ifdef LED + /* LED related variables */ + struct iwl3945_activity_blink activity; + unsigned long led_packets; + int led_state; +#endif + + u16 active_rate; + u16 active_rate_basic; + + u8 call_post_assoc_from_beacon; + u8 assoc_station_added; + /* Rate scaling data */ + s8 data_retry_limit; + u8 retry_rate; + + wait_queue_head_t wait_command_queue; + + int activity_timer_active; + + /* Rx and Tx DMA processing queues */ + struct iwl3945_rx_queue rxq; + struct iwl3945_tx_queue txq[IWL_MAX_NUM_QUEUES]; + + unsigned long status; + u32 config; + + int last_rx_rssi; /* From Rx packet statisitics */ + int last_rx_noise; /* From beacon statistics */ + + struct iwl3945_power_mgr power_data; + + struct iwl3945_notif_statistics statistics; + unsigned long last_statistics_time; + + /* context information */ + u8 essid[IW_ESSID_MAX_SIZE]; + u8 essid_len; + u16 rates_mask; + + u32 power_mode; + u32 antenna; + u8 bssid[ETH_ALEN]; + u16 rts_threshold; + u8 mac_addr[ETH_ALEN]; + + /*station table variables */ + spinlock_t sta_lock; + int num_stations; + struct iwl3945_station_entry stations[IWL_STATION_COUNT]; + + /* Indication if ieee80211_ops->open has been called */ + int is_open; + + u8 mac80211_registered; + int is_abg; + + u32 notif_missed_beacons; + + /* Rx'd packet timing information */ + u32 last_beacon_time; + u64 last_tsf; + + /* Duplicate packet detection */ + u16 last_seq_num; + u16 last_frag_num; + unsigned long last_packet_time; + + /* Hash table for finding stations in IBSS network */ + struct list_head ibss_mac_hash[IWL_IBSS_MAC_HASH_SIZE]; + + /* eeprom */ + struct iwl3945_eeprom eeprom; + + int iw_mode; + + struct sk_buff *ibss_beacon; + + /* Last Rx'd beacon timestamp */ + u32 timestamp0; + u32 timestamp1; + u16 beacon_int; + struct iwl3945_driver_hw_info hw_setting; + struct ieee80211_vif *vif; + + /* Current association information needed to configure the + * hardware */ + u16 assoc_id; + u16 assoc_capability; + u8 ps_mode; + +#ifdef CONFIG_IWL3945_QOS + struct iwl3945_qos_info qos_data; +#endif /*CONFIG_IWL3945_QOS */ + + struct workqueue_struct *workqueue; + + struct work_struct up; + struct work_struct restart; + struct work_struct calibrated_work; + struct work_struct scan_completed; + struct work_struct rx_replenish; + struct work_struct rf_kill; + struct work_struct abort_scan; + struct work_struct update_link_led; + struct work_struct auth_work; + struct work_struct report_work; + struct work_struct request_scan; + struct work_struct beacon_update; + + struct tasklet_struct irq_tasklet; + + struct delayed_work init_alive_start; + struct delayed_work alive_start; + struct delayed_work activity_timer; + struct delayed_work thermal_periodic; + struct delayed_work gather_stats; + struct delayed_work scan_check; + struct delayed_work post_associate; + +#define IWL_DEFAULT_TX_POWER 0x0F + s8 user_txpower_limit; + s8 max_channel_txpower_limit; + +#ifdef CONFIG_PM + u32 pm_state[16]; +#endif + +#ifdef CONFIG_IWL3945_DEBUG + /* debugging info */ + u32 framecnt_to_us; + atomic_t restrict_refcnt; +#endif +}; /*iwl3945_priv */ + +static inline int iwl3945_is_associated(struct iwl3945_priv *priv) +{ + return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0; +} + +static inline int is_channel_valid(const struct iwl3945_channel_info *ch_info) +{ + if (ch_info == NULL) + return 0; + return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0; +} + +static inline int is_channel_narrow(const struct iwl3945_channel_info *ch_info) +{ + return (ch_info->flags & EEPROM_CHANNEL_NARROW) ? 1 : 0; +} + +static inline int is_channel_radar(const struct iwl3945_channel_info *ch_info) +{ + return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0; +} + +static inline u8 is_channel_a_band(const struct iwl3945_channel_info *ch_info) +{ + return ch_info->phymode == MODE_IEEE80211A; +} + +static inline u8 is_channel_bg_band(const struct iwl3945_channel_info *ch_info) +{ + return ((ch_info->phymode == MODE_IEEE80211B) || + (ch_info->phymode == MODE_IEEE80211G)); +} + +static inline int is_channel_passive(const struct iwl3945_channel_info *ch) +{ + return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0; +} + +static inline int is_channel_ibss(const struct iwl3945_channel_info *ch) +{ + return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0; +} + +static inline int iwl3945_rate_index_from_plcp(int plcp) +{ + int i; + + for (i = 0; i < IWL_RATE_COUNT; i++) + if (iwl3945_rates[i].plcp == plcp) + return i; + return -1; +} + +extern const struct iwl3945_channel_info *iwl3945_get_channel_info( + const struct iwl3945_priv *priv, int phymode, u16 channel); + +/* Requires full declaration of iwl3945_priv before including */ +#include "iwl-3945-io.h" + #endif diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-commands.h b/drivers/net/wireless/iwlwifi/iwl-4965-commands.h new file mode 100644 index 00000000000..f3470c896d9 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/iwl-4965-commands.h @@ -0,0 +1,2651 @@ +/****************************************************************************** + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, + * USA + * + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * James P. Ketrenos <ipw2100-admin@linux.intel.com> + * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 + * + * BSD LICENSE + * + * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *****************************************************************************/ +/* + * Please use this file (iwl-4965-commands.h) only for uCode API definitions. + * Please use iwl-4965-hw.h for hardware-related definitions. + * Please use iwl-4965.h for driver implementation definitions. + */ + +#ifndef __iwl4965_commands_h__ +#define __iwl4965_commands_h__ + +enum { + REPLY_ALIVE = 0x1, + REPLY_ERROR = 0x2, + + /* RXON and QOS commands */ + REPLY_RXON = 0x10, + REPLY_RXON_ASSOC = 0x11, + REPLY_QOS_PARAM = 0x13, + REPLY_RXON_TIMING = 0x14, + + /* Multi-Station support */ + REPLY_ADD_STA = 0x18, + REPLY_REMOVE_STA = 0x19, /* not used */ + REPLY_REMOVE_ALL_STA = 0x1a, /* not used */ + + /* RX, TX, LEDs */ + REPLY_TX = 0x1c, + REPLY_RATE_SCALE = 0x47, /* 3945 only */ + REPLY_LEDS_CMD = 0x48, + REPLY_TX_LINK_QUALITY_CMD = 0x4e, /* 4965 only */ + + /* 802.11h related */ + RADAR_NOTIFICATION = 0x70, /* not used */ + REPLY_QUIET_CMD = 0x71, /* not used */ + REPLY_CHANNEL_SWITCH = 0x72, + CHANNEL_SWITCH_NOTIFICATION = 0x73, + REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74, + SPECTRUM_MEASURE_NOTIFICATION = 0x75, + + /* Power Management */ + POWER_TABLE_CMD = 0x77, + PM_SLEEP_NOTIFICATION = 0x7A, + PM_DEBUG_STATISTIC_NOTIFIC = 0x7B, + + /* Scan commands and notifications */ + REPLY_SCAN_CMD = 0x80, + REPLY_SCAN_ABORT_CMD = 0x81, + SCAN_START_NOTIFICATION = 0x82, + SCAN_RESULTS_NOTIFICATION = 0x83, + SCAN_COMPLETE_NOTIFICATION = 0x84, + + /* IBSS/AP commands */ + BEACON_NOTIFICATION = 0x90, + REPLY_TX_BEACON = 0x91, + WHO_IS_AWAKE_NOTIFICATION = 0x94, /* not used */ + + /* Miscellaneous commands */ + QUIET_NOTIFICATION = 0x96, /* not used */ + REPLY_TX_PWR_TABLE_CMD = 0x97, + MEASURE_ABORT_NOTIFICATION = 0x99, /* not used */ + + /* Bluetooth device coexistance config command */ + REPLY_BT_CONFIG = 0x9b, + + /* Statistics */ + REPLY_STATISTICS_CMD = 0x9c, + STATISTICS_NOTIFICATION = 0x9d, + + /* RF-KILL commands and notifications */ + REPLY_CARD_STATE_CMD = 0xa0, + CARD_STATE_NOTIFICATION = 0xa1, + + /* Missed beacons notification */ + MISSED_BEACONS_NOTIFICATION = 0xa2, + + REPLY_CT_KILL_CONFIG_CMD = 0xa4, + SENSITIVITY_CMD = 0xa8, + REPLY_PHY_CALIBRATION_CMD = 0xb0, + REPLY_RX_PHY_CMD = 0xc0, + REPLY_RX_MPDU_CMD = 0xc1, + REPLY_4965_RX = 0xc3, + REPLY_COMPRESSED_BA = 0xc5, + REPLY_MAX = 0xff +}; + +/****************************************************************************** + * (0) + * Commonly used structures and definitions: + * Command header, rate_n_flags, txpower + * + *****************************************************************************/ + +/* iwl4965_cmd_header flags value */ +#define IWL_CMD_FAILED_MSK 0x40 + +/** + * struct iwl4965_cmd_header + * + * This header format appears in the beginning of each command sent from the + * driver, and each response/notification received from uCode. + */ +struct iwl4965_cmd_header { + u8 cmd; /* Command ID: REPLY_RXON, etc. */ + u8 flags; /* IWL_CMD_* */ + /* + * The driver sets up the sequence number to values of its chosing. + * uCode does not use this value, but passes it back to the driver + * when sending the response to each driver-originated command, so + * the driver can match the response to the command. Since the values + * don't get used by uCode, the driver may set up an arbitrary format. + * + * There is one exception: uCode sets bit 15 when it originates + * the response/notification, i.e. when the response/notification + * is not a direct response to a command sent by the driver. For + * example, uCode issues REPLY_3945_RX when it sends a received frame + * to the driver; it is not a direct response to any driver command. + * + * The Linux driver uses the following format: + * + * 0:7 index/position within Tx queue + * 8:13 Tx queue selection + * 14:14 driver sets this to indicate command is in the 'huge' + * storage at the end of the command buffers, i.e. scan cmd + * 15:15 uCode sets this in uCode-originated response/notification + */ + __le16 sequence; + + /* command or response/notification data follows immediately */ + u8 data[0]; +} __attribute__ ((packed)); + +/** + * 4965 rate_n_flags bit fields + * + * rate_n_flags format is used in following 4965 commands: + * REPLY_4965_RX (response only) + * REPLY_TX (both command and response) + * REPLY_TX_LINK_QUALITY_CMD + * + * High-throughput (HT) rate format for bits 7:0 (bit 8 must be "1"): + * 2-0: 0) 6 Mbps + * 1) 12 Mbps + * 2) 18 Mbps + * 3) 24 Mbps + * 4) 36 Mbps + * 5) 48 Mbps + * 6) 54 Mbps + * 7) 60 Mbps + * + * 3: 0) Single stream (SISO) + * 1) Dual stream (MIMO) + * + * 5: Value of 0x20 in bits 7:0 indicates 6 Mbps FAT duplicate data + * + * Legacy OFDM rate format for bits 7:0 (bit 8 must be "0", bit 9 "0"): + * 3-0: 0xD) 6 Mbps + * 0xF) 9 Mbps + * 0x5) 12 Mbps + * 0x7) 18 Mbps + * 0x9) 24 Mbps + * 0xB) 36 Mbps + * 0x1) 48 Mbps + * 0x3) 54 Mbps + * + * Legacy CCK rate format for bits 7:0 (bit 8 must be "0", bit 9 "1"): + * 3-0: 10) 1 Mbps + * 20) 2 Mbps + * 55) 5.5 Mbps + * 110) 11 Mbps + */ +#define RATE_MCS_CODE_MSK 0x7 +#define RATE_MCS_MIMO_POS 3 +#define RATE_MCS_MIMO_MSK 0x8 +#define RATE_MCS_HT_DUP_POS 5 +#define RATE_MCS_HT_DUP_MSK 0x20 + +/* Bit 8: (1) HT format, (0) legacy format in bits 7:0 */ +#define RATE_MCS_FLAGS_POS 8 +#define RATE_MCS_HT_POS 8 +#define RATE_MCS_HT_MSK 0x100 + +/* Bit 9: (1) CCK, (0) OFDM. HT (bit 8) must be "0" for this bit to be valid */ +#define RATE_MCS_CCK_POS 9 +#define RATE_MCS_CCK_MSK 0x200 + +/* Bit 10: (1) Use Green Field preamble */ +#define RATE_MCS_GF_POS 10 +#define RATE_MCS_GF_MSK 0x400 + +/* Bit 11: (1) Use 40Mhz FAT chnl width, (0) use 20 MHz legacy chnl width */ +#define RATE_MCS_FAT_POS 11 +#define RATE_MCS_FAT_MSK 0x800 + +/* Bit 12: (1) Duplicate data on both 20MHz chnls. FAT (bit 11) must be set. */ +#define RATE_MCS_DUP_POS 12 +#define RATE_MCS_DUP_MSK 0x1000 + +/* Bit 13: (1) Short guard interval (0.4 usec), (0) normal GI (0.8 usec) */ +#define RATE_MCS_SGI_POS 13 +#define RATE_MCS_SGI_MSK 0x2000 + +/** + * rate_n_flags Tx antenna masks (4965 has 2 transmitters): + * bit14:15 01 B inactive, A active + * 10 B active, A inactive + * 11 Both active + */ +#define RATE_MCS_ANT_A_POS 14 +#define RATE_MCS_ANT_B_POS 15 +#define RATE_MCS_ANT_A_MSK 0x4000 +#define RATE_MCS_ANT_B_MSK 0x8000 +#define RATE_MCS_ANT_AB_MSK 0xc000 + + +/** + * struct iwl4965_tx_power - txpower format used in REPLY_SCAN_CMD + * + * Scan uses only one transmitter, so only one analog/dsp gain pair is needed. + */ +struct iwl4965_tx_power { + u8 tx_gain; /* gain for analog radio */ + u8 dsp_atten; /* gain for DSP */ +} __attribute__ ((packed)); + +#define POWER_TABLE_NUM_ENTRIES 33 +#define POWER_TABLE_NUM_HT_OFDM_ENTRIES 32 +#define POWER_TABLE_CCK_ENTRY 32 + +/** + * union iwl4965_tx_power_dual_stream + * + * Host format used for REPLY_TX_PWR_TABLE_CMD, REPLY_CHANNEL_SWITCH + * Use __le32 version (struct tx_power_dual_stream) when building command. + * + * Driver provides radio gain and DSP attenuation settings to device in pairs, + * one value for each transmitter chain. The first value is for transmitter A, + * second for transmitter B. + * + * For SISO bit rates, both values in a pair should be identical. + * For MIMO rates, one value may be different from the other, + * in order to balance the Tx output between the two transmitters. + * + * See more details in doc for TXPOWER in iwl-4965-hw.h. + */ +union iwl4965_tx_power_dual_stream { + struct { + u8 radio_tx_gain[2]; + u8 dsp_predis_atten[2]; + } s; + u32 dw; +}; + +/** + * struct tx_power_dual_stream + * + * Table entries in REPLY_TX_PWR_TABLE_CMD, REPLY_CHANNEL_SWITCH + * + * Same format as iwl_tx_power_dual_stream, but __le32 + */ +struct tx_power_dual_stream { + __le32 dw; +} __attribute__ ((packed)); + +/** + * struct iwl4965_tx_power_db + * + * Entire table within REPLY_TX_PWR_TABLE_CMD, REPLY_CHANNEL_SWITCH + */ +struct iwl4965_tx_power_db { + struct tx_power_dual_stream power_tbl[POWER_TABLE_NUM_ENTRIES]; +} __attribute__ ((packed)); + + +/****************************************************************************** + * (0a) + * Alive and Error Commands & Responses: + * + *****************************************************************************/ + +#define UCODE_VALID_OK __constant_cpu_to_le32(0x1) +#define INITIALIZE_SUBTYPE (9) + +/* + * ("Initialize") REPLY_ALIVE = 0x1 (response only, not a command) + * + * uCode issues this "initialize alive" notification once the initialization + * uCode image has completed its work, and is ready to load the runtime image. + * This is the *first* "alive" notification that the driver will receive after + * rebooting uCode; the "initialize" alive is indicated by subtype field == 9. + * + * See comments documenting "BSM" (bootstrap state machine). + * + * For 4965, this notification contains important calibration data for + * calculating txpower settings: + * + * 1) Power supply voltage indication. The voltage sensor outputs higher + * values for lower voltage, and vice versa. + * + * 2) Temperature measurement parameters, for each of two channel widths + * (20 MHz and 40 MHz) supported by the radios. Temperature sensing + * is done via one of the receiver chains, and channel width influences + * the results. + * + * 3) Tx gain compensation to balance 4965's 2 Tx chains for MIMO operation, + * for each of 5 frequency ranges. + */ +struct iwl4965_init_alive_resp { + u8 ucode_minor; + u8 ucode_major; + __le16 reserved1; + u8 sw_rev[8]; + u8 ver_type; + u8 ver_subtype; /* "9" for initialize alive */ + __le16 reserved2; + __le32 log_event_table_ptr; + __le32 error_event_table_ptr; + __le32 timestamp; + __le32 is_valid; + + /* calibration values from "initialize" uCode */ + __le32 voltage; /* signed, higher value is lower voltage */ + __le32 therm_r1[2]; /* signed, 1st for normal, 2nd for FAT channel*/ + __le32 therm_r2[2]; /* signed */ + __le32 therm_r3[2]; /* signed */ + __le32 therm_r4[2]; /* signed */ + __le32 tx_atten[5][2]; /* signed MIMO gain comp, 5 freq groups, + * 2 Tx chains */ +} __attribute__ ((packed)); + + +/** + * REPLY_ALIVE = 0x1 (response only, not a command) + * + * uCode issues this "alive" notification once the runtime image is ready + * to receive commands from the driver. This is the *second* "alive" + * notification that the driver will receive after rebooting uCode; + * this "alive" is indicated by subtype field != 9. + * + * See comments documenting "BSM" (bootstrap state machine). + * + * This response includes two pointers to structures within the device's + * data SRAM (access via HBUS_TARG_MEM_* regs) that are useful for debugging: + * + * 1) log_event_table_ptr indicates base of the event log. This traces + * a 256-entry history of uCode execution within a circular buffer. + * Its header format is: + * + * __le32 log_size; log capacity (in number of entries) + * __le32 type; (1) timestamp with each entry, (0) no timestamp + * __le32 wraps; # times uCode has wrapped to top of circular buffer + * __le32 write_index; next circular buffer entry that uCode would fill + * + * The header is followed by the circular buffer of log entries. Entries + * with timestamps have the following format: + * + * __le32 event_id; range 0 - 1500 + * __le32 timestamp; low 32 bits of TSF (of network, if associated) + * __le32 data; event_id-specific data value + * + * Entries without timestamps contain only event_id and data. + * + * 2) error_event_table_ptr indicates base of the error log. This contains + * information about any uCode error that occurs. For 4965, the format + * of the error log is: + * + * __le32 valid; (nonzero) valid, (0) log is empty + * __le32 error_id; type of error + * __le32 pc; program counter + * __le32 blink1; branch link + * __le32 blink2; branch link + * __le32 ilink1; interrupt link + * __le32 ilink2; interrupt link + * __le32 data1; error-specific data + * __le32 data2; error-specific data + * __le32 line; source code line of error + * __le32 bcon_time; beacon timer + * __le32 tsf_low; network timestamp function timer + * __le32 tsf_hi; network timestamp function timer + * + * The Linux driver can print both logs to the system log when a uCode error + * occurs. + */ +struct iwl4965_alive_resp { + u8 ucode_minor; + u8 ucode_major; + __le16 reserved1; + u8 sw_rev[8]; + u8 ver_type; + u8 ver_subtype; /* not "9" for runtime alive */ + __le16 reserved2; + __le32 log_event_table_ptr; /* SRAM address for event log */ + __le32 error_event_table_ptr; /* SRAM address for error log */ + __le32 timestamp; + __le32 is_valid; +} __attribute__ ((packed)); + + +union tsf { + u8 byte[8]; + __le16 word[4]; + __le32 dw[2]; +}; + +/* + * REPLY_ERROR = 0x2 (response only, not a command) + */ +struct iwl4965_error_resp { + __le32 error_type; + u8 cmd_id; + u8 reserved1; + __le16 bad_cmd_seq_num; + __le32 error_info; + union tsf timestamp; +} __attribute__ ((packed)); + +/****************************************************************************** + * (1) + * RXON Commands & Responses: + * + *****************************************************************************/ + +/* + * Rx config defines & structure + */ +/* rx_config device types */ +enum { + RXON_DEV_TYPE_AP = 1, + RXON_DEV_TYPE_ESS = 3, + RXON_DEV_TYPE_IBSS = 4, + RXON_DEV_TYPE_SNIFFER = 6, +}; + + +#define RXON_RX_CHAIN_DRIVER_FORCE_MSK __constant_cpu_to_le16(0x1 << 0) +#define RXON_RX_CHAIN_VALID_MSK __constant_cpu_to_le16(0x7 << 1) +#define RXON_RX_CHAIN_VALID_POS (1) +#define RXON_RX_CHAIN_FORCE_SEL_MSK __constant_cpu_to_le16(0x7 << 4) +#define RXON_RX_CHAIN_FORCE_SEL_POS (4) +#define RXON_RX_CHAIN_FORCE_MIMO_SEL_MSK __constant_cpu_to_le16(0x7 << 7) +#define RXON_RX_CHAIN_FORCE_MIMO_SEL_POS (7) +#define RXON_RX_CHAIN_CNT_MSK __constant_cpu_to_le16(0x3 << 10) +#define RXON_RX_CHAIN_CNT_POS (10) +#define RXON_RX_CHAIN_MIMO_CNT_MSK __constant_cpu_to_le16(0x3 << 12) +#define RXON_RX_CHAIN_MIMO_CNT_POS (12) +#define RXON_RX_CHAIN_MIMO_FORCE_MSK __constant_cpu_to_le16(0x1 << 14) +#define RXON_RX_CHAIN_MIMO_FORCE_POS (14) + +/* rx_config flags */ +/* band & modulation selection */ +#define RXON_FLG_BAND_24G_MSK __constant_cpu_to_le32(1 << 0) +#define RXON_FLG_CCK_MSK __constant_cpu_to_le32(1 << 1) +/* auto detection enable */ +#define RXON_FLG_AUTO_DETECT_MSK __constant_cpu_to_le32(1 << 2) +/* TGg protection when tx */ +#define RXON_FLG_TGG_PROTECT_MSK __constant_cpu_to_le32(1 << 3) +/* cck short slot & preamble */ +#define RXON_FLG_SHORT_SLOT_MSK __constant_cpu_to_le32(1 << 4) +#define RXON_FLG_SHORT_PREAMBLE_MSK __constant_cpu_to_le32(1 << 5) +/* antenna selection */ +#define RXON_FLG_DIS_DIV_MSK __constant_cpu_to_le32(1 << 7) +#define RXON_FLG_ANT_SEL_MSK __constant_cpu_to_le32(0x0f00) +#define RXON_FLG_ANT_A_MSK __constant_cpu_to_le32(1 << 8) +#define RXON_FLG_ANT_B_MSK __constant_cpu_to_le32(1 << 9) +/* radar detection enable */ +#define RXON_FLG_RADAR_DETECT_MSK __constant_cpu_to_le32(1 << 12) +#define RXON_FLG_TGJ_NARROW_BAND_MSK __constant_cpu_to_le32(1 << 13) +/* rx response to host with 8-byte TSF +* (according to ON_AIR deassertion) */ +#define RXON_FLG_TSF2HOST_MSK __constant_cpu_to_le32(1 << 15) + + +/* HT flags */ +#define RXON_FLG_CTRL_CHANNEL_LOC_POS (22) +#define RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK __constant_cpu_to_le32(0x1 << 22) + +#define RXON_FLG_HT_OPERATING_MODE_POS (23) + +#define RXON_FLG_HT_PROT_MSK __constant_cpu_to_le32(0x1 << 23) +#define RXON_FLG_FAT_PROT_MSK __constant_cpu_to_le32(0x2 << 23) + +#define RXON_FLG_CHANNEL_MODE_POS (25) +#define RXON_FLG_CHANNEL_MODE_MSK __constant_cpu_to_le32(0x3 << 25) +#define RXON_FLG_CHANNEL_MODE_PURE_40_MSK __constant_cpu_to_le32(0x1 << 25) +#define RXON_FLG_CHANNEL_MODE_MIXED_MSK __constant_cpu_to_le32(0x2 << 25) + +/* rx_config filter flags */ +/* accept all data frames */ +#define RXON_FILTER_PROMISC_MSK __constant_cpu_to_le32(1 << 0) +/* pass control & management to host */ +#define RXON_FILTER_CTL2HOST_MSK __constant_cpu_to_le32(1 << 1) +/* accept multi-cast */ +#define RXON_FILTER_ACCEPT_GRP_MSK __constant_cpu_to_le32(1 << 2) +/* don't decrypt uni-cast frames */ +#define RXON_FILTER_DIS_DECRYPT_MSK __constant_cpu_to_le32(1 << 3) +/* don't decrypt multi-cast frames */ +#define RXON_FILTER_DIS_GRP_DECRYPT_MSK __constant_cpu_to_le32(1 << 4) +/* STA is associated */ +#define RXON_FILTER_ASSOC_MSK __constant_cpu_to_le32(1 << 5) +/* transfer to host non bssid beacons in associated state */ +#define RXON_FILTER_BCON_AWARE_MSK __constant_cpu_to_le32(1 << 6) + +/** + * REPLY_RXON = 0x10 (command, has simple generic response) + * + * RXON tunes the radio tuner to a service channel, and sets up a number + * of parameters that are used primarily for Rx, but also for Tx operations. + * + * NOTE: When tuning to a new channel, driver must set the + * RXON_FILTER_ASSOC_MSK to 0. This will clear station-dependent + * info within the device, including the station tables, tx retry + * rate tables, and txpower tables. Driver must build a new station + * table and txpower table before transmitting anything on the RXON + * channel. + * + * NOTE: All RXONs wipe clean the internal txpower table. Driver must + * issue a new REPLY_TX_PWR_TABLE_CMD after each REPLY_RXON (0x10), + * regardless of whether RXON_FILTER_ASSOC_MSK is set. + */ +struct iwl4965_rxon_cmd { + u8 node_addr[6]; + __le16 reserved1; + u8 bssid_addr[6]; + __le16 reserved2; + u8 wlap_bssid_addr[6]; + __le16 reserved3; + u8 dev_type; + u8 air_propagation; + __le16 rx_chain; + u8 ofdm_basic_rates; + u8 cck_basic_rates; + __le16 assoc_id; + __le32 flags; + __le32 filter_flags; + __le16 channel; + u8 ofdm_ht_single_stream_basic_rates; + u8 ofdm_ht_dual_stream_basic_rates; +} __attribute__ ((packed)); + +/* + * REPLY_RXON_ASSOC = 0x11 (command, has simple generic response) + */ +struct iwl4965_rxon_assoc_cmd { + __le32 flags; + __le32 filter_flags; + u8 ofdm_basic_rates; + u8 cck_basic_rates; + u8 ofdm_ht_single_stream_basic_rates; + u8 ofdm_ht_dual_stream_basic_rates; + __le16 rx_chain_select_flags; + __le16 reserved; +} __attribute__ ((packed)); + +/* + * REPLY_RXON_TIMING = 0x14 (command, has simple generic response) + */ +struct iwl4965_rxon_time_cmd { + union tsf timestamp; + __le16 beacon_interval; + __le16 atim_window; + __le32 beacon_init_val; + __le16 listen_interval; + __le16 reserved; +} __attribute__ ((packed)); + +/* + * REPLY_CHANNEL_SWITCH = 0x72 (command, has simple generic response) + */ +struct iwl4965_channel_switch_cmd { + u8 band; + u8 expect_beacon; + __le16 channel; + __le32 rxon_flags; + __le32 rxon_filter_flags; + __le32 switch_time; + struct iwl4965_tx_power_db tx_power; +} __attribute__ ((packed)); + +/* + * CHANNEL_SWITCH_NOTIFICATION = 0x73 (notification only, not a command) + */ +struct iwl4965_csa_notification { + __le16 band; + __le16 channel; + __le32 status; /* 0 - OK, 1 - fail */ +} __attribute__ ((packed)); + +/****************************************************************************** + * (2) + * Quality-of-Service (QOS) Commands & Responses: + * + *****************************************************************************/ + +/** + * struct iwl_ac_qos -- QOS timing params for REPLY_QOS_PARAM + * One for each of 4 EDCA access categories in struct iwl_qosparam_cmd + * + * @cw_min: Contention window, start value in numbers of slots. + * Should be a power-of-2, minus 1. Device's default is 0x0f. + * @cw_max: Contention window, max value in numbers of slots. + * Should be a power-of-2, minus 1. Device's default is 0x3f. + * @aifsn: Number of slots in Arbitration Interframe Space (before + * performing random backoff timing prior to Tx). Device default 1. + * @edca_txop: Length of Tx opportunity, in uSecs. Device default is 0. + * + * Device will automatically increase contention window by (2*CW) + 1 for each + * transmission retry. Device uses cw_max as a bit mask, ANDed with new CW + * value, to cap the CW value. + */ +struct iwl4965_ac_qos { + __le16 cw_min; + __le16 cw_max; + u8 aifsn; + u8 reserved1; + __le16 edca_txop; +} __attribute__ ((packed)); + +/* QoS flags defines */ +#define QOS_PARAM_FLG_UPDATE_EDCA_MSK __constant_cpu_to_le32(0x01) +#define QOS_PARAM_FLG_TGN_MSK __constant_cpu_to_le32(0x02) +#define QOS_PARAM_FLG_TXOP_TYPE_MSK __constant_cpu_to_le32(0x10) + +/* Number of Access Categories (AC) (EDCA), queues 0..3 */ +#define AC_NUM 4 + +/* + * REPLY_QOS_PARAM = 0x13 (command, has simple generic response) + * + * This command sets up timings for each of the 4 prioritized EDCA Tx FIFOs + * 0: Background, 1: Best Effort, 2: Video, 3: Voice. + */ +struct iwl4965_qosparam_cmd { + __le32 qos_flags; + struct iwl4965_ac_qos ac[AC_NUM]; +} __attribute__ ((packed)); + +/****************************************************************************** + * (3) + * Add/Modify Stations Commands & Responses: + * + *****************************************************************************/ +/* + * Multi station support + */ + +/* Special, dedicated locations within device's station table */ +#define IWL_AP_ID 0 +#define IWL_MULTICAST_ID 1 +#define IWL_STA_ID 2 +#define IWL4965_BROADCAST_ID 31 +#define IWL4965_STATION_COUNT 32 + +#define IWL_STATION_COUNT 32 /* MAX(3945,4965)*/ +#define IWL_INVALID_STATION 255 + +#define STA_FLG_PWR_SAVE_MSK __constant_cpu_to_le32(1 << 8); +#define STA_FLG_RTS_MIMO_PROT_MSK __constant_cpu_to_le32(1 << 17) +#define STA_FLG_AGG_MPDU_8US_MSK __constant_cpu_to_le32(1 << 18) +#define STA_FLG_MAX_AGG_SIZE_POS (19) +#define STA_FLG_MAX_AGG_SIZE_MSK __constant_cpu_to_le32(3 << 19) +#define STA_FLG_FAT_EN_MSK __constant_cpu_to_le32(1 << 21) +#define STA_FLG_MIMO_DIS_MSK __constant_cpu_to_le32(1 << 22) +#define STA_FLG_AGG_MPDU_DENSITY_POS (23) +#define STA_FLG_AGG_MPDU_DENSITY_MSK __constant_cpu_to_le32(7 << 23) + +/* Use in mode field. 1: modify existing entry, 0: add new station entry */ +#define STA_CONTROL_MODIFY_MSK 0x01 + +/* key flags __le16*/ +#define STA_KEY_FLG_ENCRYPT_MSK __constant_cpu_to_le16(0x7) +#define STA_KEY_FLG_NO_ENC __constant_cpu_to_le16(0x0) +#define STA_KEY_FLG_WEP __constant_cpu_to_le16(0x1) +#define STA_KEY_FLG_CCMP __constant_cpu_to_le16(0x2) +#define STA_KEY_FLG_TKIP __constant_cpu_to_le16(0x3) + +#define STA_KEY_FLG_KEYID_POS 8 +#define STA_KEY_FLG_INVALID __constant_cpu_to_le16(0x0800) + +/* Flags indicate whether to modify vs. don't change various station params */ +#define STA_MODIFY_KEY_MASK 0x01 +#define STA_MODIFY_TID_DISABLE_TX 0x02 +#define STA_MODIFY_TX_RATE_MSK 0x04 +#define STA_MODIFY_ADDBA_TID_MSK 0x08 +#define STA_MODIFY_DELBA_TID_MSK 0x10 + +/* Receiver address (actually, Rx station's index into station table), + * combined with Traffic ID (QOS priority), in format used by Tx Scheduler */ +#define BUILD_RAxTID(sta_id, tid) (((sta_id) << 4) + (tid)) + +struct iwl4965_keyinfo { + __le16 key_flags; + u8 tkip_rx_tsc_byte2; /* TSC[2] for key mix ph1 detection */ + u8 reserved1; + __le16 tkip_rx_ttak[5]; /* 10-byte unicast TKIP TTAK */ + __le16 reserved2; + u8 key[16]; /* 16-byte unicast decryption key */ +} __attribute__ ((packed)); + +/** + * struct sta_id_modify + * @addr[ETH_ALEN]: station's MAC address + * @sta_id: index of station in uCode's station table + * @modify_mask: STA_MODIFY_*, 1: modify, 0: don't change + * + * Driver selects unused table index when adding new station, + * or the index to a pre-existing station entry when modifying that station. + * Some indexes have special purposes (IWL_AP_ID, index 0, is for AP). + * + * modify_mask flags select which parameters to modify vs. leave alone. + */ +struct sta_id_modify { + u8 addr[ETH_ALEN]; + __le16 reserved1; + u8 sta_id; + u8 modify_mask; + __le16 reserved2; +} __attribute__ ((packed)); + +/* + * REPLY_ADD_STA = 0x18 (command) + * + * The device contains an internal table of per-station information, + * with info on security keys, aggregation parameters, and Tx rates for + * initial Tx attempt and any retries (4965 uses REPLY_TX_LINK_QUALITY_CMD, + * 3945 uses REPLY_RATE_SCALE to set up rate tables). + * + * REPLY_ADD_STA sets up the table entry for one station, either creating + * a new entry, or modifying a pre-existing one. + * + * NOTE: RXON command (without "associated" bit set) wipes the station table + * clean. Moving into RF_KILL state does this also. Driver must set up + * new station table before transmitting anything on the RXON channel + * (except active scans or active measurements; those commands carry + * their own txpower/rate setup data). + * + * When getting started on a new channel, driver must set up the + * IWL_BROADCAST_ID entry (last entry in the table). For a client + * station in a BSS, once an AP is selected, driver sets up the AP STA + * in the IWL_AP_ID entry (1st entry in the table). BROADCAST and AP + * are all that are needed for a BSS client station. If the device is + * used as AP, or in an IBSS network, driver must set up station table + * entries for all STAs in network, starting with index IWL_STA_ID. + */ +struct iwl4965_addsta_cmd { + u8 mode; /* 1: modify existing, 0: add new station */ + u8 reserved[3]; + struct sta_id_modify sta; + struct iwl4965_keyinfo key; + __le32 station_flags; /* STA_FLG_* */ + __le32 station_flags_msk; /* STA_FLG_* */ + + /* bit field to disable (1) or enable (0) Tx for Traffic ID (TID) + * corresponding to bit (e.g. bit 5 controls TID 5). + * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */ + __le16 tid_disable_tx; + + __le16 reserved1; + + /* TID for which to add block-ack support. + * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */ + u8 add_immediate_ba_tid; + + /* TID for which to remove block-ack support. + * Set modify_mask bit STA_MODIFY_DELBA_TID_MSK to use this field. */ + u8 remove_immediate_ba_tid; + + /* Starting Sequence Number for added block-ack support. + * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */ + __le16 add_immediate_ba_ssn; + + __le32 reserved2; +} __attribute__ ((packed)); + +#define ADD_STA_SUCCESS_MSK 0x1 +#define ADD_STA_NO_ROOM_IN_TABLE 0x2 +#define ADD_STA_NO_BLOCK_ACK_RESOURCE 0x4 +#define ADD_STA_MODIFY_NON_EXIST_STA 0x8 +/* + * REPLY_ADD_STA = 0x18 (response) + */ +struct iwl4965_add_sta_resp { + u8 status; /* ADD_STA_* */ +} __attribute__ ((packed)); + + +/****************************************************************************** + * (4) + * Rx Responses: + * + *****************************************************************************/ + +struct iwl4965_rx_frame_stats { + u8 phy_count; + u8 id; + u8 rssi; + u8 agc; + __le16 sig_avg; + __le16 noise_diff; + u8 payload[0]; +} __attribute__ ((packed)); + +struct iwl4965_rx_frame_hdr { + __le16 channel; + __le16 phy_flags; + u8 reserved1; + u8 rate; + __le16 len; + u8 payload[0]; +} __attribute__ ((packed)); + +#define RX_RES_STATUS_NO_CRC32_ERROR __constant_cpu_to_le32(1 << 0) +#define RX_RES_STATUS_NO_RXE_OVERFLOW __constant_cpu_to_le32(1 << 1) + +#define RX_RES_PHY_FLAGS_BAND_24_MSK __constant_cpu_to_le16(1 << 0) +#define RX_RES_PHY_FLAGS_MOD_CCK_MSK __constant_cpu_to_le16(1 << 1) +#define RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK __constant_cpu_to_le16(1 << 2) +#define RX_RES_PHY_FLAGS_NARROW_BAND_MSK __constant_cpu_to_le16(1 << 3) +#define RX_RES_PHY_FLAGS_ANTENNA_MSK __constant_cpu_to_le16(0xf0) + +#define RX_RES_STATUS_SEC_TYPE_MSK (0x7 << 8) +#define RX_RES_STATUS_SEC_TYPE_NONE (0x0 << 8) +#define RX_RES_STATUS_SEC_TYPE_WEP (0x1 << 8) +#define RX_RES_STATUS_SEC_TYPE_CCMP (0x2 << 8) +#define RX_RES_STATUS_SEC_TYPE_TKIP (0x3 << 8) + +#define RX_RES_STATUS_DECRYPT_TYPE_MSK (0x3 << 11) +#define RX_RES_STATUS_NOT_DECRYPT (0x0 << 11) +#define RX_RES_STATUS_DECRYPT_OK (0x3 << 11) +#define RX_RES_STATUS_BAD_ICV_MIC (0x1 << 11) +#define RX_RES_STATUS_BAD_KEY_TTAK (0x2 << 11) + +struct iwl4965_rx_frame_end { + __le32 status; + __le64 timestamp; + __le32 beacon_timestamp; +} __attribute__ ((packed)); + +/* + * REPLY_3945_RX = 0x1b (response only, not a command) + * + * NOTE: DO NOT dereference from casts to this structure + * It is provided only for calculating minimum data set size. + * The actual offsets of the hdr and end are dynamic based on + * stats.phy_count + */ +struct iwl4965_rx_frame { + struct iwl4965_rx_frame_stats stats; + struct iwl4965_rx_frame_hdr hdr; + struct iwl4965_rx_frame_end end; +} __attribute__ ((packed)); + +/* Fixed (non-configurable) rx data from phy */ +#define RX_PHY_FLAGS_ANTENNAE_OFFSET (4) +#define RX_PHY_FLAGS_ANTENNAE_MASK (0x70) +#define IWL_AGC_DB_MASK (0x3f80) /* MASK(7,13) */ +#define IWL_AGC_DB_POS (7) +struct iwl4965_rx_non_cfg_phy { + __le16 ant_selection; /* ant A bit 4, ant B bit 5, ant C bit 6 */ + __le16 agc_info; /* agc code 0:6, agc dB 7:13, reserved 14:15 */ + u8 rssi_info[6]; /* we use even entries, 0/2/4 for A/B/C rssi */ + u8 pad[0]; +} __attribute__ ((packed)); + +/* + * REPLY_4965_RX = 0xc3 (response only, not a command) + * Used only for legacy (non 11n) frames. + */ +#define RX_RES_PHY_CNT 14 +struct iwl4965_rx_phy_res { + u8 non_cfg_phy_cnt; /* non configurable DSP phy data byte count */ + u8 cfg_phy_cnt; /* configurable DSP phy data byte count */ + u8 stat_id; /* configurable DSP phy data set ID */ + u8 reserved1; + __le64 timestamp; /* TSF at on air rise */ + __le32 beacon_time_stamp; /* beacon at on-air rise */ + __le16 phy_flags; /* general phy flags: band, modulation, ... */ + __le16 channel; /* channel number */ + __le16 non_cfg_phy[RX_RES_PHY_CNT]; /* upto 14 phy entries */ + __le32 reserved2; + __le32 rate_n_flags; /* RATE_MCS_* */ + __le16 byte_count; /* frame's byte-count */ + __le16 reserved3; +} __attribute__ ((packed)); + +struct iwl4965_rx_mpdu_res_start { + __le16 byte_count; + __le16 reserved; +} __attribute__ ((packed)); + + +/****************************************************************************** + * (5) + * Tx Commands & Responses: + * + * Driver must place each REPLY_TX command into one of the prioritized Tx + * queues in host DRAM, shared between driver and device (see comments for + * SCD registers and Tx/Rx Queues). When the device's Tx scheduler and uCode + * are preparing to transmit, the device pulls the Tx command over the PCI + * bus via one of the device's Tx DMA channels, to fill an internal FIFO + * from which data will be transmitted. + * + * uCode handles all timing and protocol related to control frames + * (RTS/CTS/ACK), based on flags in the Tx command. uCode and Tx scheduler + * handle reception of block-acks; uCode updates the host driver via + * REPLY_COMPRESSED_BA (4965). + * + * uCode handles retrying Tx when an ACK is expected but not received. + * This includes trying lower data rates than the one requested in the Tx + * command, as set up by the REPLY_RATE_SCALE (for 3945) or + * REPLY_TX_LINK_QUALITY_CMD (4965). + * + * Driver sets up transmit power for various rates via REPLY_TX_PWR_TABLE_CMD. + * This command must be executed after every RXON command, before Tx can occur. + *****************************************************************************/ + +/* REPLY_TX Tx flags field */ + +/* 1: Use Request-To-Send protocol before this frame. + * Mutually exclusive vs. TX_CMD_FLG_CTS_MSK. */ +#define TX_CMD_FLG_RTS_MSK __constant_cpu_to_le32(1 << 1) + +/* 1: Transmit Clear-To-Send to self before this frame. + * Driver should set this for AUTH/DEAUTH/ASSOC-REQ/REASSOC mgmnt frames. + * Mutually exclusive vs. TX_CMD_FLG_RTS_MSK. */ +#define TX_CMD_FLG_CTS_MSK __constant_cpu_to_le32(1 << 2) + +/* 1: Expect ACK from receiving station + * 0: Don't expect ACK (MAC header's duration field s/b 0) + * Set this for unicast frames, but not broadcast/multicast. */ +#define TX_CMD_FLG_ACK_MSK __constant_cpu_to_le32(1 << 3) + +/* For 4965: + * 1: Use rate scale table (see REPLY_TX_LINK_QUALITY_CMD). + * Tx command's initial_rate_index indicates first rate to try; + * uCode walks through table for additional Tx attempts. + * 0: Use Tx rate/MCS from Tx command's rate_n_flags field. + * This rate will be used for all Tx attempts; it will not be scaled. */ +#define TX_CMD_FLG_STA_RATE_MSK __constant_cpu_to_le32(1 << 4) + +/* 1: Expect immediate block-ack. + * Set when Txing a block-ack request frame. Also set TX_CMD_FLG_ACK_MSK. */ +#define TX_CMD_FLG_IMM_BA_RSP_MASK __constant_cpu_to_le32(1 << 6) + +/* 1: Frame requires full Tx-Op protection. + * Set this if either RTS or CTS Tx Flag gets set. */ +#define TX_CMD_FLG_FULL_TXOP_PROT_MSK __constant_cpu_to_le32(1 << 7) + +/* Tx antenna selection field; used only for 3945, reserved (0) for 4965. + * Set field to "0" to allow 3945 uCode to select antenna (normal usage). */ +#define TX_CMD_FLG_ANT_SEL_MSK __constant_cpu_to_le32(0xf00) +#define TX_CMD_FLG_ANT_A_MSK __constant_cpu_to_le32(1 << 8) +#define TX_CMD_FLG_ANT_B_MSK __constant_cpu_to_le32(1 << 9) + +/* 1: Ignore Bluetooth priority for this frame. + * 0: Delay Tx until Bluetooth device is done (normal usage). */ +#define TX_CMD_FLG_BT_DIS_MSK __constant_cpu_to_le32(1 << 12) + +/* 1: uCode overrides sequence control field in MAC header. + * 0: Driver provides sequence control field in MAC header. + * Set this for management frames, non-QOS data frames, non-unicast frames, + * and also in Tx command embedded in REPLY_SCAN_CMD for active scans. */ +#define TX_CMD_FLG_SEQ_CTL_MSK __constant_cpu_to_le32(1 << 13) + +/* 1: This frame is non-last MPDU; more fragments are coming. + * 0: Last fragment, or not using fragmentation. */ +#define TX_CMD_FLG_MORE_FRAG_MSK __constant_cpu_to_le32(1 << 14) + +/* 1: uCode calculates and inserts Timestamp Function (TSF) in outgoing frame. + * 0: No TSF required in outgoing frame. + * Set this for transmitting beacons and probe responses. */ +#define TX_CMD_FLG_TSF_MSK __constant_cpu_to_le32(1 << 16) + +/* 1: Driver inserted 2 bytes pad after the MAC header, for (required) dword + * alignment of frame's payload data field. + * 0: No pad + * Set this for MAC headers with 26 or 30 bytes, i.e. those with QOS or ADDR4 + * field (but not both). Driver must align frame data (i.e. data following + * MAC header) to DWORD boundary. */ +#define TX_CMD_FLG_MH_PAD_MSK __constant_cpu_to_le32(1 << 20) + +/* HCCA-AP - disable duration overwriting. */ +#define TX_CMD_FLG_DUR_MSK __constant_cpu_to_le32(1 << 25) + + +/* + * TX command security control + */ +#define TX_CMD_SEC_WEP 0x01 +#define TX_CMD_SEC_CCM 0x02 +#define TX_CMD_SEC_TKIP 0x03 +#define TX_CMD_SEC_MSK 0x03 +#define TX_CMD_SEC_SHIFT 6 +#define TX_CMD_SEC_KEY128 0x08 + +/* + * 4965 uCode updates these Tx attempt count values in host DRAM. + * Used for managing Tx retries when expecting block-acks. + * Driver should set these fields to 0. + */ +struct iwl4965_dram_scratch { + u8 try_cnt; /* Tx attempts */ + u8 bt_kill_cnt; /* Tx attempts blocked by Bluetooth device */ + __le16 reserved; +} __attribute__ ((packed)); + +/* + * REPLY_TX = 0x1c (command) + */ +struct iwl4965_tx_cmd { + /* + * MPDU byte count: + * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size, + * + 8 byte IV for CCM or TKIP (not used for WEP) + * + Data payload + * + 8-byte MIC (not used for CCM/WEP) + * NOTE: Does not include Tx command bytes, post-MAC pad bytes, + * MIC (CCM) 8 bytes, ICV (WEP/TKIP/CKIP) 4 bytes, CRC 4 bytes.i + * Range: 14-2342 bytes. + */ + __le16 len; + + /* + * MPDU or MSDU byte count for next frame. + * Used for fragmentation and bursting, but not 11n aggregation. + * Same as "len", but for next frame. Set to 0 if not applicable. + */ + __le16 next_frame_len; + + __le32 tx_flags; /* TX_CMD_FLG_* */ + + /* 4965's uCode may modify this field of the Tx command (in host DRAM!). + * Driver must also set dram_lsb_ptr and dram_msb_ptr in this cmd. */ + struct iwl4965_dram_scratch scratch; + + /* Rate for *all* Tx attempts, if TX_CMD_FLG_STA_RATE_MSK is cleared. */ + __le32 rate_n_flags; /* RATE_MCS_* */ + + /* Index of destination station in uCode's station table */ + u8 sta_id; + + /* Type of security encryption: CCM or TKIP */ + u8 sec_ctl; /* TX_CMD_SEC_* */ + + /* + * Index into rate table (see REPLY_TX_LINK_QUALITY_CMD) for initial + * Tx attempt, if TX_CMD_FLG_STA_RATE_MSK is set. Normally "0" for + * data frames, this field may be used to selectively reduce initial + * rate (via non-0 value) for special frames (e.g. management), while + * still supporting rate scaling for all frames. + */ + u8 initial_rate_index; + u8 reserved; + u8 key[16]; + __le16 next_frame_flags; + __le16 reserved2; + union { + __le32 life_time; + __le32 attempt; + } stop_time; + + /* Host DRAM physical address pointer to "scratch" in this command. + * Must be dword aligned. "0" in dram_lsb_ptr disables usage. */ + __le32 dram_lsb_ptr; + u8 dram_msb_ptr; + + u8 rts_retry_limit; /*byte 50 */ + u8 data_retry_limit; /*byte 51 */ + u8 tid_tspec; + union { + __le16 pm_frame_timeout; + __le16 attempt_duration; + } timeout; + + /* + * Duration of EDCA burst Tx Opportunity, in 32-usec units. + * Set this if txop time is not specified by HCCA protocol (e.g. by AP). + */ + __le16 driver_txop; + + /* + * MAC header goes here, followed by 2 bytes padding if MAC header + * length is 26 or 30 bytes, followed by payload data + */ + u8 payload[0]; + struct ieee80211_hdr hdr[0]; +} __attribute__ ((packed)); + +/* TX command response is sent after *all* transmission attempts. + * + * NOTES: + * + * TX_STATUS_FAIL_NEXT_FRAG + * + * If the fragment flag in the MAC header for the frame being transmitted + * is set and there is insufficient time to transmit the next frame, the + * TX status will be returned with 'TX_STATUS_FAIL_NEXT_FRAG'. + * + * TX_STATUS_FIFO_UNDERRUN + * + * Indicates the host did not provide bytes to the FIFO fast enough while + * a TX was in progress. + * + * TX_STATUS_FAIL_MGMNT_ABORT + * + * This status is only possible if the ABORT ON MGMT RX parameter was + * set to true with the TX command. + * + * If the MSB of the status parameter is set then an abort sequence is + * required. This sequence consists of the host activating the TX Abort + * control line, and then waiting for the TX Abort command response. This + * indicates that a the device is no longer in a transmit state, and that the + * command FIFO has been cleared. The host must then deactivate the TX Abort + * control line. Receiving is still allowed in this case. + */ +enum { + TX_STATUS_SUCCESS = 0x01, + TX_STATUS_DIRECT_DONE = 0x02, + TX_STATUS_FAIL_SHORT_LIMIT = 0x82, + TX_STATUS_FAIL_LONG_LIMIT = 0x83, + TX_STATUS_FAIL_FIFO_UNDERRUN = 0x84, + TX_STATUS_FAIL_MGMNT_ABORT = 0x85, + TX_STATUS_FAIL_NEXT_FRAG = 0x86, + TX_STATUS_FAIL_LIFE_EXPIRE = 0x87, + TX_STATUS_FAIL_DEST_PS = 0x88, + TX_STATUS_FAIL_ABORTED = 0x89, + TX_STATUS_FAIL_BT_RETRY = 0x8a, + TX_STATUS_FAIL_STA_INVALID = 0x8b, + TX_STATUS_FAIL_FRAG_DROPPED = 0x8c, + TX_STATUS_FAIL_TID_DISABLE = 0x8d, + TX_STATUS_FAIL_FRAME_FLUSHED = 0x8e, + TX_STATUS_FAIL_INSUFFICIENT_CF_POLL = 0x8f, + TX_STATUS_FAIL_TX_LOCKED = 0x90, + TX_STATUS_FAIL_NO_BEACON_ON_RADAR = 0x91, +}; + +#define TX_PACKET_MODE_REGULAR 0x0000 +#define TX_PACKET_MODE_BURST_SEQ 0x0100 +#define TX_PACKET_MODE_BURST_FIRST 0x0200 + +enum { + TX_POWER_PA_NOT_ACTIVE = 0x0, +}; + +enum { + TX_STATUS_MSK = 0x000000ff, /* bits 0:7 */ + TX_STATUS_DELAY_MSK = 0x00000040, + TX_STATUS_ABORT_MSK = 0x00000080, + TX_PACKET_MODE_MSK = 0x0000ff00, /* bits 8:15 */ + TX_FIFO_NUMBER_MSK = 0x00070000, /* bits 16:18 */ + TX_RESERVED = 0x00780000, /* bits 19:22 */ + TX_POWER_PA_DETECT_MSK = 0x7f800000, /* bits 23:30 */ + TX_ABORT_REQUIRED_MSK = 0x80000000, /* bits 31:31 */ +}; + +/* ******************************* + * TX aggregation status + ******************************* */ + +enum { + AGG_TX_STATE_TRANSMITTED = 0x00, + AGG_TX_STATE_UNDERRUN_MSK = 0x01, + AGG_TX_STATE_BT_PRIO_MSK = 0x02, + AGG_TX_STATE_FEW_BYTES_MSK = 0x04, + AGG_TX_STATE_ABORT_MSK = 0x08, + AGG_TX_STATE_LAST_SENT_TTL_MSK = 0x10, + AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK = 0x20, + AGG_TX_STATE_LAST_SENT_BT_KILL_MSK = 0x40, + AGG_TX_STATE_SCD_QUERY_MSK = 0x80, + AGG_TX_STATE_TEST_BAD_CRC32_MSK = 0x100, + AGG_TX_STATE_RESPONSE_MSK = 0x1ff, + AGG_TX_STATE_DUMP_TX_MSK = 0x200, + AGG_TX_STATE_DELAY_TX_MSK = 0x400 +}; + +#define AGG_TX_STATE_LAST_SENT_MSK \ +(AGG_TX_STATE_LAST_SENT_TTL_MSK | \ + AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK | \ + AGG_TX_STATE_LAST_SENT_BT_KILL_MSK) + +/* # tx attempts for first frame in aggregation */ +#define AGG_TX_STATE_TRY_CNT_POS 12 +#define AGG_TX_STATE_TRY_CNT_MSK 0xf000 + +/* Command ID and sequence number of Tx command for this frame */ +#define AGG_TX_STATE_SEQ_NUM_POS 16 +#define AGG_TX_STATE_SEQ_NUM_MSK 0xffff0000 + +/* + * REPLY_TX = 0x1c (response) + * + * This response may be in one of two slightly different formats, indicated + * by the frame_count field: + * + * 1) No aggregation (frame_count == 1). This reports Tx results for + * a single frame. Multiple attempts, at various bit rates, may have + * been made for this frame. + * + * 2) Aggregation (frame_count > 1). This reports Tx results for + * 2 or more frames that used block-acknowledge. All frames were + * transmitted at same rate. Rate scaling may have been used if first + * frame in this new agg block failed in previous agg block(s). + * + * Note that, for aggregation, ACK (block-ack) status is not delivered here; + * block-ack has not been received by the time the 4965 records this status. + * This status relates to reasons the tx might have been blocked or aborted + * within the sending station (this 4965), rather than whether it was + * received successfully by the destination station. + */ +struct iwl4965_tx_resp { + u8 frame_count; /* 1 no aggregation, >1 aggregation */ + u8 bt_kill_count; /* # blocked by bluetooth (unused for agg) */ + u8 failure_rts; /* # failures due to unsuccessful RTS */ + u8 failure_frame; /* # failures due to no ACK (unused for agg) */ + + /* For non-agg: Rate at which frame was successful. + * For agg: Rate at which all frames were transmitted. */ + __le32 rate_n_flags; /* RATE_MCS_* */ + + /* For non-agg: RTS + CTS + frame tx attempts time + ACK. + * For agg: RTS + CTS + aggregation tx time + block-ack time. */ + __le16 wireless_media_time; /* uSecs */ + + __le16 reserved; + __le32 pa_power1; /* RF power amplifier measurement (not used) */ + __le32 pa_power2; + + /* + * For non-agg: frame status TX_STATUS_* + * For agg: status of 1st frame, AGG_TX_STATE_*; other frame status + * fields follow this one, up to frame_count. + * Bit fields: + * 11- 0: AGG_TX_STATE_* status code + * 15-12: Retry count for 1st frame in aggregation (retries + * occur if tx failed for this frame when it was a + * member of a previous aggregation block). If rate + * scaling is used, retry count indicates the rate + * table entry used for all frames in the new agg. + * 31-16: Sequence # for this frame's Tx cmd (not SSN!) + */ + __le32 status; /* TX status (for aggregation status of 1st frame) */ +} __attribute__ ((packed)); + +/* + * REPLY_COMPRESSED_BA = 0xc5 (response only, not a command) + * + * Reports Block-Acknowledge from recipient station + */ +struct iwl4965_compressed_ba_resp { + __le32 sta_addr_lo32; + __le16 sta_addr_hi16; + __le16 reserved; + + /* Index of recipient (BA-sending) station in uCode's station table */ + u8 sta_id; + u8 tid; + __le16 ba_seq_ctl; + __le32 ba_bitmap0; + __le32 ba_bitmap1; + __le16 scd_flow; + __le16 scd_ssn; +} __attribute__ ((packed)); + +/* + * REPLY_TX_PWR_TABLE_CMD = 0x97 (command, has simple generic response) + * + * See details under "TXPOWER" in iwl-4965-hw.h. + */ +struct iwl4965_txpowertable_cmd { + u8 band; /* 0: 5 GHz, 1: 2.4 GHz */ + u8 reserved; + __le16 channel; + struct iwl4965_tx_power_db tx_power; +} __attribute__ ((packed)); + +/*RS_NEW_API: only TLC_RTS remains and moved to bit 0 */ +#define LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK (1 << 0) + +/* # of EDCA prioritized tx fifos */ +#define LINK_QUAL_AC_NUM AC_NUM + +/* # entries in rate scale table to support Tx retries */ +#define LINK_QUAL_MAX_RETRY_NUM 16 + +/* Tx antenna selection values */ +#define LINK_QUAL_ANT_A_MSK (1 << 0) +#define LINK_QUAL_ANT_B_MSK (1 << 1) +#define LINK_QUAL_ANT_MSK (LINK_QUAL_ANT_A_MSK|LINK_QUAL_ANT_B_MSK) + + +/** + * struct iwl4965_link_qual_general_params + * + * Used in REPLY_TX_LINK_QUALITY_CMD + */ +struct iwl4965_link_qual_general_params { + u8 flags; + + /* No entries at or above this (driver chosen) index contain MIMO */ + u8 mimo_delimiter; + + /* Best single antenna to use for single stream (legacy, SISO). */ + u8 single_stream_ant_msk; /* LINK_QUAL_ANT_* */ + + /* Best antennas to use for MIMO (unused for 4965, assumes both). */ + u8 dual_stream_ant_msk; /* LINK_QUAL_ANT_* */ + + /* + * If driver needs to use different initial rates for different + * EDCA QOS access categories (as implemented by tx fifos 0-3), + * this table will set that up, by indicating the indexes in the + * rs_table[LINK_QUAL_MAX_RETRY_NUM] rate table at which to start. + * Otherwise, driver should set all entries to 0. + * + * Entry usage: + * 0 = Background, 1 = Best Effort (normal), 2 = Video, 3 = Voice + * TX FIFOs above 3 use same value (typically 0) as TX FIFO 3. + */ + u8 start_rate_index[LINK_QUAL_AC_NUM]; +} __attribute__ ((packed)); + +/** + * struct iwl4965_link_qual_agg_params + * + * Used in REPLY_TX_LINK_QUALITY_CMD + */ +struct iwl4965_link_qual_agg_params { + + /* Maximum number of uSec in aggregation. + * Driver should set this to 4000 (4 milliseconds). */ + __le16 agg_time_limit; + + /* + * Number of Tx retries allowed for a frame, before that frame will + * no longer be considered for the start of an aggregation sequence + * (scheduler will then try to tx it as single frame). + * Driver should set this to 3. + */ + u8 agg_dis_start_th; + + /* + * Maximum number of frames in aggregation. + * 0 = no limit (default). 1 = no aggregation. + * Other values = max # frames in aggregation. + */ + u8 agg_frame_cnt_limit; + + __le32 reserved; +} __attribute__ ((packed)); + +/* + * REPLY_TX_LINK_QUALITY_CMD = 0x4e (command, has simple generic response) + * + * For 4965 only; 3945 uses REPLY_RATE_SCALE. + * + * Each station in the 4965's internal station table has its own table of 16 + * Tx rates and modulation modes (e.g. legacy/SISO/MIMO) for retrying Tx when + * an ACK is not received. This command replaces the entire table for + * one station. + * + * NOTE: Station must already be in 4965's station table. Use REPLY_ADD_STA. + * + * The rate scaling procedures described below work well. Of course, other + * procedures are possible, and may work better for particular environments. + * + * + * FILLING THE RATE TABLE + * + * Given a particular initial rate and mode, as determined by the rate + * scaling algorithm described below, the Linux driver uses the following + * formula to fill the rs_table[LINK_QUAL_MAX_RETRY_NUM] rate table in the + * Link Quality command: + * + * + * 1) If using High-throughput (HT) (SISO or MIMO) initial rate: + * a) Use this same initial rate for first 3 entries. + * b) Find next lower available rate using same mode (SISO or MIMO), + * use for next 3 entries. If no lower rate available, switch to + * legacy mode (no FAT channel, no MIMO, no short guard interval). + * c) If using MIMO, set command's mimo_delimiter to number of entries + * using MIMO (3 or 6). + * d) After trying 2 HT rates, switch to legacy mode (no FAT channel, + * no MIMO, no short guard interval), at the next lower bit rate + * (e.g. if second HT bit rate was 54, try 48 legacy), and follow + * legacy procedure for remaining table entries. + * + * 2) If using legacy initial rate: + * a) Use the initial rate for only one entry. + * b) For each following entry, reduce the rate to next lower available + * rate, until reaching the lowest available rate. + * c) When reducing rate, also switch antenna selection. + * d) Once lowest available rate is reached, repeat this rate until + * rate table is filled (16 entries), switching antenna each entry. + * + * + * ACCUMULATING HISTORY + * + * The rate scaling algorithm for 4965, as implemented in Linux driver, uses + * two sets of frame Tx success history: One for the current/active modulation + * mode, and one for a speculative/search mode that is being attempted. If the + * speculative mode turns out to be more effective (i.e. actual transfer + * rate is better), then the driver continues to use the speculative mode + * as the new current active mode. + * + * Each history set contains, separately for each possible rate, data for a + * sliding window of the 62 most recent tx attempts at that rate. The data + * includes a shifting bitmap of success(1)/failure(0), and sums of successful + * and attempted frames, from which the driver can additionally calculate a + * success ratio (success / attempted) and number of failures + * (attempted - success), and control the size of the window (attempted). + * The driver uses the bit map to remove successes from the success sum, as + * the oldest tx attempts fall out of the window. + * + * When the 4965 makes multiple tx attempts for a given frame, each attempt + * might be at a different rate, and have different modulation characteristics + * (e.g. antenna, fat channel, short guard interval), as set up in the rate + * scaling table in the Link Quality command. The driver must determine + * which rate table entry was used for each tx attempt, to determine which + * rate-specific history to update, and record only those attempts that + * match the modulation characteristics of the history set. + * + * When using block-ack (aggregation), all frames are transmitted at the same + * rate, since there is no per-attempt acknowledgement from the destination + * station. The Tx response struct iwl_tx_resp indicates the Tx rate in + * rate_n_flags field. After receiving a block-ack, the driver can update + * history for the entire block all at once. + * + * + * FINDING BEST STARTING RATE: + * + * When working with a selected initial modulation mode (see below), the + * driver attempts to find a best initial rate. The initial rate is the + * first entry in the Link Quality command's rate table. + * + * 1) Calculate actual throughput (success ratio * expected throughput, see + * table below) for current initial rate. Do this only if enough frames + * have been attempted to make the value meaningful: at least 6 failed + * tx attempts, or at least 8 successes. If not enough, don't try rate + * scaling yet. + * + * 2) Find available rates adjacent to current initial rate. Available means: + * a) supported by hardware && + * b) supported by association && + * c) within any constraints selected by user + * + * 3) Gather measured throughputs for adjacent rates. These might not have + * enough history to calculate a throughput. That's okay, we might try + * using one of them anyway! + * + * 4) Try decreasing rate if, for current rate: + * a) success ratio is < 15% || + * b) lower adjacent rate has better measured throughput || + * c) higher adjacent rate has worse throughput, and lower is unmeasured + * + * As a sanity check, if decrease was determined above, leave rate + * unchanged if: + * a) lower rate unavailable + * b) success ratio at current rate > 85% (very good) + * c) current measured throughput is better than expected throughput + * of lower rate (under perfect 100% tx conditions, see table below) + * + * 5) Try increasing rate if, for current rate: + * a) success ratio is < 15% || + * b) both adjacent rates' throughputs are unmeasured (try it!) || + * b) higher adjacent rate has better measured throughput || + * c) lower adjacent rate has worse throughput, and higher is unmeasured + * + * As a sanity check, if increase was determined above, leave rate + * unchanged if: + * a) success ratio at current rate < 70%. This is not particularly + * good performance; higher rate is sure to have poorer success. + * + * 6) Re-evaluate the rate after each tx frame. If working with block- + * acknowledge, history and statistics may be calculated for the entire + * block (including prior history that fits within the history windows), + * before re-evaluation. + * + * FINDING BEST STARTING MODULATION MODE: + * + * After working with a modulation mode for a "while" (and doing rate scaling), + * the driver searches for a new initial mode in an attempt to improve + * throughput. The "while" is measured by numbers of attempted frames: + * + * For legacy mode, search for new mode after: + * 480 successful frames, or 160 failed frames + * For high-throughput modes (SISO or MIMO), search for new mode after: + * 4500 successful frames, or 400 failed frames + * + * Mode switch possibilities are (3 for each mode): + * + * For legacy: + * Change antenna, try SISO (if HT association), try MIMO (if HT association) + * For SISO: + * Change antenna, try MIMO, try shortened guard interval (SGI) + * For MIMO: + * Try SISO antenna A, SISO antenna B, try shortened guard interval (SGI) + * + * When trying a new mode, use the same bit rate as the old/current mode when + * trying antenna switches and shortened guard interval. When switching to + * SISO from MIMO or legacy, or to MIMO from SISO or legacy, use a rate + * for which the expected throughput (under perfect conditions) is about the + * same or slightly better than the actual measured throughput delivered by + * the old/current mode. + * + * Actual throughput can be estimated by multiplying the expected throughput + * by the success ratio (successful / attempted tx frames). Frame size is + * not considered in this calculation; it assumes that frame size will average + * out to be fairly consistent over several samples. The following are + * metric values for expected throughput assuming 100% success ratio. + * Only G band has support for CCK rates: + * + * RATE: 1 2 5 11 6 9 12 18 24 36 48 54 60 + * + * G: 7 13 35 58 40 57 72 98 121 154 177 186 186 + * A: 0 0 0 0 40 57 72 98 121 154 177 186 186 + * SISO 20MHz: 0 0 0 0 42 42 76 102 124 159 183 193 202 + * SGI SISO 20MHz: 0 0 0 0 46 46 82 110 132 168 192 202 211 + * MIMO 20MHz: 0 0 0 0 74 74 123 155 179 214 236 244 251 + * SGI MIMO 20MHz: 0 0 0 0 81 81 131 164 188 222 243 251 257 + * SISO 40MHz: 0 0 0 0 77 77 127 160 184 220 242 250 257 + * SGI SISO 40MHz: 0 0 0 0 83 83 135 169 193 229 250 257 264 + * MIMO 40MHz: 0 0 0 0 123 123 182 214 235 264 279 285 289 + * SGI MIMO 40MHz: 0 0 0 0 131 131 191 222 242 270 284 289 293 + * + * After the new mode has been tried for a short while (minimum of 6 failed + * frames or 8 successful frames), compare success ratio and actual throughput + * estimate of the new mode with the old. If either is better with the new + * mode, continue to use the new mode. + * + * Continue comparing modes until all 3 possibilities have been tried. + * If moving from legacy to HT, try all 3 possibilities from the new HT + * mode. After trying all 3, a best mode is found. Continue to use this mode + * for the longer "while" described above (e.g. 480 successful frames for + * legacy), and then repeat the search process. + * + */ +struct iwl4965_link_quality_cmd { + + /* Index of destination/recipient station in uCode's station table */ + u8 sta_id; + u8 reserved1; + __le16 control; /* not used */ + struct iwl4965_link_qual_general_params general_params; + struct iwl4965_link_qual_agg_params agg_params; + + /* + * Rate info; when using rate-scaling, Tx command's initial_rate_index + * specifies 1st Tx rate attempted, via index into this table. + * 4965 works its way through table when retrying Tx. + */ + struct { + __le32 rate_n_flags; /* RATE_MCS_*, IWL_RATE_* */ + } rs_table[LINK_QUAL_MAX_RETRY_NUM]; + __le32 reserved2; +} __attribute__ ((packed)); + +/* + * REPLY_BT_CONFIG = 0x9b (command, has simple generic response) + * + * 3945 and 4965 support hardware handshake with Bluetooth device on + * same platform. Bluetooth device alerts wireless device when it will Tx; + * wireless device can delay or kill its own Tx to accomodate. + */ +struct iwl4965_bt_cmd { + u8 flags; + u8 lead_time; + u8 max_kill; + u8 reserved; + __le32 kill_ack_mask; + __le32 kill_cts_mask; +} __attribute__ ((packed)); + +/****************************************************************************** + * (6) + * Spectrum Management (802.11h) Commands, Responses, Notifications: + * + *****************************************************************************/ + +/* + * Spectrum Management + */ +#define MEASUREMENT_FILTER_FLAG (RXON_FILTER_PROMISC_MSK | \ + RXON_FILTER_CTL2HOST_MSK | \ + RXON_FILTER_ACCEPT_GRP_MSK | \ + RXON_FILTER_DIS_DECRYPT_MSK | \ + RXON_FILTER_DIS_GRP_DECRYPT_MSK | \ + RXON_FILTER_ASSOC_MSK | \ + RXON_FILTER_BCON_AWARE_MSK) + +struct iwl4965_measure_channel { + __le32 duration; /* measurement duration in extended beacon + * format */ + u8 channel; /* channel to measure */ + u8 type; /* see enum iwl4965_measure_type */ + __le16 reserved; +} __attribute__ ((packed)); + +/* + * REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74 (command) + */ +struct iwl4965_spectrum_cmd { + __le16 len; /* number of bytes starting from token */ + u8 token; /* token id */ + u8 id; /* measurement id -- 0 or 1 */ + u8 origin; /* 0 = TGh, 1 = other, 2 = TGk */ + u8 periodic; /* 1 = periodic */ + __le16 path_loss_timeout; + __le32 start_time; /* start time in extended beacon format */ + __le32 reserved2; + __le32 flags; /* rxon flags */ + __le32 filter_flags; /* rxon filter flags */ + __le16 channel_count; /* minimum 1, maximum 10 */ + __le16 reserved3; + struct iwl4965_measure_channel channels[10]; +} __attribute__ ((packed)); + +/* + * REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74 (response) + */ +struct iwl4965_spectrum_resp { + u8 token; + u8 id; /* id of the prior command replaced, or 0xff */ + __le16 status; /* 0 - command will be handled + * 1 - cannot handle (conflicts with another + * measurement) */ +} __attribute__ ((packed)); + +enum iwl4965_measurement_state { + IWL_MEASUREMENT_START = 0, + IWL_MEASUREMENT_STOP = 1, +}; + +enum iwl4965_measurement_status { + IWL_MEASUREMENT_OK = 0, + IWL_MEASUREMENT_CONCURRENT = 1, + IWL_MEASUREMENT_CSA_CONFLICT = 2, + IWL_MEASUREMENT_TGH_CONFLICT = 3, + /* 4-5 reserved */ + IWL_MEASUREMENT_STOPPED = 6, + IWL_MEASUREMENT_TIMEOUT = 7, + IWL_MEASUREMENT_PERIODIC_FAILED = 8, +}; + +#define NUM_ELEMENTS_IN_HISTOGRAM 8 + +struct iwl4965_measurement_histogram { + __le32 ofdm[NUM_ELEMENTS_IN_HISTOGRAM]; /* in 0.8usec counts */ + __le32 cck[NUM_ELEMENTS_IN_HISTOGRAM]; /* in 1usec counts */ +} __attribute__ ((packed)); + +/* clear channel availability counters */ +struct iwl4965_measurement_cca_counters { + __le32 ofdm; + __le32 cck; +} __attribute__ ((packed)); + +enum iwl4965_measure_type { + IWL_MEASURE_BASIC = (1 << 0), + IWL_MEASURE_CHANNEL_LOAD = (1 << 1), + IWL_MEASURE_HISTOGRAM_RPI = (1 << 2), + IWL_MEASURE_HISTOGRAM_NOISE = (1 << 3), + IWL_MEASURE_FRAME = (1 << 4), + /* bits 5:6 are reserved */ + IWL_MEASURE_IDLE = (1 << 7), +}; + +/* + * SPECTRUM_MEASURE_NOTIFICATION = 0x75 (notification only, not a command) + */ +struct iwl4965_spectrum_notification { + u8 id; /* measurement id -- 0 or 1 */ + u8 token; + u8 channel_index; /* index in measurement channel list */ + u8 state; /* 0 - start, 1 - stop */ + __le32 start_time; /* lower 32-bits of TSF */ + u8 band; /* 0 - 5.2GHz, 1 - 2.4GHz */ + u8 channel; + u8 type; /* see enum iwl4965_measurement_type */ + u8 reserved1; + /* NOTE: cca_ofdm, cca_cck, basic_type, and histogram are only only + * valid if applicable for measurement type requested. */ + __le32 cca_ofdm; /* cca fraction time in 40Mhz clock periods */ + __le32 cca_cck; /* cca fraction time in 44Mhz clock periods */ + __le32 cca_time; /* channel load time in usecs */ + u8 basic_type; /* 0 - bss, 1 - ofdm preamble, 2 - + * unidentified */ + u8 reserved2[3]; + struct iwl4965_measurement_histogram histogram; + __le32 stop_time; /* lower 32-bits of TSF */ + __le32 status; /* see iwl4965_measurement_status */ +} __attribute__ ((packed)); + +/****************************************************************************** + * (7) + * Power Management Commands, Responses, Notifications: + * + *****************************************************************************/ + +/** + * struct iwl4965_powertable_cmd - Power Table Command + * @flags: See below: + * + * POWER_TABLE_CMD = 0x77 (command, has simple generic response) + * + * PM allow: + * bit 0 - '0' Driver not allow power management + * '1' Driver allow PM (use rest of parameters) + * uCode send sleep notifications: + * bit 1 - '0' Don't send sleep notification + * '1' send sleep notification (SEND_PM_NOTIFICATION) + * Sleep over DTIM + * bit 2 - '0' PM have to walk up every DTIM + * '1' PM could sleep over DTIM till listen Interval. + * PCI power managed + * bit 3 - '0' (PCI_LINK_CTRL & 0x1) + * '1' !(PCI_LINK_CTRL & 0x1) + * Force sleep Modes + * bit 31/30- '00' use both mac/xtal sleeps + * '01' force Mac sleep + * '10' force xtal sleep + * '11' Illegal set + * + * NOTE: if sleep_interval[SLEEP_INTRVL_TABLE_SIZE-1] > DTIM period then + * ucode assume sleep over DTIM is allowed and we don't need to wakeup + * for every DTIM. + */ +#define IWL_POWER_VEC_SIZE 5 + +#define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK __constant_cpu_to_le16(1 << 0) +#define IWL_POWER_SLEEP_OVER_DTIM_MSK __constant_cpu_to_le16(1 << 2) +#define IWL_POWER_PCI_PM_MSK __constant_cpu_to_le16(1 << 3) + +struct iwl4965_powertable_cmd { + __le16 flags; + u8 keep_alive_seconds; + u8 debug_flags; + __le32 rx_data_timeout; + __le32 tx_data_timeout; + __le32 sleep_interval[IWL_POWER_VEC_SIZE]; + __le32 keep_alive_beacons; +} __attribute__ ((packed)); + +/* + * PM_SLEEP_NOTIFICATION = 0x7A (notification only, not a command) + * 3945 and 4965 identical. + */ +struct iwl4965_sleep_notification { + u8 pm_sleep_mode; + u8 pm_wakeup_src; + __le16 reserved; + __le32 sleep_time; + __le32 tsf_low; + __le32 bcon_timer; +} __attribute__ ((packed)); + +/* Sleep states. 3945 and 4965 identical. */ +enum { + IWL_PM_NO_SLEEP = 0, + IWL_PM_SLP_MAC = 1, + IWL_PM_SLP_FULL_MAC_UNASSOCIATE = 2, + IWL_PM_SLP_FULL_MAC_CARD_STATE = 3, + IWL_PM_SLP_PHY = 4, + IWL_PM_SLP_REPENT = 5, + IWL_PM_WAKEUP_BY_TIMER = 6, + IWL_PM_WAKEUP_BY_DRIVER = 7, + IWL_PM_WAKEUP_BY_RFKILL = 8, + /* 3 reserved */ + IWL_PM_NUM_OF_MODES = 12, +}; + +/* + * REPLY_CARD_STATE_CMD = 0xa0 (command, has simple generic response) + */ +#define CARD_STATE_CMD_DISABLE 0x00 /* Put card to sleep */ +#define CARD_STATE_CMD_ENABLE 0x01 /* Wake up card */ +#define CARD_STATE_CMD_HALT 0x02 /* Power down permanently */ +struct iwl4965_card_state_cmd { + __le32 status; /* CARD_STATE_CMD_* request new power state */ +} __attribute__ ((packed)); + +/* + * CARD_STATE_NOTIFICATION = 0xa1 (notification only, not a command) + */ +struct iwl4965_card_state_notif { + __le32 flags; +} __attribute__ ((packed)); + +#define HW_CARD_DISABLED 0x01 +#define SW_CARD_DISABLED 0x02 +#define RF_CARD_DISABLED 0x04 +#define RXON_CARD_DISABLED 0x10 + +struct iwl4965_ct_kill_config { + __le32 reserved; + __le32 critical_temperature_M; + __le32 critical_temperature_R; +} __attribute__ ((packed)); + +/****************************************************************************** + * (8) + * Scan Commands, Responses, Notifications: + * + *****************************************************************************/ + +/** + * struct iwl4965_scan_channel - entry in REPLY_SCAN_CMD channel table + * + * One for each channel in the scan list. + * Each channel can independently select: + * 1) SSID for directed active scans + * 2) Txpower setting (for rate specified within Tx command) + * 3) How long to stay on-channel (behavior may be modified by quiet_time, + * quiet_plcp_th, good_CRC_th) + * + * To avoid uCode errors, make sure the following are true (see comments + * under struct iwl4965_scan_cmd about max_out_time and quiet_time): + * 1) If using passive_dwell (i.e. passive_dwell != 0): + * active_dwell <= passive_dwell (< max_out_time if max_out_time != 0) + * 2) quiet_time <= active_dwell + * 3) If restricting off-channel time (i.e. max_out_time !=0): + * passive_dwell < max_out_time + * active_dwell < max_out_time + */ +struct iwl4965_scan_channel { + /* + * type is defined as: + * 0:0 1 = active, 0 = passive + * 1:4 SSID direct bit map; if a bit is set, then corresponding + * SSID IE is transmitted in probe request. + * 5:7 reserved + */ + u8 type; + u8 channel; /* band is selected by iwl4965_scan_cmd "flags" field */ + struct iwl4965_tx_power tpc; + __le16 active_dwell; /* in 1024-uSec TU (time units), typ 5-50 */ + __le16 passive_dwell; /* in 1024-uSec TU (time units), typ 20-500 */ +} __attribute__ ((packed)); + +/** + * struct iwl4965_ssid_ie - directed scan network information element + * + * Up to 4 of these may appear in REPLY_SCAN_CMD, selected by "type" field + * in struct iwl4965_scan_channel; each channel may select different ssids from + * among the 4 entries. SSID IEs get transmitted in reverse order of entry. + */ +struct iwl4965_ssid_ie { + u8 id; + u8 len; + u8 ssid[32]; +} __attribute__ ((packed)); + +#define PROBE_OPTION_MAX 0x4 +#define TX_CMD_LIFE_TIME_INFINITE __constant_cpu_to_le32(0xFFFFFFFF) +#define IWL_GOOD_CRC_TH __constant_cpu_to_le16(1) +#define IWL_MAX_SCAN_SIZE 1024 + +/* + * REPLY_SCAN_CMD = 0x80 (command) + * + * The hardware scan command is very powerful; the driver can set it up to + * maintain (relatively) normal network traffic while doing a scan in the + * background. The max_out_time and suspend_time control the ratio of how + * long the device stays on an associated network channel ("service channel") + * vs. how long it's away from the service channel, i.e. tuned to other channels + * for scanning. + * + * max_out_time is the max time off-channel (in usec), and suspend_time + * is how long (in "extended beacon" format) that the scan is "suspended" + * after returning to the service channel. That is, suspend_time is the + * time that we stay on the service channel, doing normal work, between + * scan segments. The driver may set these parameters differently to support + * scanning when associated vs. not associated, and light vs. heavy traffic + * loads when associated. + * + * After receiving this command, the device's scan engine does the following; + * + * 1) Sends SCAN_START notification to driver + * 2) Checks to see if it has time to do scan for one channel + * 3) Sends NULL packet, with power-save (PS) bit set to 1, + * to tell AP that we're going off-channel + * 4) Tunes to first channel in scan list, does active or passive scan + * 5) Sends SCAN_RESULT notification to driver + * 6) Checks to see if it has time to do scan on *next* channel in list + * 7) Repeats 4-6 until it no longer has time to scan the next channel + * before max_out_time expires + * 8) Returns to service channel + * 9) Sends NULL packet with PS=0 to tell AP that we're back + * 10) Stays on service channel until suspend_time expires + * 11) Repeats entire process 2-10 until list is complete + * 12) Sends SCAN_COMPLETE notification + * + * For fast, efficient scans, the scan command also has support for staying on + * a channel for just a short time, if doing active scanning and getting no + * responses to the transmitted probe request. This time is controlled by + * quiet_time, and the number of received packets below which a channel is + * considered "quiet" is controlled by quiet_plcp_threshold. + * + * For active scanning on channels that have regulatory restrictions against + * blindly transmitting, the scan can listen before transmitting, to make sure + * that there is already legitimate activity on the channel. If enough + * packets are cleanly received on the channel (controlled by good_CRC_th, + * typical value 1), the scan engine starts transmitting probe requests. + * + * Driver must use separate scan commands for 2.4 vs. 5 GHz bands. + * + * To avoid uCode errors, see timing restrictions described under + * struct iwl4965_scan_channel. + */ +struct iwl4965_scan_cmd { + __le16 len; + u8 reserved0; + u8 channel_count; /* # channels in channel list */ + __le16 quiet_time; /* dwell only this # millisecs on quiet channel + * (only for active scan) */ + __le16 quiet_plcp_th; /* quiet chnl is < this # pkts (typ. 1) */ + __le16 good_CRC_th; /* passive -> active promotion threshold */ + __le16 rx_chain; /* RXON_RX_CHAIN_* */ + __le32 max_out_time; /* max usec to be away from associated (service) + * channel */ + __le32 suspend_time; /* pause scan this long (in "extended beacon + * format") when returning to service chnl: + * 3945; 31:24 # beacons, 19:0 additional usec, + * 4965; 31:22 # beacons, 21:0 additional usec. + */ + __le32 flags; /* RXON_FLG_* */ + __le32 filter_flags; /* RXON_FILTER_* */ + + /* For active scans (set to all-0s for passive scans). + * Does not include payload. Must specify Tx rate; no rate scaling. */ + struct iwl4965_tx_cmd tx_cmd; + + /* For directed active scans (set to all-0s otherwise) */ + struct iwl4965_ssid_ie direct_scan[PROBE_OPTION_MAX]; + + /* + * Probe request frame, followed by channel list. + * + * Size of probe request frame is specified by byte count in tx_cmd. + * Channel list follows immediately after probe request frame. + * Number of channels in list is specified by channel_count. + * Each channel in list is of type: + * + * struct iwl4965_scan_channel channels[0]; + * + * NOTE: Only one band of channels can be scanned per pass. You + * must not mix 2.4GHz channels and 5.2GHz channels, and you must wait + * for one scan to complete (i.e. receive SCAN_COMPLETE_NOTIFICATION) + * before requesting another scan. + */ + u8 data[0]; +} __attribute__ ((packed)); + +/* Can abort will notify by complete notification with abort status. */ +#define CAN_ABORT_STATUS __constant_cpu_to_le32(0x1) +/* complete notification statuses */ +#define ABORT_STATUS 0x2 + +/* + * REPLY_SCAN_CMD = 0x80 (response) + */ +struct iwl4965_scanreq_notification { + __le32 status; /* 1: okay, 2: cannot fulfill request */ +} __attribute__ ((packed)); + +/* + * SCAN_START_NOTIFICATION = 0x82 (notification only, not a command) + */ +struct iwl4965_scanstart_notification { + __le32 tsf_low; + __le32 tsf_high; + __le32 beacon_timer; + u8 channel; + u8 band; + u8 reserved[2]; + __le32 status; +} __attribute__ ((packed)); + +#define SCAN_OWNER_STATUS 0x1; +#define MEASURE_OWNER_STATUS 0x2; + +#define NUMBER_OF_STATISTICS 1 /* first __le32 is good CRC */ +/* + * SCAN_RESULTS_NOTIFICATION = 0x83 (notification only, not a command) + */ +struct iwl4965_scanresults_notification { + u8 channel; + u8 band; + u8 reserved[2]; + __le32 tsf_low; + __le32 tsf_high; + __le32 statistics[NUMBER_OF_STATISTICS]; +} __attribute__ ((packed)); + +/* + * SCAN_COMPLETE_NOTIFICATION = 0x84 (notification only, not a command) + */ +struct iwl4965_scancomplete_notification { + u8 scanned_channels; + u8 status; + u8 reserved; + u8 last_channel; + __le32 tsf_low; + __le32 tsf_high; +} __attribute__ ((packed)); + + +/****************************************************************************** + * (9) + * IBSS/AP Commands and Notifications: + * + *****************************************************************************/ + +/* + * BEACON_NOTIFICATION = 0x90 (notification only, not a command) + */ +struct iwl4965_beacon_notif { + struct iwl4965_tx_resp beacon_notify_hdr; + __le32 low_tsf; + __le32 high_tsf; + __le32 ibss_mgr_status; +} __attribute__ ((packed)); + +/* + * REPLY_TX_BEACON = 0x91 (command, has simple generic response) + */ +struct iwl4965_tx_beacon_cmd { + struct iwl4965_tx_cmd tx; + __le16 tim_idx; + u8 tim_size; + u8 reserved1; + struct ieee80211_hdr frame[0]; /* beacon frame */ +} __attribute__ ((packed)); + +/****************************************************************************** + * (10) + * Statistics Commands and Notifications: + * + *****************************************************************************/ + +#define IWL_TEMP_CONVERT 260 + +#define SUP_RATE_11A_MAX_NUM_CHANNELS 8 +#define SUP_RATE_11B_MAX_NUM_CHANNELS 4 +#define SUP_RATE_11G_MAX_NUM_CHANNELS 12 + +/* Used for passing to driver number of successes and failures per rate */ +struct rate_histogram { + union { + __le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS]; + __le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS]; + __le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS]; + } success; + union { + __le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS]; + __le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS]; + __le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS]; + } failed; +} __attribute__ ((packed)); + +/* statistics command response */ + +struct statistics_rx_phy { + __le32 ina_cnt; + __le32 fina_cnt; + __le32 plcp_err; + __le32 crc32_err; + __le32 overrun_err; + __le32 early_overrun_err; + __le32 crc32_good; + __le32 false_alarm_cnt; + __le32 fina_sync_err_cnt; + __le32 sfd_timeout; + __le32 fina_timeout; + __le32 unresponded_rts; + __le32 rxe_frame_limit_overrun; + __le32 sent_ack_cnt; + __le32 sent_cts_cnt; + __le32 sent_ba_rsp_cnt; + __le32 dsp_self_kill; + __le32 mh_format_err; + __le32 re_acq_main_rssi_sum; + __le32 reserved3; +} __attribute__ ((packed)); + +struct statistics_rx_ht_phy { + __le32 plcp_err; + __le32 overrun_err; + __le32 early_overrun_err; + __le32 crc32_good; + __le32 crc32_err; + __le32 mh_format_err; + __le32 agg_crc32_good; + __le32 agg_mpdu_cnt; + __le32 agg_cnt; + __le32 reserved2; +} __attribute__ ((packed)); + +struct statistics_rx_non_phy { + __le32 bogus_cts; /* CTS received when not expecting CTS */ + __le32 bogus_ack; /* ACK received when not expecting ACK */ + __le32 non_bssid_frames; /* number of frames with BSSID that + * doesn't belong to the STA BSSID */ + __le32 filtered_frames; /* count frames that were dumped in the + * filtering process */ + __le32 non_channel_beacons; /* beacons with our bss id but not on + * our serving channel */ + __le32 channel_beacons; /* beacons with our bss id and in our + * serving channel */ + __le32 num_missed_bcon; /* number of missed beacons */ + __le32 adc_rx_saturation_time; /* count in 0.8us units the time the + * ADC was in saturation */ + __le32 ina_detection_search_time;/* total time (in 0.8us) searched + * for INA */ + __le32 beacon_silence_rssi_a; /* RSSI silence after beacon frame */ + __le32 beacon_silence_rssi_b; /* RSSI silence after beacon frame */ + __le32 beacon_silence_rssi_c; /* RSSI silence after beacon frame */ + __le32 interference_data_flag; /* flag for interference data + * availability. 1 when data is + * available. */ + __le32 channel_load; /* counts RX Enable time in uSec */ + __le32 dsp_false_alarms; /* DSP false alarm (both OFDM + * and CCK) counter */ + __le32 beacon_rssi_a; + __le32 beacon_rssi_b; + __le32 beacon_rssi_c; + __le32 beacon_energy_a; + __le32 beacon_energy_b; + __le32 beacon_energy_c; +} __attribute__ ((packed)); + +struct statistics_rx { + struct statistics_rx_phy ofdm; + struct statistics_rx_phy cck; + struct statistics_rx_non_phy general; + struct statistics_rx_ht_phy ofdm_ht; +} __attribute__ ((packed)); + +struct statistics_tx_non_phy_agg { + __le32 ba_timeout; + __le32 ba_reschedule_frames; + __le32 scd_query_agg_frame_cnt; + __le32 scd_query_no_agg; + __le32 scd_query_agg; + __le32 scd_query_mismatch; + __le32 frame_not_ready; + __le32 underrun; + __le32 bt_prio_kill; + __le32 rx_ba_rsp_cnt; + __le32 reserved2; + __le32 reserved3; +} __attribute__ ((packed)); + +struct statistics_tx { + __le32 preamble_cnt; + __le32 rx_detected_cnt; + __le32 bt_prio_defer_cnt; + __le32 bt_prio_kill_cnt; + __le32 few_bytes_cnt; + __le32 cts_timeout; + __le32 ack_timeout; + __le32 expected_ack_cnt; + __le32 actual_ack_cnt; + __le32 dump_msdu_cnt; + __le32 burst_abort_next_frame_mismatch_cnt; + __le32 burst_abort_missing_next_frame_cnt; + __le32 cts_timeout_collision; + __le32 ack_or_ba_timeout_collision; + struct statistics_tx_non_phy_agg agg; +} __attribute__ ((packed)); + +struct statistics_dbg { + __le32 burst_check; + __le32 burst_count; + __le32 reserved[4]; +} __attribute__ ((packed)); + +struct statistics_div { + __le32 tx_on_a; + __le32 tx_on_b; + __le32 exec_time; + __le32 probe_time; + __le32 reserved1; + __le32 reserved2; +} __attribute__ ((packed)); + +struct statistics_general { + __le32 temperature; + __le32 temperature_m; + struct statistics_dbg dbg; + __le32 sleep_time; + __le32 slots_out; + __le32 slots_idle; + __le32 ttl_timestamp; + struct statistics_div div; + __le32 rx_enable_counter; + __le32 reserved1; + __le32 reserved2; + __le32 reserved3; +} __attribute__ ((packed)); + +/* + * REPLY_STATISTICS_CMD = 0x9c, + * 3945 and 4965 identical. + * + * This command triggers an immediate response containing uCode statistics. + * The response is in the same format as STATISTICS_NOTIFICATION 0x9d, below. + * + * If the CLEAR_STATS configuration flag is set, uCode will clear its + * internal copy of the statistics (counters) after issuing the response. + * This flag does not affect STATISTICS_NOTIFICATIONs after beacons (see below). + * + * If the DISABLE_NOTIF configuration flag is set, uCode will not issue + * STATISTICS_NOTIFICATIONs after received beacons (see below). This flag + * does not affect the response to the REPLY_STATISTICS_CMD 0x9c itself. + */ +#define IWL_STATS_CONF_CLEAR_STATS __constant_cpu_to_le32(0x1) /* see above */ +#define IWL_STATS_CONF_DISABLE_NOTIF __constant_cpu_to_le32(0x2)/* see above */ +struct iwl4965_statistics_cmd { + __le32 configuration_flags; /* IWL_STATS_CONF_* */ +} __attribute__ ((packed)); + +/* + * STATISTICS_NOTIFICATION = 0x9d (notification only, not a command) + * + * By default, uCode issues this notification after receiving a beacon + * while associated. To disable this behavior, set DISABLE_NOTIF flag in the + * REPLY_STATISTICS_CMD 0x9c, above. + * + * Statistics counters continue to increment beacon after beacon, but are + * cleared when changing channels or when driver issues REPLY_STATISTICS_CMD + * 0x9c with CLEAR_STATS bit set (see above). + * + * uCode also issues this notification during scans. uCode clears statistics + * appropriately so that each notification contains statistics for only the + * one channel that has just been scanned. + */ +#define STATISTICS_REPLY_FLG_BAND_24G_MSK __constant_cpu_to_le32(0x2) +#define STATISTICS_REPLY_FLG_FAT_MODE_MSK __constant_cpu_to_le32(0x8) +struct iwl4965_notif_statistics { + __le32 flag; + struct statistics_rx rx; + struct statistics_tx tx; + struct statistics_general general; +} __attribute__ ((packed)); + + +/* + * MISSED_BEACONS_NOTIFICATION = 0xa2 (notification only, not a command) + */ +/* if ucode missed CONSECUTIVE_MISSED_BCONS_TH beacons in a row, + * then this notification will be sent. */ +#define CONSECUTIVE_MISSED_BCONS_TH 20 + +struct iwl4965_missed_beacon_notif { + __le32 consequtive_missed_beacons; + __le32 total_missed_becons; + __le32 num_expected_beacons; + __le32 num_recvd_beacons; +} __attribute__ ((packed)); + + +/****************************************************************************** + * (11) + * Rx Calibration Commands: + * + * With the uCode used for open source drivers, most Tx calibration (except + * for Tx Power) and most Rx calibration is done by uCode during the + * "initialize" phase of uCode boot. Driver must calibrate only: + * + * 1) Tx power (depends on temperature), described elsewhere + * 2) Receiver gain balance (optimize MIMO, and detect disconnected antennas) + * 3) Receiver sensitivity (to optimize signal detection) + * + *****************************************************************************/ + +/** + * SENSITIVITY_CMD = 0xa8 (command, has simple generic response) + * + * This command sets up the Rx signal detector for a sensitivity level that + * is high enough to lock onto all signals within the associated network, + * but low enough to ignore signals that are below a certain threshold, so as + * not to have too many "false alarms". False alarms are signals that the + * Rx DSP tries to lock onto, but then discards after determining that they + * are noise. + * + * The optimum number of false alarms is between 5 and 50 per 200 TUs + * (200 * 1024 uSecs, i.e. 204.8 milliseconds) of actual Rx time (i.e. + * time listening, not transmitting). Driver must adjust sensitivity so that + * the ratio of actual false alarms to actual Rx time falls within this range. + * + * While associated, uCode delivers STATISTICS_NOTIFICATIONs after each + * received beacon. These provide information to the driver to analyze the + * sensitivity. Don't analyze statistics that come in from scanning, or any + * other non-associated-network source. Pertinent statistics include: + * + * From "general" statistics (struct statistics_rx_non_phy): + * + * (beacon_energy_[abc] & 0x0FF00) >> 8 (unsigned, higher value is lower level) + * Measure of energy of desired signal. Used for establishing a level + * below which the device does not detect signals. + * + * (beacon_silence_rssi_[abc] & 0x0FF00) >> 8 (unsigned, units in dB) + * Measure of background noise in silent period after beacon. + * + * channel_load + * uSecs of actual Rx time during beacon period (varies according to + * how much time was spent transmitting). + * + * From "cck" and "ofdm" statistics (struct statistics_rx_phy), separately: + * + * false_alarm_cnt + * Signal locks abandoned early (before phy-level header). + * + * plcp_err + * Signal locks abandoned late (during phy-level header). + * + * NOTE: Both false_alarm_cnt and plcp_err increment monotonically from + * beacon to beacon, i.e. each value is an accumulation of all errors + * before and including the latest beacon. Values will wrap around to 0 + * after counting up to 2^32 - 1. Driver must differentiate vs. + * previous beacon's values to determine # false alarms in the current + * beacon period. + * + * Total number of false alarms = false_alarms + plcp_errs + * + * For OFDM, adjust the following table entries in struct iwl_sensitivity_cmd + * (notice that the start points for OFDM are at or close to settings for + * maximum sensitivity): + * + * START / MIN / MAX + * HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX 90 / 85 / 120 + * HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX 170 / 170 / 210 + * HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX 105 / 105 / 140 + * HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX 220 / 220 / 270 + * + * If actual rate of OFDM false alarms (+ plcp_errors) is too high + * (greater than 50 for each 204.8 msecs listening), reduce sensitivity + * by *adding* 1 to all 4 of the table entries above, up to the max for + * each entry. Conversely, if false alarm rate is too low (less than 5 + * for each 204.8 msecs listening), *subtract* 1 from each entry to + * increase sensitivity. + * + * For CCK sensitivity, keep track of the following: + * + * 1). 20-beacon history of maximum background noise, indicated by + * (beacon_silence_rssi_[abc] & 0x0FF00), units in dB, across the + * 3 receivers. For any given beacon, the "silence reference" is + * the maximum of last 60 samples (20 beacons * 3 receivers). + * + * 2). 10-beacon history of strongest signal level, as indicated + * by (beacon_energy_[abc] & 0x0FF00) >> 8, across the 3 receivers, + * i.e. the strength of the signal through the best receiver at the + * moment. These measurements are "upside down", with lower values + * for stronger signals, so max energy will be *minimum* value. + * + * Then for any given beacon, the driver must determine the *weakest* + * of the strongest signals; this is the minimum level that needs to be + * successfully detected, when using the best receiver at the moment. + * "Max cck energy" is the maximum (higher value means lower energy!) + * of the last 10 minima. Once this is determined, driver must add + * a little margin by adding "6" to it. + * + * 3). Number of consecutive beacon periods with too few false alarms. + * Reset this to 0 at the first beacon period that falls within the + * "good" range (5 to 50 false alarms per 204.8 milliseconds rx). + * + * Then, adjust the following CCK table entries in struct iwl_sensitivity_cmd + * (notice that the start points for CCK are at maximum sensitivity): + * + * START / MIN / MAX + * HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX 125 / 125 / 200 + * HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX 200 / 200 / 400 + * HD_MIN_ENERGY_CCK_DET_INDEX 100 / 0 / 100 + * + * If actual rate of CCK false alarms (+ plcp_errors) is too high + * (greater than 50 for each 204.8 msecs listening), method for reducing + * sensitivity is: + * + * 1) *Add* 3 to value in HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX, + * up to max 400. + * + * 2) If current value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX is < 160, + * sensitivity has been reduced a significant amount; bring it up to + * a moderate 161. Otherwise, *add* 3, up to max 200. + * + * 3) a) If current value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX is > 160, + * sensitivity has been reduced only a moderate or small amount; + * *subtract* 2 from value in HD_MIN_ENERGY_CCK_DET_INDEX, + * down to min 0. Otherwise (if gain has been significantly reduced), + * don't change the HD_MIN_ENERGY_CCK_DET_INDEX value. + * + * b) Save a snapshot of the "silence reference". + * + * If actual rate of CCK false alarms (+ plcp_errors) is too low + * (less than 5 for each 204.8 msecs listening), method for increasing + * sensitivity is used only if: + * + * 1a) Previous beacon did not have too many false alarms + * 1b) AND difference between previous "silence reference" and current + * "silence reference" (prev - current) is 2 or more, + * OR 2) 100 or more consecutive beacon periods have had rate of + * less than 5 false alarms per 204.8 milliseconds rx time. + * + * Method for increasing sensitivity: + * + * 1) *Subtract* 3 from value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX, + * down to min 125. + * + * 2) *Subtract* 3 from value in HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX, + * down to min 200. + * + * 3) *Add* 2 to value in HD_MIN_ENERGY_CCK_DET_INDEX, up to max 100. + * + * If actual rate of CCK false alarms (+ plcp_errors) is within good range + * (between 5 and 50 for each 204.8 msecs listening): + * + * 1) Save a snapshot of the silence reference. + * + * 2) If previous beacon had too many CCK false alarms (+ plcp_errors), + * give some extra margin to energy threshold by *subtracting* 8 + * from value in HD_MIN_ENERGY_CCK_DET_INDEX. + * + * For all cases (too few, too many, good range), make sure that the CCK + * detection threshold (energy) is below the energy level for robust + * detection over the past 10 beacon periods, the "Max cck energy". + * Lower values mean higher energy; this means making sure that the value + * in HD_MIN_ENERGY_CCK_DET_INDEX is at or *above* "Max cck energy". + * + * Driver should set the following entries to fixed values: + * + * HD_MIN_ENERGY_OFDM_DET_INDEX 100 + * HD_BARKER_CORR_TH_ADD_MIN_INDEX 190 + * HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX 390 + * HD_OFDM_ENERGY_TH_IN_INDEX 62 + */ + +/* + * Table entries in SENSITIVITY_CMD (struct iwl4965_sensitivity_cmd) + */ +#define HD_TABLE_SIZE (11) /* number of entries */ +#define HD_MIN_ENERGY_CCK_DET_INDEX (0) /* table indexes */ +#define HD_MIN_ENERGY_OFDM_DET_INDEX (1) +#define HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX (2) +#define HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX (3) +#define HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX (4) +#define HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX (5) +#define HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX (6) +#define HD_BARKER_CORR_TH_ADD_MIN_INDEX (7) +#define HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX (8) +#define HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX (9) +#define HD_OFDM_ENERGY_TH_IN_INDEX (10) + +/* Control field in struct iwl4965_sensitivity_cmd */ +#define SENSITIVITY_CMD_CONTROL_DEFAULT_TABLE __constant_cpu_to_le16(0) +#define SENSITIVITY_CMD_CONTROL_WORK_TABLE __constant_cpu_to_le16(1) + +/** + * struct iwl4965_sensitivity_cmd + * @control: (1) updates working table, (0) updates default table + * @table: energy threshold values, use HD_* as index into table + * + * Always use "1" in "control" to update uCode's working table and DSP. + */ +struct iwl4965_sensitivity_cmd { + __le16 control; /* always use "1" */ + __le16 table[HD_TABLE_SIZE]; /* use HD_* as index */ +} __attribute__ ((packed)); + + +/** + * REPLY_PHY_CALIBRATION_CMD = 0xb0 (command, has simple generic response) + * + * This command sets the relative gains of 4965's 3 radio receiver chains. + * + * After the first association, driver should accumulate signal and noise + * statistics from the STATISTICS_NOTIFICATIONs that follow the first 20 + * beacons from the associated network (don't collect statistics that come + * in from scanning, or any other non-network source). + * + * DISCONNECTED ANTENNA: + * + * Driver should determine which antennas are actually connected, by comparing + * average beacon signal levels for the 3 Rx chains. Accumulate (add) the + * following values over 20 beacons, one accumulator for each of the chains + * a/b/c, from struct statistics_rx_non_phy: + * + * beacon_rssi_[abc] & 0x0FF (unsigned, units in dB) + * + * Find the strongest signal from among a/b/c. Compare the other two to the + * strongest. If any signal is more than 15 dB (times 20, unless you + * divide the accumulated values by 20) below the strongest, the driver + * considers that antenna to be disconnected, and should not try to use that + * antenna/chain for Rx or Tx. If both A and B seem to be disconnected, + * driver should declare the stronger one as connected, and attempt to use it + * (A and B are the only 2 Tx chains!). + * + * + * RX BALANCE: + * + * Driver should balance the 3 receivers (but just the ones that are connected + * to antennas, see above) for gain, by comparing the average signal levels + * detected during the silence after each beacon (background noise). + * Accumulate (add) the following values over 20 beacons, one accumulator for + * each of the chains a/b/c, from struct statistics_rx_non_phy: + * + * beacon_silence_rssi_[abc] & 0x0FF (unsigned, units in dB) + * + * Find the weakest background noise level from among a/b/c. This Rx chain + * will be the reference, with 0 gain adjustment. Attenuate other channels by + * finding noise difference: + * + * (accum_noise[i] - accum_noise[reference]) / 30 + * + * The "30" adjusts the dB in the 20 accumulated samples to units of 1.5 dB. + * For use in diff_gain_[abc] fields of struct iwl_calibration_cmd, the + * driver should limit the difference results to a range of 0-3 (0-4.5 dB), + * and set bit 2 to indicate "reduce gain". The value for the reference + * (weakest) chain should be "0". + * + * diff_gain_[abc] bit fields: + * 2: (1) reduce gain, (0) increase gain + * 1-0: amount of gain, units of 1.5 dB + */ + +/* "Differential Gain" opcode used in REPLY_PHY_CALIBRATION_CMD. */ +#define PHY_CALIBRATE_DIFF_GAIN_CMD (7) + +struct iwl4965_calibration_cmd { + u8 opCode; /* PHY_CALIBRATE_DIFF_GAIN_CMD (7) */ + u8 flags; /* not used */ + __le16 reserved; + s8 diff_gain_a; /* see above */ + s8 diff_gain_b; + s8 diff_gain_c; + u8 reserved1; +} __attribute__ ((packed)); + +/****************************************************************************** + * (12) + * Miscellaneous Commands: + * + *****************************************************************************/ + +/* + * LEDs Command & Response + * REPLY_LEDS_CMD = 0x48 (command, has simple generic response) + * + * For each of 3 possible LEDs (Activity/Link/Tech, selected by "id" field), + * this command turns it on or off, or sets up a periodic blinking cycle. + */ +struct iwl4965_led_cmd { + __le32 interval; /* "interval" in uSec */ + u8 id; /* 1: Activity, 2: Link, 3: Tech */ + u8 off; /* # intervals off while blinking; + * "0", with >0 "on" value, turns LED on */ + u8 on; /* # intervals on while blinking; + * "0", regardless of "off", turns LED off */ + u8 reserved; +} __attribute__ ((packed)); + +/****************************************************************************** + * (13) + * Union of all expected notifications/responses: + * + *****************************************************************************/ + +struct iwl4965_rx_packet { + __le32 len; + struct iwl4965_cmd_header hdr; + union { + struct iwl4965_alive_resp alive_frame; + struct iwl4965_rx_frame rx_frame; + struct iwl4965_tx_resp tx_resp; + struct iwl4965_spectrum_notification spectrum_notif; + struct iwl4965_csa_notification csa_notif; + struct iwl4965_error_resp err_resp; + struct iwl4965_card_state_notif card_state_notif; + struct iwl4965_beacon_notif beacon_status; + struct iwl4965_add_sta_resp add_sta; + struct iwl4965_sleep_notification sleep_notif; + struct iwl4965_spectrum_resp spectrum; + struct iwl4965_notif_statistics stats; + struct iwl4965_compressed_ba_resp compressed_ba; + struct iwl4965_missed_beacon_notif missed_beacon; + __le32 status; + u8 raw[0]; + } u; +} __attribute__ ((packed)); + +#define IWL_RX_FRAME_SIZE (4 + sizeof(struct iwl4965_rx_frame)) + +#endif /* __iwl4965_commands_h__ */ diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-debug.h b/drivers/net/wireless/iwlwifi/iwl-4965-debug.h new file mode 100644 index 00000000000..36696bbf170 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/iwl-4965-debug.h @@ -0,0 +1,152 @@ +/****************************************************************************** + * + * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. + * + * Portions of this file are derived from the ipw3945 project. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * James P. Ketrenos <ipw2100-admin@linux.intel.com> + * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 + * + *****************************************************************************/ + +#ifndef __iwl4965_debug_h__ +#define __iwl4965_debug_h__ + +#ifdef CONFIG_IWL4965_DEBUG +extern u32 iwl4965_debug_level; +#define IWL_DEBUG(level, fmt, args...) \ +do { if (iwl4965_debug_level & (level)) \ + printk(KERN_ERR DRV_NAME": %c %s " fmt, \ + in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0) + +#define IWL_DEBUG_LIMIT(level, fmt, args...) \ +do { if ((iwl4965_debug_level & (level)) && net_ratelimit()) \ + printk(KERN_ERR DRV_NAME": %c %s " fmt, \ + in_interrupt() ? 'I' : 'U', __FUNCTION__ , ## args); } while (0) +#else +static inline void IWL_DEBUG(int level, const char *fmt, ...) +{ +} +static inline void IWL_DEBUG_LIMIT(int level, const char *fmt, ...) +{ +} +#endif /* CONFIG_IWL4965_DEBUG */ + +/* + * To use the debug system; + * + * If you are defining a new debug classification, simply add it to the #define + * list here in the form of: + * + * #define IWL_DL_xxxx VALUE + * + * shifting value to the left one bit from the previous entry. xxxx should be + * the name of the classification (for example, WEP) + * + * You then need to either add a IWL_xxxx_DEBUG() macro definition for your + * classification, or use IWL_DEBUG(IWL_DL_xxxx, ...) whenever you want + * to send output to that classification. + * + * To add your debug level to the list of levels seen when you perform + * + * % cat /proc/net/iwl/debug_level + * + * you simply need to add your entry to the iwl4965_debug_levels array. + * + * If you do not see debug_level in /proc/net/iwl then you do not have + * CONFIG_IWL4965_DEBUG defined in your kernel configuration + * + */ + +#define IWL_DL_INFO (1 << 0) +#define IWL_DL_MAC80211 (1 << 1) +#define IWL_DL_HOST_COMMAND (1 << 2) +#define IWL_DL_STATE (1 << 3) + +#define IWL_DL_RADIO (1 << 7) +#define IWL_DL_POWER (1 << 8) +#define IWL_DL_TEMP (1 << 9) + +#define IWL_DL_NOTIF (1 << 10) +#define IWL_DL_SCAN (1 << 11) +#define IWL_DL_ASSOC (1 << 12) +#define IWL_DL_DROP (1 << 13) + +#define IWL_DL_TXPOWER (1 << 14) + +#define IWL_DL_AP (1 << 15) + +#define IWL_DL_FW (1 << 16) +#define IWL_DL_RF_KILL (1 << 17) +#define IWL_DL_FW_ERRORS (1 << 18) + +#define IWL_DL_LED (1 << 19) + +#define IWL_DL_RATE (1 << 20) + +#define IWL_DL_CALIB (1 << 21) +#define IWL_DL_WEP (1 << 22) +#define IWL_DL_TX (1 << 23) +#define IWL_DL_RX (1 << 24) +#define IWL_DL_ISR (1 << 25) +#define IWL_DL_HT (1 << 26) +#define IWL_DL_IO (1 << 27) +#define IWL_DL_11H (1 << 28) + +#define IWL_DL_STATS (1 << 29) +#define IWL_DL_TX_REPLY (1 << 30) +#define IWL_DL_QOS (1 << 31) + +#define IWL_ERROR(f, a...) printk(KERN_ERR DRV_NAME ": " f, ## a) +#define IWL_WARNING(f, a...) printk(KERN_WARNING DRV_NAME ": " f, ## a) +#define IWL_DEBUG_INFO(f, a...) IWL_DEBUG(IWL_DL_INFO, f, ## a) + +#define IWL_DEBUG_MAC80211(f, a...) IWL_DEBUG(IWL_DL_MAC80211, f, ## a) +#define IWL_DEBUG_TEMP(f, a...) IWL_DEBUG(IWL_DL_TEMP, f, ## a) +#define IWL_DEBUG_SCAN(f, a...) IWL_DEBUG(IWL_DL_SCAN, f, ## a) +#define IWL_DEBUG_RX(f, a...) IWL_DEBUG(IWL_DL_RX, f, ## a) +#define IWL_DEBUG_TX(f, a...) IWL_DEBUG(IWL_DL_TX, f, ## a) +#define IWL_DEBUG_ISR(f, a...) IWL_DEBUG(IWL_DL_ISR, f, ## a) +#define IWL_DEBUG_LED(f, a...) IWL_DEBUG(IWL_DL_LED, f, ## a) +#define IWL_DEBUG_WEP(f, a...) IWL_DEBUG(IWL_DL_WEP, f, ## a) +#define IWL_DEBUG_HC(f, a...) IWL_DEBUG(IWL_DL_HOST_COMMAND, f, ## a) +#define IWL_DEBUG_CALIB(f, a...) IWL_DEBUG(IWL_DL_CALIB, f, ## a) +#define IWL_DEBUG_FW(f, a...) IWL_DEBUG(IWL_DL_FW, f, ## a) +#define IWL_DEBUG_RF_KILL(f, a...) IWL_DEBUG(IWL_DL_RF_KILL, f, ## a) +#define IWL_DEBUG_DROP(f, a...) IWL_DEBUG(IWL_DL_DROP, f, ## a) +#define IWL_DEBUG_DROP_LIMIT(f, a...) IWL_DEBUG_LIMIT(IWL_DL_DROP, f, ## a) +#define IWL_DEBUG_AP(f, a...) IWL_DEBUG(IWL_DL_AP, f, ## a) +#define IWL_DEBUG_TXPOWER(f, a...) IWL_DEBUG(IWL_DL_TXPOWER, f, ## a) +#define IWL_DEBUG_IO(f, a...) IWL_DEBUG(IWL_DL_IO, f, ## a) +#define IWL_DEBUG_RATE(f, a...) IWL_DEBUG(IWL_DL_RATE, f, ## a) +#define IWL_DEBUG_RATE_LIMIT(f, a...) IWL_DEBUG_LIMIT(IWL_DL_RATE, f, ## a) +#define IWL_DEBUG_NOTIF(f, a...) IWL_DEBUG(IWL_DL_NOTIF, f, ## a) +#define IWL_DEBUG_ASSOC(f, a...) IWL_DEBUG(IWL_DL_ASSOC | IWL_DL_INFO, f, ## a) +#define IWL_DEBUG_ASSOC_LIMIT(f, a...) \ + IWL_DEBUG_LIMIT(IWL_DL_ASSOC | IWL_DL_INFO, f, ## a) +#define IWL_DEBUG_HT(f, a...) IWL_DEBUG(IWL_DL_HT, f, ## a) +#define IWL_DEBUG_STATS(f, a...) IWL_DEBUG(IWL_DL_STATS, f, ## a) +#define IWL_DEBUG_TX_REPLY(f, a...) IWL_DEBUG(IWL_DL_TX_REPLY, f, ## a) +#define IWL_DEBUG_QOS(f, a...) IWL_DEBUG(IWL_DL_QOS, f, ## a) +#define IWL_DEBUG_RADIO(f, a...) IWL_DEBUG(IWL_DL_RADIO, f, ## a) +#define IWL_DEBUG_POWER(f, a...) IWL_DEBUG(IWL_DL_POWER, f, ## a) +#define IWL_DEBUG_11H(f, a...) IWL_DEBUG(IWL_DL_11H, f, ## a) + +#endif diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-hw.h b/drivers/net/wireless/iwlwifi/iwl-4965-hw.h index 99a19ef4c74..ff71c09ab1a 100644 --- a/drivers/net/wireless/iwlwifi/iwl-4965-hw.h +++ b/drivers/net/wireless/iwlwifi/iwl-4965-hw.h @@ -8,7 +8,7 @@ * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU Geeral Public License as + * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but @@ -60,48 +60,618 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *****************************************************************************/ +/* + * Please use this file (iwl-4965-hw.h) only for hardware-related definitions. + * Use iwl-4965-commands.h for uCode API definitions. + * Use iwl-4965.h for driver implementation definitions. + */ #ifndef __iwl_4965_hw_h__ #define __iwl_4965_hw_h__ -#define IWL_RX_BUF_SIZE (4 * 1024) -#define IWL_MAX_BSM_SIZE BSM_SRAM_SIZE +/* + * uCode queue management definitions ... + * Queue #4 is the command queue for 3945 and 4965; map it to Tx FIFO chnl 4. + * The first queue used for block-ack aggregation is #7 (4965 only). + * All block-ack aggregation queues should map to Tx DMA/FIFO channel 7. + */ +#define IWL_CMD_QUEUE_NUM 4 +#define IWL_CMD_FIFO_NUM 4 +#define IWL_BACK_QUEUE_FIRST_ID 7 + +/* Tx rates */ +#define IWL_CCK_RATES 4 +#define IWL_OFDM_RATES 8 +#define IWL_HT_RATES 16 +#define IWL_MAX_RATES (IWL_CCK_RATES+IWL_OFDM_RATES+IWL_HT_RATES) + +/* Time constants */ +#define SHORT_SLOT_TIME 9 +#define LONG_SLOT_TIME 20 + +/* RSSI to dBm */ +#define IWL_RSSI_OFFSET 44 + +/* + * EEPROM related constants, enums, and structures. + */ + +/* + * EEPROM access time values: + * + * Driver initiates EEPROM read by writing byte address << 1 to CSR_EEPROM_REG, + * then clearing (with subsequent read/modify/write) CSR_EEPROM_REG bit + * CSR_EEPROM_REG_BIT_CMD (0x2). + * Driver then polls CSR_EEPROM_REG for CSR_EEPROM_REG_READ_VALID_MSK (0x1). + * When polling, wait 10 uSec between polling loops, up to a maximum 5000 uSec. + * Driver reads 16-bit value from bits 31-16 of CSR_EEPROM_REG. + */ +#define IWL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */ +#define IWL_EEPROM_ACCESS_DELAY 10 /* uSec */ + +/* + * Regulatory channel usage flags in EEPROM struct iwl4965_eeprom_channel.flags. + * + * IBSS and/or AP operation is allowed *only* on those channels with + * (VALID && IBSS && ACTIVE && !RADAR). This restriction is in place because + * RADAR detection is not supported by the 4965 driver, but is a + * requirement for establishing a new network for legal operation on channels + * requiring RADAR detection or restricting ACTIVE scanning. + * + * NOTE: "WIDE" flag does not indicate anything about "FAT" 40 MHz channels. + * It only indicates that 20 MHz channel use is supported; FAT channel + * usage is indicated by a separate set of regulatory flags for each + * FAT channel pair. + * + * NOTE: Using a channel inappropriately will result in a uCode error! + */ +enum { + EEPROM_CHANNEL_VALID = (1 << 0), /* usable for this SKU/geo */ + EEPROM_CHANNEL_IBSS = (1 << 1), /* usable as an IBSS channel */ + /* Bit 2 Reserved */ + EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */ + EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */ + EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */ + EEPROM_CHANNEL_NARROW = (1 << 6), /* 10 MHz channel (not used) */ + EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */ +}; + +/* SKU Capabilities */ +#define EEPROM_SKU_CAP_SW_RF_KILL_ENABLE (1 << 0) +#define EEPROM_SKU_CAP_HW_RF_KILL_ENABLE (1 << 1) + +/* *regulatory* channel data format in eeprom, one for each channel. + * There are separate entries for FAT (40 MHz) vs. normal (20 MHz) channels. */ +struct iwl4965_eeprom_channel { + u8 flags; /* EEPROM_CHANNEL_* flags copied from EEPROM */ + s8 max_power_avg; /* max power (dBm) on this chnl, limit 31 */ +} __attribute__ ((packed)); + +/* 4965 has two radio transmitters (and 3 radio receivers) */ +#define EEPROM_TX_POWER_TX_CHAINS (2) + +/* 4965 has room for up to 8 sets of txpower calibration data */ +#define EEPROM_TX_POWER_BANDS (8) + +/* 4965 factory calibration measures txpower gain settings for + * each of 3 target output levels */ +#define EEPROM_TX_POWER_MEASUREMENTS (3) + +/* 4965 driver does not work with txpower calibration version < 5. + * Look for this in calib_version member of struct iwl4965_eeprom. */ +#define EEPROM_TX_POWER_VERSION_NEW (5) + + +/* + * 4965 factory calibration data for one txpower level, on one channel, + * measured on one of the 2 tx chains (radio transmitter and associated + * antenna). EEPROM contains: + * + * 1) Temperature (degrees Celsius) of device when measurement was made. + * + * 2) Gain table index used to achieve the target measurement power. + * This refers to the "well-known" gain tables (see iwl-4965-hw.h). + * + * 3) Actual measured output power, in half-dBm ("34" = 17 dBm). + * + * 4) RF power amplifier detector level measurement (not used). + */ +struct iwl4965_eeprom_calib_measure { + u8 temperature; /* Device temperature (Celsius) */ + u8 gain_idx; /* Index into gain table */ + u8 actual_pow; /* Measured RF output power, half-dBm */ + s8 pa_det; /* Power amp detector level (not used) */ +} __attribute__ ((packed)); + + +/* + * 4965 measurement set for one channel. EEPROM contains: + * + * 1) Channel number measured + * + * 2) Measurements for each of 3 power levels for each of 2 radio transmitters + * (a.k.a. "tx chains") (6 measurements altogether) + */ +struct iwl4965_eeprom_calib_ch_info { + u8 ch_num; + struct iwl4965_eeprom_calib_measure measurements[EEPROM_TX_POWER_TX_CHAINS] + [EEPROM_TX_POWER_MEASUREMENTS]; +} __attribute__ ((packed)); + +/* + * 4965 txpower subband info. + * + * For each frequency subband, EEPROM contains the following: + * + * 1) First and last channels within range of the subband. "0" values + * indicate that this sample set is not being used. + * + * 2) Sample measurement sets for 2 channels close to the range endpoints. + */ +struct iwl4965_eeprom_calib_subband_info { + u8 ch_from; /* channel number of lowest channel in subband */ + u8 ch_to; /* channel number of highest channel in subband */ + struct iwl4965_eeprom_calib_ch_info ch1; + struct iwl4965_eeprom_calib_ch_info ch2; +} __attribute__ ((packed)); + + +/* + * 4965 txpower calibration info. EEPROM contains: + * + * 1) Factory-measured saturation power levels (maximum levels at which + * tx power amplifier can output a signal without too much distortion). + * There is one level for 2.4 GHz band and one for 5 GHz band. These + * values apply to all channels within each of the bands. + * + * 2) Factory-measured power supply voltage level. This is assumed to be + * constant (i.e. same value applies to all channels/bands) while the + * factory measurements are being made. + * + * 3) Up to 8 sets of factory-measured txpower calibration values. + * These are for different frequency ranges, since txpower gain + * characteristics of the analog radio circuitry vary with frequency. + * + * Not all sets need to be filled with data; + * struct iwl4965_eeprom_calib_subband_info contains range of channels + * (0 if unused) for each set of data. + */ +struct iwl4965_eeprom_calib_info { + u8 saturation_power24; /* half-dBm (e.g. "34" = 17 dBm) */ + u8 saturation_power52; /* half-dBm */ + s16 voltage; /* signed */ + struct iwl4965_eeprom_calib_subband_info band_info[EEPROM_TX_POWER_BANDS]; +} __attribute__ ((packed)); + + +/* + * 4965 EEPROM map + */ +struct iwl4965_eeprom { + u8 reserved0[16]; +#define EEPROM_DEVICE_ID (2*0x08) /* 2 bytes */ + u16 device_id; /* abs.ofs: 16 */ + u8 reserved1[2]; +#define EEPROM_PMC (2*0x0A) /* 2 bytes */ + u16 pmc; /* abs.ofs: 20 */ + u8 reserved2[20]; +#define EEPROM_MAC_ADDRESS (2*0x15) /* 6 bytes */ + u8 mac_address[6]; /* abs.ofs: 42 */ + u8 reserved3[58]; +#define EEPROM_BOARD_REVISION (2*0x35) /* 2 bytes */ + u16 board_revision; /* abs.ofs: 106 */ + u8 reserved4[11]; +#define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1) /* 9 bytes */ + u8 board_pba_number[9]; /* abs.ofs: 119 */ + u8 reserved5[8]; +#define EEPROM_VERSION (2*0x44) /* 2 bytes */ + u16 version; /* abs.ofs: 136 */ +#define EEPROM_SKU_CAP (2*0x45) /* 1 bytes */ + u8 sku_cap; /* abs.ofs: 138 */ +#define EEPROM_LEDS_MODE (2*0x45+1) /* 1 bytes */ + u8 leds_mode; /* abs.ofs: 139 */ +#define EEPROM_OEM_MODE (2*0x46) /* 2 bytes */ + u16 oem_mode; +#define EEPROM_WOWLAN_MODE (2*0x47) /* 2 bytes */ + u16 wowlan_mode; /* abs.ofs: 142 */ +#define EEPROM_LEDS_TIME_INTERVAL (2*0x48) /* 2 bytes */ + u16 leds_time_interval; /* abs.ofs: 144 */ +#define EEPROM_LEDS_OFF_TIME (2*0x49) /* 1 bytes */ + u8 leds_off_time; /* abs.ofs: 146 */ +#define EEPROM_LEDS_ON_TIME (2*0x49+1) /* 1 bytes */ + u8 leds_on_time; /* abs.ofs: 147 */ +#define EEPROM_ALMGOR_M_VERSION (2*0x4A) /* 1 bytes */ + u8 almgor_m_version; /* abs.ofs: 148 */ +#define EEPROM_ANTENNA_SWITCH_TYPE (2*0x4A+1) /* 1 bytes */ + u8 antenna_switch_type; /* abs.ofs: 149 */ + u8 reserved6[8]; +#define EEPROM_4965_BOARD_REVISION (2*0x4F) /* 2 bytes */ + u16 board_revision_4965; /* abs.ofs: 158 */ + u8 reserved7[13]; +#define EEPROM_4965_BOARD_PBA (2*0x56+1) /* 9 bytes */ + u8 board_pba_number_4965[9]; /* abs.ofs: 173 */ + u8 reserved8[10]; +#define EEPROM_REGULATORY_SKU_ID (2*0x60) /* 4 bytes */ + u8 sku_id[4]; /* abs.ofs: 192 */ + +/* + * Per-channel regulatory data. + * + * Each channel that *might* be supported by 3945 or 4965 has a fixed location + * in EEPROM containing EEPROM_CHANNEL_* usage flags (LSB) and max regulatory + * txpower (MSB). + * + * Entries immediately below are for 20 MHz channel width. FAT (40 MHz) + * channels (only for 4965, not supported by 3945) appear later in the EEPROM. + * + * 2.4 GHz channels 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 + */ +#define EEPROM_REGULATORY_BAND_1 (2*0x62) /* 2 bytes */ + u16 band_1_count; /* abs.ofs: 196 */ +#define EEPROM_REGULATORY_BAND_1_CHANNELS (2*0x63) /* 28 bytes */ + struct iwl4965_eeprom_channel band_1_channels[14]; /* abs.ofs: 196 */ + +/* + * 4.9 GHz channels 183, 184, 185, 187, 188, 189, 192, 196, + * 5.0 GHz channels 7, 8, 11, 12, 16 + * (4915-5080MHz) (none of these is ever supported) + */ +#define EEPROM_REGULATORY_BAND_2 (2*0x71) /* 2 bytes */ + u16 band_2_count; /* abs.ofs: 226 */ +#define EEPROM_REGULATORY_BAND_2_CHANNELS (2*0x72) /* 26 bytes */ + struct iwl4965_eeprom_channel band_2_channels[13]; /* abs.ofs: 228 */ + +/* + * 5.2 GHz channels 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 + * (5170-5320MHz) + */ +#define EEPROM_REGULATORY_BAND_3 (2*0x7F) /* 2 bytes */ + u16 band_3_count; /* abs.ofs: 254 */ +#define EEPROM_REGULATORY_BAND_3_CHANNELS (2*0x80) /* 24 bytes */ + struct iwl4965_eeprom_channel band_3_channels[12]; /* abs.ofs: 256 */ + +/* + * 5.5 GHz channels 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 + * (5500-5700MHz) + */ +#define EEPROM_REGULATORY_BAND_4 (2*0x8C) /* 2 bytes */ + u16 band_4_count; /* abs.ofs: 280 */ +#define EEPROM_REGULATORY_BAND_4_CHANNELS (2*0x8D) /* 22 bytes */ + struct iwl4965_eeprom_channel band_4_channels[11]; /* abs.ofs: 282 */ + +/* + * 5.7 GHz channels 145, 149, 153, 157, 161, 165 + * (5725-5825MHz) + */ +#define EEPROM_REGULATORY_BAND_5 (2*0x98) /* 2 bytes */ + u16 band_5_count; /* abs.ofs: 304 */ +#define EEPROM_REGULATORY_BAND_5_CHANNELS (2*0x99) /* 12 bytes */ + struct iwl4965_eeprom_channel band_5_channels[6]; /* abs.ofs: 306 */ + + u8 reserved10[2]; + + +/* + * 2.4 GHz FAT channels 1 (5), 2 (6), 3 (7), 4 (8), 5 (9), 6 (10), 7 (11) + * + * The channel listed is the center of the lower 20 MHz half of the channel. + * The overall center frequency is actually 2 channels (10 MHz) above that, + * and the upper half of each FAT channel is centered 4 channels (20 MHz) away + * from the lower half; e.g. the upper half of FAT channel 1 is channel 5, + * and the overall FAT channel width centers on channel 3. + * + * NOTE: The RXON command uses 20 MHz channel numbers to specify the + * control channel to which to tune. RXON also specifies whether the + * control channel is the upper or lower half of a FAT channel. + * + * NOTE: 4965 does not support FAT channels on 2.4 GHz. + */ +#define EEPROM_REGULATORY_BAND_24_FAT_CHANNELS (2*0xA0) /* 14 bytes */ + struct iwl4965_eeprom_channel band_24_channels[7]; /* abs.ofs: 320 */ + u8 reserved11[2]; + +/* + * 5.2 GHz FAT channels 36 (40), 44 (48), 52 (56), 60 (64), + * 100 (104), 108 (112), 116 (120), 124 (128), 132 (136), 149 (153), 157 (161) + */ +#define EEPROM_REGULATORY_BAND_52_FAT_CHANNELS (2*0xA8) /* 22 bytes */ + struct iwl4965_eeprom_channel band_52_channels[11]; /* abs.ofs: 336 */ + u8 reserved12[6]; + +/* + * 4965 driver requires txpower calibration format version 5 or greater. + * Driver does not work with txpower calibration version < 5. + * This value is simply a 16-bit number, no major/minor versions here. + */ +#define EEPROM_CALIB_VERSION_OFFSET (2*0xB6) /* 2 bytes */ + u16 calib_version; /* abs.ofs: 364 */ + u8 reserved13[2]; + u8 reserved14[96]; /* abs.ofs: 368 */ + +/* + * 4965 Txpower calibration data. + */ +#define EEPROM_IWL_CALIB_TXPOWER_OFFSET (2*0xE8) /* 48 bytes */ + struct iwl4965_eeprom_calib_info calib_info; /* abs.ofs: 464 */ + + u8 reserved16[140]; /* fill out to full 1024 byte block */ + + +} __attribute__ ((packed)); + +#define IWL_EEPROM_IMAGE_SIZE 1024 + +/* End of EEPROM */ + +#include "iwl-4965-commands.h" + +#define PCI_LINK_CTRL 0x0F0 +#define PCI_POWER_SOURCE 0x0C8 +#define PCI_REG_WUM8 0x0E8 +#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000) + +/*=== CSR (control and status registers) ===*/ +#define CSR_BASE (0x000) + +#define CSR_SW_VER (CSR_BASE+0x000) +#define CSR_HW_IF_CONFIG_REG (CSR_BASE+0x000) /* hardware interface config */ +#define CSR_INT_COALESCING (CSR_BASE+0x004) /* accum ints, 32-usec units */ +#define CSR_INT (CSR_BASE+0x008) /* host interrupt status/ack */ +#define CSR_INT_MASK (CSR_BASE+0x00c) /* host interrupt enable */ +#define CSR_FH_INT_STATUS (CSR_BASE+0x010) /* busmaster int status/ack*/ +#define CSR_GPIO_IN (CSR_BASE+0x018) /* read external chip pins */ +#define CSR_RESET (CSR_BASE+0x020) /* busmaster enable, NMI, etc*/ +#define CSR_GP_CNTRL (CSR_BASE+0x024) + +/* + * Hardware revision info + * Bit fields: + * 31-8: Reserved + * 7-4: Type of device: 0x0 = 4965, 0xd = 3945 + * 3-2: Revision step: 0 = A, 1 = B, 2 = C, 3 = D + * 1-0: "Dash" value, as in A-1, etc. + * + * NOTE: Revision step affects calculation of CCK txpower for 4965. + */ +#define CSR_HW_REV (CSR_BASE+0x028) + +/* EEPROM reads */ +#define CSR_EEPROM_REG (CSR_BASE+0x02c) +#define CSR_EEPROM_GP (CSR_BASE+0x030) +#define CSR_GP_UCODE (CSR_BASE+0x044) +#define CSR_UCODE_DRV_GP1 (CSR_BASE+0x054) +#define CSR_UCODE_DRV_GP1_SET (CSR_BASE+0x058) +#define CSR_UCODE_DRV_GP1_CLR (CSR_BASE+0x05c) +#define CSR_UCODE_DRV_GP2 (CSR_BASE+0x060) +#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100) + +/* + * Indicates hardware rev, to determine CCK backoff for txpower calculation. + * Bit fields: + * 3-2: 0 = A, 1 = B, 2 = C, 3 = D step + */ +#define CSR_HW_REV_WA_REG (CSR_BASE+0x22C) + +/* Hardware interface configuration bits */ +#define CSR_HW_IF_CONFIG_REG_BIT_KEDRON_R (0x00000010) +#define CSR_HW_IF_CONFIG_REG_MSK_BOARD_VER (0x00000C00) +#define CSR_HW_IF_CONFIG_REG_BIT_MAC_SI (0x00000100) +#define CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI (0x00000200) +#define CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM (0x00200000) + +/* interrupt flags in INTA, set by uCode or hardware (e.g. dma), + * acknowledged (reset) by host writing "1" to flagged bits. */ +#define CSR_INT_BIT_FH_RX (1 << 31) /* Rx DMA, cmd responses, FH_INT[17:16] */ +#define CSR_INT_BIT_HW_ERR (1 << 29) /* DMA hardware error FH_INT[31] */ +#define CSR_INT_BIT_DNLD (1 << 28) /* uCode Download */ +#define CSR_INT_BIT_FH_TX (1 << 27) /* Tx DMA FH_INT[1:0] */ +#define CSR_INT_BIT_MAC_CLK_ACTV (1 << 26) /* NIC controller's clock toggled on/off */ +#define CSR_INT_BIT_SW_ERR (1 << 25) /* uCode error */ +#define CSR_INT_BIT_RF_KILL (1 << 7) /* HW RFKILL switch GP_CNTRL[27] toggled */ +#define CSR_INT_BIT_CT_KILL (1 << 6) /* Critical temp (chip too hot) rfkill */ +#define CSR_INT_BIT_SW_RX (1 << 3) /* Rx, command responses, 3945 */ +#define CSR_INT_BIT_WAKEUP (1 << 1) /* NIC controller waking up (pwr mgmt) */ +#define CSR_INT_BIT_ALIVE (1 << 0) /* uCode interrupts once it initializes */ + +#define CSR_INI_SET_MASK (CSR_INT_BIT_FH_RX | \ + CSR_INT_BIT_HW_ERR | \ + CSR_INT_BIT_FH_TX | \ + CSR_INT_BIT_SW_ERR | \ + CSR_INT_BIT_RF_KILL | \ + CSR_INT_BIT_SW_RX | \ + CSR_INT_BIT_WAKEUP | \ + CSR_INT_BIT_ALIVE) + +/* interrupt flags in FH (flow handler) (PCI busmaster DMA) */ +#define CSR_FH_INT_BIT_ERR (1 << 31) /* Error */ +#define CSR_FH_INT_BIT_HI_PRIOR (1 << 30) /* High priority Rx, bypass coalescing */ +#define CSR_FH_INT_BIT_RX_CHNL1 (1 << 17) /* Rx channel 1 */ +#define CSR_FH_INT_BIT_RX_CHNL0 (1 << 16) /* Rx channel 0 */ +#define CSR_FH_INT_BIT_TX_CHNL1 (1 << 1) /* Tx channel 1 */ +#define CSR_FH_INT_BIT_TX_CHNL0 (1 << 0) /* Tx channel 0 */ + +#define CSR_FH_INT_RX_MASK (CSR_FH_INT_BIT_HI_PRIOR | \ + CSR_FH_INT_BIT_RX_CHNL1 | \ + CSR_FH_INT_BIT_RX_CHNL0) + +#define CSR_FH_INT_TX_MASK (CSR_FH_INT_BIT_TX_CHNL1 | \ + CSR_FH_INT_BIT_TX_CHNL0) + + +/* RESET */ +#define CSR_RESET_REG_FLAG_NEVO_RESET (0x00000001) +#define CSR_RESET_REG_FLAG_FORCE_NMI (0x00000002) +#define CSR_RESET_REG_FLAG_SW_RESET (0x00000080) +#define CSR_RESET_REG_FLAG_MASTER_DISABLED (0x00000100) +#define CSR_RESET_REG_FLAG_STOP_MASTER (0x00000200) + +/* GP (general purpose) CONTROL */ +#define CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY (0x00000001) +#define CSR_GP_CNTRL_REG_FLAG_INIT_DONE (0x00000004) +#define CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ (0x00000008) +#define CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP (0x00000010) + +#define CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN (0x00000001) + +#define CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE (0x07000000) +#define CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE (0x04000000) +#define CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW (0x08000000) + + +/* EEPROM REG */ +#define CSR_EEPROM_REG_READ_VALID_MSK (0x00000001) +#define CSR_EEPROM_REG_BIT_CMD (0x00000002) + +/* EEPROM GP */ +#define CSR_EEPROM_GP_VALID_MSK (0x00000006) +#define CSR_EEPROM_GP_BAD_SIGNATURE (0x00000000) +#define CSR_EEPROM_GP_IF_OWNER_MSK (0x00000180) + +/* UCODE DRV GP */ +#define CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP (0x00000001) +#define CSR_UCODE_SW_BIT_RFKILL (0x00000002) +#define CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED (0x00000004) +#define CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT (0x00000008) + +/* GPIO */ +#define CSR_GPIO_IN_BIT_AUX_POWER (0x00000200) +#define CSR_GPIO_IN_VAL_VAUX_PWR_SRC (0x00000000) +#define CSR_GPIO_IN_VAL_VMAIN_PWR_SRC CSR_GPIO_IN_BIT_AUX_POWER + +/* GI Chicken Bits */ +#define CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX (0x00800000) +#define CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER (0x20000000) + +/*=== HBUS (Host-side Bus) ===*/ +#define HBUS_BASE (0x400) + +/* + * Registers for accessing device's internal SRAM memory (e.g. SCD SRAM + * structures, error log, event log, verifying uCode load). + * First write to address register, then read from or write to data register + * to complete the job. Once the address register is set up, accesses to + * data registers auto-increment the address by one dword. + * Bit usage for address registers (read or write): + * 0-31: memory address within device + */ +#define HBUS_TARG_MEM_RADDR (HBUS_BASE+0x00c) +#define HBUS_TARG_MEM_WADDR (HBUS_BASE+0x010) +#define HBUS_TARG_MEM_WDAT (HBUS_BASE+0x018) +#define HBUS_TARG_MEM_RDAT (HBUS_BASE+0x01c) + +/* + * Registers for accessing device's internal peripheral registers + * (e.g. SCD, BSM, etc.). First write to address register, + * then read from or write to data register to complete the job. + * Bit usage for address registers (read or write): + * 0-15: register address (offset) within device + * 24-25: (# bytes - 1) to read or write (e.g. 3 for dword) + */ +#define HBUS_TARG_PRPH_WADDR (HBUS_BASE+0x044) +#define HBUS_TARG_PRPH_RADDR (HBUS_BASE+0x048) +#define HBUS_TARG_PRPH_WDAT (HBUS_BASE+0x04c) +#define HBUS_TARG_PRPH_RDAT (HBUS_BASE+0x050) + +/* + * Per-Tx-queue write pointer (index, really!) (3945 and 4965). + * Driver sets this to indicate index to next TFD that driver will fill + * (1 past latest filled). + * Bit usage: + * 0-7: queue write index (0-255) + * 11-8: queue selector (0-15) + */ +#define HBUS_TARG_WRPTR (HBUS_BASE+0x060) + +#define HBUS_TARG_MBX_C (HBUS_BASE+0x030) + +#define HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED (0x00000004) + +#define TFD_QUEUE_SIZE_MAX (256) + +#define IWL_NUM_SCAN_RATES (2) + +#define IWL_DEFAULT_TX_RETRY 15 + +#define RX_QUEUE_SIZE 256 +#define RX_QUEUE_MASK 255 +#define RX_QUEUE_SIZE_LOG 8 + +#define TFD_TX_CMD_SLOTS 256 +#define TFD_CMD_SLOTS 32 + +#define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl4965_cmd) - \ + sizeof(struct iwl4965_cmd_meta)) + +/* + * RX related structures and functions + */ +#define RX_FREE_BUFFERS 64 +#define RX_LOW_WATERMARK 8 + +/* Size of one Rx buffer in host DRAM */ +#define IWL_RX_BUF_SIZE_4K (4 * 1024) +#define IWL_RX_BUF_SIZE_8K (8 * 1024) + +/* Sizes and addresses for instruction and data memory (SRAM) in + * 4965's embedded processor. Driver access is via HBUS_TARG_MEM_* regs. */ +#define RTC_INST_LOWER_BOUND (0x000000) #define KDR_RTC_INST_UPPER_BOUND (0x018000) + +#define RTC_DATA_LOWER_BOUND (0x800000) #define KDR_RTC_DATA_UPPER_BOUND (0x80A000) + #define KDR_RTC_INST_SIZE (KDR_RTC_INST_UPPER_BOUND - RTC_INST_LOWER_BOUND) #define KDR_RTC_DATA_SIZE (KDR_RTC_DATA_UPPER_BOUND - RTC_DATA_LOWER_BOUND) #define IWL_MAX_INST_SIZE KDR_RTC_INST_SIZE #define IWL_MAX_DATA_SIZE KDR_RTC_DATA_SIZE -static inline int iwl_hw_valid_rtc_data_addr(u32 addr) +/* Size of uCode instruction memory in bootstrap state machine */ +#define IWL_MAX_BSM_SIZE BSM_SRAM_SIZE + +static inline int iwl4965_hw_valid_rtc_data_addr(u32 addr) { return (addr >= RTC_DATA_LOWER_BOUND) && (addr < KDR_RTC_DATA_UPPER_BOUND); } -/********************* START TXPOWER *****************************************/ -enum { - HT_IE_EXT_CHANNEL_NONE = 0, - HT_IE_EXT_CHANNEL_ABOVE, - HT_IE_EXT_CHANNEL_INVALID, - HT_IE_EXT_CHANNEL_BELOW, - HT_IE_EXT_CHANNEL_MAX -}; - -enum { - CALIB_CH_GROUP_1 = 0, - CALIB_CH_GROUP_2 = 1, - CALIB_CH_GROUP_3 = 2, - CALIB_CH_GROUP_4 = 3, - CALIB_CH_GROUP_5 = 4, - CALIB_CH_GROUP_MAX -}; +/********************* START TEMPERATURE *************************************/ -/* Temperature calibration offset is 3% 0C in Kelvin */ +/** + * 4965 temperature calculation. + * + * The driver must calculate the device temperature before calculating + * a txpower setting (amplifier gain is temperature dependent). The + * calculation uses 4 measurements, 3 of which (R1, R2, R3) are calibration + * values used for the life of the driver, and one of which (R4) is the + * real-time temperature indicator. + * + * uCode provides all 4 values to the driver via the "initialize alive" + * notification (see struct iwl4965_init_alive_resp). After the runtime uCode + * image loads, uCode updates the R4 value via statistics notifications + * (see STATISTICS_NOTIFICATION), which occur after each received beacon + * when associated, or can be requested via REPLY_STATISTICS_CMD. + * + * NOTE: uCode provides the R4 value as a 23-bit signed value. Driver + * must sign-extend to 32 bits before applying formula below. + * + * Formula: + * + * degrees Kelvin = ((97 * 259 * (R4 - R2) / (R3 - R1)) / 100) + 8 + * + * NOTE: The basic formula is 259 * (R4-R2) / (R3-R1). The 97/100 is + * an additional correction, which should be centered around 0 degrees + * Celsius (273 degrees Kelvin). The 8 (3 percent of 273) compensates for + * centering the 97/100 correction around 0 degrees K. + * + * Add 273 to Kelvin value to find degrees Celsius, for comparing current + * temperature with factory-measured temperatures when calculating txpower + * settings. + */ #define TEMPERATURE_CALIB_KELVIN_OFFSET 8 #define TEMPERATURE_CALIB_A_VAL 259 +/* Limit range of calculated temperature to be between these Kelvin values */ #define IWL_TX_POWER_TEMPERATURE_MIN (263) #define IWL_TX_POWER_TEMPERATURE_MAX (410) @@ -109,228 +679,875 @@ enum { (((t) < IWL_TX_POWER_TEMPERATURE_MIN) || \ ((t) > IWL_TX_POWER_TEMPERATURE_MAX)) -#define IWL_TX_POWER_ILLEGAL_TEMPERATURE (300) +/********************* END TEMPERATURE ***************************************/ -#define IWL_TX_POWER_TEMPERATURE_DIFFERENCE (2) +/********************* START TXPOWER *****************************************/ -#define IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION (6) +/** + * 4965 txpower calculations rely on information from three sources: + * + * 1) EEPROM + * 2) "initialize" alive notification + * 3) statistics notifications + * + * EEPROM data consists of: + * + * 1) Regulatory information (max txpower and channel usage flags) is provided + * separately for each channel that can possibly supported by 4965. + * 40 MHz wide (.11n fat) channels are listed separately from 20 MHz + * (legacy) channels. + * + * See struct iwl4965_eeprom_channel for format, and struct iwl4965_eeprom + * for locations in EEPROM. + * + * 2) Factory txpower calibration information is provided separately for + * sub-bands of contiguous channels. 2.4GHz has just one sub-band, + * but 5 GHz has several sub-bands. + * + * In addition, per-band (2.4 and 5 Ghz) saturation txpowers are provided. + * + * See struct iwl4965_eeprom_calib_info (and the tree of structures + * contained within it) for format, and struct iwl4965_eeprom for + * locations in EEPROM. + * + * "Initialization alive" notification (see struct iwl4965_init_alive_resp) + * consists of: + * + * 1) Temperature calculation parameters. + * + * 2) Power supply voltage measurement. + * + * 3) Tx gain compensation to balance 2 transmitters for MIMO use. + * + * Statistics notifications deliver: + * + * 1) Current values for temperature param R4. + */ + +/** + * To calculate a txpower setting for a given desired target txpower, channel, + * modulation bit rate, and transmitter chain (4965 has 2 transmitters to + * support MIMO and transmit diversity), driver must do the following: + * + * 1) Compare desired txpower vs. (EEPROM) regulatory limit for this channel. + * Do not exceed regulatory limit; reduce target txpower if necessary. + * + * If setting up txpowers for MIMO rates (rate indexes 8-15, 24-31), + * 2 transmitters will be used simultaneously; driver must reduce the + * regulatory limit by 3 dB (half-power) for each transmitter, so the + * combined total output of the 2 transmitters is within regulatory limits. + * + * + * 2) Compare target txpower vs. (EEPROM) saturation txpower *reduced by + * backoff for this bit rate*. Do not exceed (saturation - backoff[rate]); + * reduce target txpower if necessary. + * + * Backoff values below are in 1/2 dB units (equivalent to steps in + * txpower gain tables): + * + * OFDM 6 - 36 MBit: 10 steps (5 dB) + * OFDM 48 MBit: 15 steps (7.5 dB) + * OFDM 54 MBit: 17 steps (8.5 dB) + * OFDM 60 MBit: 20 steps (10 dB) + * CCK all rates: 10 steps (5 dB) + * + * Backoff values apply to saturation txpower on a per-transmitter basis; + * when using MIMO (2 transmitters), each transmitter uses the same + * saturation level provided in EEPROM, and the same backoff values; + * no reduction (such as with regulatory txpower limits) is required. + * + * Saturation and Backoff values apply equally to 20 Mhz (legacy) channel + * widths and 40 Mhz (.11n fat) channel widths; there is no separate + * factory measurement for fat channels. + * + * The result of this step is the final target txpower. The rest of + * the steps figure out the proper settings for the device to achieve + * that target txpower. + * + * + * 3) Determine (EEPROM) calibration subband for the target channel, by + * comparing against first and last channels in each subband + * (see struct iwl4965_eeprom_calib_subband_info). + * + * + * 4) Linearly interpolate (EEPROM) factory calibration measurement sets, + * referencing the 2 factory-measured (sample) channels within the subband. + * + * Interpolation is based on difference between target channel's frequency + * and the sample channels' frequencies. Since channel numbers are based + * on frequency (5 MHz between each channel number), this is equivalent + * to interpolating based on channel number differences. + * + * Note that the sample channels may or may not be the channels at the + * edges of the subband. The target channel may be "outside" of the + * span of the sampled channels. + * + * Driver may choose the pair (for 2 Tx chains) of measurements (see + * struct iwl4965_eeprom_calib_ch_info) for which the actual measured + * txpower comes closest to the desired txpower. Usually, though, + * the middle set of measurements is closest to the regulatory limits, + * and is therefore a good choice for all txpower calculations (this + * assumes that high accuracy is needed for maximizing legal txpower, + * while lower txpower configurations do not need as much accuracy). + * + * Driver should interpolate both members of the chosen measurement pair, + * i.e. for both Tx chains (radio transmitters), unless the driver knows + * that only one of the chains will be used (e.g. only one tx antenna + * connected, but this should be unusual). The rate scaling algorithm + * switches antennas to find best performance, so both Tx chains will + * be used (although only one at a time) even for non-MIMO transmissions. + * + * Driver should interpolate factory values for temperature, gain table + * index, and actual power. The power amplifier detector values are + * not used by the driver. + * + * Sanity check: If the target channel happens to be one of the sample + * channels, the results should agree with the sample channel's + * measurements! + * + * + * 5) Find difference between desired txpower and (interpolated) + * factory-measured txpower. Using (interpolated) factory gain table index + * (shown elsewhere) as a starting point, adjust this index lower to + * increase txpower, or higher to decrease txpower, until the target + * txpower is reached. Each step in the gain table is 1/2 dB. + * + * For example, if factory measured txpower is 16 dBm, and target txpower + * is 13 dBm, add 6 steps to the factory gain index to reduce txpower + * by 3 dB. + * + * + * 6) Find difference between current device temperature and (interpolated) + * factory-measured temperature for sub-band. Factory values are in + * degrees Celsius. To calculate current temperature, see comments for + * "4965 temperature calculation". + * + * If current temperature is higher than factory temperature, driver must + * increase gain (lower gain table index), and vice versa. + * + * Temperature affects gain differently for different channels: + * + * 2.4 GHz all channels: 3.5 degrees per half-dB step + * 5 GHz channels 34-43: 4.5 degrees per half-dB step + * 5 GHz channels >= 44: 4.0 degrees per half-dB step + * + * NOTE: Temperature can increase rapidly when transmitting, especially + * with heavy traffic at high txpowers. Driver should update + * temperature calculations often under these conditions to + * maintain strong txpower in the face of rising temperature. + * + * + * 7) Find difference between current power supply voltage indicator + * (from "initialize alive") and factory-measured power supply voltage + * indicator (EEPROM). + * + * If the current voltage is higher (indicator is lower) than factory + * voltage, gain should be reduced (gain table index increased) by: + * + * (eeprom - current) / 7 + * + * If the current voltage is lower (indicator is higher) than factory + * voltage, gain should be increased (gain table index decreased) by: + * + * 2 * (current - eeprom) / 7 + * + * If number of index steps in either direction turns out to be > 2, + * something is wrong ... just use 0. + * + * NOTE: Voltage compensation is independent of band/channel. + * + * NOTE: "Initialize" uCode measures current voltage, which is assumed + * to be constant after this initial measurement. Voltage + * compensation for txpower (number of steps in gain table) + * may be calculated once and used until the next uCode bootload. + * + * + * 8) If setting up txpowers for MIMO rates (rate indexes 8-15, 24-31), + * adjust txpower for each transmitter chain, so txpower is balanced + * between the two chains. There are 5 pairs of tx_atten[group][chain] + * values in "initialize alive", one pair for each of 5 channel ranges: + * + * Group 0: 5 GHz channel 34-43 + * Group 1: 5 GHz channel 44-70 + * Group 2: 5 GHz channel 71-124 + * Group 3: 5 GHz channel 125-200 + * Group 4: 2.4 GHz all channels + * + * Add the tx_atten[group][chain] value to the index for the target chain. + * The values are signed, but are in pairs of 0 and a non-negative number, + * so as to reduce gain (if necessary) of the "hotter" channel. This + * avoids any need to double-check for regulatory compliance after + * this step. + * + * + * 9) If setting up for a CCK rate, lower the gain by adding a CCK compensation + * value to the index: + * + * Hardware rev B: 9 steps (4.5 dB) + * Hardware rev C: 5 steps (2.5 dB) + * + * Hardware rev for 4965 can be determined by reading CSR_HW_REV_WA_REG, + * bits [3:2], 1 = B, 2 = C. + * + * NOTE: This compensation is in addition to any saturation backoff that + * might have been applied in an earlier step. + * + * + * 10) Select the gain table, based on band (2.4 vs 5 GHz). + * + * Limit the adjusted index to stay within the table! + * + * + * 11) Read gain table entries for DSP and radio gain, place into appropriate + * location(s) in command (struct iwl4965_txpowertable_cmd). + */ +/* Limit range of txpower output target to be between these values */ #define IWL_TX_POWER_TARGET_POWER_MIN (0) /* 0 dBm = 1 milliwatt */ #define IWL_TX_POWER_TARGET_POWER_MAX (16) /* 16 dBm */ -/* timeout equivalent to 3 minutes */ -#define IWL_TX_POWER_TIMELIMIT_NOCALIB 1800000000 - -#define IWL_TX_POWER_CCK_COMPENSATION (9) - -#define MIN_TX_GAIN_INDEX (0) -#define MIN_TX_GAIN_INDEX_52GHZ_EXT (-9) -#define MAX_TX_GAIN_INDEX_52GHZ (98) -#define MIN_TX_GAIN_52GHZ (98) -#define MAX_TX_GAIN_INDEX_24GHZ (98) -#define MIN_TX_GAIN_24GHZ (98) -#define MAX_TX_GAIN (0) -#define MAX_TX_GAIN_52GHZ_EXT (-9) +/** + * When MIMO is used (2 transmitters operating simultaneously), driver should + * limit each transmitter to deliver a max of 3 dB below the regulatory limit + * for the device. That is, use half power for each transmitter, so total + * txpower is within regulatory limits. + * + * The value "6" represents number of steps in gain table to reduce power 3 dB. + * Each step is 1/2 dB. + */ +#define IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION (6) +/** + * CCK gain compensation. + * + * When calculating txpowers for CCK, after making sure that the target power + * is within regulatory and saturation limits, driver must additionally + * back off gain by adding these values to the gain table index. + * + * Hardware rev for 4965 can be determined by reading CSR_HW_REV_WA_REG, + * bits [3:2], 1 = B, 2 = C. + */ +#define IWL_TX_POWER_CCK_COMPENSATION_B_STEP (9) +#define IWL_TX_POWER_CCK_COMPENSATION_C_STEP (5) + +/* + * 4965 power supply voltage compensation for txpower + */ +#define TX_POWER_IWL_VOLTAGE_CODES_PER_03V (7) + +/** + * Gain tables. + * + * The following tables contain pair of values for setting txpower, i.e. + * gain settings for the output of the device's digital signal processor (DSP), + * and for the analog gain structure of the transmitter. + * + * Each entry in the gain tables represents a step of 1/2 dB. Note that these + * are *relative* steps, not indications of absolute output power. Output + * power varies with temperature, voltage, and channel frequency, and also + * requires consideration of average power (to satisfy regulatory constraints), + * and peak power (to avoid distortion of the output signal). + * + * Each entry contains two values: + * 1) DSP gain (or sometimes called DSP attenuation). This is a fine-grained + * linear value that multiplies the output of the digital signal processor, + * before being sent to the analog radio. + * 2) Radio gain. This sets the analog gain of the radio Tx path. + * It is a coarser setting, and behaves in a logarithmic (dB) fashion. + * + * EEPROM contains factory calibration data for txpower. This maps actual + * measured txpower levels to gain settings in the "well known" tables + * below ("well-known" means here that both factory calibration *and* the + * driver work with the same table). + * + * There are separate tables for 2.4 GHz and 5 GHz bands. The 5 GHz table + * has an extension (into negative indexes), in case the driver needs to + * boost power setting for high device temperatures (higher than would be + * present during factory calibration). A 5 Ghz EEPROM index of "40" + * corresponds to the 49th entry in the table used by the driver. + */ +#define MIN_TX_GAIN_INDEX (0) /* highest gain, lowest idx, 2.4 */ +#define MIN_TX_GAIN_INDEX_52GHZ_EXT (-9) /* highest gain, lowest idx, 5 */ + +/** + * 2.4 GHz gain table + * + * Index Dsp gain Radio gain + * 0 110 0x3f (highest gain) + * 1 104 0x3f + * 2 98 0x3f + * 3 110 0x3e + * 4 104 0x3e + * 5 98 0x3e + * 6 110 0x3d + * 7 104 0x3d + * 8 98 0x3d + * 9 110 0x3c + * 10 104 0x3c + * 11 98 0x3c + * 12 110 0x3b + * 13 104 0x3b + * 14 98 0x3b + * 15 110 0x3a + * 16 104 0x3a + * 17 98 0x3a + * 18 110 0x39 + * 19 104 0x39 + * 20 98 0x39 + * 21 110 0x38 + * 22 104 0x38 + * 23 98 0x38 + * 24 110 0x37 + * 25 104 0x37 + * 26 98 0x37 + * 27 110 0x36 + * 28 104 0x36 + * 29 98 0x36 + * 30 110 0x35 + * 31 104 0x35 + * 32 98 0x35 + * 33 110 0x34 + * 34 104 0x34 + * 35 98 0x34 + * 36 110 0x33 + * 37 104 0x33 + * 38 98 0x33 + * 39 110 0x32 + * 40 104 0x32 + * 41 98 0x32 + * 42 110 0x31 + * 43 104 0x31 + * 44 98 0x31 + * 45 110 0x30 + * 46 104 0x30 + * 47 98 0x30 + * 48 110 0x6 + * 49 104 0x6 + * 50 98 0x6 + * 51 110 0x5 + * 52 104 0x5 + * 53 98 0x5 + * 54 110 0x4 + * 55 104 0x4 + * 56 98 0x4 + * 57 110 0x3 + * 58 104 0x3 + * 59 98 0x3 + * 60 110 0x2 + * 61 104 0x2 + * 62 98 0x2 + * 63 110 0x1 + * 64 104 0x1 + * 65 98 0x1 + * 66 110 0x0 + * 67 104 0x0 + * 68 98 0x0 + * 69 97 0 + * 70 96 0 + * 71 95 0 + * 72 94 0 + * 73 93 0 + * 74 92 0 + * 75 91 0 + * 76 90 0 + * 77 89 0 + * 78 88 0 + * 79 87 0 + * 80 86 0 + * 81 85 0 + * 82 84 0 + * 83 83 0 + * 84 82 0 + * 85 81 0 + * 86 80 0 + * 87 79 0 + * 88 78 0 + * 89 77 0 + * 90 76 0 + * 91 75 0 + * 92 74 0 + * 93 73 0 + * 94 72 0 + * 95 71 0 + * 96 70 0 + * 97 69 0 + * 98 68 0 + */ + +/** + * 5 GHz gain table + * + * Index Dsp gain Radio gain + * -9 123 0x3F (highest gain) + * -8 117 0x3F + * -7 110 0x3F + * -6 104 0x3F + * -5 98 0x3F + * -4 110 0x3E + * -3 104 0x3E + * -2 98 0x3E + * -1 110 0x3D + * 0 104 0x3D + * 1 98 0x3D + * 2 110 0x3C + * 3 104 0x3C + * 4 98 0x3C + * 5 110 0x3B + * 6 104 0x3B + * 7 98 0x3B + * 8 110 0x3A + * 9 104 0x3A + * 10 98 0x3A + * 11 110 0x39 + * 12 104 0x39 + * 13 98 0x39 + * 14 110 0x38 + * 15 104 0x38 + * 16 98 0x38 + * 17 110 0x37 + * 18 104 0x37 + * 19 98 0x37 + * 20 110 0x36 + * 21 104 0x36 + * 22 98 0x36 + * 23 110 0x35 + * 24 104 0x35 + * 25 98 0x35 + * 26 110 0x34 + * 27 104 0x34 + * 28 98 0x34 + * 29 110 0x33 + * 30 104 0x33 + * 31 98 0x33 + * 32 110 0x32 + * 33 104 0x32 + * 34 98 0x32 + * 35 110 0x31 + * 36 104 0x31 + * 37 98 0x31 + * 38 110 0x30 + * 39 104 0x30 + * 40 98 0x30 + * 41 110 0x25 + * 42 104 0x25 + * 43 98 0x25 + * 44 110 0x24 + * 45 104 0x24 + * 46 98 0x24 + * 47 110 0x23 + * 48 104 0x23 + * 49 98 0x23 + * 50 110 0x22 + * 51 104 0x18 + * 52 98 0x18 + * 53 110 0x17 + * 54 104 0x17 + * 55 98 0x17 + * 56 110 0x16 + * 57 104 0x16 + * 58 98 0x16 + * 59 110 0x15 + * 60 104 0x15 + * 61 98 0x15 + * 62 110 0x14 + * 63 104 0x14 + * 64 98 0x14 + * 65 110 0x13 + * 66 104 0x13 + * 67 98 0x13 + * 68 110 0x12 + * 69 104 0x08 + * 70 98 0x08 + * 71 110 0x07 + * 72 104 0x07 + * 73 98 0x07 + * 74 110 0x06 + * 75 104 0x06 + * 76 98 0x06 + * 77 110 0x05 + * 78 104 0x05 + * 79 98 0x05 + * 80 110 0x04 + * 81 104 0x04 + * 82 98 0x04 + * 83 110 0x03 + * 84 104 0x03 + * 85 98 0x03 + * 86 110 0x02 + * 87 104 0x02 + * 88 98 0x02 + * 89 110 0x01 + * 90 104 0x01 + * 91 98 0x01 + * 92 110 0x00 + * 93 104 0x00 + * 94 98 0x00 + * 95 93 0x00 + * 96 88 0x00 + * 97 83 0x00 + * 98 78 0x00 + */ + + +/** + * Sanity checks and default values for EEPROM regulatory levels. + * If EEPROM values fall outside MIN/MAX range, use default values. + * + * Regulatory limits refer to the maximum average txpower allowed by + * regulatory agencies in the geographies in which the device is meant + * to be operated. These limits are SKU-specific (i.e. geography-specific), + * and channel-specific; each channel has an individual regulatory limit + * listed in the EEPROM. + * + * Units are in half-dBm (i.e. "34" means 17 dBm). + */ #define IWL_TX_POWER_DEFAULT_REGULATORY_24 (34) #define IWL_TX_POWER_DEFAULT_REGULATORY_52 (34) #define IWL_TX_POWER_REGULATORY_MIN (0) #define IWL_TX_POWER_REGULATORY_MAX (34) + +/** + * Sanity checks and default values for EEPROM saturation levels. + * If EEPROM values fall outside MIN/MAX range, use default values. + * + * Saturation is the highest level that the output power amplifier can produce + * without significant clipping distortion. This is a "peak" power level. + * Different types of modulation (i.e. various "rates", and OFDM vs. CCK) + * require differing amounts of backoff, relative to their average power output, + * in order to avoid clipping distortion. + * + * Driver must make sure that it is violating neither the saturation limit, + * nor the regulatory limit, when calculating Tx power settings for various + * rates. + * + * Units are in half-dBm (i.e. "38" means 19 dBm). + */ #define IWL_TX_POWER_DEFAULT_SATURATION_24 (38) #define IWL_TX_POWER_DEFAULT_SATURATION_52 (38) #define IWL_TX_POWER_SATURATION_MIN (20) #define IWL_TX_POWER_SATURATION_MAX (50) -/* dv *0.4 = dt; so that 5 degrees temperature diff equals - * 12.5 in voltage diff */ -#define IWL_TX_TEMPERATURE_UPDATE_LIMIT 9 - -#define IWL_INVALID_CHANNEL (0xffffffff) -#define IWL_TX_POWER_REGITRY_BIT (2) - -#define MIN_IWL_TX_POWER_CALIB_DUR (100) -#define IWL_CCK_FROM_OFDM_POWER_DIFF (-5) -#define IWL_CCK_FROM_OFDM_INDEX_DIFF (9) - -/* Number of entries in the gain table */ -#define POWER_GAIN_NUM_ENTRIES 78 -#define TX_POW_MAX_SESSION_NUM 5 -/* timeout equivalent to 3 minutes */ -#define TX_IWL_TIMELIMIT_NOCALIB 1800000000 - -/* Kedron TX_CALIB_STATES */ -#define IWL_TX_CALIB_STATE_SEND_TX 0x00000001 -#define IWL_TX_CALIB_WAIT_TX_RESPONSE 0x00000002 -#define IWL_TX_CALIB_ENABLED 0x00000004 -#define IWL_TX_CALIB_XVT_ON 0x00000008 -#define IWL_TX_CALIB_TEMPERATURE_CORRECT 0x00000010 -#define IWL_TX_CALIB_WORKING_WITH_XVT 0x00000020 -#define IWL_TX_CALIB_XVT_PERIODICAL 0x00000040 - -#define NUM_IWL_TX_CALIB_SETTINS 5 /* Number of tx correction groups */ - -#define IWL_MIN_POWER_IN_VP_TABLE 1 /* 0.5dBm multiplied by 2 */ -#define IWL_MAX_POWER_IN_VP_TABLE 40 /* 20dBm - multiplied by 2 (because - * entries are for each 0.5dBm) */ -#define IWL_STEP_IN_VP_TABLE 1 /* 0.5dB - multiplied by 2 */ -#define IWL_NUM_POINTS_IN_VPTABLE \ - (1 + IWL_MAX_POWER_IN_VP_TABLE - IWL_MIN_POWER_IN_VP_TABLE) - -#define MIN_TX_GAIN_INDEX (0) -#define MAX_TX_GAIN_INDEX_52GHZ (98) -#define MIN_TX_GAIN_52GHZ (98) -#define MAX_TX_GAIN_INDEX_24GHZ (98) -#define MIN_TX_GAIN_24GHZ (98) -#define MAX_TX_GAIN (0) - -/* First and last channels of all groups */ +/** + * Channel groups used for Tx Attenuation calibration (MIMO tx channel balance) + * and thermal Txpower calibration. + * + * When calculating txpower, driver must compensate for current device + * temperature; higher temperature requires higher gain. Driver must calculate + * current temperature (see "4965 temperature calculation"), then compare vs. + * factory calibration temperature in EEPROM; if current temperature is higher + * than factory temperature, driver must *increase* gain by proportions shown + * in table below. If current temperature is lower than factory, driver must + * *decrease* gain. + * + * Different frequency ranges require different compensation, as shown below. + */ +/* Group 0, 5.2 GHz ch 34-43: 4.5 degrees per 1/2 dB. */ #define CALIB_IWL_TX_ATTEN_GR1_FCH 34 #define CALIB_IWL_TX_ATTEN_GR1_LCH 43 + +/* Group 1, 5.3 GHz ch 44-70: 4.0 degrees per 1/2 dB. */ #define CALIB_IWL_TX_ATTEN_GR2_FCH 44 #define CALIB_IWL_TX_ATTEN_GR2_LCH 70 + +/* Group 2, 5.5 GHz ch 71-124: 4.0 degrees per 1/2 dB. */ #define CALIB_IWL_TX_ATTEN_GR3_FCH 71 #define CALIB_IWL_TX_ATTEN_GR3_LCH 124 + +/* Group 3, 5.7 GHz ch 125-200: 4.0 degrees per 1/2 dB. */ #define CALIB_IWL_TX_ATTEN_GR4_FCH 125 #define CALIB_IWL_TX_ATTEN_GR4_LCH 200 + +/* Group 4, 2.4 GHz all channels: 3.5 degrees per 1/2 dB. */ #define CALIB_IWL_TX_ATTEN_GR5_FCH 1 #define CALIB_IWL_TX_ATTEN_GR5_LCH 20 - -union iwl_tx_power_dual_stream { - struct { - u8 radio_tx_gain[2]; - u8 dsp_predis_atten[2]; - } s; - u32 dw; +enum { + CALIB_CH_GROUP_1 = 0, + CALIB_CH_GROUP_2 = 1, + CALIB_CH_GROUP_3 = 2, + CALIB_CH_GROUP_4 = 3, + CALIB_CH_GROUP_5 = 4, + CALIB_CH_GROUP_MAX }; /********************* END TXPOWER *****************************************/ -/* HT flags */ -#define RXON_FLG_CTRL_CHANNEL_LOC_POS (22) -#define RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK __constant_cpu_to_le32(0x1<<22) - -#define RXON_FLG_HT_OPERATING_MODE_POS (23) - -#define RXON_FLG_HT_PROT_MSK __constant_cpu_to_le32(0x1<<23) -#define RXON_FLG_FAT_PROT_MSK __constant_cpu_to_le32(0x2<<23) - -#define RXON_FLG_CHANNEL_MODE_POS (25) -#define RXON_FLG_CHANNEL_MODE_MSK __constant_cpu_to_le32(0x3<<25) -#define RXON_FLG_CHANNEL_MODE_PURE_40_MSK __constant_cpu_to_le32(0x1<<25) -#define RXON_FLG_CHANNEL_MODE_MIXED_MSK __constant_cpu_to_le32(0x2<<25) - -#define RXON_RX_CHAIN_DRIVER_FORCE_MSK __constant_cpu_to_le16(0x1<<0) -#define RXON_RX_CHAIN_VALID_MSK __constant_cpu_to_le16(0x7<<1) -#define RXON_RX_CHAIN_VALID_POS (1) -#define RXON_RX_CHAIN_FORCE_SEL_MSK __constant_cpu_to_le16(0x7<<4) -#define RXON_RX_CHAIN_FORCE_SEL_POS (4) -#define RXON_RX_CHAIN_FORCE_MIMO_SEL_MSK __constant_cpu_to_le16(0x7<<7) -#define RXON_RX_CHAIN_FORCE_MIMO_SEL_POS (7) -#define RXON_RX_CHAIN_CNT_MSK __constant_cpu_to_le16(0x3<<10) -#define RXON_RX_CHAIN_CNT_POS (10) -#define RXON_RX_CHAIN_MIMO_CNT_MSK __constant_cpu_to_le16(0x3<<12) -#define RXON_RX_CHAIN_MIMO_CNT_POS (12) -#define RXON_RX_CHAIN_MIMO_FORCE_MSK __constant_cpu_to_le16(0x1<<14) -#define RXON_RX_CHAIN_MIMO_FORCE_POS (14) - - -#define MCS_DUP_6M_PLCP 0x20 - -/* OFDM HT rate masks */ -/* ***************************************** */ -#define R_MCS_6M_MSK 0x1 -#define R_MCS_12M_MSK 0x2 -#define R_MCS_18M_MSK 0x4 -#define R_MCS_24M_MSK 0x8 -#define R_MCS_36M_MSK 0x10 -#define R_MCS_48M_MSK 0x20 -#define R_MCS_54M_MSK 0x40 -#define R_MCS_60M_MSK 0x80 -#define R_MCS_12M_DUAL_MSK 0x100 -#define R_MCS_24M_DUAL_MSK 0x200 -#define R_MCS_36M_DUAL_MSK 0x400 -#define R_MCS_48M_DUAL_MSK 0x800 - -#define is_legacy(tbl) (((tbl) == LQ_G) || ((tbl) == LQ_A)) -#define is_siso(tbl) (((tbl) == LQ_SISO)) -#define is_mimo(tbl) (((tbl) == LQ_MIMO)) -#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl)) -#define is_a_band(tbl) (((tbl) == LQ_A)) -#define is_g_and(tbl) (((tbl) == LQ_G)) - +/****************************/ /* Flow Handler Definitions */ +/****************************/ -/**********************/ -/* Addresses */ -/**********************/ - +/** + * This I/O area is directly read/writable by driver (e.g. Linux uses writel()) + * Addresses are offsets from device's PCI hardware base address. + */ #define FH_MEM_LOWER_BOUND (0x1000) #define FH_MEM_UPPER_BOUND (0x1EF0) -#define IWL_FH_REGS_LOWER_BOUND (0x1000) -#define IWL_FH_REGS_UPPER_BOUND (0x2000) - +/** + * Keep-Warm (KW) buffer base address. + * + * Driver must allocate a 4KByte buffer that is used by 4965 for keeping the + * host DRAM powered on (via dummy accesses to DRAM) to maintain low-latency + * DRAM access when 4965 is Txing or Rxing. The dummy accesses prevent host + * from going into a power-savings mode that would cause higher DRAM latency, + * and possible data over/under-runs, before all Tx/Rx is complete. + * + * Driver loads IWL_FH_KW_MEM_ADDR_REG with the physical address (bits 35:4) + * of the buffer, which must be 4K aligned. Once this is set up, the 4965 + * automatically invokes keep-warm accesses when normal accesses might not + * be sufficient to maintain fast DRAM response. + * + * Bit fields: + * 31-0: Keep-warm buffer physical base address [35:4], must be 4K aligned + */ #define IWL_FH_KW_MEM_ADDR_REG (FH_MEM_LOWER_BOUND + 0x97C) -/* CBBC Area - Circular buffers base address cache pointers table */ + +/** + * TFD Circular Buffers Base (CBBC) addresses + * + * 4965 has 16 base pointer registers, one for each of 16 host-DRAM-resident + * circular buffers (CBs/queues) containing Transmit Frame Descriptors (TFDs) + * (see struct iwl_tfd_frame). These 16 pointer registers are offset by 0x04 + * bytes from one another. Each TFD circular buffer in DRAM must be 256-byte + * aligned (address bits 0-7 must be 0). + * + * Bit fields in each pointer register: + * 27-0: TFD CB physical base address [35:8], must be 256-byte aligned + */ #define FH_MEM_CBBC_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0) #define FH_MEM_CBBC_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xA10) -/* queues 0 - 15 */ + +/* Find TFD CB base pointer for given queue (range 0-15). */ #define FH_MEM_CBBC_QUEUE(x) (FH_MEM_CBBC_LOWER_BOUND + (x) * 0x4) -/* RSCSR Area */ + +/** + * Rx SRAM Control and Status Registers (RSCSR) + * + * These registers provide handshake between driver and 4965 for the Rx queue + * (this queue handles *all* command responses, notifications, Rx data, etc. + * sent from 4965 uCode to host driver). Unlike Tx, there is only one Rx + * queue, and only one Rx DMA/FIFO channel. Also unlike Tx, which can + * concatenate up to 20 DRAM buffers to form a Tx frame, each Receive Buffer + * Descriptor (RBD) points to only one Rx Buffer (RB); there is a 1:1 + * mapping between RBDs and RBs. + * + * Driver must allocate host DRAM memory for the following, and set the + * physical address of each into 4965 registers: + * + * 1) Receive Buffer Descriptor (RBD) circular buffer (CB), typically with 256 + * entries (although any power of 2, up to 4096, is selectable by driver). + * Each entry (1 dword) points to a receive buffer (RB) of consistent size + * (typically 4K, although 8K or 16K are also selectable by driver). + * Driver sets up RB size and number of RBDs in the CB via Rx config + * register FH_MEM_RCSR_CHNL0_CONFIG_REG. + * + * Bit fields within one RBD: + * 27-0: Receive Buffer physical address bits [35:8], 256-byte aligned + * + * Driver sets physical address [35:8] of base of RBD circular buffer + * into FH_RSCSR_CHNL0_RBDCB_BASE_REG [27:0]. + * + * 2) Rx status buffer, 8 bytes, in which 4965 indicates which Rx Buffers + * (RBs) have been filled, via a "write pointer", actually the index of + * the RB's corresponding RBD within the circular buffer. Driver sets + * physical address [35:4] into FH_RSCSR_CHNL0_STTS_WPTR_REG [31:0]. + * + * Bit fields in lower dword of Rx status buffer (upper dword not used + * by driver; see struct iwl4965_shared, val0): + * 31-12: Not used by driver + * 11- 0: Index of last filled Rx buffer descriptor + * (4965 writes, driver reads this value) + * + * As the driver prepares Receive Buffers (RBs) for 4965 to fill, driver must + * enter pointers to these RBs into contiguous RBD circular buffer entries, + * and update the 4965's "write" index register, FH_RSCSR_CHNL0_RBDCB_WPTR_REG. + * + * This "write" index corresponds to the *next* RBD that the driver will make + * available, i.e. one RBD past the tail of the ready-to-fill RBDs within + * the circular buffer. This value should initially be 0 (before preparing any + * RBs), should be 8 after preparing the first 8 RBs (for example), and must + * wrap back to 0 at the end of the circular buffer (but don't wrap before + * "read" index has advanced past 1! See below). + * NOTE: 4965 EXPECTS THE WRITE INDEX TO BE INCREMENTED IN MULTIPLES OF 8. + * + * As the 4965 fills RBs (referenced from contiguous RBDs within the circular + * buffer), it updates the Rx status buffer in host DRAM, 2) described above, + * to tell the driver the index of the latest filled RBD. The driver must + * read this "read" index from DRAM after receiving an Rx interrupt from 4965. + * + * The driver must also internally keep track of a third index, which is the + * next RBD to process. When receiving an Rx interrupt, driver should process + * all filled but unprocessed RBs up to, but not including, the RB + * corresponding to the "read" index. For example, if "read" index becomes "1", + * driver may process the RB pointed to by RBD 0. Depending on volume of + * traffic, there may be many RBs to process. + * + * If read index == write index, 4965 thinks there is no room to put new data. + * Due to this, the maximum number of filled RBs is 255, instead of 256. To + * be safe, make sure that there is a gap of at least 2 RBDs between "write" + * and "read" indexes; that is, make sure that there are no more than 254 + * buffers waiting to be filled. + */ #define FH_MEM_RSCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xBC0) #define FH_MEM_RSCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xC00) #define FH_MEM_RSCSR_CHNL0 (FH_MEM_RSCSR_LOWER_BOUND) +/** + * Physical base address of 8-byte Rx Status buffer. + * Bit fields: + * 31-0: Rx status buffer physical base address [35:4], must 16-byte aligned. + */ #define FH_RSCSR_CHNL0_STTS_WPTR_REG (FH_MEM_RSCSR_CHNL0) + +/** + * Physical base address of Rx Buffer Descriptor Circular Buffer. + * Bit fields: + * 27-0: RBD CD physical base address [35:8], must be 256-byte aligned. + */ #define FH_RSCSR_CHNL0_RBDCB_BASE_REG (FH_MEM_RSCSR_CHNL0 + 0x004) + +/** + * Rx write pointer (index, really!). + * Bit fields: + * 11-0: Index of driver's most recent prepared-to-be-filled RBD, + 1. + * NOTE: For 256-entry circular buffer, use only bits [7:0]. + */ #define FH_RSCSR_CHNL0_RBDCB_WPTR_REG (FH_MEM_RSCSR_CHNL0 + 0x008) +#define FH_RSCSR_CHNL0_WPTR (FH_RSCSR_CHNL0_RBDCB_WPTR_REG) + -/* RCSR Area - Registers address map */ +/** + * Rx Config/Status Registers (RCSR) + * Rx Config Reg for channel 0 (only channel used) + * + * Driver must initialize FH_MEM_RCSR_CHNL0_CONFIG_REG as follows for + * normal operation (see bit fields). + * + * Clearing FH_MEM_RCSR_CHNL0_CONFIG_REG to 0 turns off Rx DMA. + * Driver should poll FH_MEM_RSSR_RX_STATUS_REG for + * FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (bit 24) before continuing. + * + * Bit fields: + * 31-30: Rx DMA channel enable: '00' off/pause, '01' pause at end of frame, + * '10' operate normally + * 29-24: reserved + * 23-20: # RBDs in circular buffer = 2^value; use "8" for 256 RBDs (normal), + * min "5" for 32 RBDs, max "12" for 4096 RBDs. + * 19-18: reserved + * 17-16: size of each receive buffer; '00' 4K (normal), '01' 8K, + * '10' 12K, '11' 16K. + * 15-14: reserved + * 13-12: IRQ destination; '00' none, '01' host driver (normal operation) + * 11- 4: timeout for closing Rx buffer and interrupting host (units 32 usec) + * typical value 0x10 (about 1/2 msec) + * 3- 0: reserved + */ #define FH_MEM_RCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC00) #define FH_MEM_RCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xCC0) #define FH_MEM_RCSR_CHNL0 (FH_MEM_RCSR_LOWER_BOUND) #define FH_MEM_RCSR_CHNL0_CONFIG_REG (FH_MEM_RCSR_CHNL0) -/* RSSR Area - Rx shared ctrl & status registers */ +#define FH_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MASK (0x00000FF0) /* bit 4-11 */ +#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MASK (0x00001000) /* bit 12 */ +#define FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MASK (0x00008000) /* bit 15 */ +#define FH_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MASK (0x00030000) /* bits 16-17 */ +#define FH_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MASK (0x00F00000) /* bits 20-23 */ +#define FH_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MASK (0xC0000000) /* bits 30-31 */ + +#define FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT (20) +#define FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_BITSHIFT (4) +#define RX_RB_TIMEOUT (0x10) + +#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL (0x00000000) +#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL (0x40000000) +#define FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL (0x80000000) + +#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K (0x00000000) +#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K (0x00010000) +#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K (0x00020000) +#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_16K (0x00030000) + +#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL (0x00000000) +#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL (0x00001000) + + +/** + * Rx Shared Status Registers (RSSR) + * + * After stopping Rx DMA channel (writing 0 to FH_MEM_RCSR_CHNL0_CONFIG_REG), + * driver must poll FH_MEM_RSSR_RX_STATUS_REG until Rx channel is idle. + * + * Bit fields: + * 24: 1 = Channel 0 is idle + * + * FH_MEM_RSSR_SHARED_CTRL_REG and FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV contain + * default values that should not be altered by the driver. + */ #define FH_MEM_RSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC40) #define FH_MEM_RSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xD00) + #define FH_MEM_RSSR_SHARED_CTRL_REG (FH_MEM_RSSR_LOWER_BOUND) #define FH_MEM_RSSR_RX_STATUS_REG (FH_MEM_RSSR_LOWER_BOUND + 0x004) #define FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV (FH_MEM_RSSR_LOWER_BOUND + 0x008) -/* TCSR */ -#define IWL_FH_TCSR_LOWER_BOUND (IWL_FH_REGS_LOWER_BOUND + 0xD00) -#define IWL_FH_TCSR_UPPER_BOUND (IWL_FH_REGS_LOWER_BOUND + 0xE60) +#define FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (0x01000000) + -#define IWL_FH_TCSR_CHNL_NUM (7) +/** + * Transmit DMA Channel Control/Status Registers (TCSR) + * + * 4965 has one configuration register for each of 8 Tx DMA/FIFO channels + * supported in hardware (don't confuse these with the 16 Tx queues in DRAM, + * which feed the DMA/FIFO channels); config regs are separated by 0x20 bytes. + * + * To use a Tx DMA channel, driver must initialize its + * IWL_FH_TCSR_CHNL_TX_CONFIG_REG(chnl) with: + * + * IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | + * IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL + * + * All other bits should be 0. + * + * Bit fields: + * 31-30: Tx DMA channel enable: '00' off/pause, '01' pause at end of frame, + * '10' operate normally + * 29- 4: Reserved, set to "0" + * 3: Enable internal DMA requests (1, normal operation), disable (0) + * 2- 0: Reserved, set to "0" + */ +#define IWL_FH_TCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xD00) +#define IWL_FH_TCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xE60) + +/* Find Control/Status reg for given Tx DMA/FIFO channel */ #define IWL_FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \ (IWL_FH_TCSR_LOWER_BOUND + 0x20 * _chnl) -/* TSSR Area - Tx shared status registers */ -/* TSSR */ -#define IWL_FH_TSSR_LOWER_BOUND (IWL_FH_REGS_LOWER_BOUND + 0xEA0) -#define IWL_FH_TSSR_UPPER_BOUND (IWL_FH_REGS_LOWER_BOUND + 0xEC0) - -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG (IWL_FH_TSSR_LOWER_BOUND + 0x008) -#define IWL_FH_TSSR_TX_STATUS_REG (IWL_FH_TSSR_LOWER_BOUND + 0x010) - -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TXPD_ON (0xFF000000) -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_TXPD_ON (0x00FF0000) +#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL (0x00000000) +#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL (0x00000008) -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_64B (0x00000000) -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_128B (0x00000400) -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_256B (0x00000800) -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_512B (0x00000C00) +#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000) +#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000) +#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000) -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TFD_ON (0x00000100) -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_CBB_ON (0x00000080) +/** + * Tx Shared Status Registers (TSSR) + * + * After stopping Tx DMA channel (writing 0 to + * IWL_FH_TCSR_CHNL_TX_CONFIG_REG(chnl)), driver must poll + * IWL_FH_TSSR_TX_STATUS_REG until selected Tx channel is idle + * (channel's buffers empty | no pending requests). + * + * Bit fields: + * 31-24: 1 = Channel buffers empty (channel 7:0) + * 23-16: 1 = No pending requests (channel 7:0) + */ +#define IWL_FH_TSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xEA0) +#define IWL_FH_TSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xEC0) -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RSP_WAIT_TH (0x00000020) -#define IWL_FH_TSSR_TX_MSG_CONFIG_REG_VAL_RSP_WAIT_TH (0x00000005) +#define IWL_FH_TSSR_TX_STATUS_REG (IWL_FH_TSSR_LOWER_BOUND + 0x010) #define IWL_FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) \ ((1 << (_chnl)) << 24) @@ -341,147 +1558,347 @@ union iwl_tx_power_dual_stream { (IWL_FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) | \ IWL_FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl)) -/* TCSR: tx_config register values */ -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF (0x00000000) -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_DRIVER (0x00000001) -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_ARC (0x00000002) - -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL (0x00000000) -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL (0x00000008) - -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_NOINT (0x00000000) -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD (0x00100000) -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD (0x00200000) - -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT (0x00000000) -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_ENDTFD (0x00400000) -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_IFTFD (0x00800000) -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000) -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000) -#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000) - -#define IWL_FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_EMPTY (0x00000000) -#define IWL_FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_WAIT (0x00002000) -#define IWL_FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID (0x00000003) - -#define IWL_FH_TCSR_CHNL_TX_BUF_STS_REG_BIT_TFDB_WPTR (0x00000001) - -#define IWL_FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM (20) -#define IWL_FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX (12) - -/* RCSR: channel 0 rx_config register defines */ -#define FH_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MASK (0xC0000000) /* bits 30-31 */ -#define FH_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MASK (0x00F00000) /* bits 20-23 */ -#define FH_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MASK (0x00030000) /* bits 16-17 */ -#define FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MASK (0x00008000) /* bit 15 */ -#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MASK (0x00001000) /* bit 12 */ -#define FH_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MASK (0x00000FF0) /* bit 4-11 */ - -#define FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT (20) -#define FH_RCSR_RX_CONFIG_RB_SIZE_BITSHIFT (16) - -/* RCSR: rx_config register values */ -#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL (0x00000000) -#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL (0x40000000) -#define FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL (0x80000000) - -#define IWL_FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K (0x00000000) - -/* RCSR channel 0 config register values */ -#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL (0x00000000) -#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL (0x00001000) - -/* RSCSR: defs used in normal mode */ -#define FH_RSCSR_CHNL0_RBDCB_WPTR_MASK (0x00000FFF) /* bits 0-11 */ +/********************* START TX SCHEDULER *************************************/ +/** + * 4965 Tx Scheduler + * + * The Tx Scheduler selects the next frame to be transmitted, chosing TFDs + * (Transmit Frame Descriptors) from up to 16 circular Tx queues resident in + * host DRAM. It steers each frame's Tx command (which contains the frame + * data) into one of up to 7 prioritized Tx DMA FIFO channels within the + * device. A queue maps to only one (selectable by driver) Tx DMA channel, + * but one DMA channel may take input from several queues. + * + * Tx DMA channels have dedicated purposes. For 4965, they are used as follows: + * + * 0 -- EDCA BK (background) frames, lowest priority + * 1 -- EDCA BE (best effort) frames, normal priority + * 2 -- EDCA VI (video) frames, higher priority + * 3 -- EDCA VO (voice) and management frames, highest priority + * 4 -- Commands (e.g. RXON, etc.) + * 5 -- HCCA short frames + * 6 -- HCCA long frames + * 7 -- not used by driver (device-internal only) + * + * Driver should normally map queues 0-6 to Tx DMA/FIFO channels 0-6. + * In addition, driver can map queues 7-15 to Tx DMA/FIFO channels 0-3 to + * support 11n aggregation via EDCA DMA channels. + * + * The driver sets up each queue to work in one of two modes: + * + * 1) Scheduler-Ack, in which the scheduler automatically supports a + * block-ack (BA) window of up to 64 TFDs. In this mode, each queue + * contains TFDs for a unique combination of Recipient Address (RA) + * and Traffic Identifier (TID), that is, traffic of a given + * Quality-Of-Service (QOS) priority, destined for a single station. + * + * In scheduler-ack mode, the scheduler keeps track of the Tx status of + * each frame within the BA window, including whether it's been transmitted, + * and whether it's been acknowledged by the receiving station. The device + * automatically processes block-acks received from the receiving STA, + * and reschedules un-acked frames to be retransmitted (successful + * Tx completion may end up being out-of-order). + * + * The driver must maintain the queue's Byte Count table in host DRAM + * (struct iwl4965_sched_queue_byte_cnt_tbl) for this mode. + * This mode does not support fragmentation. + * + * 2) FIFO (a.k.a. non-Scheduler-ACK), in which each TFD is processed in order. + * The device may automatically retry Tx, but will retry only one frame + * at a time, until receiving ACK from receiving station, or reaching + * retry limit and giving up. + * + * The command queue (#4) must use this mode! + * This mode does not require use of the Byte Count table in host DRAM. + * + * Driver controls scheduler operation via 3 means: + * 1) Scheduler registers + * 2) Shared scheduler data base in internal 4956 SRAM + * 3) Shared data in host DRAM + * + * Initialization: + * + * When loading, driver should allocate memory for: + * 1) 16 TFD circular buffers, each with space for (typically) 256 TFDs. + * 2) 16 Byte Count circular buffers in 16 KBytes contiguous memory + * (1024 bytes for each queue). + * + * After receiving "Alive" response from uCode, driver must initialize + * the scheduler (especially for queue #4, the command queue, otherwise + * the driver can't issue commands!): + */ + +/** + * Max Tx window size is the max number of contiguous TFDs that the scheduler + * can keep track of at one time when creating block-ack chains of frames. + * Note that "64" matches the number of ack bits in a block-ack packet. + * Driver should use SCD_WIN_SIZE and SCD_FRAME_LIMIT values to initialize + * SCD_CONTEXT_QUEUE_OFFSET(x) values. + */ #define SCD_WIN_SIZE 64 #define SCD_FRAME_LIMIT 64 -/* memory mapped registers */ +/* SCD registers are internal, must be accessed via HBUS_TARG_PRPH regs */ #define SCD_START_OFFSET 0xa02c00 +/* + * 4965 tells driver SRAM address for internal scheduler structs via this reg. + * Value is valid only after "Alive" response from uCode. + */ #define SCD_SRAM_BASE_ADDR (SCD_START_OFFSET + 0x0) + +/* + * Driver may need to update queue-empty bits after changing queue's + * write and read pointers (indexes) during (re-)initialization (i.e. when + * scheduler is not tracking what's happening). + * Bit fields: + * 31-16: Write mask -- 1: update empty bit, 0: don't change empty bit + * 15-00: Empty state, one for each queue -- 1: empty, 0: non-empty + * NOTE: This register is not used by Linux driver. + */ #define SCD_EMPTY_BITS (SCD_START_OFFSET + 0x4) + +/* + * Physical base address of array of byte count (BC) circular buffers (CBs). + * Each Tx queue has a BC CB in host DRAM to support Scheduler-ACK mode. + * This register points to BC CB for queue 0, must be on 1024-byte boundary. + * Others are spaced by 1024 bytes. + * Each BC CB is 2 bytes * (256 + 64) = 740 bytes, followed by 384 bytes pad. + * (Index into a queue's BC CB) = (index into queue's TFD CB) = (SSN & 0xff). + * Bit fields: + * 25-00: Byte Count CB physical address [35:10], must be 1024-byte aligned. + */ #define SCD_DRAM_BASE_ADDR (SCD_START_OFFSET + 0x10) -#define SCD_AIT (SCD_START_OFFSET + 0x18) + +/* + * Enables any/all Tx DMA/FIFO channels. + * Scheduler generates requests for only the active channels. + * Set this to 0xff to enable all 8 channels (normal usage). + * Bit fields: + * 7- 0: Enable (1), disable (0), one bit for each channel 0-7 + */ #define SCD_TXFACT (SCD_START_OFFSET + 0x1c) + +/* Mask to enable contiguous Tx DMA/FIFO channels between "lo" and "hi". */ +#define SCD_TXFACT_REG_TXFIFO_MASK(lo, hi) \ + ((1 << (hi)) | ((1 << (hi)) - (1 << (lo)))) + +/* + * Queue (x) Write Pointers (indexes, really!), one for each Tx queue. + * Initialized and updated by driver as new TFDs are added to queue. + * NOTE: If using Block Ack, index must correspond to frame's + * Start Sequence Number; index = (SSN & 0xff) + * NOTE: Alternative to HBUS_TARG_WRPTR, which is what Linux driver uses? + */ #define SCD_QUEUE_WRPTR(x) (SCD_START_OFFSET + 0x24 + (x) * 4) -#define SCD_QUEUE_RDPTR(x) (SCD_START_OFFSET + 0x64 + (x) * 4) -#define SCD_SETQUEUENUM (SCD_START_OFFSET + 0xa4) -#define SCD_SET_TXSTAT_TXED (SCD_START_OFFSET + 0xa8) -#define SCD_SET_TXSTAT_DONE (SCD_START_OFFSET + 0xac) -#define SCD_SET_TXSTAT_NOT_SCHD (SCD_START_OFFSET + 0xb0) -#define SCD_DECREASE_CREDIT (SCD_START_OFFSET + 0xb4) -#define SCD_DECREASE_SCREDIT (SCD_START_OFFSET + 0xb8) -#define SCD_LOAD_CREDIT (SCD_START_OFFSET + 0xbc) -#define SCD_LOAD_SCREDIT (SCD_START_OFFSET + 0xc0) -#define SCD_BAR (SCD_START_OFFSET + 0xc4) -#define SCD_BAR_DW0 (SCD_START_OFFSET + 0xc8) -#define SCD_BAR_DW1 (SCD_START_OFFSET + 0xcc) -#define SCD_QUEUECHAIN_SEL (SCD_START_OFFSET + 0xd0) -#define SCD_QUERY_REQ (SCD_START_OFFSET + 0xd8) -#define SCD_QUERY_RES (SCD_START_OFFSET + 0xdc) -#define SCD_PENDING_FRAMES (SCD_START_OFFSET + 0xe0) -#define SCD_INTERRUPT_MASK (SCD_START_OFFSET + 0xe4) -#define SCD_INTERRUPT_THRESHOLD (SCD_START_OFFSET + 0xe8) -#define SCD_QUERY_MIN_FRAME_SIZE (SCD_START_OFFSET + 0x100) -#define SCD_QUEUE_STATUS_BITS(x) (SCD_START_OFFSET + 0x104 + (x) * 4) -/* SRAM structures */ -#define SCD_CONTEXT_DATA_OFFSET 0x380 -#define SCD_TX_STTS_BITMAP_OFFSET 0x400 -#define SCD_TRANSLATE_TBL_OFFSET 0x500 -#define SCD_CONTEXT_QUEUE_OFFSET(x) (SCD_CONTEXT_DATA_OFFSET + ((x) * 8)) -#define SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \ - ((SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffffffc) +/* + * Queue (x) Read Pointers (indexes, really!), one for each Tx queue. + * For FIFO mode, index indicates next frame to transmit. + * For Scheduler-ACK mode, index indicates first frame in Tx window. + * Initialized by driver, updated by scheduler. + */ +#define SCD_QUEUE_RDPTR(x) (SCD_START_OFFSET + 0x64 + (x) * 4) -#define SCD_TXFACT_REG_TXFIFO_MASK(lo, hi) \ - ((1<<(hi))|((1<<(hi))-(1<<(lo)))) +/* + * Select which queues work in chain mode (1) vs. not (0). + * Use chain mode to build chains of aggregated frames. + * Bit fields: + * 31-16: Reserved + * 15-00: Mode, one bit for each queue -- 1: Chain mode, 0: one-at-a-time + * NOTE: If driver sets up queue for chain mode, it should be also set up + * Scheduler-ACK mode as well, via SCD_QUEUE_STATUS_BITS(x). + */ +#define SCD_QUEUECHAIN_SEL (SCD_START_OFFSET + 0xd0) +/* + * Select which queues interrupt driver when scheduler increments + * a queue's read pointer (index). + * Bit fields: + * 31-16: Reserved + * 15-00: Interrupt enable, one bit for each queue -- 1: enabled, 0: disabled + * NOTE: This functionality is apparently a no-op; driver relies on interrupts + * from Rx queue to read Tx command responses and update Tx queues. + */ +#define SCD_INTERRUPT_MASK (SCD_START_OFFSET + 0xe4) -#define SCD_MODE_REG_BIT_SEARCH_MODE (1<<0) -#define SCD_MODE_REG_BIT_SBYP_MODE (1<<1) +/* + * Queue search status registers. One for each queue. + * Sets up queue mode and assigns queue to Tx DMA channel. + * Bit fields: + * 19-10: Write mask/enable bits for bits 0-9 + * 9: Driver should init to "0" + * 8: Scheduler-ACK mode (1), non-Scheduler-ACK (i.e. FIFO) mode (0). + * Driver should init to "1" for aggregation mode, or "0" otherwise. + * 7-6: Driver should init to "0" + * 5: Window Size Left; indicates whether scheduler can request + * another TFD, based on window size, etc. Driver should init + * this bit to "1" for aggregation mode, or "0" for non-agg. + * 4-1: Tx FIFO to use (range 0-7). + * 0: Queue is active (1), not active (0). + * Other bits should be written as "0" + * + * NOTE: If enabling Scheduler-ACK mode, chain mode should also be enabled + * via SCD_QUEUECHAIN_SEL. + */ +#define SCD_QUEUE_STATUS_BITS(x) (SCD_START_OFFSET + 0x104 + (x) * 4) -#define SCD_TXFIFO_POS_TID (0) -#define SCD_TXFIFO_POS_RA (4) +/* Bit field positions */ #define SCD_QUEUE_STTS_REG_POS_ACTIVE (0) #define SCD_QUEUE_STTS_REG_POS_TXF (1) #define SCD_QUEUE_STTS_REG_POS_WSL (5) #define SCD_QUEUE_STTS_REG_POS_SCD_ACK (8) + +/* Write masks */ #define SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN (10) #define SCD_QUEUE_STTS_REG_MSK (0x0007FC00) -#define SCD_QUEUE_RA_TID_MAP_RATID_MSK (0x01FF) +/** + * 4965 internal SRAM structures for scheduler, shared with driver ... + * + * Driver should clear and initialize the following areas after receiving + * "Alive" response from 4965 uCode, i.e. after initial + * uCode load, or after a uCode load done for error recovery: + * + * SCD_CONTEXT_DATA_OFFSET (size 128 bytes) + * SCD_TX_STTS_BITMAP_OFFSET (size 256 bytes) + * SCD_TRANSLATE_TBL_OFFSET (size 32 bytes) + * + * Driver accesses SRAM via HBUS_TARG_MEM_* registers. + * Driver reads base address of this scheduler area from SCD_SRAM_BASE_ADDR. + * All OFFSET values must be added to this base address. + */ + +/* + * Queue context. One 8-byte entry for each of 16 queues. + * + * Driver should clear this entire area (size 0x80) to 0 after receiving + * "Alive" notification from uCode. Additionally, driver should init + * each queue's entry as follows: + * + * LS Dword bit fields: + * 0-06: Max Tx window size for Scheduler-ACK. Driver should init to 64. + * + * MS Dword bit fields: + * 16-22: Frame limit. Driver should init to 10 (0xa). + * + * Driver should init all other bits to 0. + * + * Init must be done after driver receives "Alive" response from 4965 uCode, + * and when setting up queue for aggregation. + */ +#define SCD_CONTEXT_DATA_OFFSET 0x380 +#define SCD_CONTEXT_QUEUE_OFFSET(x) (SCD_CONTEXT_DATA_OFFSET + ((x) * 8)) #define SCD_QUEUE_CTX_REG1_WIN_SIZE_POS (0) #define SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK (0x0000007F) -#define SCD_QUEUE_CTX_REG1_CREDIT_POS (8) -#define SCD_QUEUE_CTX_REG1_CREDIT_MSK (0x00FFFF00) -#define SCD_QUEUE_CTX_REG1_SUPER_CREDIT_POS (24) -#define SCD_QUEUE_CTX_REG1_SUPER_CREDIT_MSK (0xFF000000) #define SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS (16) #define SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK (0x007F0000) -#define CSR_HW_IF_CONFIG_REG_BIT_KEDRON_R (0x00000010) -#define CSR_HW_IF_CONFIG_REG_MSK_BOARD_VER (0x00000C00) -#define CSR_HW_IF_CONFIG_REG_BIT_MAC_SI (0x00000100) -#define CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI (0x00000200) +/* + * Tx Status Bitmap + * + * Driver should clear this entire area (size 0x100) to 0 after receiving + * "Alive" notification from uCode. Area is used only by device itself; + * no other support (besides clearing) is required from driver. + */ +#define SCD_TX_STTS_BITMAP_OFFSET 0x400 -static inline u8 iwl_hw_get_rate(__le32 rate_n_flags) +/* + * RAxTID to queue translation mapping. + * + * When queue is in Scheduler-ACK mode, frames placed in a that queue must be + * for only one combination of receiver address (RA) and traffic ID (TID), i.e. + * one QOS priority level destined for one station (for this wireless link, + * not final destination). The SCD_TRANSLATE_TABLE area provides 16 16-bit + * mappings, one for each of the 16 queues. If queue is not in Scheduler-ACK + * mode, the device ignores the mapping value. + * + * Bit fields, for each 16-bit map: + * 15-9: Reserved, set to 0 + * 8-4: Index into device's station table for recipient station + * 3-0: Traffic ID (tid), range 0-15 + * + * Driver should clear this entire area (size 32 bytes) to 0 after receiving + * "Alive" notification from uCode. To update a 16-bit map value, driver + * must read a dword-aligned value from device SRAM, replace the 16-bit map + * value of interest, and write the dword value back into device SRAM. + */ +#define SCD_TRANSLATE_TBL_OFFSET 0x500 + +/* Find translation table dword to read/write for given queue */ +#define SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \ + ((SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffffffc) + +#define SCD_TXFIFO_POS_TID (0) +#define SCD_TXFIFO_POS_RA (4) +#define SCD_QUEUE_RA_TID_MAP_RATID_MSK (0x01FF) + +/*********************** END TX SCHEDULER *************************************/ + +static inline u8 iwl4965_hw_get_rate(__le32 rate_n_flags) { return le32_to_cpu(rate_n_flags) & 0xFF; } -static inline u16 iwl_hw_get_rate_n_flags(__le32 rate_n_flags) +static inline u16 iwl4965_hw_get_rate_n_flags(__le32 rate_n_flags) { return le32_to_cpu(rate_n_flags) & 0xFFFF; } -static inline __le32 iwl_hw_set_rate_n_flags(u8 rate, u16 flags) +static inline __le32 iwl4965_hw_set_rate_n_flags(u8 rate, u16 flags) { return cpu_to_le32(flags|(u16)rate); } -struct iwl_tfd_frame_data { + +/** + * Tx/Rx Queues + * + * Most communication between driver and 4965 is via queues of data buffers. + * For example, all commands that the driver issues to device's embedded + * controller (uCode) are via the command queue (one of the Tx queues). All + * uCode command responses/replies/notifications, including Rx frames, are + * conveyed from uCode to driver via the Rx queue. + * + * Most support for these queues, including handshake support, resides in + * structures in host DRAM, shared between the driver and the device. When + * allocating this memory, the driver must make sure that data written by + * the host CPU updates DRAM immediately (and does not get "stuck" in CPU's + * cache memory), so DRAM and cache are consistent, and the device can + * immediately see changes made by the driver. + * + * 4965 supports up to 16 DRAM-based Tx queues, and services these queues via + * up to 7 DMA channels (FIFOs). Each Tx queue is supported by a circular array + * in DRAM containing 256 Transmit Frame Descriptors (TFDs). + */ +#define IWL4965_MAX_WIN_SIZE 64 +#define IWL4965_QUEUE_SIZE 256 +#define IWL4965_NUM_FIFOS 7 +#define IWL_MAX_NUM_QUEUES 16 + + +/** + * struct iwl4965_tfd_frame_data + * + * Describes up to 2 buffers containing (contiguous) portions of a Tx frame. + * Each buffer must be on dword boundary. + * Up to 10 iwl_tfd_frame_data structures, describing up to 20 buffers, + * may be filled within a TFD (iwl_tfd_frame). + * + * Bit fields in tb1_addr: + * 31- 0: Tx buffer 1 address bits [31:0] + * + * Bit fields in val1: + * 31-16: Tx buffer 2 address bits [15:0] + * 15- 4: Tx buffer 1 length (bytes) + * 3- 0: Tx buffer 1 address bits [32:32] + * + * Bit fields in val2: + * 31-20: Tx buffer 2 length (bytes) + * 19- 0: Tx buffer 2 address bits [35:16] + */ +struct iwl4965_tfd_frame_data { __le32 tb1_addr; __le32 val1; @@ -509,7 +1926,36 @@ struct iwl_tfd_frame_data { #define IWL_tb2_len_SYM val2 } __attribute__ ((packed)); -struct iwl_tfd_frame { + +/** + * struct iwl4965_tfd_frame + * + * Transmit Frame Descriptor (TFD) + * + * 4965 supports up to 16 Tx queues resident in host DRAM. + * Each Tx queue uses a circular buffer of 256 TFDs stored in host DRAM. + * Both driver and device share these circular buffers, each of which must be + * contiguous 256 TFDs x 128 bytes-per-TFD = 32 KBytes for 4965. + * + * Driver must indicate the physical address of the base of each + * circular buffer via the 4965's FH_MEM_CBBC_QUEUE registers. + * + * Each TFD contains pointer/size information for up to 20 data buffers + * in host DRAM. These buffers collectively contain the (one) frame described + * by the TFD. Each buffer must be a single contiguous block of memory within + * itself, but buffers may be scattered in host DRAM. Each buffer has max size + * of (4K - 4). The 4965 concatenates all of a TFD's buffers into a single + * Tx frame, up to 8 KBytes in size. + * + * Bit fields in the control dword (val0): + * 31-30: # dwords (0-3) of padding required at end of frame for 16-byte bound + * 29: reserved + * 28-24: # Transmit Buffer Descriptors in TFD + * 23- 0: reserved + * + * A maximum of 255 (not 256!) TFDs may be on a queue waiting for Tx. + */ +struct iwl4965_tfd_frame { __le32 val0; /* __le32 rsvd1:24; */ /* __le32 num_tbs:5; */ @@ -518,15 +1964,20 @@ struct iwl_tfd_frame { #define IWL_num_tbs_SYM val0 /* __le32 rsvd2:1; */ /* __le32 padding:2; */ - struct iwl_tfd_frame_data pa[10]; + struct iwl4965_tfd_frame_data pa[10]; __le32 reserved; } __attribute__ ((packed)); -#define IWL4965_MAX_WIN_SIZE 64 -#define IWL4965_QUEUE_SIZE 256 -#define IWL4965_NUM_FIFOS 7 -#define IWL_MAX_NUM_QUEUES 16 +/** + * struct iwl4965_queue_byte_cnt_entry + * + * Byte Count Table Entry + * + * Bit fields: + * 15-12: reserved + * 11- 0: total to-be-transmitted byte count of frame (does not include command) + */ struct iwl4965_queue_byte_cnt_entry { __le16 val; /* __le16 byte_cnt:12; */ @@ -536,6 +1987,25 @@ struct iwl4965_queue_byte_cnt_entry { /* __le16 rsvd:4; */ } __attribute__ ((packed)); + +/** + * struct iwl4965_sched_queue_byte_cnt_tbl + * + * Byte Count table + * + * Each Tx queue uses a byte-count table containing 320 entries: + * one 16-bit entry for each of 256 TFDs, plus an additional 64 entries that + * duplicate the first 64 entries (to avoid wrap-around within a Tx window; + * max Tx window is 64 TFDs). + * + * When driver sets up a new TFD, it must also enter the total byte count + * of the frame to be transmitted into the corresponding entry in the byte + * count table for the chosen Tx queue. If the TFD index is 0-63, the driver + * must duplicate the byte count entry in corresponding index 256-319. + * + * "dont_care" padding puts each byte count table on a 1024-byte boundary; + * 4965 assumes tables are separated by 1024 bytes. + */ struct iwl4965_sched_queue_byte_cnt_tbl { struct iwl4965_queue_byte_cnt_entry tfd_offset[IWL4965_QUEUE_SIZE + IWL4965_MAX_WIN_SIZE]; @@ -544,9 +2014,31 @@ struct iwl4965_sched_queue_byte_cnt_tbl { sizeof(__le16)]; } __attribute__ ((packed)); -/* Base physical address of iwl_shared is provided to SCD_DRAM_BASE_ADDR - * and &iwl_shared.val0 is provided to FH_RSCSR_CHNL0_STTS_WPTR_REG */ -struct iwl_shared { + +/** + * struct iwl4965_shared - handshake area for Tx and Rx + * + * For convenience in allocating memory, this structure combines 2 areas of + * DRAM which must be shared between driver and 4965. These do not need to + * be combined, if better allocation would result from keeping them separate: + * + * 1) The Tx byte count tables occupy 1024 bytes each (16 KBytes total for + * 16 queues). Driver uses SCD_DRAM_BASE_ADDR to tell 4965 where to find + * the first of these tables. 4965 assumes tables are 1024 bytes apart. + * + * 2) The Rx status (val0 and val1) occupies only 8 bytes. Driver uses + * FH_RSCSR_CHNL0_STTS_WPTR_REG to tell 4965 where to find this area. + * Driver reads val0 to determine the latest Receive Buffer Descriptor (RBD) + * that has been filled by the 4965. + * + * Bit fields val0: + * 31-12: Not used + * 11- 0: Index of last filled Rx buffer descriptor (4965 writes, driver reads) + * + * Bit fields val1: + * 31- 0: Not used + */ +struct iwl4965_shared { struct iwl4965_sched_queue_byte_cnt_tbl queues_byte_cnt_tbls[IWL_MAX_NUM_QUEUES]; __le32 val0; @@ -578,4 +2070,4 @@ struct iwl_shared { __le32 padding2; } __attribute__ ((packed)); -#endif /* __iwl_4965_hw_h__ */ +#endif /* __iwl4965_4965_hw_h__ */ diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-io.h b/drivers/net/wireless/iwlwifi/iwl-4965-io.h new file mode 100644 index 00000000000..34a0b57eea0 --- /dev/null +++ b/drivers/net/wireless/iwlwifi/iwl-4965-io.h @@ -0,0 +1,431 @@ +/****************************************************************************** + * + * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. + * + * Portions of this file are derived from the ipw3945 project. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * The full GNU General Public License is included in this distribution in the + * file called LICENSE. + * + * Contact Information: + * James P. Ketrenos <ipw2100-admin@linux.intel.com> + * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 + * + *****************************************************************************/ + +#ifndef __iwl4965_io_h__ +#define __iwl4965_io_h__ + +#include <linux/io.h> + +#include "iwl-4965-debug.h" + +/* + * IO, register, and NIC memory access functions + * + * NOTE on naming convention and macro usage for these + * + * A single _ prefix before a an access function means that no state + * check or debug information is printed when that function is called. + * + * A double __ prefix before an access function means that state is checked + * and the current line number is printed in addition to any other debug output. + * + * The non-prefixed name is the #define that maps the caller into a + * #define that provides the caller's __LINE__ to the double prefix version. + * + * If you wish to call the function without any debug or state checking, + * you should use the single _ prefix version (as is used by dependent IO + * routines, for example _iwl4965_read_direct32 calls the non-check version of + * _iwl4965_read32.) + * + * These declarations are *extremely* useful in quickly isolating code deltas + * which result in misconfiguring of the hardware I/O. In combination with + * git-bisect and the IO debug level you can quickly determine the specific + * commit which breaks the IO sequence to the hardware. + * + */ + +#define _iwl4965_write32(iwl, ofs, val) writel((val), (iwl)->hw_base + (ofs)) +#ifdef CONFIG_IWL4965_DEBUG +static inline void __iwl4965_write32(const char *f, u32 l, struct iwl4965_priv *iwl, + u32 ofs, u32 val) +{ + IWL_DEBUG_IO("write32(0x%08X, 0x%08X) - %s %d\n", ofs, val, f, l); + _iwl4965_write32(iwl, ofs, val); +} +#define iwl4965_write32(iwl, ofs, val) \ + __iwl4965_write32(__FILE__, __LINE__, iwl, ofs, val) +#else +#define iwl4965_write32(iwl, ofs, val) _iwl4965_write32(iwl, ofs, val) +#endif + +#define _iwl4965_read32(iwl, ofs) readl((iwl)->hw_base + (ofs)) +#ifdef CONFIG_IWL4965_DEBUG +static inline u32 __iwl4965_read32(char *f, u32 l, struct iwl4965_priv *iwl, u32 ofs) +{ + IWL_DEBUG_IO("read_direct32(0x%08X) - %s %d\n", ofs, f, l); + return _iwl4965_read32(iwl, ofs); +} +#define iwl4965_read32(iwl, ofs) __iwl4965_read32(__FILE__, __LINE__, iwl, ofs) +#else +#define iwl4965_read32(p, o) _iwl4965_read32(p, o) +#endif + +static inline int _iwl4965_poll_bit(struct iwl4965_priv *priv, u32 addr, + u32 bits, u32 mask, int timeout) +{ + int i = 0; + + do { + if ((_iwl4965_read32(priv, addr) & mask) == (bits & mask)) + return i; + mdelay(10); + i += 10; + } while (i < timeout); + + return -ETIMEDOUT; +} +#ifdef CONFIG_IWL4965_DEBUG +static inline int __iwl4965_poll_bit(const char *f, u32 l, + struct iwl4965_priv *priv, u32 addr, + u32 bits, u32 mask, int timeout) +{ + int ret = _iwl4965_poll_bit(priv, addr, bits, mask, timeout); + if (unlikely(ret == -ETIMEDOUT)) + IWL_DEBUG_IO + ("poll_bit(0x%08X, 0x%08X, 0x%08X) - timedout - %s %d\n", + addr, bits, mask, f, l); + else + IWL_DEBUG_IO + ("poll_bit(0x%08X, 0x%08X, 0x%08X) = 0x%08X - %s %d\n", + addr, bits, mask, ret, f, l); + return ret; +} +#define iwl4965_poll_bit(iwl, addr, bits, mask, timeout) \ + __iwl4965_poll_bit(__FILE__, __LINE__, iwl, addr, bits, mask, timeout) +#else +#define iwl4965_poll_bit(p, a, b, m, t) _iwl4965_poll_bit(p, a, b, m, t) +#endif + +static inline void _iwl4965_set_bit(struct iwl4965_priv *priv, u32 reg, u32 mask) +{ + _iwl4965_write32(priv, reg, _iwl4965_read32(priv, reg) | mask); +} +#ifdef CONFIG_IWL4965_DEBUG +static inline void __iwl4965_set_bit(const char *f, u32 l, + struct iwl4965_priv *priv, u32 reg, u32 mask) +{ + u32 val = _iwl4965_read32(priv, reg) | mask; + IWL_DEBUG_IO("set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); + _iwl4965_write32(priv, reg, val); +} +#define iwl4965_set_bit(p, r, m) __iwl4965_set_bit(__FILE__, __LINE__, p, r, m) +#else +#define iwl4965_set_bit(p, r, m) _iwl4965_set_bit(p, r, m) +#endif + +static inline void _iwl4965_clear_bit(struct iwl4965_priv *priv, u32 reg, u32 mask) +{ + _iwl4965_write32(priv, reg, _iwl4965_read32(priv, reg) & ~mask); +} +#ifdef CONFIG_IWL4965_DEBUG +static inline void __iwl4965_clear_bit(const char *f, u32 l, + struct iwl4965_priv *priv, u32 reg, u32 mask) +{ + u32 val = _iwl4965_read32(priv, reg) & ~mask; + IWL_DEBUG_IO("clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); + _iwl4965_write32(priv, reg, val); +} +#define iwl4965_clear_bit(p, r, m) __iwl4965_clear_bit(__FILE__, __LINE__, p, r, m) +#else +#define iwl4965_clear_bit(p, r, m) _iwl4965_clear_bit(p, r, m) +#endif + +static inline int _iwl4965_grab_nic_access(struct iwl4965_priv *priv) +{ + int ret; + u32 gp_ctl; + +#ifdef CONFIG_IWL4965_DEBUG + if (atomic_read(&priv->restrict_refcnt)) + return 0; +#endif + if (test_bit(STATUS_RF_KILL_HW, &priv->status) || + test_bit(STATUS_RF_KILL_SW, &priv->status)) { + IWL_WARNING("WARNING: Requesting MAC access during RFKILL " + "wakes up NIC\n"); + + /* 10 msec allows time for NIC to complete its data save */ + gp_ctl = _iwl4965_read32(priv, CSR_GP_CNTRL); + if (gp_ctl & CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY) { + IWL_DEBUG_RF_KILL("Wait for complete power-down, " + "gpctl = 0x%08x\n", gp_ctl); + mdelay(10); + } else + IWL_DEBUG_RF_KILL("power-down complete, " + "gpctl = 0x%08x\n", gp_ctl); + } + + /* this bit wakes up the NIC */ + _iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + ret = _iwl4965_poll_bit(priv, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN, + (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY | + CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 50); + if (ret < 0) { + IWL_ERROR("MAC is in deep sleep!\n"); + return -EIO; + } + +#ifdef CONFIG_IWL4965_DEBUG + atomic_inc(&priv->restrict_refcnt); +#endif + return 0; +} + +#ifdef CONFIG_IWL4965_DEBUG +static inline int __iwl4965_grab_nic_access(const char *f, u32 l, + struct iwl4965_priv *priv) +{ + if (atomic_read(&priv->restrict_refcnt)) + IWL_DEBUG_INFO("Grabbing access while already held at " + "line %d.\n", l); + + IWL_DEBUG_IO("grabbing nic access - %s %d\n", f, l); + return _iwl4965_grab_nic_access(priv); +} +#define iwl4965_grab_nic_access(priv) \ + __iwl4965_grab_nic_access(__FILE__, __LINE__, priv) +#else +#define iwl4965_grab_nic_access(priv) \ + _iwl4965_grab_nic_access(priv) +#endif + +static inline void _iwl4965_release_nic_access(struct iwl4965_priv *priv) +{ +#ifdef CONFIG_IWL4965_DEBUG + if (atomic_dec_and_test(&priv->restrict_refcnt)) +#endif + _iwl4965_clear_bit(priv, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); +} +#ifdef CONFIG_IWL4965_DEBUG +static inline void __iwl4965_release_nic_access(const char *f, u32 l, + struct iwl4965_priv *priv) +{ + if (atomic_read(&priv->restrict_refcnt) <= 0) + IWL_ERROR("Release unheld nic access at line %d.\n", l); + + IWL_DEBUG_IO("releasing nic access - %s %d\n", f, l); + _iwl4965_release_nic_access(priv); +} +#define iwl4965_release_nic_access(priv) \ + __iwl4965_release_nic_access(__FILE__, __LINE__, priv) +#else +#define iwl4965_release_nic_access(priv) \ + _iwl4965_release_nic_access(priv) +#endif + +static inline u32 _iwl4965_read_direct32(struct iwl4965_priv *priv, u32 reg) +{ + return _iwl4965_read32(priv, reg); +} +#ifdef CONFIG_IWL4965_DEBUG +static inline u32 __iwl4965_read_direct32(const char *f, u32 l, + struct iwl4965_priv *priv, u32 reg) +{ + u32 value = _iwl4965_read_direct32(priv, reg); + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access not held from %s %d\n", f, l); + IWL_DEBUG_IO("read_direct32(0x%4X) = 0x%08x - %s %d \n", reg, value, + f, l); + return value; +} +#define iwl4965_read_direct32(priv, reg) \ + __iwl4965_read_direct32(__FILE__, __LINE__, priv, reg) +#else +#define iwl4965_read_direct32 _iwl4965_read_direct32 +#endif + +static inline void _iwl4965_write_direct32(struct iwl4965_priv *priv, + u32 reg, u32 value) +{ + _iwl4965_write32(priv, reg, value); +} +#ifdef CONFIG_IWL4965_DEBUG +static void __iwl4965_write_direct32(u32 line, + struct iwl4965_priv *priv, u32 reg, u32 value) +{ + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access not held from line %d\n", line); + _iwl4965_write_direct32(priv, reg, value); +} +#define iwl4965_write_direct32(priv, reg, value) \ + __iwl4965_write_direct32(__LINE__, priv, reg, value) +#else +#define iwl4965_write_direct32 _iwl4965_write_direct32 +#endif + +static inline void iwl4965_write_reg_buf(struct iwl4965_priv *priv, + u32 reg, u32 len, u32 *values) +{ + u32 count = sizeof(u32); + + if ((priv != NULL) && (values != NULL)) { + for (; 0 < len; len -= count, reg += count, values++) + _iwl4965_write_direct32(priv, reg, *values); + } +} + +static inline int _iwl4965_poll_direct_bit(struct iwl4965_priv *priv, + u32 addr, u32 mask, int timeout) +{ + int i = 0; + + do { + if ((_iwl4965_read_direct32(priv, addr) & mask) == mask) + return i; + mdelay(10); + i += 10; + } while (i < timeout); + + return -ETIMEDOUT; +} + +#ifdef CONFIG_IWL4965_DEBUG +static inline int __iwl4965_poll_direct_bit(const char *f, u32 l, + struct iwl4965_priv *priv, + u32 addr, u32 mask, int timeout) +{ + int ret = _iwl4965_poll_direct_bit(priv, addr, mask, timeout); + + if (unlikely(ret == -ETIMEDOUT)) + IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) - " + "timedout - %s %d\n", addr, mask, f, l); + else + IWL_DEBUG_IO("poll_direct_bit(0x%08X, 0x%08X) = 0x%08X " + "- %s %d\n", addr, mask, ret, f, l); + return ret; +} +#define iwl4965_poll_direct_bit(iwl, addr, mask, timeout) \ + __iwl4965_poll_direct_bit(__FILE__, __LINE__, iwl, addr, mask, timeout) +#else +#define iwl4965_poll_direct_bit _iwl4965_poll_direct_bit +#endif + +static inline u32 _iwl4965_read_prph(struct iwl4965_priv *priv, u32 reg) +{ + _iwl4965_write_direct32(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24)); + return _iwl4965_read_direct32(priv, HBUS_TARG_PRPH_RDAT); +} +#ifdef CONFIG_IWL4965_DEBUG +static inline u32 __iwl4965_read_prph(u32 line, struct iwl4965_priv *priv, u32 reg) +{ + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access not held from line %d\n", line); + return _iwl4965_read_prph(priv, reg); +} + +#define iwl4965_read_prph(priv, reg) \ + __iwl4965_read_prph(__LINE__, priv, reg) +#else +#define iwl4965_read_prph _iwl4965_read_prph +#endif + +static inline void _iwl4965_write_prph(struct iwl4965_priv *priv, + u32 addr, u32 val) +{ + _iwl4965_write_direct32(priv, HBUS_TARG_PRPH_WADDR, + ((addr & 0x0000FFFF) | (3 << 24))); + _iwl4965_write_direct32(priv, HBUS_TARG_PRPH_WDAT, val); +} +#ifdef CONFIG_IWL4965_DEBUG +static inline void __iwl4965_write_prph(u32 line, struct iwl4965_priv *priv, + u32 addr, u32 val) +{ + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access from line %d\n", line); + _iwl4965_write_prph(priv, addr, val); +} + +#define iwl4965_write_prph(priv, addr, val) \ + __iwl4965_write_prph(__LINE__, priv, addr, val); +#else +#define iwl4965_write_prph _iwl4965_write_prph +#endif + +#define _iwl4965_set_bits_prph(priv, reg, mask) \ + _iwl4965_write_prph(priv, reg, (_iwl4965_read_prph(priv, reg) | mask)) +#ifdef CONFIG_IWL4965_DEBUG +static inline void __iwl4965_set_bits_prph(u32 line, struct iwl4965_priv *priv, + u32 reg, u32 mask) +{ + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access not held from line %d\n", line); + + _iwl4965_set_bits_prph(priv, reg, mask); +} +#define iwl4965_set_bits_prph(priv, reg, mask) \ + __iwl4965_set_bits_prph(__LINE__, priv, reg, mask) +#else +#define iwl4965_set_bits_prph _iwl4965_set_bits_prph +#endif + +#define _iwl4965_set_bits_mask_prph(priv, reg, bits, mask) \ + _iwl4965_write_prph(priv, reg, ((_iwl4965_read_prph(priv, reg) & mask) | bits)) + +#ifdef CONFIG_IWL4965_DEBUG +static inline void __iwl4965_set_bits_mask_prph(u32 line, + struct iwl4965_priv *priv, u32 reg, u32 bits, u32 mask) +{ + if (!atomic_read(&priv->restrict_refcnt)) + IWL_ERROR("Nic access not held from line %d\n", line); + _iwl4965_set_bits_mask_prph(priv, reg, bits, mask); +} +#define iwl4965_set_bits_mask_prph(priv, reg, bits, mask) \ + __iwl4965_set_bits_mask_prph(__LINE__, priv, reg, bits, mask) +#else +#define iwl4965_set_bits_mask_prph _iwl4965_set_bits_mask_prph +#endif + +static inline void iwl4965_clear_bits_prph(struct iwl4965_priv + *priv, u32 reg, u32 mask) +{ + u32 val = _iwl4965_read_prph(priv, reg); + _iwl4965_write_prph(priv, reg, (val & ~mask)); +} + +static inline u32 iwl4965_read_targ_mem(struct iwl4965_priv *priv, u32 addr) +{ + iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, addr); + return iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); +} + +static inline void iwl4965_write_targ_mem(struct iwl4965_priv *priv, u32 addr, u32 val) +{ + iwl4965_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr); + iwl4965_write_direct32(priv, HBUS_TARG_MEM_WDAT, val); +} + +static inline void iwl4965_write_targ_mem_buf(struct iwl4965_priv *priv, u32 addr, + u32 len, u32 *values) +{ + iwl4965_write_direct32(priv, HBUS_TARG_MEM_WADDR, addr); + for (; 0 < len; len -= sizeof(u32), values++) + iwl4965_write_direct32(priv, HBUS_TARG_MEM_WDAT, *values); +} +#endif diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-rs.c b/drivers/net/wireless/iwlwifi/iwl-4965-rs.c index 8dc78c0bf1f..d0646226414 100644 --- a/drivers/net/wireless/iwlwifi/iwl-4965-rs.c +++ b/drivers/net/wireless/iwlwifi/iwl-4965-rs.c @@ -36,11 +36,9 @@ #include <linux/workqueue.h> -#define IWL 4965 - #include "../net/mac80211/ieee80211_rate.h" -#include "iwlwifi.h" +#include "iwl-4965.h" #include "iwl-helpers.h" #define RS_NAME "iwl-4965-rs" @@ -49,13 +47,12 @@ #define IWL_NUMBER_TRY 1 #define IWL_HT_NUMBER_TRY 3 -#define IWL_RATE_MAX_WINDOW 62 -#define IWL_RATE_HIGH_TH 10880 -#define IWL_RATE_MIN_FAILURE_TH 6 -#define IWL_RATE_MIN_SUCCESS_TH 8 -#define IWL_RATE_DECREASE_TH 1920 -#define IWL_RATE_INCREASE_TH 8960 -#define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ) /*2 seconds */ +#define IWL_RATE_MAX_WINDOW 62 /* # tx in history window */ +#define IWL_RATE_MIN_FAILURE_TH 6 /* min failures to calc tpt */ +#define IWL_RATE_MIN_SUCCESS_TH 8 /* min successes to calc tpt */ + +/* max time to accum history 2 seconds */ +#define IWL_RATE_SCALE_FLUSH_INTVL (2*HZ) static u8 rs_ht_to_legacy[] = { IWL_RATE_6M_INDEX, IWL_RATE_6M_INDEX, @@ -67,83 +64,109 @@ static u8 rs_ht_to_legacy[] = { IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX }; -struct iwl_rate { +struct iwl4965_rate { u32 rate_n_flags; } __attribute__ ((packed)); -struct iwl_rate_scale_data { - u64 data; - s32 success_counter; - s32 success_ratio; - s32 counter; - s32 average_tpt; +/** + * struct iwl4965_rate_scale_data -- tx success history for one rate + */ +struct iwl4965_rate_scale_data { + u64 data; /* bitmap of successful frames */ + s32 success_counter; /* number of frames successful */ + s32 success_ratio; /* per-cent * 128 */ + s32 counter; /* number of frames attempted */ + s32 average_tpt; /* success ratio * expected throughput */ unsigned long stamp; }; -struct iwl_scale_tbl_info { - enum iwl_table_type lq_type; - enum iwl_antenna_type antenna_type; - u8 is_SGI; - u8 is_fat; - u8 is_dup; - u8 action; - s32 *expected_tpt; - struct iwl_rate current_rate; - struct iwl_rate_scale_data win[IWL_RATE_COUNT]; +/** + * struct iwl4965_scale_tbl_info -- tx params and success history for all rates + * + * There are two of these in struct iwl_rate_scale_priv, + * one for "active", and one for "search". + */ +struct iwl4965_scale_tbl_info { + enum iwl4965_table_type lq_type; + enum iwl4965_antenna_type antenna_type; + u8 is_SGI; /* 1 = short guard interval */ + u8 is_fat; /* 1 = 40 MHz channel width */ + u8 is_dup; /* 1 = duplicated data streams */ + u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */ + s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */ + struct iwl4965_rate current_rate; /* rate_n_flags, uCode API format */ + struct iwl4965_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */ }; -struct iwl_rate_scale_priv { - u8 active_tbl; - u8 enable_counter; - u8 stay_in_tbl; - u8 search_better_tbl; +/** + * struct iwl_rate_scale_priv -- driver's rate scaling private structure + * + * Pointer to this gets passed back and forth between driver and mac80211. + */ +struct iwl4965_lq_sta { + u8 active_tbl; /* index of active table, range 0-1 */ + u8 enable_counter; /* indicates HT mode */ + u8 stay_in_tbl; /* 1: disallow, 0: allow search for new mode */ + u8 search_better_tbl; /* 1: currently trying alternate mode */ s32 last_tpt; + + /* The following determine when to search for a new mode */ u32 table_count_limit; - u32 max_failure_limit; - u32 max_success_limit; + u32 max_failure_limit; /* # failed frames before new search */ + u32 max_success_limit; /* # successful frames before new search */ u32 table_count; - u32 total_failed; - u32 total_success; - u32 flush_timer; - u8 action_counter; + u32 total_failed; /* total failed frames, any/all rates */ + u32 total_success; /* total successful frames, any/all rates */ + u32 flush_timer; /* time staying in mode before new search */ + + u8 action_counter; /* # mode-switch actions tried */ u8 antenna; u8 valid_antenna; u8 is_green; u8 is_dup; u8 phymode; u8 ibss_sta_added; + + /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */ u32 supp_rates; u16 active_rate; u16 active_siso_rate; u16 active_mimo_rate; u16 active_rate_basic; - struct iwl_link_quality_cmd lq; - struct iwl_scale_tbl_info lq_info[LQ_SIZE]; + + struct iwl4965_link_quality_cmd lq; + struct iwl4965_scale_tbl_info lq_info[LQ_SIZE]; /* "active", "search" */ #ifdef CONFIG_MAC80211_DEBUGFS struct dentry *rs_sta_dbgfs_scale_table_file; struct dentry *rs_sta_dbgfs_stats_table_file; - struct iwl_rate dbg_fixed; - struct iwl_priv *drv; + struct iwl4965_rate dbg_fixed; + struct iwl4965_priv *drv; #endif }; -static void rs_rate_scale_perform(struct iwl_priv *priv, +static void rs_rate_scale_perform(struct iwl4965_priv *priv, struct net_device *dev, struct ieee80211_hdr *hdr, struct sta_info *sta); -static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data, - struct iwl_rate *tx_mcs, - struct iwl_link_quality_cmd *tbl); +static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta, + struct iwl4965_rate *tx_mcs, + struct iwl4965_link_quality_cmd *tbl); #ifdef CONFIG_MAC80211_DEBUGFS -static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv, - struct iwl_rate *mcs, int index); +static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta, + struct iwl4965_rate *mcs, int index); #else -static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv, - struct iwl_rate *mcs, int index) +static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta, + struct iwl4965_rate *mcs, int index) {} #endif + +/* + * Expected throughput metrics for following rates: + * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits + * "G" is the only table that supports CCK (the first 4 rates). + */ static s32 expected_tpt_A[IWL_RATE_COUNT] = { 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186 }; @@ -184,36 +207,34 @@ static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = { 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293 }; -static int iwl_lq_sync_callback(struct iwl_priv *priv, - struct iwl_cmd *cmd, struct sk_buff *skb) +static int iwl4965_lq_sync_callback(struct iwl4965_priv *priv, + struct iwl4965_cmd *cmd, struct sk_buff *skb) { /*We didn't cache the SKB; let the caller free it */ return 1; } -static inline u8 iwl_rate_get_rate(u32 rate_n_flags) +static inline u8 iwl4965_rate_get_rate(u32 rate_n_flags) { return (u8)(rate_n_flags & 0xFF); } -static int rs_send_lq_cmd(struct iwl_priv *priv, - struct iwl_link_quality_cmd *lq, u8 flags) +static int rs_send_lq_cmd(struct iwl4965_priv *priv, + struct iwl4965_link_quality_cmd *lq, u8 flags) { -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL4965_DEBUG int i; #endif - int rc = -1; - - struct iwl_host_cmd cmd = { + struct iwl4965_host_cmd cmd = { .id = REPLY_TX_LINK_QUALITY_CMD, - .len = sizeof(struct iwl_link_quality_cmd), + .len = sizeof(struct iwl4965_link_quality_cmd), .meta.flags = flags, .data = lq, }; if ((lq->sta_id == 0xFF) && (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)) - return rc; + return -EINVAL; if (lq->sta_id == 0xFF) lq->sta_id = IWL_AP_ID; @@ -222,23 +243,23 @@ static int rs_send_lq_cmd(struct iwl_priv *priv, IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n", lq->general_params.single_stream_ant_msk, lq->general_params.dual_stream_ant_msk); -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL4965_DEBUG for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) IWL_DEBUG_RATE("lq index %d 0x%X\n", i, lq->rs_table[i].rate_n_flags); #endif if (flags & CMD_ASYNC) - cmd.meta.u.callback = iwl_lq_sync_callback; + cmd.meta.u.callback = iwl4965_lq_sync_callback; - if (iwl_is_associated(priv) && priv->assoc_station_added && + if (iwl4965_is_associated(priv) && priv->assoc_station_added && priv->lq_mngr.lq_ready) - rc = iwl_send_cmd(priv, &cmd); + return iwl4965_send_cmd(priv, &cmd); - return rc; + return 0; } -static int rs_rate_scale_clear_window(struct iwl_rate_scale_data *window) +static void rs_rate_scale_clear_window(struct iwl4965_rate_scale_data *window) { window->data = 0; window->success_counter = 0; @@ -246,29 +267,38 @@ static int rs_rate_scale_clear_window(struct iwl_rate_scale_data *window) window->counter = 0; window->average_tpt = IWL_INVALID_VALUE; window->stamp = 0; - - return 0; } -static int rs_collect_tx_data(struct iwl_rate_scale_data *windows, +/** + * rs_collect_tx_data - Update the success/failure sliding window + * + * We keep a sliding window of the last 62 packets transmitted + * at this rate. window->data contains the bitmask of successful + * packets. + */ +static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows, int scale_index, s32 tpt, u32 status) { - int rc = 0; - struct iwl_rate_scale_data *window = NULL; + struct iwl4965_rate_scale_data *window = NULL; u64 mask; u8 win_size = IWL_RATE_MAX_WINDOW; s32 fail_count; - if (scale_index < 0) - return -1; - - if (scale_index >= IWL_RATE_COUNT) - return -1; + if (scale_index < 0 || scale_index >= IWL_RATE_COUNT) + return -EINVAL; + /* Select data for current tx bit rate */ window = &(windows[scale_index]); + /* + * Keep track of only the latest 62 tx frame attempts in this rate's + * history window; anything older isn't really relevant any more. + * If we have filled up the sliding window, drop the oldest attempt; + * if the oldest attempt (highest bit in bitmap) shows "success", + * subtract "1" from the success counter (this is the main reason + * we keep these bitmaps!). + */ if (window->counter >= win_size) { - window->counter = win_size - 1; mask = 1; mask = (mask << (win_size - 1)); @@ -278,7 +308,11 @@ static int rs_collect_tx_data(struct iwl_rate_scale_data *windows, } } + /* Increment frames-attempted counter */ window->counter = window->counter + 1; + + /* Shift bitmap by one frame (throw away oldest history), + * OR in "1", and increment "success" if this frame was successful. */ mask = window->data; window->data = (mask << 1); if (status != 0) { @@ -286,6 +320,7 @@ static int rs_collect_tx_data(struct iwl_rate_scale_data *windows, window->data |= 0x1; } + /* Calculate current success ratio, avoid divide-by-0! */ if (window->counter > 0) window->success_ratio = 128 * (100 * window->success_counter) / window->counter; @@ -294,37 +329,40 @@ static int rs_collect_tx_data(struct iwl_rate_scale_data *windows, fail_count = window->counter - window->success_counter; + /* Calculate average throughput, if we have enough history. */ if ((fail_count >= IWL_RATE_MIN_FAILURE_TH) || (window->success_counter >= IWL_RATE_MIN_SUCCESS_TH)) window->average_tpt = (window->success_ratio * tpt + 64) / 128; else window->average_tpt = IWL_INVALID_VALUE; + /* Tag this window as having been updated */ window->stamp = jiffies; - return rc; + return 0; } -int static rs_mcs_from_tbl(struct iwl_rate *mcs_rate, - struct iwl_scale_tbl_info *tbl, +/* + * Fill uCode API rate_n_flags field, based on "search" or "active" table. + */ +static void rs_mcs_from_tbl(struct iwl4965_rate *mcs_rate, + struct iwl4965_scale_tbl_info *tbl, int index, u8 use_green) { - int rc = 0; - if (is_legacy(tbl->lq_type)) { - mcs_rate->rate_n_flags = iwl_rates[index].plcp; + mcs_rate->rate_n_flags = iwl4965_rates[index].plcp; if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE) mcs_rate->rate_n_flags |= RATE_MCS_CCK_MSK; } else if (is_siso(tbl->lq_type)) { if (index > IWL_LAST_OFDM_RATE) index = IWL_LAST_OFDM_RATE; - mcs_rate->rate_n_flags = iwl_rates[index].plcp_siso | + mcs_rate->rate_n_flags = iwl4965_rates[index].plcp_siso | RATE_MCS_HT_MSK; } else { if (index > IWL_LAST_OFDM_RATE) index = IWL_LAST_OFDM_RATE; - mcs_rate->rate_n_flags = iwl_rates[index].plcp_mimo | + mcs_rate->rate_n_flags = iwl4965_rates[index].plcp_mimo | RATE_MCS_HT_MSK; } @@ -343,7 +381,7 @@ int static rs_mcs_from_tbl(struct iwl_rate *mcs_rate, } if (is_legacy(tbl->lq_type)) - return rc; + return; if (tbl->is_fat) { if (tbl->is_dup) @@ -359,27 +397,31 @@ int static rs_mcs_from_tbl(struct iwl_rate *mcs_rate, if (is_siso(tbl->lq_type)) mcs_rate->rate_n_flags &= ~RATE_MCS_SGI_MSK; } - return rc; } -static int rs_get_tbl_info_from_mcs(const struct iwl_rate *mcs_rate, - int phymode, struct iwl_scale_tbl_info *tbl, +/* + * Interpret uCode API's rate_n_flags format, + * fill "search" or "active" tx mode table. + */ +static int rs_get_tbl_info_from_mcs(const struct iwl4965_rate *mcs_rate, + int phymode, struct iwl4965_scale_tbl_info *tbl, int *rate_idx) { int index; u32 ant_msk; - index = iwl_rate_index_from_plcp(mcs_rate->rate_n_flags); + index = iwl4965_rate_index_from_plcp(mcs_rate->rate_n_flags); if (index == IWL_RATE_INVALID) { *rate_idx = -1; - return -1; + return -EINVAL; } - tbl->is_SGI = 0; + tbl->is_SGI = 0; /* default legacy setup */ tbl->is_fat = 0; tbl->is_dup = 0; - tbl->antenna_type = ANT_BOTH; + tbl->antenna_type = ANT_BOTH; /* default MIMO setup */ + /* legacy rate format */ if (!(mcs_rate->rate_n_flags & RATE_MCS_HT_MSK)) { ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK); @@ -399,7 +441,8 @@ static int rs_get_tbl_info_from_mcs(const struct iwl_rate *mcs_rate, } *rate_idx = index; - } else if (iwl_rate_get_rate(mcs_rate->rate_n_flags) + /* HT rate format, SISO (might be 20 MHz legacy or 40 MHz fat width) */ + } else if (iwl4965_rate_get_rate(mcs_rate->rate_n_flags) <= IWL_RATE_SISO_60M_PLCP) { tbl->lq_type = LQ_SISO; @@ -423,6 +466,8 @@ static int rs_get_tbl_info_from_mcs(const struct iwl_rate *mcs_rate, tbl->is_dup = 1; *rate_idx = index; + + /* HT rate format, MIMO (might be 20 MHz legacy or 40 MHz fat width) */ } else { tbl->lq_type = LQ_MIMO; if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK) @@ -439,8 +484,8 @@ static int rs_get_tbl_info_from_mcs(const struct iwl_rate *mcs_rate, return 0; } -static inline void rs_toggle_antenna(struct iwl_rate *new_rate, - struct iwl_scale_tbl_info *tbl) +static inline void rs_toggle_antenna(struct iwl4965_rate *new_rate, + struct iwl4965_scale_tbl_info *tbl) { if (tbl->antenna_type == ANT_AUX) { tbl->antenna_type = ANT_MAIN; @@ -453,18 +498,15 @@ static inline void rs_toggle_antenna(struct iwl_rate *new_rate, } } -static inline s8 rs_use_green(struct iwl_priv *priv) +static inline u8 rs_use_green(struct iwl4965_priv *priv, + struct ieee80211_conf *conf) { - s8 rc = 0; -#ifdef CONFIG_IWLWIFI_HT - if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht) - return 0; - - if ((priv->current_assoc_ht.is_green_field) && - !(priv->current_assoc_ht.operating_mode & 0x4)) - rc = 1; -#endif /*CONFIG_IWLWIFI_HT */ - return rc; +#ifdef CONFIG_IWL4965_HT + return ((conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && + priv->current_ht_config.is_green_field && + !priv->current_ht_config.non_GF_STA_present); +#endif /* CONFIG_IWL4965_HT */ + return 0; } /** @@ -474,23 +516,24 @@ static inline s8 rs_use_green(struct iwl_priv *priv) * basic available rates. * */ -static void rs_get_supported_rates(struct iwl_rate_scale_priv *lq_data, +static void rs_get_supported_rates(struct iwl4965_lq_sta *lq_sta, struct ieee80211_hdr *hdr, - enum iwl_table_type rate_type, + enum iwl4965_table_type rate_type, u16 *data_rate) { if (is_legacy(rate_type)) - *data_rate = lq_data->active_rate; + *data_rate = lq_sta->active_rate; else { if (is_siso(rate_type)) - *data_rate = lq_data->active_siso_rate; + *data_rate = lq_sta->active_siso_rate; else - *data_rate = lq_data->active_mimo_rate; + *data_rate = lq_sta->active_mimo_rate; } if (hdr && is_multicast_ether_addr(hdr->addr1) && - lq_data->active_rate_basic) - *data_rate = lq_data->active_rate_basic; + lq_sta->active_rate_basic) { + *data_rate = lq_sta->active_rate_basic; + } } static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type) @@ -498,7 +541,7 @@ static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type) u8 high = IWL_RATE_INVALID; u8 low = IWL_RATE_INVALID; - /* 802.11A or ht walks to the next literal adjascent rate in + /* 802.11A or ht walks to the next literal adjacent rate in * the rate table */ if (is_a_band(rate_type) || !is_legacy(rate_type)) { int i; @@ -527,7 +570,7 @@ static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type) low = index; while (low != IWL_RATE_INVALID) { - low = iwl_rates[low].prev_rs; + low = iwl4965_rates[low].prev_rs; if (low == IWL_RATE_INVALID) break; if (rate_mask & (1 << low)) @@ -537,7 +580,7 @@ static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type) high = index; while (high != IWL_RATE_INVALID) { - high = iwl_rates[high].next_rs; + high = iwl4965_rates[high].next_rs; if (high == IWL_RATE_INVALID) break; if (rate_mask & (1 << high)) @@ -548,15 +591,15 @@ static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type) return (high << 8) | low; } -static int rs_get_lower_rate(struct iwl_rate_scale_priv *lq_data, - struct iwl_scale_tbl_info *tbl, u8 scale_index, - u8 ht_possible, struct iwl_rate *mcs_rate) +static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta, + struct iwl4965_scale_tbl_info *tbl, u8 scale_index, + u8 ht_possible, struct iwl4965_rate *mcs_rate) { s32 low; u16 rate_mask; u16 high_low; u8 switch_to_legacy = 0; - u8 is_green = lq_data->is_green; + u8 is_green = lq_sta->is_green; /* check if we need to switch from HT to legacy rates. * assumption is that mandatory rates (1Mbps or 6Mbps) @@ -564,7 +607,7 @@ static int rs_get_lower_rate(struct iwl_rate_scale_priv *lq_data, if (!is_legacy(tbl->lq_type) && (!ht_possible || !scale_index)) { switch_to_legacy = 1; scale_index = rs_ht_to_legacy[scale_index]; - if (lq_data->phymode == MODE_IEEE80211A) + if (lq_sta->phymode == MODE_IEEE80211A) tbl->lq_type = LQ_A; else tbl->lq_type = LQ_G; @@ -577,22 +620,22 @@ static int rs_get_lower_rate(struct iwl_rate_scale_priv *lq_data, tbl->is_SGI = 0; } - rs_get_supported_rates(lq_data, NULL, tbl->lq_type, &rate_mask); + rs_get_supported_rates(lq_sta, NULL, tbl->lq_type, &rate_mask); - /* mask with station rate restriction */ + /* Mask with station rate restriction */ if (is_legacy(tbl->lq_type)) { - if (lq_data->phymode == (u8) MODE_IEEE80211A) + /* supp_rates has no CCK bits in A mode */ + if (lq_sta->phymode == (u8) MODE_IEEE80211A) rate_mask = (u16)(rate_mask & - (lq_data->supp_rates << IWL_FIRST_OFDM_RATE)); + (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); else - rate_mask = (u16)(rate_mask & lq_data->supp_rates); + rate_mask = (u16)(rate_mask & lq_sta->supp_rates); } - /* if we did switched from HT to legacy check current rate */ - if ((switch_to_legacy) && - (rate_mask & (1 << scale_index))) { + /* If we switched from HT to legacy, check current rate */ + if (switch_to_legacy && (rate_mask & (1 << scale_index))) { rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green); - return 0; + return; } high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type); @@ -602,29 +645,29 @@ static int rs_get_lower_rate(struct iwl_rate_scale_priv *lq_data, rs_mcs_from_tbl(mcs_rate, tbl, low, is_green); else rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green); - - return 0; } -static void rs_tx_status(void *priv_rate, - struct net_device *dev, +/* + * mac80211 sends us Tx status + */ +static void rs_tx_status(void *priv_rate, struct net_device *dev, struct sk_buff *skb, struct ieee80211_tx_status *tx_resp) { int status; u8 retries; int rs_index, index = 0; - struct iwl_rate_scale_priv *lq; - struct iwl_link_quality_cmd *table; + struct iwl4965_lq_sta *lq_sta; + struct iwl4965_link_quality_cmd *table; struct sta_info *sta; struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; - struct iwl_priv *priv = (struct iwl_priv *)priv_rate; + struct iwl4965_priv *priv = (struct iwl4965_priv *)priv_rate; struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); - struct iwl_rate_scale_data *window = NULL; - struct iwl_rate_scale_data *search_win = NULL; - struct iwl_rate tx_mcs; - struct iwl_scale_tbl_info tbl_type; - struct iwl_scale_tbl_info *curr_tbl, *search_tbl; + struct iwl4965_rate_scale_data *window = NULL; + struct iwl4965_rate_scale_data *search_win = NULL; + struct iwl4965_rate tx_mcs; + struct iwl4965_scale_tbl_info tbl_type; + struct iwl4965_scale_tbl_info *curr_tbl, *search_tbl; u8 active_index = 0; u16 fc = le16_to_cpu(hdr->frame_control); s32 tpt = 0; @@ -648,27 +691,32 @@ static void rs_tx_status(void *priv_rate, return; } - lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv; + lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv; if (!priv->lq_mngr.lq_ready) return; - if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added) + if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && + !lq_sta->ibss_sta_added) return; - table = &lq->lq; - active_index = lq->active_tbl; + table = &lq_sta->lq; + active_index = lq_sta->active_tbl; - lq->antenna = (lq->valid_antenna & local->hw.conf.antenna_sel_tx); - if (!lq->antenna) - lq->antenna = lq->valid_antenna; + /* Get mac80211 antenna info */ + lq_sta->antenna = + (lq_sta->valid_antenna & local->hw.conf.antenna_sel_tx); + if (!lq_sta->antenna) + lq_sta->antenna = lq_sta->valid_antenna; - lq->antenna = lq->valid_antenna; - curr_tbl = &(lq->lq_info[active_index]); - search_tbl = &(lq->lq_info[(1 - active_index)]); - window = (struct iwl_rate_scale_data *) + /* Ignore mac80211 antenna info for now */ + lq_sta->antenna = lq_sta->valid_antenna; + + curr_tbl = &(lq_sta->lq_info[active_index]); + search_tbl = &(lq_sta->lq_info[(1 - active_index)]); + window = (struct iwl4965_rate_scale_data *) &(curr_tbl->win[0]); - search_win = (struct iwl_rate_scale_data *) + search_win = (struct iwl4965_rate_scale_data *) &(search_tbl->win[0]); tx_mcs.rate_n_flags = tx_resp->control.tx_rate; @@ -682,6 +730,14 @@ static void rs_tx_status(void *priv_rate, return; } + /* + * Ignore this Tx frame response if its initial rate doesn't match + * that of latest Link Quality command. There may be stragglers + * from a previous Link Quality command, but we're no longer interested + * in those; they're either from the "active" mode while we're trying + * to check "search" mode, or a prior "search" mode after we've moved + * to a new "search" mode (which might become the new "active" mode). + */ if (retries && (tx_mcs.rate_n_flags != le32_to_cpu(table->rs_table[0].rate_n_flags))) { @@ -692,12 +748,17 @@ static void rs_tx_status(void *priv_rate, return; } + /* Update frame history window with "failure" for each Tx retry. */ while (retries) { + /* Look up the rate and other info used for each tx attempt. + * Each tx attempt steps one entry deeper in the rate table. */ tx_mcs.rate_n_flags = le32_to_cpu(table->rs_table[index].rate_n_flags); rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode, &tbl_type, &rs_index); + /* If type matches "search" table, + * add failure to "search" history */ if ((tbl_type.lq_type == search_tbl->lq_type) && (tbl_type.antenna_type == search_tbl->antenna_type) && (tbl_type.is_SGI == search_tbl->is_SGI)) { @@ -705,8 +766,10 @@ static void rs_tx_status(void *priv_rate, tpt = search_tbl->expected_tpt[rs_index]; else tpt = 0; - rs_collect_tx_data(search_win, - rs_index, tpt, 0); + rs_collect_tx_data(search_win, rs_index, tpt, 0); + + /* Else if type matches "current/active" table, + * add failure to "current/active" history */ } else if ((tbl_type.lq_type == curr_tbl->lq_type) && (tbl_type.antenna_type == curr_tbl->antenna_type) && (tbl_type.is_SGI == curr_tbl->is_SGI)) { @@ -716,13 +779,21 @@ static void rs_tx_status(void *priv_rate, tpt = 0; rs_collect_tx_data(window, rs_index, tpt, 0); } - if (lq->stay_in_tbl) - lq->total_failed++; + + /* If not searching for a new mode, increment failed counter + * ... this helps determine when to start searching again */ + if (lq_sta->stay_in_tbl) + lq_sta->total_failed++; --retries; index++; } + /* + * Find (by rate) the history window to update with final Tx attempt; + * if Tx was successful first try, use original rate, + * else look up the rate that was, finally, successful. + */ if (!tx_resp->retry_count) tx_mcs.rate_n_flags = tx_resp->control.tx_rate; else @@ -732,11 +803,14 @@ static void rs_tx_status(void *priv_rate, rs_get_tbl_info_from_mcs(&tx_mcs, priv->phymode, &tbl_type, &rs_index); + /* Update frame history window with "success" if Tx got ACKed ... */ if (tx_resp->flags & IEEE80211_TX_STATUS_ACK) status = 1; else status = 0; + /* If type matches "search" table, + * add final tx status to "search" history */ if ((tbl_type.lq_type == search_tbl->lq_type) && (tbl_type.antenna_type == search_tbl->antenna_type) && (tbl_type.is_SGI == search_tbl->is_SGI)) { @@ -746,6 +820,9 @@ static void rs_tx_status(void *priv_rate, tpt = 0; rs_collect_tx_data(search_win, rs_index, tpt, status); + + /* Else if type matches "current/active" table, + * add final tx status to "current/active" history */ } else if ((tbl_type.lq_type == curr_tbl->lq_type) && (tbl_type.antenna_type == curr_tbl->antenna_type) && (tbl_type.is_SGI == curr_tbl->is_SGI)) { @@ -756,67 +833,77 @@ static void rs_tx_status(void *priv_rate, rs_collect_tx_data(window, rs_index, tpt, status); } - if (lq->stay_in_tbl) { + /* If not searching for new mode, increment success/failed counter + * ... these help determine when to start searching again */ + if (lq_sta->stay_in_tbl) { if (status) - lq->total_success++; + lq_sta->total_success++; else - lq->total_failed++; + lq_sta->total_failed++; } + /* See if there's a better rate or modulation mode to try. */ rs_rate_scale_perform(priv, dev, hdr, sta); sta_info_put(sta); return; } static u8 rs_is_ant_connected(u8 valid_antenna, - enum iwl_antenna_type antenna_type) + enum iwl4965_antenna_type antenna_type) { if (antenna_type == ANT_AUX) return ((valid_antenna & 0x2) ? 1:0); else if (antenna_type == ANT_MAIN) return ((valid_antenna & 0x1) ? 1:0); - else if (antenna_type == ANT_BOTH) { - if ((valid_antenna & 0x3) == 0x3) - return 1; - else - return 0; - } + else if (antenna_type == ANT_BOTH) + return ((valid_antenna & 0x3) == 0x3); return 1; } static u8 rs_is_other_ant_connected(u8 valid_antenna, - enum iwl_antenna_type antenna_type) + enum iwl4965_antenna_type antenna_type) { if (antenna_type == ANT_AUX) - return (rs_is_ant_connected(valid_antenna, ANT_MAIN)); + return rs_is_ant_connected(valid_antenna, ANT_MAIN); else - return (rs_is_ant_connected(valid_antenna, ANT_AUX)); + return rs_is_ant_connected(valid_antenna, ANT_AUX); return 0; } +/* + * Begin a period of staying with a selected modulation mode. + * Set "stay_in_tbl" flag to prevent any mode switches. + * Set frame tx success limits according to legacy vs. high-throughput, + * and reset overall (spanning all rates) tx success history statistics. + * These control how long we stay using same modulation mode before + * searching for a new mode. + */ static void rs_set_stay_in_table(u8 is_legacy, - struct iwl_rate_scale_priv *lq_data) + struct iwl4965_lq_sta *lq_sta) { IWL_DEBUG_HT("we are staying in the same table\n"); - lq_data->stay_in_tbl = 1; + lq_sta->stay_in_tbl = 1; /* only place this gets set */ if (is_legacy) { - lq_data->table_count_limit = IWL_LEGACY_TABLE_COUNT; - lq_data->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT; - lq_data->max_success_limit = IWL_LEGACY_TABLE_COUNT; + lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT; + lq_sta->max_failure_limit = IWL_LEGACY_FAILURE_LIMIT; + lq_sta->max_success_limit = IWL_LEGACY_SUCCESS_LIMIT; } else { - lq_data->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT; - lq_data->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT; - lq_data->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT; + lq_sta->table_count_limit = IWL_NONE_LEGACY_TABLE_COUNT; + lq_sta->max_failure_limit = IWL_NONE_LEGACY_FAILURE_LIMIT; + lq_sta->max_success_limit = IWL_NONE_LEGACY_SUCCESS_LIMIT; } - lq_data->table_count = 0; - lq_data->total_failed = 0; - lq_data->total_success = 0; + lq_sta->table_count = 0; + lq_sta->total_failed = 0; + lq_sta->total_success = 0; } -static void rs_get_expected_tpt_table(struct iwl_rate_scale_priv *lq_data, - struct iwl_scale_tbl_info *tbl) +/* + * Find correct throughput table for given mode of modulation + */ +static void rs_get_expected_tpt_table(struct iwl4965_lq_sta *lq_sta, + struct iwl4965_scale_tbl_info *tbl) { if (is_legacy(tbl->lq_type)) { if (!is_a_band(tbl->lq_type)) @@ -824,7 +911,7 @@ static void rs_get_expected_tpt_table(struct iwl_rate_scale_priv *lq_data, else tbl->expected_tpt = expected_tpt_A; } else if (is_siso(tbl->lq_type)) { - if (tbl->is_fat && !lq_data->is_dup) + if (tbl->is_fat && !lq_sta->is_dup) if (tbl->is_SGI) tbl->expected_tpt = expected_tpt_siso40MHzSGI; else @@ -835,7 +922,7 @@ static void rs_get_expected_tpt_table(struct iwl_rate_scale_priv *lq_data, tbl->expected_tpt = expected_tpt_siso20MHz; } else if (is_mimo(tbl->lq_type)) { - if (tbl->is_fat && !lq_data->is_dup) + if (tbl->is_fat && !lq_sta->is_dup) if (tbl->is_SGI) tbl->expected_tpt = expected_tpt_mimo40MHzSGI; else @@ -848,18 +935,34 @@ static void rs_get_expected_tpt_table(struct iwl_rate_scale_priv *lq_data, tbl->expected_tpt = expected_tpt_G; } -#ifdef CONFIG_IWLWIFI_HT -static s32 rs_get_best_rate(struct iwl_priv *priv, - struct iwl_rate_scale_priv *lq_data, - struct iwl_scale_tbl_info *tbl, +#ifdef CONFIG_IWL4965_HT +/* + * Find starting rate for new "search" high-throughput mode of modulation. + * Goal is to find lowest expected rate (under perfect conditions) that is + * above the current measured throughput of "active" mode, to give new mode + * a fair chance to prove itself without too many challenges. + * + * This gets called when transitioning to more aggressive modulation + * (i.e. legacy to SISO or MIMO, or SISO to MIMO), as well as less aggressive + * (i.e. MIMO to SISO). When moving to MIMO, bit rate will typically need + * to decrease to match "active" throughput. When moving from MIMO to SISO, + * bit rate will typically need to increase, but not if performance was bad. + */ +static s32 rs_get_best_rate(struct iwl4965_priv *priv, + struct iwl4965_lq_sta *lq_sta, + struct iwl4965_scale_tbl_info *tbl, /* "search" */ u16 rate_mask, s8 index, s8 rate) { - struct iwl_scale_tbl_info *active_tbl = - &(lq_data->lq_info[lq_data->active_tbl]); - s32 new_rate, high, low, start_hi; + /* "active" values */ + struct iwl4965_scale_tbl_info *active_tbl = + &(lq_sta->lq_info[lq_sta->active_tbl]); s32 active_sr = active_tbl->win[index].success_ratio; - s32 *tpt_tbl = tbl->expected_tpt; s32 active_tpt = active_tbl->expected_tpt[index]; + + /* expected "search" throughput */ + s32 *tpt_tbl = tbl->expected_tpt; + + s32 new_rate, high, low, start_hi; u16 high_low; new_rate = high = low = start_hi = IWL_RATE_INVALID; @@ -870,28 +973,60 @@ static s32 rs_get_best_rate(struct iwl_priv *priv, low = high_low & 0xff; high = (high_low >> 8) & 0xff; - if ((((100 * tpt_tbl[rate]) > lq_data->last_tpt) && + /* + * Lower the "search" bit rate, to give new "search" mode + * approximately the same throughput as "active" if: + * + * 1) "Active" mode has been working modestly well (but not + * great), and expected "search" throughput (under perfect + * conditions) at candidate rate is above the actual + * measured "active" throughput (but less than expected + * "active" throughput under perfect conditions). + * OR + * 2) "Active" mode has been working perfectly or very well + * and expected "search" throughput (under perfect + * conditions) at candidate rate is above expected + * "active" throughput (under perfect conditions). + */ + if ((((100 * tpt_tbl[rate]) > lq_sta->last_tpt) && ((active_sr > IWL_RATE_DECREASE_TH) && (active_sr <= IWL_RATE_HIGH_TH) && (tpt_tbl[rate] <= active_tpt))) || ((active_sr >= IWL_RATE_SCALE_SWITCH) && (tpt_tbl[rate] > active_tpt))) { + /* (2nd or later pass) + * If we've already tried to raise the rate, and are + * now trying to lower it, use the higher rate. */ if (start_hi != IWL_RATE_INVALID) { new_rate = start_hi; break; } + new_rate = rate; + + /* Loop again with lower rate */ if (low != IWL_RATE_INVALID) rate = low; + + /* Lower rate not available, use the original */ else break; + + /* Else try to raise the "search" rate to match "active" */ } else { + /* (2nd or later pass) + * If we've already tried to lower the rate, and are + * now trying to raise it, use the lower rate. */ if (new_rate != IWL_RATE_INVALID) break; + + /* Loop again with higher rate */ else if (high != IWL_RATE_INVALID) { start_hi = high; rate = high; + + /* Higher rate not available, use the original */ } else { new_rate = rate; break; @@ -901,58 +1036,64 @@ static s32 rs_get_best_rate(struct iwl_priv *priv, return new_rate; } -#endif /* CONFIG_IWLWIFI_HT */ +#endif /* CONFIG_IWL4965_HT */ static inline u8 rs_is_both_ant_supp(u8 valid_antenna) { return (rs_is_ant_connected(valid_antenna, ANT_BOTH)); } -static int rs_switch_to_mimo(struct iwl_priv *priv, - struct iwl_rate_scale_priv *lq_data, - struct iwl_scale_tbl_info *tbl, int index) +/* + * Set up search table for MIMO + */ +static int rs_switch_to_mimo(struct iwl4965_priv *priv, + struct iwl4965_lq_sta *lq_sta, + struct ieee80211_conf *conf, + struct sta_info *sta, + struct iwl4965_scale_tbl_info *tbl, int index) { - int rc = -1; -#ifdef CONFIG_IWLWIFI_HT +#ifdef CONFIG_IWL4965_HT u16 rate_mask; s32 rate; - s8 is_green = lq_data->is_green; + s8 is_green = lq_sta->is_green; - if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht) + if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) || + !sta->ht_info.ht_supported) return -1; IWL_DEBUG_HT("LQ: try to switch to MIMO\n"); tbl->lq_type = LQ_MIMO; - rs_get_supported_rates(lq_data, NULL, tbl->lq_type, + rs_get_supported_rates(lq_sta, NULL, tbl->lq_type, &rate_mask); - if (priv->current_assoc_ht.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC) + if (priv->current_ht_config.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC) return -1; - if (!rs_is_both_ant_supp(lq_data->antenna)) + /* Need both Tx chains/antennas to support MIMO */ + if (!rs_is_both_ant_supp(lq_sta->antenna)) return -1; - rc = 0; - tbl->is_dup = lq_data->is_dup; + tbl->is_dup = lq_sta->is_dup; tbl->action = 0; - if (priv->current_channel_width == IWL_CHANNEL_WIDTH_40MHZ) + if (priv->current_ht_config.supported_chan_width + == IWL_CHANNEL_WIDTH_40MHZ) tbl->is_fat = 1; else tbl->is_fat = 0; if (tbl->is_fat) { - if (priv->current_assoc_ht.sgf & HT_SHORT_GI_40MHZ_ONLY) + if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY) tbl->is_SGI = 1; else tbl->is_SGI = 0; - } else if (priv->current_assoc_ht.sgf & HT_SHORT_GI_20MHZ_ONLY) + } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY) tbl->is_SGI = 1; else tbl->is_SGI = 0; - rs_get_expected_tpt_table(lq_data, tbl); + rs_get_expected_tpt_table(lq_sta, tbl); - rate = rs_get_best_rate(priv, lq_data, tbl, rate_mask, index, index); + rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index, index); IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate, rate_mask); if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) @@ -961,43 +1102,49 @@ static int rs_switch_to_mimo(struct iwl_priv *priv, IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n", tbl->current_rate.rate_n_flags, is_green); - -#endif /*CONFIG_IWLWIFI_HT */ - return rc; + return 0; +#else + return -1; +#endif /*CONFIG_IWL4965_HT */ } -static int rs_switch_to_siso(struct iwl_priv *priv, - struct iwl_rate_scale_priv *lq_data, - struct iwl_scale_tbl_info *tbl, int index) +/* + * Set up search table for SISO + */ +static int rs_switch_to_siso(struct iwl4965_priv *priv, + struct iwl4965_lq_sta *lq_sta, + struct ieee80211_conf *conf, + struct sta_info *sta, + struct iwl4965_scale_tbl_info *tbl, int index) { - int rc = -1; -#ifdef CONFIG_IWLWIFI_HT +#ifdef CONFIG_IWL4965_HT u16 rate_mask; - u8 is_green = lq_data->is_green; + u8 is_green = lq_sta->is_green; s32 rate; IWL_DEBUG_HT("LQ: try to switch to SISO\n"); - if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht) + if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) || + !sta->ht_info.ht_supported) return -1; - rc = 0; - tbl->is_dup = lq_data->is_dup; + tbl->is_dup = lq_sta->is_dup; tbl->lq_type = LQ_SISO; tbl->action = 0; - rs_get_supported_rates(lq_data, NULL, tbl->lq_type, + rs_get_supported_rates(lq_sta, NULL, tbl->lq_type, &rate_mask); - if (priv->current_channel_width == IWL_CHANNEL_WIDTH_40MHZ) + if (priv->current_ht_config.supported_chan_width + == IWL_CHANNEL_WIDTH_40MHZ) tbl->is_fat = 1; else tbl->is_fat = 0; if (tbl->is_fat) { - if (priv->current_assoc_ht.sgf & HT_SHORT_GI_40MHZ_ONLY) + if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY) tbl->is_SGI = 1; else tbl->is_SGI = 0; - } else if (priv->current_assoc_ht.sgf & HT_SHORT_GI_20MHZ_ONLY) + } else if (priv->current_ht_config.sgf & HT_SHORT_GI_20MHZ_ONLY) tbl->is_SGI = 1; else tbl->is_SGI = 0; @@ -1005,8 +1152,8 @@ static int rs_switch_to_siso(struct iwl_priv *priv, if (is_green) tbl->is_SGI = 0; - rs_get_expected_tpt_table(lq_data, tbl); - rate = rs_get_best_rate(priv, lq_data, tbl, rate_mask, index, index); + rs_get_expected_tpt_table(lq_sta, tbl); + rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index, index); IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate, rate_mask); if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { @@ -1017,23 +1164,30 @@ static int rs_switch_to_siso(struct iwl_priv *priv, rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green); IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n", tbl->current_rate.rate_n_flags, is_green); + return 0; +#else + return -1; -#endif /*CONFIG_IWLWIFI_HT */ - return rc; +#endif /*CONFIG_IWL4965_HT */ } -static int rs_move_legacy_other(struct iwl_priv *priv, - struct iwl_rate_scale_priv *lq_data, +/* + * Try to switch to new modulation mode from legacy + */ +static int rs_move_legacy_other(struct iwl4965_priv *priv, + struct iwl4965_lq_sta *lq_sta, + struct ieee80211_conf *conf, + struct sta_info *sta, int index) { - int rc = 0; - struct iwl_scale_tbl_info *tbl = - &(lq_data->lq_info[lq_data->active_tbl]); - struct iwl_scale_tbl_info *search_tbl = - &(lq_data->lq_info[(1 - lq_data->active_tbl)]); - struct iwl_rate_scale_data *window = &(tbl->win[index]); - u32 sz = (sizeof(struct iwl_scale_tbl_info) - - (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); + int ret = 0; + struct iwl4965_scale_tbl_info *tbl = + &(lq_sta->lq_info[lq_sta->active_tbl]); + struct iwl4965_scale_tbl_info *search_tbl = + &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); + struct iwl4965_rate_scale_data *window = &(tbl->win[index]); + u32 sz = (sizeof(struct iwl4965_scale_tbl_info) - + (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT)); u8 start_action = tbl->action; for (; ;) { @@ -1042,52 +1196,59 @@ static int rs_move_legacy_other(struct iwl_priv *priv, IWL_DEBUG_HT("LQ Legacy switch Antenna\n"); search_tbl->lq_type = LQ_NONE; - lq_data->action_counter++; + lq_sta->action_counter++; + + /* Don't change antenna if success has been great */ if (window->success_ratio >= IWL_RS_GOOD_RATIO) break; - if (!rs_is_other_ant_connected(lq_data->antenna, + + /* Don't change antenna if other one is not connected */ + if (!rs_is_other_ant_connected(lq_sta->antenna, tbl->antenna_type)) break; + /* Set up search table to try other antenna */ memcpy(search_tbl, tbl, sz); rs_toggle_antenna(&(search_tbl->current_rate), search_tbl); - rs_get_expected_tpt_table(lq_data, search_tbl); - lq_data->search_better_tbl = 1; + rs_get_expected_tpt_table(lq_sta, search_tbl); + lq_sta->search_better_tbl = 1; goto out; case IWL_LEGACY_SWITCH_SISO: IWL_DEBUG_HT("LQ: Legacy switch to SISO\n"); + + /* Set up search table to try SISO */ memcpy(search_tbl, tbl, sz); search_tbl->lq_type = LQ_SISO; search_tbl->is_SGI = 0; search_tbl->is_fat = 0; - rc = rs_switch_to_siso(priv, lq_data, search_tbl, - index); - if (!rc) { - lq_data->search_better_tbl = 1; - lq_data->action_counter = 0; - } - if (!rc) + ret = rs_switch_to_siso(priv, lq_sta, conf, sta, + search_tbl, index); + if (!ret) { + lq_sta->search_better_tbl = 1; + lq_sta->action_counter = 0; goto out; + } break; case IWL_LEGACY_SWITCH_MIMO: IWL_DEBUG_HT("LQ: Legacy switch MIMO\n"); + + /* Set up search table to try MIMO */ memcpy(search_tbl, tbl, sz); search_tbl->lq_type = LQ_MIMO; search_tbl->is_SGI = 0; search_tbl->is_fat = 0; search_tbl->antenna_type = ANT_BOTH; - rc = rs_switch_to_mimo(priv, lq_data, search_tbl, - index); - if (!rc) { - lq_data->search_better_tbl = 1; - lq_data->action_counter = 0; - } - if (!rc) + ret = rs_switch_to_mimo(priv, lq_sta, conf, sta, + search_tbl, index); + if (!ret) { + lq_sta->search_better_tbl = 1; + lq_sta->action_counter = 0; goto out; + } break; } tbl->action++; @@ -1108,30 +1269,35 @@ static int rs_move_legacy_other(struct iwl_priv *priv, } -static int rs_move_siso_to_other(struct iwl_priv *priv, - struct iwl_rate_scale_priv *lq_data, +/* + * Try to switch to new modulation mode from SISO + */ +static int rs_move_siso_to_other(struct iwl4965_priv *priv, + struct iwl4965_lq_sta *lq_sta, + struct ieee80211_conf *conf, + struct sta_info *sta, int index) { - int rc = -1; - u8 is_green = lq_data->is_green; - struct iwl_scale_tbl_info *tbl = - &(lq_data->lq_info[lq_data->active_tbl]); - struct iwl_scale_tbl_info *search_tbl = - &(lq_data->lq_info[(1 - lq_data->active_tbl)]); - struct iwl_rate_scale_data *window = &(tbl->win[index]); - u32 sz = (sizeof(struct iwl_scale_tbl_info) - - (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); + int ret; + u8 is_green = lq_sta->is_green; + struct iwl4965_scale_tbl_info *tbl = + &(lq_sta->lq_info[lq_sta->active_tbl]); + struct iwl4965_scale_tbl_info *search_tbl = + &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); + struct iwl4965_rate_scale_data *window = &(tbl->win[index]); + u32 sz = (sizeof(struct iwl4965_scale_tbl_info) - + (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT)); u8 start_action = tbl->action; for (;;) { - lq_data->action_counter++; + lq_sta->action_counter++; switch (tbl->action) { case IWL_SISO_SWITCH_ANTENNA: IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n"); search_tbl->lq_type = LQ_NONE; if (window->success_ratio >= IWL_RS_GOOD_RATIO) break; - if (!rs_is_other_ant_connected(lq_data->antenna, + if (!rs_is_other_ant_connected(lq_sta->antenna, tbl->antenna_type)) break; @@ -1139,7 +1305,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv, search_tbl->action = IWL_SISO_SWITCH_MIMO; rs_toggle_antenna(&(search_tbl->current_rate), search_tbl); - lq_data->search_better_tbl = 1; + lq_sta->search_better_tbl = 1; goto out; @@ -1150,13 +1316,12 @@ static int rs_move_siso_to_other(struct iwl_priv *priv, search_tbl->is_SGI = 0; search_tbl->is_fat = 0; search_tbl->antenna_type = ANT_BOTH; - rc = rs_switch_to_mimo(priv, lq_data, search_tbl, - index); - if (!rc) - lq_data->search_better_tbl = 1; - - if (!rc) + ret = rs_switch_to_mimo(priv, lq_sta, conf, sta, + search_tbl, index); + if (!ret) { + lq_sta->search_better_tbl = 1; goto out; + } break; case IWL_SISO_SWITCH_GI: IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n"); @@ -1168,17 +1333,17 @@ static int rs_move_siso_to_other(struct iwl_priv *priv, search_tbl->is_SGI = 1; else break; - lq_data->search_better_tbl = 1; + lq_sta->search_better_tbl = 1; if ((tbl->lq_type == LQ_SISO) && (tbl->is_SGI)) { - s32 tpt = lq_data->last_tpt / 100; + s32 tpt = lq_sta->last_tpt / 100; if (((!tbl->is_fat) && (tpt >= expected_tpt_siso20MHz[index])) || ((tbl->is_fat) && (tpt >= expected_tpt_siso40MHz[index]))) - lq_data->search_better_tbl = 0; + lq_sta->search_better_tbl = 0; } - rs_get_expected_tpt_table(lq_data, search_tbl); + rs_get_expected_tpt_table(lq_sta, search_tbl); rs_mcs_from_tbl(&search_tbl->current_rate, search_tbl, index, is_green); goto out; @@ -1199,26 +1364,33 @@ static int rs_move_siso_to_other(struct iwl_priv *priv, return 0; } -static int rs_move_mimo_to_other(struct iwl_priv *priv, - struct iwl_rate_scale_priv *lq_data, +/* + * Try to switch to new modulation mode from MIMO + */ +static int rs_move_mimo_to_other(struct iwl4965_priv *priv, + struct iwl4965_lq_sta *lq_sta, + struct ieee80211_conf *conf, + struct sta_info *sta, int index) { - int rc = -1; - s8 is_green = lq_data->is_green; - struct iwl_scale_tbl_info *tbl = - &(lq_data->lq_info[lq_data->active_tbl]); - struct iwl_scale_tbl_info *search_tbl = - &(lq_data->lq_info[(1 - lq_data->active_tbl)]); - u32 sz = (sizeof(struct iwl_scale_tbl_info) - - (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); + int ret; + s8 is_green = lq_sta->is_green; + struct iwl4965_scale_tbl_info *tbl = + &(lq_sta->lq_info[lq_sta->active_tbl]); + struct iwl4965_scale_tbl_info *search_tbl = + &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); + u32 sz = (sizeof(struct iwl4965_scale_tbl_info) - + (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT)); u8 start_action = tbl->action; for (;;) { - lq_data->action_counter++; + lq_sta->action_counter++; switch (tbl->action) { case IWL_MIMO_SWITCH_ANTENNA_A: case IWL_MIMO_SWITCH_ANTENNA_B: IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n"); + + /* Set up new search table for SISO */ memcpy(search_tbl, tbl, sz); search_tbl->lq_type = LQ_SISO; search_tbl->is_SGI = 0; @@ -1228,16 +1400,18 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv, else search_tbl->antenna_type = ANT_AUX; - rc = rs_switch_to_siso(priv, lq_data, search_tbl, - index); - if (!rc) { - lq_data->search_better_tbl = 1; + ret = rs_switch_to_siso(priv, lq_sta, conf, sta, + search_tbl, index); + if (!ret) { + lq_sta->search_better_tbl = 1; goto out; } break; case IWL_MIMO_SWITCH_GI: IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n"); + + /* Set up new search table for MIMO */ memcpy(search_tbl, tbl, sz); search_tbl->lq_type = LQ_MIMO; search_tbl->antenna_type = ANT_BOTH; @@ -1246,17 +1420,24 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv, search_tbl->is_SGI = 0; else search_tbl->is_SGI = 1; - lq_data->search_better_tbl = 1; + lq_sta->search_better_tbl = 1; + + /* + * If active table already uses the fastest possible + * modulation (dual stream with short guard interval), + * and it's working well, there's no need to look + * for a better type of modulation! + */ if ((tbl->lq_type == LQ_MIMO) && (tbl->is_SGI)) { - s32 tpt = lq_data->last_tpt / 100; + s32 tpt = lq_sta->last_tpt / 100; if (((!tbl->is_fat) && (tpt >= expected_tpt_mimo20MHz[index])) || ((tbl->is_fat) && (tpt >= expected_tpt_mimo40MHz[index]))) - lq_data->search_better_tbl = 0; + lq_sta->search_better_tbl = 0; } - rs_get_expected_tpt_table(lq_data, search_tbl); + rs_get_expected_tpt_table(lq_sta, search_tbl); rs_mcs_from_tbl(&search_tbl->current_rate, search_tbl, index, is_green); goto out; @@ -1279,43 +1460,71 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv, } -static void rs_stay_in_table(struct iwl_rate_scale_priv *lq_data) +/* + * Check whether we should continue using same modulation mode, or + * begin search for a new mode, based on: + * 1) # tx successes or failures while using this mode + * 2) # times calling this function + * 3) elapsed time in this mode (not used, for now) + */ +static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta) { - struct iwl_scale_tbl_info *tbl; + struct iwl4965_scale_tbl_info *tbl; int i; int active_tbl; int flush_interval_passed = 0; - active_tbl = lq_data->active_tbl; + active_tbl = lq_sta->active_tbl; - tbl = &(lq_data->lq_info[active_tbl]); + tbl = &(lq_sta->lq_info[active_tbl]); - if (lq_data->stay_in_tbl) { + /* If we've been disallowing search, see if we should now allow it */ + if (lq_sta->stay_in_tbl) { - if (lq_data->flush_timer) + /* Elapsed time using current modulation mode */ + if (lq_sta->flush_timer) flush_interval_passed = time_after(jiffies, - (unsigned long)(lq_data->flush_timer + + (unsigned long)(lq_sta->flush_timer + IWL_RATE_SCALE_FLUSH_INTVL)); + /* For now, disable the elapsed time criterion */ flush_interval_passed = 0; - if ((lq_data->total_failed > lq_data->max_failure_limit) || - (lq_data->total_success > lq_data->max_success_limit) || - ((!lq_data->search_better_tbl) && (lq_data->flush_timer) + + /* + * Check if we should allow search for new modulation mode. + * If many frames have failed or succeeded, or we've used + * this same modulation for a long time, allow search, and + * reset history stats that keep track of whether we should + * allow a new search. Also (below) reset all bitmaps and + * stats in active history. + */ + if ((lq_sta->total_failed > lq_sta->max_failure_limit) || + (lq_sta->total_success > lq_sta->max_success_limit) || + ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer) && (flush_interval_passed))) { IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:", - lq_data->total_failed, - lq_data->total_success, + lq_sta->total_failed, + lq_sta->total_success, flush_interval_passed); - lq_data->stay_in_tbl = 0; - lq_data->total_failed = 0; - lq_data->total_success = 0; - lq_data->flush_timer = 0; - } else if (lq_data->table_count > 0) { - lq_data->table_count++; - if (lq_data->table_count >= - lq_data->table_count_limit) { - lq_data->table_count = 0; + + /* Allow search for new mode */ + lq_sta->stay_in_tbl = 0; /* only place reset */ + lq_sta->total_failed = 0; + lq_sta->total_success = 0; + lq_sta->flush_timer = 0; + + /* + * Else if we've used this modulation mode enough repetitions + * (regardless of elapsed time or success/failure), reset + * history bitmaps and rate-specific stats for all rates in + * active table. + */ + } else { + lq_sta->table_count++; + if (lq_sta->table_count >= + lq_sta->table_count_limit) { + lq_sta->table_count = 0; IWL_DEBUG_HT("LQ: stay in table clear win\n"); for (i = 0; i < IWL_RATE_COUNT; i++) @@ -1324,23 +1533,32 @@ static void rs_stay_in_table(struct iwl_rate_scale_priv *lq_data) } } - if (!lq_data->stay_in_tbl) { + /* If transitioning to allow "search", reset all history + * bitmaps and stats in active table (this will become the new + * "search" table). */ + if (!lq_sta->stay_in_tbl) { for (i = 0; i < IWL_RATE_COUNT; i++) rs_rate_scale_clear_window(&(tbl->win[i])); } } } -static void rs_rate_scale_perform(struct iwl_priv *priv, +/* + * Do rate scaling and search for new modulation mode. + */ +static void rs_rate_scale_perform(struct iwl4965_priv *priv, struct net_device *dev, struct ieee80211_hdr *hdr, struct sta_info *sta) { + struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); + struct ieee80211_hw *hw = local_to_hw(local); + struct ieee80211_conf *conf = &hw->conf; int low = IWL_RATE_INVALID; int high = IWL_RATE_INVALID; int index; int i; - struct iwl_rate_scale_data *window = NULL; + struct iwl4965_rate_scale_data *window = NULL; int current_tpt = IWL_INVALID_VALUE; int low_tpt = IWL_INVALID_VALUE; int high_tpt = IWL_INVALID_VALUE; @@ -1348,10 +1566,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv, s8 scale_action = 0; u16 fc, rate_mask; u8 update_lq = 0; - struct iwl_rate_scale_priv *lq_data; - struct iwl_scale_tbl_info *tbl, *tbl1; + struct iwl4965_lq_sta *lq_sta; + struct iwl4965_scale_tbl_info *tbl, *tbl1; u16 rate_scale_index_msk = 0; - struct iwl_rate mcs_rate; + struct iwl4965_rate mcs_rate; u8 is_green = 0; u8 active_tbl = 0; u8 done_search = 0; @@ -1374,34 +1592,42 @@ static void rs_rate_scale_perform(struct iwl_priv *priv, IWL_DEBUG_RATE("still rate scaling not ready\n"); return; } - lq_data = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv; + lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv; - if (!lq_data->search_better_tbl) - active_tbl = lq_data->active_tbl; + /* + * Select rate-scale / modulation-mode table to work with in + * the rest of this function: "search" if searching for better + * modulation mode, or "active" if doing rate scaling within a mode. + */ + if (!lq_sta->search_better_tbl) + active_tbl = lq_sta->active_tbl; else - active_tbl = 1 - lq_data->active_tbl; + active_tbl = 1 - lq_sta->active_tbl; - tbl = &(lq_data->lq_info[active_tbl]); - is_green = lq_data->is_green; + tbl = &(lq_sta->lq_info[active_tbl]); + is_green = lq_sta->is_green; + /* current tx rate */ index = sta->last_txrate; IWL_DEBUG_RATE("Rate scale index %d for type %d\n", index, tbl->lq_type); - rs_get_supported_rates(lq_data, hdr, tbl->lq_type, + /* rates available for this association, and for modulation mode */ + rs_get_supported_rates(lq_sta, hdr, tbl->lq_type, &rate_mask); IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask); /* mask with station rate restriction */ if (is_legacy(tbl->lq_type)) { - if (lq_data->phymode == (u8) MODE_IEEE80211A) + if (lq_sta->phymode == (u8) MODE_IEEE80211A) + /* supp_rates has no CCK bits in A mode */ rate_scale_index_msk = (u16) (rate_mask & - (lq_data->supp_rates << IWL_FIRST_OFDM_RATE)); + (lq_sta->supp_rates << IWL_FIRST_OFDM_RATE)); else rate_scale_index_msk = (u16) (rate_mask & - lq_data->supp_rates); + lq_sta->supp_rates); } else rate_scale_index_msk = rate_mask; @@ -1409,11 +1635,13 @@ static void rs_rate_scale_perform(struct iwl_priv *priv, if (!rate_scale_index_msk) rate_scale_index_msk = rate_mask; + /* If current rate is no longer supported on current association, + * or user changed preferences for rates, find a new supported rate. */ if (index < 0 || !((1 << index) & rate_scale_index_msk)) { index = IWL_INVALID_VALUE; update_lq = 1; - /* get the lowest availabe rate */ + /* get the highest available rate */ for (i = 0; i <= IWL_RATE_COUNT; i++) { if ((1 << i) & rate_scale_index_msk) index = i; @@ -1425,11 +1653,19 @@ static void rs_rate_scale_perform(struct iwl_priv *priv, } } + /* Get expected throughput table and history window for current rate */ if (!tbl->expected_tpt) - rs_get_expected_tpt_table(lq_data, tbl); + rs_get_expected_tpt_table(lq_sta, tbl); window = &(tbl->win[index]); + /* + * If there is not enough history to calculate actual average + * throughput, keep analyzing results of more tx frames, without + * changing rate or mode (bypass most of the rest of this function). + * Set up new rate table in uCode only if old rate is not supported + * in current association (use new rate found above). + */ fail_count = window->counter - window->success_counter; if (((fail_count < IWL_RATE_MIN_FAILURE_TH) && (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) @@ -1437,82 +1673,118 @@ static void rs_rate_scale_perform(struct iwl_priv *priv, IWL_DEBUG_RATE("LQ: still below TH succ %d total %d " "for index %d\n", window->success_counter, window->counter, index); + + /* Can't calculate this yet; not enough history */ window->average_tpt = IWL_INVALID_VALUE; - rs_stay_in_table(lq_data); + + /* Should we stay with this modulation mode, + * or search for a new one? */ + rs_stay_in_table(lq_sta); + + /* Set up new rate table in uCode, if needed */ if (update_lq) { rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green); - rs_fill_link_cmd(lq_data, &mcs_rate, &lq_data->lq); - rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC); + rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq); + rs_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); } goto out; + /* Else we have enough samples; calculate estimate of + * actual average throughput */ } else window->average_tpt = ((window->success_ratio * tbl->expected_tpt[index] + 64) / 128); - if (lq_data->search_better_tbl) { + /* If we are searching for better modulation mode, check success. */ + if (lq_sta->search_better_tbl) { int success_limit = IWL_RATE_SCALE_SWITCH; + /* If good success, continue using the "search" mode; + * no need to send new link quality command, since we're + * continuing to use the setup that we've been trying. */ if ((window->success_ratio > success_limit) || - (window->average_tpt > lq_data->last_tpt)) { + (window->average_tpt > lq_sta->last_tpt)) { if (!is_legacy(tbl->lq_type)) { IWL_DEBUG_HT("LQ: we are switching to HT" " rate suc %d current tpt %d" " old tpt %d\n", window->success_ratio, window->average_tpt, - lq_data->last_tpt); - lq_data->enable_counter = 1; + lq_sta->last_tpt); + lq_sta->enable_counter = 1; } - lq_data->active_tbl = active_tbl; + /* Swap tables; "search" becomes "active" */ + lq_sta->active_tbl = active_tbl; current_tpt = window->average_tpt; + + /* Else poor success; go back to mode in "active" table */ } else { + /* Nullify "search" table */ tbl->lq_type = LQ_NONE; - active_tbl = lq_data->active_tbl; - tbl = &(lq_data->lq_info[active_tbl]); - index = iwl_rate_index_from_plcp( + /* Revert to "active" table */ + active_tbl = lq_sta->active_tbl; + tbl = &(lq_sta->lq_info[active_tbl]); + + /* Revert to "active" rate and throughput info */ + index = iwl4965_rate_index_from_plcp( tbl->current_rate.rate_n_flags); + current_tpt = lq_sta->last_tpt; + /* Need to set up a new rate table in uCode */ update_lq = 1; - current_tpt = lq_data->last_tpt; IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n"); } - lq_data->search_better_tbl = 0; - done_search = 1; + + /* Either way, we've made a decision; modulation mode + * search is done, allow rate adjustment next time. */ + lq_sta->search_better_tbl = 0; + done_search = 1; /* Don't switch modes below! */ goto lq_update; } + /* (Else) not in search of better modulation mode, try for better + * starting rate, while staying in this mode. */ high_low = rs_get_adjacent_rate(index, rate_scale_index_msk, tbl->lq_type); low = high_low & 0xff; high = (high_low >> 8) & 0xff; + /* Collect measured throughputs for current and adjacent rates */ current_tpt = window->average_tpt; - if (low != IWL_RATE_INVALID) low_tpt = tbl->win[low].average_tpt; - if (high != IWL_RATE_INVALID) high_tpt = tbl->win[high].average_tpt; - + /* Assume rate increase */ scale_action = 1; + /* Too many failures, decrease rate */ if ((window->success_ratio <= IWL_RATE_DECREASE_TH) || (current_tpt == 0)) { IWL_DEBUG_RATE("decrease rate because of low success_ratio\n"); scale_action = -1; + + /* No throughput measured yet for adjacent rates; try increase. */ } else if ((low_tpt == IWL_INVALID_VALUE) && (high_tpt == IWL_INVALID_VALUE)) scale_action = 1; + + /* Both adjacent throughputs are measured, but neither one has better + * throughput; we're using the best rate, don't change it! */ else if ((low_tpt != IWL_INVALID_VALUE) && (high_tpt != IWL_INVALID_VALUE) && (low_tpt < current_tpt) && (high_tpt < current_tpt)) scale_action = 0; + + /* At least one adjacent rate's throughput is measured, + * and may have better performance. */ else { + /* Higher adjacent rate's throughput is measured */ if (high_tpt != IWL_INVALID_VALUE) { + /* Higher rate has better throughput */ if (high_tpt > current_tpt) scale_action = 1; else { @@ -1520,7 +1792,10 @@ static void rs_rate_scale_perform(struct iwl_priv *priv, ("decrease rate because of high tpt\n"); scale_action = -1; } + + /* Lower adjacent rate's throughput is measured */ } else if (low_tpt != IWL_INVALID_VALUE) { + /* Lower rate has better throughput */ if (low_tpt > current_tpt) { IWL_DEBUG_RATE ("decrease rate because of low tpt\n"); @@ -1530,23 +1805,30 @@ static void rs_rate_scale_perform(struct iwl_priv *priv, } } + /* Sanity check; asked for decrease, but success rate or throughput + * has been good at old rate. Don't change it. */ if (scale_action == -1) { if ((low != IWL_RATE_INVALID) && ((window->success_ratio > IWL_RATE_HIGH_TH) || (current_tpt > (100 * tbl->expected_tpt[low])))) scale_action = 0; + + /* Sanity check; asked for increase, but success rate has not been great + * even at old rate, higher rate will be worse. Don't change it. */ } else if ((scale_action == 1) && (window->success_ratio < IWL_RATE_INCREASE_TH)) scale_action = 0; switch (scale_action) { case -1: + /* Decrease starting rate, update uCode's rate table */ if (low != IWL_RATE_INVALID) { update_lq = 1; index = low; } break; case 1: + /* Increase starting rate, update uCode's rate table */ if (high != IWL_RATE_INVALID) { update_lq = 1; index = high; @@ -1554,6 +1836,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv, break; case 0: + /* No change */ default: break; } @@ -1563,65 +1846,97 @@ static void rs_rate_scale_perform(struct iwl_priv *priv, index, scale_action, low, high, tbl->lq_type); lq_update: + /* Replace uCode's rate table for the destination station. */ if (update_lq) { rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green); - rs_fill_link_cmd(lq_data, &mcs_rate, &lq_data->lq); - rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC); + rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq); + rs_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); } - rs_stay_in_table(lq_data); - if (!update_lq && !done_search && !lq_data->stay_in_tbl) { - lq_data->last_tpt = current_tpt; + /* Should we stay with this modulation mode, or search for a new one? */ + rs_stay_in_table(lq_sta); + /* + * Search for new modulation mode if we're: + * 1) Not changing rates right now + * 2) Not just finishing up a search + * 3) Allowing a new search + */ + if (!update_lq && !done_search && !lq_sta->stay_in_tbl) { + /* Save current throughput to compare with "search" throughput*/ + lq_sta->last_tpt = current_tpt; + + /* Select a new "search" modulation mode to try. + * If one is found, set up the new "search" table. */ if (is_legacy(tbl->lq_type)) - rs_move_legacy_other(priv, lq_data, index); + rs_move_legacy_other(priv, lq_sta, conf, sta, index); else if (is_siso(tbl->lq_type)) - rs_move_siso_to_other(priv, lq_data, index); + rs_move_siso_to_other(priv, lq_sta, conf, sta, index); else - rs_move_mimo_to_other(priv, lq_data, index); + rs_move_mimo_to_other(priv, lq_sta, conf, sta, index); - if (lq_data->search_better_tbl) { - tbl = &(lq_data->lq_info[(1 - lq_data->active_tbl)]); + /* If new "search" mode was selected, set up in uCode table */ + if (lq_sta->search_better_tbl) { + /* Access the "search" table, clear its history. */ + tbl = &(lq_sta->lq_info[(1 - lq_sta->active_tbl)]); for (i = 0; i < IWL_RATE_COUNT; i++) rs_rate_scale_clear_window(&(tbl->win[i])); - index = iwl_rate_index_from_plcp( + /* Use new "search" start rate */ + index = iwl4965_rate_index_from_plcp( tbl->current_rate.rate_n_flags); IWL_DEBUG_HT("Switch current mcs: %X index: %d\n", tbl->current_rate.rate_n_flags, index); - rs_fill_link_cmd(lq_data, &tbl->current_rate, - &lq_data->lq); - rs_send_lq_cmd(priv, &lq_data->lq, CMD_ASYNC); + rs_fill_link_cmd(lq_sta, &tbl->current_rate, + &lq_sta->lq); + rs_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); } - tbl1 = &(lq_data->lq_info[lq_data->active_tbl]); + /* If the "active" (non-search) mode was legacy, + * and we've tried switching antennas, + * but we haven't been able to try HT modes (not available), + * stay with best antenna legacy modulation for a while + * before next round of mode comparisons. */ + tbl1 = &(lq_sta->lq_info[lq_sta->active_tbl]); if (is_legacy(tbl1->lq_type) && -#ifdef CONFIG_IWLWIFI_HT - !priv->current_assoc_ht.is_ht && +#ifdef CONFIG_IWL4965_HT + (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) && #endif - (lq_data->action_counter >= 1)) { - lq_data->action_counter = 0; + (lq_sta->action_counter >= 1)) { + lq_sta->action_counter = 0; IWL_DEBUG_HT("LQ: STAY in legacy table\n"); - rs_set_stay_in_table(1, lq_data); + rs_set_stay_in_table(1, lq_sta); } - if (lq_data->enable_counter && - (lq_data->action_counter >= IWL_ACTION_LIMIT)) { -#ifdef CONFIG_IWLWIFI_HT_AGG - if ((lq_data->last_tpt > TID_AGG_TPT_THREHOLD) && + /* If we're in an HT mode, and all 3 mode switch actions + * have been tried and compared, stay in this best modulation + * mode for a while before next round of mode comparisons. */ + if (lq_sta->enable_counter && + (lq_sta->action_counter >= IWL_ACTION_LIMIT)) { +#ifdef CONFIG_IWL4965_HT_AGG + /* If appropriate, set up aggregation! */ + if ((lq_sta->last_tpt > TID_AGG_TPT_THREHOLD) && (priv->lq_mngr.agg_ctrl.auto_agg)) { priv->lq_mngr.agg_ctrl.tid_retry = TID_ALL_SPECIFIED; schedule_work(&priv->agg_work); } -#endif /*CONFIG_IWLWIFI_HT_AGG */ - lq_data->action_counter = 0; - rs_set_stay_in_table(0, lq_data); +#endif /*CONFIG_IWL4965_HT_AGG */ + lq_sta->action_counter = 0; + rs_set_stay_in_table(0, lq_sta); } + + /* + * Else, don't search for a new modulation mode. + * Put new timestamp in stay-in-modulation-mode flush timer if: + * 1) Not changing rates right now + * 2) Not just finishing up a search + * 3) flush timer is empty + */ } else { - if ((!update_lq) && (!done_search) && (!lq_data->flush_timer)) - lq_data->flush_timer = jiffies; + if ((!update_lq) && (!done_search) && (!lq_sta->flush_timer)) + lq_sta->flush_timer = jiffies; } out: @@ -1632,7 +1947,7 @@ out: /* sta->txrate is an index to A mode rates which start * at IWL_FIRST_OFDM_RATE */ - if (lq_data->phymode == (u8) MODE_IEEE80211A) + if (lq_sta->phymode == (u8) MODE_IEEE80211A) sta->txrate = i - IWL_FIRST_OFDM_RATE; else sta->txrate = i; @@ -1641,38 +1956,39 @@ out: } -static void rs_initialize_lq(struct iwl_priv *priv, +static void rs_initialize_lq(struct iwl4965_priv *priv, + struct ieee80211_conf *conf, struct sta_info *sta) { int i; - struct iwl_rate_scale_priv *lq; - struct iwl_scale_tbl_info *tbl; + struct iwl4965_lq_sta *lq_sta; + struct iwl4965_scale_tbl_info *tbl; u8 active_tbl = 0; int rate_idx; - u8 use_green = rs_use_green(priv); - struct iwl_rate mcs_rate; + u8 use_green = rs_use_green(priv, conf); + struct iwl4965_rate mcs_rate; if (!sta || !sta->rate_ctrl_priv) goto out; - lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv; + lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv; i = sta->last_txrate; - if ((lq->lq.sta_id == 0xff) && + if ((lq_sta->lq.sta_id == 0xff) && (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)) goto out; - if (!lq->search_better_tbl) - active_tbl = lq->active_tbl; + if (!lq_sta->search_better_tbl) + active_tbl = lq_sta->active_tbl; else - active_tbl = 1 - lq->active_tbl; + active_tbl = 1 - lq_sta->active_tbl; - tbl = &(lq->lq_info[active_tbl]); + tbl = &(lq_sta->lq_info[active_tbl]); if ((i < 0) || (i >= IWL_RATE_COUNT)) i = 0; - mcs_rate.rate_n_flags = iwl_rates[i].plcp ; + mcs_rate.rate_n_flags = iwl4965_rates[i].plcp ; mcs_rate.rate_n_flags |= RATE_MCS_ANT_B_MSK; mcs_rate.rate_n_flags &= ~RATE_MCS_ANT_A_MSK; @@ -1686,114 +2002,95 @@ static void rs_initialize_lq(struct iwl_priv *priv, rs_mcs_from_tbl(&mcs_rate, tbl, rate_idx, use_green); tbl->current_rate.rate_n_flags = mcs_rate.rate_n_flags; - rs_get_expected_tpt_table(lq, tbl); - rs_fill_link_cmd(lq, &mcs_rate, &lq->lq); - rs_send_lq_cmd(priv, &lq->lq, CMD_ASYNC); + rs_get_expected_tpt_table(lq_sta, tbl); + rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq); + rs_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); out: return; } -static struct ieee80211_rate *rs_get_lowest_rate(struct ieee80211_local - *local) -{ - struct ieee80211_hw_mode *mode = local->oper_hw_mode; - int i; - - for (i = 0; i < mode->num_rates; i++) { - struct ieee80211_rate *rate = &mode->rates[i]; - - if (rate->flags & IEEE80211_RATE_SUPPORTED) - return rate; - } - - return &mode->rates[0]; -} - -static struct ieee80211_rate *rs_get_rate(void *priv_rate, - struct net_device *dev, - struct sk_buff *skb, - struct rate_control_extra - *extra) +static void rs_get_rate(void *priv_rate, struct net_device *dev, + struct ieee80211_hw_mode *mode, struct sk_buff *skb, + struct rate_selection *sel) { int i; struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); + struct ieee80211_conf *conf = &local->hw.conf; struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; struct sta_info *sta; u16 fc; - struct iwl_priv *priv = (struct iwl_priv *)priv_rate; - struct iwl_rate_scale_priv *lq; + struct iwl4965_priv *priv = (struct iwl4965_priv *)priv_rate; + struct iwl4965_lq_sta *lq_sta; IWL_DEBUG_RATE_LIMIT("rate scale calculate new rate for skb\n"); - memset(extra, 0, sizeof(*extra)); - - fc = le16_to_cpu(hdr->frame_control); - if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1)) { - /* Send management frames and broadcast/multicast data using - * lowest rate. */ - /* TODO: this could probably be improved.. */ - return rs_get_lowest_rate(local); - } - sta = sta_info_get(local, hdr->addr1); - if (!sta || !sta->rate_ctrl_priv) { + /* Send management frames and broadcast/multicast data using lowest + * rate. */ + fc = le16_to_cpu(hdr->frame_control); + if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1) || + !sta || !sta->rate_ctrl_priv) { + sel->rate = rate_lowest(local, local->oper_hw_mode, sta); if (sta) sta_info_put(sta); - return rs_get_lowest_rate(local); + return; } - lq = (struct iwl_rate_scale_priv *)sta->rate_ctrl_priv; + lq_sta = (struct iwl4965_lq_sta *)sta->rate_ctrl_priv; i = sta->last_txrate; - if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && !lq->ibss_sta_added) { - u8 sta_id = iwl_hw_find_station(priv, hdr->addr1); + if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && + !lq_sta->ibss_sta_added) { + u8 sta_id = iwl4965_hw_find_station(priv, hdr->addr1); DECLARE_MAC_BUF(mac); if (sta_id == IWL_INVALID_STATION) { IWL_DEBUG_RATE("LQ: ADD station %s\n", print_mac(mac, hdr->addr1)); - sta_id = iwl_add_station(priv, - hdr->addr1, 0, CMD_ASYNC); + sta_id = iwl4965_add_station_flags(priv, hdr->addr1, + 0, CMD_ASYNC, NULL); } if ((sta_id != IWL_INVALID_STATION)) { - lq->lq.sta_id = sta_id; - lq->lq.rs_table[0].rate_n_flags = 0; - lq->ibss_sta_added = 1; - rs_initialize_lq(priv, sta); + lq_sta->lq.sta_id = sta_id; + lq_sta->lq.rs_table[0].rate_n_flags = 0; + lq_sta->ibss_sta_added = 1; + rs_initialize_lq(priv, conf, sta); } - if (!lq->ibss_sta_added) + if (!lq_sta->ibss_sta_added) goto done; } done: + if ((i < 0) || (i > IWL_RATE_COUNT)) { + sel->rate = rate_lowest(local, local->oper_hw_mode, sta); + return; + } sta_info_put(sta); - if ((i < 0) || (i > IWL_RATE_COUNT)) - return rs_get_lowest_rate(local); - return &priv->ieee_rates[i]; + sel->rate = &priv->ieee_rates[i]; } static void *rs_alloc_sta(void *priv, gfp_t gfp) { - struct iwl_rate_scale_priv *crl; + struct iwl4965_lq_sta *lq_sta; int i, j; IWL_DEBUG_RATE("create station rate scale window\n"); - crl = kzalloc(sizeof(struct iwl_rate_scale_priv), gfp); + lq_sta = kzalloc(sizeof(struct iwl4965_lq_sta), gfp); - if (crl == NULL) + if (lq_sta == NULL) return NULL; - crl->lq.sta_id = 0xff; + lq_sta->lq.sta_id = 0xff; for (j = 0; j < LQ_SIZE; j++) for (i = 0; i < IWL_RATE_COUNT; i++) - rs_rate_scale_clear_window(&(crl->lq_info[j].win[i])); + rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i])); - return crl; + return lq_sta; } static void rs_rate_init(void *priv_rate, void *priv_sta, @@ -1801,16 +2098,17 @@ static void rs_rate_init(void *priv_rate, void *priv_sta, struct sta_info *sta) { int i, j; + struct ieee80211_conf *conf = &local->hw.conf; struct ieee80211_hw_mode *mode = local->oper_hw_mode; - struct iwl_priv *priv = (struct iwl_priv *)priv_rate; - struct iwl_rate_scale_priv *crl = priv_sta; + struct iwl4965_priv *priv = (struct iwl4965_priv *)priv_rate; + struct iwl4965_lq_sta *lq_sta = priv_sta; - crl->flush_timer = 0; - crl->supp_rates = sta->supp_rates; + lq_sta->flush_timer = 0; + lq_sta->supp_rates = sta->supp_rates; sta->txrate = 3; for (j = 0; j < LQ_SIZE; j++) for (i = 0; i < IWL_RATE_COUNT; i++) - rs_rate_scale_clear_window(&(crl->lq_info[j].win[i])); + rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i])); IWL_DEBUG_RATE("rate scale global init\n"); /* TODO: what is a good starting rate for STA? About middle? Maybe not @@ -1818,9 +2116,9 @@ static void rs_rate_init(void *priv_rate, void *priv_sta, * previous packets? Need to have IEEE 802.1X auth succeed immediately * after assoc.. */ - crl->ibss_sta_added = 0; + lq_sta->ibss_sta_added = 0; if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { - u8 sta_id = iwl_hw_find_station(priv, sta->addr); + u8 sta_id = iwl4965_hw_find_station(priv, sta->addr); DECLARE_MAC_BUF(mac); /* for IBSS the call are from tasklet */ @@ -1830,77 +2128,89 @@ static void rs_rate_init(void *priv_rate, void *priv_sta, if (sta_id == IWL_INVALID_STATION) { IWL_DEBUG_RATE("LQ: ADD station %s\n", print_mac(mac, sta->addr)); - sta_id = iwl_add_station(priv, - sta->addr, 0, CMD_ASYNC); + sta_id = iwl4965_add_station_flags(priv, sta->addr, + 0, CMD_ASYNC, NULL); } if ((sta_id != IWL_INVALID_STATION)) { - crl->lq.sta_id = sta_id; - crl->lq.rs_table[0].rate_n_flags = 0; + lq_sta->lq.sta_id = sta_id; + lq_sta->lq.rs_table[0].rate_n_flags = 0; } /* FIXME: this is w/a remove it later */ priv->assoc_station_added = 1; } + /* Find highest tx rate supported by hardware and destination station */ for (i = 0; i < mode->num_rates; i++) { if ((sta->supp_rates & BIT(i)) && (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED)) sta->txrate = i; } sta->last_txrate = sta->txrate; - /* For MODE_IEEE80211A mode cck rate are at end - * rate table - */ + /* For MODE_IEEE80211A, cck rates are at end of rate table */ if (local->hw.conf.phymode == MODE_IEEE80211A) sta->last_txrate += IWL_FIRST_OFDM_RATE; - crl->is_dup = priv->is_dup; - crl->valid_antenna = priv->valid_antenna; - crl->antenna = priv->antenna; - crl->is_green = rs_use_green(priv); - crl->active_rate = priv->active_rate; - crl->active_rate &= ~(0x1000); - crl->active_rate_basic = priv->active_rate_basic; - crl->phymode = priv->phymode; -#ifdef CONFIG_IWLWIFI_HT - crl->active_siso_rate = (priv->current_assoc_ht.supp_rates[0] << 1); - crl->active_siso_rate |= (priv->current_assoc_ht.supp_rates[0] & 0x1); - crl->active_siso_rate &= ~((u16)0x2); - crl->active_siso_rate = crl->active_siso_rate << IWL_FIRST_OFDM_RATE; - - crl->active_mimo_rate = (priv->current_assoc_ht.supp_rates[1] << 1); - crl->active_mimo_rate |= (priv->current_assoc_ht.supp_rates[1] & 0x1); - crl->active_mimo_rate &= ~((u16)0x2); - crl->active_mimo_rate = crl->active_mimo_rate << IWL_FIRST_OFDM_RATE; - IWL_DEBUG_HT("MIMO RATE 0x%X SISO MASK 0x%X\n", crl->active_siso_rate, - crl->active_mimo_rate); -#endif /*CONFIG_IWLWIFI_HT*/ + lq_sta->is_dup = 0; + lq_sta->valid_antenna = priv->valid_antenna; + lq_sta->antenna = priv->antenna; + lq_sta->is_green = rs_use_green(priv, conf); + lq_sta->active_rate = priv->active_rate; + lq_sta->active_rate &= ~(0x1000); + lq_sta->active_rate_basic = priv->active_rate_basic; + lq_sta->phymode = priv->phymode; +#ifdef CONFIG_IWL4965_HT + /* + * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3), + * supp_rates[] does not; shift to convert format, force 9 MBits off. + */ + lq_sta->active_siso_rate = (priv->current_ht_config.supp_mcs_set[0] << 1); + lq_sta->active_siso_rate |= + (priv->current_ht_config.supp_mcs_set[0] & 0x1); + lq_sta->active_siso_rate &= ~((u16)0x2); + lq_sta->active_siso_rate = + lq_sta->active_siso_rate << IWL_FIRST_OFDM_RATE; + + /* Same here */ + lq_sta->active_mimo_rate = (priv->current_ht_config.supp_mcs_set[1] << 1); + lq_sta->active_mimo_rate |= + (priv->current_ht_config.supp_mcs_set[1] & 0x1); + lq_sta->active_mimo_rate &= ~((u16)0x2); + lq_sta->active_mimo_rate = + lq_sta->active_mimo_rate << IWL_FIRST_OFDM_RATE; + IWL_DEBUG_HT("SISO RATE 0x%X MIMO RATE 0x%X\n", + lq_sta->active_siso_rate, + lq_sta->active_mimo_rate); +#endif /*CONFIG_IWL4965_HT*/ #ifdef CONFIG_MAC80211_DEBUGFS - crl->drv = priv; + lq_sta->drv = priv; #endif if (priv->assoc_station_added) priv->lq_mngr.lq_ready = 1; - rs_initialize_lq(priv, sta); + rs_initialize_lq(priv, conf, sta); } -static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data, - struct iwl_rate *tx_mcs, - struct iwl_link_quality_cmd *lq_cmd) +static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta, + struct iwl4965_rate *tx_mcs, + struct iwl4965_link_quality_cmd *lq_cmd) { int index = 0; int rate_idx; int repeat_rate = 0; u8 ant_toggle_count = 0; u8 use_ht_possible = 1; - struct iwl_rate new_rate; - struct iwl_scale_tbl_info tbl_type = { 0 }; + struct iwl4965_rate new_rate; + struct iwl4965_scale_tbl_info tbl_type = { 0 }; - rs_dbgfs_set_mcs(lq_data, tx_mcs, index); + /* Override starting rate (index 0) if needed for debug purposes */ + rs_dbgfs_set_mcs(lq_sta, tx_mcs, index); - rs_get_tbl_info_from_mcs(tx_mcs, lq_data->phymode, + /* Interpret rate_n_flags */ + rs_get_tbl_info_from_mcs(tx_mcs, lq_sta->phymode, &tbl_type, &rate_idx); + /* How many times should we repeat the initial rate? */ if (is_legacy(tbl_type.lq_type)) { ant_toggle_count = 1; repeat_rate = IWL_NUMBER_TRY; @@ -1909,19 +2219,27 @@ static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data, lq_cmd->general_params.mimo_delimiter = is_mimo(tbl_type.lq_type) ? 1 : 0; + + /* Fill 1st table entry (index 0) */ lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(tx_mcs->rate_n_flags); new_rate.rate_n_flags = tx_mcs->rate_n_flags; if (is_mimo(tbl_type.lq_type) || (tbl_type.antenna_type == ANT_MAIN)) - lq_cmd->general_params.single_stream_ant_msk = 1; + lq_cmd->general_params.single_stream_ant_msk + = LINK_QUAL_ANT_A_MSK; else - lq_cmd->general_params.single_stream_ant_msk = 2; + lq_cmd->general_params.single_stream_ant_msk + = LINK_QUAL_ANT_B_MSK; index++; repeat_rate--; + /* Fill rest of rate table */ while (index < LINK_QUAL_MAX_RETRY_NUM) { + /* Repeat initial/next rate. + * For legacy IWL_NUMBER_TRY == 1, this loop will not execute. + * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */ while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) { if (is_legacy(tbl_type.lq_type)) { if (ant_toggle_count < @@ -1933,22 +2251,30 @@ static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data, } } - rs_dbgfs_set_mcs(lq_data, &new_rate, index); + /* Override next rate if needed for debug purposes */ + rs_dbgfs_set_mcs(lq_sta, &new_rate, index); + + /* Fill next table entry */ lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate.rate_n_flags); repeat_rate--; index++; } - rs_get_tbl_info_from_mcs(&new_rate, lq_data->phymode, &tbl_type, + rs_get_tbl_info_from_mcs(&new_rate, lq_sta->phymode, &tbl_type, &rate_idx); + /* Indicate to uCode which entries might be MIMO. + * If initial rate was MIMO, this will finally end up + * as (IWL_HT_NUMBER_TRY * 2), after 2nd pass, otherwise 0. */ if (is_mimo(tbl_type.lq_type)) lq_cmd->general_params.mimo_delimiter = index; - rs_get_lower_rate(lq_data, &tbl_type, rate_idx, + /* Get next rate */ + rs_get_lower_rate(lq_sta, &tbl_type, rate_idx, use_ht_possible, &new_rate); + /* How many times should we repeat the next rate? */ if (is_legacy(tbl_type.lq_type)) { if (ant_toggle_count < NUM_TRY_BEFORE_ANTENNA_TOGGLE) ant_toggle_count++; @@ -1960,9 +2286,14 @@ static void rs_fill_link_cmd(struct iwl_rate_scale_priv *lq_data, } else repeat_rate = IWL_HT_NUMBER_TRY; + /* Don't allow HT rates after next pass. + * rs_get_lower_rate() will change type to LQ_A or LQ_G. */ use_ht_possible = 0; - rs_dbgfs_set_mcs(lq_data, &new_rate, index); + /* Override next rate if needed for debug purposes */ + rs_dbgfs_set_mcs(lq_sta, &new_rate, index); + + /* Fill next table entry */ lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate.rate_n_flags); @@ -1987,27 +2318,27 @@ static void rs_free(void *priv_rate) static void rs_clear(void *priv_rate) { - struct iwl_priv *priv = (struct iwl_priv *) priv_rate; + struct iwl4965_priv *priv = (struct iwl4965_priv *) priv_rate; IWL_DEBUG_RATE("enter\n"); priv->lq_mngr.lq_ready = 0; -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG if (priv->lq_mngr.agg_ctrl.granted_ba) iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED); -#endif /*CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ +#endif /*CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ IWL_DEBUG_RATE("leave\n"); } static void rs_free_sta(void *priv, void *priv_sta) { - struct iwl_rate_scale_priv *rs_priv = priv_sta; + struct iwl4965_lq_sta *lq_sta = priv_sta; IWL_DEBUG_RATE("enter\n"); - kfree(rs_priv); + kfree(lq_sta); IWL_DEBUG_RATE("leave\n"); } @@ -2018,19 +2349,19 @@ static int open_file_generic(struct inode *inode, struct file *file) file->private_data = inode->i_private; return 0; } -static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv, - struct iwl_rate *mcs, int index) +static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta, + struct iwl4965_rate *mcs, int index) { u32 base_rate; - if (rs_priv->phymode == (u8) MODE_IEEE80211A) + if (lq_sta->phymode == (u8) MODE_IEEE80211A) base_rate = 0x800D; else base_rate = 0x820A; - if (rs_priv->dbg_fixed.rate_n_flags) { + if (lq_sta->dbg_fixed.rate_n_flags) { if (index < 12) - mcs->rate_n_flags = rs_priv->dbg_fixed.rate_n_flags; + mcs->rate_n_flags = lq_sta->dbg_fixed.rate_n_flags; else mcs->rate_n_flags = base_rate; IWL_DEBUG_RATE("Fixed rate ON\n"); @@ -2043,7 +2374,7 @@ static void rs_dbgfs_set_mcs(struct iwl_rate_scale_priv *rs_priv, static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { - struct iwl_rate_scale_priv *rs_priv = file->private_data; + struct iwl4965_lq_sta *lq_sta = file->private_data; char buf[64]; int buf_size; u32 parsed_rate; @@ -2054,20 +2385,20 @@ static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file, return -EFAULT; if (sscanf(buf, "%x", &parsed_rate) == 1) - rs_priv->dbg_fixed.rate_n_flags = parsed_rate; + lq_sta->dbg_fixed.rate_n_flags = parsed_rate; else - rs_priv->dbg_fixed.rate_n_flags = 0; + lq_sta->dbg_fixed.rate_n_flags = 0; - rs_priv->active_rate = 0x0FFF; - rs_priv->active_siso_rate = 0x1FD0; - rs_priv->active_mimo_rate = 0x1FD0; + lq_sta->active_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */ + lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ + lq_sta->active_mimo_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ IWL_DEBUG_RATE("sta_id %d rate 0x%X\n", - rs_priv->lq.sta_id, rs_priv->dbg_fixed.rate_n_flags); + lq_sta->lq.sta_id, lq_sta->dbg_fixed.rate_n_flags); - if (rs_priv->dbg_fixed.rate_n_flags) { - rs_fill_link_cmd(rs_priv, &rs_priv->dbg_fixed, &rs_priv->lq); - rs_send_lq_cmd(rs_priv->drv, &rs_priv->lq, CMD_ASYNC); + if (lq_sta->dbg_fixed.rate_n_flags) { + rs_fill_link_cmd(lq_sta, &lq_sta->dbg_fixed, &lq_sta->lq); + rs_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC); } return count; @@ -2080,38 +2411,38 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file, int desc = 0; int i = 0; - struct iwl_rate_scale_priv *rs_priv = file->private_data; + struct iwl4965_lq_sta *lq_sta = file->private_data; - desc += sprintf(buff+desc, "sta_id %d\n", rs_priv->lq.sta_id); + desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id); desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n", - rs_priv->total_failed, rs_priv->total_success, - rs_priv->active_rate); + lq_sta->total_failed, lq_sta->total_success, + lq_sta->active_rate); desc += sprintf(buff+desc, "fixed rate 0x%X\n", - rs_priv->dbg_fixed.rate_n_flags); + lq_sta->dbg_fixed.rate_n_flags); desc += sprintf(buff+desc, "general:" "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n", - rs_priv->lq.general_params.flags, - rs_priv->lq.general_params.mimo_delimiter, - rs_priv->lq.general_params.single_stream_ant_msk, - rs_priv->lq.general_params.dual_stream_ant_msk); + lq_sta->lq.general_params.flags, + lq_sta->lq.general_params.mimo_delimiter, + lq_sta->lq.general_params.single_stream_ant_msk, + lq_sta->lq.general_params.dual_stream_ant_msk); desc += sprintf(buff+desc, "agg:" "time_limit=%d dist_start_th=%d frame_cnt_limit=%d\n", - le16_to_cpu(rs_priv->lq.agg_params.agg_time_limit), - rs_priv->lq.agg_params.agg_dis_start_th, - rs_priv->lq.agg_params.agg_frame_cnt_limit); + le16_to_cpu(lq_sta->lq.agg_params.agg_time_limit), + lq_sta->lq.agg_params.agg_dis_start_th, + lq_sta->lq.agg_params.agg_frame_cnt_limit); desc += sprintf(buff+desc, "Start idx [0]=0x%x [1]=0x%x [2]=0x%x [3]=0x%x\n", - rs_priv->lq.general_params.start_rate_index[0], - rs_priv->lq.general_params.start_rate_index[1], - rs_priv->lq.general_params.start_rate_index[2], - rs_priv->lq.general_params.start_rate_index[3]); + lq_sta->lq.general_params.start_rate_index[0], + lq_sta->lq.general_params.start_rate_index[1], + lq_sta->lq.general_params.start_rate_index[2], + lq_sta->lq.general_params.start_rate_index[3]); for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) desc += sprintf(buff+desc, " rate[%d] 0x%X\n", - i, le32_to_cpu(rs_priv->lq.rs_table[i].rate_n_flags)); + i, le32_to_cpu(lq_sta->lq.rs_table[i].rate_n_flags)); return simple_read_from_buffer(user_buf, count, ppos, buff, desc); } @@ -2128,22 +2459,22 @@ static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file, int desc = 0; int i, j; - struct iwl_rate_scale_priv *rs_priv = file->private_data; + struct iwl4965_lq_sta *lq_sta = file->private_data; for (i = 0; i < LQ_SIZE; i++) { desc += sprintf(buff+desc, "%s type=%d SGI=%d FAT=%d DUP=%d\n" "rate=0x%X\n", - rs_priv->active_tbl == i?"*":"x", - rs_priv->lq_info[i].lq_type, - rs_priv->lq_info[i].is_SGI, - rs_priv->lq_info[i].is_fat, - rs_priv->lq_info[i].is_dup, - rs_priv->lq_info[i].current_rate.rate_n_flags); + lq_sta->active_tbl == i?"*":"x", + lq_sta->lq_info[i].lq_type, + lq_sta->lq_info[i].is_SGI, + lq_sta->lq_info[i].is_fat, + lq_sta->lq_info[i].is_dup, + lq_sta->lq_info[i].current_rate.rate_n_flags); for (j = 0; j < IWL_RATE_COUNT; j++) { desc += sprintf(buff+desc, - "counter=%d success=%d %%=%d\n", - rs_priv->lq_info[i].win[j].counter, - rs_priv->lq_info[i].win[j].success_counter, - rs_priv->lq_info[i].win[j].success_ratio); + "counter=%d success=%d %%=%d\n", + lq_sta->lq_info[i].win[j].counter, + lq_sta->lq_info[i].win[j].success_counter, + lq_sta->lq_info[i].win[j].success_ratio); } } return simple_read_from_buffer(user_buf, count, ppos, buff, desc); @@ -2157,20 +2488,20 @@ static const struct file_operations rs_sta_dbgfs_stats_table_ops = { static void rs_add_debugfs(void *priv, void *priv_sta, struct dentry *dir) { - struct iwl_rate_scale_priv *rs_priv = priv_sta; - rs_priv->rs_sta_dbgfs_scale_table_file = + struct iwl4965_lq_sta *lq_sta = priv_sta; + lq_sta->rs_sta_dbgfs_scale_table_file = debugfs_create_file("rate_scale_table", 0600, dir, - rs_priv, &rs_sta_dbgfs_scale_table_ops); - rs_priv->rs_sta_dbgfs_stats_table_file = + lq_sta, &rs_sta_dbgfs_scale_table_ops); + lq_sta->rs_sta_dbgfs_stats_table_file = debugfs_create_file("rate_stats_table", 0600, dir, - rs_priv, &rs_sta_dbgfs_stats_table_ops); + lq_sta, &rs_sta_dbgfs_stats_table_ops); } static void rs_remove_debugfs(void *priv, void *priv_sta) { - struct iwl_rate_scale_priv *rs_priv = priv_sta; - debugfs_remove(rs_priv->rs_sta_dbgfs_scale_table_file); - debugfs_remove(rs_priv->rs_sta_dbgfs_stats_table_file); + struct iwl4965_lq_sta *lq_sta = priv_sta; + debugfs_remove(lq_sta->rs_sta_dbgfs_scale_table_file); + debugfs_remove(lq_sta->rs_sta_dbgfs_stats_table_file); } #endif @@ -2191,13 +2522,13 @@ static struct rate_control_ops rs_ops = { #endif }; -int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) +int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) { struct ieee80211_local *local = hw_to_local(hw); - struct iwl_priv *priv = hw->priv; - struct iwl_rate_scale_priv *rs_priv; + struct iwl4965_priv *priv = hw->priv; + struct iwl4965_lq_sta *lq_sta; struct sta_info *sta; - int count = 0, i; + int cnt = 0, i; u32 samples = 0, success = 0, good = 0; unsigned long now = jiffies; u32 max_time = 0; @@ -2213,10 +2544,10 @@ int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) return sprintf(buf, "station %d not found\n", sta_id); } - rs_priv = (void *)sta->rate_ctrl_priv; + lq_sta = (void *)sta->rate_ctrl_priv; - lq_type = rs_priv->lq_info[rs_priv->active_tbl].lq_type; - antenna = rs_priv->lq_info[rs_priv->active_tbl].antenna_type; + lq_type = lq_sta->lq_info[lq_sta->active_tbl].lq_type; + antenna = lq_sta->lq_info[lq_sta->active_tbl].antenna_type; if (is_legacy(lq_type)) i = IWL_RATE_54M_INDEX; @@ -2225,35 +2556,35 @@ int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) while (1) { u64 mask; int j; - int active = rs_priv->active_tbl; + int active = lq_sta->active_tbl; - count += - sprintf(&buf[count], " %2dMbs: ", iwl_rates[i].ieee / 2); + cnt += + sprintf(&buf[cnt], " %2dMbs: ", iwl4965_rates[i].ieee / 2); mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1)); for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1) - buf[count++] = - (rs_priv->lq_info[active].win[i].data & mask) + buf[cnt++] = + (lq_sta->lq_info[active].win[i].data & mask) ? '1' : '0'; - samples += rs_priv->lq_info[active].win[i].counter; - good += rs_priv->lq_info[active].win[i].success_counter; - success += rs_priv->lq_info[active].win[i].success_counter * - iwl_rates[i].ieee; + samples += lq_sta->lq_info[active].win[i].counter; + good += lq_sta->lq_info[active].win[i].success_counter; + success += lq_sta->lq_info[active].win[i].success_counter * + iwl4965_rates[i].ieee; - if (rs_priv->lq_info[active].win[i].stamp) { + if (lq_sta->lq_info[active].win[i].stamp) { int delta = jiffies_to_msecs(now - - rs_priv->lq_info[active].win[i].stamp); + lq_sta->lq_info[active].win[i].stamp); if (delta > max_time) max_time = delta; - count += sprintf(&buf[count], "%5dms\n", delta); + cnt += sprintf(&buf[cnt], "%5dms\n", delta); } else - buf[count++] = '\n'; + buf[cnt++] = '\n'; - j = iwl_get_prev_ieee_rate(i); + j = iwl4965_get_prev_ieee_rate(i); if (j == i) break; i = j; @@ -2261,37 +2592,38 @@ int iwl_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id) /* Display the average rate of all samples taken. * - * NOTE: We multiple # of samples by 2 since the IEEE measurement - * added from iwl_rates is actually 2X the rate */ + * NOTE: We multiply # of samples by 2 since the IEEE measurement + * added from iwl4965_rates is actually 2X the rate */ if (samples) - count += sprintf(&buf[count], + cnt += sprintf(&buf[cnt], "\nAverage rate is %3d.%02dMbs over last %4dms\n" "%3d%% success (%d good packets over %d tries)\n", success / (2 * samples), (success * 5 / samples) % 10, max_time, good * 100 / samples, good, samples); else - count += sprintf(&buf[count], "\nAverage rate: 0Mbs\n"); - count += sprintf(&buf[count], "\nrate scale type %d anntena %d " + cnt += sprintf(&buf[cnt], "\nAverage rate: 0Mbs\n"); + + cnt += sprintf(&buf[cnt], "\nrate scale type %d antenna %d " "active_search %d rate index %d\n", lq_type, antenna, - rs_priv->search_better_tbl, sta->last_txrate); + lq_sta->search_better_tbl, sta->last_txrate); sta_info_put(sta); - return count; + return cnt; } -void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) +void iwl4965_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; priv->lq_mngr.lq_ready = 1; } -void iwl_rate_control_register(struct ieee80211_hw *hw) +void iwl4965_rate_control_register(struct ieee80211_hw *hw) { ieee80211_rate_control_register(&rs_ops); } -void iwl_rate_control_unregister(struct ieee80211_hw *hw) +void iwl4965_rate_control_unregister(struct ieee80211_hw *hw) { ieee80211_rate_control_unregister(&rs_ops); } diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-rs.h b/drivers/net/wireless/iwlwifi/iwl-4965-rs.h index c6325f72df6..55f70738278 100644 --- a/drivers/net/wireless/iwlwifi/iwl-4965-rs.h +++ b/drivers/net/wireless/iwlwifi/iwl-4965-rs.h @@ -29,11 +29,11 @@ #include "iwl-4965.h" -struct iwl_rate_info { - u8 plcp; - u8 plcp_siso; - u8 plcp_mimo; - u8 ieee; +struct iwl4965_rate_info { + u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */ + u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */ + u8 plcp_mimo; /* uCode API: IWL_RATE_MIMO_6M_PLCP, etc. */ + u8 ieee; /* MAC header: IWL_RATE_6M_IEEE, etc. */ u8 prev_ieee; /* previous rate in IEEE speeds */ u8 next_ieee; /* next rate in IEEE speeds */ u8 prev_rs; /* previous rate used in rs algo */ @@ -42,6 +42,10 @@ struct iwl_rate_info { u8 next_rs_tgg; /* next rate used in TGG rs algo */ }; +/* + * These serve as indexes into + * struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT]; + */ enum { IWL_RATE_1M_INDEX = 0, IWL_RATE_2M_INDEX, @@ -69,20 +73,21 @@ enum { }; /* #define vs. enum to keep from defaulting to 'large integer' */ -#define IWL_RATE_6M_MASK (1<<IWL_RATE_6M_INDEX) -#define IWL_RATE_9M_MASK (1<<IWL_RATE_9M_INDEX) -#define IWL_RATE_12M_MASK (1<<IWL_RATE_12M_INDEX) -#define IWL_RATE_18M_MASK (1<<IWL_RATE_18M_INDEX) -#define IWL_RATE_24M_MASK (1<<IWL_RATE_24M_INDEX) -#define IWL_RATE_36M_MASK (1<<IWL_RATE_36M_INDEX) -#define IWL_RATE_48M_MASK (1<<IWL_RATE_48M_INDEX) -#define IWL_RATE_54M_MASK (1<<IWL_RATE_54M_INDEX) -#define IWL_RATE_60M_MASK (1<<IWL_RATE_60M_INDEX) -#define IWL_RATE_1M_MASK (1<<IWL_RATE_1M_INDEX) -#define IWL_RATE_2M_MASK (1<<IWL_RATE_2M_INDEX) -#define IWL_RATE_5M_MASK (1<<IWL_RATE_5M_INDEX) -#define IWL_RATE_11M_MASK (1<<IWL_RATE_11M_INDEX) - +#define IWL_RATE_6M_MASK (1 << IWL_RATE_6M_INDEX) +#define IWL_RATE_9M_MASK (1 << IWL_RATE_9M_INDEX) +#define IWL_RATE_12M_MASK (1 << IWL_RATE_12M_INDEX) +#define IWL_RATE_18M_MASK (1 << IWL_RATE_18M_INDEX) +#define IWL_RATE_24M_MASK (1 << IWL_RATE_24M_INDEX) +#define IWL_RATE_36M_MASK (1 << IWL_RATE_36M_INDEX) +#define IWL_RATE_48M_MASK (1 << IWL_RATE_48M_INDEX) +#define IWL_RATE_54M_MASK (1 << IWL_RATE_54M_INDEX) +#define IWL_RATE_60M_MASK (1 << IWL_RATE_60M_INDEX) +#define IWL_RATE_1M_MASK (1 << IWL_RATE_1M_INDEX) +#define IWL_RATE_2M_MASK (1 << IWL_RATE_2M_INDEX) +#define IWL_RATE_5M_MASK (1 << IWL_RATE_5M_INDEX) +#define IWL_RATE_11M_MASK (1 << IWL_RATE_11M_INDEX) + +/* 4965 uCode API values for legacy bit rates, both OFDM and CCK */ enum { IWL_RATE_6M_PLCP = 13, IWL_RATE_9M_PLCP = 15, @@ -99,7 +104,7 @@ enum { IWL_RATE_11M_PLCP = 110, }; -/* OFDM HT rate plcp */ +/* 4965 uCode API values for OFDM high-throughput (HT) bit rates */ enum { IWL_RATE_SISO_6M_PLCP = 0, IWL_RATE_SISO_12M_PLCP = 1, @@ -121,6 +126,7 @@ enum { IWL_RATE_MIMO_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP, }; +/* MAC header values for bit rates */ enum { IWL_RATE_6M_IEEE = 12, IWL_RATE_9M_IEEE = 18, @@ -163,20 +169,15 @@ enum { (IWL_OFDM_BASIC_RATES_MASK | \ IWL_CCK_BASIC_RATES_MASK) -#define IWL_RATES_MASK ((1<<IWL_RATE_COUNT)-1) +#define IWL_RATES_MASK ((1 << IWL_RATE_COUNT) - 1) #define IWL_INVALID_VALUE -1 #define IWL_MIN_RSSI_VAL -100 #define IWL_MAX_RSSI_VAL 0 -#define IWL_LEGACY_SWITCH_ANTENNA 0 -#define IWL_LEGACY_SWITCH_SISO 1 -#define IWL_LEGACY_SWITCH_MIMO 2 - -#define IWL_RS_GOOD_RATIO 12800 - -#define IWL_ACTION_LIMIT 3 +/* These values specify how many Tx frame attempts before + * searching for a new modulation mode */ #define IWL_LEGACY_FAILURE_LIMIT 160 #define IWL_LEGACY_SUCCESS_LIMIT 480 #define IWL_LEGACY_TABLE_COUNT 160 @@ -185,82 +186,104 @@ enum { #define IWL_NONE_LEGACY_SUCCESS_LIMIT 4500 #define IWL_NONE_LEGACY_TABLE_COUNT 1500 -#define IWL_RATE_SCALE_SWITCH (10880) +/* Success ratio (ACKed / attempted tx frames) values (perfect is 128 * 100) */ +#define IWL_RS_GOOD_RATIO 12800 /* 100% */ +#define IWL_RATE_SCALE_SWITCH 10880 /* 85% */ +#define IWL_RATE_HIGH_TH 10880 /* 85% */ +#define IWL_RATE_INCREASE_TH 8960 /* 70% */ +#define IWL_RATE_DECREASE_TH 1920 /* 15% */ +/* possible actions when in legacy mode */ +#define IWL_LEGACY_SWITCH_ANTENNA 0 +#define IWL_LEGACY_SWITCH_SISO 1 +#define IWL_LEGACY_SWITCH_MIMO 2 + +/* possible actions when in siso mode */ #define IWL_SISO_SWITCH_ANTENNA 0 #define IWL_SISO_SWITCH_MIMO 1 #define IWL_SISO_SWITCH_GI 2 +/* possible actions when in mimo mode */ #define IWL_MIMO_SWITCH_ANTENNA_A 0 #define IWL_MIMO_SWITCH_ANTENNA_B 1 #define IWL_MIMO_SWITCH_GI 2 -#define LQ_SIZE 2 +#define IWL_ACTION_LIMIT 3 /* # possible actions */ + +#define LQ_SIZE 2 /* 2 mode tables: "Active" and "Search" */ -extern const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT]; +extern const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT]; -enum iwl_table_type { +enum iwl4965_table_type { LQ_NONE, - LQ_G, + LQ_G, /* legacy types */ LQ_A, - LQ_SISO, + LQ_SISO, /* high-throughput types */ LQ_MIMO, LQ_MAX, }; -enum iwl_antenna_type { +#define is_legacy(tbl) (((tbl) == LQ_G) || ((tbl) == LQ_A)) +#define is_siso(tbl) (((tbl) == LQ_SISO)) +#define is_mimo(tbl) (((tbl) == LQ_MIMO)) +#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl)) +#define is_a_band(tbl) (((tbl) == LQ_A)) +#define is_g_and(tbl) (((tbl) == LQ_G)) + +/* 4965 has 2 antennas/chains for Tx (but 3 for Rx) */ +enum iwl4965_antenna_type { ANT_NONE, ANT_MAIN, ANT_AUX, ANT_BOTH, }; -static inline u8 iwl_get_prev_ieee_rate(u8 rate_index) +static inline u8 iwl4965_get_prev_ieee_rate(u8 rate_index) { - u8 rate = iwl_rates[rate_index].prev_ieee; + u8 rate = iwl4965_rates[rate_index].prev_ieee; if (rate == IWL_RATE_INVALID) rate = rate_index; return rate; } -extern int iwl_rate_index_from_plcp(int plcp); +extern int iwl4965_rate_index_from_plcp(int plcp); /** - * iwl_fill_rs_info - Fill an output text buffer with the rate representation + * iwl4965_fill_rs_info - Fill an output text buffer with the rate representation * * NOTE: This is provided as a quick mechanism for a user to visualize - * the performance of the rate control alogirthm and is not meant to be + * the performance of the rate control algorithm and is not meant to be * parsed software. */ -extern int iwl_fill_rs_info(struct ieee80211_hw *, char *buf, u8 sta_id); +extern int iwl4965_fill_rs_info(struct ieee80211_hw *, char *buf, u8 sta_id); /** - * iwl_rate_scale_init - Initialize the rate scale table based on assoc info + * iwl4965_rate_scale_init - Initialize the rate scale table based on assoc info * - * The specific througput table used is based on the type of network + * The specific throughput table used is based on the type of network * the associated with, including A, B, G, and G w/ TGG protection */ -extern void iwl_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id); +extern void iwl4965_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id); /** - * iwl_rate_control_register - Register the rate control algorithm callbacks + * iwl4965_rate_control_register - Register the rate control algorithm callbacks * * Since the rate control algorithm is hardware specific, there is no need * or reason to place it as a stand alone module. The driver can call - * iwl_rate_control_register in order to register the rate control callbacks + * iwl4965_rate_control_register in order to register the rate control callbacks * with the mac80211 subsystem. This should be performed prior to calling * ieee80211_register_hw * */ -extern void iwl_rate_control_register(struct ieee80211_hw *hw); +extern void iwl4965_rate_control_register(struct ieee80211_hw *hw); /** - * iwl_rate_control_unregister - Unregister the rate control callbacks + * iwl4965_rate_control_unregister - Unregister the rate control callbacks * * This should be called after calling ieee80211_unregister_hw, but before * the driver is unloaded. */ -extern void iwl_rate_control_unregister(struct ieee80211_hw *hw); +extern void iwl4965_rate_control_unregister(struct ieee80211_hw *hw); #endif diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c index 891f90d2f01..04db34ba814 100644 --- a/drivers/net/wireless/iwlwifi/iwl-4965.c +++ b/drivers/net/wireless/iwlwifi/iwl-4965.c @@ -36,13 +36,13 @@ #include <linux/wireless.h> #include <net/mac80211.h> #include <linux/etherdevice.h> +#include <asm/unaligned.h> -#define IWL 4965 - -#include "iwlwifi.h" #include "iwl-4965.h" #include "iwl-helpers.h" +static void iwl4965_hw_card_show_info(struct iwl4965_priv *priv); + #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \ [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \ IWL_RATE_SISO_##s##M_PLCP, \ @@ -63,7 +63,7 @@ * maps to IWL_RATE_INVALID * */ -const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = { +const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = { IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */ IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */ IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */ @@ -85,16 +85,16 @@ static int is_fat_channel(__le32 rxon_flags) (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK); } -static u8 is_single_stream(struct iwl_priv *priv) +static u8 is_single_stream(struct iwl4965_priv *priv) { -#ifdef CONFIG_IWLWIFI_HT - if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht || - (priv->active_rate_ht[1] == 0) || +#ifdef CONFIG_IWL4965_HT + if (!priv->current_ht_config.is_ht || + (priv->current_ht_config.supp_mcs_set[1] == 0) || (priv->ps_mode == IWL_MIMO_PS_STATIC)) return 1; #else return 1; -#endif /*CONFIG_IWLWIFI_HT */ +#endif /*CONFIG_IWL4965_HT */ return 0; } @@ -104,7 +104,7 @@ static u8 is_single_stream(struct iwl_priv *priv) * MIMO (dual stream) requires at least 2, but works better with 3. * This does not determine *which* chains to use, just how many. */ -static int iwl4965_get_rx_chain_counter(struct iwl_priv *priv, +static int iwl4965_get_rx_chain_counter(struct iwl4965_priv *priv, u8 *idle_state, u8 *rx_state) { u8 is_single = is_single_stream(priv); @@ -133,32 +133,32 @@ static int iwl4965_get_rx_chain_counter(struct iwl_priv *priv, return 0; } -int iwl_hw_rxq_stop(struct iwl_priv *priv) +int iwl4965_hw_rxq_stop(struct iwl4965_priv *priv) { int rc; unsigned long flags; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } - /* stop HW */ - iwl_write_restricted(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); - rc = iwl_poll_restricted_bit(priv, FH_MEM_RSSR_RX_STATUS_REG, + /* stop Rx DMA */ + iwl4965_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); + rc = iwl4965_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG, (1 << 24), 1000); if (rc < 0) IWL_ERROR("Can't stop Rx DMA.\n"); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); return 0; } -u8 iwl_hw_find_station(struct iwl_priv *priv, const u8 *addr) +u8 iwl4965_hw_find_station(struct iwl4965_priv *priv, const u8 *addr) { int i; int start = 0; @@ -190,104 +190,114 @@ u8 iwl_hw_find_station(struct iwl_priv *priv, const u8 *addr) return ret; } -static int iwl4965_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max) +static int iwl4965_nic_set_pwr_src(struct iwl4965_priv *priv, int pwr_max) { - int rc = 0; + int ret; unsigned long flags; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); - if (rc) { + ret = iwl4965_grab_nic_access(priv); + if (ret) { spin_unlock_irqrestore(&priv->lock, flags); - return rc; + return ret; } if (!pwr_max) { u32 val; - rc = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE, + ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE, &val); if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) - iwl_set_bits_mask_restricted_reg( - priv, APMG_PS_CTRL_REG, + iwl4965_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_PWR_SRC_VAUX, ~APMG_PS_CTRL_MSK_PWR_SRC); } else - iwl_set_bits_mask_restricted_reg( - priv, APMG_PS_CTRL_REG, + iwl4965_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_PWR_SRC_VMAIN, ~APMG_PS_CTRL_MSK_PWR_SRC); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); - return rc; + return ret; } -static int iwl4965_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq) +static int iwl4965_rx_init(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq) { int rc; unsigned long flags; + unsigned int rb_size; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } - /* stop HW */ - iwl_write_restricted(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); + if (iwl4965_param_amsdu_size_8K) + rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K; + else + rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K; + + /* Stop Rx DMA */ + iwl4965_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); + + /* Reset driver's Rx queue write index */ + iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0); - iwl_write_restricted(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0); - iwl_write_restricted(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG, + /* Tell device where to find RBD circular buffer in DRAM */ + iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG, rxq->dma_addr >> 8); - iwl_write_restricted(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG, + /* Tell device where in DRAM to update its Rx status */ + iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG, (priv->hw_setting.shared_phys + - offsetof(struct iwl_shared, val0)) >> 4); + offsetof(struct iwl4965_shared, val0)) >> 4); - iwl_write_restricted(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, + /* Enable Rx DMA, enable host interrupt, Rx buffer size 4k, 256 RBDs */ + iwl4965_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL | FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL | - IWL_FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K | + rb_size | /*0x10 << 4 | */ (RX_QUEUE_SIZE_LOG << FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT)); /* - * iwl_write32(priv,CSR_INT_COAL_REG,0); + * iwl4965_write32(priv,CSR_INT_COAL_REG,0); */ - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); return 0; } -static int iwl4965_kw_init(struct iwl_priv *priv) +/* Tell 4965 where to find the "keep warm" buffer */ +static int iwl4965_kw_init(struct iwl4965_priv *priv) { unsigned long flags; int rc; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) goto out; - iwl_write_restricted(priv, IWL_FH_KW_MEM_ADDR_REG, + iwl4965_write_direct32(priv, IWL_FH_KW_MEM_ADDR_REG, priv->kw.dma_addr >> 4); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); out: spin_unlock_irqrestore(&priv->lock, flags); return rc; } -static int iwl4965_kw_alloc(struct iwl_priv *priv) +static int iwl4965_kw_alloc(struct iwl4965_priv *priv) { struct pci_dev *dev = priv->pci_dev; - struct iwl_kw *kw = &priv->kw; + struct iwl4965_kw *kw = &priv->kw; kw->size = IWL4965_KW_SIZE; /* TBW need set somewhere else */ kw->v_addr = pci_alloc_consistent(dev, kw->size, &kw->dma_addr); @@ -300,14 +310,19 @@ static int iwl4965_kw_alloc(struct iwl_priv *priv) #define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \ ? # x " " : "") -int iwl4965_set_fat_chan_info(struct iwl_priv *priv, int phymode, u16 channel, - const struct iwl_eeprom_channel *eeprom_ch, +/** + * iwl4965_set_fat_chan_info - Copy fat channel info into driver's priv. + * + * Does not set up a command, or touch hardware. + */ +int iwl4965_set_fat_chan_info(struct iwl4965_priv *priv, int phymode, u16 channel, + const struct iwl4965_eeprom_channel *eeprom_ch, u8 fat_extension_channel) { - struct iwl_channel_info *ch_info; + struct iwl4965_channel_info *ch_info; - ch_info = (struct iwl_channel_info *) - iwl_get_channel_info(priv, phymode, channel); + ch_info = (struct iwl4965_channel_info *) + iwl4965_get_channel_info(priv, phymode, channel); if (!is_channel_valid(ch_info)) return -1; @@ -340,10 +355,13 @@ int iwl4965_set_fat_chan_info(struct iwl_priv *priv, int phymode, u16 channel, return 0; } -static void iwl4965_kw_free(struct iwl_priv *priv) +/** + * iwl4965_kw_free - Free the "keep warm" buffer + */ +static void iwl4965_kw_free(struct iwl4965_priv *priv) { struct pci_dev *dev = priv->pci_dev; - struct iwl_kw *kw = &priv->kw; + struct iwl4965_kw *kw = &priv->kw; if (kw->v_addr) { pci_free_consistent(dev, kw->size, kw->v_addr, kw->dma_addr); @@ -358,7 +376,7 @@ static void iwl4965_kw_free(struct iwl_priv *priv) * @param priv * @return error code */ -static int iwl4965_txq_ctx_reset(struct iwl_priv *priv) +static int iwl4965_txq_ctx_reset(struct iwl4965_priv *priv) { int rc = 0; int txq_id, slots_num; @@ -366,9 +384,10 @@ static int iwl4965_txq_ctx_reset(struct iwl_priv *priv) iwl4965_kw_free(priv); - iwl_hw_txq_ctx_free(priv); + /* Free all tx/cmd queues and keep-warm buffer */ + iwl4965_hw_txq_ctx_free(priv); - /* Tx CMD queue */ + /* Alloc keep-warm buffer */ rc = iwl4965_kw_alloc(priv); if (rc) { IWL_ERROR("Keep Warm allocation failed"); @@ -377,28 +396,31 @@ static int iwl4965_txq_ctx_reset(struct iwl_priv *priv) spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (unlikely(rc)) { IWL_ERROR("TX reset failed"); spin_unlock_irqrestore(&priv->lock, flags); goto error_reset; } - iwl_write_restricted_reg(priv, SCD_TXFACT, 0); - iwl_release_restricted_access(priv); + /* Turn off all Tx DMA channels */ + iwl4965_write_prph(priv, KDR_SCD_TXFACT, 0); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); + /* Tell 4965 where to find the keep-warm buffer */ rc = iwl4965_kw_init(priv); if (rc) { IWL_ERROR("kw_init failed\n"); goto error_reset; } - /* Tx queue(s) */ + /* Alloc and init all (default 16) Tx queues, + * including the command queue (#4) */ for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++) { slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ? TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; - rc = iwl_tx_queue_init(priv, &priv->txq[txq_id], slots_num, + rc = iwl4965_tx_queue_init(priv, &priv->txq[txq_id], slots_num, txq_id); if (rc) { IWL_ERROR("Tx %d queue init failed\n", txq_id); @@ -409,32 +431,32 @@ static int iwl4965_txq_ctx_reset(struct iwl_priv *priv) return rc; error: - iwl_hw_txq_ctx_free(priv); + iwl4965_hw_txq_ctx_free(priv); error_reset: iwl4965_kw_free(priv); error_kw: return rc; } -int iwl_hw_nic_init(struct iwl_priv *priv) +int iwl4965_hw_nic_init(struct iwl4965_priv *priv) { int rc; unsigned long flags; - struct iwl_rx_queue *rxq = &priv->rxq; + struct iwl4965_rx_queue *rxq = &priv->rxq; u8 rev_id; u32 val; u8 val_link; - iwl_power_init_handle(priv); + iwl4965_power_init_handle(priv); /* nic_init */ spin_lock_irqsave(&priv->lock, flags); - iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, + iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS, CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); - iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); - rc = iwl_poll_bit(priv, CSR_GP_CNTRL, + iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); + rc = iwl4965_poll_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); if (rc < 0) { @@ -443,26 +465,26 @@ int iwl_hw_nic_init(struct iwl_priv *priv) return rc; } - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } - iwl_read_restricted_reg(priv, APMG_CLK_CTRL_REG); + iwl4965_read_prph(priv, APMG_CLK_CTRL_REG); - iwl_write_restricted_reg(priv, APMG_CLK_CTRL_REG, + iwl4965_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT); - iwl_read_restricted_reg(priv, APMG_CLK_CTRL_REG); + iwl4965_read_prph(priv, APMG_CLK_CTRL_REG); udelay(20); - iwl_set_bits_restricted_reg(priv, APMG_PCIDEV_STT_REG, + iwl4965_set_bits_prph(priv, APMG_PCIDEV_STT_REG, APMG_PCIDEV_STT_VAL_L1_ACT_DIS); - iwl_release_restricted_access(priv); - iwl_write32(priv, CSR_INT_COALESCING, 512 / 32); + iwl4965_release_nic_access(priv); + iwl4965_write32(priv, CSR_INT_COALESCING, 512 / 32); spin_unlock_irqrestore(&priv->lock, flags); /* Determine HW type */ @@ -484,11 +506,6 @@ int iwl_hw_nic_init(struct iwl_priv *priv) spin_unlock_irqrestore(&priv->lock, flags); - /* Read the EEPROM */ - rc = iwl_eeprom_init(priv); - if (rc) - return rc; - if (priv->eeprom.calib_version < EEPROM_TX_POWER_VERSION_NEW) { IWL_ERROR("Older EEPROM detected! Aborting.\n"); return -EINVAL; @@ -503,51 +520,53 @@ int iwl_hw_nic_init(struct iwl_priv *priv) /* set CSR_HW_CONFIG_REG for uCode use */ - iwl_set_bit(priv, CSR_SW_VER, CSR_HW_IF_CONFIG_REG_BIT_KEDRON_R | + iwl4965_set_bit(priv, CSR_SW_VER, CSR_HW_IF_CONFIG_REG_BIT_KEDRON_R | CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI | CSR_HW_IF_CONFIG_REG_BIT_MAC_SI); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc < 0) { spin_unlock_irqrestore(&priv->lock, flags); IWL_DEBUG_INFO("Failed to init the card\n"); return rc; } - iwl_read_restricted_reg(priv, APMG_PS_CTRL_REG); - iwl_set_bits_restricted_reg(priv, APMG_PS_CTRL_REG, + iwl4965_read_prph(priv, APMG_PS_CTRL_REG); + iwl4965_set_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ); udelay(5); - iwl_clear_bits_restricted_reg(priv, APMG_PS_CTRL_REG, + iwl4965_clear_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); - iwl_hw_card_show_info(priv); + iwl4965_hw_card_show_info(priv); /* end nic_init */ /* Allocate the RX queue, or reset if it is already allocated */ if (!rxq->bd) { - rc = iwl_rx_queue_alloc(priv); + rc = iwl4965_rx_queue_alloc(priv); if (rc) { IWL_ERROR("Unable to initialize Rx queue\n"); return -ENOMEM; } } else - iwl_rx_queue_reset(priv, rxq); + iwl4965_rx_queue_reset(priv, rxq); - iwl_rx_replenish(priv); + iwl4965_rx_replenish(priv); iwl4965_rx_init(priv, rxq); spin_lock_irqsave(&priv->lock, flags); rxq->need_update = 1; - iwl_rx_queue_update_write_ptr(priv, rxq); + iwl4965_rx_queue_update_write_ptr(priv, rxq); spin_unlock_irqrestore(&priv->lock, flags); + + /* Allocate and init all Tx and Command queues */ rc = iwl4965_txq_ctx_reset(priv); if (rc) return rc; @@ -563,7 +582,7 @@ int iwl_hw_nic_init(struct iwl_priv *priv) return 0; } -int iwl_hw_nic_stop_master(struct iwl_priv *priv) +int iwl4965_hw_nic_stop_master(struct iwl4965_priv *priv) { int rc = 0; u32 reg_val; @@ -572,16 +591,16 @@ int iwl_hw_nic_stop_master(struct iwl_priv *priv) spin_lock_irqsave(&priv->lock, flags); /* set stop master bit */ - iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); + iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); - reg_val = iwl_read32(priv, CSR_GP_CNTRL); + reg_val = iwl4965_read32(priv, CSR_GP_CNTRL); if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE == (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE)) IWL_DEBUG_INFO("Card in power save, master is already " "stopped\n"); else { - rc = iwl_poll_bit(priv, CSR_RESET, + rc = iwl4965_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED, CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); if (rc < 0) { @@ -596,65 +615,69 @@ int iwl_hw_nic_stop_master(struct iwl_priv *priv) return rc; } -void iwl_hw_txq_ctx_stop(struct iwl_priv *priv) +/** + * iwl4965_hw_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory + */ +void iwl4965_hw_txq_ctx_stop(struct iwl4965_priv *priv) { int txq_id; unsigned long flags; - /* reset TFD queues */ + /* Stop each Tx DMA channel, and wait for it to be idle */ for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++) { spin_lock_irqsave(&priv->lock, flags); - if (iwl_grab_restricted_access(priv)) { + if (iwl4965_grab_nic_access(priv)) { spin_unlock_irqrestore(&priv->lock, flags); continue; } - iwl_write_restricted(priv, + iwl4965_write_direct32(priv, IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0); - iwl_poll_restricted_bit(priv, IWL_FH_TSSR_TX_STATUS_REG, + iwl4965_poll_direct_bit(priv, IWL_FH_TSSR_TX_STATUS_REG, IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE (txq_id), 200); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); } - iwl_hw_txq_ctx_free(priv); + /* Deallocate memory for all Tx queues */ + iwl4965_hw_txq_ctx_free(priv); } -int iwl_hw_nic_reset(struct iwl_priv *priv) +int iwl4965_hw_nic_reset(struct iwl4965_priv *priv) { int rc = 0; unsigned long flags; - iwl_hw_nic_stop_master(priv); + iwl4965_hw_nic_stop_master(priv); spin_lock_irqsave(&priv->lock, flags); - iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); + iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); udelay(10); - iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); - rc = iwl_poll_bit(priv, CSR_RESET, + iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); + rc = iwl4965_poll_bit(priv, CSR_RESET, CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25); udelay(10); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (!rc) { - iwl_write_restricted_reg(priv, APMG_CLK_EN_REG, + iwl4965_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT); udelay(10); - iwl_set_bits_restricted_reg(priv, APMG_PCIDEV_STT_REG, + iwl4965_set_bits_prph(priv, APMG_PCIDEV_STT_REG, APMG_PCIDEV_STT_VAL_L1_ACT_DIS); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); } clear_bit(STATUS_HCMD_ACTIVE, &priv->status); @@ -684,7 +707,7 @@ int iwl_hw_nic_reset(struct iwl_priv *priv) */ static void iwl4965_bg_statistics_periodic(unsigned long data) { - struct iwl_priv *priv = (struct iwl_priv *)data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)data; queue_work(priv->workqueue, &priv->statistics_work); } @@ -692,27 +715,27 @@ static void iwl4965_bg_statistics_periodic(unsigned long data) /** * iwl4965_bg_statistics_work - Send the statistics request to the hardware. * - * This is queued by iwl_bg_statistics_periodic. + * This is queued by iwl4965_bg_statistics_periodic. */ static void iwl4965_bg_statistics_work(struct work_struct *work) { - struct iwl_priv *priv = container_of(work, struct iwl_priv, + struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, statistics_work); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; mutex_lock(&priv->mutex); - iwl_send_statistics_request(priv); + iwl4965_send_statistics_request(priv); mutex_unlock(&priv->mutex); } #define CT_LIMIT_CONST 259 #define TM_CT_KILL_THRESHOLD 110 -void iwl4965_rf_kill_ct_config(struct iwl_priv *priv) +void iwl4965_rf_kill_ct_config(struct iwl4965_priv *priv) { - struct iwl_ct_kill_config cmd; + struct iwl4965_ct_kill_config cmd; u32 R1, R2, R3; u32 temp_th; u32 crit_temperature; @@ -720,7 +743,7 @@ void iwl4965_rf_kill_ct_config(struct iwl_priv *priv) int rc = 0; spin_lock_irqsave(&priv->lock, flags); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, + iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); spin_unlock_irqrestore(&priv->lock, flags); @@ -738,7 +761,7 @@ void iwl4965_rf_kill_ct_config(struct iwl_priv *priv) crit_temperature = ((temp_th * (R3-R1))/CT_LIMIT_CONST) + R2; cmd.critical_temperature_R = cpu_to_le32(crit_temperature); - rc = iwl_send_cmd_pdu(priv, + rc = iwl4965_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD, sizeof(cmd), &cmd); if (rc) IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n"); @@ -746,7 +769,7 @@ void iwl4965_rf_kill_ct_config(struct iwl_priv *priv) IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded\n"); } -#ifdef CONFIG_IWLWIFI_SENSITIVITY +#ifdef CONFIG_IWL4965_SENSITIVITY /* "false alarms" are signals that our DSP tries to lock onto, * but then determines that they are either noise, or transmissions @@ -756,7 +779,7 @@ void iwl4965_rf_kill_ct_config(struct iwl_priv *priv) * enough to receive all of our own network traffic, but not so * high that our DSP gets too busy trying to lock onto non-network * activity/noise. */ -static int iwl4965_sens_energy_cck(struct iwl_priv *priv, +static int iwl4965_sens_energy_cck(struct iwl4965_priv *priv, u32 norm_fa, u32 rx_enable_time, struct statistics_general_data *rx_info) @@ -782,7 +805,7 @@ static int iwl4965_sens_energy_cck(struct iwl_priv *priv, u32 false_alarms = norm_fa * 200 * 1024; u32 max_false_alarms = MAX_FA_CCK * rx_enable_time; u32 min_false_alarms = MIN_FA_CCK * rx_enable_time; - struct iwl_sensitivity_data *data = NULL; + struct iwl4965_sensitivity_data *data = NULL; data = &(priv->sensitivity_data); @@ -792,11 +815,11 @@ static int iwl4965_sens_energy_cck(struct iwl_priv *priv, * This is background noise, which may include transmissions from other * networks, measured during silence before our network's beacon */ silence_rssi_a = (u8)((rx_info->beacon_silence_rssi_a & - ALL_BAND_FILTER)>>8); + ALL_BAND_FILTER) >> 8); silence_rssi_b = (u8)((rx_info->beacon_silence_rssi_b & - ALL_BAND_FILTER)>>8); + ALL_BAND_FILTER) >> 8); silence_rssi_c = (u8)((rx_info->beacon_silence_rssi_c & - ALL_BAND_FILTER)>>8); + ALL_BAND_FILTER) >> 8); val = max(silence_rssi_b, silence_rssi_c); max_silence_rssi = max(silence_rssi_a, (u8) val); @@ -947,7 +970,7 @@ static int iwl4965_sens_energy_cck(struct iwl_priv *priv, } -static int iwl4965_sens_auto_corr_ofdm(struct iwl_priv *priv, +static int iwl4965_sens_auto_corr_ofdm(struct iwl4965_priv *priv, u32 norm_fa, u32 rx_enable_time) { @@ -955,7 +978,7 @@ static int iwl4965_sens_auto_corr_ofdm(struct iwl_priv *priv, u32 false_alarms = norm_fa * 200 * 1024; u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time; u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time; - struct iwl_sensitivity_data *data = NULL; + struct iwl4965_sensitivity_data *data = NULL; data = &(priv->sensitivity_data); @@ -1012,22 +1035,22 @@ static int iwl4965_sens_auto_corr_ofdm(struct iwl_priv *priv, return 0; } -static int iwl_sensitivity_callback(struct iwl_priv *priv, - struct iwl_cmd *cmd, struct sk_buff *skb) +static int iwl4965_sensitivity_callback(struct iwl4965_priv *priv, + struct iwl4965_cmd *cmd, struct sk_buff *skb) { /* We didn't cache the SKB; let the caller free it */ return 1; } /* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */ -static int iwl4965_sensitivity_write(struct iwl_priv *priv, u8 flags) +static int iwl4965_sensitivity_write(struct iwl4965_priv *priv, u8 flags) { int rc = 0; - struct iwl_sensitivity_cmd cmd ; - struct iwl_sensitivity_data *data = NULL; - struct iwl_host_cmd cmd_out = { + struct iwl4965_sensitivity_cmd cmd ; + struct iwl4965_sensitivity_data *data = NULL; + struct iwl4965_host_cmd cmd_out = { .id = SENSITIVITY_CMD, - .len = sizeof(struct iwl_sensitivity_cmd), + .len = sizeof(struct iwl4965_sensitivity_cmd), .meta.flags = flags, .data = &cmd, }; @@ -1071,10 +1094,11 @@ static int iwl4965_sensitivity_write(struct iwl_priv *priv, u8 flags) data->auto_corr_cck, data->auto_corr_cck_mrc, data->nrg_th_cck); + /* Update uCode's "work" table, and copy it to DSP */ cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE; if (flags & CMD_ASYNC) - cmd_out.meta.u.callback = iwl_sensitivity_callback; + cmd_out.meta.u.callback = iwl4965_sensitivity_callback; /* Don't send command to uCode if nothing has changed */ if (!memcmp(&cmd.table[0], &(priv->sensitivity_tbl[0]), @@ -1087,7 +1111,7 @@ static int iwl4965_sensitivity_write(struct iwl_priv *priv, u8 flags) memcpy(&(priv->sensitivity_tbl[0]), &(cmd.table[0]), sizeof(u16)*HD_TABLE_SIZE); - rc = iwl_send_cmd(priv, &cmd_out); + rc = iwl4965_send_cmd(priv, &cmd_out); if (!rc) { IWL_DEBUG_CALIB("SENSITIVITY_CMD succeeded\n"); return rc; @@ -1096,11 +1120,11 @@ static int iwl4965_sensitivity_write(struct iwl_priv *priv, u8 flags) return 0; } -void iwl4965_init_sensitivity(struct iwl_priv *priv, u8 flags, u8 force) +void iwl4965_init_sensitivity(struct iwl4965_priv *priv, u8 flags, u8 force) { int rc = 0; int i; - struct iwl_sensitivity_data *data = NULL; + struct iwl4965_sensitivity_data *data = NULL; IWL_DEBUG_CALIB("Start iwl4965_init_sensitivity\n"); @@ -1110,7 +1134,7 @@ void iwl4965_init_sensitivity(struct iwl_priv *priv, u8 flags, u8 force) /* Clear driver's sensitivity algo data */ data = &(priv->sensitivity_data); - memset(data, 0, sizeof(struct iwl_sensitivity_data)); + memset(data, 0, sizeof(struct iwl4965_sensitivity_data)); data->num_in_cck_no_fa = 0; data->nrg_curr_state = IWL_FA_TOO_MANY; @@ -1154,21 +1178,21 @@ void iwl4965_init_sensitivity(struct iwl_priv *priv, u8 flags, u8 force) /* Reset differential Rx gains in NIC to prepare for chain noise calibration. * Called after every association, but this runs only once! * ... once chain noise is calibrated the first time, it's good forever. */ -void iwl4965_chain_noise_reset(struct iwl_priv *priv) +void iwl4965_chain_noise_reset(struct iwl4965_priv *priv) { - struct iwl_chain_noise_data *data = NULL; + struct iwl4965_chain_noise_data *data = NULL; int rc = 0; data = &(priv->chain_noise_data); - if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) { - struct iwl_calibration_cmd cmd; + if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl4965_is_associated(priv)) { + struct iwl4965_calibration_cmd cmd; memset(&cmd, 0, sizeof(cmd)); cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD; cmd.diff_gain_a = 0; cmd.diff_gain_b = 0; cmd.diff_gain_c = 0; - rc = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, + rc = iwl4965_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, sizeof(cmd), &cmd); msleep(4); data->state = IWL_CHAIN_NOISE_ACCUMULATE; @@ -1183,10 +1207,10 @@ void iwl4965_chain_noise_reset(struct iwl_priv *priv) * 1) Which antennas are connected. * 2) Differential rx gain settings to balance the 3 receivers. */ -static void iwl4965_noise_calibration(struct iwl_priv *priv, - struct iwl_notif_statistics *stat_resp) +static void iwl4965_noise_calibration(struct iwl4965_priv *priv, + struct iwl4965_notif_statistics *stat_resp) { - struct iwl_chain_noise_data *data = NULL; + struct iwl4965_chain_noise_data *data = NULL; int rc = 0; u32 chain_noise_a; @@ -1385,7 +1409,7 @@ static void iwl4965_noise_calibration(struct iwl_priv *priv, /* Differential gain gets sent to uCode only once */ if (!data->radio_write) { - struct iwl_calibration_cmd cmd; + struct iwl4965_calibration_cmd cmd; data->radio_write = 1; memset(&cmd, 0, sizeof(cmd)); @@ -1393,7 +1417,7 @@ static void iwl4965_noise_calibration(struct iwl_priv *priv, cmd.diff_gain_a = data->delta_gain_code[0]; cmd.diff_gain_b = data->delta_gain_code[1]; cmd.diff_gain_c = data->delta_gain_code[2]; - rc = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, + rc = iwl4965_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, sizeof(cmd), &cmd); if (rc) IWL_DEBUG_CALIB("fail sending cmd " @@ -1416,8 +1440,8 @@ static void iwl4965_noise_calibration(struct iwl_priv *priv, return; } -static void iwl4965_sensitivity_calibration(struct iwl_priv *priv, - struct iwl_notif_statistics *resp) +static void iwl4965_sensitivity_calibration(struct iwl4965_priv *priv, + struct iwl4965_notif_statistics *resp) { int rc = 0; u32 rx_enable_time; @@ -1427,7 +1451,7 @@ static void iwl4965_sensitivity_calibration(struct iwl_priv *priv, u32 bad_plcp_ofdm; u32 norm_fa_ofdm; u32 norm_fa_cck; - struct iwl_sensitivity_data *data = NULL; + struct iwl4965_sensitivity_data *data = NULL; struct statistics_rx_non_phy *rx_info = &(resp->rx.general); struct statistics_rx *statistics = &(resp->rx); unsigned long flags; @@ -1435,7 +1459,7 @@ static void iwl4965_sensitivity_calibration(struct iwl_priv *priv, data = &(priv->sensitivity_data); - if (!iwl_is_associated(priv)) { + if (!iwl4965_is_associated(priv)) { IWL_DEBUG_CALIB("<< - not associated\n"); return; } @@ -1523,7 +1547,7 @@ static void iwl4965_sensitivity_calibration(struct iwl_priv *priv, static void iwl4965_bg_sensitivity_work(struct work_struct *work) { - struct iwl_priv *priv = container_of(work, struct iwl_priv, + struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, sensitivity_work); mutex_lock(&priv->mutex); @@ -1549,11 +1573,11 @@ static void iwl4965_bg_sensitivity_work(struct work_struct *work) mutex_unlock(&priv->mutex); return; } -#endif /*CONFIG_IWLWIFI_SENSITIVITY*/ +#endif /*CONFIG_IWL4965_SENSITIVITY*/ static void iwl4965_bg_txpower_work(struct work_struct *work) { - struct iwl_priv *priv = container_of(work, struct iwl_priv, + struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, txpower_work); /* If a scan happened to start before we got here @@ -1569,7 +1593,7 @@ static void iwl4965_bg_txpower_work(struct work_struct *work) /* Regardless of if we are assocaited, we must reconfigure the * TX power since frames can be sent on non-radar channels while * not associated */ - iwl_hw_reg_send_txpower(priv); + iwl4965_hw_reg_send_txpower(priv); /* Update last_temperature to keep is_calib_needed from running * when it isn't needed... */ @@ -1581,24 +1605,31 @@ static void iwl4965_bg_txpower_work(struct work_struct *work) /* * Acquire priv->lock before calling this function ! */ -static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index) +static void iwl4965_set_wr_ptrs(struct iwl4965_priv *priv, int txq_id, u32 index) { - iwl_write_restricted(priv, HBUS_TARG_WRPTR, + iwl4965_write_direct32(priv, HBUS_TARG_WRPTR, (index & 0xff) | (txq_id << 8)); - iwl_write_restricted_reg(priv, SCD_QUEUE_RDPTR(txq_id), index); + iwl4965_write_prph(priv, KDR_SCD_QUEUE_RDPTR(txq_id), index); } -/* - * Acquire priv->lock before calling this function ! +/** + * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue + * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed + * @scd_retry: (1) Indicates queue will be used in aggregation mode + * + * NOTE: Acquire priv->lock before calling this function ! */ -static void iwl4965_tx_queue_set_status(struct iwl_priv *priv, - struct iwl_tx_queue *txq, +static void iwl4965_tx_queue_set_status(struct iwl4965_priv *priv, + struct iwl4965_tx_queue *txq, int tx_fifo_id, int scd_retry) { int txq_id = txq->q.id; + + /* Find out whether to activate Tx queue */ int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0; - iwl_write_restricted_reg(priv, SCD_QUEUE_STATUS_BITS(txq_id), + /* Set up and activate */ + iwl4965_write_prph(priv, KDR_SCD_QUEUE_STATUS_BITS(txq_id), (active << SCD_QUEUE_STTS_REG_POS_ACTIVE) | (tx_fifo_id << SCD_QUEUE_STTS_REG_POS_TXF) | (scd_retry << SCD_QUEUE_STTS_REG_POS_WSL) | @@ -1608,7 +1639,7 @@ static void iwl4965_tx_queue_set_status(struct iwl_priv *priv, txq->sched_retry = scd_retry; IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n", - active ? "Activete" : "Deactivate", + active ? "Activate" : "Deactivate", scd_retry ? "BA" : "AC", txq_id, tx_fifo_id); } @@ -1622,17 +1653,17 @@ static const u16 default_queue_to_tx_fifo[] = { IWL_TX_FIFO_HCCA_2 }; -static inline void iwl4965_txq_ctx_activate(struct iwl_priv *priv, int txq_id) +static inline void iwl4965_txq_ctx_activate(struct iwl4965_priv *priv, int txq_id) { set_bit(txq_id, &priv->txq_ctx_active_msk); } -static inline void iwl4965_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id) +static inline void iwl4965_txq_ctx_deactivate(struct iwl4965_priv *priv, int txq_id) { clear_bit(txq_id, &priv->txq_ctx_active_msk); } -int iwl4965_alive_notify(struct iwl_priv *priv) +int iwl4965_alive_notify(struct iwl4965_priv *priv) { u32 a; int i = 0; @@ -1641,45 +1672,55 @@ int iwl4965_alive_notify(struct iwl_priv *priv) spin_lock_irqsave(&priv->lock, flags); -#ifdef CONFIG_IWLWIFI_SENSITIVITY +#ifdef CONFIG_IWL4965_SENSITIVITY memset(&(priv->sensitivity_data), 0, - sizeof(struct iwl_sensitivity_data)); + sizeof(struct iwl4965_sensitivity_data)); memset(&(priv->chain_noise_data), 0, - sizeof(struct iwl_chain_noise_data)); + sizeof(struct iwl4965_chain_noise_data)); for (i = 0; i < NUM_RX_CHAINS; i++) priv->chain_noise_data.delta_gain_code[i] = CHAIN_NOISE_DELTA_GAIN_INIT_VAL; -#endif /* CONFIG_IWLWIFI_SENSITIVITY*/ - rc = iwl_grab_restricted_access(priv); +#endif /* CONFIG_IWL4965_SENSITIVITY*/ + rc = iwl4965_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } - priv->scd_base_addr = iwl_read_restricted_reg(priv, SCD_SRAM_BASE_ADDR); + /* Clear 4965's internal Tx Scheduler data base */ + priv->scd_base_addr = iwl4965_read_prph(priv, KDR_SCD_SRAM_BASE_ADDR); a = priv->scd_base_addr + SCD_CONTEXT_DATA_OFFSET; for (; a < priv->scd_base_addr + SCD_TX_STTS_BITMAP_OFFSET; a += 4) - iwl_write_restricted_mem(priv, a, 0); + iwl4965_write_targ_mem(priv, a, 0); for (; a < priv->scd_base_addr + SCD_TRANSLATE_TBL_OFFSET; a += 4) - iwl_write_restricted_mem(priv, a, 0); + iwl4965_write_targ_mem(priv, a, 0); for (; a < sizeof(u16) * priv->hw_setting.max_txq_num; a += 4) - iwl_write_restricted_mem(priv, a, 0); + iwl4965_write_targ_mem(priv, a, 0); - iwl_write_restricted_reg(priv, SCD_DRAM_BASE_ADDR, + /* Tel 4965 where to find Tx byte count tables */ + iwl4965_write_prph(priv, KDR_SCD_DRAM_BASE_ADDR, (priv->hw_setting.shared_phys + - offsetof(struct iwl_shared, queues_byte_cnt_tbls)) >> 10); - iwl_write_restricted_reg(priv, SCD_QUEUECHAIN_SEL, 0); + offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10); - /* initiate the queues */ + /* Disable chain mode for all queues */ + iwl4965_write_prph(priv, KDR_SCD_QUEUECHAIN_SEL, 0); + + /* Initialize each Tx queue (including the command queue) */ for (i = 0; i < priv->hw_setting.max_txq_num; i++) { - iwl_write_restricted_reg(priv, SCD_QUEUE_RDPTR(i), 0); - iwl_write_restricted(priv, HBUS_TARG_WRPTR, 0 | (i << 8)); - iwl_write_restricted_mem(priv, priv->scd_base_addr + + + /* TFD circular buffer read/write indexes */ + iwl4965_write_prph(priv, KDR_SCD_QUEUE_RDPTR(i), 0); + iwl4965_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8)); + + /* Max Tx Window size for Scheduler-ACK mode */ + iwl4965_write_targ_mem(priv, priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(i), (SCD_WIN_SIZE << SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); - iwl_write_restricted_mem(priv, priv->scd_base_addr + + + /* Frame limit */ + iwl4965_write_targ_mem(priv, priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(i) + sizeof(u32), (SCD_FRAME_LIMIT << @@ -1687,87 +1728,98 @@ int iwl4965_alive_notify(struct iwl_priv *priv) SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); } - iwl_write_restricted_reg(priv, SCD_INTERRUPT_MASK, + iwl4965_write_prph(priv, KDR_SCD_INTERRUPT_MASK, (1 << priv->hw_setting.max_txq_num) - 1); - iwl_write_restricted_reg(priv, SCD_TXFACT, + /* Activate all Tx DMA/FIFO channels */ + iwl4965_write_prph(priv, KDR_SCD_TXFACT, SCD_TXFACT_REG_TXFIFO_MASK(0, 7)); iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0); - /* map qos queues to fifos one-to-one */ + + /* Map each Tx/cmd queue to its corresponding fifo */ for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) { int ac = default_queue_to_tx_fifo[i]; iwl4965_txq_ctx_activate(priv, i); iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0); } - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); return 0; } -int iwl_hw_set_hw_setting(struct iwl_priv *priv) +/** + * iwl4965_hw_set_hw_setting + * + * Called when initializing driver + */ +int iwl4965_hw_set_hw_setting(struct iwl4965_priv *priv) { + /* Allocate area for Tx byte count tables and Rx queue status */ priv->hw_setting.shared_virt = pci_alloc_consistent(priv->pci_dev, - sizeof(struct iwl_shared), + sizeof(struct iwl4965_shared), &priv->hw_setting.shared_phys); if (!priv->hw_setting.shared_virt) return -1; - memset(priv->hw_setting.shared_virt, 0, sizeof(struct iwl_shared)); + memset(priv->hw_setting.shared_virt, 0, sizeof(struct iwl4965_shared)); - priv->hw_setting.max_txq_num = iwl_param_queues_num; + priv->hw_setting.max_txq_num = iwl4965_param_queues_num; priv->hw_setting.ac_queue_count = AC_NUM; - - priv->hw_setting.cck_flag = RATE_MCS_CCK_MSK; - priv->hw_setting.tx_cmd_len = sizeof(struct iwl_tx_cmd); + priv->hw_setting.tx_cmd_len = sizeof(struct iwl4965_tx_cmd); priv->hw_setting.max_rxq_size = RX_QUEUE_SIZE; priv->hw_setting.max_rxq_log = RX_QUEUE_SIZE_LOG; - + if (iwl4965_param_amsdu_size_8K) + priv->hw_setting.rx_buf_size = IWL_RX_BUF_SIZE_8K; + else + priv->hw_setting.rx_buf_size = IWL_RX_BUF_SIZE_4K; + priv->hw_setting.max_pkt_size = priv->hw_setting.rx_buf_size - 256; priv->hw_setting.max_stations = IWL4965_STATION_COUNT; priv->hw_setting.bcast_sta_id = IWL4965_BROADCAST_ID; return 0; } /** - * iwl_hw_txq_ctx_free - Free TXQ Context + * iwl4965_hw_txq_ctx_free - Free TXQ Context * * Destroy all TX DMA queues and structures */ -void iwl_hw_txq_ctx_free(struct iwl_priv *priv) +void iwl4965_hw_txq_ctx_free(struct iwl4965_priv *priv) { int txq_id; /* Tx queues */ for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++) - iwl_tx_queue_free(priv, &priv->txq[txq_id]); + iwl4965_tx_queue_free(priv, &priv->txq[txq_id]); + /* Keep-warm buffer */ iwl4965_kw_free(priv); } /** - * iwl_hw_txq_free_tfd - Free one TFD, those at index [txq->q.last_used] + * iwl4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr] * - * Does NOT advance any indexes + * Does NOT advance any TFD circular buffer read/write indexes + * Does NOT free the TFD itself (which is within circular buffer) */ -int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq) +int iwl4965_hw_txq_free_tfd(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq) { - struct iwl_tfd_frame *bd_tmp = (struct iwl_tfd_frame *)&txq->bd[0]; - struct iwl_tfd_frame *bd = &bd_tmp[txq->q.last_used]; + struct iwl4965_tfd_frame *bd_tmp = (struct iwl4965_tfd_frame *)&txq->bd[0]; + struct iwl4965_tfd_frame *bd = &bd_tmp[txq->q.read_ptr]; struct pci_dev *dev = priv->pci_dev; int i; int counter = 0; int index, is_odd; - /* classify bd */ + /* Host command buffers stay mapped in memory, nothing to clean */ if (txq->q.id == IWL_CMD_QUEUE_NUM) - /* nothing to cleanup after for host commands */ return 0; - /* sanity check */ + /* Sanity check on number of chunks */ counter = IWL_GET_BITS(*bd, num_tbs); if (counter > MAX_NUM_OF_TBS) { IWL_ERROR("Too many chunks: %i\n", counter); @@ -1775,8 +1827,8 @@ int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq) return 0; } - /* unmap chunks if any */ - + /* Unmap chunks, if any. + * TFD info for odd chunks is different format than for even chunks. */ for (i = 0; i < counter; i++) { index = i / 2; is_odd = i & 0x1; @@ -1796,19 +1848,20 @@ int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq) IWL_GET_BITS(bd->pa[index], tb1_len), PCI_DMA_TODEVICE); - if (txq->txb[txq->q.last_used].skb[i]) { - struct sk_buff *skb = txq->txb[txq->q.last_used].skb[i]; + /* Free SKB, if any, for this chunk */ + if (txq->txb[txq->q.read_ptr].skb[i]) { + struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[i]; dev_kfree_skb(skb); - txq->txb[txq->q.last_used].skb[i] = NULL; + txq->txb[txq->q.read_ptr].skb[i] = NULL; } } return 0; } -int iwl_hw_reg_set_txpower(struct iwl_priv *priv, s8 power) +int iwl4965_hw_reg_set_txpower(struct iwl4965_priv *priv, s8 power) { - IWL_ERROR("TODO: Implement iwl_hw_reg_set_txpower!\n"); + IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n"); return -EINVAL; } @@ -1830,6 +1883,17 @@ static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res) return 1; } +/** + * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower + * + * Determines power supply voltage compensation for txpower calculations. + * Returns number of 1/2-dB steps to subtract from gain table index, + * to compensate for difference between power supply voltage during + * factory measurements, vs. current power supply voltage. + * + * Voltage indication is higher for lower voltage. + * Lower voltage requires more gain (lower gain table index). + */ static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage, s32 current_voltage) { @@ -1850,12 +1914,12 @@ static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage, return comp; } -static const struct iwl_channel_info * -iwl4965_get_channel_txpower_info(struct iwl_priv *priv, u8 phymode, u16 channel) +static const struct iwl4965_channel_info * +iwl4965_get_channel_txpower_info(struct iwl4965_priv *priv, u8 phymode, u16 channel) { - const struct iwl_channel_info *ch_info; + const struct iwl4965_channel_info *ch_info; - ch_info = iwl_get_channel_info(priv, phymode, channel); + ch_info = iwl4965_get_channel_info(priv, phymode, channel); if (!is_channel_valid(ch_info)) return NULL; @@ -1889,7 +1953,7 @@ static s32 iwl4965_get_tx_atten_grp(u16 channel) return -1; } -static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel) +static u32 iwl4965_get_sub_band(const struct iwl4965_priv *priv, u32 channel) { s32 b = -1; @@ -1917,15 +1981,23 @@ static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2) } } -static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel, - struct iwl_eeprom_calib_ch_info *chan_info) +/** + * iwl4965_interpolate_chan - Interpolate factory measurements for one channel + * + * Interpolates factory measurements from the two sample channels within a + * sub-band, to apply to channel of interest. Interpolation is proportional to + * differences in channel frequencies, which is proportional to differences + * in channel number. + */ +static int iwl4965_interpolate_chan(struct iwl4965_priv *priv, u32 channel, + struct iwl4965_eeprom_calib_ch_info *chan_info) { s32 s = -1; u32 c; u32 m; - const struct iwl_eeprom_calib_measure *m1; - const struct iwl_eeprom_calib_measure *m2; - struct iwl_eeprom_calib_measure *omeas; + const struct iwl4965_eeprom_calib_measure *m1; + const struct iwl4965_eeprom_calib_measure *m2; + struct iwl4965_eeprom_calib_measure *omeas; u32 ch_i1; u32 ch_i2; @@ -2000,7 +2072,7 @@ static s32 back_off_table[] = { /* Thermal compensation values for txpower for various frequency ranges ... * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */ -static struct iwl_txpower_comp_entry { +static struct iwl4965_txpower_comp_entry { s32 degrees_per_05db_a; s32 degrees_per_05db_a_denom; } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = { @@ -2250,9 +2322,9 @@ static const struct gain_entry gain_table[2][108] = { } }; -static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel, +static int iwl4965_fill_txpower_tbl(struct iwl4965_priv *priv, u8 band, u16 channel, u8 is_fat, u8 ctrl_chan_high, - struct iwl_tx_power_db *tx_power_tbl) + struct iwl4965_tx_power_db *tx_power_tbl) { u8 saturation_power; s32 target_power; @@ -2264,9 +2336,9 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel, s32 txatten_grp = CALIB_CH_GROUP_MAX; int i; int c; - const struct iwl_channel_info *ch_info = NULL; - struct iwl_eeprom_calib_ch_info ch_eeprom_info; - const struct iwl_eeprom_calib_measure *measurement; + const struct iwl4965_channel_info *ch_info = NULL; + struct iwl4965_eeprom_calib_ch_info ch_eeprom_info; + const struct iwl4965_eeprom_calib_measure *measurement; s16 voltage; s32 init_voltage; s32 voltage_compensation; @@ -2405,7 +2477,7 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel, /* for each of 33 bit-rates (including 1 for CCK) */ for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) { u8 is_mimo_rate; - union iwl_tx_power_dual_stream tx_power; + union iwl4965_tx_power_dual_stream tx_power; /* for mimo, reduce each chain's txpower by half * (3dB, 6 steps), so total output power is regulatory @@ -2502,14 +2574,14 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel, } /** - * iwl_hw_reg_send_txpower - Configure the TXPOWER level user limit + * iwl4965_hw_reg_send_txpower - Configure the TXPOWER level user limit * * Uses the active RXON for channel, band, and characteristics (fat, high) * The power limit is taken from priv->user_txpower_limit. */ -int iwl_hw_reg_send_txpower(struct iwl_priv *priv) +int iwl4965_hw_reg_send_txpower(struct iwl4965_priv *priv) { - struct iwl_txpowertable_cmd cmd = { 0 }; + struct iwl4965_txpowertable_cmd cmd = { 0 }; int rc = 0; u8 band = 0; u8 is_fat = 0; @@ -2541,23 +2613,23 @@ int iwl_hw_reg_send_txpower(struct iwl_priv *priv) if (rc) return rc; - rc = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd); + rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd); return rc; } -int iwl_hw_channel_switch(struct iwl_priv *priv, u16 channel) +int iwl4965_hw_channel_switch(struct iwl4965_priv *priv, u16 channel) { int rc; u8 band = 0; u8 is_fat = 0; u8 ctrl_chan_high = 0; - struct iwl_channel_switch_cmd cmd = { 0 }; - const struct iwl_channel_info *ch_info; + struct iwl4965_channel_switch_cmd cmd = { 0 }; + const struct iwl4965_channel_info *ch_info; band = ((priv->phymode == MODE_IEEE80211B) || (priv->phymode == MODE_IEEE80211G)); - ch_info = iwl_get_channel_info(priv, priv->phymode, channel); + ch_info = iwl4965_get_channel_info(priv, priv->phymode, channel); is_fat = is_fat_channel(priv->staging_rxon.flags); @@ -2583,32 +2655,36 @@ int iwl_hw_channel_switch(struct iwl_priv *priv, u16 channel) return rc; } - rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd); + rc = iwl4965_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd); return rc; } #define RTS_HCCA_RETRY_LIMIT 3 #define RTS_DFAULT_RETRY_LIMIT 60 -void iwl_hw_build_tx_cmd_rate(struct iwl_priv *priv, - struct iwl_cmd *cmd, +void iwl4965_hw_build_tx_cmd_rate(struct iwl4965_priv *priv, + struct iwl4965_cmd *cmd, struct ieee80211_tx_control *ctrl, struct ieee80211_hdr *hdr, int sta_id, int is_hcca) { - u8 rate; + struct iwl4965_tx_cmd *tx = &cmd->cmd.tx; u8 rts_retry_limit = 0; u8 data_retry_limit = 0; - __le32 tx_flags; u16 fc = le16_to_cpu(hdr->frame_control); + u8 rate_plcp; + u16 rate_flags = 0; + int rate_idx = min(ctrl->tx_rate & 0xffff, IWL_RATE_COUNT - 1); - tx_flags = cmd->cmd.tx.tx_flags; - - rate = iwl_rates[ctrl->tx_rate].plcp; + rate_plcp = iwl4965_rates[rate_idx].plcp; rts_retry_limit = (is_hcca) ? RTS_HCCA_RETRY_LIMIT : RTS_DFAULT_RETRY_LIMIT; + if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE)) + rate_flags |= RATE_MCS_CCK_MSK; + + if (ieee80211_is_probe_response(fc)) { data_retry_limit = 3; if (data_retry_limit < rts_retry_limit) @@ -2619,44 +2695,56 @@ void iwl_hw_build_tx_cmd_rate(struct iwl_priv *priv, if (priv->data_retry_limit != -1) data_retry_limit = priv->data_retry_limit; - if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { + + if (ieee80211_is_data(fc)) { + tx->initial_rate_index = 0; + tx->tx_flags |= TX_CMD_FLG_STA_RATE_MSK; + } else { switch (fc & IEEE80211_FCTL_STYPE) { case IEEE80211_STYPE_AUTH: case IEEE80211_STYPE_DEAUTH: case IEEE80211_STYPE_ASSOC_REQ: case IEEE80211_STYPE_REASSOC_REQ: - if (tx_flags & TX_CMD_FLG_RTS_MSK) { - tx_flags &= ~TX_CMD_FLG_RTS_MSK; - tx_flags |= TX_CMD_FLG_CTS_MSK; + if (tx->tx_flags & TX_CMD_FLG_RTS_MSK) { + tx->tx_flags &= ~TX_CMD_FLG_RTS_MSK; + tx->tx_flags |= TX_CMD_FLG_CTS_MSK; } break; default: break; } + + /* Alternate between antenna A and B for successive frames */ + if (priv->use_ant_b_for_management_frame) { + priv->use_ant_b_for_management_frame = 0; + rate_flags |= RATE_MCS_ANT_B_MSK; + } else { + priv->use_ant_b_for_management_frame = 1; + rate_flags |= RATE_MCS_ANT_A_MSK; + } } - cmd->cmd.tx.rts_retry_limit = rts_retry_limit; - cmd->cmd.tx.data_retry_limit = data_retry_limit; - cmd->cmd.tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate, 0); - cmd->cmd.tx.tx_flags = tx_flags; + tx->rts_retry_limit = rts_retry_limit; + tx->data_retry_limit = data_retry_limit; + tx->rate_n_flags = iwl4965_hw_set_rate_n_flags(rate_plcp, rate_flags); } -int iwl_hw_get_rx_read(struct iwl_priv *priv) +int iwl4965_hw_get_rx_read(struct iwl4965_priv *priv) { - struct iwl_shared *shared_data = priv->hw_setting.shared_virt; + struct iwl4965_shared *shared_data = priv->hw_setting.shared_virt; return IWL_GET_BITS(*shared_data, rb_closed_stts_rb_num); } -int iwl_hw_get_temperature(struct iwl_priv *priv) +int iwl4965_hw_get_temperature(struct iwl4965_priv *priv) { return priv->temperature; } -unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv, - struct iwl_frame *frame, u8 rate) +unsigned int iwl4965_hw_get_beacon_cmd(struct iwl4965_priv *priv, + struct iwl4965_frame *frame, u8 rate) { - struct iwl_tx_beacon_cmd *tx_beacon_cmd; + struct iwl4965_tx_beacon_cmd *tx_beacon_cmd; unsigned int frame_size; tx_beacon_cmd = &frame->u.beacon; @@ -2665,9 +2753,9 @@ unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv, tx_beacon_cmd->tx.sta_id = IWL4965_BROADCAST_ID; tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; - frame_size = iwl_fill_beacon_frame(priv, + frame_size = iwl4965_fill_beacon_frame(priv, tx_beacon_cmd->frame, - BROADCAST_ADDR, + iwl4965_broadcast_addr, sizeof(frame->u) - sizeof(*tx_beacon_cmd)); BUG_ON(frame_size > MAX_MPDU_SIZE); @@ -2675,53 +2763,59 @@ unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv, if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP)) tx_beacon_cmd->tx.rate_n_flags = - iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK); + iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK); else tx_beacon_cmd->tx.rate_n_flags = - iwl_hw_set_rate_n_flags(rate, 0); + iwl4965_hw_set_rate_n_flags(rate, 0); tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK | TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK); return (sizeof(*tx_beacon_cmd) + frame_size); } -int iwl_hw_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq) +/* + * Tell 4965 where to find circular buffer of Tx Frame Descriptors for + * given Tx queue, and enable the DMA channel used for that queue. + * + * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA + * channels supported in hardware. + */ +int iwl4965_hw_tx_queue_init(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq) { int rc; unsigned long flags; int txq_id = txq->q.id; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } - iwl_write_restricted(priv, FH_MEM_CBBC_QUEUE(txq_id), + /* Circular buffer (TFD queue in DRAM) physical base address */ + iwl4965_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id), txq->q.dma_addr >> 8); - iwl_write_restricted( + + /* Enable DMA channel, using same id as for TFD queue */ + iwl4965_write_direct32( priv, IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); return 0; } -static inline u8 iwl4965_get_dma_hi_address(dma_addr_t addr) -{ - return sizeof(addr) > sizeof(u32) ? (addr >> 16) >> 16 : 0; -} - -int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr, +int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl4965_priv *priv, void *ptr, dma_addr_t addr, u16 len) { int index, is_odd; - struct iwl_tfd_frame *tfd = ptr; + struct iwl4965_tfd_frame *tfd = ptr; u32 num_tbs = IWL_GET_BITS(*tfd, num_tbs); + /* Each TFD can point to a maximum 20 Tx buffers */ if ((num_tbs >= MAX_NUM_OF_TBS) || (num_tbs < 0)) { IWL_ERROR("Error can not send more than %d chunks\n", MAX_NUM_OF_TBS); @@ -2734,7 +2828,7 @@ int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr, if (!is_odd) { tfd->pa[index].tb1_addr = cpu_to_le32(addr); IWL_SET_BITS(tfd->pa[index], tb1_addr_hi, - iwl4965_get_dma_hi_address(addr)); + iwl_get_dma_hi_address(addr)); IWL_SET_BITS(tfd->pa[index], tb1_len, len); } else { IWL_SET_BITS(tfd->pa[index], tb2_addr_lo16, @@ -2748,7 +2842,7 @@ int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr, return 0; } -void iwl_hw_card_show_info(struct iwl_priv *priv) +static void iwl4965_hw_card_show_info(struct iwl4965_priv *priv) { u16 hw_version = priv->eeprom.board_revision_4965; @@ -2763,32 +2857,41 @@ void iwl_hw_card_show_info(struct iwl_priv *priv) #define IWL_TX_CRC_SIZE 4 #define IWL_TX_DELIMITER_SIZE 4 -int iwl4965_tx_queue_update_wr_ptr(struct iwl_priv *priv, - struct iwl_tx_queue *txq, u16 byte_cnt) +/** + * iwl4965_tx_queue_update_wr_ptr - Set up entry in Tx byte-count array + */ +int iwl4965_tx_queue_update_wr_ptr(struct iwl4965_priv *priv, + struct iwl4965_tx_queue *txq, u16 byte_cnt) { int len; int txq_id = txq->q.id; - struct iwl_shared *shared_data = priv->hw_setting.shared_virt; + struct iwl4965_shared *shared_data = priv->hw_setting.shared_virt; if (txq->need_update == 0) return 0; len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE; + /* Set up byte count within first 256 entries */ IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id]. - tfd_offset[txq->q.first_empty], byte_cnt, len); + tfd_offset[txq->q.write_ptr], byte_cnt, len); - if (txq->q.first_empty < IWL4965_MAX_WIN_SIZE) + /* If within first 64 entries, duplicate at end */ + if (txq->q.write_ptr < IWL4965_MAX_WIN_SIZE) IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id]. - tfd_offset[IWL4965_QUEUE_SIZE + txq->q.first_empty], + tfd_offset[IWL4965_QUEUE_SIZE + txq->q.write_ptr], byte_cnt, len); return 0; } -/* Set up Rx receiver/antenna/chain usage in "staging" RXON image. - * This should not be used for scan command ... it puts data in wrong place. */ -void iwl4965_set_rxon_chain(struct iwl_priv *priv) +/** + * iwl4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image + * + * Selects how many and which Rx receivers/antennas/chains to use. + * This should not be used for scan command ... it puts data in wrong place. + */ +void iwl4965_set_rxon_chain(struct iwl4965_priv *priv) { u8 is_single = is_single_stream(priv); u8 idle_state, rx_state; @@ -2819,19 +2922,19 @@ void iwl4965_set_rxon_chain(struct iwl_priv *priv) IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain); } -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG /* get the traffic load value for tid */ -static u32 iwl4965_tl_get_load(struct iwl_priv *priv, u8 tid) +static u32 iwl4965_tl_get_load(struct iwl4965_priv *priv, u8 tid) { u32 load = 0; u32 current_time = jiffies_to_msecs(jiffies); u32 time_diff; s32 index; unsigned long flags; - struct iwl_traffic_load *tid_ptr = NULL; + struct iwl4965_traffic_load *tid_ptr = NULL; if (tid >= TID_MAX_LOAD_COUNT) return 0; @@ -2872,13 +2975,13 @@ static u32 iwl4965_tl_get_load(struct iwl_priv *priv, u8 tid) increment traffic load value for tid and also remove any old values if passed the certian time period */ -static void iwl4965_tl_add_packet(struct iwl_priv *priv, u8 tid) +static void iwl4965_tl_add_packet(struct iwl4965_priv *priv, u8 tid) { u32 current_time = jiffies_to_msecs(jiffies); u32 time_diff; s32 index; unsigned long flags; - struct iwl_traffic_load *tid_ptr = NULL; + struct iwl4965_traffic_load *tid_ptr = NULL; if (tid >= TID_MAX_LOAD_COUNT) return; @@ -2935,14 +3038,19 @@ enum HT_STATUS { BA_STATUS_ACTIVE, }; -static u8 iwl4964_tl_ba_avail(struct iwl_priv *priv) +/** + * iwl4964_tl_ba_avail - Find out if an unused aggregation queue is available + */ +static u8 iwl4964_tl_ba_avail(struct iwl4965_priv *priv) { int i; - struct iwl_lq_mngr *lq; + struct iwl4965_lq_mngr *lq; u8 count = 0; u16 msk; - lq = (struct iwl_lq_mngr *)&(priv->lq_mngr); + lq = (struct iwl4965_lq_mngr *)&(priv->lq_mngr); + + /* Find out how many agg queues are in use */ for (i = 0; i < TID_MAX_LOAD_COUNT ; i++) { msk = 1 << i; if ((lq->agg_ctrl.granted_ba & msk) || @@ -2956,10 +3064,10 @@ static u8 iwl4964_tl_ba_avail(struct iwl_priv *priv) return 0; } -static void iwl4965_ba_status(struct iwl_priv *priv, +static void iwl4965_ba_status(struct iwl4965_priv *priv, u8 tid, enum HT_STATUS status); -static int iwl4965_perform_addba(struct iwl_priv *priv, u8 tid, u32 length, +static int iwl4965_perform_addba(struct iwl4965_priv *priv, u8 tid, u32 length, u32 ba_timeout) { int rc; @@ -2971,7 +3079,7 @@ static int iwl4965_perform_addba(struct iwl_priv *priv, u8 tid, u32 length, return rc; } -static int iwl4965_perform_delba(struct iwl_priv *priv, u8 tid) +static int iwl4965_perform_delba(struct iwl4965_priv *priv, u8 tid) { int rc; @@ -2982,8 +3090,8 @@ static int iwl4965_perform_delba(struct iwl_priv *priv, u8 tid) return rc; } -static void iwl4965_turn_on_agg_for_tid(struct iwl_priv *priv, - struct iwl_lq_mngr *lq, +static void iwl4965_turn_on_agg_for_tid(struct iwl4965_priv *priv, + struct iwl4965_lq_mngr *lq, u8 auto_agg, u8 tid) { u32 tid_msk = (1 << tid); @@ -3030,12 +3138,12 @@ static void iwl4965_turn_on_agg_for_tid(struct iwl_priv *priv, spin_unlock_irqrestore(&priv->lq_mngr.lock, flags); } -static void iwl4965_turn_on_agg(struct iwl_priv *priv, u8 tid) +static void iwl4965_turn_on_agg(struct iwl4965_priv *priv, u8 tid) { - struct iwl_lq_mngr *lq; + struct iwl4965_lq_mngr *lq; unsigned long flags; - lq = (struct iwl_lq_mngr *)&(priv->lq_mngr); + lq = (struct iwl4965_lq_mngr *)&(priv->lq_mngr); if ((tid < TID_MAX_LOAD_COUNT)) iwl4965_turn_on_agg_for_tid(priv, lq, lq->agg_ctrl.auto_agg, @@ -3055,13 +3163,13 @@ static void iwl4965_turn_on_agg(struct iwl_priv *priv, u8 tid) } -void iwl4965_turn_off_agg(struct iwl_priv *priv, u8 tid) +void iwl4965_turn_off_agg(struct iwl4965_priv *priv, u8 tid) { u32 tid_msk; - struct iwl_lq_mngr *lq; + struct iwl4965_lq_mngr *lq; unsigned long flags; - lq = (struct iwl_lq_mngr *)&(priv->lq_mngr); + lq = (struct iwl4965_lq_mngr *)&(priv->lq_mngr); if ((tid < TID_MAX_LOAD_COUNT)) { tid_msk = 1 << tid; @@ -3084,14 +3192,17 @@ void iwl4965_turn_off_agg(struct iwl_priv *priv, u8 tid) } } -static void iwl4965_ba_status(struct iwl_priv *priv, +/** + * iwl4965_ba_status - Update driver's link quality mgr with tid's HT status + */ +static void iwl4965_ba_status(struct iwl4965_priv *priv, u8 tid, enum HT_STATUS status) { - struct iwl_lq_mngr *lq; + struct iwl4965_lq_mngr *lq; u32 tid_msk = (1 << tid); unsigned long flags; - lq = (struct iwl_lq_mngr *)&(priv->lq_mngr); + lq = (struct iwl4965_lq_mngr *)&(priv->lq_mngr); if ((tid >= TID_MAX_LOAD_COUNT)) goto out; @@ -3124,14 +3235,14 @@ static void iwl4965_ba_status(struct iwl_priv *priv, static void iwl4965_bg_agg_work(struct work_struct *work) { - struct iwl_priv *priv = container_of(work, struct iwl_priv, + struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, agg_work); u32 tid; u32 retry_tid; u32 tid_msk; unsigned long flags; - struct iwl_lq_mngr *lq = (struct iwl_lq_mngr *)&(priv->lq_mngr); + struct iwl4965_lq_mngr *lq = (struct iwl4965_lq_mngr *)&(priv->lq_mngr); spin_lock_irqsave(&priv->lq_mngr.lock, flags); retry_tid = lq->agg_ctrl.tid_retry; @@ -3154,90 +3265,13 @@ static void iwl4965_bg_agg_work(struct work_struct *work) spin_unlock_irqrestore(&priv->lq_mngr.lock, flags); return; } -#endif /*CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ -int iwl4965_tx_cmd(struct iwl_priv *priv, struct iwl_cmd *out_cmd, - u8 sta_id, dma_addr_t txcmd_phys, - struct ieee80211_hdr *hdr, u8 hdr_len, - struct ieee80211_tx_control *ctrl, void *sta_in) +/* TODO: move this functionality to rate scaling */ +void iwl4965_tl_get_stats(struct iwl4965_priv *priv, + struct ieee80211_hdr *hdr) { - struct iwl_tx_cmd cmd; - struct iwl_tx_cmd *tx = (struct iwl_tx_cmd *)&out_cmd->cmd.payload[0]; - dma_addr_t scratch_phys; - u8 unicast = 0; - u8 is_data = 1; - u16 fc; - u16 rate_flags; - int rate_index = min(ctrl->tx_rate & 0xffff, IWL_RATE_COUNT - 1); -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG - __le16 *qc; -#endif /*CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ - - unicast = !is_multicast_ether_addr(hdr->addr1); - - fc = le16_to_cpu(hdr->frame_control); - if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) - is_data = 0; - - memcpy(&cmd, &(out_cmd->cmd.tx), sizeof(struct iwl_tx_cmd)); - memset(tx, 0, sizeof(struct iwl_tx_cmd)); - memcpy(tx->hdr, hdr, hdr_len); - - tx->len = cmd.len; - tx->driver_txop = cmd.driver_txop; - tx->stop_time.life_time = cmd.stop_time.life_time; - tx->tx_flags = cmd.tx_flags; - tx->sta_id = cmd.sta_id; - tx->tid_tspec = cmd.tid_tspec; - tx->timeout.pm_frame_timeout = cmd.timeout.pm_frame_timeout; - tx->next_frame_len = cmd.next_frame_len; - - tx->sec_ctl = cmd.sec_ctl; - memcpy(&(tx->key[0]), &(cmd.key[0]), 16); - tx->tx_flags = cmd.tx_flags; - - tx->rts_retry_limit = cmd.rts_retry_limit; - tx->data_retry_limit = cmd.data_retry_limit; - - scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) + - offsetof(struct iwl_tx_cmd, scratch); - tx->dram_lsb_ptr = cpu_to_le32(scratch_phys); - tx->dram_msb_ptr = iwl4965_get_dma_hi_address(scratch_phys); - - /* Hard coded to start at the highest retry fallback position - * until the 4965 specific rate control algorithm is tied in */ - tx->initial_rate_index = LINK_QUAL_MAX_RETRY_NUM - 1; - - /* Alternate between antenna A and B for successive frames */ - if (priv->use_ant_b_for_management_frame) { - priv->use_ant_b_for_management_frame = 0; - rate_flags = RATE_MCS_ANT_B_MSK; - } else { - priv->use_ant_b_for_management_frame = 1; - rate_flags = RATE_MCS_ANT_A_MSK; - } + __le16 *qc = ieee80211_get_qos_ctrl(hdr); - if (!unicast || !is_data) { - if ((rate_index >= IWL_FIRST_CCK_RATE) && - (rate_index <= IWL_LAST_CCK_RATE)) - rate_flags |= RATE_MCS_CCK_MSK; - } else { - tx->initial_rate_index = 0; - tx->tx_flags |= TX_CMD_FLG_STA_RATE_MSK; - } - - tx->rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[rate_index].plcp, - rate_flags); - - if (ieee80211_is_back_request(fc)) - tx->tx_flags |= TX_CMD_FLG_ACK_MSK | - TX_CMD_FLG_IMM_BA_RSP_MASK; -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG - qc = ieee80211_get_qos_ctrl(hdr); if (qc && (priv->iw_mode != IEEE80211_IF_TYPE_IBSS)) { u8 tid = 0; @@ -3255,11 +3289,11 @@ int iwl4965_tx_cmd(struct iwl_priv *priv, struct iwl_cmd *out_cmd, spin_unlock_irqrestore(&priv->lq_mngr.lock, flags); schedule_work(&priv->agg_work); } -#endif -#endif - return 0; } +#endif /*CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ + /** * sign_extend - Sign extend a value using specified bit as sign-bit * @@ -3282,7 +3316,7 @@ static s32 sign_extend(u32 oper, int index) * * A return of <0 indicates bogus data in the statistics */ -int iwl4965_get_temperature(const struct iwl_priv *priv) +int iwl4965_get_temperature(const struct iwl4965_priv *priv) { s32 temperature; s32 vt; @@ -3305,11 +3339,12 @@ int iwl4965_get_temperature(const struct iwl_priv *priv) } /* - * Temperature is only 23 bits so sign extend out to 32 + * Temperature is only 23 bits, so sign extend out to 32. * * NOTE If we haven't received a statistics notification yet * with an updated temperature, use R4 provided to us in the - * ALIVE response. */ + * "initialize" ALIVE response. + */ if (!test_bit(STATUS_TEMPERATURE, &priv->status)) vt = sign_extend(R4, 23); else @@ -3349,7 +3384,7 @@ int iwl4965_get_temperature(const struct iwl_priv *priv) * Assumes caller will replace priv->last_temperature once calibration * executed. */ -static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv) +static int iwl4965_is_temp_calib_needed(struct iwl4965_priv *priv) { int temp_diff; @@ -3382,7 +3417,7 @@ static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv) /* Calculate noise level, based on measurements during network silence just * before arriving beacon. This measurement can be done only if we know * exactly when to expect beacons, therefore only when we're associated. */ -static void iwl4965_rx_calc_noise(struct iwl_priv *priv) +static void iwl4965_rx_calc_noise(struct iwl4965_priv *priv) { struct statistics_rx_non_phy *rx_info = &(priv->statistics.rx.general); @@ -3419,9 +3454,9 @@ static void iwl4965_rx_calc_noise(struct iwl_priv *priv) priv->last_rx_noise); } -void iwl_hw_rx_statistics(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) +void iwl4965_hw_rx_statistics(struct iwl4965_priv *priv, struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; int change; s32 temp; @@ -3448,7 +3483,7 @@ void iwl_hw_rx_statistics(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { iwl4965_rx_calc_noise(priv); -#ifdef CONFIG_IWLWIFI_SENSITIVITY +#ifdef CONFIG_IWL4965_SENSITIVITY queue_work(priv->workqueue, &priv->sensitivity_work); #endif } @@ -3483,12 +3518,117 @@ void iwl_hw_rx_statistics(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) queue_work(priv->workqueue, &priv->txpower_work); } -static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data, +static void iwl4965_add_radiotap(struct iwl4965_priv *priv, + struct sk_buff *skb, + struct iwl4965_rx_phy_res *rx_start, + struct ieee80211_rx_status *stats, + u32 ampdu_status) +{ + s8 signal = stats->ssi; + s8 noise = 0; + int rate = stats->rate; + u64 tsf = stats->mactime; + __le16 phy_flags_hw = rx_start->phy_flags; + struct iwl4965_rt_rx_hdr { + struct ieee80211_radiotap_header rt_hdr; + __le64 rt_tsf; /* TSF */ + u8 rt_flags; /* radiotap packet flags */ + u8 rt_rate; /* rate in 500kb/s */ + __le16 rt_channelMHz; /* channel in MHz */ + __le16 rt_chbitmask; /* channel bitfield */ + s8 rt_dbmsignal; /* signal in dBm, kluged to signed */ + s8 rt_dbmnoise; + u8 rt_antenna; /* antenna number */ + } __attribute__ ((packed)) *iwl4965_rt; + + /* TODO: We won't have enough headroom for HT frames. Fix it later. */ + if (skb_headroom(skb) < sizeof(*iwl4965_rt)) { + if (net_ratelimit()) + printk(KERN_ERR "not enough headroom [%d] for " + "radiotap head [%zd]\n", + skb_headroom(skb), sizeof(*iwl4965_rt)); + return; + } + + /* put radiotap header in front of 802.11 header and data */ + iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt)); + + /* initialise radiotap header */ + iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; + iwl4965_rt->rt_hdr.it_pad = 0; + + /* total header + data */ + put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)), + &iwl4965_rt->rt_hdr.it_len); + + /* Indicate all the fields we add to the radiotap header */ + put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) | + (1 << IEEE80211_RADIOTAP_FLAGS) | + (1 << IEEE80211_RADIOTAP_RATE) | + (1 << IEEE80211_RADIOTAP_CHANNEL) | + (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | + (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | + (1 << IEEE80211_RADIOTAP_ANTENNA)), + &iwl4965_rt->rt_hdr.it_present); + + /* Zero the flags, we'll add to them as we go */ + iwl4965_rt->rt_flags = 0; + + put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf); + + iwl4965_rt->rt_dbmsignal = signal; + iwl4965_rt->rt_dbmnoise = noise; + + /* Convert the channel frequency and set the flags */ + put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz); + if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK)) + put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM | + IEEE80211_CHAN_5GHZ), + &iwl4965_rt->rt_chbitmask); + else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK) + put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK | + IEEE80211_CHAN_2GHZ), + &iwl4965_rt->rt_chbitmask); + else /* 802.11g */ + put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM | + IEEE80211_CHAN_2GHZ), + &iwl4965_rt->rt_chbitmask); + + rate = iwl4965_rate_index_from_plcp(rate); + if (rate == -1) + iwl4965_rt->rt_rate = 0; + else + iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee; + + /* + * "antenna number" + * + * It seems that the antenna field in the phy flags value + * is actually a bitfield. This is undefined by radiotap, + * it wants an actual antenna number but I always get "7" + * for most legacy frames I receive indicating that the + * same frame was received on all three RX chains. + * + * I think this field should be removed in favour of a + * new 802.11n radiotap field "RX chains" that is defined + * as a bitmask. + */ + iwl4965_rt->rt_antenna = + le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4; + + /* set the preamble flag if appropriate */ + if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) + iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; + + stats->flag |= RX_FLAG_RADIOTAP; +} + +static void iwl4965_handle_data_packet(struct iwl4965_priv *priv, int is_data, int include_phy, - struct iwl_rx_mem_buffer *rxb, + struct iwl4965_rx_mem_buffer *rxb, struct ieee80211_rx_status *stats) { - struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; + struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; struct iwl4965_rx_phy_res *rx_start = (include_phy) ? (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL; struct ieee80211_hdr *hdr; @@ -3524,9 +3664,8 @@ static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data, rx_start->byte_count = amsdu->byte_count; rx_end = (__le32 *) (((u8 *) hdr) + len); } - if (len > 2342 || len < 16) { - IWL_DEBUG_DROP("byte count out of range [16,2342]" - " : %d\n", len); + if (len > priv->hw_setting.max_pkt_size || len < 16) { + IWL_WARNING("byte count out of range [16,4K] : %d\n", len); return; } @@ -3544,26 +3683,21 @@ static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data, return; } - if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { - if (iwl_param_hwcrypto) - iwl_set_decrypted_flag(priv, rxb->skb, - ampdu_status, stats); - iwl_handle_data_packet_monitor(priv, rxb, hdr, len, stats, 0); - return; - } - stats->flag = 0; hdr = (struct ieee80211_hdr *)rxb->skb->data; - if (iwl_param_hwcrypto) - iwl_set_decrypted_flag(priv, rxb->skb, ampdu_status, stats); + if (iwl4965_param_hwcrypto) + iwl4965_set_decrypted_flag(priv, rxb->skb, ampdu_status, stats); + + if (priv->add_radiotap) + iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status); ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); priv->alloc_rxb_skb--; rxb->skb = NULL; #ifdef LED priv->led_packets += len; - iwl_setup_activity_timer(priv); + iwl4965_setup_activity_timer(priv); #endif } @@ -3601,7 +3735,7 @@ static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res *rx_resp) return (max_rssi - agc - IWL_RSSI_OFFSET); } -#ifdef CONFIG_IWLWIFI_HT +#ifdef CONFIG_IWL4965_HT /* Parsed Information Elements */ struct ieee802_11_elems { @@ -3673,9 +3807,37 @@ static int parse_elems(u8 *start, size_t len, struct ieee802_11_elems *elems) return 0; } -#endif /* CONFIG_IWLWIFI_HT */ -static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) +void iwl4965_init_ht_hw_capab(struct ieee80211_ht_info *ht_info, int mode) +{ + ht_info->cap = 0; + memset(ht_info->supp_mcs_set, 0, 16); + + ht_info->ht_supported = 1; + + if (mode == MODE_IEEE80211A) { + ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH; + ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40; + ht_info->supp_mcs_set[4] = 0x01; + } + ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD; + ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20; + ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS & + (IWL_MIMO_PS_NONE << 2)); + if (iwl4965_param_amsdu_size_8K) { + printk(KERN_DEBUG "iwl4965 in A-MSDU 8K support mode\n"); + ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU; + } + + ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF; + ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF; + + ht_info->supp_mcs_set[0] = 0xFF; + ht_info->supp_mcs_set[1] = 0xFF; +} +#endif /* CONFIG_IWL4965_HT */ + +static void iwl4965_sta_modify_ps_wake(struct iwl4965_priv *priv, int sta_id) { unsigned long flags; @@ -3686,13 +3848,13 @@ static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; spin_unlock_irqrestore(&priv->sta_lock, flags); - iwl_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); + iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); } -static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr) +static void iwl4965_update_ps_mode(struct iwl4965_priv *priv, u16 ps_bit, u8 *addr) { /* FIXME: need locking over ps_status ??? */ - u8 sta_id = iwl_hw_find_station(priv, addr); + u8 sta_id = iwl4965_hw_find_station(priv, addr); if (sta_id != IWL_INVALID_STATION) { u8 sta_awake = priv->stations[sta_id]. @@ -3707,12 +3869,14 @@ static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr) } } +#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) + /* Called for REPLY_4965_RX (legacy ABG frames), or * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */ -static void iwl4965_rx_reply_rx(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_reply_rx(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; /* Use phy data (Rx signal strength, etc.) contained within * this rx packet for legacy frames, * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */ @@ -3731,11 +3895,8 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv, (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? MODE_IEEE80211G : MODE_IEEE80211A, .antenna = 0, - .rate = iwl_hw_get_rate(rx_start->rate_n_flags), + .rate = iwl4965_hw_get_rate(rx_start->rate_n_flags), .flag = 0, -#ifdef CONFIG_IWLWIFI_HT_AGG - .ordered = 0 -#endif /* CONFIG_IWLWIFI_HT_AGG */ }; u8 network_packet; @@ -3794,32 +3955,32 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv, * which are gathered only when associated, and indicate noise * only for the associated network channel ... * Ignore these noise values while scanning (other channels) */ - if (iwl_is_associated(priv) && + if (iwl4965_is_associated(priv) && !test_bit(STATUS_SCANNING, &priv->status)) { stats.noise = priv->last_rx_noise; - stats.signal = iwl_calc_sig_qual(stats.ssi, stats.noise); + stats.signal = iwl4965_calc_sig_qual(stats.ssi, stats.noise); } else { stats.noise = IWL_NOISE_MEAS_NOT_AVAILABLE; - stats.signal = iwl_calc_sig_qual(stats.ssi, 0); + stats.signal = iwl4965_calc_sig_qual(stats.ssi, 0); } /* Reset beacon noise level if not associated. */ - if (!iwl_is_associated(priv)) + if (!iwl4965_is_associated(priv)) priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; -#ifdef CONFIG_IWLWIFI_DEBUG - /* TODO: Parts of iwl_report_frame are broken for 4965 */ - if (iwl_debug_level & (IWL_DL_RX)) +#ifdef CONFIG_IWL4965_DEBUG + /* TODO: Parts of iwl4965_report_frame are broken for 4965 */ + if (iwl4965_debug_level & (IWL_DL_RX)) /* Set "1" to report good data frames in groups of 100 */ - iwl_report_frame(priv, pkt, header, 1); + iwl4965_report_frame(priv, pkt, header, 1); - if (iwl_debug_level & (IWL_DL_RX | IWL_DL_STATS)) + if (iwl4965_debug_level & (IWL_DL_RX | IWL_DL_STATS)) IWL_DEBUG_RX("Rssi %d, noise %d, qual %d, TSF %lu\n", stats.ssi, stats.noise, stats.signal, (long unsigned int)le64_to_cpu(rx_start->timestamp)); #endif - network_packet = iwl_is_network_packet(priv, header); + network_packet = iwl4965_is_network_packet(priv, header); if (network_packet) { priv->last_rx_rssi = stats.ssi; priv->last_beacon_time = priv->ucode_beacon_time; @@ -3863,27 +4024,31 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv, break; /* - * TODO: There is no callback function from upper - * stack to inform us when associated status. this - * work around to sniff assoc_resp management frame - * and finish the association process. + * TODO: Use the new callback function from + * mac80211 instead of sniffing these packets. */ case IEEE80211_STYPE_ASSOC_RESP: case IEEE80211_STYPE_REASSOC_RESP: if (network_packet) { -#ifdef CONFIG_IWLWIFI_HT +#ifdef CONFIG_IWL4965_HT u8 *pos = NULL; struct ieee802_11_elems elems; -#endif /*CONFIG_IWLWIFI_HT */ +#endif /*CONFIG_IWL4965_HT */ struct ieee80211_mgmt *mgnt = (struct ieee80211_mgmt *)header; + /* We have just associated, give some + * time for the 4-way handshake if + * any. Don't start scan too early. */ + priv->next_scan_jiffies = jiffies + + IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; + priv->assoc_id = (~((1 << 15) | (1 << 14)) & le16_to_cpu(mgnt->u.assoc_resp.aid)); priv->assoc_capability = le16_to_cpu( mgnt->u.assoc_resp.capab_info); -#ifdef CONFIG_IWLWIFI_HT +#ifdef CONFIG_IWL4965_HT pos = mgnt->u.assoc_resp.variable; if (!parse_elems(pos, len - (pos - (u8 *) mgnt), @@ -3892,7 +4057,7 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv, elems.ht_cap_param) break; } -#endif /*CONFIG_IWLWIFI_HT */ +#endif /*CONFIG_IWL4965_HT */ /* assoc_id is 0 no association */ if (!priv->assoc_id) break; @@ -3907,7 +4072,7 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv, case IEEE80211_STYPE_PROBE_REQ: if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && - !iwl_is_associated(priv)) { + !iwl4965_is_associated(priv)) { DECLARE_MAC_BUF(mac1); DECLARE_MAC_BUF(mac2); DECLARE_MAC_BUF(mac3); @@ -3924,7 +4089,7 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv, break; case IEEE80211_FTYPE_CTL: -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT switch (fc & IEEE80211_FCTL_STYPE) { case IEEE80211_STYPE_BACK_REQ: IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n"); @@ -3935,7 +4100,6 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv, break; } #endif - break; case IEEE80211_FTYPE_DATA: { @@ -3953,7 +4117,7 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv, print_mac(mac1, header->addr1), print_mac(mac2, header->addr2), print_mac(mac3, header->addr3)); - else if (unlikely(is_duplicate_packet(priv, header))) + else if (unlikely(iwl4965_is_duplicate_packet(priv, header))) IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n", print_mac(mac1, header->addr1), print_mac(mac2, header->addr2), @@ -3971,22 +4135,22 @@ static void iwl4965_rx_reply_rx(struct iwl_priv *priv, /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD). * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */ -static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_reply_rx_phy(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; priv->last_phy_res[0] = 1; memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]), sizeof(struct iwl4965_rx_phy_res)); } -static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_missed_beacon_notif(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { -#ifdef CONFIG_IWLWIFI_SENSITIVITY - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_missed_beacon_notif *missed_beacon; +#ifdef CONFIG_IWL4965_SENSITIVITY + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_missed_beacon_notif *missed_beacon; missed_beacon = &pkt->u.missed_beacon; if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) { @@ -3999,13 +4163,18 @@ static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv, if (unlikely(!test_bit(STATUS_SCANNING, &priv->status))) queue_work(priv->workqueue, &priv->sensitivity_work); } -#endif /*CONFIG_IWLWIFI_SENSITIVITY*/ +#endif /*CONFIG_IWL4965_SENSITIVITY*/ } -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG -static void iwl4965_set_tx_status(struct iwl_priv *priv, int txq_id, int idx, +/** + * iwl4965_set_tx_status - Update driver's record of one Tx frame's status + * + * This will get sent to mac80211. + */ +static void iwl4965_set_tx_status(struct iwl4965_priv *priv, int txq_id, int idx, u32 status, u32 retry_count, u32 rate) { struct ieee80211_tx_status *tx_status = @@ -4017,24 +4186,34 @@ static void iwl4965_set_tx_status(struct iwl_priv *priv, int txq_id, int idx, } -static void iwl_sta_modify_enable_tid_tx(struct iwl_priv *priv, +/** + * iwl4965_sta_modify_enable_tid_tx - Enable Tx for this TID in station table + */ +static void iwl4965_sta_modify_enable_tid_tx(struct iwl4965_priv *priv, int sta_id, int tid) { unsigned long flags; + /* Remove "disable" flag, to enable Tx for this TID */ spin_lock_irqsave(&priv->sta_lock, flags); priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; spin_unlock_irqrestore(&priv->sta_lock, flags); - iwl_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); + iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); } -static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv, - struct iwl_ht_agg *agg, - struct iwl_compressed_ba_resp* +/** + * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack + * + * Go through block-ack's bitmap of ACK'd frames, update driver's record of + * ACK vs. not. This gets sent to mac80211, then to rate scaling algo. + */ +static int iwl4965_tx_status_reply_compressed_ba(struct iwl4965_priv *priv, + struct iwl4965_ht_agg *agg, + struct iwl4965_compressed_ba_resp* ba_resp) { @@ -4048,16 +4227,20 @@ static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv, IWL_ERROR("Received BA when not expected\n"); return -EINVAL; } + + /* Mark that the expected block-ack response arrived */ agg->wait_for_ba = 0; IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->ba_seq_ctl); - sh = agg->start_idx - SEQ_TO_INDEX(ba_seq_ctl>>4); - if (sh < 0) /* tbw something is wrong with indeces */ + + /* Calculate shift to align block-ack bits with our Tx window bits */ + sh = agg->start_idx - SEQ_TO_INDEX(ba_seq_ctl >> 4); + if (sh < 0) /* tbw something is wrong with indices */ sh += 0x100; - /* don't use 64 bits for now */ + /* don't use 64-bit values for now */ bitmap0 = resp_bitmap0 >> sh; bitmap1 = resp_bitmap1 >> sh; - bitmap0 |= (resp_bitmap1 & ((1<<sh)|((1<<sh)-1))) << (32 - sh); + bitmap0 |= (resp_bitmap1 & ((1 << sh) | ((1 << sh) - 1))) << (32 - sh); if (agg->frame_count > (64 - sh)) { IWL_DEBUG_TX_REPLY("more frames than bitmap size"); @@ -4065,10 +4248,12 @@ static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv, } /* check for success or failure according to the - * transmitted bitmap and back bitmap */ + * transmitted bitmap and block-ack bitmap */ bitmap0 &= agg->bitmap0; bitmap1 &= agg->bitmap1; + /* For each frame attempted in aggregation, + * update driver's record of tx frame's status. */ for (i = 0; i < agg->frame_count ; i++) { int idx = (agg->start_idx + i) & 0xff; ack = bitmap0 & (1 << i); @@ -4084,20 +4269,36 @@ static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv, return 0; } -static inline int iwl_queue_dec_wrap(int index, int n_bd) +/** + * iwl4965_queue_dec_wrap - Decrement queue index, wrap back to end if needed + * @index -- current index + * @n_bd -- total number of entries in queue (s/b power of 2) + */ +static inline int iwl4965_queue_dec_wrap(int index, int n_bd) { return (index == 0) ? n_bd - 1 : index - 1; } -static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +/** + * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA + * + * Handles block-acknowledge notification from device, which reports success + * of frames sent via aggregation. + */ +static void iwl4965_rx_reply_compressed_ba(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba; int index; - struct iwl_tx_queue *txq = NULL; - struct iwl_ht_agg *agg; + struct iwl4965_tx_queue *txq = NULL; + struct iwl4965_ht_agg *agg; + + /* "flow" corresponds to Tx queue */ u16 ba_resp_scd_flow = le16_to_cpu(ba_resp->scd_flow); + + /* "ssn" is start of block-ack Tx window, corresponds to index + * (in Tx queue's circular buffer) of first TFD/frame in window */ u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn); if (ba_resp_scd_flow >= ARRAY_SIZE(priv->txq)) { @@ -4107,9 +4308,11 @@ static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv, txq = &priv->txq[ba_resp_scd_flow]; agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg; - index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd); - /* TODO: Need to get this copy more sefely - now good for debug */ + /* Find index just before block-ack window */ + index = iwl4965_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd); + + /* TODO: Need to get this copy more safely - now good for debug */ /* { DECLARE_MAC_BUF(mac); @@ -4132,23 +4335,36 @@ static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv, agg->bitmap0); } */ + + /* Update driver's record of ACK vs. not for each frame in window */ iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp); - /* releases all the TFDs until the SSN */ - if (txq->q.last_used != (ba_resp_scd_ssn & 0xff)) - iwl_tx_queue_reclaim(priv, ba_resp_scd_flow, index); + + /* Release all TFDs before the SSN, i.e. all TFDs in front of + * block-ack window (we assume that they've been successfully + * transmitted ... if not, it's too late anyway). */ + if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) + iwl4965_tx_queue_reclaim(priv, ba_resp_scd_flow, index); } -static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv, u16 txq_id) +/** + * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration + */ +static void iwl4965_tx_queue_stop_scheduler(struct iwl4965_priv *priv, u16 txq_id) { - iwl_write_restricted_reg(priv, - SCD_QUEUE_STATUS_BITS(txq_id), + /* Simply stop the queue, but don't change any configuration; + * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */ + iwl4965_write_prph(priv, + KDR_SCD_QUEUE_STATUS_BITS(txq_id), (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)| (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN)); } -static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid, +/** + * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue + */ +static int iwl4965_tx_queue_set_q2ratid(struct iwl4965_priv *priv, u16 ra_tid, u16 txq_id) { u32 tbl_dw_addr; @@ -4160,22 +4376,25 @@ static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid, tbl_dw_addr = priv->scd_base_addr + SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id); - tbl_dw = iwl_read_restricted_mem(priv, tbl_dw_addr); + tbl_dw = iwl4965_read_targ_mem(priv, tbl_dw_addr); if (txq_id & 0x1) tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF); else tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000); - iwl_write_restricted_mem(priv, tbl_dw_addr, tbl_dw); + iwl4965_write_targ_mem(priv, tbl_dw_addr, tbl_dw); return 0; } /** - * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID + * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue + * + * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID, + * i.e. it must be one of the higher queues used for aggregation */ -static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id, +static int iwl4965_tx_queue_agg_enable(struct iwl4965_priv *priv, int txq_id, int tx_fifo, int sta_id, int tid, u16 ssn_idx) { @@ -4189,43 +4408,48 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id, ra_tid = BUILD_RAxTID(sta_id, tid); - iwl_sta_modify_enable_tid_tx(priv, sta_id, tid); + /* Modify device's station table to Tx this TID */ + iwl4965_sta_modify_enable_tid_tx(priv, sta_id, tid); spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } + /* Stop this Tx queue before configuring it */ iwl4965_tx_queue_stop_scheduler(priv, txq_id); + /* Map receiver-address / traffic-ID to this queue */ iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id); + /* Set this queue as a chain-building queue */ + iwl4965_set_bits_prph(priv, KDR_SCD_QUEUECHAIN_SEL, (1 << txq_id)); - iwl_set_bits_restricted_reg(priv, SCD_QUEUECHAIN_SEL, (1<<txq_id)); - - priv->txq[txq_id].q.last_used = (ssn_idx & 0xff); - priv->txq[txq_id].q.first_empty = (ssn_idx & 0xff); - - /* supposes that ssn_idx is valid (!= 0xFFF) */ + /* Place first TFD at index corresponding to start sequence number. + * Assumes that ssn_idx is valid (!= 0xFFF) */ + priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff); + priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff); iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx); - iwl_write_restricted_mem(priv, + /* Set up Tx window size and frame limit for this queue */ + iwl4965_write_targ_mem(priv, priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(txq_id), (SCD_WIN_SIZE << SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); - iwl_write_restricted_mem(priv, priv->scd_base_addr + + iwl4965_write_targ_mem(priv, priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32), (SCD_FRAME_LIMIT << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) & SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); - iwl_set_bits_restricted_reg(priv, SCD_INTERRUPT_MASK, (1 << txq_id)); + iwl4965_set_bits_prph(priv, KDR_SCD_INTERRUPT_MASK, (1 << txq_id)); + /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */ iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); return 0; @@ -4234,7 +4458,7 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id, /** * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID */ -static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id, +static int iwl4965_tx_queue_agg_disable(struct iwl4965_priv *priv, u16 txq_id, u16 ssn_idx, u8 tx_fifo) { unsigned long flags; @@ -4247,7 +4471,7 @@ static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id, } spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; @@ -4255,56 +4479,50 @@ static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id, iwl4965_tx_queue_stop_scheduler(priv, txq_id); - iwl_clear_bits_restricted_reg(priv, SCD_QUEUECHAIN_SEL, (1 << txq_id)); + iwl4965_clear_bits_prph(priv, KDR_SCD_QUEUECHAIN_SEL, (1 << txq_id)); - priv->txq[txq_id].q.last_used = (ssn_idx & 0xff); - priv->txq[txq_id].q.first_empty = (ssn_idx & 0xff); + priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff); + priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff); /* supposes that ssn_idx is valid (!= 0xFFF) */ iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx); - iwl_clear_bits_restricted_reg(priv, SCD_INTERRUPT_MASK, (1 << txq_id)); + iwl4965_clear_bits_prph(priv, KDR_SCD_INTERRUPT_MASK, (1 << txq_id)); iwl4965_txq_ctx_deactivate(priv, txq_id); iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); return 0; } -#endif/* CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ -/* - * RATE SCALE CODE - */ -int iwl4965_init_hw_rates(struct iwl_priv *priv, struct ieee80211_rate *rates) -{ - return 0; -} - +#endif/* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ /** * iwl4965_add_station - Initialize a station's hardware rate table * - * The uCode contains a table of fallback rates and retries per rate + * The uCode's station table contains a table of fallback rates * for automatic fallback during transmission. * - * NOTE: This initializes the table for a single retry per data rate - * which is not optimal. Setting up an intelligent retry per rate - * requires feedback from transmission, which isn't exposed through - * rc80211_simple which is what this driver is currently using. + * NOTE: This sets up a default set of values. These will be replaced later + * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of + * rc80211_simple. * + * NOTE: Run REPLY_ADD_STA command to set up station table entry, before + * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, + * which requires station table entry to exist). */ -void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap) +void iwl4965_add_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap) { int i, r; - struct iwl_link_quality_cmd link_cmd = { + struct iwl4965_link_quality_cmd link_cmd = { .reserved1 = 0, }; u16 rate_flags; - /* Set up the rate scaling to start at 54M and fallback - * all the way to 1M in IEEE order and then spin on IEEE */ + /* Set up the rate scaling to start at selected rate, fall back + * all the way down to 1M in IEEE order, and then spin on 1M */ if (is_ap) r = IWL_RATE_54M_INDEX; else if (priv->phymode == MODE_IEEE80211A) @@ -4317,11 +4535,13 @@ void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap) if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) rate_flags |= RATE_MCS_CCK_MSK; + /* Use Tx antenna B only */ rate_flags |= RATE_MCS_ANT_B_MSK; rate_flags &= ~RATE_MCS_ANT_A_MSK; + link_cmd.rs_table[i].rate_n_flags = - iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); - r = iwl_get_prev_ieee_rate(r); + iwl4965_hw_set_rate_n_flags(iwl4965_rates[r].plcp, rate_flags); + r = iwl4965_get_prev_ieee_rate(r); } link_cmd.general_params.single_stream_ant_msk = 2; @@ -4332,18 +4552,18 @@ void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap) /* Update the rate scaling for control frame Tx to AP */ link_cmd.sta_id = is_ap ? IWL_AP_ID : IWL4965_BROADCAST_ID; - iwl_send_cmd_pdu(priv, REPLY_TX_LINK_QUALITY_CMD, sizeof(link_cmd), + iwl4965_send_cmd_pdu(priv, REPLY_TX_LINK_QUALITY_CMD, sizeof(link_cmd), &link_cmd); } -#ifdef CONFIG_IWLWIFI_HT +#ifdef CONFIG_IWL4965_HT -static u8 iwl_is_channel_extension(struct iwl_priv *priv, int phymode, +static u8 iwl4965_is_channel_extension(struct iwl4965_priv *priv, int phymode, u16 channel, u8 extension_chan_offset) { - const struct iwl_channel_info *ch_info; + const struct iwl4965_channel_info *ch_info; - ch_info = iwl_get_channel_info(priv, phymode, channel); + ch_info = iwl4965_get_channel_info(priv, phymode, channel); if (!is_channel_valid(ch_info)) return 0; @@ -4357,36 +4577,37 @@ static u8 iwl_is_channel_extension(struct iwl_priv *priv, int phymode, return 0; } -static u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv, - const struct sta_ht_info *ht_info) +static u8 iwl4965_is_fat_tx_allowed(struct iwl4965_priv *priv, + struct ieee80211_ht_info *sta_ht_inf) { + struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config; - if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ) + if ((!iwl_ht_conf->is_ht) || + (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) || + (iwl_ht_conf->extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_AUTO)) return 0; - if (ht_info->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) - return 0; - - if (ht_info->extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_AUTO) - return 0; + if (sta_ht_inf) { + if ((!sta_ht_inf->ht_supported) || + (!sta_ht_inf->cap & IEEE80211_HT_CAP_SUP_WIDTH)) + return 0; + } - /* no fat tx allowed on 2.4GHZ */ - if (priv->phymode != MODE_IEEE80211A) - return 0; - return (iwl_is_channel_extension(priv, priv->phymode, - ht_info->control_channel, - ht_info->extension_chan_offset)); + return (iwl4965_is_channel_extension(priv, priv->phymode, + iwl_ht_conf->control_channel, + iwl_ht_conf->extension_chan_offset)); } -void iwl4965_set_rxon_ht(struct iwl_priv *priv, struct sta_ht_info *ht_info) +void iwl4965_set_rxon_ht(struct iwl4965_priv *priv, struct iwl_ht_info *ht_info) { - struct iwl_rxon_cmd *rxon = &priv->staging_rxon; + struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; u32 val; if (!ht_info->is_ht) return; - if (iwl_is_fat_tx_allowed(priv, ht_info)) + /* Set up channel bandwidth: 20 MHz only, or 20/40 mixed if fat ok */ + if (iwl4965_is_fat_tx_allowed(priv, NULL)) rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK; else rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | @@ -4400,7 +4621,7 @@ void iwl4965_set_rxon_ht(struct iwl_priv *priv, struct sta_ht_info *ht_info) return; } - /* Note: control channel is oposit to extension channel */ + /* Note: control channel is opposite of extension channel */ switch (ht_info->extension_chan_offset) { case IWL_EXT_CHANNEL_OFFSET_ABOVE: rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); @@ -4416,66 +4637,56 @@ void iwl4965_set_rxon_ht(struct iwl_priv *priv, struct sta_ht_info *ht_info) break; } - val = ht_info->operating_mode; + val = ht_info->ht_protection; rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS); - priv->active_rate_ht[0] = ht_info->supp_rates[0]; - priv->active_rate_ht[1] = ht_info->supp_rates[1]; iwl4965_set_rxon_chain(priv); IWL_DEBUG_ASSOC("supported HT rate 0x%X %X " "rxon flags 0x%X operation mode :0x%X " "extension channel offset 0x%x " "control chan %d\n", - priv->active_rate_ht[0], priv->active_rate_ht[1], - le32_to_cpu(rxon->flags), ht_info->operating_mode, + ht_info->supp_mcs_set[0], ht_info->supp_mcs_set[1], + le32_to_cpu(rxon->flags), ht_info->ht_protection, ht_info->extension_chan_offset, ht_info->control_channel); return; } -void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index) +void iwl4965_set_ht_add_station(struct iwl4965_priv *priv, u8 index, + struct ieee80211_ht_info *sta_ht_inf) { __le32 sta_flags; - struct sta_ht_info *ht_info = &priv->current_assoc_ht; - priv->current_channel_width = IWL_CHANNEL_WIDTH_20MHZ; - if (!ht_info->is_ht) + if (!sta_ht_inf || !sta_ht_inf->ht_supported) goto done; sta_flags = priv->stations[index].sta.station_flags; - if (ht_info->tx_mimo_ps_mode == IWL_MIMO_PS_DYNAMIC) + if (((sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS >> 2)) + == IWL_MIMO_PS_DYNAMIC) sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK; else sta_flags &= ~STA_FLG_RTS_MIMO_PROT_MSK; sta_flags |= cpu_to_le32( - (u32)ht_info->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); + (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); sta_flags |= cpu_to_le32( - (u32)ht_info->mpdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); - - sta_flags &= (~STA_FLG_FAT_EN_MSK); - ht_info->tx_chan_width = IWL_CHANNEL_WIDTH_20MHZ; - ht_info->chan_width_cap = IWL_CHANNEL_WIDTH_20MHZ; + (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); - if (iwl_is_fat_tx_allowed(priv, ht_info)) { + if (iwl4965_is_fat_tx_allowed(priv, sta_ht_inf)) sta_flags |= STA_FLG_FAT_EN_MSK; - ht_info->chan_width_cap = IWL_CHANNEL_WIDTH_40MHZ; - if (ht_info->supported_chan_width == IWL_CHANNEL_WIDTH_40MHZ) - ht_info->tx_chan_width = IWL_CHANNEL_WIDTH_40MHZ; - } - priv->current_channel_width = ht_info->tx_chan_width; + else + sta_flags &= (~STA_FLG_FAT_EN_MSK); + priv->stations[index].sta.station_flags = sta_flags; done: return; } -#ifdef CONFIG_IWLWIFI_HT_AGG - -static void iwl4965_sta_modify_add_ba_tid(struct iwl_priv *priv, +static void iwl4965_sta_modify_add_ba_tid(struct iwl4965_priv *priv, int sta_id, int tid, u16 ssn) { unsigned long flags; @@ -4488,10 +4699,10 @@ static void iwl4965_sta_modify_add_ba_tid(struct iwl_priv *priv, priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; spin_unlock_irqrestore(&priv->sta_lock, flags); - iwl_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); + iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); } -static void iwl4965_sta_modify_del_ba_tid(struct iwl_priv *priv, +static void iwl4965_sta_modify_del_ba_tid(struct iwl4965_priv *priv, int sta_id, int tid) { unsigned long flags; @@ -4503,9 +4714,39 @@ static void iwl4965_sta_modify_del_ba_tid(struct iwl_priv *priv, priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; spin_unlock_irqrestore(&priv->sta_lock, flags); - iwl_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); + iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); +} + +int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw, + enum ieee80211_ampdu_mlme_action action, + const u8 *addr, u16 tid, u16 ssn) +{ + struct iwl4965_priv *priv = hw->priv; + int sta_id; + DECLARE_MAC_BUF(mac); + + IWL_DEBUG_HT("A-MPDU action on da=%s tid=%d ", + print_mac(mac, addr), tid); + sta_id = iwl4965_hw_find_station(priv, addr); + switch (action) { + case IEEE80211_AMPDU_RX_START: + IWL_DEBUG_HT("start Rx\n"); + iwl4965_sta_modify_add_ba_tid(priv, sta_id, tid, ssn); + break; + case IEEE80211_AMPDU_RX_STOP: + IWL_DEBUG_HT("stop Rx\n"); + iwl4965_sta_modify_del_ba_tid(priv, sta_id, tid); + break; + default: + IWL_DEBUG_HT("unknown\n"); + return -EINVAL; + break; + } + return 0; } +#ifdef CONFIG_IWL4965_HT_AGG + static const u16 default_tid_to_tx_fifo[] = { IWL_TX_FIFO_AC1, IWL_TX_FIFO_AC0, @@ -4526,7 +4767,13 @@ static const u16 default_tid_to_tx_fifo[] = { IWL_TX_FIFO_AC3 }; -static int iwl_txq_ctx_activate_free(struct iwl_priv *priv) +/* + * Find first available (lowest unused) Tx Queue, mark it "active". + * Called only when finding queue for aggregation. + * Should never return anything < 7, because they should already + * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6). + */ +static int iwl4965_txq_ctx_activate_free(struct iwl4965_priv *priv) { int txq_id; @@ -4536,55 +4783,65 @@ static int iwl_txq_ctx_activate_free(struct iwl_priv *priv) return -1; } -int iwl_mac_ht_tx_agg_start(struct ieee80211_hw *hw, u8 *da, u16 tid, +int iwl4965_mac_ht_tx_agg_start(struct ieee80211_hw *hw, u8 *da, u16 tid, u16 *start_seq_num) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; int sta_id; int tx_fifo; int txq_id; int ssn = -1; unsigned long flags; - struct iwl_tid_data *tid_data; + struct iwl4965_tid_data *tid_data; DECLARE_MAC_BUF(mac); + /* Determine Tx DMA/FIFO channel for this Traffic ID */ if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo))) tx_fifo = default_tid_to_tx_fifo[tid]; else return -EINVAL; - IWL_WARNING("iwl-AGG iwl_mac_ht_tx_agg_start on da=%s" + IWL_WARNING("iwl-AGG iwl4965_mac_ht_tx_agg_start on da=%s" " tid=%d\n", print_mac(mac, da), tid); - sta_id = iwl_hw_find_station(priv, da); + /* Get index into station table */ + sta_id = iwl4965_hw_find_station(priv, da); if (sta_id == IWL_INVALID_STATION) return -ENXIO; - txq_id = iwl_txq_ctx_activate_free(priv); + /* Find available Tx queue for aggregation */ + txq_id = iwl4965_txq_ctx_activate_free(priv); if (txq_id == -1) return -ENXIO; spin_lock_irqsave(&priv->sta_lock, flags); tid_data = &priv->stations[sta_id].tid[tid]; + + /* Get starting sequence number for 1st frame in block ack window. + * We'll use least signif byte as 1st frame's index into Tx queue. */ ssn = SEQ_TO_SN(tid_data->seq_number); tid_data->agg.txq_id = txq_id; spin_unlock_irqrestore(&priv->sta_lock, flags); *start_seq_num = ssn; + + /* Update driver's link quality manager */ iwl4965_ba_status(priv, tid, BA_STATUS_ACTIVE); + + /* Set up and enable aggregation for selected Tx queue and FIFO */ return iwl4965_tx_queue_agg_enable(priv, txq_id, tx_fifo, sta_id, tid, ssn); } -int iwl_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, u8 *da, u16 tid, +int iwl4965_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, u8 *da, u16 tid, int generator) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; int tx_fifo_id, txq_id, sta_id, ssn = -1; - struct iwl_tid_data *tid_data; + struct iwl4965_tid_data *tid_data; int rc; DECLARE_MAC_BUF(mac); @@ -4598,7 +4855,7 @@ int iwl_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, u8 *da, u16 tid, else return -EINVAL; - sta_id = iwl_hw_find_station(priv, da); + sta_id = iwl4965_hw_find_station(priv, da); if (sta_id == IWL_INVALID_STATION) return -ENXIO; @@ -4613,45 +4870,18 @@ int iwl_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, u8 *da, u16 tid, return rc; iwl4965_ba_status(priv, tid, BA_STATUS_INITIATOR_DELBA); - IWL_DEBUG_INFO("iwl_mac_ht_tx_agg_stop on da=%s tid=%d\n", + IWL_DEBUG_INFO("iwl4965_mac_ht_tx_agg_stop on da=%s tid=%d\n", print_mac(mac, da), tid); return 0; } -int iwl_mac_ht_rx_agg_start(struct ieee80211_hw *hw, u8 *da, - u16 tid, u16 start_seq_num) -{ - struct iwl_priv *priv = hw->priv; - int sta_id; - DECLARE_MAC_BUF(mac); - IWL_WARNING("iwl-AGG iwl_mac_ht_rx_agg_start on da=%s" - " tid=%d\n", print_mac(mac, da), tid); - sta_id = iwl_hw_find_station(priv, da); - iwl4965_sta_modify_add_ba_tid(priv, sta_id, tid, start_seq_num); - return 0; -} - -int iwl_mac_ht_rx_agg_stop(struct ieee80211_hw *hw, u8 *da, - u16 tid, int generator) -{ - struct iwl_priv *priv = hw->priv; - int sta_id; - DECLARE_MAC_BUF(mac); - - IWL_WARNING("iwl-AGG iwl_mac_ht_rx_agg_stop on da=%s tid=%d\n", - print_mac(mac, da), tid); - sta_id = iwl_hw_find_station(priv, da); - iwl4965_sta_modify_del_ba_tid(priv, sta_id, tid); - return 0; -} - -#endif /* CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ /* Set up 4965-specific Rx frame reply handlers */ -void iwl_hw_rx_handler_setup(struct iwl_priv *priv) +void iwl4965_hw_rx_handler_setup(struct iwl4965_priv *priv) { /* Legacy Rx frames */ priv->rx_handlers[REPLY_4965_RX] = iwl4965_rx_reply_rx; @@ -4663,57 +4893,66 @@ void iwl_hw_rx_handler_setup(struct iwl_priv *priv) priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] = iwl4965_rx_missed_beacon_notif; -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba; -#endif /* CONFIG_IWLWIFI_AGG */ -#endif /* CONFIG_IWLWIFI */ +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ } -void iwl_hw_setup_deferred_work(struct iwl_priv *priv) +void iwl4965_hw_setup_deferred_work(struct iwl4965_priv *priv) { INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work); INIT_WORK(&priv->statistics_work, iwl4965_bg_statistics_work); -#ifdef CONFIG_IWLWIFI_SENSITIVITY +#ifdef CONFIG_IWL4965_SENSITIVITY INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work); #endif -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG INIT_WORK(&priv->agg_work, iwl4965_bg_agg_work); -#endif /* CONFIG_IWLWIFI_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ init_timer(&priv->statistics_periodic); priv->statistics_periodic.data = (unsigned long)priv; priv->statistics_periodic.function = iwl4965_bg_statistics_periodic; } -void iwl_hw_cancel_deferred_work(struct iwl_priv *priv) +void iwl4965_hw_cancel_deferred_work(struct iwl4965_priv *priv) { del_timer_sync(&priv->statistics_periodic); cancel_delayed_work(&priv->init_alive_start); } -struct pci_device_id iwl_hw_card_ids[] = { - {0x8086, 0x4229, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, - {0x8086, 0x4230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, +struct pci_device_id iwl4965_hw_card_ids[] = { + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4229)}, + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4230)}, {0} }; -int iwl_eeprom_aqcuire_semaphore(struct iwl_priv *priv) +/* + * The device's EEPROM semaphore prevents conflicts between driver and uCode + * when accessing the EEPROM; each access is a series of pulses to/from the + * EEPROM chip, not a single event, so even reads could conflict if they + * weren't arbitrated by the semaphore. + */ +int iwl4965_eeprom_acquire_semaphore(struct iwl4965_priv *priv) { u16 count; int rc; for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) { - iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, + /* Request semaphore */ + iwl4965_set_bit(priv, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); - rc = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG, + + /* See if we got it */ + rc = iwl4965_poll_bit(priv, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM, CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM, EEPROM_SEM_TIMEOUT); if (rc >= 0) { - IWL_DEBUG_IO("Aqcuired semaphore after %d tries.\n", + IWL_DEBUG_IO("Acquired semaphore after %d tries.\n", count+1); return rc; } @@ -4722,11 +4961,11 @@ int iwl_eeprom_aqcuire_semaphore(struct iwl_priv *priv) return rc; } -inline void iwl_eeprom_release_semaphore(struct iwl_priv *priv) +inline void iwl4965_eeprom_release_semaphore(struct iwl4965_priv *priv) { - iwl_clear_bit(priv, CSR_HW_IF_CONFIG_REG, + iwl4965_clear_bit(priv, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); } -MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); +MODULE_DEVICE_TABLE(pci, iwl4965_hw_card_ids); diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.h b/drivers/net/wireless/iwlwifi/iwl-4965.h index 4c700812b45..78bc148c9f7 100644 --- a/drivers/net/wireless/iwlwifi/iwl-4965.h +++ b/drivers/net/wireless/iwlwifi/iwl-4965.h @@ -23,64 +23,777 @@ * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 * *****************************************************************************/ +/* + * Please use this file (iwl-4965.h) for driver implementation definitions. + * Please use iwl-4965-commands.h for uCode API definitions. + * Please use iwl-4965-hw.h for hardware-related definitions. + */ + #ifndef __iwl_4965_h__ #define __iwl_4965_h__ -struct iwl_priv; -struct sta_ht_info; +#include <linux/pci.h> /* for struct pci_device_id */ +#include <linux/kernel.h> +#include <net/ieee80211_radiotap.h> + +/* Hardware specific file defines the PCI IDs table for that hardware module */ +extern struct pci_device_id iwl4965_hw_card_ids[]; + +#define DRV_NAME "iwl4965" +#include "iwl-4965-hw.h" +#include "iwl-prph.h" +#include "iwl-4965-debug.h" + +/* Default noise level to report when noise measurement is not available. + * This may be because we're: + * 1) Not associated (4965, no beacon statistics being sent to driver) + * 2) Scanning (noise measurement does not apply to associated channel) + * 3) Receiving CCK (3945 delivers noise info only for OFDM frames) + * Use default noise value of -127 ... this is below the range of measurable + * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user. + * Also, -127 works better than 0 when averaging frames with/without + * noise info (e.g. averaging might be done in app); measured dBm values are + * always negative ... using a negative value as the default keeps all + * averages within an s8's (used in some apps) range of negative values. */ +#define IWL_NOISE_MEAS_NOT_AVAILABLE (-127) + +/* Module parameters accessible from iwl-*.c */ +extern int iwl4965_param_hwcrypto; +extern int iwl4965_param_queues_num; +extern int iwl4965_param_amsdu_size_8K; + +enum iwl4965_antenna { + IWL_ANTENNA_DIVERSITY, + IWL_ANTENNA_MAIN, + IWL_ANTENNA_AUX +}; + +/* + * RTS threshold here is total size [2347] minus 4 FCS bytes + * Per spec: + * a value of 0 means RTS on all data/management packets + * a value > max MSDU size means no RTS + * else RTS for data/management frames where MPDU is larger + * than RTS value. + */ +#define DEFAULT_RTS_THRESHOLD 2347U +#define MIN_RTS_THRESHOLD 0U +#define MAX_RTS_THRESHOLD 2347U +#define MAX_MSDU_SIZE 2304U +#define MAX_MPDU_SIZE 2346U +#define DEFAULT_BEACON_INTERVAL 100U +#define DEFAULT_SHORT_RETRY_LIMIT 7U +#define DEFAULT_LONG_RETRY_LIMIT 4U + +struct iwl4965_rx_mem_buffer { + dma_addr_t dma_addr; + struct sk_buff *skb; + struct list_head list; +}; + +/* + * Generic queue structure + * + * Contains common data for Rx and Tx queues + */ +struct iwl4965_queue { + int n_bd; /* number of BDs in this queue */ + int write_ptr; /* 1-st empty entry (index) host_w*/ + int read_ptr; /* last used entry (index) host_r*/ + dma_addr_t dma_addr; /* physical addr for BD's */ + int n_window; /* safe queue window */ + u32 id; + int low_mark; /* low watermark, resume queue if free + * space more than this */ + int high_mark; /* high watermark, stop queue if free + * space less than this */ +} __attribute__ ((packed)); + +#define MAX_NUM_OF_TBS (20) + +/* One for each TFD */ +struct iwl4965_tx_info { + struct ieee80211_tx_status status; + struct sk_buff *skb[MAX_NUM_OF_TBS]; +}; + +/** + * struct iwl4965_tx_queue - Tx Queue for DMA + * @q: generic Rx/Tx queue descriptor + * @bd: base of circular buffer of TFDs + * @cmd: array of command/Tx buffers + * @dma_addr_cmd: physical address of cmd/tx buffer array + * @txb: array of per-TFD driver data + * @need_update: indicates need to update read/write index + * @sched_retry: indicates queue is high-throughput aggregation (HT AGG) enabled + * + * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame + * descriptors) and required locking structures. + */ +struct iwl4965_tx_queue { + struct iwl4965_queue q; + struct iwl4965_tfd_frame *bd; + struct iwl4965_cmd *cmd; + dma_addr_t dma_addr_cmd; + struct iwl4965_tx_info *txb; + int need_update; + int sched_retry; + int active; +}; + +#define IWL_NUM_SCAN_RATES (2) + +struct iwl4965_channel_tgd_info { + u8 type; + s8 max_power; +}; + +struct iwl4965_channel_tgh_info { + s64 last_radar_time; +}; + +/* current Tx power values to use, one for each rate for each channel. + * requested power is limited by: + * -- regulatory EEPROM limits for this channel + * -- hardware capabilities (clip-powers) + * -- spectrum management + * -- user preference (e.g. iwconfig) + * when requested power is set, base power index must also be set. */ +struct iwl4965_channel_power_info { + struct iwl4965_tx_power tpc; /* actual radio and DSP gain settings */ + s8 power_table_index; /* actual (compenst'd) index into gain table */ + s8 base_power_index; /* gain index for power at factory temp. */ + s8 requested_power; /* power (dBm) requested for this chnl/rate */ +}; + +/* current scan Tx power values to use, one for each scan rate for each + * channel. */ +struct iwl4965_scan_power_info { + struct iwl4965_tx_power tpc; /* actual radio and DSP gain settings */ + s8 power_table_index; /* actual (compenst'd) index into gain table */ + s8 requested_power; /* scan pwr (dBm) requested for chnl/rate */ +}; + +/* For fat_extension_channel */ +enum { + HT_IE_EXT_CHANNEL_NONE = 0, + HT_IE_EXT_CHANNEL_ABOVE, + HT_IE_EXT_CHANNEL_INVALID, + HT_IE_EXT_CHANNEL_BELOW, + HT_IE_EXT_CHANNEL_MAX +}; + +/* + * One for each channel, holds all channel setup data + * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant + * with one another! + */ +#define IWL4965_MAX_RATE (33) + +struct iwl4965_channel_info { + struct iwl4965_channel_tgd_info tgd; + struct iwl4965_channel_tgh_info tgh; + struct iwl4965_eeprom_channel eeprom; /* EEPROM regulatory limit */ + struct iwl4965_eeprom_channel fat_eeprom; /* EEPROM regulatory limit for + * FAT channel */ + + u8 channel; /* channel number */ + u8 flags; /* flags copied from EEPROM */ + s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */ + s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */ + s8 min_power; /* always 0 */ + s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */ + + u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */ + u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */ + u8 phymode; /* MODE_IEEE80211{A,B,G} */ + + /* Radio/DSP gain settings for each "normal" data Tx rate. + * These include, in addition to RF and DSP gain, a few fields for + * remembering/modifying gain settings (indexes). */ + struct iwl4965_channel_power_info power_info[IWL4965_MAX_RATE]; + + /* FAT channel info */ + s8 fat_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */ + s8 fat_curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) */ + s8 fat_min_power; /* always 0 */ + s8 fat_scan_power; /* (dBm) eeprom, direct scans, any rate */ + u8 fat_flags; /* flags copied from EEPROM */ + u8 fat_extension_channel; /* HT_IE_EXT_CHANNEL_* */ + + /* Radio/DSP gain settings for each scan rate, for directed scans. */ + struct iwl4965_scan_power_info scan_pwr_info[IWL_NUM_SCAN_RATES]; +}; + +struct iwl4965_clip_group { + /* maximum power level to prevent clipping for each rate, derived by + * us from this band's saturation power in EEPROM */ + const s8 clip_powers[IWL_MAX_RATES]; +}; + +#include "iwl-4965-rs.h" + +#define IWL_TX_FIFO_AC0 0 +#define IWL_TX_FIFO_AC1 1 +#define IWL_TX_FIFO_AC2 2 +#define IWL_TX_FIFO_AC3 3 +#define IWL_TX_FIFO_HCCA_1 5 +#define IWL_TX_FIFO_HCCA_2 6 +#define IWL_TX_FIFO_NONE 7 + +/* Minimum number of queues. MAX_NUM is defined in hw specific files */ +#define IWL_MIN_NUM_QUEUES 4 + +/* Power management (not Tx power) structures */ + +struct iwl4965_power_vec_entry { + struct iwl4965_powertable_cmd cmd; + u8 no_dtim; +}; +#define IWL_POWER_RANGE_0 (0) +#define IWL_POWER_RANGE_1 (1) + +#define IWL_POWER_MODE_CAM 0x00 /* Continuously Aware Mode, always on */ +#define IWL_POWER_INDEX_3 0x03 +#define IWL_POWER_INDEX_5 0x05 +#define IWL_POWER_AC 0x06 +#define IWL_POWER_BATTERY 0x07 +#define IWL_POWER_LIMIT 0x07 +#define IWL_POWER_MASK 0x0F +#define IWL_POWER_ENABLED 0x10 +#define IWL_POWER_LEVEL(x) ((x) & IWL_POWER_MASK) + +struct iwl4965_power_mgr { + spinlock_t lock; + struct iwl4965_power_vec_entry pwr_range_0[IWL_POWER_AC]; + struct iwl4965_power_vec_entry pwr_range_1[IWL_POWER_AC]; + u8 active_index; + u32 dtim_val; +}; + +#define IEEE80211_DATA_LEN 2304 +#define IEEE80211_4ADDR_LEN 30 +#define IEEE80211_HLEN (IEEE80211_4ADDR_LEN) +#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN) + +struct iwl4965_frame { + union { + struct ieee80211_hdr frame; + struct iwl4965_tx_beacon_cmd beacon; + u8 raw[IEEE80211_FRAME_LEN]; + u8 cmd[360]; + } u; + struct list_head list; +}; + +#define SEQ_TO_QUEUE(x) ((x >> 8) & 0xbf) +#define QUEUE_TO_SEQ(x) ((x & 0xbf) << 8) +#define SEQ_TO_INDEX(x) (x & 0xff) +#define INDEX_TO_SEQ(x) (x & 0xff) +#define SEQ_HUGE_FRAME (0x4000) +#define SEQ_RX_FRAME __constant_cpu_to_le16(0x8000) +#define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4) +#define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ) +#define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4) + +enum { + /* CMD_SIZE_NORMAL = 0, */ + CMD_SIZE_HUGE = (1 << 0), + /* CMD_SYNC = 0, */ + CMD_ASYNC = (1 << 1), + /* CMD_NO_SKB = 0, */ + CMD_WANT_SKB = (1 << 2), +}; + +struct iwl4965_cmd; +struct iwl4965_priv; + +struct iwl4965_cmd_meta { + struct iwl4965_cmd_meta *source; + union { + struct sk_buff *skb; + int (*callback)(struct iwl4965_priv *priv, + struct iwl4965_cmd *cmd, struct sk_buff *skb); + } __attribute__ ((packed)) u; + + /* The CMD_SIZE_HUGE flag bit indicates that the command + * structure is stored at the end of the shared queue memory. */ + u32 flags; + +} __attribute__ ((packed)); + +/** + * struct iwl4965_cmd + * + * For allocation of the command and tx queues, this establishes the overall + * size of the largest command we send to uCode, except for a scan command + * (which is relatively huge; space is allocated separately). + */ +struct iwl4965_cmd { + struct iwl4965_cmd_meta meta; /* driver data */ + struct iwl4965_cmd_header hdr; /* uCode API */ + union { + struct iwl4965_addsta_cmd addsta; + struct iwl4965_led_cmd led; + u32 flags; + u8 val8; + u16 val16; + u32 val32; + struct iwl4965_bt_cmd bt; + struct iwl4965_rxon_time_cmd rxon_time; + struct iwl4965_powertable_cmd powertable; + struct iwl4965_qosparam_cmd qosparam; + struct iwl4965_tx_cmd tx; + struct iwl4965_tx_beacon_cmd tx_beacon; + struct iwl4965_rxon_assoc_cmd rxon_assoc; + u8 *indirect; + u8 payload[360]; + } __attribute__ ((packed)) cmd; +} __attribute__ ((packed)); + +struct iwl4965_host_cmd { + u8 id; + u16 len; + struct iwl4965_cmd_meta meta; + const void *data; +}; + +#define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl4965_cmd) - \ + sizeof(struct iwl4965_cmd_meta)) + +/* + * RX related structures and functions + */ +#define RX_FREE_BUFFERS 64 +#define RX_LOW_WATERMARK 8 + +#define SUP_RATE_11A_MAX_NUM_CHANNELS 8 +#define SUP_RATE_11B_MAX_NUM_CHANNELS 4 +#define SUP_RATE_11G_MAX_NUM_CHANNELS 12 + +/** + * struct iwl4965_rx_queue - Rx queue + * @processed: Internal index to last handled Rx packet + * @read: Shared index to newest available Rx buffer + * @write: Shared index to oldest written Rx packet + * @free_count: Number of pre-allocated buffers in rx_free + * @rx_free: list of free SKBs for use + * @rx_used: List of Rx buffers with no SKB + * @need_update: flag to indicate we need to update read/write index + * + * NOTE: rx_free and rx_used are used as a FIFO for iwl4965_rx_mem_buffers + */ +struct iwl4965_rx_queue { + __le32 *bd; + dma_addr_t dma_addr; + struct iwl4965_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS]; + struct iwl4965_rx_mem_buffer *queue[RX_QUEUE_SIZE]; + u32 processed; + u32 read; + u32 write; + u32 free_count; + struct list_head rx_free; + struct list_head rx_used; + int need_update; + spinlock_t lock; +}; + +#define IWL_SUPPORTED_RATES_IE_LEN 8 + +#define SCAN_INTERVAL 100 + +#define MAX_A_CHANNELS 252 +#define MIN_A_CHANNELS 7 + +#define MAX_B_CHANNELS 14 +#define MIN_B_CHANNELS 1 + +#define STATUS_HCMD_ACTIVE 0 /* host command in progress */ +#define STATUS_INT_ENABLED 1 +#define STATUS_RF_KILL_HW 2 +#define STATUS_RF_KILL_SW 3 +#define STATUS_INIT 4 +#define STATUS_ALIVE 5 +#define STATUS_READY 6 +#define STATUS_TEMPERATURE 7 +#define STATUS_GEO_CONFIGURED 8 +#define STATUS_EXIT_PENDING 9 +#define STATUS_IN_SUSPEND 10 +#define STATUS_STATISTICS 11 +#define STATUS_SCANNING 12 +#define STATUS_SCAN_ABORTING 13 +#define STATUS_SCAN_HW 14 +#define STATUS_POWER_PMI 15 +#define STATUS_FW_ERROR 16 +#define STATUS_CONF_PENDING 17 + +#define MAX_TID_COUNT 9 + +#define IWL_INVALID_RATE 0xFF +#define IWL_INVALID_VALUE -1 + +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG +/** + * struct iwl4965_ht_agg -- aggregation status while waiting for block-ack + * @txq_id: Tx queue used for Tx attempt + * @frame_count: # frames attempted by Tx command + * @wait_for_ba: Expect block-ack before next Tx reply + * @start_idx: Index of 1st Transmit Frame Descriptor (TFD) in Tx window + * @bitmap0: Low order bitmap, one bit for each frame pending ACK in Tx window + * @bitmap1: High order, one bit for each frame pending ACK in Tx window + * @rate_n_flags: Rate at which Tx was attempted + * + * If REPLY_TX indicates that aggregation was attempted, driver must wait + * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info + * until block ack arrives. + */ +struct iwl4965_ht_agg { + u16 txq_id; + u16 frame_count; + u16 wait_for_ba; + u16 start_idx; + u32 bitmap0; + u32 bitmap1; + u32 rate_n_flags; +}; +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ + +struct iwl4965_tid_data { + u16 seq_number; +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG + struct iwl4965_ht_agg agg; +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ +}; + +struct iwl4965_hw_key { + enum ieee80211_key_alg alg; + int keylen; + u8 key[32]; +}; + +union iwl4965_ht_rate_supp { + u16 rates; + struct { + u8 siso_rate; + u8 mimo_rate; + }; +}; + +#ifdef CONFIG_IWL4965_HT +#define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3) +#define CFG_HT_MPDU_DENSITY_2USEC (0x5) +#define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_2USEC + +struct iwl_ht_info { + /* self configuration data */ + u8 is_ht; + u8 supported_chan_width; + u16 tx_mimo_ps_mode; + u8 is_green_field; + u8 sgf; /* HT_SHORT_GI_* short guard interval */ + u8 max_amsdu_size; + u8 ampdu_factor; + u8 mpdu_density; + u8 supp_mcs_set[16]; + /* BSS related data */ + u8 control_channel; + u8 extension_chan_offset; + u8 tx_chan_width; + u8 ht_protection; + u8 non_GF_STA_present; +}; +#endif /*CONFIG_IWL4965_HT */ + +#ifdef CONFIG_IWL4965_QOS + +union iwl4965_qos_capabity { + struct { + u8 edca_count:4; /* bit 0-3 */ + u8 q_ack:1; /* bit 4 */ + u8 queue_request:1; /* bit 5 */ + u8 txop_request:1; /* bit 6 */ + u8 reserved:1; /* bit 7 */ + } q_AP; + struct { + u8 acvo_APSD:1; /* bit 0 */ + u8 acvi_APSD:1; /* bit 1 */ + u8 ac_bk_APSD:1; /* bit 2 */ + u8 ac_be_APSD:1; /* bit 3 */ + u8 q_ack:1; /* bit 4 */ + u8 max_len:2; /* bit 5-6 */ + u8 more_data_ack:1; /* bit 7 */ + } q_STA; + u8 val; +}; + +/* QoS structures */ +struct iwl4965_qos_info { + int qos_enable; + int qos_active; + union iwl4965_qos_capabity qos_cap; + struct iwl4965_qosparam_cmd def_qos_parm; +}; +#endif /*CONFIG_IWL4965_QOS */ + +#define STA_PS_STATUS_WAKE 0 +#define STA_PS_STATUS_SLEEP 1 + +struct iwl4965_station_entry { + struct iwl4965_addsta_cmd sta; + struct iwl4965_tid_data tid[MAX_TID_COUNT]; + u8 used; + u8 ps_status; + struct iwl4965_hw_key keyinfo; +}; + +/* one for each uCode image (inst/data, boot/init/runtime) */ +struct fw_desc { + void *v_addr; /* access by driver */ + dma_addr_t p_addr; /* access by card's busmaster DMA */ + u32 len; /* bytes */ +}; + +/* uCode file layout */ +struct iwl4965_ucode { + __le32 ver; /* major/minor/subminor */ + __le32 inst_size; /* bytes of runtime instructions */ + __le32 data_size; /* bytes of runtime data */ + __le32 init_size; /* bytes of initialization instructions */ + __le32 init_data_size; /* bytes of initialization data */ + __le32 boot_size; /* bytes of bootstrap instructions */ + u8 data[0]; /* data in same order as "size" elements */ +}; + +#define IWL_IBSS_MAC_HASH_SIZE 32 + +struct iwl4965_ibss_seq { + u8 mac[ETH_ALEN]; + u16 seq_num; + u16 frag_num; + unsigned long packet_time; + struct list_head list; +}; + +/** + * struct iwl4965_driver_hw_info + * @max_txq_num: Max # Tx queues supported + * @ac_queue_count: # Tx queues for EDCA Access Categories (AC) + * @tx_cmd_len: Size of Tx command (but not including frame itself) + * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2) + * @rx_buffer_size: + * @max_rxq_log: Log-base-2 of max_rxq_size + * @max_stations: + * @bcast_sta_id: + * @shared_virt: Pointer to driver/uCode shared Tx Byte Counts and Rx status + * @shared_phys: Physical Pointer to Tx Byte Counts and Rx status + */ +struct iwl4965_driver_hw_info { + u16 max_txq_num; + u16 ac_queue_count; + u16 tx_cmd_len; + u16 max_rxq_size; + u32 rx_buf_size; + u32 max_pkt_size; + u16 max_rxq_log; + u8 max_stations; + u8 bcast_sta_id; + void *shared_virt; + dma_addr_t shared_phys; +}; + +#define HT_SHORT_GI_20MHZ_ONLY (1 << 0) +#define HT_SHORT_GI_40MHZ_ONLY (1 << 1) + + +#define IWL_RX_HDR(x) ((struct iwl4965_rx_frame_hdr *)(\ + x->u.rx_frame.stats.payload + \ + x->u.rx_frame.stats.phy_count)) +#define IWL_RX_END(x) ((struct iwl4965_rx_frame_end *)(\ + IWL_RX_HDR(x)->payload + \ + le16_to_cpu(IWL_RX_HDR(x)->len))) +#define IWL_RX_STATS(x) (&x->u.rx_frame.stats) +#define IWL_RX_DATA(x) (IWL_RX_HDR(x)->payload) + + +/****************************************************************************** + * + * Functions implemented in iwl-base.c which are forward declared here + * for use by iwl-*.c + * + *****************************************************************************/ +struct iwl4965_addsta_cmd; +extern int iwl4965_send_add_station(struct iwl4965_priv *priv, + struct iwl4965_addsta_cmd *sta, u8 flags); +extern u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr, + int is_ap, u8 flags, void *ht_data); +extern int iwl4965_is_network_packet(struct iwl4965_priv *priv, + struct ieee80211_hdr *header); +extern int iwl4965_power_init_handle(struct iwl4965_priv *priv); +extern int iwl4965_eeprom_init(struct iwl4965_priv *priv); +#ifdef CONFIG_IWL4965_DEBUG +extern void iwl4965_report_frame(struct iwl4965_priv *priv, + struct iwl4965_rx_packet *pkt, + struct ieee80211_hdr *header, int group100); +#else +static inline void iwl4965_report_frame(struct iwl4965_priv *priv, + struct iwl4965_rx_packet *pkt, + struct ieee80211_hdr *header, + int group100) {} +#endif +extern void iwl4965_handle_data_packet_monitor(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb, + void *data, short len, + struct ieee80211_rx_status *stats, + u16 phy_flags); +extern int iwl4965_is_duplicate_packet(struct iwl4965_priv *priv, + struct ieee80211_hdr *header); +extern int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv); +extern void iwl4965_rx_queue_reset(struct iwl4965_priv *priv, + struct iwl4965_rx_queue *rxq); +extern int iwl4965_calc_db_from_ratio(int sig_ratio); +extern int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm); +extern int iwl4965_tx_queue_init(struct iwl4965_priv *priv, + struct iwl4965_tx_queue *txq, int count, u32 id); +extern void iwl4965_rx_replenish(void *data); +extern void iwl4965_tx_queue_free(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq); +extern int iwl4965_send_cmd_pdu(struct iwl4965_priv *priv, u8 id, u16 len, + const void *data); +extern int __must_check iwl4965_send_cmd(struct iwl4965_priv *priv, + struct iwl4965_host_cmd *cmd); +extern unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv, + struct ieee80211_hdr *hdr, + const u8 *dest, int left); +extern int iwl4965_rx_queue_update_write_ptr(struct iwl4965_priv *priv, + struct iwl4965_rx_queue *q); +extern int iwl4965_send_statistics_request(struct iwl4965_priv *priv); +extern void iwl4965_set_decrypted_flag(struct iwl4965_priv *priv, struct sk_buff *skb, + u32 decrypt_res, + struct ieee80211_rx_status *stats); +extern __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr); + +extern const u8 iwl4965_broadcast_addr[ETH_ALEN]; + +/* + * Currently used by iwl-3945-rs... look at restructuring so that it doesn't + * call this... todo... fix that. +*/ +extern u8 iwl4965_sync_station(struct iwl4965_priv *priv, int sta_id, + u16 tx_rate, u8 flags); + +/****************************************************************************** + * + * Functions implemented in iwl-[34]*.c which are forward declared here + * for use by iwl-base.c + * + * NOTE: The implementation of these functions are hardware specific + * which is why they are in the hardware specific files (vs. iwl-base.c) + * + * Naming convention -- + * iwl4965_ <-- Its part of iwlwifi (should be changed to iwl4965_) + * iwl4965_hw_ <-- Hardware specific (implemented in iwl-XXXX.c by all HW) + * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX) + * iwl4965_bg_ <-- Called from work queue context + * iwl4965_mac_ <-- mac80211 callback + * + ****************************************************************************/ +extern void iwl4965_hw_rx_handler_setup(struct iwl4965_priv *priv); +extern void iwl4965_hw_setup_deferred_work(struct iwl4965_priv *priv); +extern void iwl4965_hw_cancel_deferred_work(struct iwl4965_priv *priv); +extern int iwl4965_hw_rxq_stop(struct iwl4965_priv *priv); +extern int iwl4965_hw_set_hw_setting(struct iwl4965_priv *priv); +extern int iwl4965_hw_nic_init(struct iwl4965_priv *priv); +extern int iwl4965_hw_nic_stop_master(struct iwl4965_priv *priv); +extern void iwl4965_hw_txq_ctx_free(struct iwl4965_priv *priv); +extern void iwl4965_hw_txq_ctx_stop(struct iwl4965_priv *priv); +extern int iwl4965_hw_nic_reset(struct iwl4965_priv *priv); +extern int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl4965_priv *priv, void *tfd, + dma_addr_t addr, u16 len); +extern int iwl4965_hw_txq_free_tfd(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq); +extern int iwl4965_hw_get_temperature(struct iwl4965_priv *priv); +extern int iwl4965_hw_tx_queue_init(struct iwl4965_priv *priv, + struct iwl4965_tx_queue *txq); +extern unsigned int iwl4965_hw_get_beacon_cmd(struct iwl4965_priv *priv, + struct iwl4965_frame *frame, u8 rate); +extern int iwl4965_hw_get_rx_read(struct iwl4965_priv *priv); +extern void iwl4965_hw_build_tx_cmd_rate(struct iwl4965_priv *priv, + struct iwl4965_cmd *cmd, + struct ieee80211_tx_control *ctrl, + struct ieee80211_hdr *hdr, + int sta_id, int tx_id); +extern int iwl4965_hw_reg_send_txpower(struct iwl4965_priv *priv); +extern int iwl4965_hw_reg_set_txpower(struct iwl4965_priv *priv, s8 power); +extern void iwl4965_hw_rx_statistics(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb); +extern void iwl4965_disable_events(struct iwl4965_priv *priv); +extern int iwl4965_get_temperature(const struct iwl4965_priv *priv); + +/** + * iwl4965_hw_find_station - Find station id for a given BSSID + * @bssid: MAC address of station ID to find + * + * NOTE: This should not be hardware specific but the code has + * not yet been merged into a single common layer for managing the + * station tables. + */ +extern u8 iwl4965_hw_find_station(struct iwl4965_priv *priv, const u8 *bssid); + +extern int iwl4965_hw_channel_switch(struct iwl4965_priv *priv, u16 channel); +extern int iwl4965_tx_queue_reclaim(struct iwl4965_priv *priv, int txq_id, int index); + +struct iwl4965_priv; /* * Forward declare iwl-4965.c functions for iwl-base.c */ -extern int iwl_eeprom_aqcuire_semaphore(struct iwl_priv *priv); -extern void iwl_eeprom_release_semaphore(struct iwl_priv *priv); +extern int iwl4965_eeprom_acquire_semaphore(struct iwl4965_priv *priv); +extern void iwl4965_eeprom_release_semaphore(struct iwl4965_priv *priv); -extern int iwl4965_tx_queue_update_wr_ptr(struct iwl_priv *priv, - struct iwl_tx_queue *txq, +extern int iwl4965_tx_queue_update_wr_ptr(struct iwl4965_priv *priv, + struct iwl4965_tx_queue *txq, u16 byte_cnt); -extern void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, +extern void iwl4965_add_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap); -extern void iwl4965_set_rxon_ht(struct iwl_priv *priv, - struct sta_ht_info *ht_info); - -extern void iwl4965_set_rxon_chain(struct iwl_priv *priv); -extern int iwl4965_tx_cmd(struct iwl_priv *priv, struct iwl_cmd *out_cmd, - u8 sta_id, dma_addr_t txcmd_phys, - struct ieee80211_hdr *hdr, u8 hdr_len, - struct ieee80211_tx_control *ctrl, void *sta_in); -extern int iwl4965_init_hw_rates(struct iwl_priv *priv, - struct ieee80211_rate *rates); -extern int iwl4965_alive_notify(struct iwl_priv *priv); -extern void iwl4965_update_rate_scaling(struct iwl_priv *priv, u8 mode); -extern void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index); - -extern void iwl4965_chain_noise_reset(struct iwl_priv *priv); -extern void iwl4965_init_sensitivity(struct iwl_priv *priv, u8 flags, +extern void iwl4965_set_rxon_chain(struct iwl4965_priv *priv); +extern int iwl4965_alive_notify(struct iwl4965_priv *priv); +extern void iwl4965_update_rate_scaling(struct iwl4965_priv *priv, u8 mode); +extern void iwl4965_chain_noise_reset(struct iwl4965_priv *priv); +extern void iwl4965_init_sensitivity(struct iwl4965_priv *priv, u8 flags, u8 force); -extern int iwl4965_set_fat_chan_info(struct iwl_priv *priv, int phymode, +extern int iwl4965_set_fat_chan_info(struct iwl4965_priv *priv, int phymode, u16 channel, - const struct iwl_eeprom_channel *eeprom_ch, + const struct iwl4965_eeprom_channel *eeprom_ch, u8 fat_extension_channel); -extern void iwl4965_rf_kill_ct_config(struct iwl_priv *priv); +extern void iwl4965_rf_kill_ct_config(struct iwl4965_priv *priv); -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG -extern int iwl_mac_ht_tx_agg_start(struct ieee80211_hw *hw, u8 *da, +#ifdef CONFIG_IWL4965_HT +extern void iwl4965_init_ht_hw_capab(struct ieee80211_ht_info *ht_info, + int mode); +extern void iwl4965_set_rxon_ht(struct iwl4965_priv *priv, + struct iwl_ht_info *ht_info); +extern void iwl4965_set_ht_add_station(struct iwl4965_priv *priv, u8 index, + struct ieee80211_ht_info *sta_ht_inf); +extern int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw, + enum ieee80211_ampdu_mlme_action action, + const u8 *addr, u16 tid, u16 ssn); +#ifdef CONFIG_IWL4965_HT_AGG +extern int iwl4965_mac_ht_tx_agg_start(struct ieee80211_hw *hw, u8 *da, u16 tid, u16 *start_seq_num); -extern int iwl_mac_ht_rx_agg_start(struct ieee80211_hw *hw, u8 *da, - u16 tid, u16 start_seq_num); -extern int iwl_mac_ht_rx_agg_stop(struct ieee80211_hw *hw, u8 *da, +extern int iwl4965_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, u8 *da, u16 tid, int generator); -extern int iwl_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, u8 *da, - u16 tid, int generator); -extern void iwl4965_turn_off_agg(struct iwl_priv *priv, u8 tid); -#endif /* CONFIG_IWLWIFI_HT_AGG */ -#endif /*CONFIG_IWLWIFI_HT */ +extern void iwl4965_turn_off_agg(struct iwl4965_priv *priv, u8 tid); +extern void iwl4965_tl_get_stats(struct iwl4965_priv *priv, + struct ieee80211_hdr *hdr); +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /*CONFIG_IWL4965_HT */ /* Structures, enum, and defines specific to the 4965 */ #define IWL4965_KW_SIZE 0x1000 /*4k */ -struct iwl_kw { +struct iwl4965_kw { dma_addr_t dma_addr; void *v_addr; size_t size; @@ -120,21 +833,9 @@ struct iwl_kw { #define NRG_NUM_PREV_STAT_L 20 #define NUM_RX_CHAINS (3) -#define TX_POWER_IWL_ILLEGAL_VDET -100000 #define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000 -#define TX_POWER_IWL_CLOSED_LOOP_MIN_POWER 18 -#define TX_POWER_IWL_CLOSED_LOOP_MAX_POWER 34 -#define TX_POWER_IWL_VDET_SLOPE_BELOW_NOMINAL 17 -#define TX_POWER_IWL_VDET_SLOPE_ABOVE_NOMINAL 20 -#define TX_POWER_IWL_NOMINAL_POWER 26 -#define TX_POWER_IWL_CLOSED_LOOP_ITERATION_LIMIT 1 -#define TX_POWER_IWL_VOLTAGE_CODES_PER_03V 7 -#define TX_POWER_IWL_DEGREES_PER_VDET_CODE 11 -#define IWL_TX_POWER_MAX_NUM_PA_MEASUREMENTS 1 -#define IWL_TX_POWER_CCK_COMPENSATION_B_STEP (9) -#define IWL_TX_POWER_CCK_COMPENSATION_C_STEP (5) - -struct iwl_traffic_load { + +struct iwl4965_traffic_load { unsigned long time_stamp; u32 packet_count[TID_QUEUE_MAX_SIZE]; u8 queue_count; @@ -142,8 +843,13 @@ struct iwl_traffic_load { u32 total; }; -#ifdef CONFIG_IWLWIFI_HT_AGG -struct iwl_agg_control { +#ifdef CONFIG_IWL4965_HT_AGG +/** + * struct iwl4965_agg_control + * @requested_ba: bit map of tids requesting aggregation/block-ack + * @granted_ba: bit map of tids granted aggregation/block-ack + */ +struct iwl4965_agg_control { unsigned long next_retry; u32 wait_for_agg_status; u32 tid_retry; @@ -152,13 +858,13 @@ struct iwl_agg_control { u8 auto_agg; u32 tid_traffic_load_threshold; u32 ba_timeout; - struct iwl_traffic_load traffic_load[TID_MAX_LOAD_COUNT]; + struct iwl4965_traffic_load traffic_load[TID_MAX_LOAD_COUNT]; }; -#endif /*CONFIG_IWLWIFI_HT_AGG */ +#endif /*CONFIG_IWL4965_HT_AGG */ -struct iwl_lq_mngr { -#ifdef CONFIG_IWLWIFI_HT_AGG - struct iwl_agg_control agg_ctrl; +struct iwl4965_lq_mngr { +#ifdef CONFIG_IWL4965_HT_AGG + struct iwl4965_agg_control agg_ctrl; #endif spinlock_t lock; s32 max_window_size; @@ -179,22 +885,6 @@ struct iwl_lq_mngr { #define CAL_NUM_OF_BEACONS 20 #define MAXIMUM_ALLOWED_PATHLOSS 15 -/* Param table within SENSITIVITY_CMD */ -#define HD_MIN_ENERGY_CCK_DET_INDEX (0) -#define HD_MIN_ENERGY_OFDM_DET_INDEX (1) -#define HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX (2) -#define HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX (3) -#define HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX (4) -#define HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX (5) -#define HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX (6) -#define HD_BARKER_CORR_TH_ADD_MIN_INDEX (7) -#define HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX (8) -#define HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX (9) -#define HD_OFDM_ENERGY_TH_IN_INDEX (10) - -#define SENSITIVITY_CMD_CONTROL_DEFAULT_TABLE __constant_cpu_to_le16(0) -#define SENSITIVITY_CMD_CONTROL_WORK_TABLE __constant_cpu_to_le16(1) - #define CHAIN_NOISE_MAX_DELTA_GAIN_CODE 3 #define MAX_FA_OFDM 50 @@ -222,8 +912,6 @@ struct iwl_lq_mngr { #define AUTO_CORR_STEP_CCK 3 #define AUTO_CORR_MAX_TH_CCK 160 -#define NRG_ALG 0 -#define AUTO_CORR_ALG 1 #define NRG_DIFF 2 #define NRG_STEP_CCK 2 #define NRG_MARGIN 8 @@ -239,24 +927,24 @@ struct iwl_lq_mngr { #define IN_BAND_FILTER 0xFF #define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF -enum iwl_false_alarm_state { +enum iwl4965_false_alarm_state { IWL_FA_TOO_MANY = 0, IWL_FA_TOO_FEW = 1, IWL_FA_GOOD_RANGE = 2, }; -enum iwl_chain_noise_state { +enum iwl4965_chain_noise_state { IWL_CHAIN_NOISE_ALIVE = 0, /* must be 0 */ IWL_CHAIN_NOISE_ACCUMULATE = 1, IWL_CHAIN_NOISE_CALIBRATED = 2, }; -enum iwl_sensitivity_state { +enum iwl4965_sensitivity_state { IWL_SENS_CALIB_ALLOWED = 0, IWL_SENS_CALIB_NEED_REINIT = 1, }; -enum iwl_calib_enabled_state { +enum iwl4965_calib_enabled_state { IWL_CALIB_DISABLED = 0, /* must be 0 */ IWL_CALIB_ENABLED = 1, }; @@ -271,7 +959,7 @@ struct statistics_general_data { }; /* Sensitivity calib data */ -struct iwl_sensitivity_data { +struct iwl4965_sensitivity_data { u32 auto_corr_ofdm; u32 auto_corr_ofdm_mrc; u32 auto_corr_ofdm_x1; @@ -300,7 +988,7 @@ struct iwl_sensitivity_data { }; /* Chain noise (differential Rx gain) calib data */ -struct iwl_chain_noise_data { +struct iwl4965_chain_noise_data { u8 state; u16 beacon_count; u32 chain_noise_a; @@ -314,28 +1002,323 @@ struct iwl_chain_noise_data { u8 radio_write; }; -/* IWL4965 */ -#define RATE_MCS_CODE_MSK 0x7 -#define RATE_MCS_MIMO_POS 3 -#define RATE_MCS_MIMO_MSK 0x8 -#define RATE_MCS_HT_DUP_POS 5 -#define RATE_MCS_HT_DUP_MSK 0x20 -#define RATE_MCS_FLAGS_POS 8 -#define RATE_MCS_HT_POS 8 -#define RATE_MCS_HT_MSK 0x100 -#define RATE_MCS_CCK_POS 9 -#define RATE_MCS_CCK_MSK 0x200 -#define RATE_MCS_GF_POS 10 -#define RATE_MCS_GF_MSK 0x400 - -#define RATE_MCS_FAT_POS 11 -#define RATE_MCS_FAT_MSK 0x800 -#define RATE_MCS_DUP_POS 12 -#define RATE_MCS_DUP_MSK 0x1000 -#define RATE_MCS_SGI_POS 13 -#define RATE_MCS_SGI_MSK 0x2000 - -#define EEPROM_SEM_TIMEOUT 10 -#define EEPROM_SEM_RETRY_LIMIT 1000 - -#endif /* __iwl_4965_h__ */ +#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */ +#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */ + + +#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT + +enum { + MEASUREMENT_READY = (1 << 0), + MEASUREMENT_ACTIVE = (1 << 1), +}; + +#endif + +struct iwl4965_priv { + + /* ieee device used by generic ieee processing code */ + struct ieee80211_hw *hw; + struct ieee80211_channel *ieee_channels; + struct ieee80211_rate *ieee_rates; + + /* temporary frame storage list */ + struct list_head free_frames; + int frames_count; + + u8 phymode; + int alloc_rxb_skb; + bool add_radiotap; + + void (*rx_handlers[REPLY_MAX])(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb); + + const struct ieee80211_hw_mode *modes; + +#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT + /* spectrum measurement report caching */ + struct iwl4965_spectrum_notification measure_report; + u8 measurement_status; +#endif + /* ucode beacon time */ + u32 ucode_beacon_time; + + /* we allocate array of iwl4965_channel_info for NIC's valid channels. + * Access via channel # using indirect index array */ + struct iwl4965_channel_info *channel_info; /* channel info array */ + u8 channel_count; /* # of channels */ + + /* each calibration channel group in the EEPROM has a derived + * clip setting for each rate. */ + const struct iwl4965_clip_group clip_groups[5]; + + /* thermal calibration */ + s32 temperature; /* degrees Kelvin */ + s32 last_temperature; + + /* Scan related variables */ + unsigned long last_scan_jiffies; + unsigned long next_scan_jiffies; + unsigned long scan_start; + unsigned long scan_pass_start; + unsigned long scan_start_tsf; + int scan_bands; + int one_direct_scan; + u8 direct_ssid_len; + u8 direct_ssid[IW_ESSID_MAX_SIZE]; + struct iwl4965_scan_cmd *scan; + u8 only_active_channel; + + /* spinlock */ + spinlock_t lock; /* protect general shared data */ + spinlock_t hcmd_lock; /* protect hcmd */ + struct mutex mutex; + + /* basic pci-network driver stuff */ + struct pci_dev *pci_dev; + + /* pci hardware address support */ + void __iomem *hw_base; + + /* uCode images, save to reload in case of failure */ + struct fw_desc ucode_code; /* runtime inst */ + struct fw_desc ucode_data; /* runtime data original */ + struct fw_desc ucode_data_backup; /* runtime data save/restore */ + struct fw_desc ucode_init; /* initialization inst */ + struct fw_desc ucode_init_data; /* initialization data */ + struct fw_desc ucode_boot; /* bootstrap inst */ + + + struct iwl4965_rxon_time_cmd rxon_timing; + + /* We declare this const so it can only be + * changed via explicit cast within the + * routines that actually update the physical + * hardware */ + const struct iwl4965_rxon_cmd active_rxon; + struct iwl4965_rxon_cmd staging_rxon; + + int error_recovering; + struct iwl4965_rxon_cmd recovery_rxon; + + /* 1st responses from initialize and runtime uCode images. + * 4965's initialize alive response contains some calibration data. */ + struct iwl4965_init_alive_resp card_alive_init; + struct iwl4965_alive_resp card_alive; + +#ifdef LED + /* LED related variables */ + struct iwl4965_activity_blink activity; + unsigned long led_packets; + int led_state; +#endif + + u16 active_rate; + u16 active_rate_basic; + + u8 call_post_assoc_from_beacon; + u8 assoc_station_added; + u8 use_ant_b_for_management_frame; /* Tx antenna selection */ + u8 valid_antenna; /* Bit mask of antennas actually connected */ +#ifdef CONFIG_IWL4965_SENSITIVITY + struct iwl4965_sensitivity_data sensitivity_data; + struct iwl4965_chain_noise_data chain_noise_data; + u8 start_calib; + __le16 sensitivity_tbl[HD_TABLE_SIZE]; +#endif /*CONFIG_IWL4965_SENSITIVITY*/ + +#ifdef CONFIG_IWL4965_HT + struct iwl_ht_info current_ht_config; +#endif + u8 last_phy_res[100]; + + /* Rate scaling data */ + struct iwl4965_lq_mngr lq_mngr; + + /* Rate scaling data */ + s8 data_retry_limit; + u8 retry_rate; + + wait_queue_head_t wait_command_queue; + + int activity_timer_active; + + /* Rx and Tx DMA processing queues */ + struct iwl4965_rx_queue rxq; + struct iwl4965_tx_queue txq[IWL_MAX_NUM_QUEUES]; + unsigned long txq_ctx_active_msk; + struct iwl4965_kw kw; /* keep warm address */ + u32 scd_base_addr; /* scheduler sram base address */ + + unsigned long status; + u32 config; + + int last_rx_rssi; /* From Rx packet statisitics */ + int last_rx_noise; /* From beacon statistics */ + + struct iwl4965_power_mgr power_data; + + struct iwl4965_notif_statistics statistics; + unsigned long last_statistics_time; + + /* context information */ + u8 essid[IW_ESSID_MAX_SIZE]; + u8 essid_len; + u16 rates_mask; + + u32 power_mode; + u32 antenna; + u8 bssid[ETH_ALEN]; + u16 rts_threshold; + u8 mac_addr[ETH_ALEN]; + + /*station table variables */ + spinlock_t sta_lock; + int num_stations; + struct iwl4965_station_entry stations[IWL_STATION_COUNT]; + + /* Indication if ieee80211_ops->open has been called */ + int is_open; + + u8 mac80211_registered; + int is_abg; + + u32 notif_missed_beacons; + + /* Rx'd packet timing information */ + u32 last_beacon_time; + u64 last_tsf; + + /* Duplicate packet detection */ + u16 last_seq_num; + u16 last_frag_num; + unsigned long last_packet_time; + + /* Hash table for finding stations in IBSS network */ + struct list_head ibss_mac_hash[IWL_IBSS_MAC_HASH_SIZE]; + + /* eeprom */ + struct iwl4965_eeprom eeprom; + + int iw_mode; + + struct sk_buff *ibss_beacon; + + /* Last Rx'd beacon timestamp */ + u32 timestamp0; + u32 timestamp1; + u16 beacon_int; + struct iwl4965_driver_hw_info hw_setting; + struct ieee80211_vif *vif; + + /* Current association information needed to configure the + * hardware */ + u16 assoc_id; + u16 assoc_capability; + u8 ps_mode; + +#ifdef CONFIG_IWL4965_QOS + struct iwl4965_qos_info qos_data; +#endif /*CONFIG_IWL4965_QOS */ + + struct workqueue_struct *workqueue; + + struct work_struct up; + struct work_struct restart; + struct work_struct calibrated_work; + struct work_struct scan_completed; + struct work_struct rx_replenish; + struct work_struct rf_kill; + struct work_struct abort_scan; + struct work_struct update_link_led; + struct work_struct auth_work; + struct work_struct report_work; + struct work_struct request_scan; + struct work_struct beacon_update; + + struct tasklet_struct irq_tasklet; + + struct delayed_work init_alive_start; + struct delayed_work alive_start; + struct delayed_work activity_timer; + struct delayed_work thermal_periodic; + struct delayed_work gather_stats; + struct delayed_work scan_check; + struct delayed_work post_associate; + +#define IWL_DEFAULT_TX_POWER 0x0F + s8 user_txpower_limit; + s8 max_channel_txpower_limit; + +#ifdef CONFIG_PM + u32 pm_state[16]; +#endif + +#ifdef CONFIG_IWL4965_DEBUG + /* debugging info */ + u32 framecnt_to_us; + atomic_t restrict_refcnt; +#endif + + struct work_struct txpower_work; +#ifdef CONFIG_IWL4965_SENSITIVITY + struct work_struct sensitivity_work; +#endif + struct work_struct statistics_work; + struct timer_list statistics_periodic; + +#ifdef CONFIG_IWL4965_HT_AGG + struct work_struct agg_work; +#endif +}; /*iwl4965_priv */ + +static inline int iwl4965_is_associated(struct iwl4965_priv *priv) +{ + return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0; +} + +static inline int is_channel_valid(const struct iwl4965_channel_info *ch_info) +{ + if (ch_info == NULL) + return 0; + return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0; +} + +static inline int is_channel_narrow(const struct iwl4965_channel_info *ch_info) +{ + return (ch_info->flags & EEPROM_CHANNEL_NARROW) ? 1 : 0; +} + +static inline int is_channel_radar(const struct iwl4965_channel_info *ch_info) +{ + return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0; +} + +static inline u8 is_channel_a_band(const struct iwl4965_channel_info *ch_info) +{ + return ch_info->phymode == MODE_IEEE80211A; +} + +static inline u8 is_channel_bg_band(const struct iwl4965_channel_info *ch_info) +{ + return ((ch_info->phymode == MODE_IEEE80211B) || + (ch_info->phymode == MODE_IEEE80211G)); +} + +static inline int is_channel_passive(const struct iwl4965_channel_info *ch) +{ + return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0; +} + +static inline int is_channel_ibss(const struct iwl4965_channel_info *ch) +{ + return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0; +} + +extern const struct iwl4965_channel_info *iwl4965_get_channel_info( + const struct iwl4965_priv *priv, int phymode, u16 channel); + +/* Requires full declaration of iwl4965_priv before including */ +#include "iwl-4965-io.h" + +#endif /* __iwl4965_4965_h__ */ diff --git a/drivers/net/wireless/iwlwifi/iwl-channel.h b/drivers/net/wireless/iwlwifi/iwl-channel.h deleted file mode 100644 index 023c3f240ce..00000000000 --- a/drivers/net/wireless/iwlwifi/iwl-channel.h +++ /dev/null @@ -1,161 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * The full GNU General Public License is included in this distribution in the - * file called LICENSE. - * - * Contact Information: - * James P. Ketrenos <ipw2100-admin@linux.intel.com> - * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 - * - *****************************************************************************/ -#ifndef __iwl_channel_h__ -#define __iwl_channel_h__ - -#define IWL_NUM_SCAN_RATES (2) - -struct iwl_channel_tgd_info { - u8 type; - s8 max_power; -}; - -struct iwl_channel_tgh_info { - s64 last_radar_time; -}; - -/* current Tx power values to use, one for each rate for each channel. - * requested power is limited by: - * -- regulatory EEPROM limits for this channel - * -- hardware capabilities (clip-powers) - * -- spectrum management - * -- user preference (e.g. iwconfig) - * when requested power is set, base power index must also be set. */ -struct iwl_channel_power_info { - struct iwl_tx_power tpc; /* actual radio and DSP gain settings */ - s8 power_table_index; /* actual (compenst'd) index into gain table */ - s8 base_power_index; /* gain index for power at factory temp. */ - s8 requested_power; /* power (dBm) requested for this chnl/rate */ -}; - -/* current scan Tx power values to use, one for each scan rate for each - * channel. */ -struct iwl_scan_power_info { - struct iwl_tx_power tpc; /* actual radio and DSP gain settings */ - s8 power_table_index; /* actual (compenst'd) index into gain table */ - s8 requested_power; /* scan pwr (dBm) requested for chnl/rate */ -}; - -/* Channel unlock period is 15 seconds. If no beacon or probe response - * has been received within 15 seconds on a locked channel then the channel - * remains locked. */ -#define TX_UNLOCK_PERIOD 15 - -/* CSA lock period is 15 seconds. If a CSA has been received on a channel in - * the last 15 seconds, the channel is locked */ -#define CSA_LOCK_PERIOD 15 -/* - * One for each channel, holds all channel setup data - * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant - * with one another! - */ -#define IWL4965_MAX_RATE (33) - -struct iwl_channel_info { - struct iwl_channel_tgd_info tgd; - struct iwl_channel_tgh_info tgh; - struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */ - struct iwl_eeprom_channel fat_eeprom; /* EEPROM regulatory limit for - * FAT channel */ - - u8 channel; /* channel number */ - u8 flags; /* flags copied from EEPROM */ - s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */ - s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) */ - s8 min_power; /* always 0 */ - s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */ - - u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */ - u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */ - u8 phymode; /* MODE_IEEE80211{A,B,G} */ - - /* Radio/DSP gain settings for each "normal" data Tx rate. - * These include, in addition to RF and DSP gain, a few fields for - * remembering/modifying gain settings (indexes). */ - struct iwl_channel_power_info power_info[IWL4965_MAX_RATE]; - -#if IWL == 4965 - /* FAT channel info */ - s8 fat_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */ - s8 fat_curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) */ - s8 fat_min_power; /* always 0 */ - s8 fat_scan_power; /* (dBm) eeprom, direct scans, any rate */ - u8 fat_flags; /* flags copied from EEPROM */ - u8 fat_extension_channel; -#endif - - /* Radio/DSP gain settings for each scan rate, for directed scans. */ - struct iwl_scan_power_info scan_pwr_info[IWL_NUM_SCAN_RATES]; -}; - -struct iwl_clip_group { - /* maximum power level to prevent clipping for each rate, derived by - * us from this band's saturation power in EEPROM */ - const s8 clip_powers[IWL_MAX_RATES]; -}; - -static inline int is_channel_valid(const struct iwl_channel_info *ch_info) -{ - if (ch_info == NULL) - return 0; - return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0; -} - -static inline int is_channel_narrow(const struct iwl_channel_info *ch_info) -{ - return (ch_info->flags & EEPROM_CHANNEL_NARROW) ? 1 : 0; -} - -static inline int is_channel_radar(const struct iwl_channel_info *ch_info) -{ - return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0; -} - -static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info) -{ - return ch_info->phymode == MODE_IEEE80211A; -} - -static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info) -{ - return ((ch_info->phymode == MODE_IEEE80211B) || - (ch_info->phymode == MODE_IEEE80211G)); -} - -static inline int is_channel_passive(const struct iwl_channel_info *ch) -{ - return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0; -} - -static inline int is_channel_ibss(const struct iwl_channel_info *ch) -{ - return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0; -} - -extern const struct iwl_channel_info *iwl_get_channel_info( - const struct iwl_priv *priv, int phymode, u16 channel); - -#endif diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.h b/drivers/net/wireless/iwlwifi/iwl-eeprom.h deleted file mode 100644 index e473c97e3f4..00000000000 --- a/drivers/net/wireless/iwlwifi/iwl-eeprom.h +++ /dev/null @@ -1,336 +0,0 @@ -/****************************************************************************** - * - * This file is provided under a dual BSD/GPLv2 license. When using or - * redistributing this file, you may do so under either license. - * - * GPL LICENSE SUMMARY - * - * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU Geeral Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, - * USA - * - * The full GNU General Public License is included in this distribution - * in the file called LICENSE.GPL. - * - * Contact Information: - * James P. Ketrenos <ipw2100-admin@linux.intel.com> - * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 - * - * BSD LICENSE - * - * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - *****************************************************************************/ - -#ifndef __iwl_eeprom_h__ -#define __iwl_eeprom_h__ - -/* - * This file defines EEPROM related constants, enums, and inline functions. - * - */ - -#define IWL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */ -#define IWL_EEPROM_ACCESS_DELAY 10 /* uSec */ -/* EEPROM field values */ -#define ANTENNA_SWITCH_NORMAL 0 -#define ANTENNA_SWITCH_INVERSE 1 - -enum { - EEPROM_CHANNEL_VALID = (1 << 0), /* usable for this SKU/geo */ - EEPROM_CHANNEL_IBSS = (1 << 1), /* usable as an IBSS channel */ - /* Bit 2 Reserved */ - EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */ - EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */ - EEPROM_CHANNEL_WIDE = (1 << 5), - EEPROM_CHANNEL_NARROW = (1 << 6), - EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */ -}; - -/* EEPROM field lengths */ -#define EEPROM_BOARD_PBA_NUMBER_LENGTH 11 - -/* EEPROM field lengths */ -#define EEPROM_BOARD_PBA_NUMBER_LENGTH 11 -#define EEPROM_REGULATORY_SKU_ID_LENGTH 4 -#define EEPROM_REGULATORY_BAND1_CHANNELS_LENGTH 14 -#define EEPROM_REGULATORY_BAND2_CHANNELS_LENGTH 13 -#define EEPROM_REGULATORY_BAND3_CHANNELS_LENGTH 12 -#define EEPROM_REGULATORY_BAND4_CHANNELS_LENGTH 11 -#define EEPROM_REGULATORY_BAND5_CHANNELS_LENGTH 6 - -#if IWL == 3945 -#define EEPROM_REGULATORY_CHANNELS_LENGTH ( \ - EEPROM_REGULATORY_BAND1_CHANNELS_LENGTH + \ - EEPROM_REGULATORY_BAND2_CHANNELS_LENGTH + \ - EEPROM_REGULATORY_BAND3_CHANNELS_LENGTH + \ - EEPROM_REGULATORY_BAND4_CHANNELS_LENGTH + \ - EEPROM_REGULATORY_BAND5_CHANNELS_LENGTH) -#elif IWL == 4965 -#define EEPROM_REGULATORY_BAND_24_FAT_CHANNELS_LENGTH 7 -#define EEPROM_REGULATORY_BAND_52_FAT_CHANNELS_LENGTH 11 -#define EEPROM_REGULATORY_CHANNELS_LENGTH ( \ - EEPROM_REGULATORY_BAND1_CHANNELS_LENGTH + \ - EEPROM_REGULATORY_BAND2_CHANNELS_LENGTH + \ - EEPROM_REGULATORY_BAND3_CHANNELS_LENGTH + \ - EEPROM_REGULATORY_BAND4_CHANNELS_LENGTH + \ - EEPROM_REGULATORY_BAND5_CHANNELS_LENGTH + \ - EEPROM_REGULATORY_BAND_24_FAT_CHANNELS_LENGTH + \ - EEPROM_REGULATORY_BAND_52_FAT_CHANNELS_LENGTH) -#endif - -#define EEPROM_REGULATORY_NUMBER_OF_BANDS 5 - -/* SKU Capabilities */ -#define EEPROM_SKU_CAP_SW_RF_KILL_ENABLE (1 << 0) -#define EEPROM_SKU_CAP_HW_RF_KILL_ENABLE (1 << 1) -#define EEPROM_SKU_CAP_OP_MODE_MRC (1 << 7) - -/* *regulatory* channel data from eeprom, one for each channel */ -struct iwl_eeprom_channel { - u8 flags; /* flags copied from EEPROM */ - s8 max_power_avg; /* max power (dBm) on this chnl, limit 31 */ -} __attribute__ ((packed)); - -/* - * Mapping of a Tx power level, at factory calibration temperature, - * to a radio/DSP gain table index. - * One for each of 5 "sample" power levels in each band. - * v_det is measured at the factory, using the 3945's built-in power amplifier - * (PA) output voltage detector. This same detector is used during Tx of - * long packets in normal operation to provide feedback as to proper output - * level. - * Data copied from EEPROM. - */ -struct iwl_eeprom_txpower_sample { - u8 gain_index; /* index into power (gain) setup table ... */ - s8 power; /* ... for this pwr level for this chnl group */ - u16 v_det; /* PA output voltage */ -} __attribute__ ((packed)); - -/* - * Mappings of Tx power levels -> nominal radio/DSP gain table indexes. - * One for each channel group (a.k.a. "band") (1 for BG, 4 for A). - * Tx power setup code interpolates between the 5 "sample" power levels - * to determine the nominal setup for a requested power level. - * Data copied from EEPROM. - * DO NOT ALTER THIS STRUCTURE!!! - */ -struct iwl_eeprom_txpower_group { - struct iwl_eeprom_txpower_sample samples[5]; /* 5 power levels */ - s32 a, b, c, d, e; /* coefficients for voltage->power - * formula (signed) */ - s32 Fa, Fb, Fc, Fd, Fe; /* these modify coeffs based on - * frequency (signed) */ - s8 saturation_power; /* highest power possible by h/w in this - * band */ - u8 group_channel; /* "representative" channel # in this band */ - s16 temperature; /* h/w temperature at factory calib this band - * (signed) */ -} __attribute__ ((packed)); - -/* - * Temperature-based Tx-power compensation data, not band-specific. - * These coefficients are use to modify a/b/c/d/e coeffs based on - * difference between current temperature and factory calib temperature. - * Data copied from EEPROM. - */ -struct iwl_eeprom_temperature_corr { - u32 Ta; - u32 Tb; - u32 Tc; - u32 Td; - u32 Te; -} __attribute__ ((packed)); - -#if IWL == 4965 -#define EEPROM_TX_POWER_TX_CHAINS (2) -#define EEPROM_TX_POWER_BANDS (8) -#define EEPROM_TX_POWER_MEASUREMENTS (3) -#define EEPROM_TX_POWER_VERSION (2) -#define EEPROM_TX_POWER_VERSION_NEW (5) - -struct iwl_eeprom_calib_measure { - u8 temperature; - u8 gain_idx; - u8 actual_pow; - s8 pa_det; -} __attribute__ ((packed)); - -struct iwl_eeprom_calib_ch_info { - u8 ch_num; - struct iwl_eeprom_calib_measure measurements[EEPROM_TX_POWER_TX_CHAINS] - [EEPROM_TX_POWER_MEASUREMENTS]; -} __attribute__ ((packed)); - -struct iwl_eeprom_calib_subband_info { - u8 ch_from; - u8 ch_to; - struct iwl_eeprom_calib_ch_info ch1; - struct iwl_eeprom_calib_ch_info ch2; -} __attribute__ ((packed)); - -struct iwl_eeprom_calib_info { - u8 saturation_power24; - u8 saturation_power52; - s16 voltage; /* signed */ - struct iwl_eeprom_calib_subband_info band_info[EEPROM_TX_POWER_BANDS]; -} __attribute__ ((packed)); - -#endif - -struct iwl_eeprom { - u8 reserved0[16]; -#define EEPROM_DEVICE_ID (2*0x08) /* 2 bytes */ - u16 device_id; /* abs.ofs: 16 */ - u8 reserved1[2]; -#define EEPROM_PMC (2*0x0A) /* 2 bytes */ - u16 pmc; /* abs.ofs: 20 */ - u8 reserved2[20]; -#define EEPROM_MAC_ADDRESS (2*0x15) /* 6 bytes */ - u8 mac_address[6]; /* abs.ofs: 42 */ - u8 reserved3[58]; -#define EEPROM_BOARD_REVISION (2*0x35) /* 2 bytes */ - u16 board_revision; /* abs.ofs: 106 */ - u8 reserved4[11]; -#define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1) /* 9 bytes */ - u8 board_pba_number[9]; /* abs.ofs: 119 */ - u8 reserved5[8]; -#define EEPROM_VERSION (2*0x44) /* 2 bytes */ - u16 version; /* abs.ofs: 136 */ -#define EEPROM_SKU_CAP (2*0x45) /* 1 bytes */ - u8 sku_cap; /* abs.ofs: 138 */ -#define EEPROM_LEDS_MODE (2*0x45+1) /* 1 bytes */ - u8 leds_mode; /* abs.ofs: 139 */ -#define EEPROM_OEM_MODE (2*0x46) /* 2 bytes */ - u16 oem_mode; -#define EEPROM_WOWLAN_MODE (2*0x47) /* 2 bytes */ - u16 wowlan_mode; /* abs.ofs: 142 */ -#define EEPROM_LEDS_TIME_INTERVAL (2*0x48) /* 2 bytes */ - u16 leds_time_interval; /* abs.ofs: 144 */ -#define EEPROM_LEDS_OFF_TIME (2*0x49) /* 1 bytes */ - u8 leds_off_time; /* abs.ofs: 146 */ -#define EEPROM_LEDS_ON_TIME (2*0x49+1) /* 1 bytes */ - u8 leds_on_time; /* abs.ofs: 147 */ -#define EEPROM_ALMGOR_M_VERSION (2*0x4A) /* 1 bytes */ - u8 almgor_m_version; /* abs.ofs: 148 */ -#define EEPROM_ANTENNA_SWITCH_TYPE (2*0x4A+1) /* 1 bytes */ - u8 antenna_switch_type; /* abs.ofs: 149 */ -#if IWL == 3945 - u8 reserved6[42]; -#else - u8 reserved6[8]; -#define EEPROM_4965_BOARD_REVISION (2*0x4F) /* 2 bytes */ - u16 board_revision_4965; /* abs.ofs: 158 */ - u8 reserved7[13]; -#define EEPROM_4965_BOARD_PBA (2*0x56+1) /* 9 bytes */ - u8 board_pba_number_4965[9]; /* abs.ofs: 173 */ - u8 reserved8[10]; -#endif -#define EEPROM_REGULATORY_SKU_ID (2*0x60) /* 4 bytes */ - u8 sku_id[4]; /* abs.ofs: 192 */ -#define EEPROM_REGULATORY_BAND_1 (2*0x62) /* 2 bytes */ - u16 band_1_count; /* abs.ofs: 196 */ -#define EEPROM_REGULATORY_BAND_1_CHANNELS (2*0x63) /* 28 bytes */ - struct iwl_eeprom_channel band_1_channels[14]; /* abs.ofs: 196 */ -#define EEPROM_REGULATORY_BAND_2 (2*0x71) /* 2 bytes */ - u16 band_2_count; /* abs.ofs: 226 */ -#define EEPROM_REGULATORY_BAND_2_CHANNELS (2*0x72) /* 26 bytes */ - struct iwl_eeprom_channel band_2_channels[13]; /* abs.ofs: 228 */ -#define EEPROM_REGULATORY_BAND_3 (2*0x7F) /* 2 bytes */ - u16 band_3_count; /* abs.ofs: 254 */ -#define EEPROM_REGULATORY_BAND_3_CHANNELS (2*0x80) /* 24 bytes */ - struct iwl_eeprom_channel band_3_channels[12]; /* abs.ofs: 256 */ -#define EEPROM_REGULATORY_BAND_4 (2*0x8C) /* 2 bytes */ - u16 band_4_count; /* abs.ofs: 280 */ -#define EEPROM_REGULATORY_BAND_4_CHANNELS (2*0x8D) /* 22 bytes */ - struct iwl_eeprom_channel band_4_channels[11]; /* abs.ofs: 282 */ -#define EEPROM_REGULATORY_BAND_5 (2*0x98) /* 2 bytes */ - u16 band_5_count; /* abs.ofs: 304 */ -#define EEPROM_REGULATORY_BAND_5_CHANNELS (2*0x99) /* 12 bytes */ - struct iwl_eeprom_channel band_5_channels[6]; /* abs.ofs: 306 */ - -/* From here on out the EEPROM diverges between the 4965 and the 3945 */ -#if IWL == 3945 - - u8 reserved9[194]; - -#define EEPROM_TXPOWER_CALIB_GROUP0 0x200 -#define EEPROM_TXPOWER_CALIB_GROUP1 0x240 -#define EEPROM_TXPOWER_CALIB_GROUP2 0x280 -#define EEPROM_TXPOWER_CALIB_GROUP3 0x2c0 -#define EEPROM_TXPOWER_CALIB_GROUP4 0x300 -#define IWL_NUM_TX_CALIB_GROUPS 5 - struct iwl_eeprom_txpower_group groups[IWL_NUM_TX_CALIB_GROUPS]; -/* abs.ofs: 512 */ -#define EEPROM_CALIB_TEMPERATURE_CORRECT 0x340 - struct iwl_eeprom_temperature_corr corrections; /* abs.ofs: 832 */ - u8 reserved16[172]; /* fill out to full 1024 byte block */ - -/* 4965AGN adds fat channel support */ -#elif IWL == 4965 - - u8 reserved10[2]; -#define EEPROM_REGULATORY_BAND_24_FAT_CHANNELS (2*0xA0) /* 14 bytes */ - struct iwl_eeprom_channel band_24_channels[7]; /* abs.ofs: 320 */ - u8 reserved11[2]; -#define EEPROM_REGULATORY_BAND_52_FAT_CHANNELS (2*0xA8) /* 22 bytes */ - struct iwl_eeprom_channel band_52_channels[11]; /* abs.ofs: 336 */ - u8 reserved12[6]; -#define EEPROM_CALIB_VERSION_OFFSET (2*0xB6) /* 2 bytes */ - u16 calib_version; /* abs.ofs: 364 */ - u8 reserved13[2]; -#define EEPROM_SATURATION_POWER_OFFSET (2*0xB8) /* 2 bytes */ - u16 satruation_power; /* abs.ofs: 368 */ - u8 reserved14[94]; -#define EEPROM_IWL_CALIB_TXPOWER_OFFSET (2*0xE8) /* 48 bytes */ - struct iwl_eeprom_calib_info calib_info; /* abs.ofs: 464 */ - - u8 reserved16[140]; /* fill out to full 1024 byte block */ - -#endif - -} __attribute__ ((packed)); - -#define IWL_EEPROM_IMAGE_SIZE 1024 - -#endif diff --git a/drivers/net/wireless/iwlwifi/iwl-helpers.h b/drivers/net/wireless/iwlwifi/iwl-helpers.h index e2a8d95ad9c..cd2eb184831 100644 --- a/drivers/net/wireless/iwlwifi/iwl-helpers.h +++ b/drivers/net/wireless/iwlwifi/iwl-helpers.h @@ -252,4 +252,27 @@ static inline unsigned long elapsed_jiffies(unsigned long start, return end + (MAX_JIFFY_OFFSET - start); } +static inline u8 iwl_get_dma_hi_address(dma_addr_t addr) +{ + return sizeof(addr) > sizeof(u32) ? (addr >> 16) >> 16 : 0; +} + +/* TODO: Move fw_desc functions to iwl-pci.ko */ +static inline void iwl_free_fw_desc(struct pci_dev *pci_dev, + struct fw_desc *desc) +{ + if (desc->v_addr) + pci_free_consistent(pci_dev, desc->len, + desc->v_addr, desc->p_addr); + desc->v_addr = NULL; + desc->len = 0; +} + +static inline int iwl_alloc_fw_desc(struct pci_dev *pci_dev, + struct fw_desc *desc) +{ + desc->v_addr = pci_alloc_consistent(pci_dev, desc->len, &desc->p_addr); + return (desc->v_addr != NULL) ? 0 : -ENOMEM; +} + #endif /* __iwl_helpers_h__ */ diff --git a/drivers/net/wireless/iwlwifi/iwl-hw.h b/drivers/net/wireless/iwlwifi/iwl-hw.h deleted file mode 100644 index 1aa6fcd39a5..00000000000 --- a/drivers/net/wireless/iwlwifi/iwl-hw.h +++ /dev/null @@ -1,537 +0,0 @@ -/****************************************************************************** - * - * This file is provided under a dual BSD/GPLv2 license. When using or - * redistributing this file, you may do so under either license. - * - * GPL LICENSE SUMMARY - * - * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU Geeral Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, - * USA - * - * The full GNU General Public License is included in this distribution - * in the file called LICENSE.GPL. - * - * Contact Information: - * James P. Ketrenos <ipw2100-admin@linux.intel.com> - * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 - * - * BSD LICENSE - * - * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -#ifndef __iwlwifi_hw_h__ -#define __iwlwifi_hw_h__ - -/* - * This file defines hardware constants common to 3945 and 4965. - * - * Device-specific constants are defined in iwl-3945-hw.h and iwl-4965-hw.h, - * although this file contains a few definitions for which the .c - * implementation is the same for 3945 and 4965, except for the value of - * a constant. - * - * uCode API constants are defined in iwl-commands.h. - * - * NOTE: DO NOT PUT OS IMPLEMENTATION-SPECIFIC DECLARATIONS HERE - * - * The iwl-*hw.h (and files they include) files should remain OS/driver - * implementation independent, declaring only the hardware interface. - */ - -/* uCode queue management definitions */ -#define IWL_CMD_QUEUE_NUM 4 -#define IWL_CMD_FIFO_NUM 4 -#define IWL_BACK_QUEUE_FIRST_ID 7 - -/* Tx rates */ -#define IWL_CCK_RATES 4 -#define IWL_OFDM_RATES 8 - -#if IWL == 3945 -#define IWL_HT_RATES 0 -#elif IWL == 4965 -#define IWL_HT_RATES 16 -#endif - -#define IWL_MAX_RATES (IWL_CCK_RATES+IWL_OFDM_RATES+IWL_HT_RATES) - -/* Time constants */ -#define SHORT_SLOT_TIME 9 -#define LONG_SLOT_TIME 20 - -/* RSSI to dBm */ -#if IWL == 3945 -#define IWL_RSSI_OFFSET 95 -#elif IWL == 4965 -#define IWL_RSSI_OFFSET 44 -#endif - -#include "iwl-eeprom.h" -#include "iwl-commands.h" - -#define PCI_LINK_CTRL 0x0F0 -#define PCI_POWER_SOURCE 0x0C8 -#define PCI_REG_WUM8 0x0E8 -#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000) - -/*=== CSR (control and status registers) ===*/ -#define CSR_BASE (0x000) - -#define CSR_SW_VER (CSR_BASE+0x000) -#define CSR_HW_IF_CONFIG_REG (CSR_BASE+0x000) /* hardware interface config */ -#define CSR_INT_COALESCING (CSR_BASE+0x004) /* accum ints, 32-usec units */ -#define CSR_INT (CSR_BASE+0x008) /* host interrupt status/ack */ -#define CSR_INT_MASK (CSR_BASE+0x00c) /* host interrupt enable */ -#define CSR_FH_INT_STATUS (CSR_BASE+0x010) /* busmaster int status/ack*/ -#define CSR_GPIO_IN (CSR_BASE+0x018) /* read external chip pins */ -#define CSR_RESET (CSR_BASE+0x020) /* busmaster enable, NMI, etc*/ -#define CSR_GP_CNTRL (CSR_BASE+0x024) -#define CSR_HW_REV (CSR_BASE+0x028) -#define CSR_EEPROM_REG (CSR_BASE+0x02c) -#define CSR_EEPROM_GP (CSR_BASE+0x030) -#define CSR_GP_UCODE (CSR_BASE+0x044) -#define CSR_UCODE_DRV_GP1 (CSR_BASE+0x054) -#define CSR_UCODE_DRV_GP1_SET (CSR_BASE+0x058) -#define CSR_UCODE_DRV_GP1_CLR (CSR_BASE+0x05c) -#define CSR_UCODE_DRV_GP2 (CSR_BASE+0x060) -#define CSR_LED_REG (CSR_BASE+0x094) -#define CSR_DRAM_INT_TBL_CTL (CSR_BASE+0x0A0) -#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100) -#define CSR_ANA_PLL_CFG (CSR_BASE+0x20c) -#define CSR_HW_REV_WA_REG (CSR_BASE+0x22C) - -/* HW I/F configuration */ -#define CSR_HW_IF_CONFIG_REG_BIT_ALMAGOR_MB (0x00000100) -#define CSR_HW_IF_CONFIG_REG_BIT_ALMAGOR_MM (0x00000200) -#define CSR_HW_IF_CONFIG_REG_BIT_SKU_MRC (0x00000400) -#define CSR_HW_IF_CONFIG_REG_BIT_BOARD_TYPE (0x00000800) -#define CSR_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_A (0x00000000) -#define CSR_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_B (0x00001000) -#define CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM (0x00200000) - -/* interrupt flags in INTA, set by uCode or hardware (e.g. dma), - * acknowledged (reset) by host writing "1" to flagged bits. */ -#define CSR_INT_BIT_FH_RX (1<<31) /* Rx DMA, cmd responses, FH_INT[17:16] */ -#define CSR_INT_BIT_HW_ERR (1<<29) /* DMA hardware error FH_INT[31] */ -#define CSR_INT_BIT_DNLD (1<<28) /* uCode Download */ -#define CSR_INT_BIT_FH_TX (1<<27) /* Tx DMA FH_INT[1:0] */ -#define CSR_INT_BIT_MAC_CLK_ACTV (1<<26) /* NIC controller's clock toggled on/off */ -#define CSR_INT_BIT_SW_ERR (1<<25) /* uCode error */ -#define CSR_INT_BIT_RF_KILL (1<<7) /* HW RFKILL switch GP_CNTRL[27] toggled */ -#define CSR_INT_BIT_CT_KILL (1<<6) /* Critical temp (chip too hot) rfkill */ -#define CSR_INT_BIT_SW_RX (1<<3) /* Rx, command responses, 3945 */ -#define CSR_INT_BIT_WAKEUP (1<<1) /* NIC controller waking up (pwr mgmt) */ -#define CSR_INT_BIT_ALIVE (1<<0) /* uCode interrupts once it initializes */ - -#define CSR_INI_SET_MASK (CSR_INT_BIT_FH_RX | \ - CSR_INT_BIT_HW_ERR | \ - CSR_INT_BIT_FH_TX | \ - CSR_INT_BIT_SW_ERR | \ - CSR_INT_BIT_RF_KILL | \ - CSR_INT_BIT_SW_RX | \ - CSR_INT_BIT_WAKEUP | \ - CSR_INT_BIT_ALIVE) - -/* interrupt flags in FH (flow handler) (PCI busmaster DMA) */ -#define CSR_FH_INT_BIT_ERR (1<<31) /* Error */ -#define CSR_FH_INT_BIT_HI_PRIOR (1<<30) /* High priority Rx, bypass coalescing */ -#define CSR_FH_INT_BIT_RX_CHNL2 (1<<18) /* Rx channel 2 (3945 only) */ -#define CSR_FH_INT_BIT_RX_CHNL1 (1<<17) /* Rx channel 1 */ -#define CSR_FH_INT_BIT_RX_CHNL0 (1<<16) /* Rx channel 0 */ -#define CSR_FH_INT_BIT_TX_CHNL6 (1<<6) /* Tx channel 6 (3945 only) */ -#define CSR_FH_INT_BIT_TX_CHNL1 (1<<1) /* Tx channel 1 */ -#define CSR_FH_INT_BIT_TX_CHNL0 (1<<0) /* Tx channel 0 */ - -#define CSR_FH_INT_RX_MASK (CSR_FH_INT_BIT_HI_PRIOR | \ - CSR_FH_INT_BIT_RX_CHNL2 | \ - CSR_FH_INT_BIT_RX_CHNL1 | \ - CSR_FH_INT_BIT_RX_CHNL0) - -#define CSR_FH_INT_TX_MASK (CSR_FH_INT_BIT_TX_CHNL6 | \ - CSR_FH_INT_BIT_TX_CHNL1 | \ - CSR_FH_INT_BIT_TX_CHNL0 ) - - -/* RESET */ -#define CSR_RESET_REG_FLAG_NEVO_RESET (0x00000001) -#define CSR_RESET_REG_FLAG_FORCE_NMI (0x00000002) -#define CSR_RESET_REG_FLAG_SW_RESET (0x00000080) -#define CSR_RESET_REG_FLAG_MASTER_DISABLED (0x00000100) -#define CSR_RESET_REG_FLAG_STOP_MASTER (0x00000200) - -/* GP (general purpose) CONTROL */ -#define CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY (0x00000001) -#define CSR_GP_CNTRL_REG_FLAG_INIT_DONE (0x00000004) -#define CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ (0x00000008) -#define CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP (0x00000010) - -#define CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN (0x00000001) - -#define CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE (0x07000000) -#define CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE (0x04000000) -#define CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW (0x08000000) - - -/* EEPROM REG */ -#define CSR_EEPROM_REG_READ_VALID_MSK (0x00000001) -#define CSR_EEPROM_REG_BIT_CMD (0x00000002) - -/* EEPROM GP */ -#define CSR_EEPROM_GP_VALID_MSK (0x00000006) -#define CSR_EEPROM_GP_BAD_SIGNATURE (0x00000000) -#define CSR_EEPROM_GP_IF_OWNER_MSK (0x00000180) - -/* UCODE DRV GP */ -#define CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP (0x00000001) -#define CSR_UCODE_SW_BIT_RFKILL (0x00000002) -#define CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED (0x00000004) -#define CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT (0x00000008) - -/* GPIO */ -#define CSR_GPIO_IN_BIT_AUX_POWER (0x00000200) -#define CSR_GPIO_IN_VAL_VAUX_PWR_SRC (0x00000000) -#define CSR_GPIO_IN_VAL_VMAIN_PWR_SRC CSR_GPIO_IN_BIT_AUX_POWER - -/* GI Chicken Bits */ -#define CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX (0x00800000) -#define CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER (0x20000000) - -/* CSR_ANA_PLL_CFG */ -#define CSR_ANA_PLL_CFG_SH (0x00880300) - -#define CSR_LED_REG_TRUN_ON (0x00000078) -#define CSR_LED_REG_TRUN_OFF (0x00000038) -#define CSR_LED_BSM_CTRL_MSK (0xFFFFFFDF) - -/* DRAM_INT_TBL_CTRL */ -#define CSR_DRAM_INT_TBL_CTRL_EN (1<<31) -#define CSR_DRAM_INT_TBL_CTRL_WRAP_CHK (1<<27) - -/*=== HBUS (Host-side Bus) ===*/ -#define HBUS_BASE (0x400) - -#define HBUS_TARG_MEM_RADDR (HBUS_BASE+0x00c) -#define HBUS_TARG_MEM_WADDR (HBUS_BASE+0x010) -#define HBUS_TARG_MEM_WDAT (HBUS_BASE+0x018) -#define HBUS_TARG_MEM_RDAT (HBUS_BASE+0x01c) -#define HBUS_TARG_PRPH_WADDR (HBUS_BASE+0x044) -#define HBUS_TARG_PRPH_RADDR (HBUS_BASE+0x048) -#define HBUS_TARG_PRPH_WDAT (HBUS_BASE+0x04c) -#define HBUS_TARG_PRPH_RDAT (HBUS_BASE+0x050) -#define HBUS_TARG_WRPTR (HBUS_BASE+0x060) - -#define HBUS_TARG_MBX_C (HBUS_BASE+0x030) - - -/* SCD (Scheduler) */ -#define SCD_BASE (CSR_BASE + 0x2E00) - -#define SCD_MODE_REG (SCD_BASE + 0x000) -#define SCD_ARASTAT_REG (SCD_BASE + 0x004) -#define SCD_TXFACT_REG (SCD_BASE + 0x010) -#define SCD_TXF4MF_REG (SCD_BASE + 0x014) -#define SCD_TXF5MF_REG (SCD_BASE + 0x020) -#define SCD_SBYP_MODE_1_REG (SCD_BASE + 0x02C) -#define SCD_SBYP_MODE_2_REG (SCD_BASE + 0x030) - -/*=== FH (data Flow Handler) ===*/ -#define FH_BASE (0x800) - -#define FH_CBCC_TABLE (FH_BASE+0x140) -#define FH_TFDB_TABLE (FH_BASE+0x180) -#define FH_RCSR_TABLE (FH_BASE+0x400) -#define FH_RSSR_TABLE (FH_BASE+0x4c0) -#define FH_TCSR_TABLE (FH_BASE+0x500) -#define FH_TSSR_TABLE (FH_BASE+0x680) - -/* TFDB (Transmit Frame Buffer Descriptor) */ -#define FH_TFDB(_channel, buf) \ - (FH_TFDB_TABLE+((_channel)*2+(buf))*0x28) -#define ALM_FH_TFDB_CHNL_BUF_CTRL_REG(_channel) \ - (FH_TFDB_TABLE + 0x50 * _channel) -/* CBCC _channel is [0,2] */ -#define FH_CBCC(_channel) (FH_CBCC_TABLE+(_channel)*0x8) -#define FH_CBCC_CTRL(_channel) (FH_CBCC(_channel)+0x00) -#define FH_CBCC_BASE(_channel) (FH_CBCC(_channel)+0x04) - -/* RCSR _channel is [0,2] */ -#define FH_RCSR(_channel) (FH_RCSR_TABLE+(_channel)*0x40) -#define FH_RCSR_CONFIG(_channel) (FH_RCSR(_channel)+0x00) -#define FH_RCSR_RBD_BASE(_channel) (FH_RCSR(_channel)+0x04) -#define FH_RCSR_WPTR(_channel) (FH_RCSR(_channel)+0x20) -#define FH_RCSR_RPTR_ADDR(_channel) (FH_RCSR(_channel)+0x24) - -#if IWL == 3945 -#define FH_RSCSR_CHNL0_WPTR (FH_RCSR_WPTR(0)) -#elif IWL == 4965 -#define FH_RSCSR_CHNL0_WPTR (FH_RSCSR_CHNL0_RBDCB_WPTR_REG) -#endif - -/* RSSR */ -#define FH_RSSR_CTRL (FH_RSSR_TABLE+0x000) -#define FH_RSSR_STATUS (FH_RSSR_TABLE+0x004) -/* TCSR */ -#define FH_TCSR(_channel) (FH_TCSR_TABLE+(_channel)*0x20) -#define FH_TCSR_CONFIG(_channel) (FH_TCSR(_channel)+0x00) -#define FH_TCSR_CREDIT(_channel) (FH_TCSR(_channel)+0x04) -#define FH_TCSR_BUFF_STTS(_channel) (FH_TCSR(_channel)+0x08) -/* TSSR */ -#define FH_TSSR_CBB_BASE (FH_TSSR_TABLE+0x000) -#define FH_TSSR_MSG_CONFIG (FH_TSSR_TABLE+0x008) -#define FH_TSSR_TX_STATUS (FH_TSSR_TABLE+0x010) -/* 18 - reserved */ - -/* card static random access memory (SRAM) for processor data and instructs */ -#define RTC_INST_LOWER_BOUND (0x000000) -#define RTC_DATA_LOWER_BOUND (0x800000) - - -/* DBM */ - -#define ALM_FH_SRVC_CHNL (6) - -#define ALM_FH_RCSR_RX_CONFIG_REG_POS_RBDC_SIZE (20) -#define ALM_FH_RCSR_RX_CONFIG_REG_POS_IRQ_RBTH (4) - -#define ALM_FH_RCSR_RX_CONFIG_REG_BIT_WR_STTS_EN (0x08000000) - -#define ALM_FH_RCSR_RX_CONFIG_REG_VAL_DMA_CHNL_EN_ENABLE (0x80000000) - -#define ALM_FH_RCSR_RX_CONFIG_REG_VAL_RDRBD_EN_ENABLE (0x20000000) - -#define ALM_FH_RCSR_RX_CONFIG_REG_VAL_MAX_FRAG_SIZE_128 (0x01000000) - -#define ALM_FH_RCSR_RX_CONFIG_REG_VAL_IRQ_DEST_INT_HOST (0x00001000) - -#define ALM_FH_RCSR_RX_CONFIG_REG_VAL_MSG_MODE_FH (0x00000000) - -#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF (0x00000000) -#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_DRIVER (0x00000001) - -#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL (0x00000000) -#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL (0x00000008) - -#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD (0x00200000) - -#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT (0x00000000) - -#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000) -#define ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000) - -#define ALM_FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID (0x00004000) - -#define ALM_FH_TCSR_CHNL_TX_BUF_STS_REG_BIT_TFDB_WPTR (0x00000001) - -#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TXPD_ON (0xFF000000) -#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_TXPD_ON (0x00FF0000) - -#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_128B (0x00000400) - -#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TFD_ON (0x00000100) -#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_CBB_ON (0x00000080) - -#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RSP_WAIT_TH (0x00000020) -#define ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_RSP_WAIT_TH (0x00000005) - -#define ALM_TB_MAX_BYTES_COUNT (0xFFF0) - -#define ALM_FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_channel) \ - ((1LU << _channel) << 24) -#define ALM_FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_channel) \ - ((1LU << _channel) << 16) - -#define ALM_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_channel) \ - (ALM_FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_channel) | \ - ALM_FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_channel)) -#define PCI_CFG_REV_ID_BIT_BASIC_SKU (0x40) /* bit 6 */ -#define PCI_CFG_REV_ID_BIT_RTP (0x80) /* bit 7 */ - -#define HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED (0x00000004) - -#define TFD_QUEUE_MIN 0 -#define TFD_QUEUE_MAX 6 -#define TFD_QUEUE_SIZE_MAX (256) - -/* spectrum and channel data structures */ -#define IWL_NUM_SCAN_RATES (2) - -#define IWL_SCAN_FLAG_24GHZ (1<<0) -#define IWL_SCAN_FLAG_52GHZ (1<<1) -#define IWL_SCAN_FLAG_ACTIVE (1<<2) -#define IWL_SCAN_FLAG_DIRECT (1<<3) - -#define IWL_MAX_CMD_SIZE 1024 - -#define IWL_DEFAULT_TX_RETRY 15 -#define IWL_MAX_TX_RETRY 16 - -/*********************************************/ - -#define RFD_SIZE 4 -#define NUM_TFD_CHUNKS 4 - -#define RX_QUEUE_SIZE 256 -#define RX_QUEUE_MASK 255 -#define RX_QUEUE_SIZE_LOG 8 - -/* QoS definitions */ - -#define CW_MIN_OFDM 15 -#define CW_MAX_OFDM 1023 -#define CW_MIN_CCK 31 -#define CW_MAX_CCK 1023 - -#define QOS_TX0_CW_MIN_OFDM CW_MIN_OFDM -#define QOS_TX1_CW_MIN_OFDM CW_MIN_OFDM -#define QOS_TX2_CW_MIN_OFDM ((CW_MIN_OFDM + 1) / 2 - 1) -#define QOS_TX3_CW_MIN_OFDM ((CW_MIN_OFDM + 1) / 4 - 1) - -#define QOS_TX0_CW_MIN_CCK CW_MIN_CCK -#define QOS_TX1_CW_MIN_CCK CW_MIN_CCK -#define QOS_TX2_CW_MIN_CCK ((CW_MIN_CCK + 1) / 2 - 1) -#define QOS_TX3_CW_MIN_CCK ((CW_MIN_CCK + 1) / 4 - 1) - -#define QOS_TX0_CW_MAX_OFDM CW_MAX_OFDM -#define QOS_TX1_CW_MAX_OFDM CW_MAX_OFDM -#define QOS_TX2_CW_MAX_OFDM CW_MIN_OFDM -#define QOS_TX3_CW_MAX_OFDM ((CW_MIN_OFDM + 1) / 2 - 1) - -#define QOS_TX0_CW_MAX_CCK CW_MAX_CCK -#define QOS_TX1_CW_MAX_CCK CW_MAX_CCK -#define QOS_TX2_CW_MAX_CCK CW_MIN_CCK -#define QOS_TX3_CW_MAX_CCK ((CW_MIN_CCK + 1) / 2 - 1) - -#define QOS_TX0_AIFS 3 -#define QOS_TX1_AIFS 7 -#define QOS_TX2_AIFS 2 -#define QOS_TX3_AIFS 2 - -#define QOS_TX0_ACM 0 -#define QOS_TX1_ACM 0 -#define QOS_TX2_ACM 0 -#define QOS_TX3_ACM 0 - -#define QOS_TX0_TXOP_LIMIT_CCK 0 -#define QOS_TX1_TXOP_LIMIT_CCK 0 -#define QOS_TX2_TXOP_LIMIT_CCK 6016 -#define QOS_TX3_TXOP_LIMIT_CCK 3264 - -#define QOS_TX0_TXOP_LIMIT_OFDM 0 -#define QOS_TX1_TXOP_LIMIT_OFDM 0 -#define QOS_TX2_TXOP_LIMIT_OFDM 3008 -#define QOS_TX3_TXOP_LIMIT_OFDM 1504 - -#define DEF_TX0_CW_MIN_OFDM CW_MIN_OFDM -#define DEF_TX1_CW_MIN_OFDM CW_MIN_OFDM -#define DEF_TX2_CW_MIN_OFDM CW_MIN_OFDM -#define DEF_TX3_CW_MIN_OFDM CW_MIN_OFDM - -#define DEF_TX0_CW_MIN_CCK CW_MIN_CCK -#define DEF_TX1_CW_MIN_CCK CW_MIN_CCK -#define DEF_TX2_CW_MIN_CCK CW_MIN_CCK -#define DEF_TX3_CW_MIN_CCK CW_MIN_CCK - -#define DEF_TX0_CW_MAX_OFDM CW_MAX_OFDM -#define DEF_TX1_CW_MAX_OFDM CW_MAX_OFDM -#define DEF_TX2_CW_MAX_OFDM CW_MAX_OFDM -#define DEF_TX3_CW_MAX_OFDM CW_MAX_OFDM - -#define DEF_TX0_CW_MAX_CCK CW_MAX_CCK -#define DEF_TX1_CW_MAX_CCK CW_MAX_CCK -#define DEF_TX2_CW_MAX_CCK CW_MAX_CCK -#define DEF_TX3_CW_MAX_CCK CW_MAX_CCK - -#define DEF_TX0_AIFS (2) -#define DEF_TX1_AIFS (2) -#define DEF_TX2_AIFS (2) -#define DEF_TX3_AIFS (2) - -#define DEF_TX0_ACM 0 -#define DEF_TX1_ACM 0 -#define DEF_TX2_ACM 0 -#define DEF_TX3_ACM 0 - -#define DEF_TX0_TXOP_LIMIT_CCK 0 -#define DEF_TX1_TXOP_LIMIT_CCK 0 -#define DEF_TX2_TXOP_LIMIT_CCK 0 -#define DEF_TX3_TXOP_LIMIT_CCK 0 - -#define DEF_TX0_TXOP_LIMIT_OFDM 0 -#define DEF_TX1_TXOP_LIMIT_OFDM 0 -#define DEF_TX2_TXOP_LIMIT_OFDM 0 -#define DEF_TX3_TXOP_LIMIT_OFDM 0 - -#define QOS_QOS_SETS 3 -#define QOS_PARAM_SET_ACTIVE 0 -#define QOS_PARAM_SET_DEF_CCK 1 -#define QOS_PARAM_SET_DEF_OFDM 2 - -#define CTRL_QOS_NO_ACK (0x0020) -#define DCT_FLAG_EXT_QOS_ENABLED (0x10) - -#define U32_PAD(n) ((4-(n))&0x3) - -/* - * Generic queue structure - * - * Contains common data for Rx and Tx queues - */ -#define TFD_CTL_COUNT_SET(n) (n<<24) -#define TFD_CTL_COUNT_GET(ctl) ((ctl>>24) & 7) -#define TFD_CTL_PAD_SET(n) (n<<28) -#define TFD_CTL_PAD_GET(ctl) (ctl>>28) - -#define TFD_TX_CMD_SLOTS 256 -#define TFD_CMD_SLOTS 32 - -#define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_cmd) - \ - sizeof(struct iwl_cmd_meta)) - -/* - * RX related structures and functions - */ -#define RX_FREE_BUFFERS 64 -#define RX_LOW_WATERMARK 8 - -#endif /* __iwlwifi_hw_h__ */ diff --git a/drivers/net/wireless/iwlwifi/iwl-io.h b/drivers/net/wireless/iwlwifi/iwl-io.h deleted file mode 100644 index 8a8b96fcf48..00000000000 --- a/drivers/net/wireless/iwlwifi/iwl-io.h +++ /dev/null @@ -1,470 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. - * - * Portions of this file are derived from the ipw3945 project. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * The full GNU General Public License is included in this distribution in the - * file called LICENSE. - * - * Contact Information: - * James P. Ketrenos <ipw2100-admin@linux.intel.com> - * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 - * - *****************************************************************************/ - -#ifndef __iwl_io_h__ -#define __iwl_io_h__ - -#include <linux/io.h> - -#include "iwl-debug.h" - -/* - * IO, register, and NIC memory access functions - * - * NOTE on naming convention and macro usage for these - * - * A single _ prefix before a an access function means that no state - * check or debug information is printed when that function is called. - * - * A double __ prefix before an access function means that state is checked - * (in the case of *restricted calls) and the current line number is printed - * in addition to any other debug output. - * - * The non-prefixed name is the #define that maps the caller into a - * #define that provides the caller's __LINE__ to the double prefix version. - * - * If you wish to call the function without any debug or state checking, - * you should use the single _ prefix version (as is used by dependent IO - * routines, for example _iwl_read_restricted calls the non-check version of - * _iwl_read32.) - * - * These declarations are *extremely* useful in quickly isolating code deltas - * which result in misconfiguring of the hardware I/O. In combination with - * git-bisect and the IO debug level you can quickly determine the specific - * commit which breaks the IO sequence to the hardware. - * - */ - -#define _iwl_write32(iwl, ofs, val) writel((val), (iwl)->hw_base + (ofs)) -#ifdef CONFIG_IWLWIFI_DEBUG -static inline void __iwl_write32(const char *f, u32 l, struct iwl_priv *iwl, - u32 ofs, u32 val) -{ - IWL_DEBUG_IO("write_direct32(0x%08X, 0x%08X) - %s %d\n", - (u32) (ofs), (u32) (val), f, l); - _iwl_write32(iwl, ofs, val); -} -#define iwl_write32(iwl, ofs, val) \ - __iwl_write32(__FILE__, __LINE__, iwl, ofs, val) -#else -#define iwl_write32(iwl, ofs, val) _iwl_write32(iwl, ofs, val) -#endif - -#define _iwl_read32(iwl, ofs) readl((iwl)->hw_base + (ofs)) -#ifdef CONFIG_IWLWIFI_DEBUG -static inline u32 __iwl_read32(char *f, u32 l, struct iwl_priv *iwl, u32 ofs) -{ - IWL_DEBUG_IO("read_direct32(0x%08X) - %s %d\n", ofs, f, l); - return _iwl_read32(iwl, ofs); -} -#define iwl_read32(iwl, ofs) __iwl_read32(__FILE__, __LINE__, iwl, ofs) -#else -#define iwl_read32(p, o) _iwl_read32(p, o) -#endif - -static inline int _iwl_poll_bit(struct iwl_priv *priv, u32 addr, - u32 bits, u32 mask, int timeout) -{ - int i = 0; - - do { - if ((_iwl_read32(priv, addr) & mask) == (bits & mask)) - return i; - mdelay(10); - i += 10; - } while (i < timeout); - - return -ETIMEDOUT; -} -#ifdef CONFIG_IWLWIFI_DEBUG -static inline int __iwl_poll_bit(const char *f, u32 l, - struct iwl_priv *priv, u32 addr, - u32 bits, u32 mask, int timeout) -{ - int rc = _iwl_poll_bit(priv, addr, bits, mask, timeout); - if (unlikely(rc == -ETIMEDOUT)) - IWL_DEBUG_IO - ("poll_bit(0x%08X, 0x%08X, 0x%08X) - timedout - %s %d\n", - addr, bits, mask, f, l); - else - IWL_DEBUG_IO - ("poll_bit(0x%08X, 0x%08X, 0x%08X) = 0x%08X - %s %d\n", - addr, bits, mask, rc, f, l); - return rc; -} -#define iwl_poll_bit(iwl, addr, bits, mask, timeout) \ - __iwl_poll_bit(__FILE__, __LINE__, iwl, addr, bits, mask, timeout) -#else -#define iwl_poll_bit(p, a, b, m, t) _iwl_poll_bit(p, a, b, m, t) -#endif - -static inline void _iwl_set_bit(struct iwl_priv *priv, u32 reg, u32 mask) -{ - _iwl_write32(priv, reg, _iwl_read32(priv, reg) | mask); -} -#ifdef CONFIG_IWLWIFI_DEBUG -static inline void __iwl_set_bit(const char *f, u32 l, - struct iwl_priv *priv, u32 reg, u32 mask) -{ - u32 val = _iwl_read32(priv, reg) | mask; - IWL_DEBUG_IO("set_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); - _iwl_write32(priv, reg, val); -} -#define iwl_set_bit(p, r, m) __iwl_set_bit(__FILE__, __LINE__, p, r, m) -#else -#define iwl_set_bit(p, r, m) _iwl_set_bit(p, r, m) -#endif - -static inline void _iwl_clear_bit(struct iwl_priv *priv, u32 reg, u32 mask) -{ - _iwl_write32(priv, reg, _iwl_read32(priv, reg) & ~mask); -} -#ifdef CONFIG_IWLWIFI_DEBUG -static inline void __iwl_clear_bit(const char *f, u32 l, - struct iwl_priv *priv, u32 reg, u32 mask) -{ - u32 val = _iwl_read32(priv, reg) & ~mask; - IWL_DEBUG_IO("clear_bit(0x%08X, 0x%08X) = 0x%08X\n", reg, mask, val); - _iwl_write32(priv, reg, val); -} -#define iwl_clear_bit(p, r, m) __iwl_clear_bit(__FILE__, __LINE__, p, r, m) -#else -#define iwl_clear_bit(p, r, m) _iwl_clear_bit(p, r, m) -#endif - -static inline int _iwl_grab_restricted_access(struct iwl_priv *priv) -{ - int rc; - u32 gp_ctl; - -#ifdef CONFIG_IWLWIFI_DEBUG - if (atomic_read(&priv->restrict_refcnt)) - return 0; -#endif - if (test_bit(STATUS_RF_KILL_HW, &priv->status) || - test_bit(STATUS_RF_KILL_SW, &priv->status)) { - IWL_WARNING("WARNING: Requesting MAC access during RFKILL " - "wakes up NIC\n"); - - /* 10 msec allows time for NIC to complete its data save */ - gp_ctl = _iwl_read32(priv, CSR_GP_CNTRL); - if (gp_ctl & CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY) { - IWL_DEBUG_RF_KILL("Wait for complete power-down, " - "gpctl = 0x%08x\n", gp_ctl); - mdelay(10); - } else - IWL_DEBUG_RF_KILL("power-down complete, " - "gpctl = 0x%08x\n", gp_ctl); - } - - /* this bit wakes up the NIC */ - _iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); - rc = _iwl_poll_bit(priv, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_VAL_MAC_ACCESS_EN, - (CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY | - CSR_GP_CNTRL_REG_FLAG_GOING_TO_SLEEP), 50); - if (rc < 0) { - IWL_ERROR("MAC is in deep sleep!\n"); - return -EIO; - } - -#ifdef CONFIG_IWLWIFI_DEBUG - atomic_inc(&priv->restrict_refcnt); -#endif - return 0; -} - -#ifdef CONFIG_IWLWIFI_DEBUG -static inline int __iwl_grab_restricted_access(const char *f, u32 l, - struct iwl_priv *priv) -{ - if (atomic_read(&priv->restrict_refcnt)) - IWL_DEBUG_INFO("Grabbing access while already held at " - "line %d.\n", l); - - IWL_DEBUG_IO("grabbing restricted access - %s %d\n", f, l); - - return _iwl_grab_restricted_access(priv); -} -#define iwl_grab_restricted_access(priv) \ - __iwl_grab_restricted_access(__FILE__, __LINE__, priv) -#else -#define iwl_grab_restricted_access(priv) \ - _iwl_grab_restricted_access(priv) -#endif - -static inline void _iwl_release_restricted_access(struct iwl_priv *priv) -{ -#ifdef CONFIG_IWLWIFI_DEBUG - if (atomic_dec_and_test(&priv->restrict_refcnt)) -#endif - _iwl_clear_bit(priv, CSR_GP_CNTRL, - CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); -} -#ifdef CONFIG_IWLWIFI_DEBUG -static inline void __iwl_release_restricted_access(const char *f, u32 l, - struct iwl_priv *priv) -{ - if (atomic_read(&priv->restrict_refcnt) <= 0) - IWL_ERROR("Release unheld restricted access at line %d.\n", l); - - IWL_DEBUG_IO("releasing restricted access - %s %d\n", f, l); - _iwl_release_restricted_access(priv); -} -#define iwl_release_restricted_access(priv) \ - __iwl_release_restricted_access(__FILE__, __LINE__, priv) -#else -#define iwl_release_restricted_access(priv) \ - _iwl_release_restricted_access(priv) -#endif - -static inline u32 _iwl_read_restricted(struct iwl_priv *priv, u32 reg) -{ - return _iwl_read32(priv, reg); -} -#ifdef CONFIG_IWLWIFI_DEBUG -static inline u32 __iwl_read_restricted(const char *f, u32 l, - struct iwl_priv *priv, u32 reg) -{ - u32 value = _iwl_read_restricted(priv, reg); - if (!atomic_read(&priv->restrict_refcnt)) - IWL_ERROR("Unrestricted access from %s %d\n", f, l); - IWL_DEBUG_IO("read_restricted(0x%4X) = 0x%08x - %s %d \n", reg, value, - f, l); - return value; -} -#define iwl_read_restricted(priv, reg) \ - __iwl_read_restricted(__FILE__, __LINE__, priv, reg) -#else -#define iwl_read_restricted _iwl_read_restricted -#endif - -static inline void _iwl_write_restricted(struct iwl_priv *priv, - u32 reg, u32 value) -{ - _iwl_write32(priv, reg, value); -} -#ifdef CONFIG_IWLWIFI_DEBUG -static void __iwl_write_restricted(u32 line, - struct iwl_priv *priv, u32 reg, u32 value) -{ - if (!atomic_read(&priv->restrict_refcnt)) - IWL_ERROR("Unrestricted access from line %d\n", line); - _iwl_write_restricted(priv, reg, value); -} -#define iwl_write_restricted(priv, reg, value) \ - __iwl_write_restricted(__LINE__, priv, reg, value) -#else -#define iwl_write_restricted _iwl_write_restricted -#endif - -static inline void iwl_write_buffer_restricted(struct iwl_priv *priv, - u32 reg, u32 len, u32 *values) -{ - u32 count = sizeof(u32); - - if ((priv != NULL) && (values != NULL)) { - for (; 0 < len; len -= count, reg += count, values++) - _iwl_write_restricted(priv, reg, *values); - } -} - -static inline int _iwl_poll_restricted_bit(struct iwl_priv *priv, - u32 addr, u32 mask, int timeout) -{ - int i = 0; - - do { - if ((_iwl_read_restricted(priv, addr) & mask) == mask) - return i; - mdelay(10); - i += 10; - } while (i < timeout); - - return -ETIMEDOUT; -} - -#ifdef CONFIG_IWLWIFI_DEBUG -static inline int __iwl_poll_restricted_bit(const char *f, u32 l, - struct iwl_priv *priv, - u32 addr, u32 mask, int timeout) -{ - int rc = _iwl_poll_restricted_bit(priv, addr, mask, timeout); - - if (unlikely(rc == -ETIMEDOUT)) - IWL_DEBUG_IO("poll_restricted_bit(0x%08X, 0x%08X) - " - "timedout - %s %d\n", addr, mask, f, l); - else - IWL_DEBUG_IO("poll_restricted_bit(0x%08X, 0x%08X) = 0x%08X " - "- %s %d\n", addr, mask, rc, f, l); - return rc; -} -#define iwl_poll_restricted_bit(iwl, addr, mask, timeout) \ - __iwl_poll_restricted_bit(__FILE__, __LINE__, iwl, addr, mask, timeout) -#else -#define iwl_poll_restricted_bit _iwl_poll_restricted_bit -#endif - -static inline u32 _iwl_read_restricted_reg(struct iwl_priv *priv, u32 reg) -{ - _iwl_write_restricted(priv, HBUS_TARG_PRPH_RADDR, reg | (3 << 24)); - return _iwl_read_restricted(priv, HBUS_TARG_PRPH_RDAT); -} -#ifdef CONFIG_IWLWIFI_DEBUG -static inline u32 __iwl_read_restricted_reg(u32 line, - struct iwl_priv *priv, u32 reg) -{ - if (!atomic_read(&priv->restrict_refcnt)) - IWL_ERROR("Unrestricted access from line %d\n", line); - return _iwl_read_restricted_reg(priv, reg); -} - -#define iwl_read_restricted_reg(priv, reg) \ - __iwl_read_restricted_reg(__LINE__, priv, reg) -#else -#define iwl_read_restricted_reg _iwl_read_restricted_reg -#endif - -static inline void _iwl_write_restricted_reg(struct iwl_priv *priv, - u32 addr, u32 val) -{ - _iwl_write_restricted(priv, HBUS_TARG_PRPH_WADDR, - ((addr & 0x0000FFFF) | (3 << 24))); - _iwl_write_restricted(priv, HBUS_TARG_PRPH_WDAT, val); -} -#ifdef CONFIG_IWLWIFI_DEBUG -static inline void __iwl_write_restricted_reg(u32 line, - struct iwl_priv *priv, - u32 addr, u32 val) -{ - if (!atomic_read(&priv->restrict_refcnt)) - IWL_ERROR("Unrestricted access from line %d\n", line); - _iwl_write_restricted_reg(priv, addr, val); -} - -#define iwl_write_restricted_reg(priv, addr, val) \ - __iwl_write_restricted_reg(__LINE__, priv, addr, val); -#else -#define iwl_write_restricted_reg _iwl_write_restricted_reg -#endif - -#define _iwl_set_bits_restricted_reg(priv, reg, mask) \ - _iwl_write_restricted_reg(priv, reg, \ - (_iwl_read_restricted_reg(priv, reg) | mask)) -#ifdef CONFIG_IWLWIFI_DEBUG -static inline void __iwl_set_bits_restricted_reg(u32 line, struct iwl_priv - *priv, u32 reg, u32 mask) -{ - if (!atomic_read(&priv->restrict_refcnt)) - IWL_ERROR("Unrestricted access from line %d\n", line); - _iwl_set_bits_restricted_reg(priv, reg, mask); -} -#define iwl_set_bits_restricted_reg(priv, reg, mask) \ - __iwl_set_bits_restricted_reg(__LINE__, priv, reg, mask) -#else -#define iwl_set_bits_restricted_reg _iwl_set_bits_restricted_reg -#endif - -#define _iwl_set_bits_mask_restricted_reg(priv, reg, bits, mask) \ - _iwl_write_restricted_reg( \ - priv, reg, ((_iwl_read_restricted_reg(priv, reg) & mask) | bits)) -#ifdef CONFIG_IWLWIFI_DEBUG -static inline void __iwl_set_bits_mask_restricted_reg(u32 line, - struct iwl_priv *priv, u32 reg, u32 bits, u32 mask) -{ - if (!atomic_read(&priv->restrict_refcnt)) - IWL_ERROR("Unrestricted access from line %d\n", line); - _iwl_set_bits_mask_restricted_reg(priv, reg, bits, mask); -} - -#define iwl_set_bits_mask_restricted_reg(priv, reg, bits, mask) \ - __iwl_set_bits_mask_restricted_reg(__LINE__, priv, reg, bits, mask) -#else -#define iwl_set_bits_mask_restricted_reg _iwl_set_bits_mask_restricted_reg -#endif - -static inline void iwl_clear_bits_restricted_reg(struct iwl_priv - *priv, u32 reg, u32 mask) -{ - u32 val = _iwl_read_restricted_reg(priv, reg); - _iwl_write_restricted_reg(priv, reg, (val & ~mask)); -} - -static inline u32 iwl_read_restricted_mem(struct iwl_priv *priv, u32 addr) -{ - iwl_write_restricted(priv, HBUS_TARG_MEM_RADDR, addr); - return iwl_read_restricted(priv, HBUS_TARG_MEM_RDAT); -} - -static inline void iwl_write_restricted_mem(struct iwl_priv *priv, u32 addr, - u32 val) -{ - iwl_write_restricted(priv, HBUS_TARG_MEM_WADDR, addr); - iwl_write_restricted(priv, HBUS_TARG_MEM_WDAT, val); -} - -static inline void iwl_write_restricted_mems(struct iwl_priv *priv, u32 addr, - u32 len, u32 *values) -{ - iwl_write_restricted(priv, HBUS_TARG_MEM_WADDR, addr); - for (; 0 < len; len -= sizeof(u32), values++) - iwl_write_restricted(priv, HBUS_TARG_MEM_WDAT, *values); -} - -static inline void iwl_write_restricted_regs(struct iwl_priv *priv, u32 reg, - u32 len, u8 *values) -{ - u32 reg_offset = reg; - u32 aligment = reg & 0x3; - - /* write any non-dword-aligned stuff at the beginning */ - if (len < sizeof(u32)) { - if ((aligment + len) <= sizeof(u32)) { - u8 size; - u32 value = 0; - size = len - 1; - memcpy(&value, values, len); - reg_offset = (reg_offset & 0x0000FFFF); - - _iwl_write_restricted(priv, - HBUS_TARG_PRPH_WADDR, - (reg_offset | (size << 24))); - _iwl_write_restricted(priv, HBUS_TARG_PRPH_WDAT, - value); - } - - return; - } - - /* now write all the dword-aligned stuff */ - for (; reg_offset < (reg + len); - reg_offset += sizeof(u32), values += sizeof(u32)) - _iwl_write_restricted_reg(priv, reg_offset, *((u32 *) values)); -} - -#endif diff --git a/drivers/net/wireless/iwlwifi/iwl-priv.h b/drivers/net/wireless/iwlwifi/iwl-priv.h deleted file mode 100644 index 6b490d08fea..00000000000 --- a/drivers/net/wireless/iwlwifi/iwl-priv.h +++ /dev/null @@ -1,308 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * The full GNU General Public License is included in this distribution in the - * file called LICENSE. - * - * Contact Information: - * James P. Ketrenos <ipw2100-admin@linux.intel.com> - * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 - * - *****************************************************************************/ - -#ifndef __iwl_priv_h__ -#define __iwl_priv_h__ - -#include <linux/workqueue.h> - -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT - -enum { - MEASUREMENT_READY = (1 << 0), - MEASUREMENT_ACTIVE = (1 << 1), -}; - -#endif - -struct iwl_priv { - - /* ieee device used by generic ieee processing code */ - struct ieee80211_hw *hw; - struct ieee80211_channel *ieee_channels; - struct ieee80211_rate *ieee_rates; - - /* temporary frame storage list */ - struct list_head free_frames; - int frames_count; - - u8 phymode; - int alloc_rxb_skb; - - void (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb); - - const struct ieee80211_hw_mode *modes; - -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT - /* spectrum measurement report caching */ - struct iwl_spectrum_notification measure_report; - u8 measurement_status; -#endif - /* ucode beacon time */ - u32 ucode_beacon_time; - - /* we allocate array of iwl_channel_info for NIC's valid channels. - * Access via channel # using indirect index array */ - struct iwl_channel_info *channel_info; /* channel info array */ - u8 channel_count; /* # of channels */ - - /* each calibration channel group in the EEPROM has a derived - * clip setting for each rate. */ - const struct iwl_clip_group clip_groups[5]; - - /* thermal calibration */ - s32 temperature; /* degrees Kelvin */ - s32 last_temperature; - - /* Scan related variables */ - unsigned long last_scan_jiffies; - unsigned long scan_start; - unsigned long scan_pass_start; - unsigned long scan_start_tsf; - int scan_bands; - int one_direct_scan; - u8 direct_ssid_len; - u8 direct_ssid[IW_ESSID_MAX_SIZE]; - struct iwl_scan_cmd *scan; - u8 only_active_channel; - - /* spinlock */ - spinlock_t lock; /* protect general shared data */ - spinlock_t hcmd_lock; /* protect hcmd */ - struct mutex mutex; - - /* basic pci-network driver stuff */ - struct pci_dev *pci_dev; - - /* pci hardware address support */ - void __iomem *hw_base; - - /* uCode images, save to reload in case of failure */ - struct fw_image_desc ucode_code; /* runtime inst */ - struct fw_image_desc ucode_data; /* runtime data original */ - struct fw_image_desc ucode_data_backup; /* runtime data save/restore */ - struct fw_image_desc ucode_init; /* initialization inst */ - struct fw_image_desc ucode_init_data; /* initialization data */ - struct fw_image_desc ucode_boot; /* bootstrap inst */ - - - struct iwl_rxon_time_cmd rxon_timing; - - /* We declare this const so it can only be - * changed via explicit cast within the - * routines that actually update the physical - * hardware */ - const struct iwl_rxon_cmd active_rxon; - struct iwl_rxon_cmd staging_rxon; - - int error_recovering; - struct iwl_rxon_cmd recovery_rxon; - - /* 1st responses from initialize and runtime uCode images. - * 4965's initialize alive response contains some calibration data. */ - struct iwl_init_alive_resp card_alive_init; - struct iwl_alive_resp card_alive; - -#ifdef LED - /* LED related variables */ - struct iwl_activity_blink activity; - unsigned long led_packets; - int led_state; -#endif - - u16 active_rate; - u16 active_rate_basic; - - u8 call_post_assoc_from_beacon; - u8 assoc_station_added; -#if IWL == 4965 - u8 use_ant_b_for_management_frame; /* Tx antenna selection */ - /* HT variables */ - u8 is_dup; - u8 is_ht_enabled; - u8 channel_width; /* 0=20MHZ, 1=40MHZ */ - u8 current_channel_width; - u8 valid_antenna; /* Bit mask of antennas actually connected */ -#ifdef CONFIG_IWLWIFI_SENSITIVITY - struct iwl_sensitivity_data sensitivity_data; - struct iwl_chain_noise_data chain_noise_data; - u8 start_calib; - __le16 sensitivity_tbl[HD_TABLE_SIZE]; -#endif /*CONFIG_IWLWIFI_SENSITIVITY*/ - -#ifdef CONFIG_IWLWIFI_HT - struct sta_ht_info current_assoc_ht; -#endif - u8 active_rate_ht[2]; - u8 last_phy_res[100]; - - /* Rate scaling data */ - struct iwl_lq_mngr lq_mngr; -#endif - - /* Rate scaling data */ - s8 data_retry_limit; - u8 retry_rate; - - wait_queue_head_t wait_command_queue; - - int activity_timer_active; - - /* Rx and Tx DMA processing queues */ - struct iwl_rx_queue rxq; - struct iwl_tx_queue txq[IWL_MAX_NUM_QUEUES]; -#if IWL == 4965 - unsigned long txq_ctx_active_msk; - struct iwl_kw kw; /* keep warm address */ - u32 scd_base_addr; /* scheduler sram base address */ -#endif - - unsigned long status; - u32 config; - - int last_rx_rssi; /* From Rx packet statisitics */ - int last_rx_noise; /* From beacon statistics */ - - struct iwl_power_mgr power_data; - - struct iwl_notif_statistics statistics; - unsigned long last_statistics_time; - - /* context information */ - u8 essid[IW_ESSID_MAX_SIZE]; - u8 essid_len; - u16 rates_mask; - - u32 power_mode; - u32 antenna; - u8 bssid[ETH_ALEN]; - u16 rts_threshold; - u8 mac_addr[ETH_ALEN]; - - /*station table variables */ - spinlock_t sta_lock; - int num_stations; - struct iwl_station_entry stations[IWL_STATION_COUNT]; - - /* Indication if ieee80211_ops->open has been called */ - int is_open; - - u8 mac80211_registered; - int is_abg; - - u32 notif_missed_beacons; - - /* Rx'd packet timing information */ - u32 last_beacon_time; - u64 last_tsf; - - /* Duplicate packet detection */ - u16 last_seq_num; - u16 last_frag_num; - unsigned long last_packet_time; - struct list_head ibss_mac_hash[IWL_IBSS_MAC_HASH_SIZE]; - - /* eeprom */ - struct iwl_eeprom eeprom; - - int iw_mode; - - struct sk_buff *ibss_beacon; - - /* Last Rx'd beacon timestamp */ - u32 timestamp0; - u32 timestamp1; - u16 beacon_int; - struct iwl_driver_hw_info hw_setting; - int interface_id; - - /* Current association information needed to configure the - * hardware */ - u16 assoc_id; - u16 assoc_capability; - u8 ps_mode; - -#ifdef CONFIG_IWLWIFI_QOS - struct iwl_qos_info qos_data; -#endif /*CONFIG_IWLWIFI_QOS */ - - struct workqueue_struct *workqueue; - - struct work_struct up; - struct work_struct restart; - struct work_struct calibrated_work; - struct work_struct scan_completed; - struct work_struct rx_replenish; - struct work_struct rf_kill; - struct work_struct abort_scan; - struct work_struct update_link_led; - struct work_struct auth_work; - struct work_struct report_work; - struct work_struct request_scan; - struct work_struct beacon_update; - - struct tasklet_struct irq_tasklet; - - struct delayed_work init_alive_start; - struct delayed_work alive_start; - struct delayed_work activity_timer; - struct delayed_work thermal_periodic; - struct delayed_work gather_stats; - struct delayed_work scan_check; - struct delayed_work post_associate; - -#define IWL_DEFAULT_TX_POWER 0x0F - s8 user_txpower_limit; - s8 max_channel_txpower_limit; - u32 cck_power_index_compensation; - -#ifdef CONFIG_PM - u32 pm_state[16]; -#endif - -#ifdef CONFIG_IWLWIFI_DEBUG - /* debugging info */ - u32 framecnt_to_us; - atomic_t restrict_refcnt; -#endif - -#if IWL == 4965 - struct work_struct txpower_work; -#ifdef CONFIG_IWLWIFI_SENSITIVITY - struct work_struct sensitivity_work; -#endif - struct work_struct statistics_work; - struct timer_list statistics_periodic; - -#ifdef CONFIG_IWLWIFI_HT_AGG - struct work_struct agg_work; -#endif - -#endif /* 4965 */ -}; /*iwl_priv */ - -#endif /* __iwl_priv_h__ */ diff --git a/drivers/net/wireless/iwlwifi/iwl-prph.h b/drivers/net/wireless/iwlwifi/iwl-prph.h index 0df41148ead..4ba12163487 100644 --- a/drivers/net/wireless/iwlwifi/iwl-prph.h +++ b/drivers/net/wireless/iwlwifi/iwl-prph.h @@ -8,7 +8,7 @@ * Copyright(c) 2005 - 2007 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or modify - * it under the terms of version 2 of the GNU Geeral Public License as + * it under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but @@ -63,7 +63,10 @@ #ifndef __iwl_prph_h__ #define __iwl_prph_h__ - +/* + * Registers in this file are internal, not PCI bus memory mapped. + * Driver accesses these via HBUS_TARG_PRPH_* registers. + */ #define PRPH_BASE (0x00000) #define PRPH_END (0xFFFFF) @@ -226,4 +229,58 @@ #define BSM_SRAM_SIZE (1024) /* bytes */ +/* 3945 Tx scheduler registers */ +#define ALM_SCD_BASE (PRPH_BASE + 0x2E00) +#define ALM_SCD_MODE_REG (ALM_SCD_BASE + 0x000) +#define ALM_SCD_ARASTAT_REG (ALM_SCD_BASE + 0x004) +#define ALM_SCD_TXFACT_REG (ALM_SCD_BASE + 0x010) +#define ALM_SCD_TXF4MF_REG (ALM_SCD_BASE + 0x014) +#define ALM_SCD_TXF5MF_REG (ALM_SCD_BASE + 0x020) +#define ALM_SCD_SBYP_MODE_1_REG (ALM_SCD_BASE + 0x02C) +#define ALM_SCD_SBYP_MODE_2_REG (ALM_SCD_BASE + 0x030) + +/* + * 4965 Tx Scheduler registers. + * Details are documented in iwl-4965-hw.h + */ +#define KDR_SCD_BASE (PRPH_BASE + 0xa02c00) + +#define KDR_SCD_SRAM_BASE_ADDR (KDR_SCD_BASE + 0x0) +#define KDR_SCD_EMPTY_BITS (KDR_SCD_BASE + 0x4) +#define KDR_SCD_DRAM_BASE_ADDR (KDR_SCD_BASE + 0x10) +#define KDR_SCD_AIT (KDR_SCD_BASE + 0x18) +#define KDR_SCD_TXFACT (KDR_SCD_BASE + 0x1c) +#define KDR_SCD_QUEUE_WRPTR(x) (KDR_SCD_BASE + 0x24 + (x) * 4) +#define KDR_SCD_QUEUE_RDPTR(x) (KDR_SCD_BASE + 0x64 + (x) * 4) +#define KDR_SCD_SETQUEUENUM (KDR_SCD_BASE + 0xa4) +#define KDR_SCD_SET_TXSTAT_TXED (KDR_SCD_BASE + 0xa8) +#define KDR_SCD_SET_TXSTAT_DONE (KDR_SCD_BASE + 0xac) +#define KDR_SCD_SET_TXSTAT_NOT_SCHD (KDR_SCD_BASE + 0xb0) +#define KDR_SCD_DECREASE_CREDIT (KDR_SCD_BASE + 0xb4) +#define KDR_SCD_DECREASE_SCREDIT (KDR_SCD_BASE + 0xb8) +#define KDR_SCD_LOAD_CREDIT (KDR_SCD_BASE + 0xbc) +#define KDR_SCD_LOAD_SCREDIT (KDR_SCD_BASE + 0xc0) +#define KDR_SCD_BAR (KDR_SCD_BASE + 0xc4) +#define KDR_SCD_BAR_DW0 (KDR_SCD_BASE + 0xc8) +#define KDR_SCD_BAR_DW1 (KDR_SCD_BASE + 0xcc) +#define KDR_SCD_QUEUECHAIN_SEL (KDR_SCD_BASE + 0xd0) +#define KDR_SCD_QUERY_REQ (KDR_SCD_BASE + 0xd8) +#define KDR_SCD_QUERY_RES (KDR_SCD_BASE + 0xdc) +#define KDR_SCD_PENDING_FRAMES (KDR_SCD_BASE + 0xe0) +#define KDR_SCD_INTERRUPT_MASK (KDR_SCD_BASE + 0xe4) +#define KDR_SCD_INTERRUPT_THRESHOLD (KDR_SCD_BASE + 0xe8) +#define KDR_SCD_QUERY_MIN_FRAME_SIZE (KDR_SCD_BASE + 0x100) +#define KDR_SCD_QUEUE_STATUS_BITS(x) (KDR_SCD_BASE + 0x104 + (x) * 4) + +/* SP SCD */ +#define SHL_SCD_BASE (PRPH_BASE + 0xa02c00) + +#define SHL_SCD_AIT (SHL_SCD_BASE + 0x0c) +#define SHL_SCD_TXFACT (SHL_SCD_BASE + 0x10) +#define SHL_SCD_QUEUE_WRPTR(x) (SHL_SCD_BASE + 0x18 + (x) * 4) +#define SHL_SCD_QUEUE_RDPTR(x) (SHL_SCD_BASE + 0x68 + (x) * 4) +#define SHL_SCD_QUEUECHAIN_SEL (SHL_SCD_BASE + 0xe8) +#define SHL_SCD_AGGR_SEL (SHL_SCD_BASE + 0x248) +#define SHL_SCD_INTERRUPT_MASK (SHL_SCD_BASE + 0x108) + #endif /* __iwl_prph_h__ */ diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c index 1a6b0e0edf6..748ac1222ab 100644 --- a/drivers/net/wireless/iwlwifi/iwl3945-base.c +++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c @@ -27,16 +27,6 @@ * *****************************************************************************/ -/* - * NOTE: This file (iwl-base.c) is used to build to multiple hardware targets - * by defining IWL to either 3945 or 4965. The Makefile used when building - * the base targets will create base-3945.o and base-4965.o - * - * The eventual goal is to move as many of the #if IWL / #endif blocks out of - * this file and into the hardware specific implementation files (iwl-XXXX.c) - * and leave only the common (non #ifdef sprinkled) code in this file - */ - #include <linux/kernel.h> #include <linux/module.h> #include <linux/version.h> @@ -56,16 +46,16 @@ #include <asm/div64.h> -#define IWL 3945 - -#include "iwlwifi.h" #include "iwl-3945.h" #include "iwl-helpers.h" -#ifdef CONFIG_IWLWIFI_DEBUG -u32 iwl_debug_level; +#ifdef CONFIG_IWL3945_DEBUG +u32 iwl3945_debug_level; #endif +static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv, + struct iwl3945_tx_queue *txq); + /****************************************************************************** * * module boiler plate @@ -73,13 +63,13 @@ u32 iwl_debug_level; ******************************************************************************/ /* module parameters */ -int iwl_param_disable_hw_scan; -int iwl_param_debug; -int iwl_param_disable; /* def: enable radio */ -int iwl_param_antenna; /* def: 0 = both antennas (use diversity) */ -int iwl_param_hwcrypto; /* def: using software encryption */ -int iwl_param_qos_enable = 1; -int iwl_param_queues_num = IWL_MAX_NUM_QUEUES; +static int iwl3945_param_disable_hw_scan; /* def: 0 = use 3945's h/w scan */ +static int iwl3945_param_debug; /* def: 0 = minimal debug log messages */ +static int iwl3945_param_disable; /* def: 0 = enable radio */ +static int iwl3945_param_antenna; /* def: 0 = both antennas (use diversity) */ +int iwl3945_param_hwcrypto; /* def: 0 = use software encryption */ +static int iwl3945_param_qos_enable = 1; /* def: 1 = use quality of service */ +int iwl3945_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 8 Tx queues */ /* * module name, copyright, version, etc. @@ -89,19 +79,19 @@ int iwl_param_queues_num = IWL_MAX_NUM_QUEUES; #define DRV_DESCRIPTION \ "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux" -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL3945_DEBUG #define VD "d" #else #define VD #endif -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT +#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT #define VS "s" #else #define VS #endif -#define IWLWIFI_VERSION "1.1.17k" VD VS +#define IWLWIFI_VERSION "1.2.23k" VD VS #define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation" #define DRV_VERSION IWLWIFI_VERSION @@ -116,7 +106,7 @@ MODULE_VERSION(DRV_VERSION); MODULE_AUTHOR(DRV_COPYRIGHT); MODULE_LICENSE("GPL"); -__le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) +static __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) { u16 fc = le16_to_cpu(hdr->frame_control); int hdr_len = ieee80211_get_hdrlen(fc); @@ -126,8 +116,8 @@ __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) return NULL; } -static const struct ieee80211_hw_mode *iwl_get_hw_mode( - struct iwl_priv *priv, int mode) +static const struct ieee80211_hw_mode *iwl3945_get_hw_mode( + struct iwl3945_priv *priv, int mode) { int i; @@ -138,7 +128,7 @@ static const struct ieee80211_hw_mode *iwl_get_hw_mode( return NULL; } -static int iwl_is_empty_essid(const char *essid, int essid_len) +static int iwl3945_is_empty_essid(const char *essid, int essid_len) { /* Single white space is for Linksys APs */ if (essid_len == 1 && essid[0] == ' ') @@ -154,13 +144,13 @@ static int iwl_is_empty_essid(const char *essid, int essid_len) return 1; } -static const char *iwl_escape_essid(const char *essid, u8 essid_len) +static const char *iwl3945_escape_essid(const char *essid, u8 essid_len) { static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; const char *s = essid; char *d = escaped; - if (iwl_is_empty_essid(essid, essid_len)) { + if (iwl3945_is_empty_essid(essid, essid_len)) { memcpy(escaped, "<hidden>", sizeof("<hidden>")); return escaped; } @@ -178,10 +168,10 @@ static const char *iwl_escape_essid(const char *essid, u8 essid_len) return escaped; } -static void iwl_print_hex_dump(int level, void *p, u32 len) +static void iwl3945_print_hex_dump(int level, void *p, u32 len) { -#ifdef CONFIG_IWLWIFI_DEBUG - if (!(iwl_debug_level & level)) +#ifdef CONFIG_IWL3945_DEBUG + if (!(iwl3945_debug_level & level)) return; print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1, @@ -194,24 +184,31 @@ static void iwl_print_hex_dump(int level, void *p, u32 len) * * Theory of operation * - * A queue is a circular buffers with 'Read' and 'Write' pointers. - * 2 empty entries always kept in the buffer to protect from overflow. + * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer + * of buffer descriptors, each of which points to one or more data buffers for + * the device to read from or fill. Driver and device exchange status of each + * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty + * entries in each circular buffer, to protect against confusing empty and full + * queue states. + * + * The device reads or writes the data in the queues via the device's several + * DMA/FIFO channels. Each queue is mapped to a single DMA channel. * * For Tx queue, there are low mark and high mark limits. If, after queuing * the packet for Tx, free space become < low mark, Tx queue stopped. When * reclaiming packets (on 'tx done IRQ), if free space become > high mark, * Tx queue resumed. * - * The IWL operates with six queues, one receive queue in the device's - * sram, one transmit queue for sending commands to the device firmware, - * and four transmit queues for data. + * The 3945 operates with six queues: One receive queue, one transmit queue + * (#4) for sending commands to the device firmware, and four transmit queues + * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused. ***************************************************/ -static int iwl_queue_space(const struct iwl_queue *q) +static int iwl3945_queue_space(const struct iwl3945_queue *q) { - int s = q->last_used - q->first_empty; + int s = q->read_ptr - q->write_ptr; - if (q->last_used > q->first_empty) + if (q->read_ptr > q->write_ptr) s -= q->n_bd; if (s <= 0) @@ -223,42 +220,55 @@ static int iwl_queue_space(const struct iwl_queue *q) return s; } -/* XXX: n_bd must be power-of-two size */ -static inline int iwl_queue_inc_wrap(int index, int n_bd) +/** + * iwl3945_queue_inc_wrap - increment queue index, wrap back to beginning + * @index -- current index + * @n_bd -- total number of entries in queue (must be power of 2) + */ +static inline int iwl3945_queue_inc_wrap(int index, int n_bd) { return ++index & (n_bd - 1); } -/* XXX: n_bd must be power-of-two size */ -static inline int iwl_queue_dec_wrap(int index, int n_bd) +/** + * iwl3945_queue_dec_wrap - increment queue index, wrap back to end + * @index -- current index + * @n_bd -- total number of entries in queue (must be power of 2) + */ +static inline int iwl3945_queue_dec_wrap(int index, int n_bd) { return --index & (n_bd - 1); } -static inline int x2_queue_used(const struct iwl_queue *q, int i) +static inline int x2_queue_used(const struct iwl3945_queue *q, int i) { - return q->first_empty > q->last_used ? - (i >= q->last_used && i < q->first_empty) : - !(i < q->last_used && i >= q->first_empty); + return q->write_ptr > q->read_ptr ? + (i >= q->read_ptr && i < q->write_ptr) : + !(i < q->read_ptr && i >= q->write_ptr); } -static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge) +static inline u8 get_cmd_index(struct iwl3945_queue *q, u32 index, int is_huge) { + /* This is for scan command, the big buffer at end of command array */ if (is_huge) - return q->n_window; + return q->n_window; /* must be power of 2 */ + /* Otherwise, use normal size buffers */ return index & (q->n_window - 1); } -static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q, +/** + * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes + */ +static int iwl3945_queue_init(struct iwl3945_priv *priv, struct iwl3945_queue *q, int count, int slots_num, u32 id) { q->n_bd = count; q->n_window = slots_num; q->id = id; - /* count must be power-of-two size, otherwise iwl_queue_inc_wrap - * and iwl_queue_dec_wrap are broken. */ + /* count must be power-of-two size, otherwise iwl3945_queue_inc_wrap + * and iwl3945_queue_dec_wrap are broken. */ BUG_ON(!is_power_of_2(count)); /* slots_num must be power-of-two size, otherwise @@ -273,27 +283,34 @@ static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q, if (q->high_mark < 2) q->high_mark = 2; - q->first_empty = q->last_used = 0; + q->write_ptr = q->read_ptr = 0; return 0; } -static int iwl_tx_queue_alloc(struct iwl_priv *priv, - struct iwl_tx_queue *txq, u32 id) +/** + * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue + */ +static int iwl3945_tx_queue_alloc(struct iwl3945_priv *priv, + struct iwl3945_tx_queue *txq, u32 id) { struct pci_dev *dev = priv->pci_dev; + /* Driver private data, only for Tx (not command) queues, + * not shared with device. */ if (id != IWL_CMD_QUEUE_NUM) { txq->txb = kmalloc(sizeof(txq->txb[0]) * TFD_QUEUE_SIZE_MAX, GFP_KERNEL); if (!txq->txb) { - IWL_ERROR("kmalloc for auxilary BD " + IWL_ERROR("kmalloc for auxiliary BD " "structures failed\n"); goto error; } } else txq->txb = NULL; + /* Circular buffer of transmit frame descriptors (TFDs), + * shared with device */ txq->bd = pci_alloc_consistent(dev, sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, &txq->q.dma_addr); @@ -316,24 +333,33 @@ static int iwl_tx_queue_alloc(struct iwl_priv *priv, return -ENOMEM; } -int iwl_tx_queue_init(struct iwl_priv *priv, - struct iwl_tx_queue *txq, int slots_num, u32 txq_id) +/** + * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue + */ +int iwl3945_tx_queue_init(struct iwl3945_priv *priv, + struct iwl3945_tx_queue *txq, int slots_num, u32 txq_id) { struct pci_dev *dev = priv->pci_dev; int len; int rc = 0; - /* alocate command space + one big command for scan since scan - * command is very huge the system will not have two scan at the - * same time */ - len = sizeof(struct iwl_cmd) * slots_num; + /* + * Alloc buffer array for commands (Tx or other types of commands). + * For the command queue (#4), allocate command space + one big + * command for scan, since scan command is very huge; the system will + * not have two scans at the same time, so only one is needed. + * For data Tx queues (all other queues), no super-size command + * space is needed. + */ + len = sizeof(struct iwl3945_cmd) * slots_num; if (txq_id == IWL_CMD_QUEUE_NUM) len += IWL_MAX_SCAN_SIZE; txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); if (!txq->cmd) return -ENOMEM; - rc = iwl_tx_queue_alloc(priv, txq, txq_id); + /* Alloc driver data array and TFD circular buffer */ + rc = iwl3945_tx_queue_alloc(priv, txq, txq_id); if (rc) { pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); @@ -342,26 +368,29 @@ int iwl_tx_queue_init(struct iwl_priv *priv, txq->need_update = 0; /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise - * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ + * iwl3945_queue_inc_wrap and iwl3945_queue_dec_wrap are broken. */ BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); - iwl_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id); - iwl_hw_tx_queue_init(priv, txq); + /* Initialize queue high/low-water, head/tail indexes */ + iwl3945_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id); + + /* Tell device where to find queue, enable DMA channel. */ + iwl3945_hw_tx_queue_init(priv, txq); return 0; } /** - * iwl_tx_queue_free - Deallocate DMA queue. + * iwl3945_tx_queue_free - Deallocate DMA queue. * @txq: Transmit queue to deallocate. * * Empty queue by removing and destroying all BD's. - * Free all buffers. txq itself is not freed. - * + * Free all buffers. + * 0-fill, but do not free "txq" descriptor structure. */ -void iwl_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq) +void iwl3945_tx_queue_free(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq) { - struct iwl_queue *q = &txq->q; + struct iwl3945_queue *q = &txq->q; struct pci_dev *dev = priv->pci_dev; int len; @@ -369,44 +398,47 @@ void iwl_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq) return; /* first, empty all BD's */ - for (; q->first_empty != q->last_used; - q->last_used = iwl_queue_inc_wrap(q->last_used, q->n_bd)) - iwl_hw_txq_free_tfd(priv, txq); + for (; q->write_ptr != q->read_ptr; + q->read_ptr = iwl3945_queue_inc_wrap(q->read_ptr, q->n_bd)) + iwl3945_hw_txq_free_tfd(priv, txq); - len = sizeof(struct iwl_cmd) * q->n_window; + len = sizeof(struct iwl3945_cmd) * q->n_window; if (q->id == IWL_CMD_QUEUE_NUM) len += IWL_MAX_SCAN_SIZE; + /* De-alloc array of command/tx buffers */ pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); - /* free buffers belonging to queue itself */ + /* De-alloc circular buffer of TFDs */ if (txq->q.n_bd) - pci_free_consistent(dev, sizeof(struct iwl_tfd_frame) * + pci_free_consistent(dev, sizeof(struct iwl3945_tfd_frame) * txq->q.n_bd, txq->bd, txq->q.dma_addr); + /* De-alloc array of per-TFD driver data */ if (txq->txb) { kfree(txq->txb); txq->txb = NULL; } - /* 0 fill whole structure */ + /* 0-fill queue descriptor structure */ memset(txq, 0, sizeof(*txq)); } -const u8 BROADCAST_ADDR[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; +const u8 iwl3945_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; /*************** STATION TABLE MANAGEMENT **** - * - * NOTE: This needs to be overhauled to better synchronize between - * how the iwl-4965.c is using iwl_hw_find_station vs. iwl-3945.c - * - * mac80211 should also be examined to determine if sta_info is duplicating + * mac80211 should be examined to determine if sta_info is duplicating * the functionality provided here */ /**************************************************************/ -#if 0 /* temparary disable till we add real remove station */ -static u8 iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) +#if 0 /* temporary disable till we add real remove station */ +/** + * iwl3945_remove_station - Remove driver's knowledge of station. + * + * NOTE: This does not remove station from device's station table. + */ +static u8 iwl3945_remove_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap) { int index = IWL_INVALID_STATION; int i; @@ -442,7 +474,13 @@ out: return 0; } #endif -static void iwl_clear_stations_table(struct iwl_priv *priv) + +/** + * iwl3945_clear_stations_table - Clear the driver's station table + * + * NOTE: This does not clear or otherwise alter the device's station table. + */ +static void iwl3945_clear_stations_table(struct iwl3945_priv *priv) { unsigned long flags; @@ -454,12 +492,14 @@ static void iwl_clear_stations_table(struct iwl_priv *priv) spin_unlock_irqrestore(&priv->sta_lock, flags); } - -u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags) +/** + * iwl3945_add_station - Add station to station tables in driver and device + */ +u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap, u8 flags) { int i; int index = IWL_INVALID_STATION; - struct iwl_station_entry *station; + struct iwl3945_station_entry *station; unsigned long flags_spin; DECLARE_MAC_BUF(mac); u8 rate; @@ -482,7 +522,7 @@ u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags) index = i; } - /* These twh conditions has the same outcome but keep them separate + /* These two conditions has the same outcome but keep them separate since they have different meaning */ if (unlikely(index == IWL_INVALID_STATION)) { spin_unlock_irqrestore(&priv->sta_lock, flags_spin); @@ -500,30 +540,35 @@ u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags) station->used = 1; priv->num_stations++; - memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); + /* Set up the REPLY_ADD_STA command to send to device */ + memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd)); memcpy(station->sta.sta.addr, addr, ETH_ALEN); station->sta.mode = 0; station->sta.sta.sta_id = index; station->sta.station_flags = 0; - rate = (priv->phymode == MODE_IEEE80211A) ? IWL_RATE_6M_PLCP : - IWL_RATE_1M_PLCP | priv->hw_setting.cck_flag; + if (priv->phymode == MODE_IEEE80211A) + rate = IWL_RATE_6M_PLCP; + else + rate = IWL_RATE_1M_PLCP; /* Turn on both antennas for the station... */ station->sta.rate_n_flags = - iwl_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK); + iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK); station->current_rate.rate_n_flags = le16_to_cpu(station->sta.rate_n_flags); spin_unlock_irqrestore(&priv->sta_lock, flags_spin); - iwl_send_add_station(priv, &station->sta, flags); + + /* Add station to device's station table */ + iwl3945_send_add_station(priv, &station->sta, flags); return index; } /*************** DRIVER STATUS FUNCTIONS *****/ -static inline int iwl_is_ready(struct iwl_priv *priv) +static inline int iwl3945_is_ready(struct iwl3945_priv *priv) { /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are * set but EXIT_PENDING is not */ @@ -532,29 +577,29 @@ static inline int iwl_is_ready(struct iwl_priv *priv) !test_bit(STATUS_EXIT_PENDING, &priv->status); } -static inline int iwl_is_alive(struct iwl_priv *priv) +static inline int iwl3945_is_alive(struct iwl3945_priv *priv) { return test_bit(STATUS_ALIVE, &priv->status); } -static inline int iwl_is_init(struct iwl_priv *priv) +static inline int iwl3945_is_init(struct iwl3945_priv *priv) { return test_bit(STATUS_INIT, &priv->status); } -static inline int iwl_is_rfkill(struct iwl_priv *priv) +static inline int iwl3945_is_rfkill(struct iwl3945_priv *priv) { return test_bit(STATUS_RF_KILL_HW, &priv->status) || test_bit(STATUS_RF_KILL_SW, &priv->status); } -static inline int iwl_is_ready_rf(struct iwl_priv *priv) +static inline int iwl3945_is_ready_rf(struct iwl3945_priv *priv) { - if (iwl_is_rfkill(priv)) + if (iwl3945_is_rfkill(priv)) return 0; - return iwl_is_ready(priv); + return iwl3945_is_ready(priv); } /*************** HOST COMMAND QUEUE FUNCTIONS *****/ @@ -613,7 +658,7 @@ static const char *get_cmd_string(u8 cmd) #define HOST_COMPLETE_TIMEOUT (HZ / 2) /** - * iwl_enqueue_hcmd - enqueue a uCode command + * iwl3945_enqueue_hcmd - enqueue a uCode command * @priv: device private data point * @cmd: a point to the ucode command structure * @@ -621,13 +666,13 @@ static const char *get_cmd_string(u8 cmd) * failed. On success, it turns the index (> 0) of command in the * command queue. */ -static int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) +static int iwl3945_enqueue_hcmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd) { - struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; - struct iwl_queue *q = &txq->q; - struct iwl_tfd_frame *tfd; + struct iwl3945_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; + struct iwl3945_queue *q = &txq->q; + struct iwl3945_tfd_frame *tfd; u32 *control_flags; - struct iwl_cmd *out_cmd; + struct iwl3945_cmd *out_cmd; u32 idx; u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); dma_addr_t phys_addr; @@ -642,19 +687,19 @@ static int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && !(cmd->meta.flags & CMD_SIZE_HUGE)); - if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { + if (iwl3945_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { IWL_ERROR("No space for Tx\n"); return -ENOSPC; } spin_lock_irqsave(&priv->hcmd_lock, flags); - tfd = &txq->bd[q->first_empty]; + tfd = &txq->bd[q->write_ptr]; memset(tfd, 0, sizeof(*tfd)); control_flags = (u32 *) tfd; - idx = get_cmd_index(q, q->first_empty, cmd->meta.flags & CMD_SIZE_HUGE); + idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE); out_cmd = &txq->cmd[idx]; out_cmd->hdr.cmd = cmd->id; @@ -666,13 +711,13 @@ static int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) out_cmd->hdr.flags = 0; out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) | - INDEX_TO_SEQ(q->first_empty)); + INDEX_TO_SEQ(q->write_ptr)); if (out_cmd->meta.flags & CMD_SIZE_HUGE) out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + - offsetof(struct iwl_cmd, hdr); - iwl_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size); + offsetof(struct iwl3945_cmd, hdr); + iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size); pad = U32_PAD(cmd->len); count = TFD_CTL_COUNT_GET(*control_flags); @@ -682,17 +727,19 @@ static int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) "%d bytes at %d[%d]:%d\n", get_cmd_string(out_cmd->hdr.cmd), out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), - fix_size, q->first_empty, idx, IWL_CMD_QUEUE_NUM); + fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); txq->need_update = 1; - q->first_empty = iwl_queue_inc_wrap(q->first_empty, q->n_bd); - ret = iwl_tx_queue_update_write_ptr(priv, txq); + + /* Increment and update queue's write index */ + q->write_ptr = iwl3945_queue_inc_wrap(q->write_ptr, q->n_bd); + ret = iwl3945_tx_queue_update_write_ptr(priv, txq); spin_unlock_irqrestore(&priv->hcmd_lock, flags); return ret ? ret : idx; } -int iwl_send_cmd_async(struct iwl_priv *priv, struct iwl_host_cmd *cmd) +static int iwl3945_send_cmd_async(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd) { int ret; @@ -707,16 +754,16 @@ int iwl_send_cmd_async(struct iwl_priv *priv, struct iwl_host_cmd *cmd) if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return -EBUSY; - ret = iwl_enqueue_hcmd(priv, cmd); + ret = iwl3945_enqueue_hcmd(priv, cmd); if (ret < 0) { - IWL_ERROR("Error sending %s: iwl_enqueue_hcmd failed: %d\n", + IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", get_cmd_string(cmd->id), ret); return ret; } return 0; } -int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd) +static int iwl3945_send_cmd_sync(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd) { int cmd_idx; int ret; @@ -738,10 +785,10 @@ int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd) if (cmd->meta.flags & CMD_WANT_SKB) cmd->meta.source = &cmd->meta; - cmd_idx = iwl_enqueue_hcmd(priv, cmd); + cmd_idx = iwl3945_enqueue_hcmd(priv, cmd); if (cmd_idx < 0) { ret = cmd_idx; - IWL_ERROR("Error sending %s: iwl_enqueue_hcmd failed: %d\n", + IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", get_cmd_string(cmd->id), ret); goto out; } @@ -785,7 +832,7 @@ int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd) cancel: if (cmd->meta.flags & CMD_WANT_SKB) { - struct iwl_cmd *qcmd; + struct iwl3945_cmd *qcmd; /* Cancel the CMD_WANT_SKB flag for the cmd in the * TX cmd queue. Otherwise in case the cmd comes @@ -804,47 +851,43 @@ out: return ret; } -int iwl_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) +int iwl3945_send_cmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd) { - /* A command can not be asynchronous AND expect an SKB to be set. */ - BUG_ON((cmd->meta.flags & CMD_ASYNC) && - (cmd->meta.flags & CMD_WANT_SKB)); - if (cmd->meta.flags & CMD_ASYNC) - return iwl_send_cmd_async(priv, cmd); + return iwl3945_send_cmd_async(priv, cmd); - return iwl_send_cmd_sync(priv, cmd); + return iwl3945_send_cmd_sync(priv, cmd); } -int iwl_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data) +int iwl3945_send_cmd_pdu(struct iwl3945_priv *priv, u8 id, u16 len, const void *data) { - struct iwl_host_cmd cmd = { + struct iwl3945_host_cmd cmd = { .id = id, .len = len, .data = data, }; - return iwl_send_cmd_sync(priv, &cmd); + return iwl3945_send_cmd_sync(priv, &cmd); } -static int __must_check iwl_send_cmd_u32(struct iwl_priv *priv, u8 id, u32 val) +static int __must_check iwl3945_send_cmd_u32(struct iwl3945_priv *priv, u8 id, u32 val) { - struct iwl_host_cmd cmd = { + struct iwl3945_host_cmd cmd = { .id = id, .len = sizeof(val), .data = &val, }; - return iwl_send_cmd_sync(priv, &cmd); + return iwl3945_send_cmd_sync(priv, &cmd); } -int iwl_send_statistics_request(struct iwl_priv *priv) +int iwl3945_send_statistics_request(struct iwl3945_priv *priv) { - return iwl_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); + return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); } /** - * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON + * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz * @channel: Any channel valid for the requested phymode @@ -853,9 +896,9 @@ int iwl_send_statistics_request(struct iwl_priv *priv) * NOTE: Does not commit to the hardware; it sets appropriate bit fields * in the staging RXON flag structure based on the phymode */ -static int iwl_set_rxon_channel(struct iwl_priv *priv, u8 phymode, u16 channel) +static int iwl3945_set_rxon_channel(struct iwl3945_priv *priv, u8 phymode, u16 channel) { - if (!iwl_get_channel_info(priv, phymode, channel)) { + if (!iwl3945_get_channel_info(priv, phymode, channel)) { IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", channel, phymode); return -EINVAL; @@ -879,13 +922,13 @@ static int iwl_set_rxon_channel(struct iwl_priv *priv, u8 phymode, u16 channel) } /** - * iwl_check_rxon_cmd - validate RXON structure is valid + * iwl3945_check_rxon_cmd - validate RXON structure is valid * * NOTE: This is really only useful during development and can eventually * be #ifdef'd out once the driver is stable and folks aren't actively * making changes */ -static int iwl_check_rxon_cmd(struct iwl_rxon_cmd *rxon) +static int iwl3945_check_rxon_cmd(struct iwl3945_rxon_cmd *rxon) { int error = 0; int counter = 1; @@ -951,21 +994,21 @@ static int iwl_check_rxon_cmd(struct iwl_rxon_cmd *rxon) le16_to_cpu(rxon->channel)); if (error) { - IWL_ERROR("Not a valid iwl_rxon_assoc_cmd field values\n"); + IWL_ERROR("Not a valid iwl3945_rxon_assoc_cmd field values\n"); return -1; } return 0; } /** - * iwl_full_rxon_required - determine if RXON_ASSOC can be used in RXON commit - * @priv: staging_rxon is comapred to active_rxon + * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed + * @priv: staging_rxon is compared to active_rxon * - * If the RXON structure is changing sufficient to require a new - * tune or to clear and reset the RXON_FILTER_ASSOC_MSK then return 1 - * to indicate a new tune is required. + * If the RXON structure is changing enough to require a new tune, + * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that + * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. */ -static int iwl_full_rxon_required(struct iwl_priv *priv) +static int iwl3945_full_rxon_required(struct iwl3945_priv *priv) { /* These items are only settable from the full RXON command */ @@ -1000,19 +1043,19 @@ static int iwl_full_rxon_required(struct iwl_priv *priv) return 0; } -static int iwl_send_rxon_assoc(struct iwl_priv *priv) +static int iwl3945_send_rxon_assoc(struct iwl3945_priv *priv) { int rc = 0; - struct iwl_rx_packet *res = NULL; - struct iwl_rxon_assoc_cmd rxon_assoc; - struct iwl_host_cmd cmd = { + struct iwl3945_rx_packet *res = NULL; + struct iwl3945_rxon_assoc_cmd rxon_assoc; + struct iwl3945_host_cmd cmd = { .id = REPLY_RXON_ASSOC, .len = sizeof(rxon_assoc), .meta.flags = CMD_WANT_SKB, .data = &rxon_assoc, }; - const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon; - const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon; + const struct iwl3945_rxon_cmd *rxon1 = &priv->staging_rxon; + const struct iwl3945_rxon_cmd *rxon2 = &priv->active_rxon; if ((rxon1->flags == rxon2->flags) && (rxon1->filter_flags == rxon2->filter_flags) && @@ -1028,11 +1071,11 @@ static int iwl_send_rxon_assoc(struct iwl_priv *priv) rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; rxon_assoc.reserved = 0; - rc = iwl_send_cmd_sync(priv, &cmd); + rc = iwl3945_send_cmd_sync(priv, &cmd); if (rc) return rc; - res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; + res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data; if (res->hdr.flags & IWL_CMD_FAILED_MSK) { IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n"); rc = -EIO; @@ -1045,21 +1088,21 @@ static int iwl_send_rxon_assoc(struct iwl_priv *priv) } /** - * iwl_commit_rxon - commit staging_rxon to hardware + * iwl3945_commit_rxon - commit staging_rxon to hardware * - * The RXON command in staging_rxon is commited to the hardware and + * The RXON command in staging_rxon is committed to the hardware and * the active_rxon structure is updated with the new data. This * function correctly transitions out of the RXON_ASSOC_MSK state if * a HW tune is required based on the RXON structure changes. */ -static int iwl_commit_rxon(struct iwl_priv *priv) +static int iwl3945_commit_rxon(struct iwl3945_priv *priv) { /* cast away the const for active_rxon in this function */ - struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; + struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon; int rc = 0; DECLARE_MAC_BUF(mac); - if (!iwl_is_alive(priv)) + if (!iwl3945_is_alive(priv)) return -1; /* always get timestamp with Rx frame */ @@ -1070,17 +1113,17 @@ static int iwl_commit_rxon(struct iwl_priv *priv) ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK); priv->staging_rxon.flags |= iwl3945_get_antenna_flags(priv); - rc = iwl_check_rxon_cmd(&priv->staging_rxon); + rc = iwl3945_check_rxon_cmd(&priv->staging_rxon); if (rc) { IWL_ERROR("Invalid RXON configuration. Not committing.\n"); return -EINVAL; } /* If we don't need to send a full RXON, we can use - * iwl_rxon_assoc_cmd which is used to reconfigure filter + * iwl3945_rxon_assoc_cmd which is used to reconfigure filter * and other flags for the current radio configuration. */ - if (!iwl_full_rxon_required(priv)) { - rc = iwl_send_rxon_assoc(priv); + if (!iwl3945_full_rxon_required(priv)) { + rc = iwl3945_send_rxon_assoc(priv); if (rc) { IWL_ERROR("Error setting RXON_ASSOC " "configuration (%d).\n", rc); @@ -1096,13 +1139,13 @@ static int iwl_commit_rxon(struct iwl_priv *priv) * an RXON_ASSOC and the new config wants the associated mask enabled, * we must clear the associated from the active configuration * before we apply the new config */ - if (iwl_is_associated(priv) && + if (iwl3945_is_associated(priv) && (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; - rc = iwl_send_cmd_pdu(priv, REPLY_RXON, - sizeof(struct iwl_rxon_cmd), + rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, + sizeof(struct iwl3945_rxon_cmd), &priv->active_rxon); /* If the mask clearing failed then we set @@ -1125,8 +1168,8 @@ static int iwl_commit_rxon(struct iwl_priv *priv) print_mac(mac, priv->staging_rxon.bssid_addr)); /* Apply the new configuration */ - rc = iwl_send_cmd_pdu(priv, REPLY_RXON, - sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); + rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, + sizeof(struct iwl3945_rxon_cmd), &priv->staging_rxon); if (rc) { IWL_ERROR("Error setting new configuration (%d).\n", rc); return rc; @@ -1134,18 +1177,18 @@ static int iwl_commit_rxon(struct iwl_priv *priv) memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); - iwl_clear_stations_table(priv); + iwl3945_clear_stations_table(priv); /* If we issue a new RXON command which required a tune then we must * send a new TXPOWER command or we won't be able to Tx any frames */ - rc = iwl_hw_reg_send_txpower(priv); + rc = iwl3945_hw_reg_send_txpower(priv); if (rc) { IWL_ERROR("Error setting Tx power (%d).\n", rc); return rc; } /* Add the broadcast address so we can send broadcast frames */ - if (iwl_add_station(priv, BROADCAST_ADDR, 0, 0) == + if (iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0) == IWL_INVALID_STATION) { IWL_ERROR("Error adding BROADCAST address for transmit.\n"); return -EIO; @@ -1153,9 +1196,9 @@ static int iwl_commit_rxon(struct iwl_priv *priv) /* If we have set the ASSOC_MSK and we are in BSS mode then * add the IWL_AP_ID to the station rate table */ - if (iwl_is_associated(priv) && + if (iwl3945_is_associated(priv) && (priv->iw_mode == IEEE80211_IF_TYPE_STA)) - if (iwl_add_station(priv, priv->active_rxon.bssid_addr, 1, 0) + if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr, 1, 0) == IWL_INVALID_STATION) { IWL_ERROR("Error adding AP address for transmit.\n"); return -EIO; @@ -1172,9 +1215,9 @@ static int iwl_commit_rxon(struct iwl_priv *priv) return 0; } -static int iwl_send_bt_config(struct iwl_priv *priv) +static int iwl3945_send_bt_config(struct iwl3945_priv *priv) { - struct iwl_bt_cmd bt_cmd = { + struct iwl3945_bt_cmd bt_cmd = { .flags = 3, .lead_time = 0xAA, .max_kill = 1, @@ -1182,15 +1225,15 @@ static int iwl_send_bt_config(struct iwl_priv *priv) .kill_cts_mask = 0, }; - return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, - sizeof(struct iwl_bt_cmd), &bt_cmd); + return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG, + sizeof(struct iwl3945_bt_cmd), &bt_cmd); } -static int iwl_send_scan_abort(struct iwl_priv *priv) +static int iwl3945_send_scan_abort(struct iwl3945_priv *priv) { int rc = 0; - struct iwl_rx_packet *res; - struct iwl_host_cmd cmd = { + struct iwl3945_rx_packet *res; + struct iwl3945_host_cmd cmd = { .id = REPLY_SCAN_ABORT_CMD, .meta.flags = CMD_WANT_SKB, }; @@ -1203,13 +1246,13 @@ static int iwl_send_scan_abort(struct iwl_priv *priv) return 0; } - rc = iwl_send_cmd_sync(priv, &cmd); + rc = iwl3945_send_cmd_sync(priv, &cmd); if (rc) { clear_bit(STATUS_SCAN_ABORTING, &priv->status); return rc; } - res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; + res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data; if (res->u.status != CAN_ABORT_STATUS) { /* The scan abort will return 1 for success or * 2 for "failure". A failure condition can be @@ -1227,8 +1270,8 @@ static int iwl_send_scan_abort(struct iwl_priv *priv) return rc; } -static int iwl_card_state_sync_callback(struct iwl_priv *priv, - struct iwl_cmd *cmd, +static int iwl3945_card_state_sync_callback(struct iwl3945_priv *priv, + struct iwl3945_cmd *cmd, struct sk_buff *skb) { return 1; @@ -1237,16 +1280,16 @@ static int iwl_card_state_sync_callback(struct iwl_priv *priv, /* * CARD_STATE_CMD * - * Use: Sets the internal card state to enable, disable, or halt + * Use: Sets the device's internal card state to enable, disable, or halt * * When in the 'enable' state the card operates as normal. * When in the 'disable' state, the card enters into a low power mode. * When in the 'halt' state, the card is shut down and must be fully * restarted to come back on. */ -static int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag) +static int iwl3945_send_card_state(struct iwl3945_priv *priv, u32 flags, u8 meta_flag) { - struct iwl_host_cmd cmd = { + struct iwl3945_host_cmd cmd = { .id = REPLY_CARD_STATE_CMD, .len = sizeof(u32), .data = &flags, @@ -1254,22 +1297,22 @@ static int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag) }; if (meta_flag & CMD_ASYNC) - cmd.meta.u.callback = iwl_card_state_sync_callback; + cmd.meta.u.callback = iwl3945_card_state_sync_callback; - return iwl_send_cmd(priv, &cmd); + return iwl3945_send_cmd(priv, &cmd); } -static int iwl_add_sta_sync_callback(struct iwl_priv *priv, - struct iwl_cmd *cmd, struct sk_buff *skb) +static int iwl3945_add_sta_sync_callback(struct iwl3945_priv *priv, + struct iwl3945_cmd *cmd, struct sk_buff *skb) { - struct iwl_rx_packet *res = NULL; + struct iwl3945_rx_packet *res = NULL; if (!skb) { IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n"); return 1; } - res = (struct iwl_rx_packet *)skb->data; + res = (struct iwl3945_rx_packet *)skb->data; if (res->hdr.flags & IWL_CMD_FAILED_MSK) { IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", res->hdr.flags); @@ -1287,29 +1330,29 @@ static int iwl_add_sta_sync_callback(struct iwl_priv *priv, return 1; } -int iwl_send_add_station(struct iwl_priv *priv, - struct iwl_addsta_cmd *sta, u8 flags) +int iwl3945_send_add_station(struct iwl3945_priv *priv, + struct iwl3945_addsta_cmd *sta, u8 flags) { - struct iwl_rx_packet *res = NULL; + struct iwl3945_rx_packet *res = NULL; int rc = 0; - struct iwl_host_cmd cmd = { + struct iwl3945_host_cmd cmd = { .id = REPLY_ADD_STA, - .len = sizeof(struct iwl_addsta_cmd), + .len = sizeof(struct iwl3945_addsta_cmd), .meta.flags = flags, .data = sta, }; if (flags & CMD_ASYNC) - cmd.meta.u.callback = iwl_add_sta_sync_callback; + cmd.meta.u.callback = iwl3945_add_sta_sync_callback; else cmd.meta.flags |= CMD_WANT_SKB; - rc = iwl_send_cmd(priv, &cmd); + rc = iwl3945_send_cmd(priv, &cmd); if (rc || (flags & CMD_ASYNC)) return rc; - res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; + res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data; if (res->hdr.flags & IWL_CMD_FAILED_MSK) { IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", res->hdr.flags); @@ -1334,7 +1377,7 @@ int iwl_send_add_station(struct iwl_priv *priv, return rc; } -static int iwl_update_sta_key_info(struct iwl_priv *priv, +static int iwl3945_update_sta_key_info(struct iwl3945_priv *priv, struct ieee80211_key_conf *keyconf, u8 sta_id) { @@ -1350,7 +1393,6 @@ static int iwl_update_sta_key_info(struct iwl_priv *priv, break; case ALG_TKIP: case ALG_WEP: - return -EINVAL; default: return -EINVAL; } @@ -1369,28 +1411,28 @@ static int iwl_update_sta_key_info(struct iwl_priv *priv, spin_unlock_irqrestore(&priv->sta_lock, flags); IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); - iwl_send_add_station(priv, &priv->stations[sta_id].sta, 0); + iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0); return 0; } -static int iwl_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id) +static int iwl3945_clear_sta_key_info(struct iwl3945_priv *priv, u8 sta_id) { unsigned long flags; spin_lock_irqsave(&priv->sta_lock, flags); - memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key)); - memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl_keyinfo)); + memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key)); + memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl3945_keyinfo)); priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; spin_unlock_irqrestore(&priv->sta_lock, flags); IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); - iwl_send_add_station(priv, &priv->stations[sta_id].sta, 0); + iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0); return 0; } -static void iwl_clear_free_frames(struct iwl_priv *priv) +static void iwl3945_clear_free_frames(struct iwl3945_priv *priv) { struct list_head *element; @@ -1400,7 +1442,7 @@ static void iwl_clear_free_frames(struct iwl_priv *priv) while (!list_empty(&priv->free_frames)) { element = priv->free_frames.next; list_del(element); - kfree(list_entry(element, struct iwl_frame, list)); + kfree(list_entry(element, struct iwl3945_frame, list)); priv->frames_count--; } @@ -1411,9 +1453,9 @@ static void iwl_clear_free_frames(struct iwl_priv *priv) } } -static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) +static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl3945_priv *priv) { - struct iwl_frame *frame; + struct iwl3945_frame *frame; struct list_head *element; if (list_empty(&priv->free_frames)) { frame = kzalloc(sizeof(*frame), GFP_KERNEL); @@ -1428,21 +1470,21 @@ static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) element = priv->free_frames.next; list_del(element); - return list_entry(element, struct iwl_frame, list); + return list_entry(element, struct iwl3945_frame, list); } -static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame) +static void iwl3945_free_frame(struct iwl3945_priv *priv, struct iwl3945_frame *frame) { memset(frame, 0, sizeof(*frame)); list_add(&frame->list, &priv->free_frames); } -unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv, +unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv *priv, struct ieee80211_hdr *hdr, const u8 *dest, int left) { - if (!iwl_is_associated(priv) || !priv->ibss_beacon || + if (!iwl3945_is_associated(priv) || !priv->ibss_beacon || ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && (priv->iw_mode != IEEE80211_IF_TYPE_AP))) return 0; @@ -1455,37 +1497,27 @@ unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv, return priv->ibss_beacon->len; } -static int iwl_rate_index_from_plcp(int plcp) -{ - int i = 0; - - for (i = 0; i < IWL_RATE_COUNT; i++) - if (iwl_rates[i].plcp == plcp) - return i; - return -1; -} - -static u8 iwl_rate_get_lowest_plcp(int rate_mask) +static u8 iwl3945_rate_get_lowest_plcp(int rate_mask) { u8 i; for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; - i = iwl_rates[i].next_ieee) { + i = iwl3945_rates[i].next_ieee) { if (rate_mask & (1 << i)) - return iwl_rates[i].plcp; + return iwl3945_rates[i].plcp; } return IWL_RATE_INVALID; } -static int iwl_send_beacon_cmd(struct iwl_priv *priv) +static int iwl3945_send_beacon_cmd(struct iwl3945_priv *priv) { - struct iwl_frame *frame; + struct iwl3945_frame *frame; unsigned int frame_size; int rc; u8 rate; - frame = iwl_get_free_frame(priv); + frame = iwl3945_get_free_frame(priv); if (!frame) { IWL_ERROR("Could not obtain free frame buffer for beacon " @@ -1494,22 +1526,22 @@ static int iwl_send_beacon_cmd(struct iwl_priv *priv) } if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { - rate = iwl_rate_get_lowest_plcp(priv->active_rate_basic & + rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic & 0xFF0); if (rate == IWL_INVALID_RATE) rate = IWL_RATE_6M_PLCP; } else { - rate = iwl_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); + rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); if (rate == IWL_INVALID_RATE) rate = IWL_RATE_1M_PLCP; } - frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate); + frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate); - rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, + rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, &frame->u.cmd[0]); - iwl_free_frame(priv, frame); + iwl3945_free_frame(priv, frame); return rc; } @@ -1520,22 +1552,22 @@ static int iwl_send_beacon_cmd(struct iwl_priv *priv) * ******************************************************************************/ -static void get_eeprom_mac(struct iwl_priv *priv, u8 *mac) +static void get_eeprom_mac(struct iwl3945_priv *priv, u8 *mac) { memcpy(mac, priv->eeprom.mac_address, 6); } /** - * iwl_eeprom_init - read EEPROM contents + * iwl3945_eeprom_init - read EEPROM contents * - * Load the EEPROM from adapter into priv->eeprom + * Load the EEPROM contents from adapter into priv->eeprom * * NOTE: This routine uses the non-debug IO access functions. */ -int iwl_eeprom_init(struct iwl_priv *priv) +int iwl3945_eeprom_init(struct iwl3945_priv *priv) { - u16 *e = (u16 *)&priv->eeprom; - u32 gp = iwl_read32(priv, CSR_EEPROM_GP); + __le16 *e = (__le16 *)&priv->eeprom; + u32 gp = iwl3945_read32(priv, CSR_EEPROM_GP); u32 r; int sz = sizeof(priv->eeprom); int rc; @@ -1553,20 +1585,21 @@ int iwl_eeprom_init(struct iwl_priv *priv) return -ENOENT; } - rc = iwl_eeprom_aqcuire_semaphore(priv); + /* Make sure driver (instead of uCode) is allowed to read EEPROM */ + rc = iwl3945_eeprom_acquire_semaphore(priv); if (rc < 0) { - IWL_ERROR("Failed to aqcuire EEPROM semaphore.\n"); + IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); return -ENOENT; } /* eeprom is an array of 16bit values */ for (addr = 0; addr < sz; addr += sizeof(u16)) { - _iwl_write32(priv, CSR_EEPROM_REG, addr << 1); - _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); + _iwl3945_write32(priv, CSR_EEPROM_REG, addr << 1); + _iwl3945_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT; i += IWL_EEPROM_ACCESS_DELAY) { - r = _iwl_read_restricted(priv, CSR_EEPROM_REG); + r = _iwl3945_read_direct32(priv, CSR_EEPROM_REG); if (r & CSR_EEPROM_REG_READ_VALID_MSK) break; udelay(IWL_EEPROM_ACCESS_DELAY); @@ -1576,7 +1609,7 @@ int iwl_eeprom_init(struct iwl_priv *priv) IWL_ERROR("Time out reading EEPROM[%d]", addr); return -ETIMEDOUT; } - e[addr / 2] = le16_to_cpu(r >> 16); + e[addr / 2] = cpu_to_le16(r >> 16); } return 0; @@ -1587,22 +1620,17 @@ int iwl_eeprom_init(struct iwl_priv *priv) * Misc. internal state and helper functions * ******************************************************************************/ -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL3945_DEBUG /** - * iwl_report_frame - dump frame to syslog during debug sessions + * iwl3945_report_frame - dump frame to syslog during debug sessions * - * hack this function to show different aspects of received frames, + * You may hack this function to show different aspects of received frames, * including selective frame dumps. * group100 parameter selects whether to show 1 out of 100 good frames. - * - * TODO: ieee80211_hdr stuff is common to 3945 and 4965, so frame type - * info output is okay, but some of this stuff (e.g. iwl_rx_frame_stats) - * is 3945-specific and gives bad output for 4965. Need to split the - * functionality, keep common stuff here. */ -void iwl_report_frame(struct iwl_priv *priv, - struct iwl_rx_packet *pkt, +void iwl3945_report_frame(struct iwl3945_priv *priv, + struct iwl3945_rx_packet *pkt, struct ieee80211_hdr *header, int group100) { u32 to_us; @@ -1624,9 +1652,9 @@ void iwl_report_frame(struct iwl_priv *priv, u8 agc; u16 sig_avg; u16 noise_diff; - struct iwl_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); - struct iwl_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); - struct iwl_rx_frame_end *rx_end = IWL_RX_END(pkt); + struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); + struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); + struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt); u8 *data = IWL_RX_DATA(pkt); /* MAC header */ @@ -1702,11 +1730,11 @@ void iwl_report_frame(struct iwl_priv *priv, else title = "Frame"; - rate = iwl_rate_index_from_plcp(rate_sym); + rate = iwl3945_rate_index_from_plcp(rate_sym); if (rate == -1) rate = 0; else - rate = iwl_rates[rate].ieee / 2; + rate = iwl3945_rates[rate].ieee / 2; /* print frame summary. * MAC addresses show just the last byte (for brevity), @@ -1728,25 +1756,25 @@ void iwl_report_frame(struct iwl_priv *priv, } } if (print_dump) - iwl_print_hex_dump(IWL_DL_RX, data, length); + iwl3945_print_hex_dump(IWL_DL_RX, data, length); } #endif -static void iwl_unset_hw_setting(struct iwl_priv *priv) +static void iwl3945_unset_hw_setting(struct iwl3945_priv *priv) { if (priv->hw_setting.shared_virt) pci_free_consistent(priv->pci_dev, - sizeof(struct iwl_shared), + sizeof(struct iwl3945_shared), priv->hw_setting.shared_virt, priv->hw_setting.shared_phys); } /** - * iwl_supported_rate_to_ie - fill in the supported rate in IE field + * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field * * return : set the bit for each supported rate insert in ie */ -static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate, +static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate, u16 basic_rate, int *left) { u16 ret_rates = 0, bit; @@ -1757,7 +1785,7 @@ static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate, for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { if (bit & supported_rate) { ret_rates |= bit; - rates[*cnt] = iwl_rates[i].ieee | + rates[*cnt] = iwl3945_rates[i].ieee | ((bit & basic_rate) ? 0x80 : 0x00); (*cnt)++; (*left)--; @@ -1771,9 +1799,9 @@ static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate, } /** - * iwl_fill_probe_req - fill in all required fields and IE for probe request + * iwl3945_fill_probe_req - fill in all required fields and IE for probe request */ -static u16 iwl_fill_probe_req(struct iwl_priv *priv, +static u16 iwl3945_fill_probe_req(struct iwl3945_priv *priv, struct ieee80211_mgmt *frame, int left, int is_direct) { @@ -1789,9 +1817,9 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv, len += 24; frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); - memcpy(frame->da, BROADCAST_ADDR, ETH_ALEN); + memcpy(frame->da, iwl3945_broadcast_addr, ETH_ALEN); memcpy(frame->sa, priv->mac_addr, ETH_ALEN); - memcpy(frame->bssid, BROADCAST_ADDR, ETH_ALEN); + memcpy(frame->bssid, iwl3945_broadcast_addr, ETH_ALEN); frame->seq_ctrl = 0; /* fill in our indirect SSID IE */ @@ -1834,11 +1862,11 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv, priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; cck_rates = IWL_CCK_RATES_MASK & active_rates; - ret_rates = iwl_supported_rate_to_ie(pos, cck_rates, + ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates, priv->active_rate_basic, &left); active_rates &= ~ret_rates; - ret_rates = iwl_supported_rate_to_ie(pos, active_rates, + ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates, priv->active_rate_basic, &left); active_rates &= ~ret_rates; @@ -1855,7 +1883,7 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv, /* ... fill it in... */ *pos++ = WLAN_EID_EXT_SUPP_RATES; *pos = 0; - iwl_supported_rate_to_ie(pos, active_rates, + iwl3945_supported_rate_to_ie(pos, active_rates, priv->active_rate_basic, &left); if (*pos > 0) len += 2 + *pos; @@ -1867,16 +1895,16 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv, /* * QoS support */ -#ifdef CONFIG_IWLWIFI_QOS -static int iwl_send_qos_params_command(struct iwl_priv *priv, - struct iwl_qosparam_cmd *qos) +#ifdef CONFIG_IWL3945_QOS +static int iwl3945_send_qos_params_command(struct iwl3945_priv *priv, + struct iwl3945_qosparam_cmd *qos) { - return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, - sizeof(struct iwl_qosparam_cmd), qos); + return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM, + sizeof(struct iwl3945_qosparam_cmd), qos); } -static void iwl_reset_qos(struct iwl_priv *priv) +static void iwl3945_reset_qos(struct iwl3945_priv *priv) { u16 cw_min = 15; u16 cw_max = 1023; @@ -1963,13 +1991,10 @@ static void iwl_reset_qos(struct iwl_priv *priv) spin_unlock_irqrestore(&priv->lock, flags); } -static void iwl_activate_qos(struct iwl_priv *priv, u8 force) +static void iwl3945_activate_qos(struct iwl3945_priv *priv, u8 force) { unsigned long flags; - if (priv == NULL) - return; - if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; @@ -1990,16 +2015,16 @@ static void iwl_activate_qos(struct iwl_priv *priv, u8 force) spin_unlock_irqrestore(&priv->lock, flags); - if (force || iwl_is_associated(priv)) { + if (force || iwl3945_is_associated(priv)) { IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n", priv->qos_data.qos_active); - iwl_send_qos_params_command(priv, + iwl3945_send_qos_params_command(priv, &(priv->qos_data.def_qos_parm)); } } -#endif /* CONFIG_IWLWIFI_QOS */ +#endif /* CONFIG_IWL3945_QOS */ /* * Power management (not Tx power!) functions */ @@ -2017,7 +2042,7 @@ static void iwl_activate_qos(struct iwl_priv *priv, u8 force) /* default power management (not Tx power) table values */ /* for tim 0-10 */ -static struct iwl_power_vec_entry range_0[IWL_POWER_AC] = { +static struct iwl3945_power_vec_entry range_0[IWL_POWER_AC] = { {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, @@ -2027,7 +2052,7 @@ static struct iwl_power_vec_entry range_0[IWL_POWER_AC] = { }; /* for tim > 10 */ -static struct iwl_power_vec_entry range_1[IWL_POWER_AC] = { +static struct iwl3945_power_vec_entry range_1[IWL_POWER_AC] = { {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, @@ -2040,11 +2065,11 @@ static struct iwl_power_vec_entry range_1[IWL_POWER_AC] = { SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} }; -int iwl_power_init_handle(struct iwl_priv *priv) +int iwl3945_power_init_handle(struct iwl3945_priv *priv) { int rc = 0, i; - struct iwl_power_mgr *pow_data; - int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_AC; + struct iwl3945_power_mgr *pow_data; + int size = sizeof(struct iwl3945_power_vec_entry) * IWL_POWER_AC; u16 pci_pm; IWL_DEBUG_POWER("Initialize power \n"); @@ -2063,7 +2088,7 @@ int iwl_power_init_handle(struct iwl_priv *priv) if (rc != 0) return 0; else { - struct iwl_powertable_cmd *cmd; + struct iwl3945_powertable_cmd *cmd; IWL_DEBUG_POWER("adjust power command flags\n"); @@ -2079,15 +2104,15 @@ int iwl_power_init_handle(struct iwl_priv *priv) return rc; } -static int iwl_update_power_cmd(struct iwl_priv *priv, - struct iwl_powertable_cmd *cmd, u32 mode) +static int iwl3945_update_power_cmd(struct iwl3945_priv *priv, + struct iwl3945_powertable_cmd *cmd, u32 mode) { int rc = 0, i; u8 skip; u32 max_sleep = 0; - struct iwl_power_vec_entry *range; + struct iwl3945_power_vec_entry *range; u8 period = 0; - struct iwl_power_mgr *pow_data; + struct iwl3945_power_mgr *pow_data; if (mode > IWL_POWER_INDEX_5) { IWL_DEBUG_POWER("Error invalid power mode \n"); @@ -2100,7 +2125,7 @@ static int iwl_update_power_cmd(struct iwl_priv *priv, else range = &pow_data->pwr_range_1[1]; - memcpy(cmd, &range[mode].cmd, sizeof(struct iwl_powertable_cmd)); + memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd)); #ifdef IWL_MAC80211_DISABLE if (priv->assoc_network != NULL) { @@ -2143,14 +2168,14 @@ static int iwl_update_power_cmd(struct iwl_priv *priv, return rc; } -static int iwl_send_power_mode(struct iwl_priv *priv, u32 mode) +static int iwl3945_send_power_mode(struct iwl3945_priv *priv, u32 mode) { - u32 final_mode = mode; + u32 uninitialized_var(final_mode); int rc; - struct iwl_powertable_cmd cmd; + struct iwl3945_powertable_cmd cmd; /* If on battery, set to 3, - * if plugged into AC power, set to CAM ("continuosly aware mode"), + * if plugged into AC power, set to CAM ("continuously aware mode"), * else user level */ switch (mode) { case IWL_POWER_BATTERY: @@ -2164,9 +2189,9 @@ static int iwl_send_power_mode(struct iwl_priv *priv, u32 mode) break; } - iwl_update_power_cmd(priv, &cmd, final_mode); + iwl3945_update_power_cmd(priv, &cmd, final_mode); - rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); + rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); if (final_mode == IWL_POWER_MODE_CAM) clear_bit(STATUS_POWER_PMI, &priv->status); @@ -2176,7 +2201,7 @@ static int iwl_send_power_mode(struct iwl_priv *priv, u32 mode) return rc; } -int iwl_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) +int iwl3945_is_network_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header) { /* Filter incoming packets to determine if they are targeted toward * this network, discarding packets coming from ourselves */ @@ -2206,7 +2231,7 @@ int iwl_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x -const char *iwl_get_tx_fail_reason(u32 status) +static const char *iwl3945_get_tx_fail_reason(u32 status) { switch (status & TX_STATUS_MSK) { case TX_STATUS_SUCCESS: @@ -2233,11 +2258,11 @@ const char *iwl_get_tx_fail_reason(u32 status) } /** - * iwl_scan_cancel - Cancel any currently executing HW scan + * iwl3945_scan_cancel - Cancel any currently executing HW scan * * NOTE: priv->mutex is not required before calling this function */ -static int iwl_scan_cancel(struct iwl_priv *priv) +static int iwl3945_scan_cancel(struct iwl3945_priv *priv) { if (!test_bit(STATUS_SCAN_HW, &priv->status)) { clear_bit(STATUS_SCANNING, &priv->status); @@ -2260,17 +2285,17 @@ static int iwl_scan_cancel(struct iwl_priv *priv) } /** - * iwl_scan_cancel_timeout - Cancel any currently executing HW scan + * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan * @ms: amount of time to wait (in milliseconds) for scan to abort * * NOTE: priv->mutex must be held before calling this function */ -static int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) +static int iwl3945_scan_cancel_timeout(struct iwl3945_priv *priv, unsigned long ms) { unsigned long now = jiffies; int ret; - ret = iwl_scan_cancel(priv); + ret = iwl3945_scan_cancel(priv); if (ret && ms) { mutex_unlock(&priv->mutex); while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && @@ -2284,7 +2309,7 @@ static int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) return ret; } -static void iwl_sequence_reset(struct iwl_priv *priv) +static void iwl3945_sequence_reset(struct iwl3945_priv *priv) { /* Reset ieee stats */ @@ -2295,13 +2320,13 @@ static void iwl_sequence_reset(struct iwl_priv *priv) priv->last_frag_num = -1; priv->last_packet_time = 0; - iwl_scan_cancel(priv); + iwl3945_scan_cancel(priv); } #define MAX_UCODE_BEACON_INTERVAL 1024 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) -static __le16 iwl_adjust_beacon_interval(u16 beacon_val) +static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val) { u16 new_val = 0; u16 beacon_factor = 0; @@ -2314,7 +2339,7 @@ static __le16 iwl_adjust_beacon_interval(u16 beacon_val) return cpu_to_le16(new_val); } -static void iwl_setup_rxon_timing(struct iwl_priv *priv) +static void iwl3945_setup_rxon_timing(struct iwl3945_priv *priv) { u64 interval_tm_unit; u64 tsf, result; @@ -2344,14 +2369,14 @@ static void iwl_setup_rxon_timing(struct iwl_priv *priv) priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int); priv->rxon_timing.beacon_interval = - iwl_adjust_beacon_interval( + iwl3945_adjust_beacon_interval( le16_to_cpu(priv->rxon_timing.beacon_interval)); } priv->rxon_timing.atim_window = 0; } else { priv->rxon_timing.beacon_interval = - iwl_adjust_beacon_interval(conf->beacon_int); + iwl3945_adjust_beacon_interval(conf->beacon_int); /* TODO: we need to get atim_window from upper stack * for now we set to 0 */ priv->rxon_timing.atim_window = 0; @@ -2370,14 +2395,14 @@ static void iwl_setup_rxon_timing(struct iwl_priv *priv) le16_to_cpu(priv->rxon_timing.atim_window)); } -static int iwl_scan_initiate(struct iwl_priv *priv) +static int iwl3945_scan_initiate(struct iwl3945_priv *priv) { if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { IWL_ERROR("APs don't scan.\n"); return 0; } - if (!iwl_is_ready_rf(priv)) { + if (!iwl3945_is_ready_rf(priv)) { IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); return -EIO; } @@ -2404,9 +2429,9 @@ static int iwl_scan_initiate(struct iwl_priv *priv) return 0; } -static int iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) +static int iwl3945_set_rxon_hwcrypto(struct iwl3945_priv *priv, int hw_decrypt) { - struct iwl_rxon_cmd *rxon = &priv->staging_rxon; + struct iwl3945_rxon_cmd *rxon = &priv->staging_rxon; if (hw_decrypt) rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; @@ -2416,7 +2441,7 @@ static int iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) return 0; } -static void iwl_set_flags_for_phymode(struct iwl_priv *priv, u8 phymode) +static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, u8 phymode) { if (phymode == MODE_IEEE80211A) { priv->staging_rxon.flags &= @@ -2424,7 +2449,7 @@ static void iwl_set_flags_for_phymode(struct iwl_priv *priv, u8 phymode) | RXON_FLG_CCK_MSK); priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; } else { - /* Copied from iwl_bg_post_associate() */ + /* Copied from iwl3945_bg_post_associate() */ if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; else @@ -2440,11 +2465,11 @@ static void iwl_set_flags_for_phymode(struct iwl_priv *priv, u8 phymode) } /* - * initilize rxon structure with default values fromm eeprom + * initialize rxon structure with default values from eeprom */ -static void iwl_connection_init_rx_config(struct iwl_priv *priv) +static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv) { - const struct iwl_channel_info *ch_info; + const struct iwl3945_channel_info *ch_info; memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); @@ -2481,7 +2506,7 @@ static void iwl_connection_init_rx_config(struct iwl_priv *priv) priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; #endif - ch_info = iwl_get_channel_info(priv, priv->phymode, + ch_info = iwl3945_get_channel_info(priv, priv->phymode, le16_to_cpu(priv->staging_rxon.channel)); if (!ch_info) @@ -2501,7 +2526,7 @@ static void iwl_connection_init_rx_config(struct iwl_priv *priv) else priv->phymode = MODE_IEEE80211G; - iwl_set_flags_for_phymode(priv, priv->phymode); + iwl3945_set_flags_for_phymode(priv, priv->phymode); priv->staging_rxon.ofdm_basic_rates = (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; @@ -2509,15 +2534,12 @@ static void iwl_connection_init_rx_config(struct iwl_priv *priv) (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; } -static int iwl_set_mode(struct iwl_priv *priv, int mode) +static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode) { - if (!iwl_is_ready_rf(priv)) - return -EAGAIN; - if (mode == IEEE80211_IF_TYPE_IBSS) { - const struct iwl_channel_info *ch_info; + const struct iwl3945_channel_info *ch_info; - ch_info = iwl_get_channel_info(priv, + ch_info = iwl3945_get_channel_info(priv, priv->phymode, le16_to_cpu(priv->staging_rxon.channel)); @@ -2528,32 +2550,36 @@ static int iwl_set_mode(struct iwl_priv *priv, int mode) } } + priv->iw_mode = mode; + + iwl3945_connection_init_rx_config(priv); + memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); + + iwl3945_clear_stations_table(priv); + + /* dont commit rxon if rf-kill is on*/ + if (!iwl3945_is_ready_rf(priv)) + return -EAGAIN; + cancel_delayed_work(&priv->scan_check); - if (iwl_scan_cancel_timeout(priv, 100)) { + if (iwl3945_scan_cancel_timeout(priv, 100)) { IWL_WARNING("Aborted scan still in progress after 100ms\n"); IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); return -EAGAIN; } - priv->iw_mode = mode; - - iwl_connection_init_rx_config(priv); - memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); - - iwl_clear_stations_table(priv); - - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); return 0; } -static void iwl_build_tx_cmd_hwcrypto(struct iwl_priv *priv, +static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv, struct ieee80211_tx_control *ctl, - struct iwl_cmd *cmd, + struct iwl3945_cmd *cmd, struct sk_buff *skb_frag, int last_frag) { - struct iwl_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; + struct iwl3945_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; switch (keyinfo->alg) { case ALG_CCMP: @@ -2596,8 +2622,8 @@ static void iwl_build_tx_cmd_hwcrypto(struct iwl_priv *priv, /* * handle build REPLY_TX command notification. */ -static void iwl_build_tx_cmd_basic(struct iwl_priv *priv, - struct iwl_cmd *cmd, +static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv, + struct iwl3945_cmd *cmd, struct ieee80211_tx_control *ctrl, struct ieee80211_hdr *hdr, int is_unicast, u8 std_id) @@ -2645,11 +2671,9 @@ static void iwl_build_tx_cmd_basic(struct iwl_priv *priv, if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) - cmd->cmd.tx.timeout.pm_frame_timeout = - cpu_to_le16(3); + cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); else - cmd->cmd.tx.timeout.pm_frame_timeout = - cpu_to_le16(2); + cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); } else cmd->cmd.tx.timeout.pm_frame_timeout = 0; @@ -2658,41 +2682,44 @@ static void iwl_build_tx_cmd_basic(struct iwl_priv *priv, cmd->cmd.tx.next_frame_len = 0; } -static int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) +/** + * iwl3945_get_sta_id - Find station's index within station table + */ +static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *hdr) { int sta_id; u16 fc = le16_to_cpu(hdr->frame_control); - /* If this frame is broadcast or not data then use the broadcast - * station id */ + /* If this frame is broadcast or management, use broadcast station id */ if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || is_multicast_ether_addr(hdr->addr1)) return priv->hw_setting.bcast_sta_id; switch (priv->iw_mode) { - /* If this frame is part of a BSS network (we're a station), then - * we use the AP's station id */ + /* If we are a client station in a BSS network, use the special + * AP station entry (that's the only station we communicate with) */ case IEEE80211_IF_TYPE_STA: return IWL_AP_ID; /* If we are an AP, then find the station, or use BCAST */ case IEEE80211_IF_TYPE_AP: - sta_id = iwl_hw_find_station(priv, hdr->addr1); + sta_id = iwl3945_hw_find_station(priv, hdr->addr1); if (sta_id != IWL_INVALID_STATION) return sta_id; return priv->hw_setting.bcast_sta_id; - /* If this frame is part of a IBSS network, then we use the - * target specific station id */ + /* If this frame is going out to an IBSS network, find the station, + * or create a new station table entry */ case IEEE80211_IF_TYPE_IBSS: { DECLARE_MAC_BUF(mac); - sta_id = iwl_hw_find_station(priv, hdr->addr1); + /* Create new station table entry */ + sta_id = iwl3945_hw_find_station(priv, hdr->addr1); if (sta_id != IWL_INVALID_STATION) return sta_id; - sta_id = iwl_add_station(priv, hdr->addr1, 0, CMD_ASYNC); + sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC); if (sta_id != IWL_INVALID_STATION) return sta_id; @@ -2700,11 +2727,11 @@ static int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) IWL_DEBUG_DROP("Station %s not in station map. " "Defaulting to broadcast...\n", print_mac(mac, hdr->addr1)); - iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); + iwl3945_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); return priv->hw_setting.bcast_sta_id; } default: - IWL_WARNING("Unkown mode of operation: %d", priv->iw_mode); + IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); return priv->hw_setting.bcast_sta_id; } } @@ -2712,18 +2739,18 @@ static int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) /* * start REPLY_TX command process */ -static int iwl_tx_skb(struct iwl_priv *priv, +static int iwl3945_tx_skb(struct iwl3945_priv *priv, struct sk_buff *skb, struct ieee80211_tx_control *ctl) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; - struct iwl_tfd_frame *tfd; + struct iwl3945_tfd_frame *tfd; u32 *control_flags; int txq_id = ctl->queue; - struct iwl_tx_queue *txq = NULL; - struct iwl_queue *q = NULL; + struct iwl3945_tx_queue *txq = NULL; + struct iwl3945_queue *q = NULL; dma_addr_t phys_addr; dma_addr_t txcmd_phys; - struct iwl_cmd *out_cmd = NULL; + struct iwl3945_cmd *out_cmd = NULL; u16 len, idx, len_org; u8 id, hdr_len, unicast; u8 sta_id; @@ -2735,13 +2762,13 @@ static int iwl_tx_skb(struct iwl_priv *priv, int rc; spin_lock_irqsave(&priv->lock, flags); - if (iwl_is_rfkill(priv)) { + if (iwl3945_is_rfkill(priv)) { IWL_DEBUG_DROP("Dropping - RF KILL\n"); goto drop_unlock; } - if (!priv->interface_id) { - IWL_DEBUG_DROP("Dropping - !priv->interface_id\n"); + if (!priv->vif) { + IWL_DEBUG_DROP("Dropping - !priv->vif\n"); goto drop_unlock; } @@ -2755,7 +2782,7 @@ static int iwl_tx_skb(struct iwl_priv *priv, fc = le16_to_cpu(hdr->frame_control); -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL3945_DEBUG if (ieee80211_is_auth(fc)) IWL_DEBUG_TX("Sending AUTH frame\n"); else if (ieee80211_is_assoc_request(fc)) @@ -2764,16 +2791,19 @@ static int iwl_tx_skb(struct iwl_priv *priv, IWL_DEBUG_TX("Sending REASSOC frame\n"); #endif - if (!iwl_is_associated(priv) && + /* drop all data frame if we are not associated */ + if (!iwl3945_is_associated(priv) && !priv->assoc_id && ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) { - IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n"); + IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n"); goto drop_unlock; } spin_unlock_irqrestore(&priv->lock, flags); hdr_len = ieee80211_get_hdrlen(fc); - sta_id = iwl_get_sta_id(priv, hdr); + + /* Find (or create) index into station table for destination station */ + sta_id = iwl3945_get_sta_id(priv, hdr); if (sta_id == IWL_INVALID_STATION) { DECLARE_MAC_BUF(mac); @@ -2794,32 +2824,54 @@ static int iwl_tx_skb(struct iwl_priv *priv, __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); seq_number += 0x10; } + + /* Descriptor for chosen Tx queue */ txq = &priv->txq[txq_id]; q = &txq->q; spin_lock_irqsave(&priv->lock, flags); - tfd = &txq->bd[q->first_empty]; + /* Set up first empty TFD within this queue's circular TFD buffer */ + tfd = &txq->bd[q->write_ptr]; memset(tfd, 0, sizeof(*tfd)); control_flags = (u32 *) tfd; - idx = get_cmd_index(q, q->first_empty, 0); + idx = get_cmd_index(q, q->write_ptr, 0); - memset(&(txq->txb[q->first_empty]), 0, sizeof(struct iwl_tx_info)); - txq->txb[q->first_empty].skb[0] = skb; - memcpy(&(txq->txb[q->first_empty].status.control), + /* Set up driver data for this TFD */ + memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info)); + txq->txb[q->write_ptr].skb[0] = skb; + memcpy(&(txq->txb[q->write_ptr].status.control), ctl, sizeof(struct ieee80211_tx_control)); + + /* Init first empty entry in queue's array of Tx/cmd buffers */ out_cmd = &txq->cmd[idx]; memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); + + /* + * Set up the Tx-command (not MAC!) header. + * Store the chosen Tx queue and TFD index within the sequence field; + * after Tx, uCode's Tx response will return this value so driver can + * locate the frame within the tx queue and do post-tx processing. + */ out_cmd->hdr.cmd = REPLY_TX; out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) | - INDEX_TO_SEQ(q->first_empty))); - /* copy frags header */ + INDEX_TO_SEQ(q->write_ptr))); + + /* Copy MAC header from skb into command buffer */ memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); - /* hdr = (struct ieee80211_hdr *)out_cmd->cmd.tx.hdr; */ + /* + * Use the first empty entry in this queue's command buffer array + * to contain the Tx command and MAC header concatenated together + * (payload data will be in another buffer). + * Size of this varies, due to varying MAC header length. + * If end is not dword aligned, we'll have 2 extra bytes at the end + * of the MAC header (device reads on dword boundaries). + * We'll tell device about this padding later. + */ len = priv->hw_setting.tx_cmd_len + - sizeof(struct iwl_cmd_header) + hdr_len; + sizeof(struct iwl3945_cmd_header) + hdr_len; len_org = len; len = (len + 3) & ~3; @@ -2829,37 +2881,45 @@ static int iwl_tx_skb(struct iwl_priv *priv, else len_org = 0; - txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx + - offsetof(struct iwl_cmd, hdr); + /* Physical address of this Tx command's header (not MAC header!), + * within command buffer array. */ + txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl3945_cmd) * idx + + offsetof(struct iwl3945_cmd, hdr); - iwl_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); + /* Add buffer containing Tx command and MAC(!) header to TFD's + * first entry */ + iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) - iwl_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); + iwl3945_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); - /* 802.11 null functions have no payload... */ + /* Set up TFD's 2nd entry to point directly to remainder of skb, + * if any (802.11 null frames have no payload). */ len = skb->len - hdr_len; if (len) { phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, len, PCI_DMA_TODEVICE); - iwl_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); + iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); } - /* If there is no payload, then only one TFD is used */ if (!len) + /* If there is no payload, then we use only one Tx buffer */ *control_flags = TFD_CTL_COUNT_SET(1); else + /* Else use 2 buffers. + * Tell 3945 about any padding after MAC header */ *control_flags = TFD_CTL_COUNT_SET(2) | TFD_CTL_PAD_SET(U32_PAD(len)); + /* Total # bytes to be transmitted */ len = (u16)skb->len; out_cmd->cmd.tx.len = cpu_to_le16(len); /* TODO need this for burst mode later on */ - iwl_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id); + iwl3945_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id); /* set is_hcca to 0; it probably will never be implemented */ - iwl_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0); + iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0); out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; @@ -2875,25 +2935,26 @@ static int iwl_tx_skb(struct iwl_priv *priv, txq->need_update = 0; } - iwl_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, + iwl3945_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, sizeof(out_cmd->cmd.tx)); - iwl_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, + iwl3945_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, ieee80211_get_hdrlen(fc)); - q->first_empty = iwl_queue_inc_wrap(q->first_empty, q->n_bd); - rc = iwl_tx_queue_update_write_ptr(priv, txq); + /* Tell device the write index *just past* this latest filled TFD */ + q->write_ptr = iwl3945_queue_inc_wrap(q->write_ptr, q->n_bd); + rc = iwl3945_tx_queue_update_write_ptr(priv, txq); spin_unlock_irqrestore(&priv->lock, flags); if (rc) return rc; - if ((iwl_queue_space(q) < q->high_mark) + if ((iwl3945_queue_space(q) < q->high_mark) && priv->mac80211_registered) { if (wait_write_ptr) { spin_lock_irqsave(&priv->lock, flags); txq->need_update = 1; - iwl_tx_queue_update_write_ptr(priv, txq); + iwl3945_tx_queue_update_write_ptr(priv, txq); spin_unlock_irqrestore(&priv->lock, flags); } @@ -2908,13 +2969,13 @@ drop: return -1; } -static void iwl_set_rate(struct iwl_priv *priv) +static void iwl3945_set_rate(struct iwl3945_priv *priv) { const struct ieee80211_hw_mode *hw = NULL; struct ieee80211_rate *rate; int i; - hw = iwl_get_hw_mode(priv, priv->phymode); + hw = iwl3945_get_hw_mode(priv, priv->phymode); if (!hw) { IWL_ERROR("Failed to set rate: unable to get hw mode\n"); return; @@ -2932,7 +2993,7 @@ static void iwl_set_rate(struct iwl_priv *priv) if ((rate->val < IWL_RATE_COUNT) && (rate->flags & IEEE80211_RATE_SUPPORTED)) { IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n", - rate->val, iwl_rates[rate->val].plcp, + rate->val, iwl3945_rates[rate->val].plcp, (rate->flags & IEEE80211_RATE_BASIC) ? "*" : ""); priv->active_rate |= (1 << rate->val); @@ -2940,7 +3001,7 @@ static void iwl_set_rate(struct iwl_priv *priv) priv->active_rate_basic |= (1 << rate->val); } else IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n", - rate->val, iwl_rates[rate->val].plcp); + rate->val, iwl3945_rates[rate->val].plcp); } IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", @@ -2969,7 +3030,7 @@ static void iwl_set_rate(struct iwl_priv *priv) (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; } -static void iwl_radio_kill_sw(struct iwl_priv *priv, int disable_radio) +static void iwl3945_radio_kill_sw(struct iwl3945_priv *priv, int disable_radio) { unsigned long flags; @@ -2980,21 +3041,21 @@ static void iwl_radio_kill_sw(struct iwl_priv *priv, int disable_radio) disable_radio ? "OFF" : "ON"); if (disable_radio) { - iwl_scan_cancel(priv); + iwl3945_scan_cancel(priv); /* FIXME: This is a workaround for AP */ if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { spin_lock_irqsave(&priv->lock, flags); - iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, + iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET, CSR_UCODE_SW_BIT_RFKILL); spin_unlock_irqrestore(&priv->lock, flags); - iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); + iwl3945_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); set_bit(STATUS_RF_KILL_SW, &priv->status); } return; } spin_lock_irqsave(&priv->lock, flags); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); clear_bit(STATUS_RF_KILL_SW, &priv->status); spin_unlock_irqrestore(&priv->lock, flags); @@ -3003,9 +3064,9 @@ static void iwl_radio_kill_sw(struct iwl_priv *priv, int disable_radio) msleep(10); spin_lock_irqsave(&priv->lock, flags); - iwl_read32(priv, CSR_UCODE_DRV_GP1); - if (!iwl_grab_restricted_access(priv)) - iwl_release_restricted_access(priv); + iwl3945_read32(priv, CSR_UCODE_DRV_GP1); + if (!iwl3945_grab_nic_access(priv)) + iwl3945_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { @@ -3018,7 +3079,7 @@ static void iwl_radio_kill_sw(struct iwl_priv *priv, int disable_radio) return; } -void iwl_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb, +void iwl3945_set_decrypted_flag(struct iwl3945_priv *priv, struct sk_buff *skb, u32 decrypt_res, struct ieee80211_rx_status *stats) { u16 fc = @@ -3050,97 +3111,9 @@ void iwl_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb, } } -void iwl_handle_data_packet_monitor(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb, - void *data, short len, - struct ieee80211_rx_status *stats, - u16 phy_flags) -{ - struct iwl_rt_rx_hdr *iwl_rt; - - /* First cache any information we need before we overwrite - * the information provided in the skb from the hardware */ - s8 signal = stats->ssi; - s8 noise = 0; - int rate = stats->rate; - u64 tsf = stats->mactime; - __le16 phy_flags_hw = cpu_to_le16(phy_flags); - - /* We received data from the HW, so stop the watchdog */ - if (len > IWL_RX_BUF_SIZE - sizeof(*iwl_rt)) { - IWL_DEBUG_DROP("Dropping too large packet in monitor\n"); - return; - } - - /* copy the frame data to write after where the radiotap header goes */ - iwl_rt = (void *)rxb->skb->data; - memmove(iwl_rt->payload, data, len); - - iwl_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; - iwl_rt->rt_hdr.it_pad = 0; /* always good to zero */ - - /* total header + data */ - iwl_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl_rt)); - - /* Set the size of the skb to the size of the frame */ - skb_put(rxb->skb, sizeof(*iwl_rt) + len); - - /* Big bitfield of all the fields we provide in radiotap */ - iwl_rt->rt_hdr.it_present = - cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) | - (1 << IEEE80211_RADIOTAP_FLAGS) | - (1 << IEEE80211_RADIOTAP_RATE) | - (1 << IEEE80211_RADIOTAP_CHANNEL) | - (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | - (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | - (1 << IEEE80211_RADIOTAP_ANTENNA)); - - /* Zero the flags, we'll add to them as we go */ - iwl_rt->rt_flags = 0; - - iwl_rt->rt_tsf = cpu_to_le64(tsf); - - /* Convert to dBm */ - iwl_rt->rt_dbmsignal = signal; - iwl_rt->rt_dbmnoise = noise; - - /* Convert the channel frequency and set the flags */ - iwl_rt->rt_channelMHz = cpu_to_le16(stats->freq); - if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK)) - iwl_rt->rt_chbitmask = - cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); - else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK) - iwl_rt->rt_chbitmask = - cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); - else /* 802.11g */ - iwl_rt->rt_chbitmask = - cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ)); - - rate = iwl_rate_index_from_plcp(rate); - if (rate == -1) - iwl_rt->rt_rate = 0; - else - iwl_rt->rt_rate = iwl_rates[rate].ieee; - - /* antenna number */ - iwl_rt->rt_antenna = - le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4; - - /* set the preamble flag if we have it */ - if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) - iwl_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; - - IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); - - stats->flag |= RX_FLAG_RADIOTAP; - ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); - rxb->skb = NULL; -} - - #define IWL_PACKET_RETRY_TIME HZ -int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) +int iwl3945_is_duplicate_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header) { u16 sc = le16_to_cpu(header->seq_ctrl); u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; @@ -3151,29 +3124,26 @@ int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) switch (priv->iw_mode) { case IEEE80211_IF_TYPE_IBSS:{ struct list_head *p; - struct iwl_ibss_seq *entry = NULL; + struct iwl3945_ibss_seq *entry = NULL; u8 *mac = header->addr2; int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); __list_for_each(p, &priv->ibss_mac_hash[index]) { - entry = - list_entry(p, struct iwl_ibss_seq, list); + entry = list_entry(p, struct iwl3945_ibss_seq, list); if (!compare_ether_addr(entry->mac, mac)) break; } if (p == &priv->ibss_mac_hash[index]) { entry = kzalloc(sizeof(*entry), GFP_ATOMIC); if (!entry) { - IWL_ERROR - ("Cannot malloc new mac entry\n"); + IWL_ERROR("Cannot malloc new mac entry\n"); return 0; } memcpy(entry->mac, mac, ETH_ALEN); entry->seq_num = seq; entry->frag_num = frag; entry->packet_time = jiffies; - list_add(&entry->list, - &priv->ibss_mac_hash[index]); + list_add(&entry->list, &priv->ibss_mac_hash[index]); return 0; } last_seq = &entry->seq_num; @@ -3207,7 +3177,7 @@ int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) return 1; } -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT +#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT #include "iwl-spectrum.h" @@ -3222,7 +3192,7 @@ int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) * the lower 3 bytes is the time in usec within one beacon interval */ -static u32 iwl_usecs_to_beacons(u32 usec, u32 beacon_interval) +static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval) { u32 quot; u32 rem; @@ -3241,7 +3211,7 @@ static u32 iwl_usecs_to_beacons(u32 usec, u32 beacon_interval) * the same as HW timer counter counting down */ -static __le32 iwl_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) +static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) { u32 base_low = base & BEACON_TIME_MASK_LOW; u32 addon_low = addon & BEACON_TIME_MASK_LOW; @@ -3260,13 +3230,13 @@ static __le32 iwl_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) return cpu_to_le32(res); } -static int iwl_get_measurement(struct iwl_priv *priv, +static int iwl3945_get_measurement(struct iwl3945_priv *priv, struct ieee80211_measurement_params *params, u8 type) { - struct iwl_spectrum_cmd spectrum; - struct iwl_rx_packet *res; - struct iwl_host_cmd cmd = { + struct iwl3945_spectrum_cmd spectrum; + struct iwl3945_rx_packet *res; + struct iwl3945_host_cmd cmd = { .id = REPLY_SPECTRUM_MEASUREMENT_CMD, .data = (void *)&spectrum, .meta.flags = CMD_WANT_SKB, @@ -3276,9 +3246,9 @@ static int iwl_get_measurement(struct iwl_priv *priv, int spectrum_resp_status; int duration = le16_to_cpu(params->duration); - if (iwl_is_associated(priv)) + if (iwl3945_is_associated(priv)) add_time = - iwl_usecs_to_beacons( + iwl3945_usecs_to_beacons( le64_to_cpu(params->start_time) - priv->last_tsf, le16_to_cpu(priv->rxon_timing.beacon_interval)); @@ -3291,9 +3261,9 @@ static int iwl_get_measurement(struct iwl_priv *priv, cmd.len = sizeof(spectrum); spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); - if (iwl_is_associated(priv)) + if (iwl3945_is_associated(priv)) spectrum.start_time = - iwl_add_beacon_time(priv->last_beacon_time, + iwl3945_add_beacon_time(priv->last_beacon_time, add_time, le16_to_cpu(priv->rxon_timing.beacon_interval)); else @@ -3306,11 +3276,11 @@ static int iwl_get_measurement(struct iwl_priv *priv, spectrum.flags |= RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; - rc = iwl_send_cmd_sync(priv, &cmd); + rc = iwl3945_send_cmd_sync(priv, &cmd); if (rc) return rc; - res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; + res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data; if (res->hdr.flags & IWL_CMD_FAILED_MSK) { IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); rc = -EIO; @@ -3320,9 +3290,8 @@ static int iwl_get_measurement(struct iwl_priv *priv, switch (spectrum_resp_status) { case 0: /* Command will be handled */ if (res->u.spectrum.id != 0xff) { - IWL_DEBUG_INFO - ("Replaced existing measurement: %d\n", - res->u.spectrum.id); + IWL_DEBUG_INFO("Replaced existing measurement: %d\n", + res->u.spectrum.id); priv->measurement_status &= ~MEASUREMENT_READY; } priv->measurement_status |= MEASUREMENT_ACTIVE; @@ -3340,8 +3309,8 @@ static int iwl_get_measurement(struct iwl_priv *priv, } #endif -static void iwl_txstatus_to_ieee(struct iwl_priv *priv, - struct iwl_tx_info *tx_sta) +static void iwl3945_txstatus_to_ieee(struct iwl3945_priv *priv, + struct iwl3945_tx_info *tx_sta) { tx_sta->status.ack_signal = 0; @@ -3360,41 +3329,41 @@ static void iwl_txstatus_to_ieee(struct iwl_priv *priv, } /** - * iwl_tx_queue_reclaim - Reclaim Tx queue entries no more used by NIC. + * iwl3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd * - * When FW advances 'R' index, all entries between old and - * new 'R' index need to be reclaimed. As result, some free space - * forms. If there is enough free space (> low mark), wake Tx queue. + * When FW advances 'R' index, all entries between old and new 'R' index + * need to be reclaimed. As result, some free space forms. If there is + * enough free space (> low mark), wake the stack that feeds us. */ -int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index) +static int iwl3945_tx_queue_reclaim(struct iwl3945_priv *priv, int txq_id, int index) { - struct iwl_tx_queue *txq = &priv->txq[txq_id]; - struct iwl_queue *q = &txq->q; + struct iwl3945_tx_queue *txq = &priv->txq[txq_id]; + struct iwl3945_queue *q = &txq->q; int nfreed = 0; if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " "is out of range [0-%d] %d %d.\n", txq_id, - index, q->n_bd, q->first_empty, q->last_used); + index, q->n_bd, q->write_ptr, q->read_ptr); return 0; } - for (index = iwl_queue_inc_wrap(index, q->n_bd); - q->last_used != index; - q->last_used = iwl_queue_inc_wrap(q->last_used, q->n_bd)) { + for (index = iwl3945_queue_inc_wrap(index, q->n_bd); + q->read_ptr != index; + q->read_ptr = iwl3945_queue_inc_wrap(q->read_ptr, q->n_bd)) { if (txq_id != IWL_CMD_QUEUE_NUM) { - iwl_txstatus_to_ieee(priv, - &(txq->txb[txq->q.last_used])); - iwl_hw_txq_free_tfd(priv, txq); + iwl3945_txstatus_to_ieee(priv, + &(txq->txb[txq->q.read_ptr])); + iwl3945_hw_txq_free_tfd(priv, txq); } else if (nfreed > 1) { IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, - q->first_empty, q->last_used); + q->write_ptr, q->read_ptr); queue_work(priv->workqueue, &priv->restart); } nfreed++; } - if (iwl_queue_space(q) > q->low_mark && (txq_id >= 0) && + if (iwl3945_queue_space(q) > q->low_mark && (txq_id >= 0) && (txq_id != IWL_CMD_QUEUE_NUM) && priv->mac80211_registered) ieee80211_wake_queue(priv->hw, txq_id); @@ -3403,7 +3372,7 @@ int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index) return nfreed; } -static int iwl_is_tx_success(u32 status) +static int iwl3945_is_tx_success(u32 status) { return (status & 0xFF) == 0x1; } @@ -3413,27 +3382,30 @@ static int iwl_is_tx_success(u32 status) * Generic RX handler implementations * ******************************************************************************/ -static void iwl_rx_reply_tx(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +/** + * iwl3945_rx_reply_tx - Handle Tx response + */ +static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; u16 sequence = le16_to_cpu(pkt->hdr.sequence); int txq_id = SEQ_TO_QUEUE(sequence); int index = SEQ_TO_INDEX(sequence); - struct iwl_tx_queue *txq = &priv->txq[txq_id]; + struct iwl3945_tx_queue *txq = &priv->txq[txq_id]; struct ieee80211_tx_status *tx_status; - struct iwl_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; + struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; u32 status = le32_to_cpu(tx_resp->status); if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " "is out of range [0-%d] %d %d\n", txq_id, - index, txq->q.n_bd, txq->q.first_empty, - txq->q.last_used); + index, txq->q.n_bd, txq->q.write_ptr, + txq->q.read_ptr); return; } - tx_status = &(txq->txb[txq->q.last_used].status); + tx_status = &(txq->txb[txq->q.read_ptr].status); tx_status->retry_count = tx_resp->failure_frame; tx_status->queue_number = status; @@ -3441,28 +3413,28 @@ static void iwl_rx_reply_tx(struct iwl_priv *priv, tx_status->queue_length |= tx_resp->failure_rts; tx_status->flags = - iwl_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; + iwl3945_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; - tx_status->control.tx_rate = iwl_rate_index_from_plcp(tx_resp->rate); + tx_status->control.tx_rate = iwl3945_rate_index_from_plcp(tx_resp->rate); IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n", - txq_id, iwl_get_tx_fail_reason(status), status, + txq_id, iwl3945_get_tx_fail_reason(status), status, tx_resp->rate, tx_resp->failure_frame); IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); if (index != -1) - iwl_tx_queue_reclaim(priv, txq_id, index); + iwl3945_tx_queue_reclaim(priv, txq_id, index); if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); } -static void iwl_rx_reply_alive(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_reply_alive(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_alive_resp *palive; + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_alive_resp *palive; struct delayed_work *pwork; palive = &pkt->u.alive_frame; @@ -3476,14 +3448,14 @@ static void iwl_rx_reply_alive(struct iwl_priv *priv, IWL_DEBUG_INFO("Initialization Alive received.\n"); memcpy(&priv->card_alive_init, &pkt->u.alive_frame, - sizeof(struct iwl_init_alive_resp)); + sizeof(struct iwl3945_init_alive_resp)); pwork = &priv->init_alive_start; } else { IWL_DEBUG_INFO("Runtime Alive received.\n"); memcpy(&priv->card_alive, &pkt->u.alive_frame, - sizeof(struct iwl_alive_resp)); + sizeof(struct iwl3945_alive_resp)); pwork = &priv->alive_start; - iwl_disable_events(priv); + iwl3945_disable_events(priv); } /* We delay the ALIVE response by 5ms to @@ -3495,19 +3467,19 @@ static void iwl_rx_reply_alive(struct iwl_priv *priv, IWL_WARNING("uCode did not respond OK.\n"); } -static void iwl_rx_reply_add_sta(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_reply_add_sta(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); return; } -static void iwl_rx_reply_error(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_reply_error(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " "seq 0x%04X ser 0x%08X\n", @@ -3520,23 +3492,23 @@ static void iwl_rx_reply_error(struct iwl_priv *priv, #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x -static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_csa(struct iwl3945_priv *priv, struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; - struct iwl_csa_notification *csa = &(pkt->u.csa_notif); + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_rxon_cmd *rxon = (void *)&priv->active_rxon; + struct iwl3945_csa_notification *csa = &(pkt->u.csa_notif); IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); rxon->channel = csa->channel; priv->staging_rxon.channel = csa->channel; } -static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_spectrum_measure_notif(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif); +#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_spectrum_notification *report = &(pkt->u.spectrum_notif); if (!report->state) { IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, @@ -3549,35 +3521,35 @@ static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv, #endif } -static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_pm_sleep_notif(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { -#ifdef CONFIG_IWLWIFI_DEBUG - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); +#ifdef CONFIG_IWL3945_DEBUG + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_sleep_notification *sleep = &(pkt->u.sleep_notif); IWL_DEBUG_RX("sleep mode: %d, src: %d\n", sleep->pm_sleep_mode, sleep->pm_wakeup_src); #endif } -static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_pm_debug_statistics_notif(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " "notification for %s:\n", le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); - iwl_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len)); + iwl3945_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len)); } -static void iwl_bg_beacon_update(struct work_struct *work) +static void iwl3945_bg_beacon_update(struct work_struct *work) { - struct iwl_priv *priv = - container_of(work, struct iwl_priv, beacon_update); + struct iwl3945_priv *priv = + container_of(work, struct iwl3945_priv, beacon_update); struct sk_buff *beacon; /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ - beacon = ieee80211_beacon_get(priv->hw, priv->interface_id, NULL); + beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); if (!beacon) { IWL_ERROR("update beacon failed\n"); @@ -3592,15 +3564,15 @@ static void iwl_bg_beacon_update(struct work_struct *work) priv->ibss_beacon = beacon; mutex_unlock(&priv->mutex); - iwl_send_beacon_cmd(priv); + iwl3945_send_beacon_cmd(priv); } -static void iwl_rx_beacon_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_beacon_notif(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { -#ifdef CONFIG_IWLWIFI_DEBUG - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_beacon_notif *beacon = &(pkt->u.beacon_status); +#ifdef CONFIG_IWL3945_DEBUG + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status); u8 rate = beacon->beacon_notify_hdr.rate; IWL_DEBUG_RX("beacon status %x retries %d iss %d " @@ -3618,25 +3590,25 @@ static void iwl_rx_beacon_notif(struct iwl_priv *priv, } /* Service response to REPLY_SCAN_CMD (0x80) */ -static void iwl_rx_reply_scan(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_reply_scan(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { -#ifdef CONFIG_IWLWIFI_DEBUG - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_scanreq_notification *notif = - (struct iwl_scanreq_notification *)pkt->u.raw; +#ifdef CONFIG_IWL3945_DEBUG + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_scanreq_notification *notif = + (struct iwl3945_scanreq_notification *)pkt->u.raw; IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); #endif } /* Service SCAN_START_NOTIFICATION (0x82) */ -static void iwl_rx_scan_start_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_scan_start_notif(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_scanstart_notification *notif = - (struct iwl_scanstart_notification *)pkt->u.raw; + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_scanstart_notification *notif = + (struct iwl3945_scanstart_notification *)pkt->u.raw; priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); IWL_DEBUG_SCAN("Scan start: " "%d [802.11%s] " @@ -3648,12 +3620,12 @@ static void iwl_rx_scan_start_notif(struct iwl_priv *priv, } /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ -static void iwl_rx_scan_results_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_scan_results_notif(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_scanresults_notification *notif = - (struct iwl_scanresults_notification *)pkt->u.raw; + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_scanresults_notification *notif = + (struct iwl3945_scanresults_notification *)pkt->u.raw; IWL_DEBUG_SCAN("Scan ch.res: " "%d [802.11%s] " @@ -3669,14 +3641,15 @@ static void iwl_rx_scan_results_notif(struct iwl_priv *priv, (priv->last_scan_jiffies, jiffies))); priv->last_scan_jiffies = jiffies; + priv->next_scan_jiffies = 0; } /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ -static void iwl_rx_scan_complete_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw; + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_scancomplete_notification *scan_notif = (void *)pkt->u.raw; IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", scan_notif->scanned_channels, @@ -3711,6 +3684,7 @@ static void iwl_rx_scan_complete_notif(struct iwl_priv *priv, } priv->last_scan_jiffies = jiffies; + priv->next_scan_jiffies = 0; IWL_DEBUG_INFO("Setting scan to off\n"); clear_bit(STATUS_SCANNING, &priv->status); @@ -3729,10 +3703,10 @@ reschedule: /* Handle notification from uCode that card's power state is changing * due to software, hardware, or critical temperature RFKILL */ -static void iwl_rx_card_state_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_rx_card_state_notif(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); unsigned long status = priv->status; @@ -3740,7 +3714,7 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv, (flags & HW_CARD_DISABLED) ? "Kill" : "On", (flags & SW_CARD_DISABLED) ? "Kill" : "On"); - iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, + iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET, CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); if (flags & HW_CARD_DISABLED) @@ -3754,7 +3728,7 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv, else clear_bit(STATUS_RF_KILL_SW, &priv->status); - iwl_scan_cancel(priv); + iwl3945_scan_cancel(priv); if ((test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status)) || @@ -3766,7 +3740,7 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv, } /** - * iwl_setup_rx_handlers - Initialize Rx handler callbacks + * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks * * Setup the RX handlers for each of the reply types sent from the uCode * to the host. @@ -3774,61 +3748,58 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv, * This function chains into the hardware specific files for them to setup * any hardware specific handlers as well. */ -static void iwl_setup_rx_handlers(struct iwl_priv *priv) +static void iwl3945_setup_rx_handlers(struct iwl3945_priv *priv) { - priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; - priv->rx_handlers[REPLY_ADD_STA] = iwl_rx_reply_add_sta; - priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error; - priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa; + priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive; + priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta; + priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error; + priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa; priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = - iwl_rx_spectrum_measure_notif; - priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif; + iwl3945_rx_spectrum_measure_notif; + priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif; priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = - iwl_rx_pm_debug_statistics_notif; - priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif; - - /* NOTE: iwl_rx_statistics is different based on whether - * the build is for the 3945 or the 4965. See the - * corresponding implementation in iwl-XXXX.c - * - * The same handler is used for both the REPLY to a - * discrete statistics request from the host as well as - * for the periodic statistics notification from the uCode + iwl3945_rx_pm_debug_statistics_notif; + priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif; + + /* + * The same handler is used for both the REPLY to a discrete + * statistics request from the host as well as for the periodic + * statistics notifications (after received beacons) from the uCode. */ - priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_hw_rx_statistics; - priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_hw_rx_statistics; + priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics; + priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics; - priv->rx_handlers[REPLY_SCAN_CMD] = iwl_rx_reply_scan; - priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl_rx_scan_start_notif; + priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan; + priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif; priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = - iwl_rx_scan_results_notif; + iwl3945_rx_scan_results_notif; priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = - iwl_rx_scan_complete_notif; - priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif; - priv->rx_handlers[REPLY_TX] = iwl_rx_reply_tx; + iwl3945_rx_scan_complete_notif; + priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif; + priv->rx_handlers[REPLY_TX] = iwl3945_rx_reply_tx; - /* Setup hardware specific Rx handlers */ - iwl_hw_rx_handler_setup(priv); + /* Set up hardware specific Rx handlers */ + iwl3945_hw_rx_handler_setup(priv); } /** - * iwl_tx_cmd_complete - Pull unused buffers off the queue and reclaim them + * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them * @rxb: Rx buffer to reclaim * * If an Rx buffer has an async callback associated with it the callback * will be executed. The attached skb (if present) will only be freed * if the callback returns 1 */ -static void iwl_tx_cmd_complete(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl3945_tx_cmd_complete(struct iwl3945_priv *priv, + struct iwl3945_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; + struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data; u16 sequence = le16_to_cpu(pkt->hdr.sequence); int txq_id = SEQ_TO_QUEUE(sequence); int index = SEQ_TO_INDEX(sequence); int huge = sequence & SEQ_HUGE_FRAME; int cmd_index; - struct iwl_cmd *cmd; + struct iwl3945_cmd *cmd; /* If a Tx command is being handled and it isn't in the actual * command queue then there a command routing bug has been introduced @@ -3849,7 +3820,7 @@ static void iwl_tx_cmd_complete(struct iwl_priv *priv, !cmd->meta.u.callback(priv, cmd, rxb->skb)) rxb->skb = NULL; - iwl_tx_queue_reclaim(priv, txq_id, index); + iwl3945_tx_queue_reclaim(priv, txq_id, index); if (!(cmd->meta.flags & CMD_ASYNC)) { clear_bit(STATUS_HCMD_ACTIVE, &priv->status); @@ -3879,10 +3850,10 @@ static void iwl_tx_cmd_complete(struct iwl_priv *priv, * The queue is empty (no good data) if WRITE = READ - 1, and is full if * WRITE = READ. * - * During initialization the host sets up the READ queue position to the first + * During initialization, the host sets up the READ queue position to the first * INDEX position, and WRITE to the last (READ - 1 wrapped) * - * When the firmware places a packet in a buffer it will advance the READ index + * When the firmware places a packet in a buffer, it will advance the READ index * and fire the RX interrupt. The driver can then query the READ index and * process as many packets as possible, moving the WRITE index forward as it * resets the Rx queue buffers with new memory. @@ -3890,8 +3861,8 @@ static void iwl_tx_cmd_complete(struct iwl_priv *priv, * The management in the driver is as follows: * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled - * to replensish the iwl->rxq->rx_free. - * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the + * to replenish the iwl->rxq->rx_free. + * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the * iwl->rxq is replenished and the READ INDEX is updated (updating the * 'processed' and 'read' driver indexes as well) * + A received packet is processed and handed to the kernel network stack, @@ -3904,28 +3875,28 @@ static void iwl_tx_cmd_complete(struct iwl_priv *priv, * * Driver sequence: * - * iwl_rx_queue_alloc() Allocates rx_free - * iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls - * iwl_rx_queue_restock - * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx + * iwl3945_rx_queue_alloc() Allocates rx_free + * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls + * iwl3945_rx_queue_restock + * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx * queue, updates firmware pointers, and updates * the WRITE index. If insufficient rx_free buffers - * are available, schedules iwl_rx_replenish + * are available, schedules iwl3945_rx_replenish * * -- enable interrupts -- - * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the + * ISR - iwl3945_rx() Detach iwl3945_rx_mem_buffers from pool up to the * READ INDEX, detaching the SKB from the pool. * Moves the packet buffer from queue to rx_used. - * Calls iwl_rx_queue_restock to refill any empty + * Calls iwl3945_rx_queue_restock to refill any empty * slots. * ... * */ /** - * iwl_rx_queue_space - Return number of free slots available in queue. + * iwl3945_rx_queue_space - Return number of free slots available in queue. */ -static int iwl_rx_queue_space(const struct iwl_rx_queue *q) +static int iwl3945_rx_queue_space(const struct iwl3945_rx_queue *q) { int s = q->read - q->write; if (s <= 0) @@ -3938,15 +3909,9 @@ static int iwl_rx_queue_space(const struct iwl_rx_queue *q) } /** - * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue - * - * NOTE: This function has 3945 and 4965 specific code sections - * but is declared in base due to the majority of the - * implementation being the same (only a numeric constant is - * different) - * + * iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue */ -int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q) +int iwl3945_rx_queue_update_write_ptr(struct iwl3945_priv *priv, struct iwl3945_rx_queue *q) { u32 reg = 0; int rc = 0; @@ -3957,24 +3922,29 @@ int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q) if (q->need_update == 0) goto exit_unlock; + /* If power-saving is in use, make sure device is awake */ if (test_bit(STATUS_POWER_PMI, &priv->status)) { - reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); + reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1); if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { - iwl_set_bit(priv, CSR_GP_CNTRL, + iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); goto exit_unlock; } - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) goto exit_unlock; - iwl_write_restricted(priv, FH_RSCSR_CHNL0_WPTR, + /* Device expects a multiple of 8 */ + iwl3945_write_direct32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); + + /* Else device is assumed to be awake */ } else - iwl_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); + /* Device expects a multiple of 8 */ + iwl3945_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); q->need_update = 0; @@ -3985,42 +3955,43 @@ int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q) } /** - * iwl_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer pointer. - * - * NOTE: This function has 3945 and 4965 specific code paths in it. + * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr */ -static inline __le32 iwl_dma_addr2rbd_ptr(struct iwl_priv *priv, +static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl3945_priv *priv, dma_addr_t dma_addr) { return cpu_to_le32((u32)dma_addr); } /** - * iwl_rx_queue_restock - refill RX queue from pre-allocated pool + * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool * - * If there are slots in the RX queue that need to be restocked, + * If there are slots in the RX queue that need to be restocked, * and we have free pre-allocated buffers, fill the ranks as much - * as we can pulling from rx_free. + * as we can, pulling from rx_free. * * This moves the 'write' index forward to catch up with 'processed', and * also updates the memory address in the firmware to reference the new * target buffer. */ -int iwl_rx_queue_restock(struct iwl_priv *priv) +static int iwl3945_rx_queue_restock(struct iwl3945_priv *priv) { - struct iwl_rx_queue *rxq = &priv->rxq; + struct iwl3945_rx_queue *rxq = &priv->rxq; struct list_head *element; - struct iwl_rx_mem_buffer *rxb; + struct iwl3945_rx_mem_buffer *rxb; unsigned long flags; int write, rc; spin_lock_irqsave(&rxq->lock, flags); write = rxq->write & ~0x7; - while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) { + while ((iwl3945_rx_queue_space(rxq) > 0) && (rxq->free_count)) { + /* Get next free Rx buffer, remove from free list */ element = rxq->rx_free.next; - rxb = list_entry(element, struct iwl_rx_mem_buffer, list); + rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list); list_del(element); - rxq->bd[rxq->write] = iwl_dma_addr2rbd_ptr(priv, rxb->dma_addr); + + /* Point to Rx buffer via next RBD in circular buffer */ + rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->dma_addr); rxq->queue[rxq->write] = rxb; rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; rxq->free_count--; @@ -4032,13 +4003,14 @@ int iwl_rx_queue_restock(struct iwl_priv *priv) queue_work(priv->workqueue, &priv->rx_replenish); - /* If we've added more space for the firmware to place data, tell it */ + /* If we've added more space for the firmware to place data, tell it. + * Increment device's write pointer in multiples of 8. */ if ((write != (rxq->write & ~0x7)) || (abs(rxq->write - rxq->read) > 7)) { spin_lock_irqsave(&rxq->lock, flags); rxq->need_update = 1; spin_unlock_irqrestore(&rxq->lock, flags); - rc = iwl_rx_queue_update_write_ptr(priv, rxq); + rc = iwl3945_rx_queue_update_write_ptr(priv, rxq); if (rc) return rc; } @@ -4047,24 +4019,25 @@ int iwl_rx_queue_restock(struct iwl_priv *priv) } /** - * iwl_rx_replensih - Move all used packet from rx_used to rx_free + * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free * * When moving to rx_free an SKB is allocated for the slot. * - * Also restock the Rx queue via iwl_rx_queue_restock. - * This is called as a scheduled work item (except for during intialization) + * Also restock the Rx queue via iwl3945_rx_queue_restock. + * This is called as a scheduled work item (except for during initialization) */ -void iwl_rx_replenish(void *data) +static void iwl3945_rx_allocate(struct iwl3945_priv *priv) { - struct iwl_priv *priv = data; - struct iwl_rx_queue *rxq = &priv->rxq; + struct iwl3945_rx_queue *rxq = &priv->rxq; struct list_head *element; - struct iwl_rx_mem_buffer *rxb; + struct iwl3945_rx_mem_buffer *rxb; unsigned long flags; spin_lock_irqsave(&rxq->lock, flags); while (!list_empty(&rxq->rx_used)) { element = rxq->rx_used.next; - rxb = list_entry(element, struct iwl_rx_mem_buffer, list); + rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list); + + /* Alloc a new receive buffer */ rxb->skb = alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC); if (!rxb->skb) { @@ -4076,8 +4049,19 @@ void iwl_rx_replenish(void *data) * more buffers it will schedule replenish */ break; } + + /* If radiotap head is required, reserve some headroom here. + * The physical head count is a variable rx_stats->phy_count. + * We reserve 4 bytes here. Plus these extra bytes, the + * headroom of the physical head should be enough for the + * radiotap head that iwl3945 supported. See iwl3945_rt. + */ + skb_reserve(rxb->skb, 4); + priv->alloc_rxb_skb++; list_del(element); + + /* Get physical address of RB/SKB */ rxb->dma_addr = pci_map_single(priv->pci_dev, rxb->skb->data, IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); @@ -4085,18 +4069,38 @@ void iwl_rx_replenish(void *data) rxq->free_count++; } spin_unlock_irqrestore(&rxq->lock, flags); +} + +/* + * this should be called while priv->lock is locked + */ +static void __iwl3945_rx_replenish(void *data) +{ + struct iwl3945_priv *priv = data; + + iwl3945_rx_allocate(priv); + iwl3945_rx_queue_restock(priv); +} + + +void iwl3945_rx_replenish(void *data) +{ + struct iwl3945_priv *priv = data; + unsigned long flags; + + iwl3945_rx_allocate(priv); spin_lock_irqsave(&priv->lock, flags); - iwl_rx_queue_restock(priv); + iwl3945_rx_queue_restock(priv); spin_unlock_irqrestore(&priv->lock, flags); } /* Assumes that the skb field of the buffers in 'pool' is kept accurate. - * If an SKB has been detached, the POOL needs to have it's SKB set to NULL + * If an SKB has been detached, the POOL needs to have its SKB set to NULL * This free routine walks the list of POOL entries and if SKB is set to * non NULL it is unmapped and freed */ -void iwl_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq) +static void iwl3945_rx_queue_free(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq) { int i; for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { @@ -4113,21 +4117,25 @@ void iwl_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq) rxq->bd = NULL; } -int iwl_rx_queue_alloc(struct iwl_priv *priv) +int iwl3945_rx_queue_alloc(struct iwl3945_priv *priv) { - struct iwl_rx_queue *rxq = &priv->rxq; + struct iwl3945_rx_queue *rxq = &priv->rxq; struct pci_dev *dev = priv->pci_dev; int i; spin_lock_init(&rxq->lock); INIT_LIST_HEAD(&rxq->rx_free); INIT_LIST_HEAD(&rxq->rx_used); + + /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); if (!rxq->bd) return -ENOMEM; + /* Fill the rx_used queue with _all_ of the Rx buffers */ for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) list_add_tail(&rxq->pool[i].list, &rxq->rx_used); + /* Set us so that we have processed and used all buffers, but have * not restocked the Rx queue with fresh buffers */ rxq->read = rxq->write = 0; @@ -4136,7 +4144,7 @@ int iwl_rx_queue_alloc(struct iwl_priv *priv) return 0; } -void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq) +void iwl3945_rx_queue_reset(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq) { unsigned long flags; int i; @@ -4183,7 +4191,7 @@ static u8 ratio2dB[100] = { /* Calculates a relative dB value from a ratio of linear * (i.e. not dB) signal levels. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ -int iwl_calc_db_from_ratio(int sig_ratio) +int iwl3945_calc_db_from_ratio(int sig_ratio) { /* Anything above 1000:1 just report as 60 dB */ if (sig_ratio > 1000) @@ -4209,7 +4217,7 @@ int iwl_calc_db_from_ratio(int sig_ratio) /* Calculate an indication of rx signal quality (a percentage, not dBm!). * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info * about formulas used below. */ -int iwl_calc_sig_qual(int rssi_dbm, int noise_dbm) +int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm) { int sig_qual; int degradation = PERFECT_RSSI - rssi_dbm; @@ -4244,24 +4252,30 @@ int iwl_calc_sig_qual(int rssi_dbm, int noise_dbm) } /** - * iwl_rx_handle - Main entry function for receiving responses from the uCode + * iwl3945_rx_handle - Main entry function for receiving responses from uCode * * Uses the priv->rx_handlers callback function array to invoke * the appropriate handlers, including command responses, * frame-received notifications, and other notifications. */ -static void iwl_rx_handle(struct iwl_priv *priv) +static void iwl3945_rx_handle(struct iwl3945_priv *priv) { - struct iwl_rx_mem_buffer *rxb; - struct iwl_rx_packet *pkt; - struct iwl_rx_queue *rxq = &priv->rxq; + struct iwl3945_rx_mem_buffer *rxb; + struct iwl3945_rx_packet *pkt; + struct iwl3945_rx_queue *rxq = &priv->rxq; u32 r, i; int reclaim; unsigned long flags; + u8 fill_rx = 0; + u32 count = 0; - r = iwl_hw_get_rx_read(priv); + /* uCode's read index (stored in shared DRAM) indicates the last Rx + * buffer that the driver may process (last buffer filled by ucode). */ + r = iwl3945_hw_get_rx_read(priv); i = rxq->read; + if (iwl3945_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) + fill_rx = 1; /* Rx interrupt, but nothing sent from uCode */ if (i == r) IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); @@ -4269,7 +4283,7 @@ static void iwl_rx_handle(struct iwl_priv *priv) while (i != r) { rxb = rxq->queue[i]; - /* If an RXB doesn't have a queue slot associated with it + /* If an RXB doesn't have a Rx queue slot associated with it, * then a bug has been introduced in the queue refilling * routines -- catch it here */ BUG_ON(rxb == NULL); @@ -4279,7 +4293,7 @@ static void iwl_rx_handle(struct iwl_priv *priv) pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); - pkt = (struct iwl_rx_packet *)rxb->skb->data; + pkt = (struct iwl3945_rx_packet *)rxb->skb->data; /* Reclaim a command buffer only if this packet is a response * to a (driver-originated) command. @@ -4293,7 +4307,7 @@ static void iwl_rx_handle(struct iwl_priv *priv) /* Based on type of command response or notification, * handle those that need handling via function in - * rx_handlers table. See iwl_setup_rx_handlers() */ + * rx_handlers table. See iwl3945_setup_rx_handlers() */ if (priv->rx_handlers[pkt->hdr.cmd]) { IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d, %s, 0x%02x\n", r, i, @@ -4308,11 +4322,11 @@ static void iwl_rx_handle(struct iwl_priv *priv) } if (reclaim) { - /* Invoke any callbacks, transfer the skb to caller, - * and fire off the (possibly) blocking iwl_send_cmd() + /* Invoke any callbacks, transfer the skb to caller, and + * fire off the (possibly) blocking iwl3945_send_cmd() * as we reclaim the driver command queue */ if (rxb && rxb->skb) - iwl_tx_cmd_complete(priv, rxb); + iwl3945_tx_cmd_complete(priv, rxb); else IWL_WARNING("Claim null rxb?\n"); } @@ -4332,15 +4346,28 @@ static void iwl_rx_handle(struct iwl_priv *priv) list_add_tail(&rxb->list, &priv->rxq.rx_used); spin_unlock_irqrestore(&rxq->lock, flags); i = (i + 1) & RX_QUEUE_MASK; + /* If there are a lot of unused frames, + * restock the Rx queue so ucode won't assert. */ + if (fill_rx) { + count++; + if (count >= 8) { + priv->rxq.read = i; + __iwl3945_rx_replenish(priv); + count = 0; + } + } } /* Backtrack one entry */ priv->rxq.read = i; - iwl_rx_queue_restock(priv); + iwl3945_rx_queue_restock(priv); } -int iwl_tx_queue_update_write_ptr(struct iwl_priv *priv, - struct iwl_tx_queue *txq) +/** + * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware + */ +static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv, + struct iwl3945_tx_queue *txq) { u32 reg = 0; int rc = 0; @@ -4354,41 +4381,41 @@ int iwl_tx_queue_update_write_ptr(struct iwl_priv *priv, /* wake up nic if it's powered down ... * uCode will wake up, and interrupt us again, so next * time we'll skip this part. */ - reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); + reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1); if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); - iwl_set_bit(priv, CSR_GP_CNTRL, + iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); return rc; } /* restore this queue's parameters in nic hardware. */ - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) return rc; - iwl_write_restricted(priv, HBUS_TARG_WRPTR, - txq->q.first_empty | (txq_id << 8)); - iwl_release_restricted_access(priv); + iwl3945_write_direct32(priv, HBUS_TARG_WRPTR, + txq->q.write_ptr | (txq_id << 8)); + iwl3945_release_nic_access(priv); /* else not in power-save mode, uCode will never sleep when we're * trying to tx (during RFKILL, we're not trying to tx). */ } else - iwl_write32(priv, HBUS_TARG_WRPTR, - txq->q.first_empty | (txq_id << 8)); + iwl3945_write32(priv, HBUS_TARG_WRPTR, + txq->q.write_ptr | (txq_id << 8)); txq->need_update = 0; return rc; } -#ifdef CONFIG_IWLWIFI_DEBUG -static void iwl_print_rx_config_cmd(struct iwl_rxon_cmd *rxon) +#ifdef CONFIG_IWL3945_DEBUG +static void iwl3945_print_rx_config_cmd(struct iwl3945_rxon_cmd *rxon) { DECLARE_MAC_BUF(mac); IWL_DEBUG_RADIO("RX CONFIG:\n"); - iwl_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); + iwl3945_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", @@ -4405,24 +4432,24 @@ static void iwl_print_rx_config_cmd(struct iwl_rxon_cmd *rxon) } #endif -static void iwl_enable_interrupts(struct iwl_priv *priv) +static void iwl3945_enable_interrupts(struct iwl3945_priv *priv) { IWL_DEBUG_ISR("Enabling interrupts\n"); set_bit(STATUS_INT_ENABLED, &priv->status); - iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); + iwl3945_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); } -static inline void iwl_disable_interrupts(struct iwl_priv *priv) +static inline void iwl3945_disable_interrupts(struct iwl3945_priv *priv) { clear_bit(STATUS_INT_ENABLED, &priv->status); /* disable interrupts from uCode/NIC to host */ - iwl_write32(priv, CSR_INT_MASK, 0x00000000); + iwl3945_write32(priv, CSR_INT_MASK, 0x00000000); /* acknowledge/clear/reset any interrupts still pending * from uCode or flow handler (Rx/Tx DMA) */ - iwl_write32(priv, CSR_INT, 0xffffffff); - iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); + iwl3945_write32(priv, CSR_INT, 0xffffffff); + iwl3945_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); IWL_DEBUG_ISR("Disabled interrupts\n"); } @@ -4449,7 +4476,7 @@ static const char *desc_lookup(int i) #define ERROR_START_OFFSET (1 * sizeof(u32)) #define ERROR_ELEM_SIZE (7 * sizeof(u32)) -static void iwl_dump_nic_error_log(struct iwl_priv *priv) +static void iwl3945_dump_nic_error_log(struct iwl3945_priv *priv) { u32 i; u32 desc, time, count, base, data1; @@ -4458,18 +4485,18 @@ static void iwl_dump_nic_error_log(struct iwl_priv *priv) base = le32_to_cpu(priv->card_alive.error_event_table_ptr); - if (!iwl_hw_valid_rtc_data_addr(base)) { + if (!iwl3945_hw_valid_rtc_data_addr(base)) { IWL_ERROR("Not valid error log pointer 0x%08X\n", base); return; } - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { IWL_WARNING("Can not read from adapter at this time.\n"); return; } - count = iwl_read_restricted_mem(priv, base); + count = iwl3945_read_targ_mem(priv, base); if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { IWL_ERROR("Start IWL Error Log Dump:\n"); @@ -4482,19 +4509,19 @@ static void iwl_dump_nic_error_log(struct iwl_priv *priv) for (i = ERROR_START_OFFSET; i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET; i += ERROR_ELEM_SIZE) { - desc = iwl_read_restricted_mem(priv, base + i); + desc = iwl3945_read_targ_mem(priv, base + i); time = - iwl_read_restricted_mem(priv, base + i + 1 * sizeof(u32)); + iwl3945_read_targ_mem(priv, base + i + 1 * sizeof(u32)); blink1 = - iwl_read_restricted_mem(priv, base + i + 2 * sizeof(u32)); + iwl3945_read_targ_mem(priv, base + i + 2 * sizeof(u32)); blink2 = - iwl_read_restricted_mem(priv, base + i + 3 * sizeof(u32)); + iwl3945_read_targ_mem(priv, base + i + 3 * sizeof(u32)); ilink1 = - iwl_read_restricted_mem(priv, base + i + 4 * sizeof(u32)); + iwl3945_read_targ_mem(priv, base + i + 4 * sizeof(u32)); ilink2 = - iwl_read_restricted_mem(priv, base + i + 5 * sizeof(u32)); + iwl3945_read_targ_mem(priv, base + i + 5 * sizeof(u32)); data1 = - iwl_read_restricted_mem(priv, base + i + 6 * sizeof(u32)); + iwl3945_read_targ_mem(priv, base + i + 6 * sizeof(u32)); IWL_ERROR ("%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n", @@ -4502,18 +4529,18 @@ static void iwl_dump_nic_error_log(struct iwl_priv *priv) ilink1, ilink2, data1); } - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); } -#define EVENT_START_OFFSET (4 * sizeof(u32)) +#define EVENT_START_OFFSET (6 * sizeof(u32)) /** - * iwl_print_event_log - Dump error event log to syslog + * iwl3945_print_event_log - Dump error event log to syslog * - * NOTE: Must be called with iwl_grab_restricted_access() already obtained! + * NOTE: Must be called with iwl3945_grab_nic_access() already obtained! */ -static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, +static void iwl3945_print_event_log(struct iwl3945_priv *priv, u32 start_idx, u32 num_events, u32 mode) { u32 i; @@ -4537,21 +4564,21 @@ static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, /* "time" is actually "data" for mode 0 (no timestamp). * place event id # at far right for easier visual parsing. */ for (i = 0; i < num_events; i++) { - ev = iwl_read_restricted_mem(priv, ptr); + ev = iwl3945_read_targ_mem(priv, ptr); ptr += sizeof(u32); - time = iwl_read_restricted_mem(priv, ptr); + time = iwl3945_read_targ_mem(priv, ptr); ptr += sizeof(u32); if (mode == 0) IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ else { - data = iwl_read_restricted_mem(priv, ptr); + data = iwl3945_read_targ_mem(priv, ptr); ptr += sizeof(u32); IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); } } } -static void iwl_dump_nic_event_log(struct iwl_priv *priv) +static void iwl3945_dump_nic_event_log(struct iwl3945_priv *priv) { int rc; u32 base; /* SRAM byte address of event log header */ @@ -4562,29 +4589,29 @@ static void iwl_dump_nic_event_log(struct iwl_priv *priv) u32 size; /* # entries that we'll print */ base = le32_to_cpu(priv->card_alive.log_event_table_ptr); - if (!iwl_hw_valid_rtc_data_addr(base)) { + if (!iwl3945_hw_valid_rtc_data_addr(base)) { IWL_ERROR("Invalid event log pointer 0x%08X\n", base); return; } - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { IWL_WARNING("Can not read from adapter at this time.\n"); return; } /* event log header */ - capacity = iwl_read_restricted_mem(priv, base); - mode = iwl_read_restricted_mem(priv, base + (1 * sizeof(u32))); - num_wraps = iwl_read_restricted_mem(priv, base + (2 * sizeof(u32))); - next_entry = iwl_read_restricted_mem(priv, base + (3 * sizeof(u32))); + capacity = iwl3945_read_targ_mem(priv, base); + mode = iwl3945_read_targ_mem(priv, base + (1 * sizeof(u32))); + num_wraps = iwl3945_read_targ_mem(priv, base + (2 * sizeof(u32))); + next_entry = iwl3945_read_targ_mem(priv, base + (3 * sizeof(u32))); size = num_wraps ? capacity : next_entry; /* bail out if nothing in log */ if (size == 0) { IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); return; } @@ -4594,31 +4621,31 @@ static void iwl_dump_nic_event_log(struct iwl_priv *priv) /* if uCode has wrapped back to top of log, start at the oldest entry, * i.e the next one that uCode would fill. */ if (num_wraps) - iwl_print_event_log(priv, next_entry, + iwl3945_print_event_log(priv, next_entry, capacity - next_entry, mode); /* (then/else) start at top of log */ - iwl_print_event_log(priv, 0, next_entry, mode); + iwl3945_print_event_log(priv, 0, next_entry, mode); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); } /** - * iwl_irq_handle_error - called for HW or SW error interrupt from card + * iwl3945_irq_handle_error - called for HW or SW error interrupt from card */ -static void iwl_irq_handle_error(struct iwl_priv *priv) +static void iwl3945_irq_handle_error(struct iwl3945_priv *priv) { - /* Set the FW error flag -- cleared on iwl_down */ + /* Set the FW error flag -- cleared on iwl3945_down */ set_bit(STATUS_FW_ERROR, &priv->status); /* Cancel currently queued command. */ clear_bit(STATUS_HCMD_ACTIVE, &priv->status); -#ifdef CONFIG_IWLWIFI_DEBUG - if (iwl_debug_level & IWL_DL_FW_ERRORS) { - iwl_dump_nic_error_log(priv); - iwl_dump_nic_event_log(priv); - iwl_print_rx_config_cmd(&priv->staging_rxon); +#ifdef CONFIG_IWL3945_DEBUG + if (iwl3945_debug_level & IWL_DL_FW_ERRORS) { + iwl3945_dump_nic_error_log(priv); + iwl3945_dump_nic_event_log(priv); + iwl3945_print_rx_config_cmd(&priv->staging_rxon); } #endif @@ -4632,7 +4659,7 @@ static void iwl_irq_handle_error(struct iwl_priv *priv) IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, "Restarting adapter due to uCode error.\n"); - if (iwl_is_associated(priv)) { + if (iwl3945_is_associated(priv)) { memcpy(&priv->recovery_rxon, &priv->active_rxon, sizeof(priv->recovery_rxon)); priv->error_recovering = 1; @@ -4641,16 +4668,16 @@ static void iwl_irq_handle_error(struct iwl_priv *priv) } } -static void iwl_error_recovery(struct iwl_priv *priv) +static void iwl3945_error_recovery(struct iwl3945_priv *priv) { unsigned long flags; memcpy(&priv->staging_rxon, &priv->recovery_rxon, sizeof(priv->staging_rxon)); priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); - iwl_add_station(priv, priv->bssid, 1, 0); + iwl3945_add_station(priv, priv->bssid, 1, 0); spin_lock_irqsave(&priv->lock, flags); priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); @@ -4658,12 +4685,12 @@ static void iwl_error_recovery(struct iwl_priv *priv) spin_unlock_irqrestore(&priv->lock, flags); } -static void iwl_irq_tasklet(struct iwl_priv *priv) +static void iwl3945_irq_tasklet(struct iwl3945_priv *priv) { u32 inta, handled = 0; u32 inta_fh; unsigned long flags; -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL3945_DEBUG u32 inta_mask; #endif @@ -4672,18 +4699,19 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) /* Ack/clear/reset pending uCode interrupts. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, * and will clear only when CSR_FH_INT_STATUS gets cleared. */ - inta = iwl_read32(priv, CSR_INT); - iwl_write32(priv, CSR_INT, inta); + inta = iwl3945_read32(priv, CSR_INT); + iwl3945_write32(priv, CSR_INT, inta); /* Ack/clear/reset pending flow-handler (DMA) interrupts. * Any new interrupts that happen after this, either while we're * in this tasklet, or later, will show up in next ISR/tasklet. */ - inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); - iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); + inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS); + iwl3945_write32(priv, CSR_FH_INT_STATUS, inta_fh); -#ifdef CONFIG_IWLWIFI_DEBUG - if (iwl_debug_level & IWL_DL_ISR) { - inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ +#ifdef CONFIG_IWL3945_DEBUG + if (iwl3945_debug_level & IWL_DL_ISR) { + /* just for debug */ + inta_mask = iwl3945_read32(priv, CSR_INT_MASK); IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", inta, inta_mask, inta_fh); } @@ -4703,9 +4731,9 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) IWL_ERROR("Microcode HW error detected. Restarting.\n"); /* Tell the device to stop sending interrupts */ - iwl_disable_interrupts(priv); + iwl3945_disable_interrupts(priv); - iwl_irq_handle_error(priv); + iwl3945_irq_handle_error(priv); handled |= CSR_INT_BIT_HW_ERR; @@ -4714,8 +4742,8 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) return; } -#ifdef CONFIG_IWLWIFI_DEBUG - if (iwl_debug_level & (IWL_DL_ISR)) { +#ifdef CONFIG_IWL3945_DEBUG + if (iwl3945_debug_level & (IWL_DL_ISR)) { /* NIC fires this, but we don't use it, redundant with WAKEUP */ if (inta & CSR_INT_BIT_MAC_CLK_ACTV) IWL_DEBUG_ISR("Microcode started or stopped.\n"); @@ -4731,7 +4759,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) /* HW RF KILL switch toggled (4965 only) */ if (inta & CSR_INT_BIT_RF_KILL) { int hw_rf_kill = 0; - if (!(iwl_read32(priv, CSR_GP_CNTRL) & + if (!(iwl3945_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) hw_rf_kill = 1; @@ -4761,20 +4789,20 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) if (inta & CSR_INT_BIT_SW_ERR) { IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", inta); - iwl_irq_handle_error(priv); + iwl3945_irq_handle_error(priv); handled |= CSR_INT_BIT_SW_ERR; } /* uCode wakes up after power-down sleep */ if (inta & CSR_INT_BIT_WAKEUP) { IWL_DEBUG_ISR("Wakeup interrupt\n"); - iwl_rx_queue_update_write_ptr(priv, &priv->rxq); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[0]); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[1]); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[2]); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[3]); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[4]); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[5]); + iwl3945_rx_queue_update_write_ptr(priv, &priv->rxq); + iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[0]); + iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[1]); + iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[2]); + iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[3]); + iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[4]); + iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[5]); handled |= CSR_INT_BIT_WAKEUP; } @@ -4783,19 +4811,19 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) * Rx "responses" (frame-received notification), and other * notifications from uCode come through here*/ if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { - iwl_rx_handle(priv); + iwl3945_rx_handle(priv); handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); } if (inta & CSR_INT_BIT_FH_TX) { IWL_DEBUG_ISR("Tx interrupt\n"); - iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); - if (!iwl_grab_restricted_access(priv)) { - iwl_write_restricted(priv, + iwl3945_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); + if (!iwl3945_grab_nic_access(priv)) { + iwl3945_write_direct32(priv, FH_TCSR_CREDIT (ALM_FH_SRVC_CHNL), 0x0); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); } handled |= CSR_INT_BIT_FH_TX; } @@ -4810,13 +4838,13 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) } /* Re-enable all interrupts */ - iwl_enable_interrupts(priv); + iwl3945_enable_interrupts(priv); -#ifdef CONFIG_IWLWIFI_DEBUG - if (iwl_debug_level & (IWL_DL_ISR)) { - inta = iwl_read32(priv, CSR_INT); - inta_mask = iwl_read32(priv, CSR_INT_MASK); - inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); +#ifdef CONFIG_IWL3945_DEBUG + if (iwl3945_debug_level & (IWL_DL_ISR)) { + inta = iwl3945_read32(priv, CSR_INT); + inta_mask = iwl3945_read32(priv, CSR_INT_MASK); + inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS); IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); } @@ -4824,9 +4852,9 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) spin_unlock_irqrestore(&priv->lock, flags); } -static irqreturn_t iwl_isr(int irq, void *data) +static irqreturn_t iwl3945_isr(int irq, void *data) { - struct iwl_priv *priv = data; + struct iwl3945_priv *priv = data; u32 inta, inta_mask; u32 inta_fh; if (!priv) @@ -4838,12 +4866,12 @@ static irqreturn_t iwl_isr(int irq, void *data) * back-to-back ISRs and sporadic interrupts from our NIC. * If we have something to service, the tasklet will re-enable ints. * If we *don't* have something, we'll re-enable before leaving here. */ - inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ - iwl_write32(priv, CSR_INT_MASK, 0x00000000); + inta_mask = iwl3945_read32(priv, CSR_INT_MASK); /* just for debug */ + iwl3945_write32(priv, CSR_INT_MASK, 0x00000000); /* Discover which interrupts are active/pending */ - inta = iwl_read32(priv, CSR_INT); - inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); + inta = iwl3945_read32(priv, CSR_INT); + inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS); /* Ignore interrupt if there's nothing in NIC to service. * This may be due to IRQ shared with another device, @@ -4862,7 +4890,7 @@ static irqreturn_t iwl_isr(int irq, void *data) IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", inta, inta_mask, inta_fh); - /* iwl_irq_tasklet() will service interrupts and re-enable them */ + /* iwl3945_irq_tasklet() will service interrupts and re-enable them */ tasklet_schedule(&priv->irq_tasklet); unplugged: spin_unlock(&priv->lock); @@ -4871,18 +4899,18 @@ unplugged: none: /* re-enable interrupts here since we don't have anything to service. */ - iwl_enable_interrupts(priv); + iwl3945_enable_interrupts(priv); spin_unlock(&priv->lock); return IRQ_NONE; } /************************** EEPROM BANDS **************************** * - * The iwl_eeprom_band definitions below provide the mapping from the + * The iwl3945_eeprom_band definitions below provide the mapping from the * EEPROM contents to the specific channel number supported for each * band. * - * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3 + * For example, iwl3945_priv->eeprom.band_3_channels[4] from the band_3 * definition below maps to physical channel 42 in the 5.2GHz spectrum. * The specific geography and calibration information for that channel * is contained in the eeprom map itself. @@ -4908,58 +4936,58 @@ unplugged: *********************************************************************/ /* 2.4 GHz */ -static const u8 iwl_eeprom_band_1[14] = { +static const u8 iwl3945_eeprom_band_1[14] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; /* 5.2 GHz bands */ -static const u8 iwl_eeprom_band_2[] = { +static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */ 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 }; -static const u8 iwl_eeprom_band_3[] = { /* 5205-5320MHz */ +static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */ 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 }; -static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */ +static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */ 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 }; -static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */ +static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */ 145, 149, 153, 157, 161, 165 }; -static void iwl_init_band_reference(const struct iwl_priv *priv, int band, +static void iwl3945_init_band_reference(const struct iwl3945_priv *priv, int band, int *eeprom_ch_count, - const struct iwl_eeprom_channel + const struct iwl3945_eeprom_channel **eeprom_ch_info, const u8 **eeprom_ch_index) { switch (band) { case 1: /* 2.4GHz band */ - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1); + *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1); *eeprom_ch_info = priv->eeprom.band_1_channels; - *eeprom_ch_index = iwl_eeprom_band_1; + *eeprom_ch_index = iwl3945_eeprom_band_1; break; - case 2: /* 5.2GHz band */ - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2); + case 2: /* 4.9GHz band */ + *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2); *eeprom_ch_info = priv->eeprom.band_2_channels; - *eeprom_ch_index = iwl_eeprom_band_2; + *eeprom_ch_index = iwl3945_eeprom_band_2; break; case 3: /* 5.2GHz band */ - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3); + *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3); *eeprom_ch_info = priv->eeprom.band_3_channels; - *eeprom_ch_index = iwl_eeprom_band_3; + *eeprom_ch_index = iwl3945_eeprom_band_3; break; - case 4: /* 5.2GHz band */ - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4); + case 4: /* 5.5GHz band */ + *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4); *eeprom_ch_info = priv->eeprom.band_4_channels; - *eeprom_ch_index = iwl_eeprom_band_4; + *eeprom_ch_index = iwl3945_eeprom_band_4; break; - case 5: /* 5.2GHz band */ - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5); + case 5: /* 5.7GHz band */ + *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5); *eeprom_ch_info = priv->eeprom.band_5_channels; - *eeprom_ch_index = iwl_eeprom_band_5; + *eeprom_ch_index = iwl3945_eeprom_band_5; break; default: BUG(); @@ -4967,7 +4995,12 @@ static void iwl_init_band_reference(const struct iwl_priv *priv, int band, } } -const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv, +/** + * iwl3945_get_channel_info - Find driver's private channel info + * + * Based on band and channel number. + */ +const struct iwl3945_channel_info *iwl3945_get_channel_info(const struct iwl3945_priv *priv, int phymode, u16 channel) { int i; @@ -4994,13 +5027,16 @@ const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv, #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ ? # x " " : "") -static int iwl_init_channel_map(struct iwl_priv *priv) +/** + * iwl3945_init_channel_map - Set up driver's info for all possible channels + */ +static int iwl3945_init_channel_map(struct iwl3945_priv *priv) { int eeprom_ch_count = 0; const u8 *eeprom_ch_index = NULL; - const struct iwl_eeprom_channel *eeprom_ch_info = NULL; + const struct iwl3945_eeprom_channel *eeprom_ch_info = NULL; int band, ch; - struct iwl_channel_info *ch_info; + struct iwl3945_channel_info *ch_info; if (priv->channel_count) { IWL_DEBUG_INFO("Channel map already initialized.\n"); @@ -5016,15 +5052,15 @@ static int iwl_init_channel_map(struct iwl_priv *priv) IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); priv->channel_count = - ARRAY_SIZE(iwl_eeprom_band_1) + - ARRAY_SIZE(iwl_eeprom_band_2) + - ARRAY_SIZE(iwl_eeprom_band_3) + - ARRAY_SIZE(iwl_eeprom_band_4) + - ARRAY_SIZE(iwl_eeprom_band_5); + ARRAY_SIZE(iwl3945_eeprom_band_1) + + ARRAY_SIZE(iwl3945_eeprom_band_2) + + ARRAY_SIZE(iwl3945_eeprom_band_3) + + ARRAY_SIZE(iwl3945_eeprom_band_4) + + ARRAY_SIZE(iwl3945_eeprom_band_5); IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); - priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) * + priv->channel_info = kzalloc(sizeof(struct iwl3945_channel_info) * priv->channel_count, GFP_KERNEL); if (!priv->channel_info) { IWL_ERROR("Could not allocate channel_info\n"); @@ -5039,7 +5075,7 @@ static int iwl_init_channel_map(struct iwl_priv *priv) * what just in the EEPROM) */ for (band = 1; band <= 5; band++) { - iwl_init_band_reference(priv, band, &eeprom_ch_count, + iwl3945_init_band_reference(priv, band, &eeprom_ch_count, &eeprom_ch_info, &eeprom_ch_index); /* Loop through each band adding each of the channels */ @@ -5103,6 +5139,7 @@ static int iwl_init_channel_map(struct iwl_priv *priv) } } + /* Set up txpower settings in driver for all channels */ if (iwl3945_txpower_set_from_eeprom(priv)) return -EIO; @@ -5132,7 +5169,7 @@ static int iwl_init_channel_map(struct iwl_priv *priv) #define IWL_PASSIVE_DWELL_BASE (100) #define IWL_CHANNEL_TUNE_TIME 5 -static inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv, int phymode) +static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv, int phymode) { if (phymode == MODE_IEEE80211A) return IWL_ACTIVE_DWELL_TIME_52; @@ -5140,14 +5177,14 @@ static inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv, int phymode) return IWL_ACTIVE_DWELL_TIME_24; } -static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv, int phymode) +static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv, int phymode) { - u16 active = iwl_get_active_dwell_time(priv, phymode); + u16 active = iwl3945_get_active_dwell_time(priv, phymode); u16 passive = (phymode != MODE_IEEE80211A) ? IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; - if (iwl_is_associated(priv)) { + if (iwl3945_is_associated(priv)) { /* If we're associated, we clamp the maximum passive * dwell time to be 98% of the beacon interval (minus * 2 * channel tune time) */ @@ -5163,30 +5200,30 @@ static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv, int phymode) return passive; } -static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, +static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, int phymode, u8 is_active, u8 direct_mask, - struct iwl_scan_channel *scan_ch) + struct iwl3945_scan_channel *scan_ch) { const struct ieee80211_channel *channels = NULL; const struct ieee80211_hw_mode *hw_mode; - const struct iwl_channel_info *ch_info; + const struct iwl3945_channel_info *ch_info; u16 passive_dwell = 0; u16 active_dwell = 0; int added, i; - hw_mode = iwl_get_hw_mode(priv, phymode); + hw_mode = iwl3945_get_hw_mode(priv, phymode); if (!hw_mode) return 0; channels = hw_mode->channels; - active_dwell = iwl_get_active_dwell_time(priv, phymode); - passive_dwell = iwl_get_passive_dwell_time(priv, phymode); + active_dwell = iwl3945_get_active_dwell_time(priv, phymode); + passive_dwell = iwl3945_get_passive_dwell_time(priv, phymode); for (i = 0, added = 0; i < hw_mode->num_channels; i++) { if (channels[i].chan == le16_to_cpu(priv->active_rxon.channel)) { - if (iwl_is_associated(priv)) { + if (iwl3945_is_associated(priv)) { IWL_DEBUG_SCAN ("Skipping current channel %d\n", le16_to_cpu(priv->active_rxon.channel)); @@ -5197,7 +5234,7 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, scan_ch->channel = channels[i].chan; - ch_info = iwl_get_channel_info(priv, phymode, scan_ch->channel); + ch_info = iwl3945_get_channel_info(priv, phymode, scan_ch->channel); if (!is_channel_valid(ch_info)) { IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", scan_ch->channel); @@ -5219,7 +5256,7 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, scan_ch->active_dwell = cpu_to_le16(active_dwell); scan_ch->passive_dwell = cpu_to_le16(passive_dwell); - /* Set power levels to defaults */ + /* Set txpower levels to defaults */ scan_ch->tpc.dsp_atten = 110; /* scan_pwr_info->tpc.dsp_atten; */ @@ -5229,8 +5266,8 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, else { scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); /* NOTE: if we were doing 6Mb OFDM for scans we'd use - * power level - scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3; + * power level: + * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; */ } @@ -5248,7 +5285,7 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, return added; } -static void iwl_reset_channel_flag(struct iwl_priv *priv) +static void iwl3945_reset_channel_flag(struct iwl3945_priv *priv) { int i, j; for (i = 0; i < 3; i++) { @@ -5258,13 +5295,13 @@ static void iwl_reset_channel_flag(struct iwl_priv *priv) } } -static void iwl_init_hw_rates(struct iwl_priv *priv, +static void iwl3945_init_hw_rates(struct iwl3945_priv *priv, struct ieee80211_rate *rates) { int i; for (i = 0; i < IWL_RATE_COUNT; i++) { - rates[i].rate = iwl_rates[i].ieee * 5; + rates[i].rate = iwl3945_rates[i].ieee * 5; rates[i].val = i; /* Rate scaling will work on indexes */ rates[i].val2 = i; rates[i].flags = IEEE80211_RATE_SUPPORTED; @@ -5276,7 +5313,7 @@ static void iwl_init_hw_rates(struct iwl_priv *priv, * If CCK 1M then set rate flag to CCK else CCK_2 * which is CCK | PREAMBLE2 */ - rates[i].flags |= (iwl_rates[i].plcp == 10) ? + rates[i].flags |= (iwl3945_rates[i].plcp == 10) ? IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2; } @@ -5287,11 +5324,11 @@ static void iwl_init_hw_rates(struct iwl_priv *priv, } /** - * iwl_init_geos - Initialize mac80211's geo/channel info based from eeprom + * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom */ -static int iwl_init_geos(struct iwl_priv *priv) +static int iwl3945_init_geos(struct iwl3945_priv *priv) { - struct iwl_channel_info *ch; + struct iwl3945_channel_info *ch; struct ieee80211_hw_mode *modes; struct ieee80211_channel *channels; struct ieee80211_channel *geo_ch; @@ -5337,7 +5374,7 @@ static int iwl_init_geos(struct iwl_priv *priv) /* 5.2GHz channels start after the 2.4GHz channels */ modes[A].mode = MODE_IEEE80211A; - modes[A].channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)]; + modes[A].channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)]; modes[A].rates = &rates[4]; modes[A].num_rates = 8; /* just OFDM */ modes[A].num_channels = 0; @@ -5357,7 +5394,7 @@ static int iwl_init_geos(struct iwl_priv *priv) priv->ieee_channels = channels; priv->ieee_rates = rates; - iwl_init_hw_rates(priv, rates); + iwl3945_init_hw_rates(priv, rates); for (i = 0, geo_ch = channels; i < priv->channel_count; i++) { ch = &priv->channel_info[i]; @@ -5440,57 +5477,21 @@ static int iwl_init_geos(struct iwl_priv *priv) * ******************************************************************************/ -static void iwl_dealloc_ucode_pci(struct iwl_priv *priv) +static void iwl3945_dealloc_ucode_pci(struct iwl3945_priv *priv) { - if (priv->ucode_code.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_code.len, - priv->ucode_code.v_addr, - priv->ucode_code.p_addr); - priv->ucode_code.v_addr = NULL; - } - if (priv->ucode_data.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_data.len, - priv->ucode_data.v_addr, - priv->ucode_data.p_addr); - priv->ucode_data.v_addr = NULL; - } - if (priv->ucode_data_backup.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_data_backup.len, - priv->ucode_data_backup.v_addr, - priv->ucode_data_backup.p_addr); - priv->ucode_data_backup.v_addr = NULL; - } - if (priv->ucode_init.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_init.len, - priv->ucode_init.v_addr, - priv->ucode_init.p_addr); - priv->ucode_init.v_addr = NULL; - } - if (priv->ucode_init_data.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_init_data.len, - priv->ucode_init_data.v_addr, - priv->ucode_init_data.p_addr); - priv->ucode_init_data.v_addr = NULL; - } - if (priv->ucode_boot.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_boot.len, - priv->ucode_boot.v_addr, - priv->ucode_boot.p_addr); - priv->ucode_boot.v_addr = NULL; - } + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); } /** - * iwl_verify_inst_full - verify runtime uCode image in card vs. host, + * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host, * looking at all data. */ -static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 * image, u32 len) +static int iwl3945_verify_inst_full(struct iwl3945_priv *priv, __le32 * image, u32 len) { u32 val; u32 save_len = len; @@ -5499,18 +5500,18 @@ static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 * image, u32 len) IWL_DEBUG_INFO("ucode inst image size is %u\n", len); - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) return rc; - iwl_write_restricted(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); + iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); errcnt = 0; for (; len > 0; len -= sizeof(u32), image++) { /* read data comes through single port, auto-incr addr */ /* NOTE: Use the debugless read so we don't flood kernel log * if IWL_DL_IO is set */ - val = _iwl_read_restricted(priv, HBUS_TARG_MEM_RDAT); + val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT); if (val != le32_to_cpu(*image)) { IWL_ERROR("uCode INST section is invalid at " "offset 0x%x, is 0x%x, s/b 0x%x\n", @@ -5522,22 +5523,21 @@ static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 * image, u32 len) } } - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); if (!errcnt) - IWL_DEBUG_INFO - ("ucode image in INSTRUCTION memory is good\n"); + IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n"); return rc; } /** - * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host, + * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host, * using sample data 100 bytes apart. If these sample points are good, * it's a pretty good bet that everything between them is good, too. */ -static int iwl_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) +static int iwl3945_verify_inst_sparse(struct iwl3945_priv *priv, __le32 *image, u32 len) { u32 val; int rc = 0; @@ -5546,7 +5546,7 @@ static int iwl_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) IWL_DEBUG_INFO("ucode inst image size is %u\n", len); - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) return rc; @@ -5554,9 +5554,9 @@ static int iwl_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) /* read data comes through single port, auto-incr addr */ /* NOTE: Use the debugless read so we don't flood kernel log * if IWL_DL_IO is set */ - iwl_write_restricted(priv, HBUS_TARG_MEM_RADDR, + iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, i + RTC_INST_LOWER_BOUND); - val = _iwl_read_restricted(priv, HBUS_TARG_MEM_RDAT); + val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT); if (val != le32_to_cpu(*image)) { #if 0 /* Enable this if you want to see details */ IWL_ERROR("uCode INST section is invalid at " @@ -5570,17 +5570,17 @@ static int iwl_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) } } - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); return rc; } /** - * iwl_verify_ucode - determine which instruction image is in SRAM, + * iwl3945_verify_ucode - determine which instruction image is in SRAM, * and verify its contents */ -static int iwl_verify_ucode(struct iwl_priv *priv) +static int iwl3945_verify_ucode(struct iwl3945_priv *priv) { __le32 *image; u32 len; @@ -5589,7 +5589,7 @@ static int iwl_verify_ucode(struct iwl_priv *priv) /* Try bootstrap */ image = (__le32 *)priv->ucode_boot.v_addr; len = priv->ucode_boot.len; - rc = iwl_verify_inst_sparse(priv, image, len); + rc = iwl3945_verify_inst_sparse(priv, image, len); if (rc == 0) { IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); return 0; @@ -5598,7 +5598,7 @@ static int iwl_verify_ucode(struct iwl_priv *priv) /* Try initialize */ image = (__le32 *)priv->ucode_init.v_addr; len = priv->ucode_init.len; - rc = iwl_verify_inst_sparse(priv, image, len); + rc = iwl3945_verify_inst_sparse(priv, image, len); if (rc == 0) { IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); return 0; @@ -5607,7 +5607,7 @@ static int iwl_verify_ucode(struct iwl_priv *priv) /* Try runtime/protocol */ image = (__le32 *)priv->ucode_code.v_addr; len = priv->ucode_code.len; - rc = iwl_verify_inst_sparse(priv, image, len); + rc = iwl3945_verify_inst_sparse(priv, image, len); if (rc == 0) { IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); return 0; @@ -5615,18 +5615,19 @@ static int iwl_verify_ucode(struct iwl_priv *priv) IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); - /* Show first several data entries in instruction SRAM. - * Selection of bootstrap image is arbitrary. */ + /* Since nothing seems to match, show first several data entries in + * instruction SRAM, so maybe visual inspection will give a clue. + * Selection of bootstrap image (vs. other images) is arbitrary. */ image = (__le32 *)priv->ucode_boot.v_addr; len = priv->ucode_boot.len; - rc = iwl_verify_inst_full(priv, image, len); + rc = iwl3945_verify_inst_full(priv, image, len); return rc; } /* check contents of special bootstrap uCode SRAM */ -static int iwl_verify_bsm(struct iwl_priv *priv) +static int iwl3945_verify_bsm(struct iwl3945_priv *priv) { __le32 *image = priv->ucode_boot.v_addr; u32 len = priv->ucode_boot.len; @@ -5636,11 +5637,11 @@ static int iwl_verify_bsm(struct iwl_priv *priv) IWL_DEBUG_INFO("Begin verify bsm\n"); /* verify BSM SRAM contents */ - val = iwl_read_restricted_reg(priv, BSM_WR_DWCOUNT_REG); + val = iwl3945_read_prph(priv, BSM_WR_DWCOUNT_REG); for (reg = BSM_SRAM_LOWER_BOUND; reg < BSM_SRAM_LOWER_BOUND + len; reg += sizeof(u32), image ++) { - val = iwl_read_restricted_reg(priv, reg); + val = iwl3945_read_prph(priv, reg); if (val != le32_to_cpu(*image)) { IWL_ERROR("BSM uCode verification failed at " "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", @@ -5657,7 +5658,7 @@ static int iwl_verify_bsm(struct iwl_priv *priv) } /** - * iwl_load_bsm - Load bootstrap instructions + * iwl3945_load_bsm - Load bootstrap instructions * * BSM operation: * @@ -5688,7 +5689,7 @@ static int iwl_verify_bsm(struct iwl_priv *priv) * the runtime uCode instructions and the backup data cache into SRAM, * and re-launches the runtime uCode from where it left off. */ -static int iwl_load_bsm(struct iwl_priv *priv) +static int iwl3945_load_bsm(struct iwl3945_priv *priv) { __le32 *image = priv->ucode_boot.v_addr; u32 len = priv->ucode_boot.len; @@ -5708,8 +5709,8 @@ static int iwl_load_bsm(struct iwl_priv *priv) return -EINVAL; /* Tell bootstrap uCode where to find the "Initialize" uCode - * in host DRAM ... bits 31:0 for 3945, bits 35:4 for 4965. - * NOTE: iwl_initialize_alive_start() will replace these values, + * in host DRAM ... host DRAM physical address bits 31:0 for 3945. + * NOTE: iwl3945_initialize_alive_start() will replace these values, * after the "initialize" uCode has run, to point to * runtime/protocol instructions and backup data cache. */ pinst = priv->ucode_init.p_addr; @@ -5717,42 +5718,42 @@ static int iwl_load_bsm(struct iwl_priv *priv) inst_len = priv->ucode_init.len; data_len = priv->ucode_init_data.len; - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) return rc; - iwl_write_restricted_reg(priv, BSM_DRAM_INST_PTR_REG, pinst); - iwl_write_restricted_reg(priv, BSM_DRAM_DATA_PTR_REG, pdata); - iwl_write_restricted_reg(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); - iwl_write_restricted_reg(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); + iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); + iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); + iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); + iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); /* Fill BSM memory with bootstrap instructions */ for (reg_offset = BSM_SRAM_LOWER_BOUND; reg_offset < BSM_SRAM_LOWER_BOUND + len; reg_offset += sizeof(u32), image++) - _iwl_write_restricted_reg(priv, reg_offset, + _iwl3945_write_prph(priv, reg_offset, le32_to_cpu(*image)); - rc = iwl_verify_bsm(priv); + rc = iwl3945_verify_bsm(priv); if (rc) { - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); return rc; } /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ - iwl_write_restricted_reg(priv, BSM_WR_MEM_SRC_REG, 0x0); - iwl_write_restricted_reg(priv, BSM_WR_MEM_DST_REG, + iwl3945_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); + iwl3945_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND); - iwl_write_restricted_reg(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); + iwl3945_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); /* Load bootstrap code into instruction SRAM now, * to prepare to load "initialize" uCode */ - iwl_write_restricted_reg(priv, BSM_WR_CTRL_REG, + iwl3945_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START); /* Wait for load of bootstrap uCode to finish */ for (i = 0; i < 100; i++) { - done = iwl_read_restricted_reg(priv, BSM_WR_CTRL_REG); + done = iwl3945_read_prph(priv, BSM_WR_CTRL_REG); if (!(done & BSM_WR_CTRL_REG_BIT_START)) break; udelay(10); @@ -5766,29 +5767,29 @@ static int iwl_load_bsm(struct iwl_priv *priv) /* Enable future boot loads whenever power management unit triggers it * (e.g. when powering back up after power-save shutdown) */ - iwl_write_restricted_reg(priv, BSM_WR_CTRL_REG, + iwl3945_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); return 0; } -static void iwl_nic_start(struct iwl_priv *priv) +static void iwl3945_nic_start(struct iwl3945_priv *priv) { /* Remove all resets to allow NIC to operate */ - iwl_write32(priv, CSR_RESET, 0); + iwl3945_write32(priv, CSR_RESET, 0); } /** - * iwl_read_ucode - Read uCode images from disk file. + * iwl3945_read_ucode - Read uCode images from disk file. * * Copy into buffers for card to fetch via bus-mastering */ -static int iwl_read_ucode(struct iwl_priv *priv) +static int iwl3945_read_ucode(struct iwl3945_priv *priv) { - struct iwl_ucode *ucode; - int rc = 0; + struct iwl3945_ucode *ucode; + int ret = 0; const struct firmware *ucode_raw; /* firmware file name contains uCode/driver compatibility version */ const char *name = "iwlwifi-3945" IWL3945_UCODE_API ".ucode"; @@ -5798,9 +5799,10 @@ static int iwl_read_ucode(struct iwl_priv *priv) /* Ask kernel firmware_class module to get the boot firmware off disk. * request_firmware() is synchronous, file is in memory on return. */ - rc = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); - if (rc < 0) { - IWL_ERROR("%s firmware file req failed: Reason %d\n", name, rc); + ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); + if (ret < 0) { + IWL_ERROR("%s firmware file req failed: Reason %d\n", + name, ret); goto error; } @@ -5810,7 +5812,7 @@ static int iwl_read_ucode(struct iwl_priv *priv) /* Make sure that we got at least our header! */ if (ucode_raw->size < sizeof(*ucode)) { IWL_ERROR("File size way too small!\n"); - rc = -EINVAL; + ret = -EINVAL; goto err_release; } @@ -5825,16 +5827,11 @@ static int iwl_read_ucode(struct iwl_priv *priv) boot_size = le32_to_cpu(ucode->boot_size); IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); - IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", - inst_size); - IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", - data_size); - IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", - init_size); - IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", - init_data_size); - IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", - boot_size); + IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size); + IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size); + IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size); + IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size); + IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size); /* Verify size of file vs. image size info in file's header */ if (ucode_raw->size < sizeof(*ucode) + @@ -5843,43 +5840,40 @@ static int iwl_read_ucode(struct iwl_priv *priv) IWL_DEBUG_INFO("uCode file size %d too small\n", (int)ucode_raw->size); - rc = -EINVAL; + ret = -EINVAL; goto err_release; } /* Verify that uCode images will fit in card's SRAM */ if (inst_size > IWL_MAX_INST_SIZE) { - IWL_DEBUG_INFO("uCode instr len %d too large to fit in card\n", - (int)inst_size); - rc = -EINVAL; + IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", + inst_size); + ret = -EINVAL; goto err_release; } if (data_size > IWL_MAX_DATA_SIZE) { - IWL_DEBUG_INFO("uCode data len %d too large to fit in card\n", - (int)data_size); - rc = -EINVAL; + IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", + data_size); + ret = -EINVAL; goto err_release; } if (init_size > IWL_MAX_INST_SIZE) { - IWL_DEBUG_INFO - ("uCode init instr len %d too large to fit in card\n", - (int)init_size); - rc = -EINVAL; + IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n", + init_size); + ret = -EINVAL; goto err_release; } if (init_data_size > IWL_MAX_DATA_SIZE) { - IWL_DEBUG_INFO - ("uCode init data len %d too large to fit in card\n", - (int)init_data_size); - rc = -EINVAL; + IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n", + init_data_size); + ret = -EINVAL; goto err_release; } if (boot_size > IWL_MAX_BSM_SIZE) { - IWL_DEBUG_INFO - ("uCode boot instr len %d too large to fit in bsm\n", - (int)boot_size); - rc = -EINVAL; + IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n", + boot_size); + ret = -EINVAL; goto err_release; } @@ -5889,66 +5883,54 @@ static int iwl_read_ucode(struct iwl_priv *priv) * 1) unmodified from disk * 2) backup cache for save/restore during power-downs */ priv->ucode_code.len = inst_size; - priv->ucode_code.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_code.len, - &(priv->ucode_code.p_addr)); + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); priv->ucode_data.len = data_size; - priv->ucode_data.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_data.len, - &(priv->ucode_data.p_addr)); + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); priv->ucode_data_backup.len = data_size; - priv->ucode_data_backup.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_data_backup.len, - &(priv->ucode_data_backup.p_addr)); + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); + if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || + !priv->ucode_data_backup.v_addr) + goto err_pci_alloc; /* Initialization instructions and data */ - priv->ucode_init.len = init_size; - priv->ucode_init.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_init.len, - &(priv->ucode_init.p_addr)); - - priv->ucode_init_data.len = init_data_size; - priv->ucode_init_data.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_init_data.len, - &(priv->ucode_init_data.p_addr)); + if (init_size && init_data_size) { + priv->ucode_init.len = init_size; + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); + + priv->ucode_init_data.len = init_data_size; + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); + + if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) + goto err_pci_alloc; + } /* Bootstrap (instructions only, no data) */ - priv->ucode_boot.len = boot_size; - priv->ucode_boot.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_boot.len, - &(priv->ucode_boot.p_addr)); + if (boot_size) { + priv->ucode_boot.len = boot_size; + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); - if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || - !priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr || - !priv->ucode_boot.v_addr || !priv->ucode_data_backup.v_addr) - goto err_pci_alloc; + if (!priv->ucode_boot.v_addr) + goto err_pci_alloc; + } /* Copy images into buffers for card's bus-master reads ... */ /* Runtime instructions (first block of data in file) */ src = &ucode->data[0]; len = priv->ucode_code.len; - IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %d\n", - (int)len); + IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len); memcpy(priv->ucode_code.v_addr, src, len); IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); /* Runtime data (2nd block) - * NOTE: Copy into backup buffer will be done in iwl_up() */ + * NOTE: Copy into backup buffer will be done in iwl3945_up() */ src = &ucode->data[inst_size]; len = priv->ucode_data.len; - IWL_DEBUG_INFO("Copying (but not loading) uCode data len %d\n", - (int)len); + IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len); memcpy(priv->ucode_data.v_addr, src, len); memcpy(priv->ucode_data_backup.v_addr, src, len); @@ -5956,8 +5938,8 @@ static int iwl_read_ucode(struct iwl_priv *priv) if (init_size) { src = &ucode->data[inst_size + data_size]; len = priv->ucode_init.len; - IWL_DEBUG_INFO("Copying (but not loading) init instr len %d\n", - (int)len); + IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", + len); memcpy(priv->ucode_init.v_addr, src, len); } @@ -5983,19 +5965,19 @@ static int iwl_read_ucode(struct iwl_priv *priv) err_pci_alloc: IWL_ERROR("failed to allocate pci memory\n"); - rc = -ENOMEM; - iwl_dealloc_ucode_pci(priv); + ret = -ENOMEM; + iwl3945_dealloc_ucode_pci(priv); err_release: release_firmware(ucode_raw); error: - return rc; + return ret; } /** - * iwl_set_ucode_ptrs - Set uCode address location + * iwl3945_set_ucode_ptrs - Set uCode address location * * Tell initialization uCode where to find runtime uCode. * @@ -6003,7 +5985,7 @@ static int iwl_read_ucode(struct iwl_priv *priv) * We need to replace them to load runtime uCode inst and data, * and to save runtime data when powering down. */ -static int iwl_set_ucode_ptrs(struct iwl_priv *priv) +static int iwl3945_set_ucode_ptrs(struct iwl3945_priv *priv) { dma_addr_t pinst; dma_addr_t pdata; @@ -6015,24 +5997,24 @@ static int iwl_set_ucode_ptrs(struct iwl_priv *priv) pdata = priv->ucode_data_backup.p_addr; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } /* Tell bootstrap uCode where to find image to load */ - iwl_write_restricted_reg(priv, BSM_DRAM_INST_PTR_REG, pinst); - iwl_write_restricted_reg(priv, BSM_DRAM_DATA_PTR_REG, pdata); - iwl_write_restricted_reg(priv, BSM_DRAM_DATA_BYTECOUNT_REG, + iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); + iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); + iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, priv->ucode_data.len); /* Inst bytecount must be last to set up, bit 31 signals uCode * that all new ptr/size info is in place */ - iwl_write_restricted_reg(priv, BSM_DRAM_INST_BYTECOUNT_REG, + iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, priv->ucode_code.len | BSM_DRAM_INST_LOAD); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); @@ -6042,17 +6024,13 @@ static int iwl_set_ucode_ptrs(struct iwl_priv *priv) } /** - * iwl_init_alive_start - Called after REPLY_ALIVE notification receieved + * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received * * Called after REPLY_ALIVE notification received from "initialize" uCode. * - * The 4965 "initialize" ALIVE reply contains calibration data for: - * Voltage, temperature, and MIMO tx gain correction, now stored in priv - * (3945 does not contain this data). - * * Tell "initialize" uCode to go ahead and load the runtime uCode. -*/ -static void iwl_init_alive_start(struct iwl_priv *priv) + */ +static void iwl3945_init_alive_start(struct iwl3945_priv *priv) { /* Check alive response for "valid" sign from uCode */ if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { @@ -6065,7 +6043,7 @@ static void iwl_init_alive_start(struct iwl_priv *priv) /* Bootstrap uCode has loaded initialize uCode ... verify inst image. * This is a paranoid check, because we would not have gotten the * "initialize" alive if code weren't properly loaded. */ - if (iwl_verify_ucode(priv)) { + if (iwl3945_verify_ucode(priv)) { /* Runtime instruction load was bad; * take it all the way back down so we can try again */ IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); @@ -6076,7 +6054,7 @@ static void iwl_init_alive_start(struct iwl_priv *priv) * load and launch runtime uCode, which will send us another "Alive" * notification. */ IWL_DEBUG_INFO("Initialization Alive received.\n"); - if (iwl_set_ucode_ptrs(priv)) { + if (iwl3945_set_ucode_ptrs(priv)) { /* Runtime instruction load won't happen; * take it all the way back down so we can try again */ IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); @@ -6090,11 +6068,11 @@ static void iwl_init_alive_start(struct iwl_priv *priv) /** - * iwl_alive_start - called after REPLY_ALIVE notification received + * iwl3945_alive_start - called after REPLY_ALIVE notification received * from protocol/runtime uCode (initialization uCode's - * Alive gets handled by iwl_init_alive_start()). + * Alive gets handled by iwl3945_init_alive_start()). */ -static void iwl_alive_start(struct iwl_priv *priv) +static void iwl3945_alive_start(struct iwl3945_priv *priv) { int rc = 0; int thermal_spin = 0; @@ -6112,30 +6090,30 @@ static void iwl_alive_start(struct iwl_priv *priv) /* Initialize uCode has loaded Runtime uCode ... verify inst image. * This is a paranoid check, because we would not have gotten the * "runtime" alive if code weren't properly loaded. */ - if (iwl_verify_ucode(priv)) { + if (iwl3945_verify_ucode(priv)) { /* Runtime instruction load was bad; * take it all the way back down so we can try again */ IWL_DEBUG_INFO("Bad runtime uCode load.\n"); goto restart; } - iwl_clear_stations_table(priv); + iwl3945_clear_stations_table(priv); - rc = iwl_grab_restricted_access(priv); + rc = iwl3945_grab_nic_access(priv); if (rc) { IWL_WARNING("Can not read rfkill status from adapter\n"); return; } - rfkill = iwl_read_restricted_reg(priv, APMG_RFKILL_REG); + rfkill = iwl3945_read_prph(priv, APMG_RFKILL_REG); IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); if (rfkill & 0x1) { clear_bit(STATUS_RF_KILL_HW, &priv->status); /* if rfkill is not on, then wait for thermal * sensor in adapter to kick in */ - while (iwl_hw_get_temperature(priv) == 0) { + while (iwl3945_hw_get_temperature(priv) == 0) { thermal_spin++; udelay(10); } @@ -6146,68 +6124,49 @@ static void iwl_alive_start(struct iwl_priv *priv) } else set_bit(STATUS_RF_KILL_HW, &priv->status); - /* After the ALIVE response, we can process host commands */ + /* After the ALIVE response, we can send commands to 3945 uCode */ set_bit(STATUS_ALIVE, &priv->status); /* Clear out the uCode error bit if it is set */ clear_bit(STATUS_FW_ERROR, &priv->status); - rc = iwl_init_channel_map(priv); + rc = iwl3945_init_channel_map(priv); if (rc) { IWL_ERROR("initializing regulatory failed: %d\n", rc); return; } - iwl_init_geos(priv); + iwl3945_init_geos(priv); + iwl3945_reset_channel_flag(priv); - if (iwl_is_rfkill(priv)) + if (iwl3945_is_rfkill(priv)) return; - if (!priv->mac80211_registered) { - /* Unlock so any user space entry points can call back into - * the driver without a deadlock... */ - mutex_unlock(&priv->mutex); - iwl_rate_control_register(priv->hw); - rc = ieee80211_register_hw(priv->hw); - priv->hw->conf.beacon_int = 100; - mutex_lock(&priv->mutex); - - if (rc) { - iwl_rate_control_unregister(priv->hw); - IWL_ERROR("Failed to register network " - "device (error %d)\n", rc); - return; - } - - priv->mac80211_registered = 1; - - iwl_reset_channel_flag(priv); - } else - ieee80211_start_queues(priv->hw); + ieee80211_start_queues(priv->hw); priv->active_rate = priv->rates_mask; priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; - iwl_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); + iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); - if (iwl_is_associated(priv)) { - struct iwl_rxon_cmd *active_rxon = - (struct iwl_rxon_cmd *)(&priv->active_rxon); + if (iwl3945_is_associated(priv)) { + struct iwl3945_rxon_cmd *active_rxon = + (struct iwl3945_rxon_cmd *)(&priv->active_rxon); memcpy(&priv->staging_rxon, &priv->active_rxon, sizeof(priv->staging_rxon)); active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; } else { /* Initialize our rx_config data */ - iwl_connection_init_rx_config(priv); + iwl3945_connection_init_rx_config(priv); memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); } - /* Configure BT coexistence */ - iwl_send_bt_config(priv); + /* Configure Bluetooth device coexistence support */ + iwl3945_send_bt_config(priv); /* Configure the adapter for unassociated operation */ - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); /* At this point, the NIC is initialized and operational */ priv->notif_missed_beacons = 0; @@ -6216,9 +6175,10 @@ static void iwl_alive_start(struct iwl_priv *priv) iwl3945_reg_txpower_periodic(priv); IWL_DEBUG_INFO("ALIVE processing complete.\n"); + wake_up_interruptible(&priv->wait_command_queue); if (priv->error_recovering) - iwl_error_recovery(priv); + iwl3945_error_recovery(priv); return; @@ -6226,9 +6186,9 @@ static void iwl_alive_start(struct iwl_priv *priv) queue_work(priv->workqueue, &priv->restart); } -static void iwl_cancel_deferred_work(struct iwl_priv *priv); +static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv); -static void __iwl_down(struct iwl_priv *priv) +static void __iwl3945_down(struct iwl3945_priv *priv) { unsigned long flags; int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); @@ -6241,7 +6201,7 @@ static void __iwl_down(struct iwl_priv *priv) if (!exit_pending) set_bit(STATUS_EXIT_PENDING, &priv->status); - iwl_clear_stations_table(priv); + iwl3945_clear_stations_table(priv); /* Unblock any waiting calls */ wake_up_interruptible_all(&priv->wait_command_queue); @@ -6252,17 +6212,17 @@ static void __iwl_down(struct iwl_priv *priv) clear_bit(STATUS_EXIT_PENDING, &priv->status); /* stop and reset the on-board processor */ - iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); + iwl3945_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); /* tell the device to stop sending interrupts */ - iwl_disable_interrupts(priv); + iwl3945_disable_interrupts(priv); if (priv->mac80211_registered) ieee80211_stop_queues(priv->hw); - /* If we have not previously called iwl_init() then + /* If we have not previously called iwl3945_init() then * clear all bits but the RF Kill and SUSPEND bits and return */ - if (!iwl_is_init(priv)) { + if (!iwl3945_is_init(priv)) { priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << STATUS_RF_KILL_HW | test_bit(STATUS_RF_KILL_SW, &priv->status) << @@ -6284,51 +6244,50 @@ static void __iwl_down(struct iwl_priv *priv) STATUS_FW_ERROR; spin_lock_irqsave(&priv->lock, flags); - iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); spin_unlock_irqrestore(&priv->lock, flags); - iwl_hw_txq_ctx_stop(priv); - iwl_hw_rxq_stop(priv); + iwl3945_hw_txq_ctx_stop(priv); + iwl3945_hw_rxq_stop(priv); spin_lock_irqsave(&priv->lock, flags); - if (!iwl_grab_restricted_access(priv)) { - iwl_write_restricted_reg(priv, APMG_CLK_DIS_REG, + if (!iwl3945_grab_nic_access(priv)) { + iwl3945_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT); - iwl_release_restricted_access(priv); + iwl3945_release_nic_access(priv); } spin_unlock_irqrestore(&priv->lock, flags); udelay(5); - iwl_hw_nic_stop_master(priv); - iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); - iwl_hw_nic_reset(priv); + iwl3945_hw_nic_stop_master(priv); + iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); + iwl3945_hw_nic_reset(priv); exit: - memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); + memset(&priv->card_alive, 0, sizeof(struct iwl3945_alive_resp)); if (priv->ibss_beacon) dev_kfree_skb(priv->ibss_beacon); priv->ibss_beacon = NULL; /* clear out any free frames */ - iwl_clear_free_frames(priv); + iwl3945_clear_free_frames(priv); } -static void iwl_down(struct iwl_priv *priv) +static void iwl3945_down(struct iwl3945_priv *priv) { mutex_lock(&priv->mutex); - __iwl_down(priv); + __iwl3945_down(priv); mutex_unlock(&priv->mutex); - iwl_cancel_deferred_work(priv); + iwl3945_cancel_deferred_work(priv); } #define MAX_HW_RESTARTS 5 -static int __iwl_up(struct iwl_priv *priv) +static int __iwl3945_up(struct iwl3945_priv *priv) { - DECLARE_MAC_BUF(mac); int rc, i; if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { @@ -6339,44 +6298,65 @@ static int __iwl_up(struct iwl_priv *priv) if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { IWL_WARNING("Radio disabled by SW RF kill (module " "parameter)\n"); - return 0; + return -ENODEV; } - iwl_write32(priv, CSR_INT, 0xFFFFFFFF); + /* If platform's RF_KILL switch is NOT set to KILL */ + if (iwl3945_read32(priv, CSR_GP_CNTRL) & + CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) + clear_bit(STATUS_RF_KILL_HW, &priv->status); + else { + set_bit(STATUS_RF_KILL_HW, &priv->status); + if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { + IWL_WARNING("Radio disabled by HW RF Kill switch\n"); + return -ENODEV; + } + } - rc = iwl_hw_nic_init(priv); + if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { + IWL_ERROR("ucode not available for device bringup\n"); + return -EIO; + } + + iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF); + + rc = iwl3945_hw_nic_init(priv); if (rc) { IWL_ERROR("Unable to int nic\n"); return rc; } /* make sure rfkill handshake bits are cleared */ - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, + iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); /* clear (again), then enable host interrupts */ - iwl_write32(priv, CSR_INT, 0xFFFFFFFF); - iwl_enable_interrupts(priv); + iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF); + iwl3945_enable_interrupts(priv); /* really make sure rfkill handshake bits are cleared */ - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); /* Copy original ucode data image from disk into backup cache. * This will be used to initialize the on-board processor's * data SRAM for a clean start when the runtime program first loads. */ memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, - priv->ucode_data.len); + priv->ucode_data.len); + + /* We return success when we resume from suspend and rf_kill is on. */ + if (test_bit(STATUS_RF_KILL_HW, &priv->status)) + return 0; for (i = 0; i < MAX_HW_RESTARTS; i++) { - iwl_clear_stations_table(priv); + iwl3945_clear_stations_table(priv); /* load bootstrap state machine, * load bootstrap program into processor's memory, * prepare to load the "initialize" uCode */ - rc = iwl_load_bsm(priv); + rc = iwl3945_load_bsm(priv); if (rc) { IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc); @@ -6384,14 +6364,7 @@ static int __iwl_up(struct iwl_priv *priv) } /* start card; "initialize" will load runtime ucode */ - iwl_nic_start(priv); - - /* MAC Address location in EEPROM same for 3945/4965 */ - get_eeprom_mac(priv, priv->mac_addr); - IWL_DEBUG_INFO("MAC address: %s\n", - print_mac(mac, priv->mac_addr)); - - SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); + iwl3945_nic_start(priv); IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); @@ -6399,7 +6372,7 @@ static int __iwl_up(struct iwl_priv *priv) } set_bit(STATUS_EXIT_PENDING, &priv->status); - __iwl_down(priv); + __iwl3945_down(priv); /* tried to restart and config the device for as long as our * patience could withstand */ @@ -6414,35 +6387,35 @@ static int __iwl_up(struct iwl_priv *priv) * *****************************************************************************/ -static void iwl_bg_init_alive_start(struct work_struct *data) +static void iwl3945_bg_init_alive_start(struct work_struct *data) { - struct iwl_priv *priv = - container_of(data, struct iwl_priv, init_alive_start.work); + struct iwl3945_priv *priv = + container_of(data, struct iwl3945_priv, init_alive_start.work); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; mutex_lock(&priv->mutex); - iwl_init_alive_start(priv); + iwl3945_init_alive_start(priv); mutex_unlock(&priv->mutex); } -static void iwl_bg_alive_start(struct work_struct *data) +static void iwl3945_bg_alive_start(struct work_struct *data) { - struct iwl_priv *priv = - container_of(data, struct iwl_priv, alive_start.work); + struct iwl3945_priv *priv = + container_of(data, struct iwl3945_priv, alive_start.work); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; mutex_lock(&priv->mutex); - iwl_alive_start(priv); + iwl3945_alive_start(priv); mutex_unlock(&priv->mutex); } -static void iwl_bg_rf_kill(struct work_struct *work) +static void iwl3945_bg_rf_kill(struct work_struct *work) { - struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); + struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, rf_kill); wake_up_interruptible(&priv->wait_command_queue); @@ -6451,7 +6424,7 @@ static void iwl_bg_rf_kill(struct work_struct *work) mutex_lock(&priv->mutex); - if (!iwl_is_rfkill(priv)) { + if (!iwl3945_is_rfkill(priv)) { IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, "HW and/or SW RF Kill no longer active, restarting " "device\n"); @@ -6472,10 +6445,10 @@ static void iwl_bg_rf_kill(struct work_struct *work) #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) -static void iwl_bg_scan_check(struct work_struct *data) +static void iwl3945_bg_scan_check(struct work_struct *data) { - struct iwl_priv *priv = - container_of(data, struct iwl_priv, scan_check.work); + struct iwl3945_priv *priv = + container_of(data, struct iwl3945_priv, scan_check.work); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; @@ -6488,22 +6461,22 @@ static void iwl_bg_scan_check(struct work_struct *data) jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) - iwl_send_scan_abort(priv); + iwl3945_send_scan_abort(priv); } mutex_unlock(&priv->mutex); } -static void iwl_bg_request_scan(struct work_struct *data) +static void iwl3945_bg_request_scan(struct work_struct *data) { - struct iwl_priv *priv = - container_of(data, struct iwl_priv, request_scan); - struct iwl_host_cmd cmd = { + struct iwl3945_priv *priv = + container_of(data, struct iwl3945_priv, request_scan); + struct iwl3945_host_cmd cmd = { .id = REPLY_SCAN_CMD, - .len = sizeof(struct iwl_scan_cmd), + .len = sizeof(struct iwl3945_scan_cmd), .meta.flags = CMD_SIZE_HUGE, }; int rc = 0; - struct iwl_scan_cmd *scan; + struct iwl3945_scan_cmd *scan; struct ieee80211_conf *conf = NULL; u8 direct_mask; int phymode; @@ -6512,7 +6485,7 @@ static void iwl_bg_request_scan(struct work_struct *data) mutex_lock(&priv->mutex); - if (!iwl_is_ready(priv)) { + if (!iwl3945_is_ready(priv)) { IWL_WARNING("request scan called when driver not ready.\n"); goto done; } @@ -6541,7 +6514,7 @@ static void iwl_bg_request_scan(struct work_struct *data) goto done; } - if (iwl_is_rfkill(priv)) { + if (iwl3945_is_rfkill(priv)) { IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); goto done; } @@ -6557,7 +6530,7 @@ static void iwl_bg_request_scan(struct work_struct *data) } if (!priv->scan) { - priv->scan = kmalloc(sizeof(struct iwl_scan_cmd) + + priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE, GFP_KERNEL); if (!priv->scan) { rc = -ENOMEM; @@ -6565,12 +6538,12 @@ static void iwl_bg_request_scan(struct work_struct *data) } } scan = priv->scan; - memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE); + memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE); scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; scan->quiet_time = IWL_ACTIVE_QUIET_TIME; - if (iwl_is_associated(priv)) { + if (iwl3945_is_associated(priv)) { u16 interval = 0; u32 extra; u32 suspend_time = 100; @@ -6607,14 +6580,14 @@ static void iwl_bg_request_scan(struct work_struct *data) if (priv->one_direct_scan) { IWL_DEBUG_SCAN ("Kicking off one direct scan for '%s'\n", - iwl_escape_essid(priv->direct_ssid, + iwl3945_escape_essid(priv->direct_ssid, priv->direct_ssid_len)); scan->direct_scan[0].id = WLAN_EID_SSID; scan->direct_scan[0].len = priv->direct_ssid_len; memcpy(scan->direct_scan[0].ssid, priv->direct_ssid, priv->direct_ssid_len); direct_mask = 1; - } else if (!iwl_is_associated(priv) && priv->essid_len) { + } else if (!iwl3945_is_associated(priv) && priv->essid_len) { scan->direct_scan[0].id = WLAN_EID_SSID; scan->direct_scan[0].len = priv->essid_len; memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); @@ -6625,7 +6598,7 @@ static void iwl_bg_request_scan(struct work_struct *data) /* We don't build a direct scan probe request; the uCode will do * that based on the direct_mask added to each channel entry */ scan->tx_cmd.len = cpu_to_le16( - iwl_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, + iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, IWL_MAX_SCAN_SIZE - sizeof(scan), 0)); scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; @@ -6661,23 +6634,23 @@ static void iwl_bg_request_scan(struct work_struct *data) if (direct_mask) IWL_DEBUG_SCAN ("Initiating direct scan for %s.\n", - iwl_escape_essid(priv->essid, priv->essid_len)); + iwl3945_escape_essid(priv->essid, priv->essid_len)); else IWL_DEBUG_SCAN("Initiating indirect scan.\n"); scan->channel_count = - iwl_get_channels_for_scan( + iwl3945_get_channels_for_scan( priv, phymode, 1, /* active */ direct_mask, (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); cmd.len += le16_to_cpu(scan->tx_cmd.len) + - scan->channel_count * sizeof(struct iwl_scan_channel); + scan->channel_count * sizeof(struct iwl3945_scan_channel); cmd.data = scan; scan->len = cpu_to_le16(cmd.len); set_bit(STATUS_SCAN_HW, &priv->status); - rc = iwl_send_cmd_sync(priv, &cmd); + rc = iwl3945_send_cmd_sync(priv, &cmd); if (rc) goto done; @@ -6688,50 +6661,52 @@ static void iwl_bg_request_scan(struct work_struct *data) return; done: - /* inform mac80211 sacn aborted */ + /* inform mac80211 scan aborted */ queue_work(priv->workqueue, &priv->scan_completed); mutex_unlock(&priv->mutex); } -static void iwl_bg_up(struct work_struct *data) +static void iwl3945_bg_up(struct work_struct *data) { - struct iwl_priv *priv = container_of(data, struct iwl_priv, up); + struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, up); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; mutex_lock(&priv->mutex); - __iwl_up(priv); + __iwl3945_up(priv); mutex_unlock(&priv->mutex); } -static void iwl_bg_restart(struct work_struct *data) +static void iwl3945_bg_restart(struct work_struct *data) { - struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); + struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, restart); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; - iwl_down(priv); + iwl3945_down(priv); queue_work(priv->workqueue, &priv->up); } -static void iwl_bg_rx_replenish(struct work_struct *data) +static void iwl3945_bg_rx_replenish(struct work_struct *data) { - struct iwl_priv *priv = - container_of(data, struct iwl_priv, rx_replenish); + struct iwl3945_priv *priv = + container_of(data, struct iwl3945_priv, rx_replenish); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; mutex_lock(&priv->mutex); - iwl_rx_replenish(priv); + iwl3945_rx_replenish(priv); mutex_unlock(&priv->mutex); } -static void iwl_bg_post_associate(struct work_struct *data) +#define IWL_DELAY_NEXT_SCAN (HZ*2) + +static void iwl3945_bg_post_associate(struct work_struct *data) { - struct iwl_priv *priv = container_of(data, struct iwl_priv, + struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, post_associate.work); int rc = 0; @@ -6753,20 +6728,20 @@ static void iwl_bg_post_associate(struct work_struct *data) mutex_lock(&priv->mutex); - if (!priv->interface_id || !priv->is_open) { + if (!priv->vif || !priv->is_open) { mutex_unlock(&priv->mutex); return; } - iwl_scan_cancel_timeout(priv, 200); + iwl3945_scan_cancel_timeout(priv, 200); conf = ieee80211_get_hw_conf(priv->hw); priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); - memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); - iwl_setup_rxon_timing(priv); - rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, + memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd)); + iwl3945_setup_rxon_timing(priv); + rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, sizeof(priv->rxon_timing), &priv->rxon_timing); if (rc) IWL_WARNING("REPLY_RXON_TIMING failed - " @@ -6795,75 +6770,81 @@ static void iwl_bg_post_associate(struct work_struct *data) } - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); switch (priv->iw_mode) { case IEEE80211_IF_TYPE_STA: - iwl_rate_scale_init(priv->hw, IWL_AP_ID); + iwl3945_rate_scale_init(priv->hw, IWL_AP_ID); break; case IEEE80211_IF_TYPE_IBSS: /* clear out the station table */ - iwl_clear_stations_table(priv); + iwl3945_clear_stations_table(priv); - iwl_add_station(priv, BROADCAST_ADDR, 0, 0); - iwl_add_station(priv, priv->bssid, 0, 0); + iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0); + iwl3945_add_station(priv, priv->bssid, 0, 0); iwl3945_sync_sta(priv, IWL_STA_ID, (priv->phymode == MODE_IEEE80211A)? IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, CMD_ASYNC); - iwl_rate_scale_init(priv->hw, IWL_STA_ID); - iwl_send_beacon_cmd(priv); + iwl3945_rate_scale_init(priv->hw, IWL_STA_ID); + iwl3945_send_beacon_cmd(priv); break; default: IWL_ERROR("%s Should not be called in %d mode\n", - __FUNCTION__, priv->iw_mode); + __FUNCTION__, priv->iw_mode); break; } - iwl_sequence_reset(priv); + iwl3945_sequence_reset(priv); -#ifdef CONFIG_IWLWIFI_QOS - iwl_activate_qos(priv, 0); -#endif /* CONFIG_IWLWIFI_QOS */ +#ifdef CONFIG_IWL3945_QOS + iwl3945_activate_qos(priv, 0); +#endif /* CONFIG_IWL3945_QOS */ + /* we have just associated, don't start scan too early */ + priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; mutex_unlock(&priv->mutex); } -static void iwl_bg_abort_scan(struct work_struct *work) +static void iwl3945_bg_abort_scan(struct work_struct *work) { - struct iwl_priv *priv = container_of(work, struct iwl_priv, - abort_scan); + struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, abort_scan); - if (!iwl_is_ready(priv)) + if (!iwl3945_is_ready(priv)) return; mutex_lock(&priv->mutex); set_bit(STATUS_SCAN_ABORTING, &priv->status); - iwl_send_scan_abort(priv); + iwl3945_send_scan_abort(priv); mutex_unlock(&priv->mutex); } -static void iwl_bg_scan_completed(struct work_struct *work) +static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); + +static void iwl3945_bg_scan_completed(struct work_struct *work) { - struct iwl_priv *priv = - container_of(work, struct iwl_priv, scan_completed); + struct iwl3945_priv *priv = + container_of(work, struct iwl3945_priv, scan_completed); IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; + if (test_bit(STATUS_CONF_PENDING, &priv->status)) + iwl3945_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); + ieee80211_scan_completed(priv->hw); /* Since setting the TXPOWER may have been deferred while * performing the scan, fire one off */ mutex_lock(&priv->mutex); - iwl_hw_reg_send_txpower(priv); + iwl3945_hw_reg_send_txpower(priv); mutex_unlock(&priv->mutex); } @@ -6873,50 +6854,123 @@ static void iwl_bg_scan_completed(struct work_struct *work) * *****************************************************************************/ -static int iwl_mac_start(struct ieee80211_hw *hw) +#define UCODE_READY_TIMEOUT (2 * HZ) + +static int iwl3945_mac_start(struct ieee80211_hw *hw) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; + int ret; IWL_DEBUG_MAC80211("enter\n"); + if (pci_enable_device(priv->pci_dev)) { + IWL_ERROR("Fail to pci_enable_device\n"); + return -ENODEV; + } + pci_restore_state(priv->pci_dev); + pci_enable_msi(priv->pci_dev); + + ret = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED, + DRV_NAME, priv); + if (ret) { + IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); + goto out_disable_msi; + } + /* we should be verifying the device is ready to be opened */ mutex_lock(&priv->mutex); - priv->is_open = 1; + memset(&priv->staging_rxon, 0, sizeof(struct iwl3945_rxon_cmd)); + /* fetch ucode file from disk, alloc and copy to bus-master buffers ... + * ucode filename and max sizes are card-specific. */ - if (!iwl_is_rfkill(priv)) - ieee80211_start_queues(priv->hw); + if (!priv->ucode_code.len) { + ret = iwl3945_read_ucode(priv); + if (ret) { + IWL_ERROR("Could not read microcode: %d\n", ret); + mutex_unlock(&priv->mutex); + goto out_release_irq; + } + } + + ret = __iwl3945_up(priv); mutex_unlock(&priv->mutex); + + if (ret) + goto out_release_irq; + + IWL_DEBUG_INFO("Start UP work.\n"); + + if (test_bit(STATUS_IN_SUSPEND, &priv->status)) + return 0; + + /* Wait for START_ALIVE from ucode. Otherwise callbacks from + * mac80211 will not be run successfully. */ + ret = wait_event_interruptible_timeout(priv->wait_command_queue, + test_bit(STATUS_READY, &priv->status), + UCODE_READY_TIMEOUT); + if (!ret) { + if (!test_bit(STATUS_READY, &priv->status)) { + IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", + jiffies_to_msecs(UCODE_READY_TIMEOUT)); + ret = -ETIMEDOUT; + goto out_release_irq; + } + } + + priv->is_open = 1; IWL_DEBUG_MAC80211("leave\n"); return 0; + +out_release_irq: + free_irq(priv->pci_dev->irq, priv); +out_disable_msi: + pci_disable_msi(priv->pci_dev); + pci_disable_device(priv->pci_dev); + priv->is_open = 0; + IWL_DEBUG_MAC80211("leave - failed\n"); + return ret; } -static void iwl_mac_stop(struct ieee80211_hw *hw) +static void iwl3945_mac_stop(struct ieee80211_hw *hw) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; IWL_DEBUG_MAC80211("enter\n"); + if (!priv->is_open) { + IWL_DEBUG_MAC80211("leave - skip\n"); + return; + } - mutex_lock(&priv->mutex); - /* stop mac, cancel any scan request and clear - * RXON_FILTER_ASSOC_MSK BIT - */ priv->is_open = 0; - iwl_scan_cancel_timeout(priv, 100); - cancel_delayed_work(&priv->post_associate); - priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); - mutex_unlock(&priv->mutex); + + if (iwl3945_is_ready_rf(priv)) { + /* stop mac, cancel any scan request and clear + * RXON_FILTER_ASSOC_MSK BIT + */ + mutex_lock(&priv->mutex); + iwl3945_scan_cancel_timeout(priv, 100); + cancel_delayed_work(&priv->post_associate); + mutex_unlock(&priv->mutex); + } + + iwl3945_down(priv); + + flush_workqueue(priv->workqueue); + free_irq(priv->pci_dev->irq, priv); + pci_disable_msi(priv->pci_dev); + pci_save_state(priv->pci_dev); + pci_disable_device(priv->pci_dev); IWL_DEBUG_MAC80211("leave\n"); } -static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, +static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, struct ieee80211_tx_control *ctl) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; IWL_DEBUG_MAC80211("enter\n"); @@ -6928,29 +6982,29 @@ static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, ctl->tx_rate); - if (iwl_tx_skb(priv, skb, ctl)) + if (iwl3945_tx_skb(priv, skb, ctl)) dev_kfree_skb_any(skb); IWL_DEBUG_MAC80211("leave\n"); return 0; } -static int iwl_mac_add_interface(struct ieee80211_hw *hw, +static int iwl3945_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_if_init_conf *conf) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; unsigned long flags; DECLARE_MAC_BUF(mac); - IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type); + IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); - if (priv->interface_id) { - IWL_DEBUG_MAC80211("leave - interface_id != 0\n"); + if (priv->vif) { + IWL_DEBUG_MAC80211("leave - vif != NULL\n"); return -EOPNOTSUPP; } spin_lock_irqsave(&priv->lock, flags); - priv->interface_id = conf->if_id; + priv->vif = conf->vif; spin_unlock_irqrestore(&priv->lock, flags); @@ -6961,106 +7015,108 @@ static int iwl_mac_add_interface(struct ieee80211_hw *hw, memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); } - iwl_set_mode(priv, conf->type); + if (iwl3945_is_ready(priv)) + iwl3945_set_mode(priv, conf->type); - IWL_DEBUG_MAC80211("leave\n"); mutex_unlock(&priv->mutex); + IWL_DEBUG_MAC80211("leave\n"); return 0; } /** - * iwl_mac_config - mac80211 config callback + * iwl3945_mac_config - mac80211 config callback * * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to * be set inappropriately and the driver currently sets the hardware up to * use it whenever needed. */ -static int iwl_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) +static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) { - struct iwl_priv *priv = hw->priv; - const struct iwl_channel_info *ch_info; + struct iwl3945_priv *priv = hw->priv; + const struct iwl3945_channel_info *ch_info; unsigned long flags; + int ret = 0; mutex_lock(&priv->mutex); IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel); - if (!iwl_is_ready(priv)) { + priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); + + if (!iwl3945_is_ready(priv)) { IWL_DEBUG_MAC80211("leave - not ready\n"); - mutex_unlock(&priv->mutex); - return -EIO; + ret = -EIO; + goto out; } - /* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only - * what is exposed through include/ declrations */ - if (unlikely(!iwl_param_disable_hw_scan && + if (unlikely(!iwl3945_param_disable_hw_scan && test_bit(STATUS_SCANNING, &priv->status))) { IWL_DEBUG_MAC80211("leave - scanning\n"); + set_bit(STATUS_CONF_PENDING, &priv->status); mutex_unlock(&priv->mutex); return 0; } spin_lock_irqsave(&priv->lock, flags); - ch_info = iwl_get_channel_info(priv, conf->phymode, conf->channel); + ch_info = iwl3945_get_channel_info(priv, conf->phymode, conf->channel); if (!is_channel_valid(ch_info)) { IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n", conf->channel, conf->phymode); IWL_DEBUG_MAC80211("leave - invalid channel\n"); spin_unlock_irqrestore(&priv->lock, flags); - mutex_unlock(&priv->mutex); - return -EINVAL; + ret = -EINVAL; + goto out; } - iwl_set_rxon_channel(priv, conf->phymode, conf->channel); + iwl3945_set_rxon_channel(priv, conf->phymode, conf->channel); - iwl_set_flags_for_phymode(priv, conf->phymode); + iwl3945_set_flags_for_phymode(priv, conf->phymode); /* The list of supported rates and rate mask can be different * for each phymode; since the phymode may have changed, reset * the rate mask to what mac80211 lists */ - iwl_set_rate(priv); + iwl3945_set_rate(priv); spin_unlock_irqrestore(&priv->lock, flags); #ifdef IEEE80211_CONF_CHANNEL_SWITCH if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { - iwl_hw_channel_switch(priv, conf->channel); - mutex_unlock(&priv->mutex); - return 0; + iwl3945_hw_channel_switch(priv, conf->channel); + goto out; } #endif - iwl_radio_kill_sw(priv, !conf->radio_enabled); + iwl3945_radio_kill_sw(priv, !conf->radio_enabled); if (!conf->radio_enabled) { IWL_DEBUG_MAC80211("leave - radio disabled\n"); - mutex_unlock(&priv->mutex); - return 0; + goto out; } - if (iwl_is_rfkill(priv)) { + if (iwl3945_is_rfkill(priv)) { IWL_DEBUG_MAC80211("leave - RF kill\n"); - mutex_unlock(&priv->mutex); - return -EIO; + ret = -EIO; + goto out; } - iwl_set_rate(priv); + iwl3945_set_rate(priv); if (memcmp(&priv->active_rxon, &priv->staging_rxon, sizeof(priv->staging_rxon))) - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); else IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); IWL_DEBUG_MAC80211("leave\n"); +out: + clear_bit(STATUS_CONF_PENDING, &priv->status); mutex_unlock(&priv->mutex); - - return 0; + return ret; } -static void iwl_config_ap(struct iwl_priv *priv) +static void iwl3945_config_ap(struct iwl3945_priv *priv) { int rc = 0; @@ -7072,12 +7128,12 @@ static void iwl_config_ap(struct iwl_priv *priv) /* RXON - unassoc (to set timing command) */ priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); /* RXON Timing */ - memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); - iwl_setup_rxon_timing(priv); - rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, + memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd)); + iwl3945_setup_rxon_timing(priv); + rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, sizeof(priv->rxon_timing), &priv->rxon_timing); if (rc) IWL_WARNING("REPLY_RXON_TIMING failed - " @@ -7107,20 +7163,21 @@ static void iwl_config_ap(struct iwl_priv *priv) } /* restore RXON assoc */ priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); - iwl_add_station(priv, BROADCAST_ADDR, 0, 0); + iwl3945_commit_rxon(priv); + iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0); } - iwl_send_beacon_cmd(priv); + iwl3945_send_beacon_cmd(priv); /* FIXME - we need to add code here to detect a totally new * configuration, reset the AP, unassoc, rxon timing, assoc, * clear sta table, add BCAST sta... */ } -static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, +static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, struct ieee80211_if_conf *conf) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; DECLARE_MAC_BUF(mac); unsigned long flags; int rc; @@ -7137,9 +7194,11 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, return 0; } + if (!iwl3945_is_alive(priv)) + return -EAGAIN; + mutex_lock(&priv->mutex); - IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id); if (conf->bssid) IWL_DEBUG_MAC80211("bssid: %s\n", print_mac(mac, conf->bssid)); @@ -7156,8 +7215,8 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, return 0; } - if (priv->interface_id != if_id) { - IWL_DEBUG_MAC80211("leave - interface_id != if_id\n"); + if (priv->vif != vif) { + IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); mutex_unlock(&priv->mutex); return 0; } @@ -7175,11 +7234,14 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, priv->ibss_beacon = conf->beacon; } + if (iwl3945_is_rfkill(priv)) + goto done; + if (conf->bssid && !is_zero_ether_addr(conf->bssid) && !is_multicast_ether_addr(conf->bssid)) { /* If there is currently a HW scan going on in the background * then we need to cancel it else the RXON below will fail. */ - if (iwl_scan_cancel_timeout(priv, 100)) { + if (iwl3945_scan_cancel_timeout(priv, 100)) { IWL_WARNING("Aborted scan still in progress " "after 100ms\n"); IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); @@ -7195,20 +7257,21 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, memcpy(priv->bssid, conf->bssid, ETH_ALEN); if (priv->iw_mode == IEEE80211_IF_TYPE_AP) - iwl_config_ap(priv); + iwl3945_config_ap(priv); else { - rc = iwl_commit_rxon(priv); + rc = iwl3945_commit_rxon(priv); if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) - iwl_add_station(priv, + iwl3945_add_station(priv, priv->active_rxon.bssid_addr, 1, 0); } } else { - iwl_scan_cancel_timeout(priv, 100); + iwl3945_scan_cancel_timeout(priv, 100); priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); } + done: spin_lock_irqsave(&priv->lock, flags); if (!conf->ssid_len) memset(priv->essid, 0, IW_ESSID_MAX_SIZE); @@ -7224,34 +7287,35 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, return 0; } -static void iwl_configure_filter(struct ieee80211_hw *hw, +static void iwl3945_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, unsigned int *total_flags, int mc_count, struct dev_addr_list *mc_list) { /* * XXX: dummy - * see also iwl_connection_init_rx_config + * see also iwl3945_connection_init_rx_config */ *total_flags = 0; } -static void iwl_mac_remove_interface(struct ieee80211_hw *hw, +static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw, struct ieee80211_if_init_conf *conf) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; IWL_DEBUG_MAC80211("enter\n"); mutex_lock(&priv->mutex); - iwl_scan_cancel_timeout(priv, 100); - cancel_delayed_work(&priv->post_associate); - priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); - - if (priv->interface_id == conf->if_id) { - priv->interface_id = 0; + if (iwl3945_is_ready_rf(priv)) { + iwl3945_scan_cancel_timeout(priv, 100); + cancel_delayed_work(&priv->post_associate); + priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; + iwl3945_commit_rxon(priv); + } + if (priv->vif == conf->vif) { + priv->vif = NULL; memset(priv->bssid, 0, ETH_ALEN); memset(priv->essid, 0, IW_ESSID_MAX_SIZE); priv->essid_len = 0; @@ -7259,22 +7323,20 @@ static void iwl_mac_remove_interface(struct ieee80211_hw *hw, mutex_unlock(&priv->mutex); IWL_DEBUG_MAC80211("leave\n"); - } -#define IWL_DELAY_NEXT_SCAN (HZ*2) -static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) +static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) { int rc = 0; unsigned long flags; - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; IWL_DEBUG_MAC80211("enter\n"); mutex_lock(&priv->mutex); spin_lock_irqsave(&priv->lock, flags); - if (!iwl_is_ready_rf(priv)) { + if (!iwl3945_is_ready_rf(priv)) { rc = -EIO; IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); goto out_unlock; @@ -7286,17 +7348,21 @@ static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) goto out_unlock; } + /* we don't schedule scan within next_scan_jiffies period */ + if (priv->next_scan_jiffies && + time_after(priv->next_scan_jiffies, jiffies)) { + rc = -EAGAIN; + goto out_unlock; + } /* if we just finished scan ask for delay */ - if (priv->last_scan_jiffies && - time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, - jiffies)) { + if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + + IWL_DELAY_NEXT_SCAN, jiffies)) { rc = -EAGAIN; goto out_unlock; } if (len) { - IWL_DEBUG_SCAN("direct scan for " - "%s [%d]\n ", - iwl_escape_essid(ssid, len), (int)len); + IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", + iwl3945_escape_essid(ssid, len), (int)len); priv->one_direct_scan = 1; priv->direct_ssid_len = (u8) @@ -7305,7 +7371,7 @@ static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) } else priv->one_direct_scan = 0; - rc = iwl_scan_initiate(priv); + rc = iwl3945_scan_initiate(priv); IWL_DEBUG_MAC80211("leave\n"); @@ -7316,17 +7382,17 @@ out_unlock: return rc; } -static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, +static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, const u8 *local_addr, const u8 *addr, struct ieee80211_key_conf *key) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; int rc = 0; u8 sta_id; IWL_DEBUG_MAC80211("enter\n"); - if (!iwl_param_hwcrypto) { + if (!iwl3945_param_hwcrypto) { IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); return -EOPNOTSUPP; } @@ -7335,7 +7401,7 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, /* only support pairwise keys */ return -EOPNOTSUPP; - sta_id = iwl_hw_find_station(priv, addr); + sta_id = iwl3945_hw_find_station(priv, addr); if (sta_id == IWL_INVALID_STATION) { DECLARE_MAC_BUF(mac); @@ -7346,24 +7412,24 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, mutex_lock(&priv->mutex); - iwl_scan_cancel_timeout(priv, 100); + iwl3945_scan_cancel_timeout(priv, 100); switch (cmd) { case SET_KEY: - rc = iwl_update_sta_key_info(priv, key, sta_id); + rc = iwl3945_update_sta_key_info(priv, key, sta_id); if (!rc) { - iwl_set_rxon_hwcrypto(priv, 1); - iwl_commit_rxon(priv); + iwl3945_set_rxon_hwcrypto(priv, 1); + iwl3945_commit_rxon(priv); key->hw_key_idx = sta_id; IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; } break; case DISABLE_KEY: - rc = iwl_clear_sta_key_info(priv, sta_id); + rc = iwl3945_clear_sta_key_info(priv, sta_id); if (!rc) { - iwl_set_rxon_hwcrypto(priv, 0); - iwl_commit_rxon(priv); + iwl3945_set_rxon_hwcrypto(priv, 0); + iwl3945_commit_rxon(priv); IWL_DEBUG_MAC80211("disable hwcrypto key\n"); } break; @@ -7377,18 +7443,18 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, return rc; } -static int iwl_mac_conf_tx(struct ieee80211_hw *hw, int queue, +static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, int queue, const struct ieee80211_tx_queue_params *params) { - struct iwl_priv *priv = hw->priv; -#ifdef CONFIG_IWLWIFI_QOS + struct iwl3945_priv *priv = hw->priv; +#ifdef CONFIG_IWL3945_QOS unsigned long flags; int q; -#endif /* CONFIG_IWL_QOS */ +#endif /* CONFIG_IWL3945_QOS */ IWL_DEBUG_MAC80211("enter\n"); - if (!iwl_is_ready_rf(priv)) { + if (!iwl3945_is_ready_rf(priv)) { IWL_DEBUG_MAC80211("leave - RF not ready\n"); return -EIO; } @@ -7398,7 +7464,7 @@ static int iwl_mac_conf_tx(struct ieee80211_hw *hw, int queue, return 0; } -#ifdef CONFIG_IWLWIFI_QOS +#ifdef CONFIG_IWL3945_QOS if (!priv->qos_data.qos_enable) { priv->qos_data.qos_active = 0; IWL_DEBUG_MAC80211("leave - qos not enabled\n"); @@ -7421,30 +7487,30 @@ static int iwl_mac_conf_tx(struct ieee80211_hw *hw, int queue, mutex_lock(&priv->mutex); if (priv->iw_mode == IEEE80211_IF_TYPE_AP) - iwl_activate_qos(priv, 1); - else if (priv->assoc_id && iwl_is_associated(priv)) - iwl_activate_qos(priv, 0); + iwl3945_activate_qos(priv, 1); + else if (priv->assoc_id && iwl3945_is_associated(priv)) + iwl3945_activate_qos(priv, 0); mutex_unlock(&priv->mutex); -#endif /*CONFIG_IWLWIFI_QOS */ +#endif /*CONFIG_IWL3945_QOS */ IWL_DEBUG_MAC80211("leave\n"); return 0; } -static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw, +static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw, struct ieee80211_tx_queue_stats *stats) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; int i, avail; - struct iwl_tx_queue *txq; - struct iwl_queue *q; + struct iwl3945_tx_queue *txq; + struct iwl3945_queue *q; unsigned long flags; IWL_DEBUG_MAC80211("enter\n"); - if (!iwl_is_ready_rf(priv)) { + if (!iwl3945_is_ready_rf(priv)) { IWL_DEBUG_MAC80211("leave - RF not ready\n"); return -EIO; } @@ -7454,7 +7520,7 @@ static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw, for (i = 0; i < AC_NUM; i++) { txq = &priv->txq[i]; q = &txq->q; - avail = iwl_queue_space(q); + avail = iwl3945_queue_space(q); stats->data[i].len = q->n_window - avail; stats->data[i].limit = q->n_window - q->high_mark; @@ -7468,7 +7534,7 @@ static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw, return 0; } -static int iwl_mac_get_stats(struct ieee80211_hw *hw, +static int iwl3945_mac_get_stats(struct ieee80211_hw *hw, struct ieee80211_low_level_stats *stats) { IWL_DEBUG_MAC80211("enter\n"); @@ -7477,7 +7543,7 @@ static int iwl_mac_get_stats(struct ieee80211_hw *hw, return 0; } -static u64 iwl_mac_get_tsf(struct ieee80211_hw *hw) +static u64 iwl3945_mac_get_tsf(struct ieee80211_hw *hw) { IWL_DEBUG_MAC80211("enter\n"); IWL_DEBUG_MAC80211("leave\n"); @@ -7485,16 +7551,16 @@ static u64 iwl_mac_get_tsf(struct ieee80211_hw *hw) return 0; } -static void iwl_mac_reset_tsf(struct ieee80211_hw *hw) +static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; unsigned long flags; mutex_lock(&priv->mutex); IWL_DEBUG_MAC80211("enter\n"); -#ifdef CONFIG_IWLWIFI_QOS - iwl_reset_qos(priv); +#ifdef CONFIG_IWL3945_QOS + iwl3945_reset_qos(priv); #endif cancel_delayed_work(&priv->post_associate); @@ -7517,13 +7583,19 @@ static void iwl_mac_reset_tsf(struct ieee80211_hw *hw) spin_unlock_irqrestore(&priv->lock, flags); + if (!iwl3945_is_ready_rf(priv)) { + IWL_DEBUG_MAC80211("leave - not ready\n"); + mutex_unlock(&priv->mutex); + return; + } + /* we are restarting association process * clear RXON_FILTER_ASSOC_MSK bit */ if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { - iwl_scan_cancel_timeout(priv, 100); + iwl3945_scan_cancel_timeout(priv, 100); priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); } /* Per mac80211.h: This is only used in IBSS mode... */ @@ -7534,15 +7606,9 @@ static void iwl_mac_reset_tsf(struct ieee80211_hw *hw) return; } - if (!iwl_is_ready_rf(priv)) { - IWL_DEBUG_MAC80211("leave - not ready\n"); - mutex_unlock(&priv->mutex); - return; - } - priv->only_active_channel = 0; - iwl_set_rate(priv); + iwl3945_set_rate(priv); mutex_unlock(&priv->mutex); @@ -7550,16 +7616,16 @@ static void iwl_mac_reset_tsf(struct ieee80211_hw *hw) } -static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, +static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, struct ieee80211_tx_control *control) { - struct iwl_priv *priv = hw->priv; + struct iwl3945_priv *priv = hw->priv; unsigned long flags; mutex_lock(&priv->mutex); IWL_DEBUG_MAC80211("enter\n"); - if (!iwl_is_ready_rf(priv)) { + if (!iwl3945_is_ready_rf(priv)) { IWL_DEBUG_MAC80211("leave - RF not ready\n"); mutex_unlock(&priv->mutex); return -EIO; @@ -7583,8 +7649,8 @@ static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, IWL_DEBUG_MAC80211("leave\n"); spin_unlock_irqrestore(&priv->lock, flags); -#ifdef CONFIG_IWLWIFI_QOS - iwl_reset_qos(priv); +#ifdef CONFIG_IWL3945_QOS + iwl3945_reset_qos(priv); #endif queue_work(priv->workqueue, &priv->post_associate.work); @@ -7600,7 +7666,7 @@ static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, * *****************************************************************************/ -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL3945_DEBUG /* * The following adds a new attribute to the sysfs representation @@ -7612,7 +7678,7 @@ static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, static ssize_t show_debug_level(struct device_driver *d, char *buf) { - return sprintf(buf, "0x%08X\n", iwl_debug_level); + return sprintf(buf, "0x%08X\n", iwl3945_debug_level); } static ssize_t store_debug_level(struct device_driver *d, const char *buf, size_t count) @@ -7625,7 +7691,7 @@ static ssize_t store_debug_level(struct device_driver *d, printk(KERN_INFO DRV_NAME ": %s is not in hex or decimal form.\n", buf); else - iwl_debug_level = val; + iwl3945_debug_level = val; return strnlen(buf, count); } @@ -7633,7 +7699,7 @@ static ssize_t store_debug_level(struct device_driver *d, static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level, store_debug_level); -#endif /* CONFIG_IWLWIFI_DEBUG */ +#endif /* CONFIG_IWL3945_DEBUG */ static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr, char *buf) @@ -7644,7 +7710,7 @@ static ssize_t show_rf_kill(struct device *d, * 2 - HW based RF kill active * 3 - Both HW and SW based RF kill active */ - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) | (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0); @@ -7655,10 +7721,10 @@ static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; mutex_lock(&priv->mutex); - iwl_radio_kill_sw(priv, buf[0] == '1'); + iwl3945_radio_kill_sw(priv, buf[0] == '1'); mutex_unlock(&priv->mutex); return count; @@ -7669,12 +7735,12 @@ static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); static ssize_t show_temperature(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; - if (!iwl_is_alive(priv)) + if (!iwl3945_is_alive(priv)) return -EAGAIN; - return sprintf(buf, "%d\n", iwl_hw_get_temperature(priv)); + return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv)); } static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); @@ -7683,15 +7749,15 @@ static ssize_t show_rs_window(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = d->driver_data; - return iwl_fill_rs_info(priv->hw, buf, IWL_AP_ID); + struct iwl3945_priv *priv = d->driver_data; + return iwl3945_fill_rs_info(priv->hw, buf, IWL_AP_ID); } static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); static ssize_t show_tx_power(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; return sprintf(buf, "%d\n", priv->user_txpower_limit); } @@ -7699,7 +7765,7 @@ static ssize_t store_tx_power(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; char *p = (char *)buf; u32 val; @@ -7708,7 +7774,7 @@ static ssize_t store_tx_power(struct device *d, printk(KERN_INFO DRV_NAME ": %s is not in decimal form.\n", buf); else - iwl_hw_reg_set_txpower(priv, val); + iwl3945_hw_reg_set_txpower(priv, val); return count; } @@ -7718,7 +7784,7 @@ static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); static ssize_t show_flags(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); } @@ -7727,19 +7793,19 @@ static ssize_t store_flags(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; u32 flags = simple_strtoul(buf, NULL, 0); mutex_lock(&priv->mutex); if (le32_to_cpu(priv->staging_rxon.flags) != flags) { /* Cancel any currently running scans... */ - if (iwl_scan_cancel_timeout(priv, 100)) + if (iwl3945_scan_cancel_timeout(priv, 100)) IWL_WARNING("Could not cancel scan.\n"); else { IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", flags); priv->staging_rxon.flags = cpu_to_le32(flags); - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); } } mutex_unlock(&priv->mutex); @@ -7752,7 +7818,7 @@ static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); static ssize_t show_filter_flags(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; return sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.filter_flags)); @@ -7762,20 +7828,20 @@ static ssize_t store_filter_flags(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; u32 filter_flags = simple_strtoul(buf, NULL, 0); mutex_lock(&priv->mutex); if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { /* Cancel any currently running scans... */ - if (iwl_scan_cancel_timeout(priv, 100)) + if (iwl3945_scan_cancel_timeout(priv, 100)) IWL_WARNING("Could not cancel scan.\n"); else { IWL_DEBUG_INFO("Committing rxon.filter_flags = " "0x%04X\n", filter_flags); priv->staging_rxon.filter_flags = cpu_to_le32(filter_flags); - iwl_commit_rxon(priv); + iwl3945_commit_rxon(priv); } } mutex_unlock(&priv->mutex); @@ -7789,20 +7855,20 @@ static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, static ssize_t show_tune(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; return sprintf(buf, "0x%04X\n", (priv->phymode << 8) | le16_to_cpu(priv->active_rxon.channel)); } -static void iwl_set_flags_for_phymode(struct iwl_priv *priv, u8 phymode); +static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, u8 phymode); static ssize_t store_tune(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; char *p = (char *)buf; u16 tune = simple_strtoul(p, &p, 0); u8 phymode = (tune >> 8) & 0xff; @@ -7813,9 +7879,9 @@ static ssize_t store_tune(struct device *d, mutex_lock(&priv->mutex); if ((le16_to_cpu(priv->staging_rxon.channel) != channel) || (priv->phymode != phymode)) { - const struct iwl_channel_info *ch_info; + const struct iwl3945_channel_info *ch_info; - ch_info = iwl_get_channel_info(priv, phymode, channel); + ch_info = iwl3945_get_channel_info(priv, phymode, channel); if (!ch_info) { IWL_WARNING("Requested invalid phymode/channel " "combination: %d %d\n", phymode, channel); @@ -7824,18 +7890,18 @@ static ssize_t store_tune(struct device *d, } /* Cancel any currently running scans... */ - if (iwl_scan_cancel_timeout(priv, 100)) + if (iwl3945_scan_cancel_timeout(priv, 100)) IWL_WARNING("Could not cancel scan.\n"); else { IWL_DEBUG_INFO("Committing phymode and " "rxon.channel = %d %d\n", phymode, channel); - iwl_set_rxon_channel(priv, phymode, channel); - iwl_set_flags_for_phymode(priv, phymode); + iwl3945_set_rxon_channel(priv, phymode, channel); + iwl3945_set_flags_for_phymode(priv, phymode); - iwl_set_rate(priv); - iwl_commit_rxon(priv); + iwl3945_set_rate(priv); + iwl3945_commit_rxon(priv); } } mutex_unlock(&priv->mutex); @@ -7845,13 +7911,13 @@ static ssize_t store_tune(struct device *d, static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune); -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT +#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT static ssize_t show_measurement(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); - struct iwl_spectrum_notification measure_report; + struct iwl3945_priv *priv = dev_get_drvdata(d); + struct iwl3945_spectrum_notification measure_report; u32 size = sizeof(measure_report), len = 0, ofs = 0; u8 *data = (u8 *) & measure_report; unsigned long flags; @@ -7883,7 +7949,7 @@ static ssize_t store_measurement(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl3945_priv *priv = dev_get_drvdata(d); struct ieee80211_measurement_params params = { .channel = le16_to_cpu(priv->active_rxon.channel), .start_time = cpu_to_le64(priv->last_tsf), @@ -7909,19 +7975,19 @@ static ssize_t store_measurement(struct device *d, IWL_DEBUG_INFO("Invoking measurement of type %d on " "channel %d (for '%s')\n", type, params.channel, buf); - iwl_get_measurement(priv, ¶ms, type); + iwl3945_get_measurement(priv, ¶ms, type); return count; } static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, show_measurement, store_measurement); -#endif /* CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT */ +#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */ static ssize_t show_rate(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl3945_priv *priv = dev_get_drvdata(d); unsigned long flags; int i; @@ -7932,13 +7998,13 @@ static ssize_t show_rate(struct device *d, i = priv->stations[IWL_STA_ID].current_rate.s.rate; spin_unlock_irqrestore(&priv->sta_lock, flags); - i = iwl_rate_index_from_plcp(i); + i = iwl3945_rate_index_from_plcp(i); if (i == -1) return sprintf(buf, "0\n"); return sprintf(buf, "%d%s\n", - (iwl_rates[i].ieee >> 1), - (iwl_rates[i].ieee & 0x1) ? ".5" : ""); + (iwl3945_rates[i].ieee >> 1), + (iwl3945_rates[i].ieee & 0x1) ? ".5" : ""); } static DEVICE_ATTR(rate, S_IRUSR, show_rate, NULL); @@ -7947,7 +8013,7 @@ static ssize_t store_retry_rate(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl3945_priv *priv = dev_get_drvdata(d); priv->retry_rate = simple_strtoul(buf, NULL, 0); if (priv->retry_rate <= 0) @@ -7959,7 +8025,7 @@ static ssize_t store_retry_rate(struct device *d, static ssize_t show_retry_rate(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl3945_priv *priv = dev_get_drvdata(d); return sprintf(buf, "%d", priv->retry_rate); } @@ -7970,14 +8036,14 @@ static ssize_t store_power_level(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl3945_priv *priv = dev_get_drvdata(d); int rc; int mode; mode = simple_strtoul(buf, NULL, 0); mutex_lock(&priv->mutex); - if (!iwl_is_ready(priv)) { + if (!iwl3945_is_ready(priv)) { rc = -EAGAIN; goto out; } @@ -7988,7 +8054,7 @@ static ssize_t store_power_level(struct device *d, mode |= IWL_POWER_ENABLED; if (mode != priv->power_mode) { - rc = iwl_send_power_mode(priv, IWL_POWER_LEVEL(mode)); + rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode)); if (rc) { IWL_DEBUG_MAC80211("failed setting power mode.\n"); goto out; @@ -8024,7 +8090,7 @@ static const s32 period_duration[] = { static ssize_t show_power_level(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl3945_priv *priv = dev_get_drvdata(d); int level = IWL_POWER_LEVEL(priv->power_mode); char *p = buf; @@ -8059,18 +8125,18 @@ static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, static ssize_t show_channels(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl3945_priv *priv = dev_get_drvdata(d); int len = 0, i; struct ieee80211_channel *channels = NULL; const struct ieee80211_hw_mode *hw_mode = NULL; int count = 0; - if (!iwl_is_ready(priv)) + if (!iwl3945_is_ready(priv)) return -EAGAIN; - hw_mode = iwl_get_hw_mode(priv, MODE_IEEE80211G); + hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211G); if (!hw_mode) - hw_mode = iwl_get_hw_mode(priv, MODE_IEEE80211B); + hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211B); if (hw_mode) { channels = hw_mode->channels; count = hw_mode->num_channels; @@ -8097,7 +8163,7 @@ static ssize_t show_channels(struct device *d, flag & IEEE80211_CHAN_W_ACTIVE_SCAN ? "active/passive" : "passive only"); - hw_mode = iwl_get_hw_mode(priv, MODE_IEEE80211A); + hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211A); if (hw_mode) { channels = hw_mode->channels; count = hw_mode->num_channels; @@ -8133,17 +8199,17 @@ static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); static ssize_t show_statistics(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); - u32 size = sizeof(struct iwl_notif_statistics); + struct iwl3945_priv *priv = dev_get_drvdata(d); + u32 size = sizeof(struct iwl3945_notif_statistics); u32 len = 0, ofs = 0; u8 *data = (u8 *) & priv->statistics; int rc = 0; - if (!iwl_is_alive(priv)) + if (!iwl3945_is_alive(priv)) return -EAGAIN; mutex_lock(&priv->mutex); - rc = iwl_send_statistics_request(priv); + rc = iwl3945_send_statistics_request(priv); mutex_unlock(&priv->mutex); if (rc) { @@ -8171,9 +8237,9 @@ static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); static ssize_t show_antenna(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl3945_priv *priv = dev_get_drvdata(d); - if (!iwl_is_alive(priv)) + if (!iwl3945_is_alive(priv)) return -EAGAIN; return sprintf(buf, "%d\n", priv->antenna); @@ -8184,7 +8250,7 @@ static ssize_t store_antenna(struct device *d, const char *buf, size_t count) { int ant; - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl3945_priv *priv = dev_get_drvdata(d); if (count == 0) return 0; @@ -8196,7 +8262,7 @@ static ssize_t store_antenna(struct device *d, if ((ant >= 0) && (ant <= 2)) { IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); - priv->antenna = (enum iwl_antenna)ant; + priv->antenna = (enum iwl3945_antenna)ant; } else IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); @@ -8209,8 +8275,8 @@ static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); static ssize_t show_status(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; - if (!iwl_is_alive(priv)) + struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; + if (!iwl3945_is_alive(priv)) return -EAGAIN; return sprintf(buf, "0x%08x\n", (int)priv->status); } @@ -8224,7 +8290,7 @@ static ssize_t dump_error_log(struct device *d, char *p = (char *)buf; if (p[0] == '1') - iwl_dump_nic_error_log((struct iwl_priv *)d->driver_data); + iwl3945_dump_nic_error_log((struct iwl3945_priv *)d->driver_data); return strnlen(buf, count); } @@ -8238,7 +8304,7 @@ static ssize_t dump_event_log(struct device *d, char *p = (char *)buf; if (p[0] == '1') - iwl_dump_nic_event_log((struct iwl_priv *)d->driver_data); + iwl3945_dump_nic_event_log((struct iwl3945_priv *)d->driver_data); return strnlen(buf, count); } @@ -8251,34 +8317,34 @@ static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); * *****************************************************************************/ -static void iwl_setup_deferred_work(struct iwl_priv *priv) +static void iwl3945_setup_deferred_work(struct iwl3945_priv *priv) { priv->workqueue = create_workqueue(DRV_NAME); init_waitqueue_head(&priv->wait_command_queue); - INIT_WORK(&priv->up, iwl_bg_up); - INIT_WORK(&priv->restart, iwl_bg_restart); - INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish); - INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); - INIT_WORK(&priv->request_scan, iwl_bg_request_scan); - INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan); - INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill); - INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update); - INIT_DELAYED_WORK(&priv->post_associate, iwl_bg_post_associate); - INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); - INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); - INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check); - - iwl_hw_setup_deferred_work(priv); + INIT_WORK(&priv->up, iwl3945_bg_up); + INIT_WORK(&priv->restart, iwl3945_bg_restart); + INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish); + INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed); + INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan); + INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan); + INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill); + INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); + INIT_DELAYED_WORK(&priv->post_associate, iwl3945_bg_post_associate); + INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); + INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); + INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check); + + iwl3945_hw_setup_deferred_work(priv); tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) - iwl_irq_tasklet, (unsigned long)priv); + iwl3945_irq_tasklet, (unsigned long)priv); } -static void iwl_cancel_deferred_work(struct iwl_priv *priv) +static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv) { - iwl_hw_cancel_deferred_work(priv); + iwl3945_hw_cancel_deferred_work(priv); cancel_delayed_work_sync(&priv->init_alive_start); cancel_delayed_work(&priv->scan_check); @@ -8287,14 +8353,14 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv) cancel_work_sync(&priv->beacon_update); } -static struct attribute *iwl_sysfs_entries[] = { +static struct attribute *iwl3945_sysfs_entries[] = { &dev_attr_antenna.attr, &dev_attr_channels.attr, &dev_attr_dump_errors.attr, &dev_attr_dump_events.attr, &dev_attr_flags.attr, &dev_attr_filter_flags.attr, -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT +#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT &dev_attr_measurement.attr, #endif &dev_attr_power_level.attr, @@ -8311,45 +8377,48 @@ static struct attribute *iwl_sysfs_entries[] = { NULL }; -static struct attribute_group iwl_attribute_group = { +static struct attribute_group iwl3945_attribute_group = { .name = NULL, /* put in device directory */ - .attrs = iwl_sysfs_entries, + .attrs = iwl3945_sysfs_entries, }; -static struct ieee80211_ops iwl_hw_ops = { - .tx = iwl_mac_tx, - .start = iwl_mac_start, - .stop = iwl_mac_stop, - .add_interface = iwl_mac_add_interface, - .remove_interface = iwl_mac_remove_interface, - .config = iwl_mac_config, - .config_interface = iwl_mac_config_interface, - .configure_filter = iwl_configure_filter, - .set_key = iwl_mac_set_key, - .get_stats = iwl_mac_get_stats, - .get_tx_stats = iwl_mac_get_tx_stats, - .conf_tx = iwl_mac_conf_tx, - .get_tsf = iwl_mac_get_tsf, - .reset_tsf = iwl_mac_reset_tsf, - .beacon_update = iwl_mac_beacon_update, - .hw_scan = iwl_mac_hw_scan +static struct ieee80211_ops iwl3945_hw_ops = { + .tx = iwl3945_mac_tx, + .start = iwl3945_mac_start, + .stop = iwl3945_mac_stop, + .add_interface = iwl3945_mac_add_interface, + .remove_interface = iwl3945_mac_remove_interface, + .config = iwl3945_mac_config, + .config_interface = iwl3945_mac_config_interface, + .configure_filter = iwl3945_configure_filter, + .set_key = iwl3945_mac_set_key, + .get_stats = iwl3945_mac_get_stats, + .get_tx_stats = iwl3945_mac_get_tx_stats, + .conf_tx = iwl3945_mac_conf_tx, + .get_tsf = iwl3945_mac_get_tsf, + .reset_tsf = iwl3945_mac_reset_tsf, + .beacon_update = iwl3945_mac_beacon_update, + .hw_scan = iwl3945_mac_hw_scan }; -static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) +static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { int err = 0; u32 pci_id; - struct iwl_priv *priv; + struct iwl3945_priv *priv; struct ieee80211_hw *hw; int i; + DECLARE_MAC_BUF(mac); - if (iwl_param_disable_hw_scan) { + /* Disabling hardware scan means that mac80211 will perform scans + * "the hard way", rather than using device's scan. */ + if (iwl3945_param_disable_hw_scan) { IWL_DEBUG_INFO("Disabling hw_scan\n"); - iwl_hw_ops.hw_scan = NULL; + iwl3945_hw_ops.hw_scan = NULL; } - if ((iwl_param_queues_num > IWL_MAX_NUM_QUEUES) || - (iwl_param_queues_num < IWL_MIN_NUM_QUEUES)) { + if ((iwl3945_param_queues_num > IWL_MAX_NUM_QUEUES) || + (iwl3945_param_queues_num < IWL_MIN_NUM_QUEUES)) { IWL_ERROR("invalid queues_num, should be between %d and %d\n", IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES); err = -EINVAL; @@ -8358,7 +8427,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) /* mac80211 allocates memory for this device instance, including * space for this driver's private structure */ - hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwl_hw_ops); + hw = ieee80211_alloc_hw(sizeof(struct iwl3945_priv), &iwl3945_hw_ops); if (hw == NULL) { IWL_ERROR("Can not allocate network device\n"); err = -ENOMEM; @@ -8373,9 +8442,11 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) priv->hw = hw; priv->pci_dev = pdev; - priv->antenna = (enum iwl_antenna)iwl_param_antenna; -#ifdef CONFIG_IWLWIFI_DEBUG - iwl_debug_level = iwl_param_debug; + + /* Select antenna (may be helpful if only one antenna is connected) */ + priv->antenna = (enum iwl3945_antenna)iwl3945_param_antenna; +#ifdef CONFIG_IWL3945_DEBUG + iwl3945_debug_level = iwl3945_param_debug; atomic_set(&priv->restrict_refcnt, 0); #endif priv->retry_rate = 1; @@ -8394,6 +8465,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) /* Tell mac80211 our Tx characteristics */ hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; + /* 4 EDCA QOS priorities */ hw->queues = 4; spin_lock_init(&priv->lock); @@ -8414,7 +8486,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_master(pdev); - iwl_clear_stations_table(priv); + /* Clear the driver's (not device's) station table */ + iwl3945_clear_stations_table(priv); priv->data_retry_limit = -1; priv->ieee_channels = NULL; @@ -8433,9 +8506,11 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err = pci_request_regions(pdev, DRV_NAME); if (err) goto out_pci_disable_device; + /* We disable the RETRY_TIMEOUT register (0x41) to keep * PCI Tx retries from interfering with C3 CPU state */ pci_write_config_byte(pdev, 0x41, 0x00); + priv->hw_base = pci_iomap(pdev, 0, 0); if (!priv->hw_base) { err = -ENODEV; @@ -8448,7 +8523,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) /* Initialize module parameter values here */ - if (iwl_param_disable) { + /* Disable radio (SW RF KILL) via parameter when loading driver */ + if (iwl3945_param_disable) { set_bit(STATUS_RF_KILL_SW, &priv->status); IWL_DEBUG_INFO("Radio disabled.\n"); } @@ -8483,78 +8559,82 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) priv->is_abg ? "A" : ""); /* Device-specific setup */ - if (iwl_hw_set_hw_setting(priv)) { + if (iwl3945_hw_set_hw_setting(priv)) { IWL_ERROR("failed to set hw settings\n"); - mutex_unlock(&priv->mutex); goto out_iounmap; } -#ifdef CONFIG_IWLWIFI_QOS - if (iwl_param_qos_enable) +#ifdef CONFIG_IWL3945_QOS + if (iwl3945_param_qos_enable) priv->qos_data.qos_enable = 1; - iwl_reset_qos(priv); + iwl3945_reset_qos(priv); priv->qos_data.qos_active = 0; priv->qos_data.qos_cap.val = 0; -#endif /* CONFIG_IWLWIFI_QOS */ +#endif /* CONFIG_IWL3945_QOS */ - iwl_set_rxon_channel(priv, MODE_IEEE80211G, 6); - iwl_setup_deferred_work(priv); - iwl_setup_rx_handlers(priv); + iwl3945_set_rxon_channel(priv, MODE_IEEE80211G, 6); + iwl3945_setup_deferred_work(priv); + iwl3945_setup_rx_handlers(priv); priv->rates_mask = IWL_RATES_MASK; /* If power management is turned on, default to AC mode */ priv->power_mode = IWL_POWER_AC; priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; - pci_enable_msi(pdev); + iwl3945_disable_interrupts(priv); - err = request_irq(pdev->irq, iwl_isr, IRQF_SHARED, DRV_NAME, priv); - if (err) { - IWL_ERROR("Error allocating IRQ %d\n", pdev->irq); - goto out_disable_msi; - } - - mutex_lock(&priv->mutex); - - err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group); + err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group); if (err) { IWL_ERROR("failed to create sysfs device attributes\n"); - mutex_unlock(&priv->mutex); goto out_release_irq; } - /* fetch ucode file from disk, alloc and copy to bus-master buffers ... - * ucode filename and max sizes are card-specific. */ - err = iwl_read_ucode(priv); + /* nic init */ + iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS, + CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); + + iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); + err = iwl3945_poll_bit(priv, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, + CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); + if (err < 0) { + IWL_DEBUG_INFO("Failed to init the card\n"); + goto out_remove_sysfs; + } + /* Read the EEPROM */ + err = iwl3945_eeprom_init(priv); if (err) { - IWL_ERROR("Could not read microcode: %d\n", err); - mutex_unlock(&priv->mutex); - goto out_pci_alloc; + IWL_ERROR("Unable to init EEPROM\n"); + goto out_remove_sysfs; } + /* MAC Address location in EEPROM same for 3945/4965 */ + get_eeprom_mac(priv, priv->mac_addr); + IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); + SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); - mutex_unlock(&priv->mutex); - - IWL_DEBUG_INFO("Queing UP work.\n"); + iwl3945_rate_control_register(priv->hw); + err = ieee80211_register_hw(priv->hw); + if (err) { + IWL_ERROR("Failed to register network device (error %d)\n", err); + goto out_remove_sysfs; + } - queue_work(priv->workqueue, &priv->up); + priv->hw->conf.beacon_int = 100; + priv->mac80211_registered = 1; + pci_save_state(pdev); + pci_disable_device(pdev); return 0; - out_pci_alloc: - iwl_dealloc_ucode_pci(priv); - - sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group); + out_remove_sysfs: + sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); out_release_irq: - free_irq(pdev->irq, priv); - - out_disable_msi: - pci_disable_msi(pdev); destroy_workqueue(priv->workqueue); priv->workqueue = NULL; - iwl_unset_hw_setting(priv); + iwl3945_unset_hw_setting(priv); out_iounmap: pci_iounmap(pdev, priv->hw_base); @@ -8569,9 +8649,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return err; } -static void iwl_pci_remove(struct pci_dev *pdev) +static void iwl3945_pci_remove(struct pci_dev *pdev) { - struct iwl_priv *priv = pci_get_drvdata(pdev); + struct iwl3945_priv *priv = pci_get_drvdata(pdev); struct list_head *p, *q; int i; @@ -8582,43 +8662,41 @@ static void iwl_pci_remove(struct pci_dev *pdev) set_bit(STATUS_EXIT_PENDING, &priv->status); - iwl_down(priv); + iwl3945_down(priv); /* Free MAC hash list for ADHOC */ for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { list_del(p); - kfree(list_entry(p, struct iwl_ibss_seq, list)); + kfree(list_entry(p, struct iwl3945_ibss_seq, list)); } } - sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group); + sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); - iwl_dealloc_ucode_pci(priv); + iwl3945_dealloc_ucode_pci(priv); if (priv->rxq.bd) - iwl_rx_queue_free(priv, &priv->rxq); - iwl_hw_txq_ctx_free(priv); + iwl3945_rx_queue_free(priv, &priv->rxq); + iwl3945_hw_txq_ctx_free(priv); - iwl_unset_hw_setting(priv); - iwl_clear_stations_table(priv); + iwl3945_unset_hw_setting(priv); + iwl3945_clear_stations_table(priv); if (priv->mac80211_registered) { ieee80211_unregister_hw(priv->hw); - iwl_rate_control_unregister(priv->hw); + iwl3945_rate_control_unregister(priv->hw); } /*netif_stop_queue(dev); */ flush_workqueue(priv->workqueue); - /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes + /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes * priv->workqueue... so we can't take down the workqueue * until now... */ destroy_workqueue(priv->workqueue); priv->workqueue = NULL; - free_irq(pdev->irq, priv); - pci_disable_msi(pdev); pci_iounmap(pdev, priv->hw_base); pci_release_regions(pdev); pci_disable_device(pdev); @@ -8637,93 +8715,31 @@ static void iwl_pci_remove(struct pci_dev *pdev) #ifdef CONFIG_PM -static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state) +static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state) { - struct iwl_priv *priv = pci_get_drvdata(pdev); - - set_bit(STATUS_IN_SUSPEND, &priv->status); - - /* Take down the device; powers it off, etc. */ - iwl_down(priv); + struct iwl3945_priv *priv = pci_get_drvdata(pdev); - if (priv->mac80211_registered) - ieee80211_stop_queues(priv->hw); + if (priv->is_open) { + set_bit(STATUS_IN_SUSPEND, &priv->status); + iwl3945_mac_stop(priv->hw); + priv->is_open = 1; + } - pci_save_state(pdev); - pci_disable_device(pdev); pci_set_power_state(pdev, PCI_D3hot); return 0; } -static void iwl_resume(struct iwl_priv *priv) +static int iwl3945_pci_resume(struct pci_dev *pdev) { - unsigned long flags; - - /* The following it a temporary work around due to the - * suspend / resume not fully initializing the NIC correctly. - * Without all of the following, resume will not attempt to take - * down the NIC (it shouldn't really need to) and will just try - * and bring the NIC back up. However that fails during the - * ucode verification process. This then causes iwl_down to be - * called *after* iwl_hw_nic_init() has succeeded -- which - * then lets the next init sequence succeed. So, we've - * replicated all of that NIC init code here... */ - - iwl_write32(priv, CSR_INT, 0xFFFFFFFF); - - iwl_hw_nic_init(priv); - - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, - CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); - iwl_write32(priv, CSR_INT, 0xFFFFFFFF); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - - /* tell the device to stop sending interrupts */ - iwl_disable_interrupts(priv); - - spin_lock_irqsave(&priv->lock, flags); - iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); - - if (!iwl_grab_restricted_access(priv)) { - iwl_write_restricted_reg(priv, APMG_CLK_DIS_REG, - APMG_CLK_VAL_DMA_CLK_RQT); - iwl_release_restricted_access(priv); - } - spin_unlock_irqrestore(&priv->lock, flags); - - udelay(5); - - iwl_hw_nic_reset(priv); - - /* Bring the device back up */ - clear_bit(STATUS_IN_SUSPEND, &priv->status); - queue_work(priv->workqueue, &priv->up); -} - -static int iwl_pci_resume(struct pci_dev *pdev) -{ - struct iwl_priv *priv = pci_get_drvdata(pdev); - int err; - - printk(KERN_INFO "Coming out of suspend...\n"); + struct iwl3945_priv *priv = pci_get_drvdata(pdev); pci_set_power_state(pdev, PCI_D0); - err = pci_enable_device(pdev); - pci_restore_state(pdev); - /* - * Suspend/Resume resets the PCI configuration space, so we have to - * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries - * from interfering with C3 CPU state. pci_restore_state won't help - * here since it only restores the first 64 bytes pci config header. - */ - pci_write_config_byte(pdev, 0x41, 0x00); - - iwl_resume(priv); + if (priv->is_open) + iwl3945_mac_start(priv->hw); + clear_bit(STATUS_IN_SUSPEND, &priv->status); return 0; } @@ -8735,33 +8751,33 @@ static int iwl_pci_resume(struct pci_dev *pdev) * *****************************************************************************/ -static struct pci_driver iwl_driver = { +static struct pci_driver iwl3945_driver = { .name = DRV_NAME, - .id_table = iwl_hw_card_ids, - .probe = iwl_pci_probe, - .remove = __devexit_p(iwl_pci_remove), + .id_table = iwl3945_hw_card_ids, + .probe = iwl3945_pci_probe, + .remove = __devexit_p(iwl3945_pci_remove), #ifdef CONFIG_PM - .suspend = iwl_pci_suspend, - .resume = iwl_pci_resume, + .suspend = iwl3945_pci_suspend, + .resume = iwl3945_pci_resume, #endif }; -static int __init iwl_init(void) +static int __init iwl3945_init(void) { int ret; printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); - ret = pci_register_driver(&iwl_driver); + ret = pci_register_driver(&iwl3945_driver); if (ret) { IWL_ERROR("Unable to initialize PCI module\n"); return ret; } -#ifdef CONFIG_IWLWIFI_DEBUG - ret = driver_create_file(&iwl_driver.driver, &driver_attr_debug_level); +#ifdef CONFIG_IWL3945_DEBUG + ret = driver_create_file(&iwl3945_driver.driver, &driver_attr_debug_level); if (ret) { IWL_ERROR("Unable to create driver sysfs file\n"); - pci_unregister_driver(&iwl_driver); + pci_unregister_driver(&iwl3945_driver); return ret; } #endif @@ -8769,32 +8785,32 @@ static int __init iwl_init(void) return ret; } -static void __exit iwl_exit(void) +static void __exit iwl3945_exit(void) { -#ifdef CONFIG_IWLWIFI_DEBUG - driver_remove_file(&iwl_driver.driver, &driver_attr_debug_level); +#ifdef CONFIG_IWL3945_DEBUG + driver_remove_file(&iwl3945_driver.driver, &driver_attr_debug_level); #endif - pci_unregister_driver(&iwl_driver); + pci_unregister_driver(&iwl3945_driver); } -module_param_named(antenna, iwl_param_antenna, int, 0444); +module_param_named(antenna, iwl3945_param_antenna, int, 0444); MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); -module_param_named(disable, iwl_param_disable, int, 0444); +module_param_named(disable, iwl3945_param_disable, int, 0444); MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); -module_param_named(hwcrypto, iwl_param_hwcrypto, int, 0444); +module_param_named(hwcrypto, iwl3945_param_hwcrypto, int, 0444); MODULE_PARM_DESC(hwcrypto, "using hardware crypto engine (default 0 [software])\n"); -module_param_named(debug, iwl_param_debug, int, 0444); +module_param_named(debug, iwl3945_param_debug, int, 0444); MODULE_PARM_DESC(debug, "debug output mask"); -module_param_named(disable_hw_scan, iwl_param_disable_hw_scan, int, 0444); +module_param_named(disable_hw_scan, iwl3945_param_disable_hw_scan, int, 0444); MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); -module_param_named(queues_num, iwl_param_queues_num, int, 0444); +module_param_named(queues_num, iwl3945_param_queues_num, int, 0444); MODULE_PARM_DESC(queues_num, "number of hw queues."); /* QoS */ -module_param_named(qos_enable, iwl_param_qos_enable, int, 0444); +module_param_named(qos_enable, iwl3945_param_qos_enable, int, 0444); MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); -module_exit(iwl_exit); -module_init(iwl_init); +module_exit(iwl3945_exit); +module_init(iwl3945_init); diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c index 6cd57c22063..c86da5cd1df 100644 --- a/drivers/net/wireless/iwlwifi/iwl4965-base.c +++ b/drivers/net/wireless/iwlwifi/iwl4965-base.c @@ -27,16 +27,6 @@ * *****************************************************************************/ -/* - * NOTE: This file (iwl-base.c) is used to build to multiple hardware targets - * by defining IWL to either 3945 or 4965. The Makefile used when building - * the base targets will create base-3945.o and base-4965.o - * - * The eventual goal is to move as many of the #if IWL / #endif blocks out of - * this file and into the hardware specific implementation files (iwl-XXXX.c) - * and leave only the common (non #ifdef sprinkled) code in this file - */ - #include <linux/kernel.h> #include <linux/module.h> #include <linux/version.h> @@ -51,21 +41,20 @@ #include <linux/etherdevice.h> #include <linux/if_arp.h> -#include <net/ieee80211_radiotap.h> #include <net/mac80211.h> #include <asm/div64.h> -#define IWL 4965 - -#include "iwlwifi.h" #include "iwl-4965.h" #include "iwl-helpers.h" -#ifdef CONFIG_IWLWIFI_DEBUG -u32 iwl_debug_level; +#ifdef CONFIG_IWL4965_DEBUG +u32 iwl4965_debug_level; #endif +static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, + struct iwl4965_tx_queue *txq); + /****************************************************************************** * * module boiler plate @@ -73,13 +62,14 @@ u32 iwl_debug_level; ******************************************************************************/ /* module parameters */ -int iwl_param_disable_hw_scan; -int iwl_param_debug; -int iwl_param_disable; /* def: enable radio */ -int iwl_param_antenna; /* def: 0 = both antennas (use diversity) */ -int iwl_param_hwcrypto; /* def: using software encryption */ -int iwl_param_qos_enable = 1; -int iwl_param_queues_num = IWL_MAX_NUM_QUEUES; +static int iwl4965_param_disable_hw_scan; /* def: 0 = use 4965's h/w scan */ +static int iwl4965_param_debug; /* def: 0 = minimal debug log messages */ +static int iwl4965_param_disable; /* def: enable radio */ +static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */ +int iwl4965_param_hwcrypto; /* def: using software encryption */ +static int iwl4965_param_qos_enable = 1; /* def: 1 = use quality of service */ +int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 16 Tx queues */ +int iwl4965_param_amsdu_size_8K; /* def: enable 8K amsdu size */ /* * module name, copyright, version, etc. @@ -88,19 +78,19 @@ int iwl_param_queues_num = IWL_MAX_NUM_QUEUES; #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL4965_DEBUG #define VD "d" #else #define VD #endif -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT +#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT #define VS "s" #else #define VS #endif -#define IWLWIFI_VERSION "1.1.17k" VD VS +#define IWLWIFI_VERSION "1.2.23k" VD VS #define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation" #define DRV_VERSION IWLWIFI_VERSION @@ -125,8 +115,8 @@ __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) return NULL; } -static const struct ieee80211_hw_mode *iwl_get_hw_mode( - struct iwl_priv *priv, int mode) +static const struct ieee80211_hw_mode *iwl4965_get_hw_mode( + struct iwl4965_priv *priv, int mode) { int i; @@ -137,7 +127,7 @@ static const struct ieee80211_hw_mode *iwl_get_hw_mode( return NULL; } -static int iwl_is_empty_essid(const char *essid, int essid_len) +static int iwl4965_is_empty_essid(const char *essid, int essid_len) { /* Single white space is for Linksys APs */ if (essid_len == 1 && essid[0] == ' ') @@ -153,13 +143,13 @@ static int iwl_is_empty_essid(const char *essid, int essid_len) return 1; } -static const char *iwl_escape_essid(const char *essid, u8 essid_len) +static const char *iwl4965_escape_essid(const char *essid, u8 essid_len) { static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; const char *s = essid; char *d = escaped; - if (iwl_is_empty_essid(essid, essid_len)) { + if (iwl4965_is_empty_essid(essid, essid_len)) { memcpy(escaped, "<hidden>", sizeof("<hidden>")); return escaped; } @@ -177,10 +167,10 @@ static const char *iwl_escape_essid(const char *essid, u8 essid_len) return escaped; } -static void iwl_print_hex_dump(int level, void *p, u32 len) +static void iwl4965_print_hex_dump(int level, void *p, u32 len) { -#ifdef CONFIG_IWLWIFI_DEBUG - if (!(iwl_debug_level & level)) +#ifdef CONFIG_IWL4965_DEBUG + if (!(iwl4965_debug_level & level)) return; print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1, @@ -193,24 +183,33 @@ static void iwl_print_hex_dump(int level, void *p, u32 len) * * Theory of operation * - * A queue is a circular buffers with 'Read' and 'Write' pointers. - * 2 empty entries always kept in the buffer to protect from overflow. + * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer + * of buffer descriptors, each of which points to one or more data buffers for + * the device to read from or fill. Driver and device exchange status of each + * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty + * entries in each circular buffer, to protect against confusing empty and full + * queue states. + * + * The device reads or writes the data in the queues via the device's several + * DMA/FIFO channels. Each queue is mapped to a single DMA channel. * * For Tx queue, there are low mark and high mark limits. If, after queuing * the packet for Tx, free space become < low mark, Tx queue stopped. When * reclaiming packets (on 'tx done IRQ), if free space become > high mark, * Tx queue resumed. * - * The IWL operates with six queues, one receive queue in the device's - * sram, one transmit queue for sending commands to the device firmware, - * and four transmit queues for data. + * The 4965 operates with up to 17 queues: One receive queue, one transmit + * queue (#4) for sending commands to the device firmware, and 15 other + * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels. + * + * See more detailed info in iwl-4965-hw.h. ***************************************************/ -static int iwl_queue_space(const struct iwl_queue *q) +static int iwl4965_queue_space(const struct iwl4965_queue *q) { - int s = q->last_used - q->first_empty; + int s = q->read_ptr - q->write_ptr; - if (q->last_used > q->first_empty) + if (q->read_ptr > q->write_ptr) s -= q->n_bd; if (s <= 0) @@ -222,42 +221,55 @@ static int iwl_queue_space(const struct iwl_queue *q) return s; } -/* XXX: n_bd must be power-of-two size */ -static inline int iwl_queue_inc_wrap(int index, int n_bd) +/** + * iwl4965_queue_inc_wrap - increment queue index, wrap back to beginning + * @index -- current index + * @n_bd -- total number of entries in queue (must be power of 2) + */ +static inline int iwl4965_queue_inc_wrap(int index, int n_bd) { return ++index & (n_bd - 1); } -/* XXX: n_bd must be power-of-two size */ -static inline int iwl_queue_dec_wrap(int index, int n_bd) +/** + * iwl4965_queue_dec_wrap - decrement queue index, wrap back to end + * @index -- current index + * @n_bd -- total number of entries in queue (must be power of 2) + */ +static inline int iwl4965_queue_dec_wrap(int index, int n_bd) { return --index & (n_bd - 1); } -static inline int x2_queue_used(const struct iwl_queue *q, int i) +static inline int x2_queue_used(const struct iwl4965_queue *q, int i) { - return q->first_empty > q->last_used ? - (i >= q->last_used && i < q->first_empty) : - !(i < q->last_used && i >= q->first_empty); + return q->write_ptr > q->read_ptr ? + (i >= q->read_ptr && i < q->write_ptr) : + !(i < q->read_ptr && i >= q->write_ptr); } -static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge) +static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge) { + /* This is for scan command, the big buffer at end of command array */ if (is_huge) - return q->n_window; + return q->n_window; /* must be power of 2 */ + /* Otherwise, use normal size buffers */ return index & (q->n_window - 1); } -static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q, +/** + * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes + */ +static int iwl4965_queue_init(struct iwl4965_priv *priv, struct iwl4965_queue *q, int count, int slots_num, u32 id) { q->n_bd = count; q->n_window = slots_num; q->id = id; - /* count must be power-of-two size, otherwise iwl_queue_inc_wrap - * and iwl_queue_dec_wrap are broken. */ + /* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap + * and iwl4965_queue_dec_wrap are broken. */ BUG_ON(!is_power_of_2(count)); /* slots_num must be power-of-two size, otherwise @@ -272,27 +284,34 @@ static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q, if (q->high_mark < 2) q->high_mark = 2; - q->first_empty = q->last_used = 0; + q->write_ptr = q->read_ptr = 0; return 0; } -static int iwl_tx_queue_alloc(struct iwl_priv *priv, - struct iwl_tx_queue *txq, u32 id) +/** + * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue + */ +static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv, + struct iwl4965_tx_queue *txq, u32 id) { struct pci_dev *dev = priv->pci_dev; + /* Driver private data, only for Tx (not command) queues, + * not shared with device. */ if (id != IWL_CMD_QUEUE_NUM) { txq->txb = kmalloc(sizeof(txq->txb[0]) * TFD_QUEUE_SIZE_MAX, GFP_KERNEL); if (!txq->txb) { - IWL_ERROR("kmalloc for auxilary BD " + IWL_ERROR("kmalloc for auxiliary BD " "structures failed\n"); goto error; } } else txq->txb = NULL; + /* Circular buffer of transmit frame descriptors (TFDs), + * shared with device */ txq->bd = pci_alloc_consistent(dev, sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, &txq->q.dma_addr); @@ -315,24 +334,33 @@ static int iwl_tx_queue_alloc(struct iwl_priv *priv, return -ENOMEM; } -int iwl_tx_queue_init(struct iwl_priv *priv, - struct iwl_tx_queue *txq, int slots_num, u32 txq_id) +/** + * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue + */ +int iwl4965_tx_queue_init(struct iwl4965_priv *priv, + struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id) { struct pci_dev *dev = priv->pci_dev; int len; int rc = 0; - /* alocate command space + one big command for scan since scan - * command is very huge the system will not have two scan at the - * same time */ - len = sizeof(struct iwl_cmd) * slots_num; + /* + * Alloc buffer array for commands (Tx or other types of commands). + * For the command queue (#4), allocate command space + one big + * command for scan, since scan command is very huge; the system will + * not have two scans at the same time, so only one is needed. + * For normal Tx queues (all other queues), no super-size command + * space is needed. + */ + len = sizeof(struct iwl4965_cmd) * slots_num; if (txq_id == IWL_CMD_QUEUE_NUM) len += IWL_MAX_SCAN_SIZE; txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); if (!txq->cmd) return -ENOMEM; - rc = iwl_tx_queue_alloc(priv, txq, txq_id); + /* Alloc driver data array and TFD circular buffer */ + rc = iwl4965_tx_queue_alloc(priv, txq, txq_id); if (rc) { pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); @@ -341,26 +369,29 @@ int iwl_tx_queue_init(struct iwl_priv *priv, txq->need_update = 0; /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise - * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ + * iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */ BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); - iwl_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id); - iwl_hw_tx_queue_init(priv, txq); + /* Initialize queue's high/low-water marks, and head/tail indexes */ + iwl4965_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id); + + /* Tell device where to find queue */ + iwl4965_hw_tx_queue_init(priv, txq); return 0; } /** - * iwl_tx_queue_free - Deallocate DMA queue. + * iwl4965_tx_queue_free - Deallocate DMA queue. * @txq: Transmit queue to deallocate. * * Empty queue by removing and destroying all BD's. - * Free all buffers. txq itself is not freed. - * + * Free all buffers. + * 0-fill, but do not free "txq" descriptor structure. */ -void iwl_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq) +void iwl4965_tx_queue_free(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq) { - struct iwl_queue *q = &txq->q; + struct iwl4965_queue *q = &txq->q; struct pci_dev *dev = priv->pci_dev; int len; @@ -368,45 +399,48 @@ void iwl_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq) return; /* first, empty all BD's */ - for (; q->first_empty != q->last_used; - q->last_used = iwl_queue_inc_wrap(q->last_used, q->n_bd)) - iwl_hw_txq_free_tfd(priv, txq); + for (; q->write_ptr != q->read_ptr; + q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) + iwl4965_hw_txq_free_tfd(priv, txq); - len = sizeof(struct iwl_cmd) * q->n_window; + len = sizeof(struct iwl4965_cmd) * q->n_window; if (q->id == IWL_CMD_QUEUE_NUM) len += IWL_MAX_SCAN_SIZE; + /* De-alloc array of command/tx buffers */ pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); - /* free buffers belonging to queue itself */ + /* De-alloc circular buffer of TFDs */ if (txq->q.n_bd) - pci_free_consistent(dev, sizeof(struct iwl_tfd_frame) * + pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) * txq->q.n_bd, txq->bd, txq->q.dma_addr); + /* De-alloc array of per-TFD driver data */ if (txq->txb) { kfree(txq->txb); txq->txb = NULL; } - /* 0 fill whole structure */ + /* 0-fill queue descriptor structure */ memset(txq, 0, sizeof(*txq)); } -const u8 BROADCAST_ADDR[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; +const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; /*************** STATION TABLE MANAGEMENT **** - * - * NOTE: This needs to be overhauled to better synchronize between - * how the iwl-4965.c is using iwl_hw_find_station vs. iwl-3945.c - * - * mac80211 should also be examined to determine if sta_info is duplicating + * mac80211 should be examined to determine if sta_info is duplicating * the functionality provided here */ /**************************************************************/ -#if 0 /* temparary disable till we add real remove station */ -static u8 iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) +#if 0 /* temporary disable till we add real remove station */ +/** + * iwl4965_remove_station - Remove driver's knowledge of station. + * + * NOTE: This does not remove station from device's station table. + */ +static u8 iwl4965_remove_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap) { int index = IWL_INVALID_STATION; int i; @@ -443,7 +477,12 @@ out: } #endif -static void iwl_clear_stations_table(struct iwl_priv *priv) +/** + * iwl4965_clear_stations_table - Clear the driver's station table + * + * NOTE: This does not clear or otherwise alter the device's station table. + */ +static void iwl4965_clear_stations_table(struct iwl4965_priv *priv) { unsigned long flags; @@ -455,11 +494,15 @@ static void iwl_clear_stations_table(struct iwl_priv *priv) spin_unlock_irqrestore(&priv->sta_lock, flags); } -u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags) +/** + * iwl4965_add_station_flags - Add station to tables in driver and device + */ +u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr, + int is_ap, u8 flags, void *ht_data) { int i; int index = IWL_INVALID_STATION; - struct iwl_station_entry *station; + struct iwl4965_station_entry *station; unsigned long flags_spin; DECLARE_MAC_BUF(mac); @@ -482,8 +525,8 @@ u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags) } - /* These twh conditions has the same outcome but keep them separate - since they have different meaning */ + /* These two conditions have the same outcome, but keep them separate + since they have different meanings */ if (unlikely(index == IWL_INVALID_STATION)) { spin_unlock_irqrestore(&priv->sta_lock, flags_spin); return index; @@ -501,28 +544,32 @@ u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags) station->used = 1; priv->num_stations++; - memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); + /* Set up the REPLY_ADD_STA command to send to device */ + memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd)); memcpy(station->sta.sta.addr, addr, ETH_ALEN); station->sta.mode = 0; station->sta.sta.sta_id = index; station->sta.station_flags = 0; -#ifdef CONFIG_IWLWIFI_HT +#ifdef CONFIG_IWL4965_HT /* BCAST station and IBSS stations do not work in HT mode */ if (index != priv->hw_setting.bcast_sta_id && priv->iw_mode != IEEE80211_IF_TYPE_IBSS) - iwl4965_set_ht_add_station(priv, index); -#endif /*CONFIG_IWLWIFI_HT*/ + iwl4965_set_ht_add_station(priv, index, + (struct ieee80211_ht_info *) ht_data); +#endif /*CONFIG_IWL4965_HT*/ spin_unlock_irqrestore(&priv->sta_lock, flags_spin); - iwl_send_add_station(priv, &station->sta, flags); + + /* Add station to device's station table */ + iwl4965_send_add_station(priv, &station->sta, flags); return index; } /*************** DRIVER STATUS FUNCTIONS *****/ -static inline int iwl_is_ready(struct iwl_priv *priv) +static inline int iwl4965_is_ready(struct iwl4965_priv *priv) { /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are * set but EXIT_PENDING is not */ @@ -531,29 +578,29 @@ static inline int iwl_is_ready(struct iwl_priv *priv) !test_bit(STATUS_EXIT_PENDING, &priv->status); } -static inline int iwl_is_alive(struct iwl_priv *priv) +static inline int iwl4965_is_alive(struct iwl4965_priv *priv) { return test_bit(STATUS_ALIVE, &priv->status); } -static inline int iwl_is_init(struct iwl_priv *priv) +static inline int iwl4965_is_init(struct iwl4965_priv *priv) { return test_bit(STATUS_INIT, &priv->status); } -static inline int iwl_is_rfkill(struct iwl_priv *priv) +static inline int iwl4965_is_rfkill(struct iwl4965_priv *priv) { return test_bit(STATUS_RF_KILL_HW, &priv->status) || test_bit(STATUS_RF_KILL_SW, &priv->status); } -static inline int iwl_is_ready_rf(struct iwl_priv *priv) +static inline int iwl4965_is_ready_rf(struct iwl4965_priv *priv) { - if (iwl_is_rfkill(priv)) + if (iwl4965_is_rfkill(priv)) return 0; - return iwl_is_ready(priv); + return iwl4965_is_ready(priv); } /*************** HOST COMMAND QUEUE FUNCTIONS *****/ @@ -618,7 +665,7 @@ static const char *get_cmd_string(u8 cmd) #define HOST_COMPLETE_TIMEOUT (HZ / 2) /** - * iwl_enqueue_hcmd - enqueue a uCode command + * iwl4965_enqueue_hcmd - enqueue a uCode command * @priv: device private data point * @cmd: a point to the ucode command structure * @@ -626,13 +673,13 @@ static const char *get_cmd_string(u8 cmd) * failed. On success, it turns the index (> 0) of command in the * command queue. */ -static int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) +static int iwl4965_enqueue_hcmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd) { - struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; - struct iwl_queue *q = &txq->q; - struct iwl_tfd_frame *tfd; + struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; + struct iwl4965_queue *q = &txq->q; + struct iwl4965_tfd_frame *tfd; u32 *control_flags; - struct iwl_cmd *out_cmd; + struct iwl4965_cmd *out_cmd; u32 idx; u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); dma_addr_t phys_addr; @@ -645,19 +692,19 @@ static int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && !(cmd->meta.flags & CMD_SIZE_HUGE)); - if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { + if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { IWL_ERROR("No space for Tx\n"); return -ENOSPC; } spin_lock_irqsave(&priv->hcmd_lock, flags); - tfd = &txq->bd[q->first_empty]; + tfd = &txq->bd[q->write_ptr]; memset(tfd, 0, sizeof(*tfd)); control_flags = (u32 *) tfd; - idx = get_cmd_index(q, q->first_empty, cmd->meta.flags & CMD_SIZE_HUGE); + idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE); out_cmd = &txq->cmd[idx]; out_cmd->hdr.cmd = cmd->id; @@ -669,30 +716,34 @@ static int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) out_cmd->hdr.flags = 0; out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) | - INDEX_TO_SEQ(q->first_empty)); + INDEX_TO_SEQ(q->write_ptr)); if (out_cmd->meta.flags & CMD_SIZE_HUGE) out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + - offsetof(struct iwl_cmd, hdr); - iwl_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size); + offsetof(struct iwl4965_cmd, hdr); + iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size); IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " "%d bytes at %d[%d]:%d\n", get_cmd_string(out_cmd->hdr.cmd), out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), - fix_size, q->first_empty, idx, IWL_CMD_QUEUE_NUM); + fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); txq->need_update = 1; + + /* Set up entry in queue's byte count circular buffer */ ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0); - q->first_empty = iwl_queue_inc_wrap(q->first_empty, q->n_bd); - iwl_tx_queue_update_write_ptr(priv, txq); + + /* Increment and update queue's write index */ + q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); + iwl4965_tx_queue_update_write_ptr(priv, txq); spin_unlock_irqrestore(&priv->hcmd_lock, flags); return ret ? ret : idx; } -int iwl_send_cmd_async(struct iwl_priv *priv, struct iwl_host_cmd *cmd) +static int iwl4965_send_cmd_async(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd) { int ret; @@ -707,16 +758,16 @@ int iwl_send_cmd_async(struct iwl_priv *priv, struct iwl_host_cmd *cmd) if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return -EBUSY; - ret = iwl_enqueue_hcmd(priv, cmd); + ret = iwl4965_enqueue_hcmd(priv, cmd); if (ret < 0) { - IWL_ERROR("Error sending %s: iwl_enqueue_hcmd failed: %d\n", + IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", get_cmd_string(cmd->id), ret); return ret; } return 0; } -int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd) +static int iwl4965_send_cmd_sync(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd) { int cmd_idx; int ret; @@ -738,10 +789,10 @@ int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd) if (cmd->meta.flags & CMD_WANT_SKB) cmd->meta.source = &cmd->meta; - cmd_idx = iwl_enqueue_hcmd(priv, cmd); + cmd_idx = iwl4965_enqueue_hcmd(priv, cmd); if (cmd_idx < 0) { ret = cmd_idx; - IWL_ERROR("Error sending %s: iwl_enqueue_hcmd failed: %d\n", + IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", get_cmd_string(cmd->id), ret); goto out; } @@ -785,7 +836,7 @@ int iwl_send_cmd_sync(struct iwl_priv *priv, struct iwl_host_cmd *cmd) cancel: if (cmd->meta.flags & CMD_WANT_SKB) { - struct iwl_cmd *qcmd; + struct iwl4965_cmd *qcmd; /* Cancel the CMD_WANT_SKB flag for the cmd in the * TX cmd queue. Otherwise in case the cmd comes @@ -804,64 +855,75 @@ out: return ret; } -int iwl_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) +int iwl4965_send_cmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd) { - /* A command can not be asynchronous AND expect an SKB to be set. */ - BUG_ON((cmd->meta.flags & CMD_ASYNC) && - (cmd->meta.flags & CMD_WANT_SKB)); - if (cmd->meta.flags & CMD_ASYNC) - return iwl_send_cmd_async(priv, cmd); + return iwl4965_send_cmd_async(priv, cmd); - return iwl_send_cmd_sync(priv, cmd); + return iwl4965_send_cmd_sync(priv, cmd); } -int iwl_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data) +int iwl4965_send_cmd_pdu(struct iwl4965_priv *priv, u8 id, u16 len, const void *data) { - struct iwl_host_cmd cmd = { + struct iwl4965_host_cmd cmd = { .id = id, .len = len, .data = data, }; - return iwl_send_cmd_sync(priv, &cmd); + return iwl4965_send_cmd_sync(priv, &cmd); } -static int __must_check iwl_send_cmd_u32(struct iwl_priv *priv, u8 id, u32 val) +static int __must_check iwl4965_send_cmd_u32(struct iwl4965_priv *priv, u8 id, u32 val) { - struct iwl_host_cmd cmd = { + struct iwl4965_host_cmd cmd = { .id = id, .len = sizeof(val), .data = &val, }; - return iwl_send_cmd_sync(priv, &cmd); + return iwl4965_send_cmd_sync(priv, &cmd); } -int iwl_send_statistics_request(struct iwl_priv *priv) +int iwl4965_send_statistics_request(struct iwl4965_priv *priv) { - return iwl_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); + return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); } /** - * iwl_rxon_add_station - add station into station table. + * iwl4965_rxon_add_station - add station into station table. * * there is only one AP station with id= IWL_AP_ID - * NOTE: mutex must be held before calling the this fnction -*/ -static int iwl_rxon_add_station(struct iwl_priv *priv, + * NOTE: mutex must be held before calling this fnction + */ +static int iwl4965_rxon_add_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap) { u8 sta_id; - sta_id = iwl_add_station(priv, addr, is_ap, 0); + /* Add station to device's station table */ +#ifdef CONFIG_IWL4965_HT + struct ieee80211_conf *conf = &priv->hw->conf; + struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf; + + if ((is_ap) && + (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && + (priv->iw_mode == IEEE80211_IF_TYPE_STA)) + sta_id = iwl4965_add_station_flags(priv, addr, is_ap, + 0, cur_ht_config); + else +#endif /* CONFIG_IWL4965_HT */ + sta_id = iwl4965_add_station_flags(priv, addr, is_ap, + 0, NULL); + + /* Set up default rate scaling table in device's station table */ iwl4965_add_station(priv, addr, is_ap); return sta_id; } /** - * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON + * iwl4965_set_rxon_channel - Set the phymode and channel values in staging RXON * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz * @channel: Any channel valid for the requested phymode @@ -870,9 +932,10 @@ static int iwl_rxon_add_station(struct iwl_priv *priv, * NOTE: Does not commit to the hardware; it sets appropriate bit fields * in the staging RXON flag structure based on the phymode */ -static int iwl_set_rxon_channel(struct iwl_priv *priv, u8 phymode, u16 channel) +static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv, u8 phymode, + u16 channel) { - if (!iwl_get_channel_info(priv, phymode, channel)) { + if (!iwl4965_get_channel_info(priv, phymode, channel)) { IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", channel, phymode); return -EINVAL; @@ -896,13 +959,13 @@ static int iwl_set_rxon_channel(struct iwl_priv *priv, u8 phymode, u16 channel) } /** - * iwl_check_rxon_cmd - validate RXON structure is valid + * iwl4965_check_rxon_cmd - validate RXON structure is valid * * NOTE: This is really only useful during development and can eventually * be #ifdef'd out once the driver is stable and folks aren't actively * making changes */ -static int iwl_check_rxon_cmd(struct iwl_rxon_cmd *rxon) +static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon) { int error = 0; int counter = 1; @@ -962,21 +1025,21 @@ static int iwl_check_rxon_cmd(struct iwl_rxon_cmd *rxon) le16_to_cpu(rxon->channel)); if (error) { - IWL_ERROR("Not a valid iwl_rxon_assoc_cmd field values\n"); + IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); return -1; } return 0; } /** - * iwl_full_rxon_required - determine if RXON_ASSOC can be used in RXON commit - * @priv: staging_rxon is comapred to active_rxon + * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed + * @priv: staging_rxon is compared to active_rxon * - * If the RXON structure is changing sufficient to require a new - * tune or to clear and reset the RXON_FILTER_ASSOC_MSK then return 1 - * to indicate a new tune is required. + * If the RXON structure is changing enough to require a new tune, + * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that + * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. */ -static int iwl_full_rxon_required(struct iwl_priv *priv) +static int iwl4965_full_rxon_required(struct iwl4965_priv *priv) { /* These items are only settable from the full RXON command */ @@ -1016,19 +1079,19 @@ static int iwl_full_rxon_required(struct iwl_priv *priv) return 0; } -static int iwl_send_rxon_assoc(struct iwl_priv *priv) +static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv) { int rc = 0; - struct iwl_rx_packet *res = NULL; - struct iwl_rxon_assoc_cmd rxon_assoc; - struct iwl_host_cmd cmd = { + struct iwl4965_rx_packet *res = NULL; + struct iwl4965_rxon_assoc_cmd rxon_assoc; + struct iwl4965_host_cmd cmd = { .id = REPLY_RXON_ASSOC, .len = sizeof(rxon_assoc), .meta.flags = CMD_WANT_SKB, .data = &rxon_assoc, }; - const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon; - const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon; + const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon; + const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon; if ((rxon1->flags == rxon2->flags) && (rxon1->filter_flags == rxon2->filter_flags) && @@ -1054,11 +1117,11 @@ static int iwl_send_rxon_assoc(struct iwl_priv *priv) priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; - rc = iwl_send_cmd_sync(priv, &cmd); + rc = iwl4965_send_cmd_sync(priv, &cmd); if (rc) return rc; - res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; + res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; if (res->hdr.flags & IWL_CMD_FAILED_MSK) { IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n"); rc = -EIO; @@ -1071,37 +1134,37 @@ static int iwl_send_rxon_assoc(struct iwl_priv *priv) } /** - * iwl_commit_rxon - commit staging_rxon to hardware + * iwl4965_commit_rxon - commit staging_rxon to hardware * - * The RXON command in staging_rxon is commited to the hardware and + * The RXON command in staging_rxon is committed to the hardware and * the active_rxon structure is updated with the new data. This * function correctly transitions out of the RXON_ASSOC_MSK state if * a HW tune is required based on the RXON structure changes. */ -static int iwl_commit_rxon(struct iwl_priv *priv) +static int iwl4965_commit_rxon(struct iwl4965_priv *priv) { /* cast away the const for active_rxon in this function */ - struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; + struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon; DECLARE_MAC_BUF(mac); int rc = 0; - if (!iwl_is_alive(priv)) + if (!iwl4965_is_alive(priv)) return -1; /* always get timestamp with Rx frame */ priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; - rc = iwl_check_rxon_cmd(&priv->staging_rxon); + rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); if (rc) { IWL_ERROR("Invalid RXON configuration. Not committing.\n"); return -EINVAL; } /* If we don't need to send a full RXON, we can use - * iwl_rxon_assoc_cmd which is used to reconfigure filter + * iwl4965_rxon_assoc_cmd which is used to reconfigure filter * and other flags for the current radio configuration. */ - if (!iwl_full_rxon_required(priv)) { - rc = iwl_send_rxon_assoc(priv); + if (!iwl4965_full_rxon_required(priv)) { + rc = iwl4965_send_rxon_assoc(priv); if (rc) { IWL_ERROR("Error setting RXON_ASSOC " "configuration (%d).\n", rc); @@ -1116,25 +1179,25 @@ static int iwl_commit_rxon(struct iwl_priv *priv) /* station table will be cleared */ priv->assoc_station_added = 0; -#ifdef CONFIG_IWLWIFI_SENSITIVITY +#ifdef CONFIG_IWL4965_SENSITIVITY priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; if (!priv->error_recovering) priv->start_calib = 0; iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); -#endif /* CONFIG_IWLWIFI_SENSITIVITY */ +#endif /* CONFIG_IWL4965_SENSITIVITY */ /* If we are currently associated and the new config requires * an RXON_ASSOC and the new config wants the associated mask enabled, * we must clear the associated from the active configuration * before we apply the new config */ - if (iwl_is_associated(priv) && + if (iwl4965_is_associated(priv) && (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; - rc = iwl_send_cmd_pdu(priv, REPLY_RXON, - sizeof(struct iwl_rxon_cmd), + rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, + sizeof(struct iwl4965_rxon_cmd), &priv->active_rxon); /* If the mask clearing failed then we set @@ -1157,35 +1220,35 @@ static int iwl_commit_rxon(struct iwl_priv *priv) print_mac(mac, priv->staging_rxon.bssid_addr)); /* Apply the new configuration */ - rc = iwl_send_cmd_pdu(priv, REPLY_RXON, - sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); + rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, + sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon); if (rc) { IWL_ERROR("Error setting new configuration (%d).\n", rc); return rc; } - iwl_clear_stations_table(priv); + iwl4965_clear_stations_table(priv); -#ifdef CONFIG_IWLWIFI_SENSITIVITY +#ifdef CONFIG_IWL4965_SENSITIVITY if (!priv->error_recovering) priv->start_calib = 0; priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); -#endif /* CONFIG_IWLWIFI_SENSITIVITY */ +#endif /* CONFIG_IWL4965_SENSITIVITY */ memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); /* If we issue a new RXON command which required a tune then we must * send a new TXPOWER command or we won't be able to Tx any frames */ - rc = iwl_hw_reg_send_txpower(priv); + rc = iwl4965_hw_reg_send_txpower(priv); if (rc) { IWL_ERROR("Error setting Tx power (%d).\n", rc); return rc; } /* Add the broadcast address so we can send broadcast frames */ - if (iwl_rxon_add_station(priv, BROADCAST_ADDR, 0) == + if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) == IWL_INVALID_STATION) { IWL_ERROR("Error adding BROADCAST address for transmit.\n"); return -EIO; @@ -1193,9 +1256,9 @@ static int iwl_commit_rxon(struct iwl_priv *priv) /* If we have set the ASSOC_MSK and we are in BSS mode then * add the IWL_AP_ID to the station rate table */ - if (iwl_is_associated(priv) && + if (iwl4965_is_associated(priv) && (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { - if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) + if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) == IWL_INVALID_STATION) { IWL_ERROR("Error adding AP address for transmit.\n"); return -EIO; @@ -1206,9 +1269,9 @@ static int iwl_commit_rxon(struct iwl_priv *priv) return 0; } -static int iwl_send_bt_config(struct iwl_priv *priv) +static int iwl4965_send_bt_config(struct iwl4965_priv *priv) { - struct iwl_bt_cmd bt_cmd = { + struct iwl4965_bt_cmd bt_cmd = { .flags = 3, .lead_time = 0xAA, .max_kill = 1, @@ -1216,15 +1279,15 @@ static int iwl_send_bt_config(struct iwl_priv *priv) .kill_cts_mask = 0, }; - return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, - sizeof(struct iwl_bt_cmd), &bt_cmd); + return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG, + sizeof(struct iwl4965_bt_cmd), &bt_cmd); } -static int iwl_send_scan_abort(struct iwl_priv *priv) +static int iwl4965_send_scan_abort(struct iwl4965_priv *priv) { int rc = 0; - struct iwl_rx_packet *res; - struct iwl_host_cmd cmd = { + struct iwl4965_rx_packet *res; + struct iwl4965_host_cmd cmd = { .id = REPLY_SCAN_ABORT_CMD, .meta.flags = CMD_WANT_SKB, }; @@ -1237,13 +1300,13 @@ static int iwl_send_scan_abort(struct iwl_priv *priv) return 0; } - rc = iwl_send_cmd_sync(priv, &cmd); + rc = iwl4965_send_cmd_sync(priv, &cmd); if (rc) { clear_bit(STATUS_SCAN_ABORTING, &priv->status); return rc; } - res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; + res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; if (res->u.status != CAN_ABORT_STATUS) { /* The scan abort will return 1 for success or * 2 for "failure". A failure condition can be @@ -1261,8 +1324,8 @@ static int iwl_send_scan_abort(struct iwl_priv *priv) return rc; } -static int iwl_card_state_sync_callback(struct iwl_priv *priv, - struct iwl_cmd *cmd, +static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv, + struct iwl4965_cmd *cmd, struct sk_buff *skb) { return 1; @@ -1271,16 +1334,16 @@ static int iwl_card_state_sync_callback(struct iwl_priv *priv, /* * CARD_STATE_CMD * - * Use: Sets the internal card state to enable, disable, or halt + * Use: Sets the device's internal card state to enable, disable, or halt * * When in the 'enable' state the card operates as normal. * When in the 'disable' state, the card enters into a low power mode. * When in the 'halt' state, the card is shut down and must be fully * restarted to come back on. */ -static int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag) +static int iwl4965_send_card_state(struct iwl4965_priv *priv, u32 flags, u8 meta_flag) { - struct iwl_host_cmd cmd = { + struct iwl4965_host_cmd cmd = { .id = REPLY_CARD_STATE_CMD, .len = sizeof(u32), .data = &flags, @@ -1288,22 +1351,22 @@ static int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag) }; if (meta_flag & CMD_ASYNC) - cmd.meta.u.callback = iwl_card_state_sync_callback; + cmd.meta.u.callback = iwl4965_card_state_sync_callback; - return iwl_send_cmd(priv, &cmd); + return iwl4965_send_cmd(priv, &cmd); } -static int iwl_add_sta_sync_callback(struct iwl_priv *priv, - struct iwl_cmd *cmd, struct sk_buff *skb) +static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv, + struct iwl4965_cmd *cmd, struct sk_buff *skb) { - struct iwl_rx_packet *res = NULL; + struct iwl4965_rx_packet *res = NULL; if (!skb) { IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n"); return 1; } - res = (struct iwl_rx_packet *)skb->data; + res = (struct iwl4965_rx_packet *)skb->data; if (res->hdr.flags & IWL_CMD_FAILED_MSK) { IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", res->hdr.flags); @@ -1321,29 +1384,29 @@ static int iwl_add_sta_sync_callback(struct iwl_priv *priv, return 1; } -int iwl_send_add_station(struct iwl_priv *priv, - struct iwl_addsta_cmd *sta, u8 flags) +int iwl4965_send_add_station(struct iwl4965_priv *priv, + struct iwl4965_addsta_cmd *sta, u8 flags) { - struct iwl_rx_packet *res = NULL; + struct iwl4965_rx_packet *res = NULL; int rc = 0; - struct iwl_host_cmd cmd = { + struct iwl4965_host_cmd cmd = { .id = REPLY_ADD_STA, - .len = sizeof(struct iwl_addsta_cmd), + .len = sizeof(struct iwl4965_addsta_cmd), .meta.flags = flags, .data = sta, }; if (flags & CMD_ASYNC) - cmd.meta.u.callback = iwl_add_sta_sync_callback; + cmd.meta.u.callback = iwl4965_add_sta_sync_callback; else cmd.meta.flags |= CMD_WANT_SKB; - rc = iwl_send_cmd(priv, &cmd); + rc = iwl4965_send_cmd(priv, &cmd); if (rc || (flags & CMD_ASYNC)) return rc; - res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; + res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; if (res->hdr.flags & IWL_CMD_FAILED_MSK) { IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", res->hdr.flags); @@ -1368,7 +1431,7 @@ int iwl_send_add_station(struct iwl_priv *priv, return rc; } -static int iwl_update_sta_key_info(struct iwl_priv *priv, +static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv, struct ieee80211_key_conf *keyconf, u8 sta_id) { @@ -1384,7 +1447,6 @@ static int iwl_update_sta_key_info(struct iwl_priv *priv, break; case ALG_TKIP: case ALG_WEP: - return -EINVAL; default: return -EINVAL; } @@ -1403,28 +1465,28 @@ static int iwl_update_sta_key_info(struct iwl_priv *priv, spin_unlock_irqrestore(&priv->sta_lock, flags); IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); - iwl_send_add_station(priv, &priv->stations[sta_id].sta, 0); + iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); return 0; } -static int iwl_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id) +static int iwl4965_clear_sta_key_info(struct iwl4965_priv *priv, u8 sta_id) { unsigned long flags; spin_lock_irqsave(&priv->sta_lock, flags); - memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key)); - memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl_keyinfo)); + memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key)); + memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo)); priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; spin_unlock_irqrestore(&priv->sta_lock, flags); IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); - iwl_send_add_station(priv, &priv->stations[sta_id].sta, 0); + iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); return 0; } -static void iwl_clear_free_frames(struct iwl_priv *priv) +static void iwl4965_clear_free_frames(struct iwl4965_priv *priv) { struct list_head *element; @@ -1434,7 +1496,7 @@ static void iwl_clear_free_frames(struct iwl_priv *priv) while (!list_empty(&priv->free_frames)) { element = priv->free_frames.next; list_del(element); - kfree(list_entry(element, struct iwl_frame, list)); + kfree(list_entry(element, struct iwl4965_frame, list)); priv->frames_count--; } @@ -1445,9 +1507,9 @@ static void iwl_clear_free_frames(struct iwl_priv *priv) } } -static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) +static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv) { - struct iwl_frame *frame; + struct iwl4965_frame *frame; struct list_head *element; if (list_empty(&priv->free_frames)) { frame = kzalloc(sizeof(*frame), GFP_KERNEL); @@ -1462,21 +1524,21 @@ static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) element = priv->free_frames.next; list_del(element); - return list_entry(element, struct iwl_frame, list); + return list_entry(element, struct iwl4965_frame, list); } -static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame) +static void iwl4965_free_frame(struct iwl4965_priv *priv, struct iwl4965_frame *frame) { memset(frame, 0, sizeof(*frame)); list_add(&frame->list, &priv->free_frames); } -unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv, +unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv, struct ieee80211_hdr *hdr, const u8 *dest, int left) { - if (!iwl_is_associated(priv) || !priv->ibss_beacon || + if (!iwl4965_is_associated(priv) || !priv->ibss_beacon || ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && (priv->iw_mode != IEEE80211_IF_TYPE_AP))) return 0; @@ -1489,10 +1551,11 @@ unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv, return priv->ibss_beacon->len; } -int iwl_rate_index_from_plcp(int plcp) +int iwl4965_rate_index_from_plcp(int plcp) { int i = 0; + /* 4965 HT rate format */ if (plcp & RATE_MCS_HT_MSK) { i = (plcp & 0xff); @@ -1506,35 +1569,37 @@ int iwl_rate_index_from_plcp(int plcp) if ((i >= IWL_FIRST_OFDM_RATE) && (i <= IWL_LAST_OFDM_RATE)) return i; + + /* 4965 legacy rate format, search for match in table */ } else { - for (i = 0; i < ARRAY_SIZE(iwl_rates); i++) - if (iwl_rates[i].plcp == (plcp &0xFF)) + for (i = 0; i < ARRAY_SIZE(iwl4965_rates); i++) + if (iwl4965_rates[i].plcp == (plcp &0xFF)) return i; } return -1; } -static u8 iwl_rate_get_lowest_plcp(int rate_mask) +static u8 iwl4965_rate_get_lowest_plcp(int rate_mask) { u8 i; for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; - i = iwl_rates[i].next_ieee) { + i = iwl4965_rates[i].next_ieee) { if (rate_mask & (1 << i)) - return iwl_rates[i].plcp; + return iwl4965_rates[i].plcp; } return IWL_RATE_INVALID; } -static int iwl_send_beacon_cmd(struct iwl_priv *priv) +static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv) { - struct iwl_frame *frame; + struct iwl4965_frame *frame; unsigned int frame_size; int rc; u8 rate; - frame = iwl_get_free_frame(priv); + frame = iwl4965_get_free_frame(priv); if (!frame) { IWL_ERROR("Could not obtain free frame buffer for beacon " @@ -1543,22 +1608,22 @@ static int iwl_send_beacon_cmd(struct iwl_priv *priv) } if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { - rate = iwl_rate_get_lowest_plcp(priv->active_rate_basic & + rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xFF0); if (rate == IWL_INVALID_RATE) rate = IWL_RATE_6M_PLCP; } else { - rate = iwl_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); + rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); if (rate == IWL_INVALID_RATE) rate = IWL_RATE_1M_PLCP; } - frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate); + frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); - rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, + rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, &frame->u.cmd[0]); - iwl_free_frame(priv, frame); + iwl4965_free_frame(priv, frame); return rc; } @@ -1569,22 +1634,22 @@ static int iwl_send_beacon_cmd(struct iwl_priv *priv) * ******************************************************************************/ -static void get_eeprom_mac(struct iwl_priv *priv, u8 *mac) +static void get_eeprom_mac(struct iwl4965_priv *priv, u8 *mac) { memcpy(mac, priv->eeprom.mac_address, 6); } /** - * iwl_eeprom_init - read EEPROM contents + * iwl4965_eeprom_init - read EEPROM contents * - * Load the EEPROM from adapter into priv->eeprom + * Load the EEPROM contents from adapter into priv->eeprom * * NOTE: This routine uses the non-debug IO access functions. */ -int iwl_eeprom_init(struct iwl_priv *priv) +int iwl4965_eeprom_init(struct iwl4965_priv *priv) { - u16 *e = (u16 *)&priv->eeprom; - u32 gp = iwl_read32(priv, CSR_EEPROM_GP); + __le16 *e = (__le16 *)&priv->eeprom; + u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP); u32 r; int sz = sizeof(priv->eeprom); int rc; @@ -1602,20 +1667,21 @@ int iwl_eeprom_init(struct iwl_priv *priv) return -ENOENT; } - rc = iwl_eeprom_aqcuire_semaphore(priv); + /* Make sure driver (instead of uCode) is allowed to read EEPROM */ + rc = iwl4965_eeprom_acquire_semaphore(priv); if (rc < 0) { - IWL_ERROR("Failed to aqcuire EEPROM semaphore.\n"); + IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); return -ENOENT; } /* eeprom is an array of 16bit values */ for (addr = 0; addr < sz; addr += sizeof(u16)) { - _iwl_write32(priv, CSR_EEPROM_REG, addr << 1); - _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); + _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1); + _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT; i += IWL_EEPROM_ACCESS_DELAY) { - r = _iwl_read_restricted(priv, CSR_EEPROM_REG); + r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG); if (r & CSR_EEPROM_REG_READ_VALID_MSK) break; udelay(IWL_EEPROM_ACCESS_DELAY); @@ -1626,12 +1692,12 @@ int iwl_eeprom_init(struct iwl_priv *priv) rc = -ETIMEDOUT; goto done; } - e[addr / 2] = le16_to_cpu(r >> 16); + e[addr / 2] = cpu_to_le16(r >> 16); } rc = 0; done: - iwl_eeprom_release_semaphore(priv); + iwl4965_eeprom_release_semaphore(priv); return rc; } @@ -1640,22 +1706,20 @@ done: * Misc. internal state and helper functions * ******************************************************************************/ -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL4965_DEBUG /** - * iwl_report_frame - dump frame to syslog during debug sessions + * iwl4965_report_frame - dump frame to syslog during debug sessions * - * hack this function to show different aspects of received frames, + * You may hack this function to show different aspects of received frames, * including selective frame dumps. * group100 parameter selects whether to show 1 out of 100 good frames. * - * TODO: ieee80211_hdr stuff is common to 3945 and 4965, so frame type - * info output is okay, but some of this stuff (e.g. iwl_rx_frame_stats) - * is 3945-specific and gives bad output for 4965. Need to split the - * functionality, keep common stuff here. + * TODO: This was originally written for 3945, need to audit for + * proper operation with 4965. */ -void iwl_report_frame(struct iwl_priv *priv, - struct iwl_rx_packet *pkt, +void iwl4965_report_frame(struct iwl4965_priv *priv, + struct iwl4965_rx_packet *pkt, struct ieee80211_hdr *header, int group100) { u32 to_us; @@ -1677,9 +1741,9 @@ void iwl_report_frame(struct iwl_priv *priv, u8 agc; u16 sig_avg; u16 noise_diff; - struct iwl_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); - struct iwl_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); - struct iwl_rx_frame_end *rx_end = IWL_RX_END(pkt); + struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); + struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); + struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt); u8 *data = IWL_RX_DATA(pkt); /* MAC header */ @@ -1755,11 +1819,11 @@ void iwl_report_frame(struct iwl_priv *priv, else title = "Frame"; - rate = iwl_rate_index_from_plcp(rate_sym); + rate = iwl4965_rate_index_from_plcp(rate_sym); if (rate == -1) rate = 0; else - rate = iwl_rates[rate].ieee / 2; + rate = iwl4965_rates[rate].ieee / 2; /* print frame summary. * MAC addresses show just the last byte (for brevity), @@ -1781,25 +1845,25 @@ void iwl_report_frame(struct iwl_priv *priv, } } if (print_dump) - iwl_print_hex_dump(IWL_DL_RX, data, length); + iwl4965_print_hex_dump(IWL_DL_RX, data, length); } #endif -static void iwl_unset_hw_setting(struct iwl_priv *priv) +static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv) { if (priv->hw_setting.shared_virt) pci_free_consistent(priv->pci_dev, - sizeof(struct iwl_shared), + sizeof(struct iwl4965_shared), priv->hw_setting.shared_virt, priv->hw_setting.shared_phys); } /** - * iwl_supported_rate_to_ie - fill in the supported rate in IE field + * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field * * return : set the bit for each supported rate insert in ie */ -static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate, +static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, u16 basic_rate, int *left) { u16 ret_rates = 0, bit; @@ -1810,7 +1874,7 @@ static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate, for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { if (bit & supported_rate) { ret_rates |= bit; - rates[*cnt] = iwl_rates[i].ieee | + rates[*cnt] = iwl4965_rates[i].ieee | ((bit & basic_rate) ? 0x80 : 0x00); (*cnt)++; (*left)--; @@ -1823,22 +1887,25 @@ static u16 iwl_supported_rate_to_ie(u8 *ie, u16 supported_rate, return ret_rates; } -#ifdef CONFIG_IWLWIFI_HT -void static iwl_set_ht_capab(struct ieee80211_hw *hw, - struct ieee80211_ht_capability *ht_cap, - u8 use_wide_chan); +#ifdef CONFIG_IWL4965_HT +void static iwl4965_set_ht_capab(struct ieee80211_hw *hw, + struct ieee80211_ht_cap *ht_cap, + u8 use_current_config); #endif /** - * iwl_fill_probe_req - fill in all required fields and IE for probe request + * iwl4965_fill_probe_req - fill in all required fields and IE for probe request */ -static u16 iwl_fill_probe_req(struct iwl_priv *priv, +static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv, struct ieee80211_mgmt *frame, int left, int is_direct) { int len = 0; u8 *pos = NULL; - u16 active_rates, ret_rates, cck_rates; + u16 active_rates, ret_rates, cck_rates, active_rate_basic; +#ifdef CONFIG_IWL4965_HT + struct ieee80211_hw_mode *mode; +#endif /* CONFIG_IWL4965_HT */ /* Make sure there is enough space for the probe request, * two mandatory IEs and the data */ @@ -1848,9 +1915,9 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv, len += 24; frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); - memcpy(frame->da, BROADCAST_ADDR, ETH_ALEN); + memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); memcpy(frame->sa, priv->mac_addr, ETH_ALEN); - memcpy(frame->bssid, BROADCAST_ADDR, ETH_ALEN); + memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); frame->seq_ctrl = 0; /* fill in our indirect SSID IE */ @@ -1888,17 +1955,19 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv, *pos++ = WLAN_EID_SUPP_RATES; *pos = 0; - priv->active_rate = priv->rates_mask; - active_rates = priv->active_rate; - priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; + /* exclude 60M rate */ + active_rates = priv->rates_mask; + active_rates &= ~IWL_RATE_60M_MASK; + + active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; cck_rates = IWL_CCK_RATES_MASK & active_rates; - ret_rates = iwl_supported_rate_to_ie(pos, cck_rates, - priv->active_rate_basic, &left); + ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, + active_rate_basic, &left); active_rates &= ~ret_rates; - ret_rates = iwl_supported_rate_to_ie(pos, active_rates, - priv->active_rate_basic, &left); + ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, + active_rate_basic, &left); active_rates &= ~ret_rates; len += 2 + *pos; @@ -1914,25 +1983,22 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv, /* ... fill it in... */ *pos++ = WLAN_EID_EXT_SUPP_RATES; *pos = 0; - iwl_supported_rate_to_ie(pos, active_rates, - priv->active_rate_basic, &left); + iwl4965_supported_rate_to_ie(pos, active_rates, + active_rate_basic, &left); if (*pos > 0) len += 2 + *pos; -#ifdef CONFIG_IWLWIFI_HT - if (is_direct && priv->is_ht_enabled) { - u8 use_wide_chan = 1; - - if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ) - use_wide_chan = 0; +#ifdef CONFIG_IWL4965_HT + mode = priv->hw->conf.mode; + if (mode->ht_info.ht_supported) { pos += (*pos) + 1; *pos++ = WLAN_EID_HT_CAPABILITY; - *pos++ = sizeof(struct ieee80211_ht_capability); - iwl_set_ht_capab(NULL, (struct ieee80211_ht_capability *)pos, - use_wide_chan); - len += 2 + sizeof(struct ieee80211_ht_capability); + *pos++ = sizeof(struct ieee80211_ht_cap); + iwl4965_set_ht_capab(priv->hw, + (struct ieee80211_ht_cap *)pos, 0); + len += 2 + sizeof(struct ieee80211_ht_cap); } -#endif /*CONFIG_IWLWIFI_HT */ +#endif /*CONFIG_IWL4965_HT */ fill_end: return (u16)len; @@ -1941,16 +2007,16 @@ static u16 iwl_fill_probe_req(struct iwl_priv *priv, /* * QoS support */ -#ifdef CONFIG_IWLWIFI_QOS -static int iwl_send_qos_params_command(struct iwl_priv *priv, - struct iwl_qosparam_cmd *qos) +#ifdef CONFIG_IWL4965_QOS +static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv, + struct iwl4965_qosparam_cmd *qos) { - return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, - sizeof(struct iwl_qosparam_cmd), qos); + return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM, + sizeof(struct iwl4965_qosparam_cmd), qos); } -static void iwl_reset_qos(struct iwl_priv *priv) +static void iwl4965_reset_qos(struct iwl4965_priv *priv) { u16 cw_min = 15; u16 cw_max = 1023; @@ -2037,13 +2103,10 @@ static void iwl_reset_qos(struct iwl_priv *priv) spin_unlock_irqrestore(&priv->lock, flags); } -static void iwl_activate_qos(struct iwl_priv *priv, u8 force) +static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force) { unsigned long flags; - if (priv == NULL) - return; - if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; @@ -2057,23 +2120,28 @@ static void iwl_activate_qos(struct iwl_priv *priv, u8 force) !priv->qos_data.qos_cap.q_AP.txop_request) priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TXOP_TYPE_MSK; - if (priv->qos_data.qos_active) priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_UPDATE_EDCA_MSK; +#ifdef CONFIG_IWL4965_HT + if (priv->current_ht_config.is_ht) + priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; +#endif /* CONFIG_IWL4965_HT */ + spin_unlock_irqrestore(&priv->lock, flags); - if (force || iwl_is_associated(priv)) { - IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n", - priv->qos_data.qos_active); + if (force || iwl4965_is_associated(priv)) { + IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", + priv->qos_data.qos_active, + priv->qos_data.def_qos_parm.qos_flags); - iwl_send_qos_params_command(priv, + iwl4965_send_qos_params_command(priv, &(priv->qos_data.def_qos_parm)); } } -#endif /* CONFIG_IWLWIFI_QOS */ +#endif /* CONFIG_IWL4965_QOS */ /* * Power management (not Tx power!) functions */ @@ -2091,7 +2159,7 @@ static void iwl_activate_qos(struct iwl_priv *priv, u8 force) /* default power management (not Tx power) table values */ /* for tim 0-10 */ -static struct iwl_power_vec_entry range_0[IWL_POWER_AC] = { +static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = { {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, @@ -2101,7 +2169,7 @@ static struct iwl_power_vec_entry range_0[IWL_POWER_AC] = { }; /* for tim > 10 */ -static struct iwl_power_vec_entry range_1[IWL_POWER_AC] = { +static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = { {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, @@ -2114,11 +2182,11 @@ static struct iwl_power_vec_entry range_1[IWL_POWER_AC] = { SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} }; -int iwl_power_init_handle(struct iwl_priv *priv) +int iwl4965_power_init_handle(struct iwl4965_priv *priv) { int rc = 0, i; - struct iwl_power_mgr *pow_data; - int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_AC; + struct iwl4965_power_mgr *pow_data; + int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC; u16 pci_pm; IWL_DEBUG_POWER("Initialize power \n"); @@ -2137,7 +2205,7 @@ int iwl_power_init_handle(struct iwl_priv *priv) if (rc != 0) return 0; else { - struct iwl_powertable_cmd *cmd; + struct iwl4965_powertable_cmd *cmd; IWL_DEBUG_POWER("adjust power command flags\n"); @@ -2153,15 +2221,15 @@ int iwl_power_init_handle(struct iwl_priv *priv) return rc; } -static int iwl_update_power_cmd(struct iwl_priv *priv, - struct iwl_powertable_cmd *cmd, u32 mode) +static int iwl4965_update_power_cmd(struct iwl4965_priv *priv, + struct iwl4965_powertable_cmd *cmd, u32 mode) { int rc = 0, i; u8 skip; u32 max_sleep = 0; - struct iwl_power_vec_entry *range; + struct iwl4965_power_vec_entry *range; u8 period = 0; - struct iwl_power_mgr *pow_data; + struct iwl4965_power_mgr *pow_data; if (mode > IWL_POWER_INDEX_5) { IWL_DEBUG_POWER("Error invalid power mode \n"); @@ -2174,7 +2242,7 @@ static int iwl_update_power_cmd(struct iwl_priv *priv, else range = &pow_data->pwr_range_1[1]; - memcpy(cmd, &range[mode].cmd, sizeof(struct iwl_powertable_cmd)); + memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd)); #ifdef IWL_MAC80211_DISABLE if (priv->assoc_network != NULL) { @@ -2217,14 +2285,14 @@ static int iwl_update_power_cmd(struct iwl_priv *priv, return rc; } -static int iwl_send_power_mode(struct iwl_priv *priv, u32 mode) +static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode) { - u32 final_mode = mode; + u32 uninitialized_var(final_mode); int rc; - struct iwl_powertable_cmd cmd; + struct iwl4965_powertable_cmd cmd; /* If on battery, set to 3, - * if plugged into AC power, set to CAM ("continuosly aware mode"), + * if plugged into AC power, set to CAM ("continuously aware mode"), * else user level */ switch (mode) { case IWL_POWER_BATTERY: @@ -2240,9 +2308,9 @@ static int iwl_send_power_mode(struct iwl_priv *priv, u32 mode) cmd.keep_alive_beacons = 0; - iwl_update_power_cmd(priv, &cmd, final_mode); + iwl4965_update_power_cmd(priv, &cmd, final_mode); - rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); + rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); if (final_mode == IWL_POWER_MODE_CAM) clear_bit(STATUS_POWER_PMI, &priv->status); @@ -2252,7 +2320,7 @@ static int iwl_send_power_mode(struct iwl_priv *priv, u32 mode) return rc; } -int iwl_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) +int iwl4965_is_network_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header) { /* Filter incoming packets to determine if they are targeted toward * this network, discarding packets coming from ourselves */ @@ -2282,7 +2350,7 @@ int iwl_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x -const char *iwl_get_tx_fail_reason(u32 status) +static const char *iwl4965_get_tx_fail_reason(u32 status) { switch (status & TX_STATUS_MSK) { case TX_STATUS_SUCCESS: @@ -2309,11 +2377,11 @@ const char *iwl_get_tx_fail_reason(u32 status) } /** - * iwl_scan_cancel - Cancel any currently executing HW scan + * iwl4965_scan_cancel - Cancel any currently executing HW scan * * NOTE: priv->mutex is not required before calling this function */ -static int iwl_scan_cancel(struct iwl_priv *priv) +static int iwl4965_scan_cancel(struct iwl4965_priv *priv) { if (!test_bit(STATUS_SCAN_HW, &priv->status)) { clear_bit(STATUS_SCANNING, &priv->status); @@ -2336,17 +2404,17 @@ static int iwl_scan_cancel(struct iwl_priv *priv) } /** - * iwl_scan_cancel_timeout - Cancel any currently executing HW scan + * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan * @ms: amount of time to wait (in milliseconds) for scan to abort * * NOTE: priv->mutex must be held before calling this function */ -static int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) +static int iwl4965_scan_cancel_timeout(struct iwl4965_priv *priv, unsigned long ms) { unsigned long now = jiffies; int ret; - ret = iwl_scan_cancel(priv); + ret = iwl4965_scan_cancel(priv); if (ret && ms) { mutex_unlock(&priv->mutex); while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && @@ -2360,7 +2428,7 @@ static int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) return ret; } -static void iwl_sequence_reset(struct iwl_priv *priv) +static void iwl4965_sequence_reset(struct iwl4965_priv *priv) { /* Reset ieee stats */ @@ -2371,13 +2439,13 @@ static void iwl_sequence_reset(struct iwl_priv *priv) priv->last_frag_num = -1; priv->last_packet_time = 0; - iwl_scan_cancel(priv); + iwl4965_scan_cancel(priv); } #define MAX_UCODE_BEACON_INTERVAL 4096 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) -static __le16 iwl_adjust_beacon_interval(u16 beacon_val) +static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) { u16 new_val = 0; u16 beacon_factor = 0; @@ -2390,7 +2458,7 @@ static __le16 iwl_adjust_beacon_interval(u16 beacon_val) return cpu_to_le16(new_val); } -static void iwl_setup_rxon_timing(struct iwl_priv *priv) +static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv) { u64 interval_tm_unit; u64 tsf, result; @@ -2420,14 +2488,14 @@ static void iwl_setup_rxon_timing(struct iwl_priv *priv) priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int); priv->rxon_timing.beacon_interval = - iwl_adjust_beacon_interval( + iwl4965_adjust_beacon_interval( le16_to_cpu(priv->rxon_timing.beacon_interval)); } priv->rxon_timing.atim_window = 0; } else { priv->rxon_timing.beacon_interval = - iwl_adjust_beacon_interval(conf->beacon_int); + iwl4965_adjust_beacon_interval(conf->beacon_int); /* TODO: we need to get atim_window from upper stack * for now we set to 0 */ priv->rxon_timing.atim_window = 0; @@ -2446,14 +2514,14 @@ static void iwl_setup_rxon_timing(struct iwl_priv *priv) le16_to_cpu(priv->rxon_timing.atim_window)); } -static int iwl_scan_initiate(struct iwl_priv *priv) +static int iwl4965_scan_initiate(struct iwl4965_priv *priv) { if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { IWL_ERROR("APs don't scan.\n"); return 0; } - if (!iwl_is_ready_rf(priv)) { + if (!iwl4965_is_ready_rf(priv)) { IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); return -EIO; } @@ -2480,9 +2548,9 @@ static int iwl_scan_initiate(struct iwl_priv *priv) return 0; } -static int iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) +static int iwl4965_set_rxon_hwcrypto(struct iwl4965_priv *priv, int hw_decrypt) { - struct iwl_rxon_cmd *rxon = &priv->staging_rxon; + struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; if (hw_decrypt) rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; @@ -2492,7 +2560,7 @@ static int iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) return 0; } -static void iwl_set_flags_for_phymode(struct iwl_priv *priv, u8 phymode) +static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode) { if (phymode == MODE_IEEE80211A) { priv->staging_rxon.flags &= @@ -2500,7 +2568,7 @@ static void iwl_set_flags_for_phymode(struct iwl_priv *priv, u8 phymode) | RXON_FLG_CCK_MSK); priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; } else { - /* Copied from iwl_bg_post_associate() */ + /* Copied from iwl4965_bg_post_associate() */ if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; else @@ -2516,11 +2584,11 @@ static void iwl_set_flags_for_phymode(struct iwl_priv *priv, u8 phymode) } /* - * initilize rxon structure with default values fromm eeprom + * initialize rxon structure with default values from eeprom */ -static void iwl_connection_init_rx_config(struct iwl_priv *priv) +static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv) { - const struct iwl_channel_info *ch_info; + const struct iwl4965_channel_info *ch_info; memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); @@ -2557,7 +2625,7 @@ static void iwl_connection_init_rx_config(struct iwl_priv *priv) priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; #endif - ch_info = iwl_get_channel_info(priv, priv->phymode, + ch_info = iwl4965_get_channel_info(priv, priv->phymode, le16_to_cpu(priv->staging_rxon.channel)); if (!ch_info) @@ -2577,7 +2645,7 @@ static void iwl_connection_init_rx_config(struct iwl_priv *priv) else priv->phymode = MODE_IEEE80211G; - iwl_set_flags_for_phymode(priv, priv->phymode); + iwl4965_set_flags_for_phymode(priv, priv->phymode); priv->staging_rxon.ofdm_basic_rates = (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; @@ -2593,15 +2661,12 @@ static void iwl_connection_init_rx_config(struct iwl_priv *priv) iwl4965_set_rxon_chain(priv); } -static int iwl_set_mode(struct iwl_priv *priv, int mode) +static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode) { - if (!iwl_is_ready_rf(priv)) - return -EAGAIN; - if (mode == IEEE80211_IF_TYPE_IBSS) { - const struct iwl_channel_info *ch_info; + const struct iwl4965_channel_info *ch_info; - ch_info = iwl_get_channel_info(priv, + ch_info = iwl4965_get_channel_info(priv, priv->phymode, le16_to_cpu(priv->staging_rxon.channel)); @@ -2612,32 +2677,36 @@ static int iwl_set_mode(struct iwl_priv *priv, int mode) } } + priv->iw_mode = mode; + + iwl4965_connection_init_rx_config(priv); + memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); + + iwl4965_clear_stations_table(priv); + + /* dont commit rxon if rf-kill is on*/ + if (!iwl4965_is_ready_rf(priv)) + return -EAGAIN; + cancel_delayed_work(&priv->scan_check); - if (iwl_scan_cancel_timeout(priv, 100)) { + if (iwl4965_scan_cancel_timeout(priv, 100)) { IWL_WARNING("Aborted scan still in progress after 100ms\n"); IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); return -EAGAIN; } - priv->iw_mode = mode; - - iwl_connection_init_rx_config(priv); - memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); - - iwl_clear_stations_table(priv); - - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); return 0; } -static void iwl_build_tx_cmd_hwcrypto(struct iwl_priv *priv, +static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv, struct ieee80211_tx_control *ctl, - struct iwl_cmd *cmd, + struct iwl4965_cmd *cmd, struct sk_buff *skb_frag, int last_frag) { - struct iwl_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; + struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; switch (keyinfo->alg) { case ALG_CCMP: @@ -2680,8 +2749,8 @@ static void iwl_build_tx_cmd_hwcrypto(struct iwl_priv *priv, /* * handle build REPLY_TX command notification. */ -static void iwl_build_tx_cmd_basic(struct iwl_priv *priv, - struct iwl_cmd *cmd, +static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv, + struct iwl4965_cmd *cmd, struct ieee80211_tx_control *ctrl, struct ieee80211_hdr *hdr, int is_unicast, u8 std_id) @@ -2703,6 +2772,10 @@ static void iwl_build_tx_cmd_basic(struct iwl_priv *priv, tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; } + if (ieee80211_is_back_request(fc)) + tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; + + cmd->cmd.tx.sta_id = std_id; if (ieee80211_get_morefrag(hdr)) tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; @@ -2729,11 +2802,9 @@ static void iwl_build_tx_cmd_basic(struct iwl_priv *priv, if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) - cmd->cmd.tx.timeout.pm_frame_timeout = - cpu_to_le16(3); + cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); else - cmd->cmd.tx.timeout.pm_frame_timeout = - cpu_to_le16(2); + cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); } else cmd->cmd.tx.timeout.pm_frame_timeout = 0; @@ -2742,40 +2813,47 @@ static void iwl_build_tx_cmd_basic(struct iwl_priv *priv, cmd->cmd.tx.next_frame_len = 0; } -static int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) +/** + * iwl4965_get_sta_id - Find station's index within station table + * + * If new IBSS station, create new entry in station table + */ +static int iwl4965_get_sta_id(struct iwl4965_priv *priv, + struct ieee80211_hdr *hdr) { int sta_id; u16 fc = le16_to_cpu(hdr->frame_control); DECLARE_MAC_BUF(mac); - /* If this frame is broadcast or not data then use the broadcast - * station id */ + /* If this frame is broadcast or management, use broadcast station id */ if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || is_multicast_ether_addr(hdr->addr1)) return priv->hw_setting.bcast_sta_id; switch (priv->iw_mode) { - /* If this frame is part of a BSS network (we're a station), then - * we use the AP's station id */ + /* If we are a client station in a BSS network, use the special + * AP station entry (that's the only station we communicate with) */ case IEEE80211_IF_TYPE_STA: return IWL_AP_ID; /* If we are an AP, then find the station, or use BCAST */ case IEEE80211_IF_TYPE_AP: - sta_id = iwl_hw_find_station(priv, hdr->addr1); + sta_id = iwl4965_hw_find_station(priv, hdr->addr1); if (sta_id != IWL_INVALID_STATION) return sta_id; return priv->hw_setting.bcast_sta_id; - /* If this frame is part of a IBSS network, then we use the - * target specific station id */ + /* If this frame is going out to an IBSS network, find the station, + * or create a new station table entry */ case IEEE80211_IF_TYPE_IBSS: - sta_id = iwl_hw_find_station(priv, hdr->addr1); + sta_id = iwl4965_hw_find_station(priv, hdr->addr1); if (sta_id != IWL_INVALID_STATION) return sta_id; - sta_id = iwl_add_station(priv, hdr->addr1, 0, CMD_ASYNC); + /* Create new station table entry */ + sta_id = iwl4965_add_station_flags(priv, hdr->addr1, + 0, CMD_ASYNC, NULL); if (sta_id != IWL_INVALID_STATION) return sta_id; @@ -2783,11 +2861,11 @@ static int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) IWL_DEBUG_DROP("Station %s not in station map. " "Defaulting to broadcast...\n", print_mac(mac, hdr->addr1)); - iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); + iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); return priv->hw_setting.bcast_sta_id; default: - IWL_WARNING("Unkown mode of operation: %d", priv->iw_mode); + IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); return priv->hw_setting.bcast_sta_id; } } @@ -2795,18 +2873,19 @@ static int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) /* * start REPLY_TX command process */ -static int iwl_tx_skb(struct iwl_priv *priv, +static int iwl4965_tx_skb(struct iwl4965_priv *priv, struct sk_buff *skb, struct ieee80211_tx_control *ctl) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; - struct iwl_tfd_frame *tfd; + struct iwl4965_tfd_frame *tfd; u32 *control_flags; int txq_id = ctl->queue; - struct iwl_tx_queue *txq = NULL; - struct iwl_queue *q = NULL; + struct iwl4965_tx_queue *txq = NULL; + struct iwl4965_queue *q = NULL; dma_addr_t phys_addr; dma_addr_t txcmd_phys; - struct iwl_cmd *out_cmd = NULL; + dma_addr_t scratch_phys; + struct iwl4965_cmd *out_cmd = NULL; u16 len, idx, len_org; u8 id, hdr_len, unicast; u8 sta_id; @@ -2818,13 +2897,13 @@ static int iwl_tx_skb(struct iwl_priv *priv, int rc; spin_lock_irqsave(&priv->lock, flags); - if (iwl_is_rfkill(priv)) { + if (iwl4965_is_rfkill(priv)) { IWL_DEBUG_DROP("Dropping - RF KILL\n"); goto drop_unlock; } - if (!priv->interface_id) { - IWL_DEBUG_DROP("Dropping - !priv->interface_id\n"); + if (!priv->vif) { + IWL_DEBUG_DROP("Dropping - !priv->vif\n"); goto drop_unlock; } @@ -2838,7 +2917,7 @@ static int iwl_tx_skb(struct iwl_priv *priv, fc = le16_to_cpu(hdr->frame_control); -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL4965_DEBUG if (ieee80211_is_auth(fc)) IWL_DEBUG_TX("Sending AUTH frame\n"); else if (ieee80211_is_assoc_request(fc)) @@ -2847,16 +2926,19 @@ static int iwl_tx_skb(struct iwl_priv *priv, IWL_DEBUG_TX("Sending REASSOC frame\n"); #endif - if (!iwl_is_associated(priv) && + /* drop all data frame if we are not associated */ + if (!iwl4965_is_associated(priv) && !priv->assoc_id && ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) { - IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n"); + IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n"); goto drop_unlock; } spin_unlock_irqrestore(&priv->lock, flags); hdr_len = ieee80211_get_hdrlen(fc); - sta_id = iwl_get_sta_id(priv, hdr); + + /* Find (or create) index into station table for destination station */ + sta_id = iwl4965_get_sta_id(priv, hdr); if (sta_id == IWL_INVALID_STATION) { DECLARE_MAC_BUF(mac); @@ -2876,40 +2958,62 @@ static int iwl_tx_skb(struct iwl_priv *priv, (hdr->seq_ctrl & __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); seq_number += 0x10; -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG /* aggregation is on for this <sta,tid> */ if (ctl->flags & IEEE80211_TXCTL_HT_MPDU_AGG) txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; -#endif /* CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ } + + /* Descriptor for chosen Tx queue */ txq = &priv->txq[txq_id]; q = &txq->q; spin_lock_irqsave(&priv->lock, flags); - tfd = &txq->bd[q->first_empty]; + /* Set up first empty TFD within this queue's circular TFD buffer */ + tfd = &txq->bd[q->write_ptr]; memset(tfd, 0, sizeof(*tfd)); control_flags = (u32 *) tfd; - idx = get_cmd_index(q, q->first_empty, 0); + idx = get_cmd_index(q, q->write_ptr, 0); - memset(&(txq->txb[q->first_empty]), 0, sizeof(struct iwl_tx_info)); - txq->txb[q->first_empty].skb[0] = skb; - memcpy(&(txq->txb[q->first_empty].status.control), + /* Set up driver data for this TFD */ + memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info)); + txq->txb[q->write_ptr].skb[0] = skb; + memcpy(&(txq->txb[q->write_ptr].status.control), ctl, sizeof(struct ieee80211_tx_control)); + + /* Set up first empty entry in queue's array of Tx/cmd buffers */ out_cmd = &txq->cmd[idx]; memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); + + /* + * Set up the Tx-command (not MAC!) header. + * Store the chosen Tx queue and TFD index within the sequence field; + * after Tx, uCode's Tx response will return this value so driver can + * locate the frame within the tx queue and do post-tx processing. + */ out_cmd->hdr.cmd = REPLY_TX; out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) | - INDEX_TO_SEQ(q->first_empty))); - /* copy frags header */ + INDEX_TO_SEQ(q->write_ptr))); + + /* Copy MAC header from skb into command buffer */ memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); - /* hdr = (struct ieee80211_hdr *)out_cmd->cmd.tx.hdr; */ + /* + * Use the first empty entry in this queue's command buffer array + * to contain the Tx command and MAC header concatenated together + * (payload data will be in another buffer). + * Size of this varies, due to varying MAC header length. + * If end is not dword aligned, we'll have 2 extra bytes at the end + * of the MAC header (device reads on dword boundaries). + * We'll tell device about this padding later. + */ len = priv->hw_setting.tx_cmd_len + - sizeof(struct iwl_cmd_header) + hdr_len; + sizeof(struct iwl4965_cmd_header) + hdr_len; len_org = len; len = (len + 3) & ~3; @@ -2919,36 +3023,53 @@ static int iwl_tx_skb(struct iwl_priv *priv, else len_org = 0; - txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx + - offsetof(struct iwl_cmd, hdr); + /* Physical address of this Tx command's header (not MAC header!), + * within command buffer array. */ + txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx + + offsetof(struct iwl4965_cmd, hdr); - iwl_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); + /* Add buffer containing Tx command and MAC(!) header to TFD's + * first entry */ + iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) - iwl_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); + iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); - /* 802.11 null functions have no payload... */ + /* Set up TFD's 2nd entry to point directly to remainder of skb, + * if any (802.11 null frames have no payload). */ len = skb->len - hdr_len; if (len) { phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, len, PCI_DMA_TODEVICE); - iwl_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); + iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); } + /* Tell 4965 about any 2-byte padding after MAC header */ if (len_org) out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; + /* Total # bytes to be transmitted */ len = (u16)skb->len; out_cmd->cmd.tx.len = cpu_to_le16(len); /* TODO need this for burst mode later on */ - iwl_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id); + iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id); /* set is_hcca to 0; it probably will never be implemented */ - iwl_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0); + iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0); + + scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) + + offsetof(struct iwl4965_tx_cmd, scratch); + out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys); + out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys); + +#ifdef CONFIG_IWL4965_HT_AGG +#ifdef CONFIG_IWL4965_HT + /* TODO: move this functionality to rate scaling */ + iwl4965_tl_get_stats(priv, hdr); +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /*CONFIG_IWL4965_HT */ - iwl4965_tx_cmd(priv, out_cmd, sta_id, txcmd_phys, - hdr, hdr_len, ctl, NULL); if (!ieee80211_get_morefrag(hdr)) { txq->need_update = 1; @@ -2961,27 +3082,29 @@ static int iwl_tx_skb(struct iwl_priv *priv, txq->need_update = 0; } - iwl_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, + iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, sizeof(out_cmd->cmd.tx)); - iwl_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, + iwl4965_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, ieee80211_get_hdrlen(fc)); + /* Set up entry for this TFD in Tx byte-count array */ iwl4965_tx_queue_update_wr_ptr(priv, txq, len); - q->first_empty = iwl_queue_inc_wrap(q->first_empty, q->n_bd); - rc = iwl_tx_queue_update_write_ptr(priv, txq); + /* Tell device the write index *just past* this latest filled TFD */ + q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); + rc = iwl4965_tx_queue_update_write_ptr(priv, txq); spin_unlock_irqrestore(&priv->lock, flags); if (rc) return rc; - if ((iwl_queue_space(q) < q->high_mark) + if ((iwl4965_queue_space(q) < q->high_mark) && priv->mac80211_registered) { if (wait_write_ptr) { spin_lock_irqsave(&priv->lock, flags); txq->need_update = 1; - iwl_tx_queue_update_write_ptr(priv, txq); + iwl4965_tx_queue_update_write_ptr(priv, txq); spin_unlock_irqrestore(&priv->lock, flags); } @@ -2996,13 +3119,13 @@ drop: return -1; } -static void iwl_set_rate(struct iwl_priv *priv) +static void iwl4965_set_rate(struct iwl4965_priv *priv) { const struct ieee80211_hw_mode *hw = NULL; struct ieee80211_rate *rate; int i; - hw = iwl_get_hw_mode(priv, priv->phymode); + hw = iwl4965_get_hw_mode(priv, priv->phymode); if (!hw) { IWL_ERROR("Failed to set rate: unable to get hw mode\n"); return; @@ -3020,7 +3143,7 @@ static void iwl_set_rate(struct iwl_priv *priv) if ((rate->val < IWL_RATE_COUNT) && (rate->flags & IEEE80211_RATE_SUPPORTED)) { IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n", - rate->val, iwl_rates[rate->val].plcp, + rate->val, iwl4965_rates[rate->val].plcp, (rate->flags & IEEE80211_RATE_BASIC) ? "*" : ""); priv->active_rate |= (1 << rate->val); @@ -3028,7 +3151,7 @@ static void iwl_set_rate(struct iwl_priv *priv) priv->active_rate_basic |= (1 << rate->val); } else IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n", - rate->val, iwl_rates[rate->val].plcp); + rate->val, iwl4965_rates[rate->val].plcp); } IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", @@ -3057,7 +3180,7 @@ static void iwl_set_rate(struct iwl_priv *priv) (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; } -static void iwl_radio_kill_sw(struct iwl_priv *priv, int disable_radio) +static void iwl4965_radio_kill_sw(struct iwl4965_priv *priv, int disable_radio) { unsigned long flags; @@ -3068,21 +3191,21 @@ static void iwl_radio_kill_sw(struct iwl_priv *priv, int disable_radio) disable_radio ? "OFF" : "ON"); if (disable_radio) { - iwl_scan_cancel(priv); + iwl4965_scan_cancel(priv); /* FIXME: This is a workaround for AP */ if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { spin_lock_irqsave(&priv->lock, flags); - iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, + iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, CSR_UCODE_SW_BIT_RFKILL); spin_unlock_irqrestore(&priv->lock, flags); - iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); + iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); set_bit(STATUS_RF_KILL_SW, &priv->status); } return; } spin_lock_irqsave(&priv->lock, flags); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); clear_bit(STATUS_RF_KILL_SW, &priv->status); spin_unlock_irqrestore(&priv->lock, flags); @@ -3091,9 +3214,9 @@ static void iwl_radio_kill_sw(struct iwl_priv *priv, int disable_radio) msleep(10); spin_lock_irqsave(&priv->lock, flags); - iwl_read32(priv, CSR_UCODE_DRV_GP1); - if (!iwl_grab_restricted_access(priv)) - iwl_release_restricted_access(priv); + iwl4965_read32(priv, CSR_UCODE_DRV_GP1); + if (!iwl4965_grab_nic_access(priv)) + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { @@ -3106,7 +3229,7 @@ static void iwl_radio_kill_sw(struct iwl_priv *priv, int disable_radio) return; } -void iwl_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb, +void iwl4965_set_decrypted_flag(struct iwl4965_priv *priv, struct sk_buff *skb, u32 decrypt_res, struct ieee80211_rx_status *stats) { u16 fc = @@ -3138,97 +3261,10 @@ void iwl_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb, } } -void iwl_handle_data_packet_monitor(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb, - void *data, short len, - struct ieee80211_rx_status *stats, - u16 phy_flags) -{ - struct iwl_rt_rx_hdr *iwl_rt; - - /* First cache any information we need before we overwrite - * the information provided in the skb from the hardware */ - s8 signal = stats->ssi; - s8 noise = 0; - int rate = stats->rate; - u64 tsf = stats->mactime; - __le16 phy_flags_hw = cpu_to_le16(phy_flags); - - /* We received data from the HW, so stop the watchdog */ - if (len > IWL_RX_BUF_SIZE - sizeof(*iwl_rt)) { - IWL_DEBUG_DROP("Dropping too large packet in monitor\n"); - return; - } - - /* copy the frame data to write after where the radiotap header goes */ - iwl_rt = (void *)rxb->skb->data; - memmove(iwl_rt->payload, data, len); - - iwl_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; - iwl_rt->rt_hdr.it_pad = 0; /* always good to zero */ - - /* total header + data */ - iwl_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl_rt)); - - /* Set the size of the skb to the size of the frame */ - skb_put(rxb->skb, sizeof(*iwl_rt) + len); - - /* Big bitfield of all the fields we provide in radiotap */ - iwl_rt->rt_hdr.it_present = - cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) | - (1 << IEEE80211_RADIOTAP_FLAGS) | - (1 << IEEE80211_RADIOTAP_RATE) | - (1 << IEEE80211_RADIOTAP_CHANNEL) | - (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | - (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | - (1 << IEEE80211_RADIOTAP_ANTENNA)); - - /* Zero the flags, we'll add to them as we go */ - iwl_rt->rt_flags = 0; - - iwl_rt->rt_tsf = cpu_to_le64(tsf); - - /* Convert to dBm */ - iwl_rt->rt_dbmsignal = signal; - iwl_rt->rt_dbmnoise = noise; - - /* Convert the channel frequency and set the flags */ - iwl_rt->rt_channelMHz = cpu_to_le16(stats->freq); - if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK)) - iwl_rt->rt_chbitmask = - cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ)); - else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK) - iwl_rt->rt_chbitmask = - cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ)); - else /* 802.11g */ - iwl_rt->rt_chbitmask = - cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ)); - - rate = iwl_rate_index_from_plcp(rate); - if (rate == -1) - iwl_rt->rt_rate = 0; - else - iwl_rt->rt_rate = iwl_rates[rate].ieee; - - /* antenna number */ - iwl_rt->rt_antenna = - le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4; - - /* set the preamble flag if we have it */ - if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) - iwl_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; - - IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); - - stats->flag |= RX_FLAG_RADIOTAP; - ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); - rxb->skb = NULL; -} - #define IWL_PACKET_RETRY_TIME HZ -int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) +int iwl4965_is_duplicate_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header) { u16 sc = le16_to_cpu(header->seq_ctrl); u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; @@ -3239,29 +3275,26 @@ int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) switch (priv->iw_mode) { case IEEE80211_IF_TYPE_IBSS:{ struct list_head *p; - struct iwl_ibss_seq *entry = NULL; + struct iwl4965_ibss_seq *entry = NULL; u8 *mac = header->addr2; int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); __list_for_each(p, &priv->ibss_mac_hash[index]) { - entry = - list_entry(p, struct iwl_ibss_seq, list); + entry = list_entry(p, struct iwl4965_ibss_seq, list); if (!compare_ether_addr(entry->mac, mac)) break; } if (p == &priv->ibss_mac_hash[index]) { entry = kzalloc(sizeof(*entry), GFP_ATOMIC); if (!entry) { - IWL_ERROR - ("Cannot malloc new mac entry\n"); + IWL_ERROR("Cannot malloc new mac entry\n"); return 0; } memcpy(entry->mac, mac, ETH_ALEN); entry->seq_num = seq; entry->frag_num = frag; entry->packet_time = jiffies; - list_add(&entry->list, - &priv->ibss_mac_hash[index]); + list_add(&entry->list, &priv->ibss_mac_hash[index]); return 0; } last_seq = &entry->seq_num; @@ -3295,7 +3328,7 @@ int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) return 1; } -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT +#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT #include "iwl-spectrum.h" @@ -3310,7 +3343,7 @@ int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) * the lower 3 bytes is the time in usec within one beacon interval */ -static u32 iwl_usecs_to_beacons(u32 usec, u32 beacon_interval) +static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) { u32 quot; u32 rem; @@ -3329,7 +3362,7 @@ static u32 iwl_usecs_to_beacons(u32 usec, u32 beacon_interval) * the same as HW timer counter counting down */ -static __le32 iwl_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) +static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) { u32 base_low = base & BEACON_TIME_MASK_LOW; u32 addon_low = addon & BEACON_TIME_MASK_LOW; @@ -3348,13 +3381,13 @@ static __le32 iwl_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) return cpu_to_le32(res); } -static int iwl_get_measurement(struct iwl_priv *priv, +static int iwl4965_get_measurement(struct iwl4965_priv *priv, struct ieee80211_measurement_params *params, u8 type) { - struct iwl_spectrum_cmd spectrum; - struct iwl_rx_packet *res; - struct iwl_host_cmd cmd = { + struct iwl4965_spectrum_cmd spectrum; + struct iwl4965_rx_packet *res; + struct iwl4965_host_cmd cmd = { .id = REPLY_SPECTRUM_MEASUREMENT_CMD, .data = (void *)&spectrum, .meta.flags = CMD_WANT_SKB, @@ -3364,9 +3397,9 @@ static int iwl_get_measurement(struct iwl_priv *priv, int spectrum_resp_status; int duration = le16_to_cpu(params->duration); - if (iwl_is_associated(priv)) + if (iwl4965_is_associated(priv)) add_time = - iwl_usecs_to_beacons( + iwl4965_usecs_to_beacons( le64_to_cpu(params->start_time) - priv->last_tsf, le16_to_cpu(priv->rxon_timing.beacon_interval)); @@ -3379,9 +3412,9 @@ static int iwl_get_measurement(struct iwl_priv *priv, cmd.len = sizeof(spectrum); spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); - if (iwl_is_associated(priv)) + if (iwl4965_is_associated(priv)) spectrum.start_time = - iwl_add_beacon_time(priv->last_beacon_time, + iwl4965_add_beacon_time(priv->last_beacon_time, add_time, le16_to_cpu(priv->rxon_timing.beacon_interval)); else @@ -3394,11 +3427,11 @@ static int iwl_get_measurement(struct iwl_priv *priv, spectrum.flags |= RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; - rc = iwl_send_cmd_sync(priv, &cmd); + rc = iwl4965_send_cmd_sync(priv, &cmd); if (rc) return rc; - res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; + res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; if (res->hdr.flags & IWL_CMD_FAILED_MSK) { IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); rc = -EIO; @@ -3428,8 +3461,8 @@ static int iwl_get_measurement(struct iwl_priv *priv, } #endif -static void iwl_txstatus_to_ieee(struct iwl_priv *priv, - struct iwl_tx_info *tx_sta) +static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv, + struct iwl4965_tx_info *tx_sta) { tx_sta->status.ack_signal = 0; @@ -3448,41 +3481,41 @@ static void iwl_txstatus_to_ieee(struct iwl_priv *priv, } /** - * iwl_tx_queue_reclaim - Reclaim Tx queue entries no more used by NIC. + * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd * - * When FW advances 'R' index, all entries between old and - * new 'R' index need to be reclaimed. As result, some free space - * forms. If there is enough free space (> low mark), wake Tx queue. + * When FW advances 'R' index, all entries between old and new 'R' index + * need to be reclaimed. As result, some free space forms. If there is + * enough free space (> low mark), wake the stack that feeds us. */ -int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index) +int iwl4965_tx_queue_reclaim(struct iwl4965_priv *priv, int txq_id, int index) { - struct iwl_tx_queue *txq = &priv->txq[txq_id]; - struct iwl_queue *q = &txq->q; + struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; + struct iwl4965_queue *q = &txq->q; int nfreed = 0; if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " "is out of range [0-%d] %d %d.\n", txq_id, - index, q->n_bd, q->first_empty, q->last_used); + index, q->n_bd, q->write_ptr, q->read_ptr); return 0; } - for (index = iwl_queue_inc_wrap(index, q->n_bd); - q->last_used != index; - q->last_used = iwl_queue_inc_wrap(q->last_used, q->n_bd)) { + for (index = iwl4965_queue_inc_wrap(index, q->n_bd); + q->read_ptr != index; + q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) { if (txq_id != IWL_CMD_QUEUE_NUM) { - iwl_txstatus_to_ieee(priv, - &(txq->txb[txq->q.last_used])); - iwl_hw_txq_free_tfd(priv, txq); + iwl4965_txstatus_to_ieee(priv, + &(txq->txb[txq->q.read_ptr])); + iwl4965_hw_txq_free_tfd(priv, txq); } else if (nfreed > 1) { IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, - q->first_empty, q->last_used); + q->write_ptr, q->read_ptr); queue_work(priv->workqueue, &priv->restart); } nfreed++; } - if (iwl_queue_space(q) > q->low_mark && (txq_id >= 0) && + if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) && (txq_id != IWL_CMD_QUEUE_NUM) && priv->mac80211_registered) ieee80211_wake_queue(priv->hw, txq_id); @@ -3491,7 +3524,7 @@ int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index) return nfreed; } -static int iwl_is_tx_success(u32 status) +static int iwl4965_is_tx_success(u32 status) { status &= TX_STATUS_MSK; return (status == TX_STATUS_SUCCESS) @@ -3503,22 +3536,22 @@ static int iwl_is_tx_success(u32 status) * Generic RX handler implementations * ******************************************************************************/ -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG -static inline int iwl_get_ra_sta_id(struct iwl_priv *priv, +static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv, struct ieee80211_hdr *hdr) { if (priv->iw_mode == IEEE80211_IF_TYPE_STA) return IWL_AP_ID; else { u8 *da = ieee80211_get_DA(hdr); - return iwl_hw_find_station(priv, da); + return iwl4965_hw_find_station(priv, da); } } -static struct ieee80211_hdr *iwl_tx_queue_get_hdr( - struct iwl_priv *priv, int txq_id, int idx) +static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( + struct iwl4965_priv *priv, int txq_id, int idx) { if (priv->txq[txq_id].txb[idx].skb[0]) return (struct ieee80211_hdr *)priv->txq[txq_id]. @@ -3526,16 +3559,20 @@ static struct ieee80211_hdr *iwl_tx_queue_get_hdr( return NULL; } -static inline u32 iwl_get_scd_ssn(struct iwl_tx_resp *tx_resp) +static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp) { __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + tx_resp->frame_count); return le32_to_cpu(*scd_ssn) & MAX_SN; } -static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, - struct iwl_ht_agg *agg, - struct iwl_tx_resp *tx_resp, + +/** + * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue + */ +static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv, + struct iwl4965_ht_agg *agg, + struct iwl4965_tx_resp *tx_resp, u16 start_idx) { u32 status; @@ -3547,15 +3584,17 @@ static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, u16 seq; if (agg->wait_for_ba) - IWL_DEBUG_TX_REPLY("got tx repsons w/o back\n"); + IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); agg->frame_count = tx_resp->frame_count; agg->start_idx = start_idx; agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); agg->bitmap0 = agg->bitmap1 = 0; + /* # frames attempted by Tx command */ if (agg->frame_count == 1) { - struct iwl_tx_queue *txq ; + /* Only one frame was attempted; no block-ack will arrive */ + struct iwl4965_tx_queue *txq ; status = le32_to_cpu(frame_status[0]); txq_id = agg->txq_id; @@ -3564,28 +3603,30 @@ static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d \n", agg->frame_count, agg->start_idx); - tx_status = &(priv->txq[txq_id].txb[txq->q.last_used].status); + tx_status = &(priv->txq[txq_id].txb[txq->q.read_ptr].status); tx_status->retry_count = tx_resp->failure_frame; tx_status->queue_number = status & 0xff; tx_status->queue_length = tx_resp->bt_kill_count; tx_status->queue_length |= tx_resp->failure_rts; - tx_status->flags = iwl_is_tx_success(status)? + tx_status->flags = iwl4965_is_tx_success(status)? IEEE80211_TX_STATUS_ACK : 0; tx_status->control.tx_rate = - iwl_hw_get_rate_n_flags(tx_resp->rate_n_flags); + iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags); /* FIXME: code repetition end */ IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", status & 0xff, tx_resp->failure_frame); IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", - iwl_hw_get_rate_n_flags(tx_resp->rate_n_flags)); + iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); agg->wait_for_ba = 0; } else { + /* Two or more frames were attempted; expect block-ack */ u64 bitmap = 0; int start = agg->start_idx; + /* Construct bit-map of pending frames within Tx window */ for (i = 0; i < agg->frame_count; i++) { u16 sc; status = le32_to_cpu(frame_status[i]); @@ -3600,7 +3641,7 @@ static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", agg->frame_count, txq_id, idx); - hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx); + hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); sc = le16_to_cpu(hdr->seq_ctrl); if (idx != (SEQ_TO_SN(sc) & 0xff)) { @@ -3649,19 +3690,22 @@ static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, #endif #endif -static void iwl_rx_reply_tx(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +/** + * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response + */ +static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; u16 sequence = le16_to_cpu(pkt->hdr.sequence); int txq_id = SEQ_TO_QUEUE(sequence); int index = SEQ_TO_INDEX(sequence); - struct iwl_tx_queue *txq = &priv->txq[txq_id]; + struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; struct ieee80211_tx_status *tx_status; - struct iwl_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; + struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; u32 status = le32_to_cpu(tx_resp->status); -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG int tid, sta_id; #endif #endif @@ -3669,18 +3713,18 @@ static void iwl_rx_reply_tx(struct iwl_priv *priv, if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " "is out of range [0-%d] %d %d\n", txq_id, - index, txq->q.n_bd, txq->q.first_empty, - txq->q.last_used); + index, txq->q.n_bd, txq->q.write_ptr, + txq->q.read_ptr); return; } -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG if (txq->sched_retry) { - const u32 scd_ssn = iwl_get_scd_ssn(tx_resp); + const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); struct ieee80211_hdr *hdr = - iwl_tx_queue_get_hdr(priv, txq_id, index); - struct iwl_ht_agg *agg = NULL; + iwl4965_tx_queue_get_hdr(priv, txq_id, index); + struct iwl4965_ht_agg *agg = NULL; __le16 *qc = ieee80211_get_qos_ctrl(hdr); if (qc == NULL) { @@ -3690,7 +3734,7 @@ static void iwl_rx_reply_tx(struct iwl_priv *priv, tid = le16_to_cpu(*qc) & 0xf; - sta_id = iwl_get_ra_sta_id(priv, hdr); + sta_id = iwl4965_get_ra_sta_id(priv, hdr); if (unlikely(sta_id == IWL_INVALID_STATION)) { IWL_ERROR("Station not known for\n"); return; @@ -3701,20 +3745,20 @@ static void iwl_rx_reply_tx(struct iwl_priv *priv, iwl4965_tx_status_reply_tx(priv, agg, tx_resp, index); if ((tx_resp->frame_count == 1) && - !iwl_is_tx_success(status)) { + !iwl4965_is_tx_success(status)) { /* TODO: send BAR */ } - if ((txq->q.last_used != (scd_ssn & 0xff))) { - index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); + if ((txq->q.read_ptr != (scd_ssn & 0xff))) { + index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " "%d index %d\n", scd_ssn , index); - iwl_tx_queue_reclaim(priv, txq_id, index); + iwl4965_tx_queue_reclaim(priv, txq_id, index); } } else { -#endif /* CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ - tx_status = &(txq->txb[txq->q.last_used].status); +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ + tx_status = &(txq->txb[txq->q.read_ptr].status); tx_status->retry_count = tx_resp->failure_frame; tx_status->queue_number = status; @@ -3722,35 +3766,35 @@ static void iwl_rx_reply_tx(struct iwl_priv *priv, tx_status->queue_length |= tx_resp->failure_rts; tx_status->flags = - iwl_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; + iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; tx_status->control.tx_rate = - iwl_hw_get_rate_n_flags(tx_resp->rate_n_flags); + iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags); IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x " - "retries %d\n", txq_id, iwl_get_tx_fail_reason(status), + "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), status, le32_to_cpu(tx_resp->rate_n_flags), tx_resp->failure_frame); IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); if (index != -1) - iwl_tx_queue_reclaim(priv, txq_id, index); -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG + iwl4965_tx_queue_reclaim(priv, txq_id, index); +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG } -#endif /* CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); } -static void iwl_rx_reply_alive(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_alive_resp *palive; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_alive_resp *palive; struct delayed_work *pwork; palive = &pkt->u.alive_frame; @@ -3764,12 +3808,12 @@ static void iwl_rx_reply_alive(struct iwl_priv *priv, IWL_DEBUG_INFO("Initialization Alive received.\n"); memcpy(&priv->card_alive_init, &pkt->u.alive_frame, - sizeof(struct iwl_init_alive_resp)); + sizeof(struct iwl4965_init_alive_resp)); pwork = &priv->init_alive_start; } else { IWL_DEBUG_INFO("Runtime Alive received.\n"); memcpy(&priv->card_alive, &pkt->u.alive_frame, - sizeof(struct iwl_alive_resp)); + sizeof(struct iwl4965_alive_resp)); pwork = &priv->alive_start; } @@ -3782,19 +3826,19 @@ static void iwl_rx_reply_alive(struct iwl_priv *priv, IWL_WARNING("uCode did not respond OK.\n"); } -static void iwl_rx_reply_add_sta(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); return; } -static void iwl_rx_reply_error(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_reply_error(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " "seq 0x%04X ser 0x%08X\n", @@ -3807,23 +3851,23 @@ static void iwl_rx_reply_error(struct iwl_priv *priv, #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x -static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_csa(struct iwl4965_priv *priv, struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; - struct iwl_csa_notification *csa = &(pkt->u.csa_notif); + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon; + struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); rxon->channel = csa->channel; priv->staging_rxon.channel = csa->channel; } -static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif); +#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); if (!report->state) { IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, @@ -3836,35 +3880,35 @@ static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv, #endif } -static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { -#ifdef CONFIG_IWLWIFI_DEBUG - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif); +#ifdef CONFIG_IWL4965_DEBUG + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); IWL_DEBUG_RX("sleep mode: %d, src: %d\n", sleep->pm_sleep_mode, sleep->pm_wakeup_src); #endif } -static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " "notification for %s:\n", le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); - iwl_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len)); + iwl4965_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len)); } -static void iwl_bg_beacon_update(struct work_struct *work) +static void iwl4965_bg_beacon_update(struct work_struct *work) { - struct iwl_priv *priv = - container_of(work, struct iwl_priv, beacon_update); + struct iwl4965_priv *priv = + container_of(work, struct iwl4965_priv, beacon_update); struct sk_buff *beacon; /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ - beacon = ieee80211_beacon_get(priv->hw, priv->interface_id, NULL); + beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); if (!beacon) { IWL_ERROR("update beacon failed\n"); @@ -3879,16 +3923,16 @@ static void iwl_bg_beacon_update(struct work_struct *work) priv->ibss_beacon = beacon; mutex_unlock(&priv->mutex); - iwl_send_beacon_cmd(priv); + iwl4965_send_beacon_cmd(priv); } -static void iwl_rx_beacon_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { -#ifdef CONFIG_IWLWIFI_DEBUG - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_beacon_notif *beacon = &(pkt->u.beacon_status); - u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); +#ifdef CONFIG_IWL4965_DEBUG + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); + u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); IWL_DEBUG_RX("beacon status %x retries %d iss %d " "tsf %d %d rate %d\n", @@ -3905,25 +3949,25 @@ static void iwl_rx_beacon_notif(struct iwl_priv *priv, } /* Service response to REPLY_SCAN_CMD (0x80) */ -static void iwl_rx_reply_scan(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { -#ifdef CONFIG_IWLWIFI_DEBUG - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_scanreq_notification *notif = - (struct iwl_scanreq_notification *)pkt->u.raw; +#ifdef CONFIG_IWL4965_DEBUG + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_scanreq_notification *notif = + (struct iwl4965_scanreq_notification *)pkt->u.raw; IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); #endif } /* Service SCAN_START_NOTIFICATION (0x82) */ -static void iwl_rx_scan_start_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_scanstart_notification *notif = - (struct iwl_scanstart_notification *)pkt->u.raw; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_scanstart_notification *notif = + (struct iwl4965_scanstart_notification *)pkt->u.raw; priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); IWL_DEBUG_SCAN("Scan start: " "%d [802.11%s] " @@ -3935,12 +3979,12 @@ static void iwl_rx_scan_start_notif(struct iwl_priv *priv, } /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ -static void iwl_rx_scan_results_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_scanresults_notification *notif = - (struct iwl_scanresults_notification *)pkt->u.raw; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_scanresults_notification *notif = + (struct iwl4965_scanresults_notification *)pkt->u.raw; IWL_DEBUG_SCAN("Scan ch.res: " "%d [802.11%s] " @@ -3956,14 +4000,15 @@ static void iwl_rx_scan_results_notif(struct iwl_priv *priv, (priv->last_scan_jiffies, jiffies))); priv->last_scan_jiffies = jiffies; + priv->next_scan_jiffies = 0; } /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ -static void iwl_rx_scan_complete_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; - struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", scan_notif->scanned_channels, @@ -3998,6 +4043,7 @@ static void iwl_rx_scan_complete_notif(struct iwl_priv *priv, } priv->last_scan_jiffies = jiffies; + priv->next_scan_jiffies = 0; IWL_DEBUG_INFO("Setting scan to off\n"); clear_bit(STATUS_SCANNING, &priv->status); @@ -4016,10 +4062,10 @@ reschedule: /* Handle notification from uCode that card's power state is changing * due to software, hardware, or critical temperature RFKILL */ -static void iwl_rx_card_state_notif(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (void *)rxb->skb->data; + struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); unsigned long status = priv->status; @@ -4030,35 +4076,35 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv, if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | RF_CARD_DISABLED)) { - iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, + iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); - if (!iwl_grab_restricted_access(priv)) { - iwl_write_restricted( + if (!iwl4965_grab_nic_access(priv)) { + iwl4965_write_direct32( priv, HBUS_TARG_MBX_C, HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); } if (!(flags & RXON_CARD_DISABLED)) { - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, + iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); - if (!iwl_grab_restricted_access(priv)) { - iwl_write_restricted( + if (!iwl4965_grab_nic_access(priv)) { + iwl4965_write_direct32( priv, HBUS_TARG_MBX_C, HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); } } if (flags & RF_CARD_DISABLED) { - iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, + iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); - iwl_read32(priv, CSR_UCODE_DRV_GP1); - if (!iwl_grab_restricted_access(priv)) - iwl_release_restricted_access(priv); + iwl4965_read32(priv, CSR_UCODE_DRV_GP1); + if (!iwl4965_grab_nic_access(priv)) + iwl4965_release_nic_access(priv); } } @@ -4074,7 +4120,7 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv, clear_bit(STATUS_RF_KILL_SW, &priv->status); if (!(flags & RXON_CARD_DISABLED)) - iwl_scan_cancel(priv); + iwl4965_scan_cancel(priv); if ((test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status)) || @@ -4086,7 +4132,7 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv, } /** - * iwl_setup_rx_handlers - Initialize Rx handler callbacks + * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks * * Setup the RX handlers for each of the reply types sent from the uCode * to the host. @@ -4094,61 +4140,58 @@ static void iwl_rx_card_state_notif(struct iwl_priv *priv, * This function chains into the hardware specific files for them to setup * any hardware specific handlers as well. */ -static void iwl_setup_rx_handlers(struct iwl_priv *priv) +static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv) { - priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; - priv->rx_handlers[REPLY_ADD_STA] = iwl_rx_reply_add_sta; - priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error; - priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa; + priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; + priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; + priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; + priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = - iwl_rx_spectrum_measure_notif; - priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif; + iwl4965_rx_spectrum_measure_notif; + priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = - iwl_rx_pm_debug_statistics_notif; - priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif; - - /* NOTE: iwl_rx_statistics is different based on whether - * the build is for the 3945 or the 4965. See the - * corresponding implementation in iwl-XXXX.c - * - * The same handler is used for both the REPLY to a - * discrete statistics request from the host as well as - * for the periodic statistics notification from the uCode + iwl4965_rx_pm_debug_statistics_notif; + priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; + + /* + * The same handler is used for both the REPLY to a discrete + * statistics request from the host as well as for the periodic + * statistics notifications (after received beacons) from the uCode. */ - priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_hw_rx_statistics; - priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_hw_rx_statistics; + priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; + priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; - priv->rx_handlers[REPLY_SCAN_CMD] = iwl_rx_reply_scan; - priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl_rx_scan_start_notif; + priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; + priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = - iwl_rx_scan_results_notif; + iwl4965_rx_scan_results_notif; priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = - iwl_rx_scan_complete_notif; - priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif; - priv->rx_handlers[REPLY_TX] = iwl_rx_reply_tx; + iwl4965_rx_scan_complete_notif; + priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; + priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; - /* Setup hardware specific Rx handlers */ - iwl_hw_rx_handler_setup(priv); + /* Set up hardware specific Rx handlers */ + iwl4965_hw_rx_handler_setup(priv); } /** - * iwl_tx_cmd_complete - Pull unused buffers off the queue and reclaim them + * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them * @rxb: Rx buffer to reclaim * * If an Rx buffer has an async callback associated with it the callback * will be executed. The attached skb (if present) will only be freed * if the callback returns 1 */ -static void iwl_tx_cmd_complete(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb) +static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv, + struct iwl4965_rx_mem_buffer *rxb) { - struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; + struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; u16 sequence = le16_to_cpu(pkt->hdr.sequence); int txq_id = SEQ_TO_QUEUE(sequence); int index = SEQ_TO_INDEX(sequence); int huge = sequence & SEQ_HUGE_FRAME; int cmd_index; - struct iwl_cmd *cmd; + struct iwl4965_cmd *cmd; /* If a Tx command is being handled and it isn't in the actual * command queue then there a command routing bug has been introduced @@ -4169,7 +4212,7 @@ static void iwl_tx_cmd_complete(struct iwl_priv *priv, !cmd->meta.u.callback(priv, cmd, rxb->skb)) rxb->skb = NULL; - iwl_tx_queue_reclaim(priv, txq_id, index); + iwl4965_tx_queue_reclaim(priv, txq_id, index); if (!(cmd->meta.flags & CMD_ASYNC)) { clear_bit(STATUS_HCMD_ACTIVE, &priv->status); @@ -4181,9 +4224,11 @@ static void iwl_tx_cmd_complete(struct iwl_priv *priv, /* * Rx theory of operation * - * The host allocates 32 DMA target addresses and passes the host address - * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is - * 0 to 31 + * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), + * each of which point to Receive Buffers to be filled by 4965. These get + * used not only for Rx frames, but for any command response or notification + * from the 4965. The driver and 4965 manage the Rx buffers by means + * of indexes into the circular buffer. * * Rx Queue Indexes * The host/firmware share two index registers for managing the Rx buffers. @@ -4199,10 +4244,10 @@ static void iwl_tx_cmd_complete(struct iwl_priv *priv, * The queue is empty (no good data) if WRITE = READ - 1, and is full if * WRITE = READ. * - * During initialization the host sets up the READ queue position to the first + * During initialization, the host sets up the READ queue position to the first * INDEX position, and WRITE to the last (READ - 1 wrapped) * - * When the firmware places a packet in a buffer it will advance the READ index + * When the firmware places a packet in a buffer, it will advance the READ index * and fire the RX interrupt. The driver can then query the READ index and * process as many packets as possible, moving the WRITE index forward as it * resets the Rx queue buffers with new memory. @@ -4210,8 +4255,8 @@ static void iwl_tx_cmd_complete(struct iwl_priv *priv, * The management in the driver is as follows: * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled - * to replensish the iwl->rxq->rx_free. - * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the + * to replenish the iwl->rxq->rx_free. + * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the * iwl->rxq is replenished and the READ INDEX is updated (updating the * 'processed' and 'read' driver indexes as well) * + A received packet is processed and handed to the kernel network stack, @@ -4224,28 +4269,28 @@ static void iwl_tx_cmd_complete(struct iwl_priv *priv, * * Driver sequence: * - * iwl_rx_queue_alloc() Allocates rx_free - * iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls - * iwl_rx_queue_restock - * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx + * iwl4965_rx_queue_alloc() Allocates rx_free + * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls + * iwl4965_rx_queue_restock + * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx * queue, updates firmware pointers, and updates * the WRITE index. If insufficient rx_free buffers - * are available, schedules iwl_rx_replenish + * are available, schedules iwl4965_rx_replenish * * -- enable interrupts -- - * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the + * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the * READ INDEX, detaching the SKB from the pool. * Moves the packet buffer from queue to rx_used. - * Calls iwl_rx_queue_restock to refill any empty + * Calls iwl4965_rx_queue_restock to refill any empty * slots. * ... * */ /** - * iwl_rx_queue_space - Return number of free slots available in queue. + * iwl4965_rx_queue_space - Return number of free slots available in queue. */ -static int iwl_rx_queue_space(const struct iwl_rx_queue *q) +static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q) { int s = q->read - q->write; if (s <= 0) @@ -4258,15 +4303,9 @@ static int iwl_rx_queue_space(const struct iwl_rx_queue *q) } /** - * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue - * - * NOTE: This function has 3945 and 4965 specific code sections - * but is declared in base due to the majority of the - * implementation being the same (only a numeric constant is - * different) - * + * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue */ -int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q) +int iwl4965_rx_queue_update_write_ptr(struct iwl4965_priv *priv, struct iwl4965_rx_queue *q) { u32 reg = 0; int rc = 0; @@ -4277,24 +4316,29 @@ int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q) if (q->need_update == 0) goto exit_unlock; + /* If power-saving is in use, make sure device is awake */ if (test_bit(STATUS_POWER_PMI, &priv->status)) { - reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); + reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { - iwl_set_bit(priv, CSR_GP_CNTRL, + iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); goto exit_unlock; } - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) goto exit_unlock; - iwl_write_restricted(priv, FH_RSCSR_CHNL0_WPTR, + /* Device expects a multiple of 8 */ + iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); + + /* Else device is assumed to be awake */ } else - iwl_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); + /* Device expects a multiple of 8 */ + iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); q->need_update = 0; @@ -4305,11 +4349,9 @@ int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q) } /** - * iwl_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer pointer. - * - * NOTE: This function has 3945 and 4965 specific code paths in it. + * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr */ -static inline __le32 iwl_dma_addr2rbd_ptr(struct iwl_priv *priv, +static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv, dma_addr_t dma_addr) { return cpu_to_le32((u32)(dma_addr >> 8)); @@ -4317,31 +4359,34 @@ static inline __le32 iwl_dma_addr2rbd_ptr(struct iwl_priv *priv, /** - * iwl_rx_queue_restock - refill RX queue from pre-allocated pool + * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool * - * If there are slots in the RX queue that need to be restocked, + * If there are slots in the RX queue that need to be restocked, * and we have free pre-allocated buffers, fill the ranks as much - * as we can pulling from rx_free. + * as we can, pulling from rx_free. * * This moves the 'write' index forward to catch up with 'processed', and * also updates the memory address in the firmware to reference the new * target buffer. */ -int iwl_rx_queue_restock(struct iwl_priv *priv) +static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv) { - struct iwl_rx_queue *rxq = &priv->rxq; + struct iwl4965_rx_queue *rxq = &priv->rxq; struct list_head *element; - struct iwl_rx_mem_buffer *rxb; + struct iwl4965_rx_mem_buffer *rxb; unsigned long flags; int write, rc; spin_lock_irqsave(&rxq->lock, flags); write = rxq->write & ~0x7; - while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) { + while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) { + /* Get next free Rx buffer, remove from free list */ element = rxq->rx_free.next; - rxb = list_entry(element, struct iwl_rx_mem_buffer, list); + rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); list_del(element); - rxq->bd[rxq->write] = iwl_dma_addr2rbd_ptr(priv, rxb->dma_addr); + + /* Point to Rx buffer via next RBD in circular buffer */ + rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr); rxq->queue[rxq->write] = rxb; rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; rxq->free_count--; @@ -4353,13 +4398,14 @@ int iwl_rx_queue_restock(struct iwl_priv *priv) queue_work(priv->workqueue, &priv->rx_replenish); - /* If we've added more space for the firmware to place data, tell it */ + /* If we've added more space for the firmware to place data, tell it. + * Increment device's write pointer in multiples of 8. */ if ((write != (rxq->write & ~0x7)) || (abs(rxq->write - rxq->read) > 7)) { spin_lock_irqsave(&rxq->lock, flags); rxq->need_update = 1; spin_unlock_irqrestore(&rxq->lock, flags); - rc = iwl_rx_queue_update_write_ptr(priv, rxq); + rc = iwl4965_rx_queue_update_write_ptr(priv, rxq); if (rc) return rc; } @@ -4368,26 +4414,28 @@ int iwl_rx_queue_restock(struct iwl_priv *priv) } /** - * iwl_rx_replensih - Move all used packet from rx_used to rx_free + * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free * * When moving to rx_free an SKB is allocated for the slot. * - * Also restock the Rx queue via iwl_rx_queue_restock. - * This is called as a scheduled work item (except for during intialization) + * Also restock the Rx queue via iwl4965_rx_queue_restock. + * This is called as a scheduled work item (except for during initialization) */ -void iwl_rx_replenish(void *data) +static void iwl4965_rx_allocate(struct iwl4965_priv *priv) { - struct iwl_priv *priv = data; - struct iwl_rx_queue *rxq = &priv->rxq; + struct iwl4965_rx_queue *rxq = &priv->rxq; struct list_head *element; - struct iwl_rx_mem_buffer *rxb; + struct iwl4965_rx_mem_buffer *rxb; unsigned long flags; spin_lock_irqsave(&rxq->lock, flags); while (!list_empty(&rxq->rx_used)) { element = rxq->rx_used.next; - rxb = list_entry(element, struct iwl_rx_mem_buffer, list); + rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); + + /* Alloc a new receive buffer */ rxb->skb = - alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC); + alloc_skb(priv->hw_setting.rx_buf_size, + __GFP_NOWARN | GFP_ATOMIC); if (!rxb->skb) { if (net_ratelimit()) printk(KERN_CRIT DRV_NAME @@ -4399,32 +4447,55 @@ void iwl_rx_replenish(void *data) } priv->alloc_rxb_skb++; list_del(element); + + /* Get physical address of RB/SKB */ rxb->dma_addr = pci_map_single(priv->pci_dev, rxb->skb->data, - IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); + priv->hw_setting.rx_buf_size, PCI_DMA_FROMDEVICE); list_add_tail(&rxb->list, &rxq->rx_free); rxq->free_count++; } spin_unlock_irqrestore(&rxq->lock, flags); +} + +/* + * this should be called while priv->lock is locked +*/ +static void __iwl4965_rx_replenish(void *data) +{ + struct iwl4965_priv *priv = data; + + iwl4965_rx_allocate(priv); + iwl4965_rx_queue_restock(priv); +} + + +void iwl4965_rx_replenish(void *data) +{ + struct iwl4965_priv *priv = data; + unsigned long flags; + + iwl4965_rx_allocate(priv); spin_lock_irqsave(&priv->lock, flags); - iwl_rx_queue_restock(priv); + iwl4965_rx_queue_restock(priv); spin_unlock_irqrestore(&priv->lock, flags); } /* Assumes that the skb field of the buffers in 'pool' is kept accurate. - * If an SKB has been detached, the POOL needs to have it's SKB set to NULL + * If an SKB has been detached, the POOL needs to have its SKB set to NULL * This free routine walks the list of POOL entries and if SKB is set to * non NULL it is unmapped and freed */ -void iwl_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq) +static void iwl4965_rx_queue_free(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq) { int i; for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { if (rxq->pool[i].skb != NULL) { pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, - IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); + priv->hw_setting.rx_buf_size, + PCI_DMA_FROMDEVICE); dev_kfree_skb(rxq->pool[i].skb); } } @@ -4434,21 +4505,25 @@ void iwl_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq) rxq->bd = NULL; } -int iwl_rx_queue_alloc(struct iwl_priv *priv) +int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv) { - struct iwl_rx_queue *rxq = &priv->rxq; + struct iwl4965_rx_queue *rxq = &priv->rxq; struct pci_dev *dev = priv->pci_dev; int i; spin_lock_init(&rxq->lock); INIT_LIST_HEAD(&rxq->rx_free); INIT_LIST_HEAD(&rxq->rx_used); + + /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); if (!rxq->bd) return -ENOMEM; + /* Fill the rx_used queue with _all_ of the Rx buffers */ for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) list_add_tail(&rxq->pool[i].list, &rxq->rx_used); + /* Set us so that we have processed and used all buffers, but have * not restocked the Rx queue with fresh buffers */ rxq->read = rxq->write = 0; @@ -4457,7 +4532,7 @@ int iwl_rx_queue_alloc(struct iwl_priv *priv) return 0; } -void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq) +void iwl4965_rx_queue_reset(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq) { unsigned long flags; int i; @@ -4471,7 +4546,8 @@ void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq) if (rxq->pool[i].skb != NULL) { pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, - IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); + priv->hw_setting.rx_buf_size, + PCI_DMA_FROMDEVICE); priv->alloc_rxb_skb--; dev_kfree_skb(rxq->pool[i].skb); rxq->pool[i].skb = NULL; @@ -4504,7 +4580,7 @@ static u8 ratio2dB[100] = { /* Calculates a relative dB value from a ratio of linear * (i.e. not dB) signal levels. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ -int iwl_calc_db_from_ratio(int sig_ratio) +int iwl4965_calc_db_from_ratio(int sig_ratio) { /* 1000:1 or higher just report as 60 dB */ if (sig_ratio >= 1000) @@ -4530,7 +4606,7 @@ int iwl_calc_db_from_ratio(int sig_ratio) /* Calculate an indication of rx signal quality (a percentage, not dBm!). * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info * about formulas used below. */ -int iwl_calc_sig_qual(int rssi_dbm, int noise_dbm) +int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) { int sig_qual; int degradation = PERFECT_RSSI - rssi_dbm; @@ -4565,32 +4641,39 @@ int iwl_calc_sig_qual(int rssi_dbm, int noise_dbm) } /** - * iwl_rx_handle - Main entry function for receiving responses from the uCode + * iwl4965_rx_handle - Main entry function for receiving responses from uCode * * Uses the priv->rx_handlers callback function array to invoke * the appropriate handlers, including command responses, * frame-received notifications, and other notifications. */ -static void iwl_rx_handle(struct iwl_priv *priv) +static void iwl4965_rx_handle(struct iwl4965_priv *priv) { - struct iwl_rx_mem_buffer *rxb; - struct iwl_rx_packet *pkt; - struct iwl_rx_queue *rxq = &priv->rxq; + struct iwl4965_rx_mem_buffer *rxb; + struct iwl4965_rx_packet *pkt; + struct iwl4965_rx_queue *rxq = &priv->rxq; u32 r, i; int reclaim; unsigned long flags; + u8 fill_rx = 0; + u32 count = 0; - r = iwl_hw_get_rx_read(priv); + /* uCode's read index (stored in shared DRAM) indicates the last Rx + * buffer that the driver may process (last buffer filled by ucode). */ + r = iwl4965_hw_get_rx_read(priv); i = rxq->read; /* Rx interrupt, but nothing sent from uCode */ if (i == r) IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); + if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) + fill_rx = 1; + while (i != r) { rxb = rxq->queue[i]; - /* If an RXB doesn't have a queue slot associated with it + /* If an RXB doesn't have a Rx queue slot associated with it, * then a bug has been introduced in the queue refilling * routines -- catch it here */ BUG_ON(rxb == NULL); @@ -4598,9 +4681,9 @@ static void iwl_rx_handle(struct iwl_priv *priv) rxq->queue[i] = NULL; pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, - IWL_RX_BUF_SIZE, + priv->hw_setting.rx_buf_size, PCI_DMA_FROMDEVICE); - pkt = (struct iwl_rx_packet *)rxb->skb->data; + pkt = (struct iwl4965_rx_packet *)rxb->skb->data; /* Reclaim a command buffer only if this packet is a response * to a (driver-originated) command. @@ -4617,7 +4700,7 @@ static void iwl_rx_handle(struct iwl_priv *priv) /* Based on type of command response or notification, * handle those that need handling via function in - * rx_handlers table. See iwl_setup_rx_handlers() */ + * rx_handlers table. See iwl4965_setup_rx_handlers() */ if (priv->rx_handlers[pkt->hdr.cmd]) { IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d, %s, 0x%02x\n", r, i, @@ -4632,11 +4715,11 @@ static void iwl_rx_handle(struct iwl_priv *priv) } if (reclaim) { - /* Invoke any callbacks, transfer the skb to caller, - * and fire off the (possibly) blocking iwl_send_cmd() + /* Invoke any callbacks, transfer the skb to caller, and + * fire off the (possibly) blocking iwl4965_send_cmd() * as we reclaim the driver command queue */ if (rxb && rxb->skb) - iwl_tx_cmd_complete(priv, rxb); + iwl4965_tx_cmd_complete(priv, rxb); else IWL_WARNING("Claim null rxb?\n"); } @@ -4651,20 +4734,34 @@ static void iwl_rx_handle(struct iwl_priv *priv) } pci_unmap_single(priv->pci_dev, rxb->dma_addr, - IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); + priv->hw_setting.rx_buf_size, + PCI_DMA_FROMDEVICE); spin_lock_irqsave(&rxq->lock, flags); list_add_tail(&rxb->list, &priv->rxq.rx_used); spin_unlock_irqrestore(&rxq->lock, flags); i = (i + 1) & RX_QUEUE_MASK; + /* If there are a lot of unused frames, + * restock the Rx queue so ucode wont assert. */ + if (fill_rx) { + count++; + if (count >= 8) { + priv->rxq.read = i; + __iwl4965_rx_replenish(priv); + count = 0; + } + } } /* Backtrack one entry */ priv->rxq.read = i; - iwl_rx_queue_restock(priv); + iwl4965_rx_queue_restock(priv); } -int iwl_tx_queue_update_write_ptr(struct iwl_priv *priv, - struct iwl_tx_queue *txq) +/** + * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware + */ +static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, + struct iwl4965_tx_queue *txq) { u32 reg = 0; int rc = 0; @@ -4678,41 +4775,41 @@ int iwl_tx_queue_update_write_ptr(struct iwl_priv *priv, /* wake up nic if it's powered down ... * uCode will wake up, and interrupt us again, so next * time we'll skip this part. */ - reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); + reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); - iwl_set_bit(priv, CSR_GP_CNTRL, + iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); return rc; } /* restore this queue's parameters in nic hardware. */ - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) return rc; - iwl_write_restricted(priv, HBUS_TARG_WRPTR, - txq->q.first_empty | (txq_id << 8)); - iwl_release_restricted_access(priv); + iwl4965_write_direct32(priv, HBUS_TARG_WRPTR, + txq->q.write_ptr | (txq_id << 8)); + iwl4965_release_nic_access(priv); /* else not in power-save mode, uCode will never sleep when we're * trying to tx (during RFKILL, we're not trying to tx). */ } else - iwl_write32(priv, HBUS_TARG_WRPTR, - txq->q.first_empty | (txq_id << 8)); + iwl4965_write32(priv, HBUS_TARG_WRPTR, + txq->q.write_ptr | (txq_id << 8)); txq->need_update = 0; return rc; } -#ifdef CONFIG_IWLWIFI_DEBUG -static void iwl_print_rx_config_cmd(struct iwl_rxon_cmd *rxon) +#ifdef CONFIG_IWL4965_DEBUG +static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon) { DECLARE_MAC_BUF(mac); IWL_DEBUG_RADIO("RX CONFIG:\n"); - iwl_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); + iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", @@ -4729,24 +4826,24 @@ static void iwl_print_rx_config_cmd(struct iwl_rxon_cmd *rxon) } #endif -static void iwl_enable_interrupts(struct iwl_priv *priv) +static void iwl4965_enable_interrupts(struct iwl4965_priv *priv) { IWL_DEBUG_ISR("Enabling interrupts\n"); set_bit(STATUS_INT_ENABLED, &priv->status); - iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); + iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); } -static inline void iwl_disable_interrupts(struct iwl_priv *priv) +static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv) { clear_bit(STATUS_INT_ENABLED, &priv->status); /* disable interrupts from uCode/NIC to host */ - iwl_write32(priv, CSR_INT_MASK, 0x00000000); + iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); /* acknowledge/clear/reset any interrupts still pending * from uCode or flow handler (Rx/Tx DMA) */ - iwl_write32(priv, CSR_INT, 0xffffffff); - iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); + iwl4965_write32(priv, CSR_INT, 0xffffffff); + iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); IWL_DEBUG_ISR("Disabled interrupts\n"); } @@ -4773,7 +4870,7 @@ static const char *desc_lookup(int i) #define ERROR_START_OFFSET (1 * sizeof(u32)) #define ERROR_ELEM_SIZE (7 * sizeof(u32)) -static void iwl_dump_nic_error_log(struct iwl_priv *priv) +static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv) { u32 data2, line; u32 desc, time, count, base, data1; @@ -4782,18 +4879,18 @@ static void iwl_dump_nic_error_log(struct iwl_priv *priv) base = le32_to_cpu(priv->card_alive.error_event_table_ptr); - if (!iwl_hw_valid_rtc_data_addr(base)) { + if (!iwl4965_hw_valid_rtc_data_addr(base)) { IWL_ERROR("Not valid error log pointer 0x%08X\n", base); return; } - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) { IWL_WARNING("Can not read from adapter at this time.\n"); return; } - count = iwl_read_restricted_mem(priv, base); + count = iwl4965_read_targ_mem(priv, base); if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { IWL_ERROR("Start IWL Error Log Dump:\n"); @@ -4801,15 +4898,15 @@ static void iwl_dump_nic_error_log(struct iwl_priv *priv) priv->status, priv->config, count); } - desc = iwl_read_restricted_mem(priv, base + 1 * sizeof(u32)); - blink1 = iwl_read_restricted_mem(priv, base + 3 * sizeof(u32)); - blink2 = iwl_read_restricted_mem(priv, base + 4 * sizeof(u32)); - ilink1 = iwl_read_restricted_mem(priv, base + 5 * sizeof(u32)); - ilink2 = iwl_read_restricted_mem(priv, base + 6 * sizeof(u32)); - data1 = iwl_read_restricted_mem(priv, base + 7 * sizeof(u32)); - data2 = iwl_read_restricted_mem(priv, base + 8 * sizeof(u32)); - line = iwl_read_restricted_mem(priv, base + 9 * sizeof(u32)); - time = iwl_read_restricted_mem(priv, base + 11 * sizeof(u32)); + desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32)); + blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32)); + blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32)); + ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32)); + ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32)); + data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32)); + data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32)); + line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32)); + time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32)); IWL_ERROR("Desc Time " "data1 data2 line\n"); @@ -4819,17 +4916,17 @@ static void iwl_dump_nic_error_log(struct iwl_priv *priv) IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, ilink1, ilink2); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); } #define EVENT_START_OFFSET (4 * sizeof(u32)) /** - * iwl_print_event_log - Dump error event log to syslog + * iwl4965_print_event_log - Dump error event log to syslog * - * NOTE: Must be called with iwl_grab_restricted_access() already obtained! + * NOTE: Must be called with iwl4965_grab_nic_access() already obtained! */ -static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, +static void iwl4965_print_event_log(struct iwl4965_priv *priv, u32 start_idx, u32 num_events, u32 mode) { u32 i; @@ -4853,21 +4950,21 @@ static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, /* "time" is actually "data" for mode 0 (no timestamp). * place event id # at far right for easier visual parsing. */ for (i = 0; i < num_events; i++) { - ev = iwl_read_restricted_mem(priv, ptr); + ev = iwl4965_read_targ_mem(priv, ptr); ptr += sizeof(u32); - time = iwl_read_restricted_mem(priv, ptr); + time = iwl4965_read_targ_mem(priv, ptr); ptr += sizeof(u32); if (mode == 0) IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ else { - data = iwl_read_restricted_mem(priv, ptr); + data = iwl4965_read_targ_mem(priv, ptr); ptr += sizeof(u32); IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); } } } -static void iwl_dump_nic_event_log(struct iwl_priv *priv) +static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv) { int rc; u32 base; /* SRAM byte address of event log header */ @@ -4878,29 +4975,29 @@ static void iwl_dump_nic_event_log(struct iwl_priv *priv) u32 size; /* # entries that we'll print */ base = le32_to_cpu(priv->card_alive.log_event_table_ptr); - if (!iwl_hw_valid_rtc_data_addr(base)) { + if (!iwl4965_hw_valid_rtc_data_addr(base)) { IWL_ERROR("Invalid event log pointer 0x%08X\n", base); return; } - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) { IWL_WARNING("Can not read from adapter at this time.\n"); return; } /* event log header */ - capacity = iwl_read_restricted_mem(priv, base); - mode = iwl_read_restricted_mem(priv, base + (1 * sizeof(u32))); - num_wraps = iwl_read_restricted_mem(priv, base + (2 * sizeof(u32))); - next_entry = iwl_read_restricted_mem(priv, base + (3 * sizeof(u32))); + capacity = iwl4965_read_targ_mem(priv, base); + mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32))); + num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32))); + next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32))); size = num_wraps ? capacity : next_entry; /* bail out if nothing in log */ if (size == 0) { IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); return; } @@ -4910,31 +5007,31 @@ static void iwl_dump_nic_event_log(struct iwl_priv *priv) /* if uCode has wrapped back to top of log, start at the oldest entry, * i.e the next one that uCode would fill. */ if (num_wraps) - iwl_print_event_log(priv, next_entry, + iwl4965_print_event_log(priv, next_entry, capacity - next_entry, mode); /* (then/else) start at top of log */ - iwl_print_event_log(priv, 0, next_entry, mode); + iwl4965_print_event_log(priv, 0, next_entry, mode); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); } /** - * iwl_irq_handle_error - called for HW or SW error interrupt from card + * iwl4965_irq_handle_error - called for HW or SW error interrupt from card */ -static void iwl_irq_handle_error(struct iwl_priv *priv) +static void iwl4965_irq_handle_error(struct iwl4965_priv *priv) { - /* Set the FW error flag -- cleared on iwl_down */ + /* Set the FW error flag -- cleared on iwl4965_down */ set_bit(STATUS_FW_ERROR, &priv->status); /* Cancel currently queued command. */ clear_bit(STATUS_HCMD_ACTIVE, &priv->status); -#ifdef CONFIG_IWLWIFI_DEBUG - if (iwl_debug_level & IWL_DL_FW_ERRORS) { - iwl_dump_nic_error_log(priv); - iwl_dump_nic_event_log(priv); - iwl_print_rx_config_cmd(&priv->staging_rxon); +#ifdef CONFIG_IWL4965_DEBUG + if (iwl4965_debug_level & IWL_DL_FW_ERRORS) { + iwl4965_dump_nic_error_log(priv); + iwl4965_dump_nic_event_log(priv); + iwl4965_print_rx_config_cmd(&priv->staging_rxon); } #endif @@ -4948,7 +5045,7 @@ static void iwl_irq_handle_error(struct iwl_priv *priv) IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, "Restarting adapter due to uCode error.\n"); - if (iwl_is_associated(priv)) { + if (iwl4965_is_associated(priv)) { memcpy(&priv->recovery_rxon, &priv->active_rxon, sizeof(priv->recovery_rxon)); priv->error_recovering = 1; @@ -4957,16 +5054,16 @@ static void iwl_irq_handle_error(struct iwl_priv *priv) } } -static void iwl_error_recovery(struct iwl_priv *priv) +static void iwl4965_error_recovery(struct iwl4965_priv *priv) { unsigned long flags; memcpy(&priv->staging_rxon, &priv->recovery_rxon, sizeof(priv->staging_rxon)); priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); - iwl_rxon_add_station(priv, priv->bssid, 1); + iwl4965_rxon_add_station(priv, priv->bssid, 1); spin_lock_irqsave(&priv->lock, flags); priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); @@ -4974,12 +5071,12 @@ static void iwl_error_recovery(struct iwl_priv *priv) spin_unlock_irqrestore(&priv->lock, flags); } -static void iwl_irq_tasklet(struct iwl_priv *priv) +static void iwl4965_irq_tasklet(struct iwl4965_priv *priv) { u32 inta, handled = 0; u32 inta_fh; unsigned long flags; -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL4965_DEBUG u32 inta_mask; #endif @@ -4988,18 +5085,19 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) /* Ack/clear/reset pending uCode interrupts. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, * and will clear only when CSR_FH_INT_STATUS gets cleared. */ - inta = iwl_read32(priv, CSR_INT); - iwl_write32(priv, CSR_INT, inta); + inta = iwl4965_read32(priv, CSR_INT); + iwl4965_write32(priv, CSR_INT, inta); /* Ack/clear/reset pending flow-handler (DMA) interrupts. * Any new interrupts that happen after this, either while we're * in this tasklet, or later, will show up in next ISR/tasklet. */ - inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); - iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); + inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); + iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh); -#ifdef CONFIG_IWLWIFI_DEBUG - if (iwl_debug_level & IWL_DL_ISR) { - inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ +#ifdef CONFIG_IWL4965_DEBUG + if (iwl4965_debug_level & IWL_DL_ISR) { + /* just for debug */ + inta_mask = iwl4965_read32(priv, CSR_INT_MASK); IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", inta, inta_mask, inta_fh); } @@ -5019,9 +5117,9 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) IWL_ERROR("Microcode HW error detected. Restarting.\n"); /* Tell the device to stop sending interrupts */ - iwl_disable_interrupts(priv); + iwl4965_disable_interrupts(priv); - iwl_irq_handle_error(priv); + iwl4965_irq_handle_error(priv); handled |= CSR_INT_BIT_HW_ERR; @@ -5030,8 +5128,8 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) return; } -#ifdef CONFIG_IWLWIFI_DEBUG - if (iwl_debug_level & (IWL_DL_ISR)) { +#ifdef CONFIG_IWL4965_DEBUG + if (iwl4965_debug_level & (IWL_DL_ISR)) { /* NIC fires this, but we don't use it, redundant with WAKEUP */ if (inta & CSR_INT_BIT_MAC_CLK_ACTV) IWL_DEBUG_ISR("Microcode started or stopped.\n"); @@ -5044,10 +5142,10 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) /* Safely ignore these bits for debug checks below */ inta &= ~(CSR_INT_BIT_MAC_CLK_ACTV | CSR_INT_BIT_ALIVE); - /* HW RF KILL switch toggled (4965 only) */ + /* HW RF KILL switch toggled */ if (inta & CSR_INT_BIT_RF_KILL) { int hw_rf_kill = 0; - if (!(iwl_read32(priv, CSR_GP_CNTRL) & + if (!(iwl4965_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) hw_rf_kill = 1; @@ -5067,7 +5165,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) handled |= CSR_INT_BIT_RF_KILL; } - /* Chip got too hot and stopped itself (4965 only) */ + /* Chip got too hot and stopped itself */ if (inta & CSR_INT_BIT_CT_KILL) { IWL_ERROR("Microcode CT kill error detected.\n"); handled |= CSR_INT_BIT_CT_KILL; @@ -5077,20 +5175,20 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) if (inta & CSR_INT_BIT_SW_ERR) { IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", inta); - iwl_irq_handle_error(priv); + iwl4965_irq_handle_error(priv); handled |= CSR_INT_BIT_SW_ERR; } /* uCode wakes up after power-down sleep */ if (inta & CSR_INT_BIT_WAKEUP) { IWL_DEBUG_ISR("Wakeup interrupt\n"); - iwl_rx_queue_update_write_ptr(priv, &priv->rxq); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[0]); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[1]); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[2]); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[3]); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[4]); - iwl_tx_queue_update_write_ptr(priv, &priv->txq[5]); + iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq); + iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]); + iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]); + iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]); + iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]); + iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]); + iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]); handled |= CSR_INT_BIT_WAKEUP; } @@ -5099,7 +5197,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) * Rx "responses" (frame-received notification), and other * notifications from uCode come through here*/ if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { - iwl_rx_handle(priv); + iwl4965_rx_handle(priv); handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); } @@ -5118,13 +5216,13 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) } /* Re-enable all interrupts */ - iwl_enable_interrupts(priv); + iwl4965_enable_interrupts(priv); -#ifdef CONFIG_IWLWIFI_DEBUG - if (iwl_debug_level & (IWL_DL_ISR)) { - inta = iwl_read32(priv, CSR_INT); - inta_mask = iwl_read32(priv, CSR_INT_MASK); - inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); +#ifdef CONFIG_IWL4965_DEBUG + if (iwl4965_debug_level & (IWL_DL_ISR)) { + inta = iwl4965_read32(priv, CSR_INT); + inta_mask = iwl4965_read32(priv, CSR_INT_MASK); + inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); } @@ -5132,9 +5230,9 @@ static void iwl_irq_tasklet(struct iwl_priv *priv) spin_unlock_irqrestore(&priv->lock, flags); } -static irqreturn_t iwl_isr(int irq, void *data) +static irqreturn_t iwl4965_isr(int irq, void *data) { - struct iwl_priv *priv = data; + struct iwl4965_priv *priv = data; u32 inta, inta_mask; u32 inta_fh; if (!priv) @@ -5146,12 +5244,12 @@ static irqreturn_t iwl_isr(int irq, void *data) * back-to-back ISRs and sporadic interrupts from our NIC. * If we have something to service, the tasklet will re-enable ints. * If we *don't* have something, we'll re-enable before leaving here. */ - inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ - iwl_write32(priv, CSR_INT_MASK, 0x00000000); + inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */ + iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); /* Discover which interrupts are active/pending */ - inta = iwl_read32(priv, CSR_INT); - inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); + inta = iwl4965_read32(priv, CSR_INT); + inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); /* Ignore interrupt if there's nothing in NIC to service. * This may be due to IRQ shared with another device, @@ -5171,7 +5269,7 @@ static irqreturn_t iwl_isr(int irq, void *data) IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", inta, inta_mask, inta_fh); - /* iwl_irq_tasklet() will service interrupts and re-enable them */ + /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ tasklet_schedule(&priv->irq_tasklet); unplugged: @@ -5180,18 +5278,18 @@ static irqreturn_t iwl_isr(int irq, void *data) none: /* re-enable interrupts here since we don't have anything to service. */ - iwl_enable_interrupts(priv); + iwl4965_enable_interrupts(priv); spin_unlock(&priv->lock); return IRQ_NONE; } /************************** EEPROM BANDS **************************** * - * The iwl_eeprom_band definitions below provide the mapping from the + * The iwl4965_eeprom_band definitions below provide the mapping from the * EEPROM contents to the specific channel number supported for each * band. * - * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3 + * For example, iwl4965_priv->eeprom.band_3_channels[4] from the band_3 * definition below maps to physical channel 42 in the 5.2GHz spectrum. * The specific geography and calibration information for that channel * is contained in the eeprom map itself. @@ -5217,76 +5315,77 @@ static irqreturn_t iwl_isr(int irq, void *data) *********************************************************************/ /* 2.4 GHz */ -static const u8 iwl_eeprom_band_1[14] = { +static const u8 iwl4965_eeprom_band_1[14] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }; /* 5.2 GHz bands */ -static const u8 iwl_eeprom_band_2[] = { +static const u8 iwl4965_eeprom_band_2[] = { /* 4915-5080MHz */ 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 }; -static const u8 iwl_eeprom_band_3[] = { /* 5205-5320MHz */ +static const u8 iwl4965_eeprom_band_3[] = { /* 5170-5320MHz */ 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 }; -static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */ +static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */ 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 }; -static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */ +static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */ 145, 149, 153, 157, 161, 165 }; -static u8 iwl_eeprom_band_6[] = { /* 2.4 FAT channel */ +static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */ 1, 2, 3, 4, 5, 6, 7 }; -static u8 iwl_eeprom_band_7[] = { /* 5.2 FAT channel */ +static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */ 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 }; -static void iwl_init_band_reference(const struct iwl_priv *priv, int band, +static void iwl4965_init_band_reference(const struct iwl4965_priv *priv, + int band, int *eeprom_ch_count, - const struct iwl_eeprom_channel + const struct iwl4965_eeprom_channel **eeprom_ch_info, const u8 **eeprom_ch_index) { switch (band) { case 1: /* 2.4GHz band */ - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1); + *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1); *eeprom_ch_info = priv->eeprom.band_1_channels; - *eeprom_ch_index = iwl_eeprom_band_1; + *eeprom_ch_index = iwl4965_eeprom_band_1; break; - case 2: /* 5.2GHz band */ - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2); + case 2: /* 4.9GHz band */ + *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2); *eeprom_ch_info = priv->eeprom.band_2_channels; - *eeprom_ch_index = iwl_eeprom_band_2; + *eeprom_ch_index = iwl4965_eeprom_band_2; break; case 3: /* 5.2GHz band */ - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3); + *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3); *eeprom_ch_info = priv->eeprom.band_3_channels; - *eeprom_ch_index = iwl_eeprom_band_3; + *eeprom_ch_index = iwl4965_eeprom_band_3; break; - case 4: /* 5.2GHz band */ - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4); + case 4: /* 5.5GHz band */ + *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4); *eeprom_ch_info = priv->eeprom.band_4_channels; - *eeprom_ch_index = iwl_eeprom_band_4; + *eeprom_ch_index = iwl4965_eeprom_band_4; break; - case 5: /* 5.2GHz band */ - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5); + case 5: /* 5.7GHz band */ + *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5); *eeprom_ch_info = priv->eeprom.band_5_channels; - *eeprom_ch_index = iwl_eeprom_band_5; + *eeprom_ch_index = iwl4965_eeprom_band_5; break; - case 6: - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6); + case 6: /* 2.4GHz FAT channels */ + *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6); *eeprom_ch_info = priv->eeprom.band_24_channels; - *eeprom_ch_index = iwl_eeprom_band_6; + *eeprom_ch_index = iwl4965_eeprom_band_6; break; - case 7: - *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7); + case 7: /* 5 GHz FAT channels */ + *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7); *eeprom_ch_info = priv->eeprom.band_52_channels; - *eeprom_ch_index = iwl_eeprom_band_7; + *eeprom_ch_index = iwl4965_eeprom_band_7; break; default: BUG(); @@ -5294,7 +5393,12 @@ static void iwl_init_band_reference(const struct iwl_priv *priv, int band, } } -const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv, +/** + * iwl4965_get_channel_info - Find driver's private channel info + * + * Based on band and channel number. + */ +const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv, int phymode, u16 channel) { int i; @@ -5321,13 +5425,16 @@ const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv, #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ ? # x " " : "") -static int iwl_init_channel_map(struct iwl_priv *priv) +/** + * iwl4965_init_channel_map - Set up driver's info for all possible channels + */ +static int iwl4965_init_channel_map(struct iwl4965_priv *priv) { int eeprom_ch_count = 0; const u8 *eeprom_ch_index = NULL; - const struct iwl_eeprom_channel *eeprom_ch_info = NULL; + const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL; int band, ch; - struct iwl_channel_info *ch_info; + struct iwl4965_channel_info *ch_info; if (priv->channel_count) { IWL_DEBUG_INFO("Channel map already initialized.\n"); @@ -5343,15 +5450,15 @@ static int iwl_init_channel_map(struct iwl_priv *priv) IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); priv->channel_count = - ARRAY_SIZE(iwl_eeprom_band_1) + - ARRAY_SIZE(iwl_eeprom_band_2) + - ARRAY_SIZE(iwl_eeprom_band_3) + - ARRAY_SIZE(iwl_eeprom_band_4) + - ARRAY_SIZE(iwl_eeprom_band_5); + ARRAY_SIZE(iwl4965_eeprom_band_1) + + ARRAY_SIZE(iwl4965_eeprom_band_2) + + ARRAY_SIZE(iwl4965_eeprom_band_3) + + ARRAY_SIZE(iwl4965_eeprom_band_4) + + ARRAY_SIZE(iwl4965_eeprom_band_5); IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); - priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) * + priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) * priv->channel_count, GFP_KERNEL); if (!priv->channel_info) { IWL_ERROR("Could not allocate channel_info\n"); @@ -5366,7 +5473,7 @@ static int iwl_init_channel_map(struct iwl_priv *priv) * what just in the EEPROM) */ for (band = 1; band <= 5; band++) { - iwl_init_band_reference(priv, band, &eeprom_ch_count, + iwl4965_init_band_reference(priv, band, &eeprom_ch_count, &eeprom_ch_info, &eeprom_ch_index); /* Loop through each band adding each of the channels */ @@ -5430,14 +5537,17 @@ static int iwl_init_channel_map(struct iwl_priv *priv) } } + /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */ for (band = 6; band <= 7; band++) { int phymode; u8 fat_extension_chan; - iwl_init_band_reference(priv, band, &eeprom_ch_count, + iwl4965_init_band_reference(priv, band, &eeprom_ch_count, &eeprom_ch_info, &eeprom_ch_index); + /* EEPROM band 6 is 2.4, band 7 is 5 GHz */ phymode = (band == 6) ? MODE_IEEE80211B : MODE_IEEE80211A; + /* Loop through each band adding each of the channels */ for (ch = 0; ch < eeprom_ch_count; ch++) { @@ -5449,11 +5559,13 @@ static int iwl_init_channel_map(struct iwl_priv *priv) else fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; + /* Set up driver's info for lower half */ iwl4965_set_fat_chan_info(priv, phymode, eeprom_ch_index[ch], &(eeprom_ch_info[ch]), fat_extension_chan); + /* Set up driver's info for upper half */ iwl4965_set_fat_chan_info(priv, phymode, (eeprom_ch_index[ch] + 4), &(eeprom_ch_info[ch]), @@ -5487,7 +5599,7 @@ static int iwl_init_channel_map(struct iwl_priv *priv) #define IWL_PASSIVE_DWELL_BASE (100) #define IWL_CHANNEL_TUNE_TIME 5 -static inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv, int phymode) +static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv, int phymode) { if (phymode == MODE_IEEE80211A) return IWL_ACTIVE_DWELL_TIME_52; @@ -5495,14 +5607,14 @@ static inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv, int phymode) return IWL_ACTIVE_DWELL_TIME_24; } -static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv, int phymode) +static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv, int phymode) { - u16 active = iwl_get_active_dwell_time(priv, phymode); + u16 active = iwl4965_get_active_dwell_time(priv, phymode); u16 passive = (phymode != MODE_IEEE80211A) ? IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; - if (iwl_is_associated(priv)) { + if (iwl4965_is_associated(priv)) { /* If we're associated, we clamp the maximum passive * dwell time to be 98% of the beacon interval (minus * 2 * channel tune time) */ @@ -5518,30 +5630,30 @@ static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv, int phymode) return passive; } -static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, +static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode, u8 is_active, u8 direct_mask, - struct iwl_scan_channel *scan_ch) + struct iwl4965_scan_channel *scan_ch) { const struct ieee80211_channel *channels = NULL; const struct ieee80211_hw_mode *hw_mode; - const struct iwl_channel_info *ch_info; + const struct iwl4965_channel_info *ch_info; u16 passive_dwell = 0; u16 active_dwell = 0; int added, i; - hw_mode = iwl_get_hw_mode(priv, phymode); + hw_mode = iwl4965_get_hw_mode(priv, phymode); if (!hw_mode) return 0; channels = hw_mode->channels; - active_dwell = iwl_get_active_dwell_time(priv, phymode); - passive_dwell = iwl_get_passive_dwell_time(priv, phymode); + active_dwell = iwl4965_get_active_dwell_time(priv, phymode); + passive_dwell = iwl4965_get_passive_dwell_time(priv, phymode); for (i = 0, added = 0; i < hw_mode->num_channels; i++) { if (channels[i].chan == le16_to_cpu(priv->active_rxon.channel)) { - if (iwl_is_associated(priv)) { + if (iwl4965_is_associated(priv)) { IWL_DEBUG_SCAN ("Skipping current channel %d\n", le16_to_cpu(priv->active_rxon.channel)); @@ -5552,7 +5664,8 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, scan_ch->channel = channels[i].chan; - ch_info = iwl_get_channel_info(priv, phymode, scan_ch->channel); + ch_info = iwl4965_get_channel_info(priv, phymode, + scan_ch->channel); if (!is_channel_valid(ch_info)) { IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", scan_ch->channel); @@ -5574,7 +5687,7 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, scan_ch->active_dwell = cpu_to_le16(active_dwell); scan_ch->passive_dwell = cpu_to_le16(passive_dwell); - /* Set power levels to defaults */ + /* Set txpower levels to defaults */ scan_ch->tpc.dsp_atten = 110; /* scan_pwr_info->tpc.dsp_atten; */ @@ -5584,8 +5697,8 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, else { scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); /* NOTE: if we were doing 6Mb OFDM for scans we'd use - * power level - scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3; + * power level: + * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; */ } @@ -5603,7 +5716,7 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv, int phymode, return added; } -static void iwl_reset_channel_flag(struct iwl_priv *priv) +static void iwl4965_reset_channel_flag(struct iwl4965_priv *priv) { int i, j; for (i = 0; i < 3; i++) { @@ -5613,13 +5726,13 @@ static void iwl_reset_channel_flag(struct iwl_priv *priv) } } -static void iwl_init_hw_rates(struct iwl_priv *priv, +static void iwl4965_init_hw_rates(struct iwl4965_priv *priv, struct ieee80211_rate *rates) { int i; for (i = 0; i < IWL_RATE_COUNT; i++) { - rates[i].rate = iwl_rates[i].ieee * 5; + rates[i].rate = iwl4965_rates[i].ieee * 5; rates[i].val = i; /* Rate scaling will work on indexes */ rates[i].val2 = i; rates[i].flags = IEEE80211_RATE_SUPPORTED; @@ -5631,7 +5744,7 @@ static void iwl_init_hw_rates(struct iwl_priv *priv, * If CCK 1M then set rate flag to CCK else CCK_2 * which is CCK | PREAMBLE2 */ - rates[i].flags |= (iwl_rates[i].plcp == 10) ? + rates[i].flags |= (iwl4965_rates[i].plcp == 10) ? IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2; } @@ -5639,16 +5752,14 @@ static void iwl_init_hw_rates(struct iwl_priv *priv, if (IWL_BASIC_RATES_MASK & (1 << i)) rates[i].flags |= IEEE80211_RATE_BASIC; } - - iwl4965_init_hw_rates(priv, rates); } /** - * iwl_init_geos - Initialize mac80211's geo/channel info based from eeprom + * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom */ -static int iwl_init_geos(struct iwl_priv *priv) +static int iwl4965_init_geos(struct iwl4965_priv *priv) { - struct iwl_channel_info *ch; + struct iwl4965_channel_info *ch; struct ieee80211_hw_mode *modes; struct ieee80211_channel *channels; struct ieee80211_channel *geo_ch; @@ -5658,10 +5769,8 @@ static int iwl_init_geos(struct iwl_priv *priv) A = 0, B = 1, G = 2, - A_11N = 3, - G_11N = 4, }; - int mode_count = 5; + int mode_count = 3; if (priv->modes) { IWL_DEBUG_INFO("Geography modes already initialized.\n"); @@ -5696,11 +5805,14 @@ static int iwl_init_geos(struct iwl_priv *priv) /* 5.2GHz channels start after the 2.4GHz channels */ modes[A].mode = MODE_IEEE80211A; - modes[A].channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)]; + modes[A].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)]; modes[A].rates = rates; modes[A].num_rates = 8; /* just OFDM */ modes[A].rates = &rates[4]; modes[A].num_channels = 0; +#ifdef CONFIG_IWL4965_HT + iwl4965_init_ht_hw_capab(&modes[A].ht_info, MODE_IEEE80211A); +#endif modes[B].mode = MODE_IEEE80211B; modes[B].channels = channels; @@ -5713,23 +5825,14 @@ static int iwl_init_geos(struct iwl_priv *priv) modes[G].rates = rates; modes[G].num_rates = 12; /* OFDM & CCK */ modes[G].num_channels = 0; - - modes[G_11N].mode = MODE_IEEE80211G; - modes[G_11N].channels = channels; - modes[G_11N].num_rates = 13; /* OFDM & CCK */ - modes[G_11N].rates = rates; - modes[G_11N].num_channels = 0; - - modes[A_11N].mode = MODE_IEEE80211A; - modes[A_11N].channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)]; - modes[A_11N].rates = &rates[4]; - modes[A_11N].num_rates = 9; /* just OFDM */ - modes[A_11N].num_channels = 0; +#ifdef CONFIG_IWL4965_HT + iwl4965_init_ht_hw_capab(&modes[G].ht_info, MODE_IEEE80211G); +#endif priv->ieee_channels = channels; priv->ieee_rates = rates; - iwl_init_hw_rates(priv, rates); + iwl4965_init_hw_rates(priv, rates); for (i = 0, geo_ch = channels; i < priv->channel_count; i++) { ch = &priv->channel_info[i]; @@ -5744,11 +5847,9 @@ static int iwl_init_geos(struct iwl_priv *priv) if (is_channel_a_band(ch)) { geo_ch = &modes[A].channels[modes[A].num_channels++]; - modes[A_11N].num_channels++; } else { geo_ch = &modes[B].channels[modes[B].num_channels++]; modes[G].num_channels++; - modes[G_11N].num_channels++; } geo_ch->freq = ieee80211chan2mhz(ch->channel); @@ -5814,57 +5915,22 @@ static int iwl_init_geos(struct iwl_priv *priv) * ******************************************************************************/ -static void iwl_dealloc_ucode_pci(struct iwl_priv *priv) +static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv) { - if (priv->ucode_code.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_code.len, - priv->ucode_code.v_addr, - priv->ucode_code.p_addr); - priv->ucode_code.v_addr = NULL; - } - if (priv->ucode_data.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_data.len, - priv->ucode_data.v_addr, - priv->ucode_data.p_addr); - priv->ucode_data.v_addr = NULL; - } - if (priv->ucode_data_backup.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_data_backup.len, - priv->ucode_data_backup.v_addr, - priv->ucode_data_backup.p_addr); - priv->ucode_data_backup.v_addr = NULL; - } - if (priv->ucode_init.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_init.len, - priv->ucode_init.v_addr, - priv->ucode_init.p_addr); - priv->ucode_init.v_addr = NULL; - } - if (priv->ucode_init_data.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_init_data.len, - priv->ucode_init_data.v_addr, - priv->ucode_init_data.p_addr); - priv->ucode_init_data.v_addr = NULL; - } - if (priv->ucode_boot.v_addr != NULL) { - pci_free_consistent(priv->pci_dev, - priv->ucode_boot.len, - priv->ucode_boot.v_addr, - priv->ucode_boot.p_addr); - priv->ucode_boot.v_addr = NULL; - } + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); + iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); } /** - * iwl_verify_inst_full - verify runtime uCode image in card vs. host, + * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host, * looking at all data. */ -static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 * image, u32 len) +static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 *image, + u32 len) { u32 val; u32 save_len = len; @@ -5873,18 +5939,18 @@ static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 * image, u32 len) IWL_DEBUG_INFO("ucode inst image size is %u\n", len); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) return rc; - iwl_write_restricted(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); + iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); errcnt = 0; for (; len > 0; len -= sizeof(u32), image++) { /* read data comes through single port, auto-incr addr */ /* NOTE: Use the debugless read so we don't flood kernel log * if IWL_DL_IO is set */ - val = _iwl_read_restricted(priv, HBUS_TARG_MEM_RDAT); + val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); if (val != le32_to_cpu(*image)) { IWL_ERROR("uCode INST section is invalid at " "offset 0x%x, is 0x%x, s/b 0x%x\n", @@ -5896,7 +5962,7 @@ static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 * image, u32 len) } } - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); if (!errcnt) IWL_DEBUG_INFO @@ -5907,11 +5973,11 @@ static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 * image, u32 len) /** - * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host, + * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host, * using sample data 100 bytes apart. If these sample points are good, * it's a pretty good bet that everything between them is good, too. */ -static int iwl_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) +static int iwl4965_verify_inst_sparse(struct iwl4965_priv *priv, __le32 *image, u32 len) { u32 val; int rc = 0; @@ -5920,7 +5986,7 @@ static int iwl_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) IWL_DEBUG_INFO("ucode inst image size is %u\n", len); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) return rc; @@ -5928,9 +5994,9 @@ static int iwl_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) /* read data comes through single port, auto-incr addr */ /* NOTE: Use the debugless read so we don't flood kernel log * if IWL_DL_IO is set */ - iwl_write_restricted(priv, HBUS_TARG_MEM_RADDR, + iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, i + RTC_INST_LOWER_BOUND); - val = _iwl_read_restricted(priv, HBUS_TARG_MEM_RDAT); + val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); if (val != le32_to_cpu(*image)) { #if 0 /* Enable this if you want to see details */ IWL_ERROR("uCode INST section is invalid at " @@ -5944,17 +6010,17 @@ static int iwl_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) } } - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); return rc; } /** - * iwl_verify_ucode - determine which instruction image is in SRAM, + * iwl4965_verify_ucode - determine which instruction image is in SRAM, * and verify its contents */ -static int iwl_verify_ucode(struct iwl_priv *priv) +static int iwl4965_verify_ucode(struct iwl4965_priv *priv) { __le32 *image; u32 len; @@ -5963,7 +6029,7 @@ static int iwl_verify_ucode(struct iwl_priv *priv) /* Try bootstrap */ image = (__le32 *)priv->ucode_boot.v_addr; len = priv->ucode_boot.len; - rc = iwl_verify_inst_sparse(priv, image, len); + rc = iwl4965_verify_inst_sparse(priv, image, len); if (rc == 0) { IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); return 0; @@ -5972,7 +6038,7 @@ static int iwl_verify_ucode(struct iwl_priv *priv) /* Try initialize */ image = (__le32 *)priv->ucode_init.v_addr; len = priv->ucode_init.len; - rc = iwl_verify_inst_sparse(priv, image, len); + rc = iwl4965_verify_inst_sparse(priv, image, len); if (rc == 0) { IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); return 0; @@ -5981,7 +6047,7 @@ static int iwl_verify_ucode(struct iwl_priv *priv) /* Try runtime/protocol */ image = (__le32 *)priv->ucode_code.v_addr; len = priv->ucode_code.len; - rc = iwl_verify_inst_sparse(priv, image, len); + rc = iwl4965_verify_inst_sparse(priv, image, len); if (rc == 0) { IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); return 0; @@ -5989,18 +6055,19 @@ static int iwl_verify_ucode(struct iwl_priv *priv) IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); - /* Show first several data entries in instruction SRAM. - * Selection of bootstrap image is arbitrary. */ + /* Since nothing seems to match, show first several data entries in + * instruction SRAM, so maybe visual inspection will give a clue. + * Selection of bootstrap image (vs. other images) is arbitrary. */ image = (__le32 *)priv->ucode_boot.v_addr; len = priv->ucode_boot.len; - rc = iwl_verify_inst_full(priv, image, len); + rc = iwl4965_verify_inst_full(priv, image, len); return rc; } /* check contents of special bootstrap uCode SRAM */ -static int iwl_verify_bsm(struct iwl_priv *priv) +static int iwl4965_verify_bsm(struct iwl4965_priv *priv) { __le32 *image = priv->ucode_boot.v_addr; u32 len = priv->ucode_boot.len; @@ -6010,11 +6077,11 @@ static int iwl_verify_bsm(struct iwl_priv *priv) IWL_DEBUG_INFO("Begin verify bsm\n"); /* verify BSM SRAM contents */ - val = iwl_read_restricted_reg(priv, BSM_WR_DWCOUNT_REG); + val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG); for (reg = BSM_SRAM_LOWER_BOUND; reg < BSM_SRAM_LOWER_BOUND + len; reg += sizeof(u32), image ++) { - val = iwl_read_restricted_reg(priv, reg); + val = iwl4965_read_prph(priv, reg); if (val != le32_to_cpu(*image)) { IWL_ERROR("BSM uCode verification failed at " "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", @@ -6031,7 +6098,7 @@ static int iwl_verify_bsm(struct iwl_priv *priv) } /** - * iwl_load_bsm - Load bootstrap instructions + * iwl4965_load_bsm - Load bootstrap instructions * * BSM operation: * @@ -6062,7 +6129,7 @@ static int iwl_verify_bsm(struct iwl_priv *priv) * the runtime uCode instructions and the backup data cache into SRAM, * and re-launches the runtime uCode from where it left off. */ -static int iwl_load_bsm(struct iwl_priv *priv) +static int iwl4965_load_bsm(struct iwl4965_priv *priv) { __le32 *image = priv->ucode_boot.v_addr; u32 len = priv->ucode_boot.len; @@ -6082,8 +6149,8 @@ static int iwl_load_bsm(struct iwl_priv *priv) return -EINVAL; /* Tell bootstrap uCode where to find the "Initialize" uCode - * in host DRAM ... bits 31:0 for 3945, bits 35:4 for 4965. - * NOTE: iwl_initialize_alive_start() will replace these values, + * in host DRAM ... host DRAM physical address bits 35:4 for 4965. + * NOTE: iwl4965_initialize_alive_start() will replace these values, * after the "initialize" uCode has run, to point to * runtime/protocol instructions and backup data cache. */ pinst = priv->ucode_init.p_addr >> 4; @@ -6091,42 +6158,42 @@ static int iwl_load_bsm(struct iwl_priv *priv) inst_len = priv->ucode_init.len; data_len = priv->ucode_init_data.len; - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) return rc; - iwl_write_restricted_reg(priv, BSM_DRAM_INST_PTR_REG, pinst); - iwl_write_restricted_reg(priv, BSM_DRAM_DATA_PTR_REG, pdata); - iwl_write_restricted_reg(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); - iwl_write_restricted_reg(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); + iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); + iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); + iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); + iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); /* Fill BSM memory with bootstrap instructions */ for (reg_offset = BSM_SRAM_LOWER_BOUND; reg_offset < BSM_SRAM_LOWER_BOUND + len; reg_offset += sizeof(u32), image++) - _iwl_write_restricted_reg(priv, reg_offset, + _iwl4965_write_prph(priv, reg_offset, le32_to_cpu(*image)); - rc = iwl_verify_bsm(priv); + rc = iwl4965_verify_bsm(priv); if (rc) { - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); return rc; } /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ - iwl_write_restricted_reg(priv, BSM_WR_MEM_SRC_REG, 0x0); - iwl_write_restricted_reg(priv, BSM_WR_MEM_DST_REG, + iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); + iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND); - iwl_write_restricted_reg(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); + iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); /* Load bootstrap code into instruction SRAM now, * to prepare to load "initialize" uCode */ - iwl_write_restricted_reg(priv, BSM_WR_CTRL_REG, + iwl4965_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START); /* Wait for load of bootstrap uCode to finish */ for (i = 0; i < 100; i++) { - done = iwl_read_restricted_reg(priv, BSM_WR_CTRL_REG); + done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG); if (!(done & BSM_WR_CTRL_REG_BIT_START)) break; udelay(10); @@ -6140,29 +6207,30 @@ static int iwl_load_bsm(struct iwl_priv *priv) /* Enable future boot loads whenever power management unit triggers it * (e.g. when powering back up after power-save shutdown) */ - iwl_write_restricted_reg(priv, BSM_WR_CTRL_REG, + iwl4965_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); return 0; } -static void iwl_nic_start(struct iwl_priv *priv) +static void iwl4965_nic_start(struct iwl4965_priv *priv) { /* Remove all resets to allow NIC to operate */ - iwl_write32(priv, CSR_RESET, 0); + iwl4965_write32(priv, CSR_RESET, 0); } + /** - * iwl_read_ucode - Read uCode images from disk file. + * iwl4965_read_ucode - Read uCode images from disk file. * * Copy into buffers for card to fetch via bus-mastering */ -static int iwl_read_ucode(struct iwl_priv *priv) +static int iwl4965_read_ucode(struct iwl4965_priv *priv) { - struct iwl_ucode *ucode; - int rc = 0; + struct iwl4965_ucode *ucode; + int ret; const struct firmware *ucode_raw; const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode"; u8 *src; @@ -6171,9 +6239,10 @@ static int iwl_read_ucode(struct iwl_priv *priv) /* Ask kernel firmware_class module to get the boot firmware off disk. * request_firmware() is synchronous, file is in memory on return. */ - rc = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); - if (rc < 0) { - IWL_ERROR("%s firmware file req failed: Reason %d\n", name, rc); + ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); + if (ret < 0) { + IWL_ERROR("%s firmware file req failed: Reason %d\n", + name, ret); goto error; } @@ -6183,7 +6252,7 @@ static int iwl_read_ucode(struct iwl_priv *priv) /* Make sure that we got at least our header! */ if (ucode_raw->size < sizeof(*ucode)) { IWL_ERROR("File size way too small!\n"); - rc = -EINVAL; + ret = -EINVAL; goto err_release; } @@ -6216,43 +6285,43 @@ static int iwl_read_ucode(struct iwl_priv *priv) IWL_DEBUG_INFO("uCode file size %d too small\n", (int)ucode_raw->size); - rc = -EINVAL; + ret = -EINVAL; goto err_release; } /* Verify that uCode images will fit in card's SRAM */ if (inst_size > IWL_MAX_INST_SIZE) { - IWL_DEBUG_INFO("uCode instr len %d too large to fit in card\n", - (int)inst_size); - rc = -EINVAL; + IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", + inst_size); + ret = -EINVAL; goto err_release; } if (data_size > IWL_MAX_DATA_SIZE) { - IWL_DEBUG_INFO("uCode data len %d too large to fit in card\n", - (int)data_size); - rc = -EINVAL; + IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", + data_size); + ret = -EINVAL; goto err_release; } if (init_size > IWL_MAX_INST_SIZE) { IWL_DEBUG_INFO - ("uCode init instr len %d too large to fit in card\n", - (int)init_size); - rc = -EINVAL; + ("uCode init instr len %d too large to fit in\n", + init_size); + ret = -EINVAL; goto err_release; } if (init_data_size > IWL_MAX_DATA_SIZE) { IWL_DEBUG_INFO - ("uCode init data len %d too large to fit in card\n", - (int)init_data_size); - rc = -EINVAL; + ("uCode init data len %d too large to fit in\n", + init_data_size); + ret = -EINVAL; goto err_release; } if (boot_size > IWL_MAX_BSM_SIZE) { IWL_DEBUG_INFO - ("uCode boot instr len %d too large to fit in bsm\n", - (int)boot_size); - rc = -EINVAL; + ("uCode boot instr len %d too large to fit in\n", + boot_size); + ret = -EINVAL; goto err_release; } @@ -6262,66 +6331,50 @@ static int iwl_read_ucode(struct iwl_priv *priv) * 1) unmodified from disk * 2) backup cache for save/restore during power-downs */ priv->ucode_code.len = inst_size; - priv->ucode_code.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_code.len, - &(priv->ucode_code.p_addr)); + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); priv->ucode_data.len = data_size; - priv->ucode_data.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_data.len, - &(priv->ucode_data.p_addr)); + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); priv->ucode_data_backup.len = data_size; - priv->ucode_data_backup.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_data_backup.len, - &(priv->ucode_data_backup.p_addr)); - + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); /* Initialization instructions and data */ - priv->ucode_init.len = init_size; - priv->ucode_init.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_init.len, - &(priv->ucode_init.p_addr)); - - priv->ucode_init_data.len = init_data_size; - priv->ucode_init_data.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_init_data.len, - &(priv->ucode_init_data.p_addr)); + if (init_size && init_data_size) { + priv->ucode_init.len = init_size; + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); + + priv->ucode_init_data.len = init_data_size; + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); + + if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) + goto err_pci_alloc; + } /* Bootstrap (instructions only, no data) */ - priv->ucode_boot.len = boot_size; - priv->ucode_boot.v_addr = - pci_alloc_consistent(priv->pci_dev, - priv->ucode_boot.len, - &(priv->ucode_boot.p_addr)); + if (boot_size) { + priv->ucode_boot.len = boot_size; + iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); - if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || - !priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr || - !priv->ucode_boot.v_addr || !priv->ucode_data_backup.v_addr) - goto err_pci_alloc; + if (!priv->ucode_boot.v_addr) + goto err_pci_alloc; + } /* Copy images into buffers for card's bus-master reads ... */ /* Runtime instructions (first block of data in file) */ src = &ucode->data[0]; len = priv->ucode_code.len; - IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %d\n", - (int)len); + IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len); memcpy(priv->ucode_code.v_addr, src, len); IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); /* Runtime data (2nd block) - * NOTE: Copy into backup buffer will be done in iwl_up() */ + * NOTE: Copy into backup buffer will be done in iwl4965_up() */ src = &ucode->data[inst_size]; len = priv->ucode_data.len; - IWL_DEBUG_INFO("Copying (but not loading) uCode data len %d\n", - (int)len); + IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len); memcpy(priv->ucode_data.v_addr, src, len); memcpy(priv->ucode_data_backup.v_addr, src, len); @@ -6329,8 +6382,8 @@ static int iwl_read_ucode(struct iwl_priv *priv) if (init_size) { src = &ucode->data[inst_size + data_size]; len = priv->ucode_init.len; - IWL_DEBUG_INFO("Copying (but not loading) init instr len %d\n", - (int)len); + IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", + len); memcpy(priv->ucode_init.v_addr, src, len); } @@ -6338,16 +6391,15 @@ static int iwl_read_ucode(struct iwl_priv *priv) if (init_data_size) { src = &ucode->data[inst_size + data_size + init_size]; len = priv->ucode_init_data.len; - IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n", - (int)len); + IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", + len); memcpy(priv->ucode_init_data.v_addr, src, len); } /* Bootstrap instructions (5th block) */ src = &ucode->data[inst_size + data_size + init_size + init_data_size]; len = priv->ucode_boot.len; - IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n", - (int)len); + IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len); memcpy(priv->ucode_boot.v_addr, src, len); /* We have our copies now, allow OS release its copies */ @@ -6356,19 +6408,19 @@ static int iwl_read_ucode(struct iwl_priv *priv) err_pci_alloc: IWL_ERROR("failed to allocate pci memory\n"); - rc = -ENOMEM; - iwl_dealloc_ucode_pci(priv); + ret = -ENOMEM; + iwl4965_dealloc_ucode_pci(priv); err_release: release_firmware(ucode_raw); error: - return rc; + return ret; } /** - * iwl_set_ucode_ptrs - Set uCode address location + * iwl4965_set_ucode_ptrs - Set uCode address location * * Tell initialization uCode where to find runtime uCode. * @@ -6376,7 +6428,7 @@ static int iwl_read_ucode(struct iwl_priv *priv) * We need to replace them to load runtime uCode inst and data, * and to save runtime data when powering down. */ -static int iwl_set_ucode_ptrs(struct iwl_priv *priv) +static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv) { dma_addr_t pinst; dma_addr_t pdata; @@ -6388,24 +6440,24 @@ static int iwl_set_ucode_ptrs(struct iwl_priv *priv) pdata = priv->ucode_data_backup.p_addr >> 4; spin_lock_irqsave(&priv->lock, flags); - rc = iwl_grab_restricted_access(priv); + rc = iwl4965_grab_nic_access(priv); if (rc) { spin_unlock_irqrestore(&priv->lock, flags); return rc; } /* Tell bootstrap uCode where to find image to load */ - iwl_write_restricted_reg(priv, BSM_DRAM_INST_PTR_REG, pinst); - iwl_write_restricted_reg(priv, BSM_DRAM_DATA_PTR_REG, pdata); - iwl_write_restricted_reg(priv, BSM_DRAM_DATA_BYTECOUNT_REG, + iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); + iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); + iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, priv->ucode_data.len); /* Inst bytecount must be last to set up, bit 31 signals uCode * that all new ptr/size info is in place */ - iwl_write_restricted_reg(priv, BSM_DRAM_INST_BYTECOUNT_REG, + iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, priv->ucode_code.len | BSM_DRAM_INST_LOAD); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); spin_unlock_irqrestore(&priv->lock, flags); @@ -6415,7 +6467,7 @@ static int iwl_set_ucode_ptrs(struct iwl_priv *priv) } /** - * iwl_init_alive_start - Called after REPLY_ALIVE notification receieved + * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received * * Called after REPLY_ALIVE notification received from "initialize" uCode. * @@ -6425,7 +6477,7 @@ static int iwl_set_ucode_ptrs(struct iwl_priv *priv) * * Tell "initialize" uCode to go ahead and load the runtime uCode. */ -static void iwl_init_alive_start(struct iwl_priv *priv) +static void iwl4965_init_alive_start(struct iwl4965_priv *priv) { /* Check alive response for "valid" sign from uCode */ if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { @@ -6438,7 +6490,7 @@ static void iwl_init_alive_start(struct iwl_priv *priv) /* Bootstrap uCode has loaded initialize uCode ... verify inst image. * This is a paranoid check, because we would not have gotten the * "initialize" alive if code weren't properly loaded. */ - if (iwl_verify_ucode(priv)) { + if (iwl4965_verify_ucode(priv)) { /* Runtime instruction load was bad; * take it all the way back down so we can try again */ IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); @@ -6452,7 +6504,7 @@ static void iwl_init_alive_start(struct iwl_priv *priv) * load and launch runtime uCode, which will send us another "Alive" * notification. */ IWL_DEBUG_INFO("Initialization Alive received.\n"); - if (iwl_set_ucode_ptrs(priv)) { + if (iwl4965_set_ucode_ptrs(priv)) { /* Runtime instruction load won't happen; * take it all the way back down so we can try again */ IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); @@ -6466,11 +6518,11 @@ static void iwl_init_alive_start(struct iwl_priv *priv) /** - * iwl_alive_start - called after REPLY_ALIVE notification received + * iwl4965_alive_start - called after REPLY_ALIVE notification received * from protocol/runtime uCode (initialization uCode's - * Alive gets handled by iwl_init_alive_start()). + * Alive gets handled by iwl4965_init_alive_start()). */ -static void iwl_alive_start(struct iwl_priv *priv) +static void iwl4965_alive_start(struct iwl4965_priv *priv) { int rc = 0; @@ -6486,14 +6538,14 @@ static void iwl_alive_start(struct iwl_priv *priv) /* Initialize uCode has loaded Runtime uCode ... verify inst image. * This is a paranoid check, because we would not have gotten the * "runtime" alive if code weren't properly loaded. */ - if (iwl_verify_ucode(priv)) { + if (iwl4965_verify_ucode(priv)) { /* Runtime instruction load was bad; * take it all the way back down so we can try again */ IWL_DEBUG_INFO("Bad runtime uCode load.\n"); goto restart; } - iwl_clear_stations_table(priv); + iwl4965_clear_stations_table(priv); rc = iwl4965_alive_notify(priv); if (rc) { @@ -6502,78 +6554,61 @@ static void iwl_alive_start(struct iwl_priv *priv) goto restart; } - /* After the ALIVE response, we can process host commands */ + /* After the ALIVE response, we can send host commands to 4965 uCode */ set_bit(STATUS_ALIVE, &priv->status); /* Clear out the uCode error bit if it is set */ clear_bit(STATUS_FW_ERROR, &priv->status); - rc = iwl_init_channel_map(priv); + rc = iwl4965_init_channel_map(priv); if (rc) { IWL_ERROR("initializing regulatory failed: %d\n", rc); return; } - iwl_init_geos(priv); + iwl4965_init_geos(priv); + iwl4965_reset_channel_flag(priv); - if (iwl_is_rfkill(priv)) + if (iwl4965_is_rfkill(priv)) return; - if (!priv->mac80211_registered) { - /* Unlock so any user space entry points can call back into - * the driver without a deadlock... */ - mutex_unlock(&priv->mutex); - iwl_rate_control_register(priv->hw); - rc = ieee80211_register_hw(priv->hw); - priv->hw->conf.beacon_int = 100; - mutex_lock(&priv->mutex); - - if (rc) { - iwl_rate_control_unregister(priv->hw); - IWL_ERROR("Failed to register network " - "device (error %d)\n", rc); - return; - } - - priv->mac80211_registered = 1; - - iwl_reset_channel_flag(priv); - } else - ieee80211_start_queues(priv->hw); + ieee80211_start_queues(priv->hw); priv->active_rate = priv->rates_mask; priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; - iwl_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); + iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); - if (iwl_is_associated(priv)) { - struct iwl_rxon_cmd *active_rxon = - (struct iwl_rxon_cmd *)(&priv->active_rxon); + if (iwl4965_is_associated(priv)) { + struct iwl4965_rxon_cmd *active_rxon = + (struct iwl4965_rxon_cmd *)(&priv->active_rxon); memcpy(&priv->staging_rxon, &priv->active_rxon, sizeof(priv->staging_rxon)); active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; } else { /* Initialize our rx_config data */ - iwl_connection_init_rx_config(priv); + iwl4965_connection_init_rx_config(priv); memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); } - /* Configure BT coexistence */ - iwl_send_bt_config(priv); + /* Configure Bluetooth device coexistence support */ + iwl4965_send_bt_config(priv); /* Configure the adapter for unassociated operation */ - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); /* At this point, the NIC is initialized and operational */ priv->notif_missed_beacons = 0; set_bit(STATUS_READY, &priv->status); iwl4965_rf_kill_ct_config(priv); + IWL_DEBUG_INFO("ALIVE processing complete.\n"); + wake_up_interruptible(&priv->wait_command_queue); if (priv->error_recovering) - iwl_error_recovery(priv); + iwl4965_error_recovery(priv); return; @@ -6581,9 +6616,9 @@ static void iwl_alive_start(struct iwl_priv *priv) queue_work(priv->workqueue, &priv->restart); } -static void iwl_cancel_deferred_work(struct iwl_priv *priv); +static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv); -static void __iwl_down(struct iwl_priv *priv) +static void __iwl4965_down(struct iwl4965_priv *priv) { unsigned long flags; int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); @@ -6596,7 +6631,7 @@ static void __iwl_down(struct iwl_priv *priv) if (!exit_pending) set_bit(STATUS_EXIT_PENDING, &priv->status); - iwl_clear_stations_table(priv); + iwl4965_clear_stations_table(priv); /* Unblock any waiting calls */ wake_up_interruptible_all(&priv->wait_command_queue); @@ -6607,17 +6642,17 @@ static void __iwl_down(struct iwl_priv *priv) clear_bit(STATUS_EXIT_PENDING, &priv->status); /* stop and reset the on-board processor */ - iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); + iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); /* tell the device to stop sending interrupts */ - iwl_disable_interrupts(priv); + iwl4965_disable_interrupts(priv); if (priv->mac80211_registered) ieee80211_stop_queues(priv->hw); - /* If we have not previously called iwl_init() then + /* If we have not previously called iwl4965_init() then * clear all bits but the RF Kill and SUSPEND bits and return */ - if (!iwl_is_init(priv)) { + if (!iwl4965_is_init(priv)) { priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << STATUS_RF_KILL_HW | test_bit(STATUS_RF_KILL_SW, &priv->status) << @@ -6639,53 +6674,52 @@ static void __iwl_down(struct iwl_priv *priv) STATUS_FW_ERROR; spin_lock_irqsave(&priv->lock, flags); - iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); + iwl4965_clear_bit(priv, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); spin_unlock_irqrestore(&priv->lock, flags); - iwl_hw_txq_ctx_stop(priv); - iwl_hw_rxq_stop(priv); + iwl4965_hw_txq_ctx_stop(priv); + iwl4965_hw_rxq_stop(priv); spin_lock_irqsave(&priv->lock, flags); - if (!iwl_grab_restricted_access(priv)) { - iwl_write_restricted_reg(priv, APMG_CLK_DIS_REG, + if (!iwl4965_grab_nic_access(priv)) { + iwl4965_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT); - iwl_release_restricted_access(priv); + iwl4965_release_nic_access(priv); } spin_unlock_irqrestore(&priv->lock, flags); udelay(5); - iwl_hw_nic_stop_master(priv); - iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); - iwl_hw_nic_reset(priv); + iwl4965_hw_nic_stop_master(priv); + iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); + iwl4965_hw_nic_reset(priv); exit: - memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); + memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); if (priv->ibss_beacon) dev_kfree_skb(priv->ibss_beacon); priv->ibss_beacon = NULL; /* clear out any free frames */ - iwl_clear_free_frames(priv); + iwl4965_clear_free_frames(priv); } -static void iwl_down(struct iwl_priv *priv) +static void iwl4965_down(struct iwl4965_priv *priv) { mutex_lock(&priv->mutex); - __iwl_down(priv); + __iwl4965_down(priv); mutex_unlock(&priv->mutex); - iwl_cancel_deferred_work(priv); + iwl4965_cancel_deferred_work(priv); } #define MAX_HW_RESTARTS 5 -static int __iwl_up(struct iwl_priv *priv) +static int __iwl4965_up(struct iwl4965_priv *priv) { - DECLARE_MAC_BUF(mac); int rc, i; - u32 hw_rf_kill = 0; if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { IWL_WARNING("Exit pending; will not bring the NIC up\n"); @@ -6695,56 +6729,65 @@ static int __iwl_up(struct iwl_priv *priv) if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { IWL_WARNING("Radio disabled by SW RF kill (module " "parameter)\n"); - return 0; + return -ENODEV; + } + + /* If platform's RF_KILL switch is NOT set to KILL */ + if (iwl4965_read32(priv, CSR_GP_CNTRL) & + CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) + clear_bit(STATUS_RF_KILL_HW, &priv->status); + else { + set_bit(STATUS_RF_KILL_HW, &priv->status); + if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { + IWL_WARNING("Radio disabled by HW RF Kill switch\n"); + return -ENODEV; + } + } + + if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { + IWL_ERROR("ucode not available for device bringup\n"); + return -EIO; } - iwl_write32(priv, CSR_INT, 0xFFFFFFFF); + iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); - rc = iwl_hw_nic_init(priv); + rc = iwl4965_hw_nic_init(priv); if (rc) { IWL_ERROR("Unable to int nic\n"); return rc; } /* make sure rfkill handshake bits are cleared */ - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, + iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); /* clear (again), then enable host interrupts */ - iwl_write32(priv, CSR_INT, 0xFFFFFFFF); - iwl_enable_interrupts(priv); + iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); + iwl4965_enable_interrupts(priv); /* really make sure rfkill handshake bits are cleared */ - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); + iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); /* Copy original ucode data image from disk into backup cache. * This will be used to initialize the on-board processor's * data SRAM for a clean start when the runtime program first loads. */ memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, - priv->ucode_data.len); - - /* If platform's RF_KILL switch is set to KILL, - * wait for BIT_INT_RF_KILL interrupt before loading uCode - * and getting things started */ - if (!(iwl_read32(priv, CSR_GP_CNTRL) & - CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) - hw_rf_kill = 1; + priv->ucode_data.len); - if (test_bit(STATUS_RF_KILL_HW, &priv->status) || hw_rf_kill) { - IWL_WARNING("Radio disabled by HW RF Kill switch\n"); + /* We return success when we resume from suspend and rf_kill is on. */ + if (test_bit(STATUS_RF_KILL_HW, &priv->status)) return 0; - } for (i = 0; i < MAX_HW_RESTARTS; i++) { - iwl_clear_stations_table(priv); + iwl4965_clear_stations_table(priv); /* load bootstrap state machine, * load bootstrap program into processor's memory, * prepare to load the "initialize" uCode */ - rc = iwl_load_bsm(priv); + rc = iwl4965_load_bsm(priv); if (rc) { IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc); @@ -6752,14 +6795,7 @@ static int __iwl_up(struct iwl_priv *priv) } /* start card; "initialize" will load runtime ucode */ - iwl_nic_start(priv); - - /* MAC Address location in EEPROM same for 3945/4965 */ - get_eeprom_mac(priv, priv->mac_addr); - IWL_DEBUG_INFO("MAC address: %s\n", - print_mac(mac, priv->mac_addr)); - - SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); + iwl4965_nic_start(priv); IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); @@ -6767,7 +6803,7 @@ static int __iwl_up(struct iwl_priv *priv) } set_bit(STATUS_EXIT_PENDING, &priv->status); - __iwl_down(priv); + __iwl4965_down(priv); /* tried to restart and config the device for as long as our * patience could withstand */ @@ -6782,35 +6818,35 @@ static int __iwl_up(struct iwl_priv *priv) * *****************************************************************************/ -static void iwl_bg_init_alive_start(struct work_struct *data) +static void iwl4965_bg_init_alive_start(struct work_struct *data) { - struct iwl_priv *priv = - container_of(data, struct iwl_priv, init_alive_start.work); + struct iwl4965_priv *priv = + container_of(data, struct iwl4965_priv, init_alive_start.work); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; mutex_lock(&priv->mutex); - iwl_init_alive_start(priv); + iwl4965_init_alive_start(priv); mutex_unlock(&priv->mutex); } -static void iwl_bg_alive_start(struct work_struct *data) +static void iwl4965_bg_alive_start(struct work_struct *data) { - struct iwl_priv *priv = - container_of(data, struct iwl_priv, alive_start.work); + struct iwl4965_priv *priv = + container_of(data, struct iwl4965_priv, alive_start.work); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; mutex_lock(&priv->mutex); - iwl_alive_start(priv); + iwl4965_alive_start(priv); mutex_unlock(&priv->mutex); } -static void iwl_bg_rf_kill(struct work_struct *work) +static void iwl4965_bg_rf_kill(struct work_struct *work) { - struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); + struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill); wake_up_interruptible(&priv->wait_command_queue); @@ -6819,7 +6855,7 @@ static void iwl_bg_rf_kill(struct work_struct *work) mutex_lock(&priv->mutex); - if (!iwl_is_rfkill(priv)) { + if (!iwl4965_is_rfkill(priv)) { IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, "HW and/or SW RF Kill no longer active, restarting " "device\n"); @@ -6840,10 +6876,10 @@ static void iwl_bg_rf_kill(struct work_struct *work) #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) -static void iwl_bg_scan_check(struct work_struct *data) +static void iwl4965_bg_scan_check(struct work_struct *data) { - struct iwl_priv *priv = - container_of(data, struct iwl_priv, scan_check.work); + struct iwl4965_priv *priv = + container_of(data, struct iwl4965_priv, scan_check.work); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; @@ -6856,22 +6892,22 @@ static void iwl_bg_scan_check(struct work_struct *data) jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) - iwl_send_scan_abort(priv); + iwl4965_send_scan_abort(priv); } mutex_unlock(&priv->mutex); } -static void iwl_bg_request_scan(struct work_struct *data) +static void iwl4965_bg_request_scan(struct work_struct *data) { - struct iwl_priv *priv = - container_of(data, struct iwl_priv, request_scan); - struct iwl_host_cmd cmd = { + struct iwl4965_priv *priv = + container_of(data, struct iwl4965_priv, request_scan); + struct iwl4965_host_cmd cmd = { .id = REPLY_SCAN_CMD, - .len = sizeof(struct iwl_scan_cmd), + .len = sizeof(struct iwl4965_scan_cmd), .meta.flags = CMD_SIZE_HUGE, }; int rc = 0; - struct iwl_scan_cmd *scan; + struct iwl4965_scan_cmd *scan; struct ieee80211_conf *conf = NULL; u8 direct_mask; int phymode; @@ -6880,7 +6916,7 @@ static void iwl_bg_request_scan(struct work_struct *data) mutex_lock(&priv->mutex); - if (!iwl_is_ready(priv)) { + if (!iwl4965_is_ready(priv)) { IWL_WARNING("request scan called when driver not ready.\n"); goto done; } @@ -6909,7 +6945,7 @@ static void iwl_bg_request_scan(struct work_struct *data) goto done; } - if (iwl_is_rfkill(priv)) { + if (iwl4965_is_rfkill(priv)) { IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); goto done; } @@ -6925,7 +6961,7 @@ static void iwl_bg_request_scan(struct work_struct *data) } if (!priv->scan) { - priv->scan = kmalloc(sizeof(struct iwl_scan_cmd) + + priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE, GFP_KERNEL); if (!priv->scan) { rc = -ENOMEM; @@ -6933,12 +6969,12 @@ static void iwl_bg_request_scan(struct work_struct *data) } } scan = priv->scan; - memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE); + memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; scan->quiet_time = IWL_ACTIVE_QUIET_TIME; - if (iwl_is_associated(priv)) { + if (iwl4965_is_associated(priv)) { u16 interval = 0; u32 extra; u32 suspend_time = 100; @@ -6968,14 +7004,14 @@ static void iwl_bg_request_scan(struct work_struct *data) if (priv->one_direct_scan) { IWL_DEBUG_SCAN ("Kicking off one direct scan for '%s'\n", - iwl_escape_essid(priv->direct_ssid, + iwl4965_escape_essid(priv->direct_ssid, priv->direct_ssid_len)); scan->direct_scan[0].id = WLAN_EID_SSID; scan->direct_scan[0].len = priv->direct_ssid_len; memcpy(scan->direct_scan[0].ssid, priv->direct_ssid, priv->direct_ssid_len); direct_mask = 1; - } else if (!iwl_is_associated(priv) && priv->essid_len) { + } else if (!iwl4965_is_associated(priv) && priv->essid_len) { scan->direct_scan[0].id = WLAN_EID_SSID; scan->direct_scan[0].len = priv->essid_len; memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); @@ -6986,7 +7022,7 @@ static void iwl_bg_request_scan(struct work_struct *data) /* We don't build a direct scan probe request; the uCode will do * that based on the direct_mask added to each channel entry */ scan->tx_cmd.len = cpu_to_le16( - iwl_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, + iwl4965_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, IWL_MAX_SCAN_SIZE - sizeof(scan), 0)); scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; @@ -7000,7 +7036,7 @@ static void iwl_bg_request_scan(struct work_struct *data) case 2: scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; scan->tx_cmd.rate_n_flags = - iwl_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, + iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); scan->good_CRC_th = 0; @@ -7009,7 +7045,7 @@ static void iwl_bg_request_scan(struct work_struct *data) case 1: scan->tx_cmd.rate_n_flags = - iwl_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, + iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, RATE_MCS_ANT_B_MSK); scan->good_CRC_th = IWL_GOOD_CRC_TH; phymode = MODE_IEEE80211A; @@ -7036,23 +7072,23 @@ static void iwl_bg_request_scan(struct work_struct *data) if (direct_mask) IWL_DEBUG_SCAN ("Initiating direct scan for %s.\n", - iwl_escape_essid(priv->essid, priv->essid_len)); + iwl4965_escape_essid(priv->essid, priv->essid_len)); else IWL_DEBUG_SCAN("Initiating indirect scan.\n"); scan->channel_count = - iwl_get_channels_for_scan( + iwl4965_get_channels_for_scan( priv, phymode, 1, /* active */ direct_mask, (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); cmd.len += le16_to_cpu(scan->tx_cmd.len) + - scan->channel_count * sizeof(struct iwl_scan_channel); + scan->channel_count * sizeof(struct iwl4965_scan_channel); cmd.data = scan; scan->len = cpu_to_le16(cmd.len); set_bit(STATUS_SCAN_HW, &priv->status); - rc = iwl_send_cmd_sync(priv, &cmd); + rc = iwl4965_send_cmd_sync(priv, &cmd); if (rc) goto done; @@ -7063,50 +7099,52 @@ static void iwl_bg_request_scan(struct work_struct *data) return; done: - /* inform mac80211 sacn aborted */ + /* inform mac80211 scan aborted */ queue_work(priv->workqueue, &priv->scan_completed); mutex_unlock(&priv->mutex); } -static void iwl_bg_up(struct work_struct *data) +static void iwl4965_bg_up(struct work_struct *data) { - struct iwl_priv *priv = container_of(data, struct iwl_priv, up); + struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; mutex_lock(&priv->mutex); - __iwl_up(priv); + __iwl4965_up(priv); mutex_unlock(&priv->mutex); } -static void iwl_bg_restart(struct work_struct *data) +static void iwl4965_bg_restart(struct work_struct *data) { - struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); + struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; - iwl_down(priv); + iwl4965_down(priv); queue_work(priv->workqueue, &priv->up); } -static void iwl_bg_rx_replenish(struct work_struct *data) +static void iwl4965_bg_rx_replenish(struct work_struct *data) { - struct iwl_priv *priv = - container_of(data, struct iwl_priv, rx_replenish); + struct iwl4965_priv *priv = + container_of(data, struct iwl4965_priv, rx_replenish); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; mutex_lock(&priv->mutex); - iwl_rx_replenish(priv); + iwl4965_rx_replenish(priv); mutex_unlock(&priv->mutex); } -static void iwl_bg_post_associate(struct work_struct *data) +#define IWL_DELAY_NEXT_SCAN (HZ*2) + +static void iwl4965_bg_post_associate(struct work_struct *data) { - struct iwl_priv *priv = container_of(data, struct iwl_priv, + struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, post_associate.work); int rc = 0; @@ -7128,20 +7166,20 @@ static void iwl_bg_post_associate(struct work_struct *data) mutex_lock(&priv->mutex); - if (!priv->interface_id || !priv->is_open) { + if (!priv->vif || !priv->is_open) { mutex_unlock(&priv->mutex); return; } - iwl_scan_cancel_timeout(priv, 200); + iwl4965_scan_cancel_timeout(priv, 200); conf = ieee80211_get_hw_conf(priv->hw); priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); - memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); - iwl_setup_rxon_timing(priv); - rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, + memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); + iwl4965_setup_rxon_timing(priv); + rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, sizeof(priv->rxon_timing), &priv->rxon_timing); if (rc) IWL_WARNING("REPLY_RXON_TIMING failed - " @@ -7149,15 +7187,10 @@ static void iwl_bg_post_associate(struct work_struct *data) priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; -#ifdef CONFIG_IWLWIFI_HT - if (priv->is_ht_enabled && priv->current_assoc_ht.is_ht) - iwl4965_set_rxon_ht(priv, &priv->current_assoc_ht); - else { - priv->active_rate_ht[0] = 0; - priv->active_rate_ht[1] = 0; - priv->current_channel_width = IWL_CHANNEL_WIDTH_20MHZ; - } -#endif /* CONFIG_IWLWIFI_HT*/ +#ifdef CONFIG_IWL4965_HT + if (priv->current_ht_config.is_ht) + iwl4965_set_rxon_ht(priv, &priv->current_ht_config); +#endif /* CONFIG_IWL4965_HT*/ iwl4965_set_rxon_chain(priv); priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); @@ -7180,22 +7213,22 @@ static void iwl_bg_post_associate(struct work_struct *data) } - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); switch (priv->iw_mode) { case IEEE80211_IF_TYPE_STA: - iwl_rate_scale_init(priv->hw, IWL_AP_ID); + iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); break; case IEEE80211_IF_TYPE_IBSS: /* clear out the station table */ - iwl_clear_stations_table(priv); + iwl4965_clear_stations_table(priv); - iwl_rxon_add_station(priv, BROADCAST_ADDR, 0); - iwl_rxon_add_station(priv, priv->bssid, 0); - iwl_rate_scale_init(priv->hw, IWL_STA_ID); - iwl_send_beacon_cmd(priv); + iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); + iwl4965_rxon_add_station(priv, priv->bssid, 0); + iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); + iwl4965_send_beacon_cmd(priv); break; @@ -7205,55 +7238,61 @@ static void iwl_bg_post_associate(struct work_struct *data) break; } - iwl_sequence_reset(priv); + iwl4965_sequence_reset(priv); -#ifdef CONFIG_IWLWIFI_SENSITIVITY +#ifdef CONFIG_IWL4965_SENSITIVITY /* Enable Rx differential gain and sensitivity calibrations */ iwl4965_chain_noise_reset(priv); priv->start_calib = 1; -#endif /* CONFIG_IWLWIFI_SENSITIVITY */ +#endif /* CONFIG_IWL4965_SENSITIVITY */ if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) priv->assoc_station_added = 1; -#ifdef CONFIG_IWLWIFI_QOS - iwl_activate_qos(priv, 0); -#endif /* CONFIG_IWLWIFI_QOS */ +#ifdef CONFIG_IWL4965_QOS + iwl4965_activate_qos(priv, 0); +#endif /* CONFIG_IWL4965_QOS */ + /* we have just associated, don't start scan too early */ + priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; mutex_unlock(&priv->mutex); } -static void iwl_bg_abort_scan(struct work_struct *work) +static void iwl4965_bg_abort_scan(struct work_struct *work) { - struct iwl_priv *priv = container_of(work, struct iwl_priv, - abort_scan); + struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan); - if (!iwl_is_ready(priv)) + if (!iwl4965_is_ready(priv)) return; mutex_lock(&priv->mutex); set_bit(STATUS_SCAN_ABORTING, &priv->status); - iwl_send_scan_abort(priv); + iwl4965_send_scan_abort(priv); mutex_unlock(&priv->mutex); } -static void iwl_bg_scan_completed(struct work_struct *work) +static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); + +static void iwl4965_bg_scan_completed(struct work_struct *work) { - struct iwl_priv *priv = - container_of(work, struct iwl_priv, scan_completed); + struct iwl4965_priv *priv = + container_of(work, struct iwl4965_priv, scan_completed); IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); if (test_bit(STATUS_EXIT_PENDING, &priv->status)) return; + if (test_bit(STATUS_CONF_PENDING, &priv->status)) + iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); + ieee80211_scan_completed(priv->hw); /* Since setting the TXPOWER may have been deferred while * performing the scan, fire one off */ mutex_lock(&priv->mutex); - iwl_hw_reg_send_txpower(priv); + iwl4965_hw_reg_send_txpower(priv); mutex_unlock(&priv->mutex); } @@ -7263,50 +7302,123 @@ static void iwl_bg_scan_completed(struct work_struct *work) * *****************************************************************************/ -static int iwl_mac_start(struct ieee80211_hw *hw) +#define UCODE_READY_TIMEOUT (2 * HZ) + +static int iwl4965_mac_start(struct ieee80211_hw *hw) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; + int ret; IWL_DEBUG_MAC80211("enter\n"); + if (pci_enable_device(priv->pci_dev)) { + IWL_ERROR("Fail to pci_enable_device\n"); + return -ENODEV; + } + pci_restore_state(priv->pci_dev); + pci_enable_msi(priv->pci_dev); + + ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, + DRV_NAME, priv); + if (ret) { + IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); + goto out_disable_msi; + } + /* we should be verifying the device is ready to be opened */ mutex_lock(&priv->mutex); - priv->is_open = 1; + memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd)); + /* fetch ucode file from disk, alloc and copy to bus-master buffers ... + * ucode filename and max sizes are card-specific. */ + + if (!priv->ucode_code.len) { + ret = iwl4965_read_ucode(priv); + if (ret) { + IWL_ERROR("Could not read microcode: %d\n", ret); + mutex_unlock(&priv->mutex); + goto out_release_irq; + } + } - if (!iwl_is_rfkill(priv)) - ieee80211_start_queues(priv->hw); + ret = __iwl4965_up(priv); mutex_unlock(&priv->mutex); + + if (ret) + goto out_release_irq; + + IWL_DEBUG_INFO("Start UP work done.\n"); + + if (test_bit(STATUS_IN_SUSPEND, &priv->status)) + return 0; + + /* Wait for START_ALIVE from ucode. Otherwise callbacks from + * mac80211 will not be run successfully. */ + ret = wait_event_interruptible_timeout(priv->wait_command_queue, + test_bit(STATUS_READY, &priv->status), + UCODE_READY_TIMEOUT); + if (!ret) { + if (!test_bit(STATUS_READY, &priv->status)) { + IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", + jiffies_to_msecs(UCODE_READY_TIMEOUT)); + ret = -ETIMEDOUT; + goto out_release_irq; + } + } + + priv->is_open = 1; IWL_DEBUG_MAC80211("leave\n"); return 0; + +out_release_irq: + free_irq(priv->pci_dev->irq, priv); +out_disable_msi: + pci_disable_msi(priv->pci_dev); + pci_disable_device(priv->pci_dev); + priv->is_open = 0; + IWL_DEBUG_MAC80211("leave - failed\n"); + return ret; } -static void iwl_mac_stop(struct ieee80211_hw *hw) +static void iwl4965_mac_stop(struct ieee80211_hw *hw) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; IWL_DEBUG_MAC80211("enter\n"); + if (!priv->is_open) { + IWL_DEBUG_MAC80211("leave - skip\n"); + return; + } - mutex_lock(&priv->mutex); - /* stop mac, cancel any scan request and clear - * RXON_FILTER_ASSOC_MSK BIT - */ priv->is_open = 0; - iwl_scan_cancel_timeout(priv, 100); - cancel_delayed_work(&priv->post_associate); - priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); - mutex_unlock(&priv->mutex); + + if (iwl4965_is_ready_rf(priv)) { + /* stop mac, cancel any scan request and clear + * RXON_FILTER_ASSOC_MSK BIT + */ + mutex_lock(&priv->mutex); + iwl4965_scan_cancel_timeout(priv, 100); + cancel_delayed_work(&priv->post_associate); + mutex_unlock(&priv->mutex); + } + + iwl4965_down(priv); + + flush_workqueue(priv->workqueue); + free_irq(priv->pci_dev->irq, priv); + pci_disable_msi(priv->pci_dev); + pci_save_state(priv->pci_dev); + pci_disable_device(priv->pci_dev); IWL_DEBUG_MAC80211("leave\n"); } -static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, +static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, struct ieee80211_tx_control *ctl) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; IWL_DEBUG_MAC80211("enter\n"); @@ -7318,29 +7430,29 @@ static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, ctl->tx_rate); - if (iwl_tx_skb(priv, skb, ctl)) + if (iwl4965_tx_skb(priv, skb, ctl)) dev_kfree_skb_any(skb); IWL_DEBUG_MAC80211("leave\n"); return 0; } -static int iwl_mac_add_interface(struct ieee80211_hw *hw, +static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_if_init_conf *conf) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; unsigned long flags; DECLARE_MAC_BUF(mac); - IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type); + IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); - if (priv->interface_id) { - IWL_DEBUG_MAC80211("leave - interface_id != 0\n"); + if (priv->vif) { + IWL_DEBUG_MAC80211("leave - vif != NULL\n"); return 0; } spin_lock_irqsave(&priv->lock, flags); - priv->interface_id = conf->if_id; + priv->vif = conf->vif; spin_unlock_irqrestore(&priv->lock, flags); @@ -7350,58 +7462,62 @@ static int iwl_mac_add_interface(struct ieee80211_hw *hw, IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); } - iwl_set_mode(priv, conf->type); - IWL_DEBUG_MAC80211("leave\n"); + if (iwl4965_is_ready(priv)) + iwl4965_set_mode(priv, conf->type); + mutex_unlock(&priv->mutex); + IWL_DEBUG_MAC80211("leave\n"); return 0; } /** - * iwl_mac_config - mac80211 config callback + * iwl4965_mac_config - mac80211 config callback * * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to * be set inappropriately and the driver currently sets the hardware up to * use it whenever needed. */ -static int iwl_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) +static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) { - struct iwl_priv *priv = hw->priv; - const struct iwl_channel_info *ch_info; + struct iwl4965_priv *priv = hw->priv; + const struct iwl4965_channel_info *ch_info; unsigned long flags; + int ret = 0; mutex_lock(&priv->mutex); IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel); - if (!iwl_is_ready(priv)) { + priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); + + if (!iwl4965_is_ready(priv)) { IWL_DEBUG_MAC80211("leave - not ready\n"); - mutex_unlock(&priv->mutex); - return -EIO; + ret = -EIO; + goto out; } - /* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only - * what is exposed through include/ declrations */ - if (unlikely(!iwl_param_disable_hw_scan && + if (unlikely(!iwl4965_param_disable_hw_scan && test_bit(STATUS_SCANNING, &priv->status))) { IWL_DEBUG_MAC80211("leave - scanning\n"); + set_bit(STATUS_CONF_PENDING, &priv->status); mutex_unlock(&priv->mutex); return 0; } spin_lock_irqsave(&priv->lock, flags); - ch_info = iwl_get_channel_info(priv, conf->phymode, conf->channel); + ch_info = iwl4965_get_channel_info(priv, conf->phymode, conf->channel); if (!is_channel_valid(ch_info)) { IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n", conf->channel, conf->phymode); IWL_DEBUG_MAC80211("leave - invalid channel\n"); spin_unlock_irqrestore(&priv->lock, flags); - mutex_unlock(&priv->mutex); - return -EINVAL; + ret = -EINVAL; + goto out; } -#ifdef CONFIG_IWLWIFI_HT +#ifdef CONFIG_IWL4965_HT /* if we are switching fron ht to 2.4 clear flags * from any ht related info since 2.4 does not * support ht */ @@ -7411,57 +7527,56 @@ static int iwl_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) #endif ) priv->staging_rxon.flags = 0; -#endif /* CONFIG_IWLWIFI_HT */ +#endif /* CONFIG_IWL4965_HT */ - iwl_set_rxon_channel(priv, conf->phymode, conf->channel); + iwl4965_set_rxon_channel(priv, conf->phymode, conf->channel); - iwl_set_flags_for_phymode(priv, conf->phymode); + iwl4965_set_flags_for_phymode(priv, conf->phymode); /* The list of supported rates and rate mask can be different * for each phymode; since the phymode may have changed, reset * the rate mask to what mac80211 lists */ - iwl_set_rate(priv); + iwl4965_set_rate(priv); spin_unlock_irqrestore(&priv->lock, flags); #ifdef IEEE80211_CONF_CHANNEL_SWITCH if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { - iwl_hw_channel_switch(priv, conf->channel); - mutex_unlock(&priv->mutex); - return 0; + iwl4965_hw_channel_switch(priv, conf->channel); + goto out; } #endif - iwl_radio_kill_sw(priv, !conf->radio_enabled); + iwl4965_radio_kill_sw(priv, !conf->radio_enabled); if (!conf->radio_enabled) { IWL_DEBUG_MAC80211("leave - radio disabled\n"); - mutex_unlock(&priv->mutex); - return 0; + goto out; } - if (iwl_is_rfkill(priv)) { + if (iwl4965_is_rfkill(priv)) { IWL_DEBUG_MAC80211("leave - RF kill\n"); - mutex_unlock(&priv->mutex); - return -EIO; + ret = -EIO; + goto out; } - iwl_set_rate(priv); + iwl4965_set_rate(priv); if (memcmp(&priv->active_rxon, &priv->staging_rxon, sizeof(priv->staging_rxon))) - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); else IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); IWL_DEBUG_MAC80211("leave\n"); +out: + clear_bit(STATUS_CONF_PENDING, &priv->status); mutex_unlock(&priv->mutex); - - return 0; + return ret; } -static void iwl_config_ap(struct iwl_priv *priv) +static void iwl4965_config_ap(struct iwl4965_priv *priv) { int rc = 0; @@ -7473,12 +7588,12 @@ static void iwl_config_ap(struct iwl_priv *priv) /* RXON - unassoc (to set timing command) */ priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); /* RXON Timing */ - memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); - iwl_setup_rxon_timing(priv); - rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, + memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); + iwl4965_setup_rxon_timing(priv); + rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, sizeof(priv->rxon_timing), &priv->rxon_timing); if (rc) IWL_WARNING("REPLY_RXON_TIMING failed - " @@ -7510,23 +7625,24 @@ static void iwl_config_ap(struct iwl_priv *priv) } /* restore RXON assoc */ priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); -#ifdef CONFIG_IWLWIFI_QOS - iwl_activate_qos(priv, 1); + iwl4965_commit_rxon(priv); +#ifdef CONFIG_IWL4965_QOS + iwl4965_activate_qos(priv, 1); #endif - iwl_rxon_add_station(priv, BROADCAST_ADDR, 0); + iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); } - iwl_send_beacon_cmd(priv); + iwl4965_send_beacon_cmd(priv); /* FIXME - we need to add code here to detect a totally new * configuration, reset the AP, unassoc, rxon timing, assoc, * clear sta table, add BCAST sta... */ } -static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, +static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, struct ieee80211_if_conf *conf) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; DECLARE_MAC_BUF(mac); unsigned long flags; int rc; @@ -7541,9 +7657,11 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, return 0; } + if (!iwl4965_is_alive(priv)) + return -EAGAIN; + mutex_lock(&priv->mutex); - IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id); if (conf->bssid) IWL_DEBUG_MAC80211("bssid: %s\n", print_mac(mac, conf->bssid)); @@ -7560,8 +7678,8 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, return 0; } - if (priv->interface_id != if_id) { - IWL_DEBUG_MAC80211("leave - interface_id != if_id\n"); + if (priv->vif != vif) { + IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); mutex_unlock(&priv->mutex); return 0; } @@ -7579,11 +7697,14 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, priv->ibss_beacon = conf->beacon; } + if (iwl4965_is_rfkill(priv)) + goto done; + if (conf->bssid && !is_zero_ether_addr(conf->bssid) && !is_multicast_ether_addr(conf->bssid)) { /* If there is currently a HW scan going on in the background * then we need to cancel it else the RXON below will fail. */ - if (iwl_scan_cancel_timeout(priv, 100)) { + if (iwl4965_scan_cancel_timeout(priv, 100)) { IWL_WARNING("Aborted scan still in progress " "after 100ms\n"); IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); @@ -7599,20 +7720,21 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, memcpy(priv->bssid, conf->bssid, ETH_ALEN); if (priv->iw_mode == IEEE80211_IF_TYPE_AP) - iwl_config_ap(priv); + iwl4965_config_ap(priv); else { - rc = iwl_commit_rxon(priv); + rc = iwl4965_commit_rxon(priv); if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) - iwl_rxon_add_station( + iwl4965_rxon_add_station( priv, priv->active_rxon.bssid_addr, 1); } } else { - iwl_scan_cancel_timeout(priv, 100); + iwl4965_scan_cancel_timeout(priv, 100); priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); } + done: spin_lock_irqsave(&priv->lock, flags); if (!conf->ssid_len) memset(priv->essid, 0, IW_ESSID_MAX_SIZE); @@ -7628,34 +7750,35 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw, int if_id, return 0; } -static void iwl_configure_filter(struct ieee80211_hw *hw, +static void iwl4965_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags, unsigned int *total_flags, int mc_count, struct dev_addr_list *mc_list) { /* * XXX: dummy - * see also iwl_connection_init_rx_config + * see also iwl4965_connection_init_rx_config */ *total_flags = 0; } -static void iwl_mac_remove_interface(struct ieee80211_hw *hw, +static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, struct ieee80211_if_init_conf *conf) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; IWL_DEBUG_MAC80211("enter\n"); mutex_lock(&priv->mutex); - iwl_scan_cancel_timeout(priv, 100); - cancel_delayed_work(&priv->post_associate); - priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); - - if (priv->interface_id == conf->if_id) { - priv->interface_id = 0; + if (iwl4965_is_ready_rf(priv)) { + iwl4965_scan_cancel_timeout(priv, 100); + cancel_delayed_work(&priv->post_associate); + priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; + iwl4965_commit_rxon(priv); + } + if (priv->vif == conf->vif) { + priv->vif = NULL; memset(priv->bssid, 0, ETH_ALEN); memset(priv->essid, 0, IW_ESSID_MAX_SIZE); priv->essid_len = 0; @@ -7666,19 +7789,50 @@ static void iwl_mac_remove_interface(struct ieee80211_hw *hw, } -#define IWL_DELAY_NEXT_SCAN (HZ*2) -static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) +static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, + struct ieee80211_vif *vif, + struct ieee80211_bss_conf *bss_conf, + u32 changes) +{ + struct iwl4965_priv *priv = hw->priv; + + if (changes & BSS_CHANGED_ERP_PREAMBLE) { + if (bss_conf->use_short_preamble) + priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; + else + priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; + } + + if (changes & BSS_CHANGED_ERP_CTS_PROT) { + if (bss_conf->use_cts_prot && (priv->phymode != MODE_IEEE80211A)) + priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; + else + priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; + } + + if (changes & BSS_CHANGED_ASSOC) { + /* + * TODO: + * do stuff instead of sniffing assoc resp + */ + } + + if (iwl4965_is_associated(priv)) + iwl4965_send_rxon_assoc(priv); +} + +static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) { int rc = 0; unsigned long flags; - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; IWL_DEBUG_MAC80211("enter\n"); mutex_lock(&priv->mutex); spin_lock_irqsave(&priv->lock, flags); - if (!iwl_is_ready_rf(priv)) { + if (!iwl4965_is_ready_rf(priv)) { rc = -EIO; IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); goto out_unlock; @@ -7690,17 +7844,21 @@ static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) goto out_unlock; } + /* we don't schedule scan within next_scan_jiffies period */ + if (priv->next_scan_jiffies && + time_after(priv->next_scan_jiffies, jiffies)) { + rc = -EAGAIN; + goto out_unlock; + } /* if we just finished scan ask for delay */ - if (priv->last_scan_jiffies && - time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, - jiffies)) { + if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + + IWL_DELAY_NEXT_SCAN, jiffies)) { rc = -EAGAIN; goto out_unlock; } if (len) { - IWL_DEBUG_SCAN("direct scan for " - "%s [%d]\n ", - iwl_escape_essid(ssid, len), (int)len); + IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", + iwl4965_escape_essid(ssid, len), (int)len); priv->one_direct_scan = 1; priv->direct_ssid_len = (u8) @@ -7709,7 +7867,7 @@ static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) } else priv->one_direct_scan = 0; - rc = iwl_scan_initiate(priv); + rc = iwl4965_scan_initiate(priv); IWL_DEBUG_MAC80211("leave\n"); @@ -7720,18 +7878,18 @@ out_unlock: return rc; } -static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, +static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, const u8 *local_addr, const u8 *addr, struct ieee80211_key_conf *key) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; DECLARE_MAC_BUF(mac); int rc = 0; u8 sta_id; IWL_DEBUG_MAC80211("enter\n"); - if (!iwl_param_hwcrypto) { + if (!iwl4965_param_hwcrypto) { IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); return -EOPNOTSUPP; } @@ -7740,7 +7898,7 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, /* only support pairwise keys */ return -EOPNOTSUPP; - sta_id = iwl_hw_find_station(priv, addr); + sta_id = iwl4965_hw_find_station(priv, addr); if (sta_id == IWL_INVALID_STATION) { IWL_DEBUG_MAC80211("leave - %s not in station map.\n", print_mac(mac, addr)); @@ -7749,24 +7907,24 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, mutex_lock(&priv->mutex); - iwl_scan_cancel_timeout(priv, 100); + iwl4965_scan_cancel_timeout(priv, 100); switch (cmd) { case SET_KEY: - rc = iwl_update_sta_key_info(priv, key, sta_id); + rc = iwl4965_update_sta_key_info(priv, key, sta_id); if (!rc) { - iwl_set_rxon_hwcrypto(priv, 1); - iwl_commit_rxon(priv); + iwl4965_set_rxon_hwcrypto(priv, 1); + iwl4965_commit_rxon(priv); key->hw_key_idx = sta_id; IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; } break; case DISABLE_KEY: - rc = iwl_clear_sta_key_info(priv, sta_id); + rc = iwl4965_clear_sta_key_info(priv, sta_id); if (!rc) { - iwl_set_rxon_hwcrypto(priv, 0); - iwl_commit_rxon(priv); + iwl4965_set_rxon_hwcrypto(priv, 0); + iwl4965_commit_rxon(priv); IWL_DEBUG_MAC80211("disable hwcrypto key\n"); } break; @@ -7780,18 +7938,18 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, return rc; } -static int iwl_mac_conf_tx(struct ieee80211_hw *hw, int queue, +static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue, const struct ieee80211_tx_queue_params *params) { - struct iwl_priv *priv = hw->priv; -#ifdef CONFIG_IWLWIFI_QOS + struct iwl4965_priv *priv = hw->priv; +#ifdef CONFIG_IWL4965_QOS unsigned long flags; int q; -#endif /* CONFIG_IWL_QOS */ +#endif /* CONFIG_IWL4965_QOS */ IWL_DEBUG_MAC80211("enter\n"); - if (!iwl_is_ready_rf(priv)) { + if (!iwl4965_is_ready_rf(priv)) { IWL_DEBUG_MAC80211("leave - RF not ready\n"); return -EIO; } @@ -7801,7 +7959,7 @@ static int iwl_mac_conf_tx(struct ieee80211_hw *hw, int queue, return 0; } -#ifdef CONFIG_IWLWIFI_QOS +#ifdef CONFIG_IWL4965_QOS if (!priv->qos_data.qos_enable) { priv->qos_data.qos_active = 0; IWL_DEBUG_MAC80211("leave - qos not enabled\n"); @@ -7824,30 +7982,30 @@ static int iwl_mac_conf_tx(struct ieee80211_hw *hw, int queue, mutex_lock(&priv->mutex); if (priv->iw_mode == IEEE80211_IF_TYPE_AP) - iwl_activate_qos(priv, 1); - else if (priv->assoc_id && iwl_is_associated(priv)) - iwl_activate_qos(priv, 0); + iwl4965_activate_qos(priv, 1); + else if (priv->assoc_id && iwl4965_is_associated(priv)) + iwl4965_activate_qos(priv, 0); mutex_unlock(&priv->mutex); -#endif /*CONFIG_IWLWIFI_QOS */ +#endif /*CONFIG_IWL4965_QOS */ IWL_DEBUG_MAC80211("leave\n"); return 0; } -static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw, +static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, struct ieee80211_tx_queue_stats *stats) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; int i, avail; - struct iwl_tx_queue *txq; - struct iwl_queue *q; + struct iwl4965_tx_queue *txq; + struct iwl4965_queue *q; unsigned long flags; IWL_DEBUG_MAC80211("enter\n"); - if (!iwl_is_ready_rf(priv)) { + if (!iwl4965_is_ready_rf(priv)) { IWL_DEBUG_MAC80211("leave - RF not ready\n"); return -EIO; } @@ -7857,7 +8015,7 @@ static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw, for (i = 0; i < AC_NUM; i++) { txq = &priv->txq[i]; q = &txq->q; - avail = iwl_queue_space(q); + avail = iwl4965_queue_space(q); stats->data[i].len = q->n_window - avail; stats->data[i].limit = q->n_window - q->high_mark; @@ -7871,7 +8029,7 @@ static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw, return 0; } -static int iwl_mac_get_stats(struct ieee80211_hw *hw, +static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, struct ieee80211_low_level_stats *stats) { IWL_DEBUG_MAC80211("enter\n"); @@ -7880,7 +8038,7 @@ static int iwl_mac_get_stats(struct ieee80211_hw *hw, return 0; } -static u64 iwl_mac_get_tsf(struct ieee80211_hw *hw) +static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) { IWL_DEBUG_MAC80211("enter\n"); IWL_DEBUG_MAC80211("leave\n"); @@ -7888,35 +8046,35 @@ static u64 iwl_mac_get_tsf(struct ieee80211_hw *hw) return 0; } -static void iwl_mac_reset_tsf(struct ieee80211_hw *hw) +static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; unsigned long flags; mutex_lock(&priv->mutex); IWL_DEBUG_MAC80211("enter\n"); priv->lq_mngr.lq_ready = 0; -#ifdef CONFIG_IWLWIFI_HT +#ifdef CONFIG_IWL4965_HT spin_lock_irqsave(&priv->lock, flags); - memset(&priv->current_assoc_ht, 0, sizeof(struct sta_ht_info)); + memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); spin_unlock_irqrestore(&priv->lock, flags); -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT_AGG /* if (priv->lq_mngr.agg_ctrl.granted_ba) iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);*/ - memset(&(priv->lq_mngr.agg_ctrl), 0, sizeof(struct iwl_agg_control)); + memset(&(priv->lq_mngr.agg_ctrl), 0, sizeof(struct iwl4965_agg_control)); priv->lq_mngr.agg_ctrl.tid_traffic_load_threshold = 10; priv->lq_mngr.agg_ctrl.ba_timeout = 5000; priv->lq_mngr.agg_ctrl.auto_agg = 1; if (priv->lq_mngr.agg_ctrl.auto_agg) priv->lq_mngr.agg_ctrl.requested_ba = TID_ALL_ENABLED; -#endif /*CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ +#endif /*CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ -#ifdef CONFIG_IWLWIFI_QOS - iwl_reset_qos(priv); +#ifdef CONFIG_IWL4965_QOS + iwl4965_reset_qos(priv); #endif cancel_delayed_work(&priv->post_associate); @@ -7941,13 +8099,19 @@ static void iwl_mac_reset_tsf(struct ieee80211_hw *hw) spin_unlock_irqrestore(&priv->lock, flags); + if (!iwl4965_is_ready_rf(priv)) { + IWL_DEBUG_MAC80211("leave - not ready\n"); + mutex_unlock(&priv->mutex); + return; + } + /* we are restarting association process * clear RXON_FILTER_ASSOC_MSK bit */ if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { - iwl_scan_cancel_timeout(priv, 100); + iwl4965_scan_cancel_timeout(priv, 100); priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); } /* Per mac80211.h: This is only used in IBSS mode... */ @@ -7958,32 +8122,25 @@ static void iwl_mac_reset_tsf(struct ieee80211_hw *hw) return; } - if (!iwl_is_ready_rf(priv)) { - IWL_DEBUG_MAC80211("leave - not ready\n"); - mutex_unlock(&priv->mutex); - return; - } - priv->only_active_channel = 0; - iwl_set_rate(priv); + iwl4965_set_rate(priv); mutex_unlock(&priv->mutex); IWL_DEBUG_MAC80211("leave\n"); - } -static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, +static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, struct ieee80211_tx_control *control) { - struct iwl_priv *priv = hw->priv; + struct iwl4965_priv *priv = hw->priv; unsigned long flags; mutex_lock(&priv->mutex); IWL_DEBUG_MAC80211("enter\n"); - if (!iwl_is_ready_rf(priv)) { + if (!iwl4965_is_ready_rf(priv)) { IWL_DEBUG_MAC80211("leave - RF not ready\n"); mutex_unlock(&priv->mutex); return -EIO; @@ -8007,8 +8164,8 @@ static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, IWL_DEBUG_MAC80211("leave\n"); spin_unlock_irqrestore(&priv->lock, flags); -#ifdef CONFIG_IWLWIFI_QOS - iwl_reset_qos(priv); +#ifdef CONFIG_IWL4965_QOS + iwl4965_reset_qos(priv); #endif queue_work(priv->workqueue, &priv->post_associate.work); @@ -8018,133 +8175,62 @@ static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, return 0; } -#ifdef CONFIG_IWLWIFI_HT -union ht_cap_info { - struct { - u16 advanced_coding_cap :1; - u16 supported_chan_width_set :1; - u16 mimo_power_save_mode :2; - u16 green_field :1; - u16 short_GI20 :1; - u16 short_GI40 :1; - u16 tx_stbc :1; - u16 rx_stbc :1; - u16 beam_forming :1; - u16 delayed_ba :1; - u16 maximal_amsdu_size :1; - u16 cck_mode_at_40MHz :1; - u16 psmp_support :1; - u16 stbc_ctrl_frame_support :1; - u16 sig_txop_protection_support :1; - }; - u16 val; -} __attribute__ ((packed)); - -union ht_param_info{ - struct { - u8 max_rx_ampdu_factor :2; - u8 mpdu_density :3; - u8 reserved :3; - }; - u8 val; -} __attribute__ ((packed)); - -union ht_exra_param_info { - struct { - u8 ext_chan_offset :2; - u8 tx_chan_width :1; - u8 rifs_mode :1; - u8 controlled_access_only :1; - u8 service_interval_granularity :3; - }; - u8 val; -} __attribute__ ((packed)); - -union ht_operation_mode{ - struct { - u16 op_mode :2; - u16 non_GF :1; - u16 reserved :13; - }; - u16 val; -} __attribute__ ((packed)); - +#ifdef CONFIG_IWL4965_HT -static int sta_ht_info_init(struct ieee80211_ht_capability *ht_cap, - struct ieee80211_ht_additional_info *ht_extra, - struct sta_ht_info *ht_info_ap, - struct sta_ht_info *ht_info) +static void iwl4965_ht_info_fill(struct ieee80211_conf *conf, + struct iwl4965_priv *priv) { - union ht_cap_info cap; - union ht_operation_mode op_mode; - union ht_param_info param_info; - union ht_exra_param_info extra_param_info; + struct iwl_ht_info *iwl_conf = &priv->current_ht_config; + struct ieee80211_ht_info *ht_conf = &conf->ht_conf; + struct ieee80211_ht_bss_info *ht_bss_conf = &conf->ht_bss_conf; IWL_DEBUG_MAC80211("enter: \n"); - if (!ht_info) { - IWL_DEBUG_MAC80211("leave: ht_info is NULL\n"); - return -1; + if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) { + iwl_conf->is_ht = 0; + return; } - if (ht_cap) { - cap.val = (u16) le16_to_cpu(ht_cap->capabilities_info); - param_info.val = ht_cap->mac_ht_params_info; - ht_info->is_ht = 1; - if (cap.short_GI20) - ht_info->sgf |= 0x1; - if (cap.short_GI40) - ht_info->sgf |= 0x2; - ht_info->is_green_field = cap.green_field; - ht_info->max_amsdu_size = cap.maximal_amsdu_size; - ht_info->supported_chan_width = cap.supported_chan_width_set; - ht_info->tx_mimo_ps_mode = cap.mimo_power_save_mode; - memcpy(ht_info->supp_rates, ht_cap->supported_mcs_set, 16); - - ht_info->ampdu_factor = param_info.max_rx_ampdu_factor; - ht_info->mpdu_density = param_info.mpdu_density; - - IWL_DEBUG_MAC80211("SISO mask 0x%X MIMO mask 0x%X \n", - ht_cap->supported_mcs_set[0], - ht_cap->supported_mcs_set[1]); - - if (ht_info_ap) { - ht_info->control_channel = ht_info_ap->control_channel; - ht_info->extension_chan_offset = - ht_info_ap->extension_chan_offset; - ht_info->tx_chan_width = ht_info_ap->tx_chan_width; - ht_info->operating_mode = ht_info_ap->operating_mode; - } - - if (ht_extra) { - extra_param_info.val = ht_extra->ht_param; - ht_info->control_channel = ht_extra->control_chan; - ht_info->extension_chan_offset = - extra_param_info.ext_chan_offset; - ht_info->tx_chan_width = extra_param_info.tx_chan_width; - op_mode.val = (u16) - le16_to_cpu(ht_extra->operation_mode); - ht_info->operating_mode = op_mode.op_mode; - IWL_DEBUG_MAC80211("control channel %d\n", - ht_extra->control_chan); - } - } else - ht_info->is_ht = 0; - + iwl_conf->is_ht = 1; + priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); + + if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) + iwl_conf->sgf |= 0x1; + if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) + iwl_conf->sgf |= 0x2; + + iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); + iwl_conf->max_amsdu_size = + !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); + iwl_conf->supported_chan_width = + !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); + iwl_conf->tx_mimo_ps_mode = + (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); + memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); + + iwl_conf->control_channel = ht_bss_conf->primary_channel; + iwl_conf->extension_chan_offset = + ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; + iwl_conf->tx_chan_width = + !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); + iwl_conf->ht_protection = + ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; + iwl_conf->non_GF_STA_present = + !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); + + IWL_DEBUG_MAC80211("control channel %d\n", + iwl_conf->control_channel); IWL_DEBUG_MAC80211("leave\n"); - return 0; } -static int iwl_mac_conf_ht(struct ieee80211_hw *hw, - struct ieee80211_ht_capability *ht_cap, - struct ieee80211_ht_additional_info *ht_extra) +static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw, + struct ieee80211_conf *conf) { - struct iwl_priv *priv = hw->priv; - int rs; + struct iwl4965_priv *priv = hw->priv; IWL_DEBUG_MAC80211("enter: \n"); - rs = sta_ht_info_init(ht_cap, ht_extra, NULL, &priv->current_assoc_ht); + iwl4965_ht_info_fill(conf, priv); iwl4965_set_rxon_chain(priv); if (priv && priv->assoc_id && @@ -8159,58 +8245,33 @@ static int iwl_mac_conf_ht(struct ieee80211_hw *hw, spin_unlock_irqrestore(&priv->lock, flags); } - IWL_DEBUG_MAC80211("leave: control channel %d\n", - ht_extra->control_chan); - return rs; - + IWL_DEBUG_MAC80211("leave:\n"); + return 0; } -static void iwl_set_ht_capab(struct ieee80211_hw *hw, - struct ieee80211_ht_capability *ht_cap, - u8 use_wide_chan) +static void iwl4965_set_ht_capab(struct ieee80211_hw *hw, + struct ieee80211_ht_cap *ht_cap, + u8 use_current_config) { - union ht_cap_info cap; - union ht_param_info param_info; - - memset(&cap, 0, sizeof(union ht_cap_info)); - memset(¶m_info, 0, sizeof(union ht_param_info)); - - cap.maximal_amsdu_size = HT_IE_MAX_AMSDU_SIZE_4K; - cap.green_field = 1; - cap.short_GI20 = 1; - cap.short_GI40 = 1; - cap.supported_chan_width_set = use_wide_chan; - cap.mimo_power_save_mode = 0x3; - - param_info.max_rx_ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF; - param_info.mpdu_density = CFG_HT_MPDU_DENSITY_DEF; - ht_cap->capabilities_info = (__le16) cpu_to_le16(cap.val); - ht_cap->mac_ht_params_info = (u8) param_info.val; + struct ieee80211_conf *conf = &hw->conf; + struct ieee80211_hw_mode *mode = conf->mode; - ht_cap->supported_mcs_set[0] = 0xff; - ht_cap->supported_mcs_set[1] = 0xff; - ht_cap->supported_mcs_set[4] = - (cap.supported_chan_width_set) ? 0x1: 0x0; + if (use_current_config) { + ht_cap->cap_info = cpu_to_le16(conf->ht_conf.cap); + memcpy(ht_cap->supp_mcs_set, + conf->ht_conf.supp_mcs_set, 16); + } else { + ht_cap->cap_info = cpu_to_le16(mode->ht_info.cap); + memcpy(ht_cap->supp_mcs_set, + mode->ht_info.supp_mcs_set, 16); + } + ht_cap->ampdu_params_info = + (mode->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) | + ((mode->ht_info.ampdu_density << 2) & + IEEE80211_HT_CAP_AMPDU_DENSITY); } -static void iwl_mac_get_ht_capab(struct ieee80211_hw *hw, - struct ieee80211_ht_capability *ht_cap) -{ - u8 use_wide_channel = 1; - struct iwl_priv *priv = hw->priv; - - IWL_DEBUG_MAC80211("enter: \n"); - if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ) - use_wide_channel = 0; - - /* no fat tx allowed on 2.4GHZ */ - if (priv->phymode != MODE_IEEE80211A) - use_wide_channel = 0; - - iwl_set_ht_capab(hw, ht_cap, use_wide_channel); - IWL_DEBUG_MAC80211("leave: \n"); -} -#endif /*CONFIG_IWLWIFI_HT*/ +#endif /*CONFIG_IWL4965_HT*/ /***************************************************************************** * @@ -8218,7 +8279,7 @@ static void iwl_mac_get_ht_capab(struct ieee80211_hw *hw, * *****************************************************************************/ -#ifdef CONFIG_IWLWIFI_DEBUG +#ifdef CONFIG_IWL4965_DEBUG /* * The following adds a new attribute to the sysfs representation @@ -8230,7 +8291,7 @@ static void iwl_mac_get_ht_capab(struct ieee80211_hw *hw, static ssize_t show_debug_level(struct device_driver *d, char *buf) { - return sprintf(buf, "0x%08X\n", iwl_debug_level); + return sprintf(buf, "0x%08X\n", iwl4965_debug_level); } static ssize_t store_debug_level(struct device_driver *d, const char *buf, size_t count) @@ -8243,7 +8304,7 @@ static ssize_t store_debug_level(struct device_driver *d, printk(KERN_INFO DRV_NAME ": %s is not in hex or decimal form.\n", buf); else - iwl_debug_level = val; + iwl4965_debug_level = val; return strnlen(buf, count); } @@ -8251,7 +8312,7 @@ static ssize_t store_debug_level(struct device_driver *d, static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level, store_debug_level); -#endif /* CONFIG_IWLWIFI_DEBUG */ +#endif /* CONFIG_IWL4965_DEBUG */ static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr, char *buf) @@ -8262,7 +8323,7 @@ static ssize_t show_rf_kill(struct device *d, * 2 - HW based RF kill active * 3 - Both HW and SW based RF kill active */ - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) | (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0); @@ -8273,10 +8334,10 @@ static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; mutex_lock(&priv->mutex); - iwl_radio_kill_sw(priv, buf[0] == '1'); + iwl4965_radio_kill_sw(priv, buf[0] == '1'); mutex_unlock(&priv->mutex); return count; @@ -8287,12 +8348,12 @@ static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); static ssize_t show_temperature(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; - if (!iwl_is_alive(priv)) + if (!iwl4965_is_alive(priv)) return -EAGAIN; - return sprintf(buf, "%d\n", iwl_hw_get_temperature(priv)); + return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); } static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); @@ -8301,15 +8362,15 @@ static ssize_t show_rs_window(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = d->driver_data; - return iwl_fill_rs_info(priv->hw, buf, IWL_AP_ID); + struct iwl4965_priv *priv = d->driver_data; + return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); } static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); static ssize_t show_tx_power(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; return sprintf(buf, "%d\n", priv->user_txpower_limit); } @@ -8317,7 +8378,7 @@ static ssize_t store_tx_power(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; char *p = (char *)buf; u32 val; @@ -8326,7 +8387,7 @@ static ssize_t store_tx_power(struct device *d, printk(KERN_INFO DRV_NAME ": %s is not in decimal form.\n", buf); else - iwl_hw_reg_set_txpower(priv, val); + iwl4965_hw_reg_set_txpower(priv, val); return count; } @@ -8336,7 +8397,7 @@ static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); static ssize_t show_flags(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); } @@ -8345,19 +8406,19 @@ static ssize_t store_flags(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; u32 flags = simple_strtoul(buf, NULL, 0); mutex_lock(&priv->mutex); if (le32_to_cpu(priv->staging_rxon.flags) != flags) { /* Cancel any currently running scans... */ - if (iwl_scan_cancel_timeout(priv, 100)) + if (iwl4965_scan_cancel_timeout(priv, 100)) IWL_WARNING("Could not cancel scan.\n"); else { IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", flags); priv->staging_rxon.flags = cpu_to_le32(flags); - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); } } mutex_unlock(&priv->mutex); @@ -8370,7 +8431,7 @@ static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); static ssize_t show_filter_flags(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; return sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.filter_flags)); @@ -8380,20 +8441,20 @@ static ssize_t store_filter_flags(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; u32 filter_flags = simple_strtoul(buf, NULL, 0); mutex_lock(&priv->mutex); if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { /* Cancel any currently running scans... */ - if (iwl_scan_cancel_timeout(priv, 100)) + if (iwl4965_scan_cancel_timeout(priv, 100)) IWL_WARNING("Could not cancel scan.\n"); else { IWL_DEBUG_INFO("Committing rxon.filter_flags = " "0x%04X\n", filter_flags); priv->staging_rxon.filter_flags = cpu_to_le32(filter_flags); - iwl_commit_rxon(priv); + iwl4965_commit_rxon(priv); } } mutex_unlock(&priv->mutex); @@ -8407,20 +8468,20 @@ static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, static ssize_t show_tune(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; return sprintf(buf, "0x%04X\n", (priv->phymode << 8) | le16_to_cpu(priv->active_rxon.channel)); } -static void iwl_set_flags_for_phymode(struct iwl_priv *priv, u8 phymode); +static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode); static ssize_t store_tune(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; char *p = (char *)buf; u16 tune = simple_strtoul(p, &p, 0); u8 phymode = (tune >> 8) & 0xff; @@ -8431,9 +8492,9 @@ static ssize_t store_tune(struct device *d, mutex_lock(&priv->mutex); if ((le16_to_cpu(priv->staging_rxon.channel) != channel) || (priv->phymode != phymode)) { - const struct iwl_channel_info *ch_info; + const struct iwl4965_channel_info *ch_info; - ch_info = iwl_get_channel_info(priv, phymode, channel); + ch_info = iwl4965_get_channel_info(priv, phymode, channel); if (!ch_info) { IWL_WARNING("Requested invalid phymode/channel " "combination: %d %d\n", phymode, channel); @@ -8442,18 +8503,18 @@ static ssize_t store_tune(struct device *d, } /* Cancel any currently running scans... */ - if (iwl_scan_cancel_timeout(priv, 100)) + if (iwl4965_scan_cancel_timeout(priv, 100)) IWL_WARNING("Could not cancel scan.\n"); else { IWL_DEBUG_INFO("Committing phymode and " "rxon.channel = %d %d\n", phymode, channel); - iwl_set_rxon_channel(priv, phymode, channel); - iwl_set_flags_for_phymode(priv, phymode); + iwl4965_set_rxon_channel(priv, phymode, channel); + iwl4965_set_flags_for_phymode(priv, phymode); - iwl_set_rate(priv); - iwl_commit_rxon(priv); + iwl4965_set_rate(priv); + iwl4965_commit_rxon(priv); } } mutex_unlock(&priv->mutex); @@ -8463,13 +8524,13 @@ static ssize_t store_tune(struct device *d, static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune); -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT +#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT static ssize_t show_measurement(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); - struct iwl_spectrum_notification measure_report; + struct iwl4965_priv *priv = dev_get_drvdata(d); + struct iwl4965_spectrum_notification measure_report; u32 size = sizeof(measure_report), len = 0, ofs = 0; u8 *data = (u8 *) & measure_report; unsigned long flags; @@ -8501,7 +8562,7 @@ static ssize_t store_measurement(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl4965_priv *priv = dev_get_drvdata(d); struct ieee80211_measurement_params params = { .channel = le16_to_cpu(priv->active_rxon.channel), .start_time = cpu_to_le64(priv->last_tsf), @@ -8527,20 +8588,20 @@ static ssize_t store_measurement(struct device *d, IWL_DEBUG_INFO("Invoking measurement of type %d on " "channel %d (for '%s')\n", type, params.channel, buf); - iwl_get_measurement(priv, ¶ms, type); + iwl4965_get_measurement(priv, ¶ms, type); return count; } static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, show_measurement, store_measurement); -#endif /* CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT */ +#endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ static ssize_t store_retry_rate(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl4965_priv *priv = dev_get_drvdata(d); priv->retry_rate = simple_strtoul(buf, NULL, 0); if (priv->retry_rate <= 0) @@ -8552,7 +8613,7 @@ static ssize_t store_retry_rate(struct device *d, static ssize_t show_retry_rate(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl4965_priv *priv = dev_get_drvdata(d); return sprintf(buf, "%d", priv->retry_rate); } @@ -8563,14 +8624,14 @@ static ssize_t store_power_level(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl4965_priv *priv = dev_get_drvdata(d); int rc; int mode; mode = simple_strtoul(buf, NULL, 0); mutex_lock(&priv->mutex); - if (!iwl_is_ready(priv)) { + if (!iwl4965_is_ready(priv)) { rc = -EAGAIN; goto out; } @@ -8581,7 +8642,7 @@ static ssize_t store_power_level(struct device *d, mode |= IWL_POWER_ENABLED; if (mode != priv->power_mode) { - rc = iwl_send_power_mode(priv, IWL_POWER_LEVEL(mode)); + rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode)); if (rc) { IWL_DEBUG_MAC80211("failed setting power mode.\n"); goto out; @@ -8617,7 +8678,7 @@ static const s32 period_duration[] = { static ssize_t show_power_level(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl4965_priv *priv = dev_get_drvdata(d); int level = IWL_POWER_LEVEL(priv->power_mode); char *p = buf; @@ -8652,18 +8713,18 @@ static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, static ssize_t show_channels(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl4965_priv *priv = dev_get_drvdata(d); int len = 0, i; struct ieee80211_channel *channels = NULL; const struct ieee80211_hw_mode *hw_mode = NULL; int count = 0; - if (!iwl_is_ready(priv)) + if (!iwl4965_is_ready(priv)) return -EAGAIN; - hw_mode = iwl_get_hw_mode(priv, MODE_IEEE80211G); + hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211G); if (!hw_mode) - hw_mode = iwl_get_hw_mode(priv, MODE_IEEE80211B); + hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211B); if (hw_mode) { channels = hw_mode->channels; count = hw_mode->num_channels; @@ -8690,7 +8751,7 @@ static ssize_t show_channels(struct device *d, flag & IEEE80211_CHAN_W_ACTIVE_SCAN ? "active/passive" : "passive only"); - hw_mode = iwl_get_hw_mode(priv, MODE_IEEE80211A); + hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211A); if (hw_mode) { channels = hw_mode->channels; count = hw_mode->num_channels; @@ -8726,17 +8787,17 @@ static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); static ssize_t show_statistics(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); - u32 size = sizeof(struct iwl_notif_statistics); + struct iwl4965_priv *priv = dev_get_drvdata(d); + u32 size = sizeof(struct iwl4965_notif_statistics); u32 len = 0, ofs = 0; u8 *data = (u8 *) & priv->statistics; int rc = 0; - if (!iwl_is_alive(priv)) + if (!iwl4965_is_alive(priv)) return -EAGAIN; mutex_lock(&priv->mutex); - rc = iwl_send_statistics_request(priv); + rc = iwl4965_send_statistics_request(priv); mutex_unlock(&priv->mutex); if (rc) { @@ -8764,9 +8825,9 @@ static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); static ssize_t show_antenna(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl4965_priv *priv = dev_get_drvdata(d); - if (!iwl_is_alive(priv)) + if (!iwl4965_is_alive(priv)) return -EAGAIN; return sprintf(buf, "%d\n", priv->antenna); @@ -8777,7 +8838,7 @@ static ssize_t store_antenna(struct device *d, const char *buf, size_t count) { int ant; - struct iwl_priv *priv = dev_get_drvdata(d); + struct iwl4965_priv *priv = dev_get_drvdata(d); if (count == 0) return 0; @@ -8789,7 +8850,7 @@ static ssize_t store_antenna(struct device *d, if ((ant >= 0) && (ant <= 2)) { IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); - priv->antenna = (enum iwl_antenna)ant; + priv->antenna = (enum iwl4965_antenna)ant; } else IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); @@ -8802,8 +8863,8 @@ static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); static ssize_t show_status(struct device *d, struct device_attribute *attr, char *buf) { - struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; - if (!iwl_is_alive(priv)) + struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; + if (!iwl4965_is_alive(priv)) return -EAGAIN; return sprintf(buf, "0x%08x\n", (int)priv->status); } @@ -8817,7 +8878,7 @@ static ssize_t dump_error_log(struct device *d, char *p = (char *)buf; if (p[0] == '1') - iwl_dump_nic_error_log((struct iwl_priv *)d->driver_data); + iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data); return strnlen(buf, count); } @@ -8831,7 +8892,7 @@ static ssize_t dump_event_log(struct device *d, char *p = (char *)buf; if (p[0] == '1') - iwl_dump_nic_event_log((struct iwl_priv *)d->driver_data); + iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data); return strnlen(buf, count); } @@ -8844,34 +8905,34 @@ static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); * *****************************************************************************/ -static void iwl_setup_deferred_work(struct iwl_priv *priv) +static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv) { priv->workqueue = create_workqueue(DRV_NAME); init_waitqueue_head(&priv->wait_command_queue); - INIT_WORK(&priv->up, iwl_bg_up); - INIT_WORK(&priv->restart, iwl_bg_restart); - INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish); - INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); - INIT_WORK(&priv->request_scan, iwl_bg_request_scan); - INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan); - INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill); - INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update); - INIT_DELAYED_WORK(&priv->post_associate, iwl_bg_post_associate); - INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); - INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); - INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check); - - iwl_hw_setup_deferred_work(priv); + INIT_WORK(&priv->up, iwl4965_bg_up); + INIT_WORK(&priv->restart, iwl4965_bg_restart); + INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); + INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); + INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); + INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); + INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); + INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); + INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); + INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); + INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); + INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); + + iwl4965_hw_setup_deferred_work(priv); tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) - iwl_irq_tasklet, (unsigned long)priv); + iwl4965_irq_tasklet, (unsigned long)priv); } -static void iwl_cancel_deferred_work(struct iwl_priv *priv) +static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv) { - iwl_hw_cancel_deferred_work(priv); + iwl4965_hw_cancel_deferred_work(priv); cancel_delayed_work_sync(&priv->init_alive_start); cancel_delayed_work(&priv->scan_check); @@ -8880,14 +8941,14 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv) cancel_work_sync(&priv->beacon_update); } -static struct attribute *iwl_sysfs_entries[] = { +static struct attribute *iwl4965_sysfs_entries[] = { &dev_attr_antenna.attr, &dev_attr_channels.attr, &dev_attr_dump_errors.attr, &dev_attr_dump_events.attr, &dev_attr_flags.attr, &dev_attr_filter_flags.attr, -#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT +#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT &dev_attr_measurement.attr, #endif &dev_attr_power_level.attr, @@ -8903,54 +8964,56 @@ static struct attribute *iwl_sysfs_entries[] = { NULL }; -static struct attribute_group iwl_attribute_group = { +static struct attribute_group iwl4965_attribute_group = { .name = NULL, /* put in device directory */ - .attrs = iwl_sysfs_entries, + .attrs = iwl4965_sysfs_entries, }; -static struct ieee80211_ops iwl_hw_ops = { - .tx = iwl_mac_tx, - .start = iwl_mac_start, - .stop = iwl_mac_stop, - .add_interface = iwl_mac_add_interface, - .remove_interface = iwl_mac_remove_interface, - .config = iwl_mac_config, - .config_interface = iwl_mac_config_interface, - .configure_filter = iwl_configure_filter, - .set_key = iwl_mac_set_key, - .get_stats = iwl_mac_get_stats, - .get_tx_stats = iwl_mac_get_tx_stats, - .conf_tx = iwl_mac_conf_tx, - .get_tsf = iwl_mac_get_tsf, - .reset_tsf = iwl_mac_reset_tsf, - .beacon_update = iwl_mac_beacon_update, -#ifdef CONFIG_IWLWIFI_HT - .conf_ht = iwl_mac_conf_ht, - .get_ht_capab = iwl_mac_get_ht_capab, -#ifdef CONFIG_IWLWIFI_HT_AGG - .ht_tx_agg_start = iwl_mac_ht_tx_agg_start, - .ht_tx_agg_stop = iwl_mac_ht_tx_agg_stop, - .ht_rx_agg_start = iwl_mac_ht_rx_agg_start, - .ht_rx_agg_stop = iwl_mac_ht_rx_agg_stop, -#endif /* CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ - .hw_scan = iwl_mac_hw_scan +static struct ieee80211_ops iwl4965_hw_ops = { + .tx = iwl4965_mac_tx, + .start = iwl4965_mac_start, + .stop = iwl4965_mac_stop, + .add_interface = iwl4965_mac_add_interface, + .remove_interface = iwl4965_mac_remove_interface, + .config = iwl4965_mac_config, + .config_interface = iwl4965_mac_config_interface, + .configure_filter = iwl4965_configure_filter, + .set_key = iwl4965_mac_set_key, + .get_stats = iwl4965_mac_get_stats, + .get_tx_stats = iwl4965_mac_get_tx_stats, + .conf_tx = iwl4965_mac_conf_tx, + .get_tsf = iwl4965_mac_get_tsf, + .reset_tsf = iwl4965_mac_reset_tsf, + .beacon_update = iwl4965_mac_beacon_update, + .bss_info_changed = iwl4965_bss_info_changed, +#ifdef CONFIG_IWL4965_HT + .conf_ht = iwl4965_mac_conf_ht, + .ampdu_action = iwl4965_mac_ampdu_action, +#ifdef CONFIG_IWL4965_HT_AGG + .ht_tx_agg_start = iwl4965_mac_ht_tx_agg_start, + .ht_tx_agg_stop = iwl4965_mac_ht_tx_agg_stop, +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ + .hw_scan = iwl4965_mac_hw_scan }; -static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) +static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { int err = 0; - struct iwl_priv *priv; + struct iwl4965_priv *priv; struct ieee80211_hw *hw; int i; + DECLARE_MAC_BUF(mac); - if (iwl_param_disable_hw_scan) { + /* Disabling hardware scan means that mac80211 will perform scans + * "the hard way", rather than using device's scan. */ + if (iwl4965_param_disable_hw_scan) { IWL_DEBUG_INFO("Disabling hw_scan\n"); - iwl_hw_ops.hw_scan = NULL; + iwl4965_hw_ops.hw_scan = NULL; } - if ((iwl_param_queues_num > IWL_MAX_NUM_QUEUES) || - (iwl_param_queues_num < IWL_MIN_NUM_QUEUES)) { + if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) || + (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) { IWL_ERROR("invalid queues_num, should be between %d and %d\n", IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES); err = -EINVAL; @@ -8959,7 +9022,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) /* mac80211 allocates memory for this device instance, including * space for this driver's private structure */ - hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwl_hw_ops); + hw = ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops); if (hw == NULL) { IWL_ERROR("Can not allocate network device\n"); err = -ENOMEM; @@ -8974,9 +9037,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) priv->hw = hw; priv->pci_dev = pdev; - priv->antenna = (enum iwl_antenna)iwl_param_antenna; -#ifdef CONFIG_IWLWIFI_DEBUG - iwl_debug_level = iwl_param_debug; + priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna; +#ifdef CONFIG_IWL4965_DEBUG + iwl4965_debug_level = iwl4965_param_debug; atomic_set(&priv->restrict_refcnt, 0); #endif priv->retry_rate = 1; @@ -8995,12 +9058,14 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) /* Tell mac80211 our Tx characteristics */ hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; + /* Default value; 4 EDCA QOS priorities */ hw->queues = 4; -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG +#ifdef CONFIG_IWL4965_HT +#ifdef CONFIG_IWL4965_HT_AGG + /* Enhanced value; more queues, to support 11n aggregation */ hw->queues = 16; -#endif /* CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ +#endif /* CONFIG_IWL4965_HT_AGG */ +#endif /* CONFIG_IWL4965_HT */ spin_lock_init(&priv->lock); spin_lock_init(&priv->power_data.lock); @@ -9021,7 +9086,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_master(pdev); - iwl_clear_stations_table(priv); + /* Clear the driver's (not device's) station table */ + iwl4965_clear_stations_table(priv); priv->data_retry_limit = -1; priv->ieee_channels = NULL; @@ -9040,9 +9106,11 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err = pci_request_regions(pdev, DRV_NAME); if (err) goto out_pci_disable_device; + /* We disable the RETRY_TIMEOUT register (0x41) to keep * PCI Tx retries from interfering with C3 CPU state */ pci_write_config_byte(pdev, 0x41, 0x00); + priv->hw_base = pci_iomap(pdev, 0, 0); if (!priv->hw_base) { err = -ENODEV; @@ -9055,7 +9123,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) /* Initialize module parameter values here */ - if (iwl_param_disable) { + /* Disable radio (SW RF KILL) via parameter when loading driver */ + if (iwl4965_param_disable) { set_bit(STATUS_RF_KILL_SW, &priv->status); IWL_DEBUG_INFO("Radio disabled.\n"); } @@ -9064,91 +9133,92 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) priv->ps_mode = 0; priv->use_ant_b_for_management_frame = 1; /* start with ant B */ - priv->is_ht_enabled = 1; - priv->channel_width = IWL_CHANNEL_WIDTH_40MHZ; priv->valid_antenna = 0x7; /* assume all 3 connected */ priv->ps_mode = IWL_MIMO_PS_NONE; - priv->cck_power_index_compensation = iwl_read32( - priv, CSR_HW_REV_WA_REG); + /* Choose which receivers/antennas to use */ iwl4965_set_rxon_chain(priv); printk(KERN_INFO DRV_NAME ": Detected Intel Wireless WiFi Link 4965AGN\n"); /* Device-specific setup */ - if (iwl_hw_set_hw_setting(priv)) { + if (iwl4965_hw_set_hw_setting(priv)) { IWL_ERROR("failed to set hw settings\n"); - mutex_unlock(&priv->mutex); goto out_iounmap; } -#ifdef CONFIG_IWLWIFI_QOS - if (iwl_param_qos_enable) +#ifdef CONFIG_IWL4965_QOS + if (iwl4965_param_qos_enable) priv->qos_data.qos_enable = 1; - iwl_reset_qos(priv); + iwl4965_reset_qos(priv); priv->qos_data.qos_active = 0; priv->qos_data.qos_cap.val = 0; -#endif /* CONFIG_IWLWIFI_QOS */ +#endif /* CONFIG_IWL4965_QOS */ - iwl_set_rxon_channel(priv, MODE_IEEE80211G, 6); - iwl_setup_deferred_work(priv); - iwl_setup_rx_handlers(priv); + iwl4965_set_rxon_channel(priv, MODE_IEEE80211G, 6); + iwl4965_setup_deferred_work(priv); + iwl4965_setup_rx_handlers(priv); priv->rates_mask = IWL_RATES_MASK; /* If power management is turned on, default to AC mode */ priv->power_mode = IWL_POWER_AC; priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; - pci_enable_msi(pdev); - - err = request_irq(pdev->irq, iwl_isr, IRQF_SHARED, DRV_NAME, priv); - if (err) { - IWL_ERROR("Error allocating IRQ %d\n", pdev->irq); - goto out_disable_msi; - } - - mutex_lock(&priv->mutex); + iwl4965_disable_interrupts(priv); - err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group); + err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); if (err) { IWL_ERROR("failed to create sysfs device attributes\n"); - mutex_unlock(&priv->mutex); goto out_release_irq; } - /* fetch ucode file from disk, alloc and copy to bus-master buffers ... - * ucode filename and max sizes are card-specific. */ - err = iwl_read_ucode(priv); + /* nic init */ + iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS, + CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); + + iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); + err = iwl4965_poll_bit(priv, CSR_GP_CNTRL, + CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, + CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); + if (err < 0) { + IWL_DEBUG_INFO("Failed to init the card\n"); + goto out_remove_sysfs; + } + /* Read the EEPROM */ + err = iwl4965_eeprom_init(priv); if (err) { - IWL_ERROR("Could not read microcode: %d\n", err); - mutex_unlock(&priv->mutex); - goto out_pci_alloc; + IWL_ERROR("Unable to init EEPROM\n"); + goto out_remove_sysfs; } + /* MAC Address location in EEPROM same for 3945/4965 */ + get_eeprom_mac(priv, priv->mac_addr); + IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); + SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); - mutex_unlock(&priv->mutex); - - IWL_DEBUG_INFO("Queing UP work.\n"); + iwl4965_rate_control_register(priv->hw); + err = ieee80211_register_hw(priv->hw); + if (err) { + IWL_ERROR("Failed to register network device (error %d)\n", err); + goto out_remove_sysfs; + } - queue_work(priv->workqueue, &priv->up); + priv->hw->conf.beacon_int = 100; + priv->mac80211_registered = 1; + pci_save_state(pdev); + pci_disable_device(pdev); return 0; - out_pci_alloc: - iwl_dealloc_ucode_pci(priv); - - sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group); + out_remove_sysfs: + sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); out_release_irq: - free_irq(pdev->irq, priv); - - out_disable_msi: - pci_disable_msi(pdev); destroy_workqueue(priv->workqueue); priv->workqueue = NULL; - iwl_unset_hw_setting(priv); + iwl4965_unset_hw_setting(priv); out_iounmap: pci_iounmap(pdev, priv->hw_base); @@ -9163,9 +9233,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) return err; } -static void iwl_pci_remove(struct pci_dev *pdev) +static void iwl4965_pci_remove(struct pci_dev *pdev) { - struct iwl_priv *priv = pci_get_drvdata(pdev); + struct iwl4965_priv *priv = pci_get_drvdata(pdev); struct list_head *p, *q; int i; @@ -9176,43 +9246,41 @@ static void iwl_pci_remove(struct pci_dev *pdev) set_bit(STATUS_EXIT_PENDING, &priv->status); - iwl_down(priv); + iwl4965_down(priv); /* Free MAC hash list for ADHOC */ for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { list_del(p); - kfree(list_entry(p, struct iwl_ibss_seq, list)); + kfree(list_entry(p, struct iwl4965_ibss_seq, list)); } } - sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group); + sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); - iwl_dealloc_ucode_pci(priv); + iwl4965_dealloc_ucode_pci(priv); if (priv->rxq.bd) - iwl_rx_queue_free(priv, &priv->rxq); - iwl_hw_txq_ctx_free(priv); + iwl4965_rx_queue_free(priv, &priv->rxq); + iwl4965_hw_txq_ctx_free(priv); - iwl_unset_hw_setting(priv); - iwl_clear_stations_table(priv); + iwl4965_unset_hw_setting(priv); + iwl4965_clear_stations_table(priv); if (priv->mac80211_registered) { ieee80211_unregister_hw(priv->hw); - iwl_rate_control_unregister(priv->hw); + iwl4965_rate_control_unregister(priv->hw); } /*netif_stop_queue(dev); */ flush_workqueue(priv->workqueue); - /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes + /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes * priv->workqueue... so we can't take down the workqueue * until now... */ destroy_workqueue(priv->workqueue); priv->workqueue = NULL; - free_irq(pdev->irq, priv); - pci_disable_msi(pdev); pci_iounmap(pdev, priv->hw_base); pci_release_regions(pdev); pci_disable_device(pdev); @@ -9231,93 +9299,31 @@ static void iwl_pci_remove(struct pci_dev *pdev) #ifdef CONFIG_PM -static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state) +static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state) { - struct iwl_priv *priv = pci_get_drvdata(pdev); + struct iwl4965_priv *priv = pci_get_drvdata(pdev); - set_bit(STATUS_IN_SUSPEND, &priv->status); - - /* Take down the device; powers it off, etc. */ - iwl_down(priv); - - if (priv->mac80211_registered) - ieee80211_stop_queues(priv->hw); + if (priv->is_open) { + set_bit(STATUS_IN_SUSPEND, &priv->status); + iwl4965_mac_stop(priv->hw); + priv->is_open = 1; + } - pci_save_state(pdev); - pci_disable_device(pdev); pci_set_power_state(pdev, PCI_D3hot); return 0; } -static void iwl_resume(struct iwl_priv *priv) +static int iwl4965_pci_resume(struct pci_dev *pdev) { - unsigned long flags; - - /* The following it a temporary work around due to the - * suspend / resume not fully initializing the NIC correctly. - * Without all of the following, resume will not attempt to take - * down the NIC (it shouldn't really need to) and will just try - * and bring the NIC back up. However that fails during the - * ucode verification process. This then causes iwl_down to be - * called *after* iwl_hw_nic_init() has succeeded -- which - * then lets the next init sequence succeed. So, we've - * replicated all of that NIC init code here... */ - - iwl_write32(priv, CSR_INT, 0xFFFFFFFF); - - iwl_hw_nic_init(priv); - - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, - CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); - iwl_write32(priv, CSR_INT, 0xFFFFFFFF); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); - - /* tell the device to stop sending interrupts */ - iwl_disable_interrupts(priv); - - spin_lock_irqsave(&priv->lock, flags); - iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); - - if (!iwl_grab_restricted_access(priv)) { - iwl_write_restricted_reg(priv, APMG_CLK_DIS_REG, - APMG_CLK_VAL_DMA_CLK_RQT); - iwl_release_restricted_access(priv); - } - spin_unlock_irqrestore(&priv->lock, flags); - - udelay(5); - - iwl_hw_nic_reset(priv); - - /* Bring the device back up */ - clear_bit(STATUS_IN_SUSPEND, &priv->status); - queue_work(priv->workqueue, &priv->up); -} - -static int iwl_pci_resume(struct pci_dev *pdev) -{ - struct iwl_priv *priv = pci_get_drvdata(pdev); - int err; - - printk(KERN_INFO "Coming out of suspend...\n"); + struct iwl4965_priv *priv = pci_get_drvdata(pdev); pci_set_power_state(pdev, PCI_D0); - err = pci_enable_device(pdev); - pci_restore_state(pdev); - - /* - * Suspend/Resume resets the PCI configuration space, so we have to - * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries - * from interfering with C3 CPU state. pci_restore_state won't help - * here since it only restores the first 64 bytes pci config header. - */ - pci_write_config_byte(pdev, 0x41, 0x00); - iwl_resume(priv); + if (priv->is_open) + iwl4965_mac_start(priv->hw); + clear_bit(STATUS_IN_SUSPEND, &priv->status); return 0; } @@ -9329,33 +9335,33 @@ static int iwl_pci_resume(struct pci_dev *pdev) * *****************************************************************************/ -static struct pci_driver iwl_driver = { +static struct pci_driver iwl4965_driver = { .name = DRV_NAME, - .id_table = iwl_hw_card_ids, - .probe = iwl_pci_probe, - .remove = __devexit_p(iwl_pci_remove), + .id_table = iwl4965_hw_card_ids, + .probe = iwl4965_pci_probe, + .remove = __devexit_p(iwl4965_pci_remove), #ifdef CONFIG_PM - .suspend = iwl_pci_suspend, - .resume = iwl_pci_resume, + .suspend = iwl4965_pci_suspend, + .resume = iwl4965_pci_resume, #endif }; -static int __init iwl_init(void) +static int __init iwl4965_init(void) { int ret; printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); - ret = pci_register_driver(&iwl_driver); + ret = pci_register_driver(&iwl4965_driver); if (ret) { IWL_ERROR("Unable to initialize PCI module\n"); return ret; } -#ifdef CONFIG_IWLWIFI_DEBUG - ret = driver_create_file(&iwl_driver.driver, &driver_attr_debug_level); +#ifdef CONFIG_IWL4965_DEBUG + ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level); if (ret) { IWL_ERROR("Unable to create driver sysfs file\n"); - pci_unregister_driver(&iwl_driver); + pci_unregister_driver(&iwl4965_driver); return ret; } #endif @@ -9363,32 +9369,34 @@ static int __init iwl_init(void) return ret; } -static void __exit iwl_exit(void) +static void __exit iwl4965_exit(void) { -#ifdef CONFIG_IWLWIFI_DEBUG - driver_remove_file(&iwl_driver.driver, &driver_attr_debug_level); +#ifdef CONFIG_IWL4965_DEBUG + driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level); #endif - pci_unregister_driver(&iwl_driver); + pci_unregister_driver(&iwl4965_driver); } -module_param_named(antenna, iwl_param_antenna, int, 0444); +module_param_named(antenna, iwl4965_param_antenna, int, 0444); MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); -module_param_named(disable, iwl_param_disable, int, 0444); +module_param_named(disable, iwl4965_param_disable, int, 0444); MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); -module_param_named(hwcrypto, iwl_param_hwcrypto, int, 0444); +module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444); MODULE_PARM_DESC(hwcrypto, "using hardware crypto engine (default 0 [software])\n"); -module_param_named(debug, iwl_param_debug, int, 0444); +module_param_named(debug, iwl4965_param_debug, int, 0444); MODULE_PARM_DESC(debug, "debug output mask"); -module_param_named(disable_hw_scan, iwl_param_disable_hw_scan, int, 0444); +module_param_named(disable_hw_scan, iwl4965_param_disable_hw_scan, int, 0444); MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); -module_param_named(queues_num, iwl_param_queues_num, int, 0444); +module_param_named(queues_num, iwl4965_param_queues_num, int, 0444); MODULE_PARM_DESC(queues_num, "number of hw queues."); /* QoS */ -module_param_named(qos_enable, iwl_param_qos_enable, int, 0444); +module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444); MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); +module_param_named(amsdu_size_8K, iwl4965_param_amsdu_size_8K, int, 0444); +MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); -module_exit(iwl_exit); -module_init(iwl_init); +module_exit(iwl4965_exit); +module_init(iwl4965_init); diff --git a/drivers/net/wireless/iwlwifi/iwlwifi.h b/drivers/net/wireless/iwlwifi/iwlwifi.h deleted file mode 100644 index 432ce887807..00000000000 --- a/drivers/net/wireless/iwlwifi/iwlwifi.h +++ /dev/null @@ -1,708 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. - * - * Portions of this file are derived from the ipw3945 project, as well - * as portions of the ieee80211 subsystem header files. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * The full GNU General Public License is included in this distribution in the - * file called LICENSE. - * - * Contact Information: - * James P. Ketrenos <ipw2100-admin@linux.intel.com> - * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 - * - *****************************************************************************/ - -#ifndef __iwlwifi_h__ -#define __iwlwifi_h__ - -#include <linux/pci.h> /* for struct pci_device_id */ -#include <linux/kernel.h> -#include <net/ieee80211_radiotap.h> - -struct iwl_priv; - -/* Hardware specific file defines the PCI IDs table for that hardware module */ -extern struct pci_device_id iwl_hw_card_ids[]; - -#include "iwl-hw.h" -#if IWL == 3945 -#define DRV_NAME "iwl3945" -#include "iwl-3945-hw.h" -#elif IWL == 4965 -#define DRV_NAME "iwl4965" -#include "iwl-4965-hw.h" -#endif - -#include "iwl-prph.h" - -/* - * Driver implementation data structures, constants, inline - * functions - * - * NOTE: DO NOT PUT HARDWARE/UCODE SPECIFIC DECLRATIONS HERE - * - * Hardware specific declrations go into iwl-*hw.h - * - */ - -#include "iwl-debug.h" - -/* Default noise level to report when noise measurement is not available. - * This may be because we're: - * 1) Not associated (4965, no beacon statistics being sent to driver) - * 2) Scanning (noise measurement does not apply to associated channel) - * 3) Receiving CCK (3945 delivers noise info only for OFDM frames) - * Use default noise value of -127 ... this is below the range of measurable - * Rx dBm for either 3945 or 4965, so it can indicate "unmeasurable" to user. - * Also, -127 works better than 0 when averaging frames with/without - * noise info (e.g. averaging might be done in app); measured dBm values are - * always negative ... using a negative value as the default keeps all - * averages within an s8's (used in some apps) range of negative values. */ -#define IWL_NOISE_MEAS_NOT_AVAILABLE (-127) - -/* Module parameters accessible from iwl-*.c */ -extern int iwl_param_disable_hw_scan; -extern int iwl_param_debug; -extern int iwl_param_mode; -extern int iwl_param_disable; -extern int iwl_param_antenna; -extern int iwl_param_hwcrypto; -extern int iwl_param_qos_enable; -extern int iwl_param_queues_num; - -enum iwl_antenna { - IWL_ANTENNA_DIVERSITY, - IWL_ANTENNA_MAIN, - IWL_ANTENNA_AUX -}; - -/* - * RTS threshold here is total size [2347] minus 4 FCS bytes - * Per spec: - * a value of 0 means RTS on all data/management packets - * a value > max MSDU size means no RTS - * else RTS for data/management frames where MPDU is larger - * than RTS value. - */ -#define DEFAULT_RTS_THRESHOLD 2347U -#define MIN_RTS_THRESHOLD 0U -#define MAX_RTS_THRESHOLD 2347U -#define MAX_MSDU_SIZE 2304U -#define MAX_MPDU_SIZE 2346U -#define DEFAULT_BEACON_INTERVAL 100U -#define DEFAULT_SHORT_RETRY_LIMIT 7U -#define DEFAULT_LONG_RETRY_LIMIT 4U - -struct iwl_rx_mem_buffer { - dma_addr_t dma_addr; - struct sk_buff *skb; - struct list_head list; -}; - -struct iwl_rt_rx_hdr { - struct ieee80211_radiotap_header rt_hdr; - __le64 rt_tsf; /* TSF */ - u8 rt_flags; /* radiotap packet flags */ - u8 rt_rate; /* rate in 500kb/s */ - __le16 rt_channelMHz; /* channel in MHz */ - __le16 rt_chbitmask; /* channel bitfield */ - s8 rt_dbmsignal; /* signal in dBm, kluged to signed */ - s8 rt_dbmnoise; - u8 rt_antenna; /* antenna number */ - u8 payload[0]; /* payload... */ -} __attribute__ ((packed)); - -struct iwl_rt_tx_hdr { - struct ieee80211_radiotap_header rt_hdr; - u8 rt_rate; /* rate in 500kb/s */ - __le16 rt_channel; /* channel in mHz */ - __le16 rt_chbitmask; /* channel bitfield */ - s8 rt_dbmsignal; /* signal in dBm, kluged to signed */ - u8 rt_antenna; /* antenna number */ - u8 payload[0]; /* payload... */ -} __attribute__ ((packed)); - -/* - * Generic queue structure - * - * Contains common data for Rx and Tx queues - */ -struct iwl_queue { - int n_bd; /* number of BDs in this queue */ - int first_empty; /* 1-st empty entry (index) host_w*/ - int last_used; /* last used entry (index) host_r*/ - dma_addr_t dma_addr; /* physical addr for BD's */ - int n_window; /* safe queue window */ - u32 id; - int low_mark; /* low watermark, resume queue if free - * space more than this */ - int high_mark; /* high watermark, stop queue if free - * space less than this */ -} __attribute__ ((packed)); - -#define MAX_NUM_OF_TBS (20) - -struct iwl_tx_info { - struct ieee80211_tx_status status; - struct sk_buff *skb[MAX_NUM_OF_TBS]; -}; - -/** - * struct iwl_tx_queue - Tx Queue for DMA - * @need_update: need to update read/write index - * @shed_retry: queue is HT AGG enabled - * - * Queue consists of circular buffer of BD's and required locking structures. - */ -struct iwl_tx_queue { - struct iwl_queue q; - struct iwl_tfd_frame *bd; - struct iwl_cmd *cmd; - dma_addr_t dma_addr_cmd; - struct iwl_tx_info *txb; - int need_update; - int sched_retry; - int active; -}; - -#include "iwl-channel.h" - -#if IWL == 3945 -#include "iwl-3945-rs.h" -#else -#include "iwl-4965-rs.h" -#endif - -#define IWL_TX_FIFO_AC0 0 -#define IWL_TX_FIFO_AC1 1 -#define IWL_TX_FIFO_AC2 2 -#define IWL_TX_FIFO_AC3 3 -#define IWL_TX_FIFO_HCCA_1 5 -#define IWL_TX_FIFO_HCCA_2 6 -#define IWL_TX_FIFO_NONE 7 - -/* Minimum number of queues. MAX_NUM is defined in hw specific files */ -#define IWL_MIN_NUM_QUEUES 4 - -/* Power management (not Tx power) structures */ - -struct iwl_power_vec_entry { - struct iwl_powertable_cmd cmd; - u8 no_dtim; -}; -#define IWL_POWER_RANGE_0 (0) -#define IWL_POWER_RANGE_1 (1) - -#define IWL_POWER_MODE_CAM 0x00 /* Continuously Aware Mode, always on */ -#define IWL_POWER_INDEX_3 0x03 -#define IWL_POWER_INDEX_5 0x05 -#define IWL_POWER_AC 0x06 -#define IWL_POWER_BATTERY 0x07 -#define IWL_POWER_LIMIT 0x07 -#define IWL_POWER_MASK 0x0F -#define IWL_POWER_ENABLED 0x10 -#define IWL_POWER_LEVEL(x) ((x) & IWL_POWER_MASK) - -struct iwl_power_mgr { - spinlock_t lock; - struct iwl_power_vec_entry pwr_range_0[IWL_POWER_AC]; - struct iwl_power_vec_entry pwr_range_1[IWL_POWER_AC]; - u8 active_index; - u32 dtim_val; -}; - -#define IEEE80211_DATA_LEN 2304 -#define IEEE80211_4ADDR_LEN 30 -#define IEEE80211_HLEN (IEEE80211_4ADDR_LEN) -#define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN) - -struct iwl_frame { - union { - struct ieee80211_hdr frame; - struct iwl_tx_beacon_cmd beacon; - u8 raw[IEEE80211_FRAME_LEN]; - u8 cmd[360]; - } u; - struct list_head list; -}; - -#define SEQ_TO_QUEUE(x) ((x >> 8) & 0xbf) -#define QUEUE_TO_SEQ(x) ((x & 0xbf) << 8) -#define SEQ_TO_INDEX(x) (x & 0xff) -#define INDEX_TO_SEQ(x) (x & 0xff) -#define SEQ_HUGE_FRAME (0x4000) -#define SEQ_RX_FRAME __constant_cpu_to_le16(0x8000) -#define SEQ_TO_SN(seq) (((seq) & IEEE80211_SCTL_SEQ) >> 4) -#define SN_TO_SEQ(ssn) (((ssn) << 4) & IEEE80211_SCTL_SEQ) -#define MAX_SN ((IEEE80211_SCTL_SEQ) >> 4) - -enum { - /* CMD_SIZE_NORMAL = 0, */ - CMD_SIZE_HUGE = (1 << 0), - /* CMD_SYNC = 0, */ - CMD_ASYNC = (1 << 1), - /* CMD_NO_SKB = 0, */ - CMD_WANT_SKB = (1 << 2), -}; - -struct iwl_cmd; -struct iwl_priv; - -struct iwl_cmd_meta { - struct iwl_cmd_meta *source; - union { - struct sk_buff *skb; - int (*callback)(struct iwl_priv *priv, - struct iwl_cmd *cmd, struct sk_buff *skb); - } __attribute__ ((packed)) u; - - /* The CMD_SIZE_HUGE flag bit indicates that the command - * structure is stored at the end of the shared queue memory. */ - u32 flags; - -} __attribute__ ((packed)); - -struct iwl_cmd { - struct iwl_cmd_meta meta; - struct iwl_cmd_header hdr; - union { - struct iwl_addsta_cmd addsta; - struct iwl_led_cmd led; - u32 flags; - u8 val8; - u16 val16; - u32 val32; - struct iwl_bt_cmd bt; - struct iwl_rxon_time_cmd rxon_time; - struct iwl_powertable_cmd powertable; - struct iwl_qosparam_cmd qosparam; - struct iwl_tx_cmd tx; - struct iwl_tx_beacon_cmd tx_beacon; - struct iwl_rxon_assoc_cmd rxon_assoc; - u8 *indirect; - u8 payload[360]; - } __attribute__ ((packed)) cmd; -} __attribute__ ((packed)); - -struct iwl_host_cmd { - u8 id; - u16 len; - struct iwl_cmd_meta meta; - const void *data; -}; - -#define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_cmd) - \ - sizeof(struct iwl_cmd_meta)) - -/* - * RX related structures and functions - */ -#define RX_FREE_BUFFERS 64 -#define RX_LOW_WATERMARK 8 - -#define SUP_RATE_11A_MAX_NUM_CHANNELS 8 -#define SUP_RATE_11B_MAX_NUM_CHANNELS 4 -#define SUP_RATE_11G_MAX_NUM_CHANNELS 12 - -/** - * struct iwl_rx_queue - Rx queue - * @processed: Internal index to last handled Rx packet - * @read: Shared index to newest available Rx buffer - * @write: Shared index to oldest written Rx packet - * @free_count: Number of pre-allocated buffers in rx_free - * @rx_free: list of free SKBs for use - * @rx_used: List of Rx buffers with no SKB - * @need_update: flag to indicate we need to update read/write index - * - * NOTE: rx_free and rx_used are used as a FIFO for iwl_rx_mem_buffers - */ -struct iwl_rx_queue { - __le32 *bd; - dma_addr_t dma_addr; - struct iwl_rx_mem_buffer pool[RX_QUEUE_SIZE + RX_FREE_BUFFERS]; - struct iwl_rx_mem_buffer *queue[RX_QUEUE_SIZE]; - u32 processed; - u32 read; - u32 write; - u32 free_count; - struct list_head rx_free; - struct list_head rx_used; - int need_update; - spinlock_t lock; -}; - -#define IWL_SUPPORTED_RATES_IE_LEN 8 - -#define SCAN_INTERVAL 100 - -#define MAX_A_CHANNELS 252 -#define MIN_A_CHANNELS 7 - -#define MAX_B_CHANNELS 14 -#define MIN_B_CHANNELS 1 - -#define STATUS_HCMD_ACTIVE 0 /* host command in progress */ -#define STATUS_INT_ENABLED 1 -#define STATUS_RF_KILL_HW 2 -#define STATUS_RF_KILL_SW 3 -#define STATUS_INIT 4 -#define STATUS_ALIVE 5 -#define STATUS_READY 6 -#define STATUS_TEMPERATURE 7 -#define STATUS_GEO_CONFIGURED 8 -#define STATUS_EXIT_PENDING 9 -#define STATUS_IN_SUSPEND 10 -#define STATUS_STATISTICS 11 -#define STATUS_SCANNING 12 -#define STATUS_SCAN_ABORTING 13 -#define STATUS_SCAN_HW 14 -#define STATUS_POWER_PMI 15 -#define STATUS_FW_ERROR 16 - -#define MAX_TID_COUNT 9 - -#define IWL_INVALID_RATE 0xFF -#define IWL_INVALID_VALUE -1 - -#if IWL == 4965 -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG -struct iwl_ht_agg { - u16 txq_id; - u16 frame_count; - u16 wait_for_ba; - u16 start_idx; - u32 bitmap0; - u32 bitmap1; - u32 rate_n_flags; -}; -#endif /* CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ -#endif - -struct iwl_tid_data { - u16 seq_number; -#if IWL == 4965 -#ifdef CONFIG_IWLWIFI_HT -#ifdef CONFIG_IWLWIFI_HT_AGG - struct iwl_ht_agg agg; -#endif /* CONFIG_IWLWIFI_HT_AGG */ -#endif /* CONFIG_IWLWIFI_HT */ -#endif -}; - -struct iwl_hw_key { - enum ieee80211_key_alg alg; - int keylen; - u8 key[32]; -}; - -union iwl_ht_rate_supp { - u16 rates; - struct { - u8 siso_rate; - u8 mimo_rate; - }; -}; - -#ifdef CONFIG_IWLWIFI_HT -#define CFG_HT_RX_AMPDU_FACTOR_DEF (0x3) -#define HT_IE_MAX_AMSDU_SIZE_4K (0) -#define CFG_HT_MPDU_DENSITY_2USEC (0x5) -#define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_2USEC - -struct sta_ht_info { - u8 is_ht; - u16 rx_mimo_ps_mode; - u16 tx_mimo_ps_mode; - u16 control_channel; - u8 max_amsdu_size; - u8 ampdu_factor; - u8 mpdu_density; - u8 operating_mode; - u8 supported_chan_width; - u8 extension_chan_offset; - u8 is_green_field; - u8 sgf; - u8 supp_rates[16]; - u8 tx_chan_width; - u8 chan_width_cap; -}; -#endif /*CONFIG_IWLWIFI_HT */ - -#ifdef CONFIG_IWLWIFI_QOS - -union iwl_qos_capabity { - struct { - u8 edca_count:4; /* bit 0-3 */ - u8 q_ack:1; /* bit 4 */ - u8 queue_request:1; /* bit 5 */ - u8 txop_request:1; /* bit 6 */ - u8 reserved:1; /* bit 7 */ - } q_AP; - struct { - u8 acvo_APSD:1; /* bit 0 */ - u8 acvi_APSD:1; /* bit 1 */ - u8 ac_bk_APSD:1; /* bit 2 */ - u8 ac_be_APSD:1; /* bit 3 */ - u8 q_ack:1; /* bit 4 */ - u8 max_len:2; /* bit 5-6 */ - u8 more_data_ack:1; /* bit 7 */ - } q_STA; - u8 val; -}; - -/* QoS sturctures */ -struct iwl_qos_info { - int qos_enable; - int qos_active; - union iwl_qos_capabity qos_cap; - struct iwl_qosparam_cmd def_qos_parm; -}; -#endif /*CONFIG_IWLWIFI_QOS */ - -#define STA_PS_STATUS_WAKE 0 -#define STA_PS_STATUS_SLEEP 1 - -struct iwl_station_entry { - struct iwl_addsta_cmd sta; - struct iwl_tid_data tid[MAX_TID_COUNT]; -#if IWL == 3945 - union { - struct { - u8 rate; - u8 flags; - } s; - u16 rate_n_flags; - } current_rate; -#endif - u8 used; - u8 ps_status; - struct iwl_hw_key keyinfo; -}; - -/* one for each uCode image (inst/data, boot/init/runtime) */ -struct fw_image_desc { - void *v_addr; /* access by driver */ - dma_addr_t p_addr; /* access by card's busmaster DMA */ - u32 len; /* bytes */ -}; - -/* uCode file layout */ -struct iwl_ucode { - __le32 ver; /* major/minor/subminor */ - __le32 inst_size; /* bytes of runtime instructions */ - __le32 data_size; /* bytes of runtime data */ - __le32 init_size; /* bytes of initialization instructions */ - __le32 init_data_size; /* bytes of initialization data */ - __le32 boot_size; /* bytes of bootstrap instructions */ - u8 data[0]; /* data in same order as "size" elements */ -}; - -#define IWL_IBSS_MAC_HASH_SIZE 32 - -struct iwl_ibss_seq { - u8 mac[ETH_ALEN]; - u16 seq_num; - u16 frag_num; - unsigned long packet_time; - struct list_head list; -}; - -struct iwl_driver_hw_info { - u16 max_txq_num; - u16 ac_queue_count; - u32 rx_buffer_size; - u16 tx_cmd_len; - u16 max_rxq_size; - u16 max_rxq_log; - u32 cck_flag; - u8 max_stations; - u8 bcast_sta_id; - void *shared_virt; - dma_addr_t shared_phys; -}; - - -#define STA_FLG_RTS_MIMO_PROT_MSK __constant_cpu_to_le32(1 << 17) -#define STA_FLG_AGG_MPDU_8US_MSK __constant_cpu_to_le32(1 << 18) -#define STA_FLG_MAX_AGG_SIZE_POS (19) -#define STA_FLG_MAX_AGG_SIZE_MSK __constant_cpu_to_le32(3 << 19) -#define STA_FLG_FAT_EN_MSK __constant_cpu_to_le32(1 << 21) -#define STA_FLG_MIMO_DIS_MSK __constant_cpu_to_le32(1 << 22) -#define STA_FLG_AGG_MPDU_DENSITY_POS (23) -#define STA_FLG_AGG_MPDU_DENSITY_MSK __constant_cpu_to_le32(7 << 23) -#define HT_SHORT_GI_20MHZ_ONLY (1 << 0) -#define HT_SHORT_GI_40MHZ_ONLY (1 << 1) - - -#include "iwl-priv.h" - -/* Requires full declaration of iwl_priv before including */ -#include "iwl-io.h" - -#define IWL_RX_HDR(x) ((struct iwl_rx_frame_hdr *)(\ - x->u.rx_frame.stats.payload + \ - x->u.rx_frame.stats.phy_count)) -#define IWL_RX_END(x) ((struct iwl_rx_frame_end *)(\ - IWL_RX_HDR(x)->payload + \ - le16_to_cpu(IWL_RX_HDR(x)->len))) -#define IWL_RX_STATS(x) (&x->u.rx_frame.stats) -#define IWL_RX_DATA(x) (IWL_RX_HDR(x)->payload) - - -/****************************************************************************** - * - * Functions implemented in iwl-base.c which are forward declared here - * for use by iwl-*.c - * - *****************************************************************************/ -struct iwl_addsta_cmd; -extern int iwl_send_add_station(struct iwl_priv *priv, - struct iwl_addsta_cmd *sta, u8 flags); -extern const char *iwl_get_tx_fail_reason(u32 status); -extern u8 iwl_add_station(struct iwl_priv *priv, const u8 *bssid, - int is_ap, u8 flags); -extern int iwl_is_network_packet(struct iwl_priv *priv, - struct ieee80211_hdr *header); -extern int iwl_power_init_handle(struct iwl_priv *priv); -extern int iwl_eeprom_init(struct iwl_priv *priv); -#ifdef CONFIG_IWLWIFI_DEBUG -extern void iwl_report_frame(struct iwl_priv *priv, - struct iwl_rx_packet *pkt, - struct ieee80211_hdr *header, int group100); -#else -static inline void iwl_report_frame(struct iwl_priv *priv, - struct iwl_rx_packet *pkt, - struct ieee80211_hdr *header, - int group100) {} -#endif -extern int iwl_tx_queue_update_write_ptr(struct iwl_priv *priv, - struct iwl_tx_queue *txq); -extern void iwl_handle_data_packet_monitor(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb, - void *data, short len, - struct ieee80211_rx_status *stats, - u16 phy_flags); -extern int is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr - *header); -extern void iwl_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq); -extern int iwl_rx_queue_alloc(struct iwl_priv *priv); -extern void iwl_rx_queue_reset(struct iwl_priv *priv, - struct iwl_rx_queue *rxq); -extern int iwl_calc_db_from_ratio(int sig_ratio); -extern int iwl_calc_sig_qual(int rssi_dbm, int noise_dbm); -extern int iwl_tx_queue_init(struct iwl_priv *priv, - struct iwl_tx_queue *txq, int count, u32 id); -extern int iwl_rx_queue_restock(struct iwl_priv *priv); -extern void iwl_rx_replenish(void *data); -extern void iwl_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq); -extern int iwl_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, - const void *data); -extern int __must_check iwl_send_cmd_async(struct iwl_priv *priv, - struct iwl_host_cmd *cmd); -extern int __must_check iwl_send_cmd_sync(struct iwl_priv *priv, - struct iwl_host_cmd *cmd); -extern int __must_check iwl_send_cmd(struct iwl_priv *priv, - struct iwl_host_cmd *cmd); -extern unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv, - struct ieee80211_hdr *hdr, - const u8 *dest, int left); -extern int iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, - struct iwl_rx_queue *q); -extern int iwl_send_statistics_request(struct iwl_priv *priv); -extern void iwl_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb, - u32 decrypt_res, - struct ieee80211_rx_status *stats); -extern __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr); - -extern const u8 BROADCAST_ADDR[ETH_ALEN]; - -/* - * Currently used by iwl-3945-rs... look at restructuring so that it doesn't - * call this... todo... fix that. -*/ -extern u8 iwl_sync_station(struct iwl_priv *priv, int sta_id, - u16 tx_rate, u8 flags); - -static inline int iwl_is_associated(struct iwl_priv *priv) -{ - return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0; -} - -/****************************************************************************** - * - * Functions implemented in iwl-[34]*.c which are forward declared here - * for use by iwl-base.c - * - * NOTE: The implementation of these functions are hardware specific - * which is why they are in the hardware specific files (vs. iwl-base.c) - * - * Naming convention -- - * iwl_ <-- Its part of iwlwifi (should be changed to iwl_) - * iwl_hw_ <-- Hardware specific (implemented in iwl-XXXX.c by all HW) - * iwlXXXX_ <-- Hardware specific (implemented in iwl-XXXX.c for XXXX) - * iwl_bg_ <-- Called from work queue context - * iwl_mac_ <-- mac80211 callback - * - ****************************************************************************/ -extern void iwl_hw_rx_handler_setup(struct iwl_priv *priv); -extern void iwl_hw_setup_deferred_work(struct iwl_priv *priv); -extern void iwl_hw_cancel_deferred_work(struct iwl_priv *priv); -extern int iwl_hw_rxq_stop(struct iwl_priv *priv); -extern int iwl_hw_set_hw_setting(struct iwl_priv *priv); -extern int iwl_hw_nic_init(struct iwl_priv *priv); -extern void iwl_hw_card_show_info(struct iwl_priv *priv); -extern int iwl_hw_nic_stop_master(struct iwl_priv *priv); -extern void iwl_hw_txq_ctx_free(struct iwl_priv *priv); -extern void iwl_hw_txq_ctx_stop(struct iwl_priv *priv); -extern int iwl_hw_nic_reset(struct iwl_priv *priv); -extern int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *tfd, - dma_addr_t addr, u16 len); -extern int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq); -extern int iwl_hw_get_temperature(struct iwl_priv *priv); -extern int iwl_hw_tx_queue_init(struct iwl_priv *priv, - struct iwl_tx_queue *txq); -extern unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv, - struct iwl_frame *frame, u8 rate); -extern int iwl_hw_get_rx_read(struct iwl_priv *priv); -extern void iwl_hw_build_tx_cmd_rate(struct iwl_priv *priv, - struct iwl_cmd *cmd, - struct ieee80211_tx_control *ctrl, - struct ieee80211_hdr *hdr, - int sta_id, int tx_id); -extern int iwl_hw_reg_send_txpower(struct iwl_priv *priv); -extern int iwl_hw_reg_set_txpower(struct iwl_priv *priv, s8 power); -extern void iwl_hw_rx_statistics(struct iwl_priv *priv, - struct iwl_rx_mem_buffer *rxb); -extern void iwl_disable_events(struct iwl_priv *priv); -extern int iwl4965_get_temperature(const struct iwl_priv *priv); - -/** - * iwl_hw_find_station - Find station id for a given BSSID - * @bssid: MAC address of station ID to find - * - * NOTE: This should not be hardware specific but the code has - * not yet been merged into a single common layer for managing the - * station tables. - */ -extern u8 iwl_hw_find_station(struct iwl_priv *priv, const u8 *bssid); - -extern int iwl_hw_channel_switch(struct iwl_priv *priv, u16 channel); -extern int iwl_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index); -#endif |