23 #include <linux/slab.h>
27 #include <linux/export.h>
34 { .bitrate = 10, .hw_value = 0, },
38 { .bitrate = 60, .hw_value = 4, },
39 { .bitrate = 90, .hw_value = 5, },
40 { .bitrate = 120, .hw_value = 6, },
41 { .bitrate = 180, .hw_value = 7, },
42 { .bitrate = 240, .hw_value = 8, },
43 { .bitrate = 360, .hw_value = 9, },
44 { .bitrate = 480, .hw_value = 10, },
45 { .bitrate = 540, .hw_value = 11, },
49 { .bitrate = 60, .hw_value = 4, },
50 { .bitrate = 90, .hw_value = 5, },
51 { .bitrate = 120, .hw_value = 6, },
52 { .bitrate = 180, .hw_value = 7, },
53 { .bitrate = 240, .hw_value = 8, },
54 { .bitrate = 360, .hw_value = 9, },
55 { .bitrate = 480, .hw_value = 10, },
56 { .bitrate = 540, .hw_value = 11, },
70 #define CHAN_HAS_CAL BIT(0)
71 #define CHAN_HAS_LIMIT BIT(1)
72 #define CHAN_HAS_CURVE BIT(2)
73 #define CHAN_HAS_ALL (CHAN_HAS_CAL | CHAN_HAS_LIMIT | CHAN_HAS_CURVE)
90 static int p54_get_band_from_freq(
u16 freq)
94 if ((freq >= 2412) && (freq <= 2484))
97 if ((freq >= 4920) && (freq <= 5825))
105 return p54_get_band_from_freq(freq) == p54_get_band_from_freq(freq2);
108 static int p54_compare_channels(
const void *_a,
117 static int p54_compare_rssichan(
const void *_a,
170 ret = p54_fill_band_bitrates(dev, tmp, band);
179 if (chan->
band != band)
184 "channel:%d [%d MHz].\n",
186 " [iqauto calibration data]"),
188 " [output power limits]"),
246 for (i = list->
entries; i >= 0; i--) {
247 if (freq == list->
channels[i].freq) {
255 int band = p54_get_band_from_freq(freq);
280 static int p54_get_maxpower(
struct p54_common *priv,
void *data)
301 return rawpower / 16;
323 static int p54_generate_channel_lists(
struct ieee80211_hw *dev)
327 unsigned int i,
j,
k, max_channel_num;
334 "Unsupported or damaged EEPROM detected. "
335 "You may not be able to use all channels.\n");
339 max_channel_num =
max_t(
unsigned int, max_channel_num,
363 for (i = 0; i < max_channel_num; i++) {
364 if (i < priv->iq_autocal_len) {
369 if (i < priv->output_limit->entries) {
372 void *data = (
void *) ((
unsigned long) i *
378 tmp = p54_update_channel_param(list, freq,
381 tmp->
max_power = p54_get_maxpower(priv, data);
385 if (i < priv->curve_data->entries) {
397 p54_compare_channels,
NULL);
401 if (p54_generate_band(dev, list, &k, i) == 0)
428 size_t cd_len =
sizeof(*curve_data) +
445 source = curve_data->
data;
447 for (i = 0; i < curve_data->
channels; i++) {
460 #define SUB(x, y) (u8)(((x) - (y)) > (x) ? 0 : (x) - (y))
467 source +=
sizeof(*src);
480 size_t cd_len =
sizeof(*curve_data) +
497 source = curve_data->
data;
499 for (i = 0; i < curve_data->
channels; i++) {
508 source +=
sizeof(*src);
516 static const char *p54_rf_chips[] = {
"INVALID-0",
"Duette3",
"Duette2",
517 "Frisbee",
"Xbow",
"Longbow",
"INVALID-6",
"INVALID-7" };
541 entries = (len -
offset) /
551 db_len =
sizeof(*entry) *
entries;
558 priv->
rssi_db->entry_size =
sizeof(*entry);
561 entry = (
void *)((
unsigned long)priv->
rssi_db->data + priv->
rssi_db->offset);
565 for (i = 0; i <
entries; i++) {
573 for (i = 0; i <
entries; i++) {
591 sort(entry, entries,
sizeof(*entry), p54_compare_rssichan,
NULL);
596 "rssi calibration data packing type:(%x) len:%d.\n",
611 return &p54_rssi_default;
614 for (i = 0; i < priv->
rssi_db->entries; i++) {
615 if (!same_band(freq, entry[i].freq))
624 if (
abs(freq - entry[i].freq) <
625 abs(freq - entry[found].freq)) {
633 return found < 0 ? &p54_rssi_default : &entry[found];
636 static void p54_parse_default_country(
struct ieee80211_hw *dev,
641 if (len !=
sizeof(*country)) {
643 "found possible invalid default country eeprom entry. (entry size: %d)\n",
665 static int p54_convert_output_limits(
struct ieee80211_hw *dev,
666 u8 *data,
size_t len)
713 if (((entries * entry_size + offset) != payload_len) ||
714 (payload_len +
sizeof(*src) != total_len))
746 while ((
u8 *)entry <= end -
sizeof(*entry)) {
748 data_len = ((entry_len - 1) << 1);
751 if ((
u8 *)entry +
sizeof(*entry) + data_len >
end)
758 SET_IEEE80211_PERM_ADDR(dev, entry->
data);
763 err = p54_convert_output_limits(dev, entry->
data,
771 if (data_len <
sizeof(*curve_data)) {
778 err = p54_convert_rev0(dev, curve_data);
781 err = p54_convert_rev1(dev, curve_data);
785 "unknown curve data revision %d\n",
805 p54_parse_default_country(dev, entry->
data, data_len);
809 while ((
u8 *)tmp < entry->data + data_len) {
813 tmp +=
sizeof(*exp_if);
824 err = p54_parse_rssical(dev, entry->
data, data_len,
835 if (priv->
rssi_db || data_len <
sizeof(*pda))
838 priv->
rssi_db = p54_convert_db(pda, data_len);
842 src = (
void *) priv->
rssi_db->data;
843 dst = (
void *) priv->
rssi_db->data;
845 for (i = 0; i < priv->
rssi_db->entries; i++)
861 priv->
curve_data = p54_convert_db(pda, data_len);
865 crc16 = ~
crc_ccitt(crc16, (
u8 *) entry,
sizeof(*entry));
879 crc16 =
crc_ccitt(crc16, (
u8 *)entry, (entry_len + 1) * 2);
880 entry = (
void *)entry + (entry_len + 1) * 2;
891 "not all required entries found in eeprom!\n");
898 err = p54_generate_channel_lists(dev);
915 if (!is_valid_ether_addr(dev->
wiphy->perm_addr)) {
919 "Invalid hwaddr! Using randomly generated MAC addr\n");
920 eth_random_addr(perm_addr);
921 SET_IEEE80211_PERM_ADDR(dev, perm_addr);
928 p54_rf_chips[priv->
rxhw]);
952 size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize;
957 if (priv->
fw_var >= 0x509)
966 while (eeprom_size) {
967 blocksize =
min(eeprom_size, maxblocksize);
974 eeprom_size -= blocksize;