mac80211: merge latest changes from trunk, fixes #9227
[10.03/openwrt.git] / package / mac80211 / patches / 473-ath5k_read_mac_addr.patch
1 --- a/drivers/net/wireless/ath/ath5k/ath5k.h
2 +++ b/drivers/net/wireless/ath/ath5k/ath5k.h
3 @@ -1159,6 +1159,7 @@ struct ath_bus_ops {
4         enum ath_bus_type ath_bus_type;
5         void (*read_cachesize)(struct ath_common *common, int *csz);
6         bool (*eeprom_read)(struct ath_common *common, u32 off, u16 *data);
7 +       int (*eeprom_read_mac)(struct ath5k_hw *ah, u8 *mac);
8  };
9  
10  /*
11 @@ -1244,7 +1245,6 @@ int ath5k_hw_dma_stop(struct ath5k_hw *a
12  /* EEPROM access functions */
13  int ath5k_eeprom_init(struct ath5k_hw *ah);
14  void ath5k_eeprom_detach(struct ath5k_hw *ah);
15 -int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac);
16  
17  
18  /* Protocol Control Unit Functions */
19 --- a/drivers/net/wireless/ath/ath5k/eeprom.c
20 +++ b/drivers/net/wireless/ath/ath5k/eeprom.c
21 @@ -1723,46 +1723,6 @@ ath5k_eeprom_read_spur_chans(struct ath5
22         return ret;
23  }
24  
25 -/*
26 - * Read the MAC address from eeprom or platform_data
27 - */
28 -int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
29 -{
30 -       u8 mac_d[ETH_ALEN] = {};
31 -       u32 total, offset;
32 -       u16 data;
33 -       int octet;
34 -       struct ath5k_platform_data *pdata = NULL;
35 -
36 -       if (ah->ah_sc->pdev)
37 -               pdata = ah->ah_sc->pdev->dev.platform_data;
38 -
39 -       if (pdata && pdata->macaddr)
40 -       {
41 -               memcpy(mac, pdata->macaddr, ETH_ALEN);
42 -               return 0;
43 -       }
44 -
45 -       AR5K_EEPROM_READ(0x20, data);
46 -
47 -       for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
48 -               AR5K_EEPROM_READ(offset, data);
49 -
50 -               total += data;
51 -               mac_d[octet + 1] = data & 0xff;
52 -               mac_d[octet] = data >> 8;
53 -               octet += 2;
54 -       }
55 -
56 -       if (!total || total == 3 * 0xffff)
57 -               return -EINVAL;
58 -
59 -       memcpy(mac, mac_d, ETH_ALEN);
60 -
61 -       return 0;
62 -}
63 -
64 -
65  /***********************\
66  * Init/Detach functions *
67  \***********************/
68 --- a/drivers/net/wireless/ath/ath5k/pci.c
69 +++ b/drivers/net/wireless/ath/ath5k/pci.c
70 @@ -18,6 +18,7 @@
71  #include <linux/pci.h>
72  #include <linux/pci-aspm.h>
73  #include <linux/ath5k_platform.h>
74 +#include <linux/etherdevice.h>
75  #include "../ath.h"
76  #include "ath5k.h"
77  #include "debug.h"
78 @@ -122,11 +123,52 @@ int ath5k_hw_read_srev(struct ath5k_hw *
79         return 0;
80  }
81  
82 +/*
83 + * Read the MAC address from eeprom or platform_data
84 + */
85 +static int ath5k_pci_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
86 +{
87 +       u8 mac_d[ETH_ALEN] = {};
88 +       u32 total, offset;
89 +       u16 data;
90 +       int octet;
91 +       struct ath5k_platform_data *pdata = NULL;
92 +
93 +       if (ah->ah_sc->pdev)
94 +               pdata = ah->ah_sc->pdev->dev.platform_data;
95 +
96 +       if (pdata && pdata->macaddr)
97 +       {
98 +               memcpy(mac, pdata->macaddr, ETH_ALEN);
99 +               return 0;
100 +       }
101 +
102 +       AR5K_EEPROM_READ(0x20, data);
103 +
104 +       for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
105 +               AR5K_EEPROM_READ(offset, data);
106 +
107 +               total += data;
108 +               mac_d[octet + 1] = data & 0xff;
109 +               mac_d[octet] = data >> 8;
110 +               octet += 2;
111 +       }
112 +
113 +       if (!total || total == 3 * 0xffff)
114 +               return -EINVAL;
115 +
116 +       memcpy(mac, mac_d, ETH_ALEN);
117 +
118 +       return 0;
119 +}
120 +
121 +
122  /* Common ath_bus_opts structure */
123  static const struct ath_bus_ops ath_pci_bus_ops = {
124         .ath_bus_type = ATH_PCI,
125         .read_cachesize = ath5k_pci_read_cachesize,
126         .eeprom_read = ath5k_pci_eeprom_read,
127 +       .eeprom_read_mac = ath5k_pci_eeprom_read_mac,
128  };
129  
130  /********************\
131 --- a/drivers/net/wireless/ath/ath5k/ahb.c
132 +++ b/drivers/net/wireless/ath/ath5k/ahb.c
133 @@ -18,6 +18,7 @@
134  
135  #include <linux/nl80211.h>
136  #include <linux/platform_device.h>
137 +#include <linux/etherdevice.h>
138  #include <ar231x_platform.h>
139  #include "ath5k.h"
140  #include "debug.h"
141 @@ -62,10 +63,27 @@ int ath5k_hw_read_srev(struct ath5k_hw *
142         return 0;
143  }
144  
145 +static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
146 +{
147 +       struct ath5k_softc *sc = ah->ah_sc;
148 +       struct platform_device *pdev = to_platform_device(sc->dev);
149 +       struct ar231x_board_config *bcfg = pdev->dev.platform_data;
150 +       u8 *cfg_mac;
151 +
152 +       if (to_platform_device(sc->dev)->id == 0)
153 +               cfg_mac = bcfg->config->wlan0_mac;
154 +       else
155 +               cfg_mac = bcfg->config->wlan1_mac;
156 +
157 +       memcpy(mac, cfg_mac, ETH_ALEN);
158 +       return 0;
159 +}
160 +
161  static const struct ath_bus_ops ath_ahb_bus_ops = {
162         .ath_bus_type = ATH_AHB,
163         .read_cachesize = ath5k_ahb_read_cachesize,
164         .eeprom_read = ath5k_ahb_eeprom_read,
165 +       .eeprom_read_mac = ath5k_ahb_eeprom_read_mac,
166  };
167  
168  /*Initialization*/
169 --- a/drivers/net/wireless/ath/ath5k/base.c
170 +++ b/drivers/net/wireless/ath/ath5k/base.c
171 @@ -2880,7 +2880,7 @@ ath5k_init(struct ieee80211_hw *hw)
172         INIT_WORK(&sc->reset_work, ath5k_reset_work);
173         INIT_DELAYED_WORK(&sc->tx_complete_work, ath5k_tx_complete_poll_work);
174  
175 -       ret = ath5k_eeprom_read_mac(ah, mac);
176 +       ret = ath5k_hw_common(ah)->bus_ops->eeprom_read_mac(ah, mac);
177         if (ret) {
178                 ATH5K_ERR(sc, "unable to read address from EEPROM\n");
179                 goto err_queues;