aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-agn.c
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2008-11-07 12:58:41 -0500
committerJohn W. Linville <linville@tuxdriver.com>2008-11-21 11:07:23 -0500
commit21c339bf51ad46c6f8143df907b4bcce99dbe0b8 (patch)
tree6f3c6eff45fc7b7308a3c2fe467291bb7e452d5a /drivers/net/wireless/iwlwifi/iwl-agn.c
parent4ddbb7d060061e584cb2137f4c7e41e502a560b4 (diff)
iwlwifi: move spectrum measurement code to iwl-spectrum.c file
This patch moves spectrum measurement code into iwl-sepctrum.c file. Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-agn.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c229
1 files changed, 1 insertions, 228 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index a9000f14e704..8fa4f7a2dc1a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -871,138 +871,6 @@ static void iwl_set_rate(struct iwl_priv *priv)
871 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; 871 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
872} 872}
873 873
874#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
875
876#include "iwl-spectrum.h"
877
878#define BEACON_TIME_MASK_LOW 0x00FFFFFF
879#define BEACON_TIME_MASK_HIGH 0xFF000000
880#define TIME_UNIT 1024
881
882/*
883 * extended beacon time format
884 * time in usec will be changed into a 32-bit value in 8:24 format
885 * the high 1 byte is the beacon counts
886 * the lower 3 bytes is the time in usec within one beacon interval
887 */
888
889static u32 iwl_usecs_to_beacons(u32 usec, u32 beacon_interval)
890{
891 u32 quot;
892 u32 rem;
893 u32 interval = beacon_interval * 1024;
894
895 if (!interval || !usec)
896 return 0;
897
898 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
899 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
900
901 return (quot << 24) + rem;
902}
903
904/* base is usually what we get from ucode with each received frame,
905 * the same as HW timer counter counting down
906 */
907
908static __le32 iwl_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
909{
910 u32 base_low = base & BEACON_TIME_MASK_LOW;
911 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
912 u32 interval = beacon_interval * TIME_UNIT;
913 u32 res = (base & BEACON_TIME_MASK_HIGH) +
914 (addon & BEACON_TIME_MASK_HIGH);
915
916 if (base_low > addon_low)
917 res += base_low - addon_low;
918 else if (base_low < addon_low) {
919 res += interval + base_low - addon_low;
920 res += (1 << 24);
921 } else
922 res += (1 << 24);
923
924 return cpu_to_le32(res);
925}
926
927static int iwl_get_measurement(struct iwl_priv *priv,
928 struct ieee80211_measurement_params *params,
929 u8 type)
930{
931 struct iwl4965_spectrum_cmd spectrum;
932 struct iwl_rx_packet *res;
933 struct iwl_host_cmd cmd = {
934 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
935 .data = (void *)&spectrum,
936 .meta.flags = CMD_WANT_SKB,
937 };
938 u32 add_time = le64_to_cpu(params->start_time);
939 int rc;
940 int spectrum_resp_status;
941 int duration = le16_to_cpu(params->duration);
942
943 if (iwl_is_associated(priv))
944 add_time =
945 iwl_usecs_to_beacons(
946 le64_to_cpu(params->start_time) - priv->last_tsf,
947 le16_to_cpu(priv->rxon_timing.beacon_interval));
948
949 memset(&spectrum, 0, sizeof(spectrum));
950
951 spectrum.channel_count = cpu_to_le16(1);
952 spectrum.flags =
953 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
954 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
955 cmd.len = sizeof(spectrum);
956 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
957
958 if (iwl_is_associated(priv))
959 spectrum.start_time =
960 iwl_add_beacon_time(priv->last_beacon_time,
961 add_time,
962 le16_to_cpu(priv->rxon_timing.beacon_interval));
963 else
964 spectrum.start_time = 0;
965
966 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
967 spectrum.channels[0].channel = params->channel;
968 spectrum.channels[0].type = type;
969 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
970 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
971 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
972
973 rc = iwl_send_cmd_sync(priv, &cmd);
974 if (rc)
975 return rc;
976
977 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
978 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
979 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
980 rc = -EIO;
981 }
982
983 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
984 switch (spectrum_resp_status) {
985 case 0: /* Command will be handled */
986 if (res->u.spectrum.id != 0xff) {
987 IWL_DEBUG_INFO
988 ("Replaced existing measurement: %d\n",
989 res->u.spectrum.id);
990 priv->measurement_status &= ~MEASUREMENT_READY;
991 }
992 priv->measurement_status |= MEASUREMENT_ACTIVE;
993 rc = 0;
994 break;
995
996 case 1: /* Command will not be handled */
997 rc = -EAGAIN;
998 break;
999 }
1000
1001 dev_kfree_skb_any(cmd.meta.u.skb);
1002
1003 return rc;
1004}
1005#endif
1006 874
1007/****************************************************************************** 875/******************************************************************************
1008 * 876 *
@@ -1072,24 +940,6 @@ static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1072 priv->staging_rxon.channel = csa->channel; 940 priv->staging_rxon.channel = csa->channel;
1073} 941}
1074 942
1075static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv,
1076 struct iwl_rx_mem_buffer *rxb)
1077{
1078#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
1079 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1080 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
1081
1082 if (!report->state) {
1083 IWL_DEBUG(IWL_DL_11H,
1084 "Spectrum Measure Notification: Start\n");
1085 return;
1086 }
1087
1088 memcpy(&priv->measure_report, report, sizeof(*report));
1089 priv->measurement_status |= MEASUREMENT_READY;
1090#endif
1091}
1092
1093static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv, 943static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
1094 struct iwl_rx_mem_buffer *rxb) 944 struct iwl_rx_mem_buffer *rxb)
1095{ 945{
@@ -1298,8 +1148,6 @@ static void iwl_setup_rx_handlers(struct iwl_priv *priv)
1298 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; 1148 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
1299 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error; 1149 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
1300 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa; 1150 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
1301 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
1302 iwl_rx_spectrum_measure_notif;
1303 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif; 1151 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
1304 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = 1152 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
1305 iwl_rx_pm_debug_statistics_notif; 1153 iwl_rx_pm_debug_statistics_notif;
@@ -1313,6 +1161,7 @@ static void iwl_setup_rx_handlers(struct iwl_priv *priv)
1313 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics; 1161 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1314 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics; 1162 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
1315 1163
1164 iwl_setup_spectrum_handlers(priv);
1316 iwl_setup_rx_scan_handlers(priv); 1165 iwl_setup_rx_scan_handlers(priv);
1317 1166
1318 /* status change handler */ 1167 /* status change handler */
@@ -3767,79 +3616,6 @@ static ssize_t store_filter_flags(struct device *d,
3767static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, 3616static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3768 store_filter_flags); 3617 store_filter_flags);
3769 3618
3770#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
3771
3772static ssize_t show_measurement(struct device *d,
3773 struct device_attribute *attr, char *buf)
3774{
3775 struct iwl_priv *priv = dev_get_drvdata(d);
3776 struct iwl4965_spectrum_notification measure_report;
3777 u32 size = sizeof(measure_report), len = 0, ofs = 0;
3778 u8 *data = (u8 *)&measure_report;
3779 unsigned long flags;
3780
3781 spin_lock_irqsave(&priv->lock, flags);
3782 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3783 spin_unlock_irqrestore(&priv->lock, flags);
3784 return 0;
3785 }
3786 memcpy(&measure_report, &priv->measure_report, size);
3787 priv->measurement_status = 0;
3788 spin_unlock_irqrestore(&priv->lock, flags);
3789
3790 while (size && (PAGE_SIZE - len)) {
3791 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3792 PAGE_SIZE - len, 1);
3793 len = strlen(buf);
3794 if (PAGE_SIZE - len)
3795 buf[len++] = '\n';
3796
3797 ofs += 16;
3798 size -= min(size, 16U);
3799 }
3800
3801 return len;
3802}
3803
3804static ssize_t store_measurement(struct device *d,
3805 struct device_attribute *attr,
3806 const char *buf, size_t count)
3807{
3808 struct iwl_priv *priv = dev_get_drvdata(d);
3809 struct ieee80211_measurement_params params = {
3810 .channel = le16_to_cpu(priv->active_rxon.channel),
3811 .start_time = cpu_to_le64(priv->last_tsf),
3812 .duration = cpu_to_le16(1),
3813 };
3814 u8 type = IWL_MEASURE_BASIC;
3815 u8 buffer[32];
3816 u8 channel;
3817
3818 if (count) {
3819 char *p = buffer;
3820 strncpy(buffer, buf, min(sizeof(buffer), count));
3821 channel = simple_strtoul(p, NULL, 0);
3822 if (channel)
3823 params.channel = channel;
3824
3825 p = buffer;
3826 while (*p && *p != ' ')
3827 p++;
3828 if (*p)
3829 type = simple_strtoul(p + 1, NULL, 0);
3830 }
3831
3832 IWL_DEBUG_INFO("Invoking measurement of type %d on "
3833 "channel %d (for '%s')\n", type, params.channel, buf);
3834 iwl_get_measurement(priv, &params, type);
3835
3836 return count;
3837}
3838
3839static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3840 show_measurement, store_measurement);
3841#endif /* CONFIG_IWLAGN_SPECTRUM_MEASUREMENT */
3842
3843static ssize_t store_retry_rate(struct device *d, 3619static ssize_t store_retry_rate(struct device *d,
3844 struct device_attribute *attr, 3620 struct device_attribute *attr,
3845 const char *buf, size_t count) 3621 const char *buf, size_t count)
@@ -4092,9 +3868,6 @@ static struct attribute *iwl_sysfs_entries[] = {
4092 &dev_attr_channels.attr, 3868 &dev_attr_channels.attr,
4093 &dev_attr_flags.attr, 3869 &dev_attr_flags.attr,
4094 &dev_attr_filter_flags.attr, 3870 &dev_attr_filter_flags.attr,
4095#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
4096 &dev_attr_measurement.attr,
4097#endif
4098 &dev_attr_power_level.attr, 3871 &dev_attr_power_level.attr,
4099 &dev_attr_retry_rate.attr, 3872 &dev_attr_retry_rate.attr,
4100 &dev_attr_statistics.attr, 3873 &dev_attr_statistics.attr,