Commit 66f742f36cb7d6a4f371d72fe5b6e4c7d19e587b

Authored by Eric Lee
1 parent fa5318953a
Exists in v3.2_SBC_SMARTMEN

Upgrade eMMC from 4GB to 8GB

Showing 3 changed files with 18 additions and 15 deletions Inline Diff

drivers/mmc/core/mmc.c
1 /* 1 /*
2 * linux/drivers/mmc/core/mmc.c 2 * linux/drivers/mmc/core/mmc.c
3 * 3 *
4 * Copyright (C) 2003-2004 Russell King, All Rights Reserved. 4 * Copyright (C) 2003-2004 Russell King, All Rights Reserved.
5 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. 5 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
6 * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved. 6 * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved.
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as 9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13 #include <linux/err.h> 13 #include <linux/err.h>
14 #include <linux/slab.h> 14 #include <linux/slab.h>
15 #include <linux/stat.h> 15 #include <linux/stat.h>
16 16
17 #include <linux/mmc/host.h> 17 #include <linux/mmc/host.h>
18 #include <linux/mmc/card.h> 18 #include <linux/mmc/card.h>
19 #include <linux/mmc/mmc.h> 19 #include <linux/mmc/mmc.h>
20 20
21 #include "core.h" 21 #include "core.h"
22 #include "bus.h" 22 #include "bus.h"
23 #include "mmc_ops.h" 23 #include "mmc_ops.h"
24 #include "sd_ops.h" 24 #include "sd_ops.h"
25 25
26 static const unsigned int tran_exp[] = { 26 static const unsigned int tran_exp[] = {
27 10000, 100000, 1000000, 10000000, 27 10000, 100000, 1000000, 10000000,
28 0, 0, 0, 0 28 0, 0, 0, 0
29 }; 29 };
30 30
31 static const unsigned char tran_mant[] = { 31 static const unsigned char tran_mant[] = {
32 0, 10, 12, 13, 15, 20, 25, 30, 32 0, 10, 12, 13, 15, 20, 25, 30,
33 35, 40, 45, 50, 55, 60, 70, 80, 33 35, 40, 45, 50, 55, 60, 70, 80,
34 }; 34 };
35 35
36 static const unsigned int tacc_exp[] = { 36 static const unsigned int tacc_exp[] = {
37 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 37 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
38 }; 38 };
39 39
40 static const unsigned int tacc_mant[] = { 40 static const unsigned int tacc_mant[] = {
41 0, 10, 12, 13, 15, 20, 25, 30, 41 0, 10, 12, 13, 15, 20, 25, 30,
42 35, 40, 45, 50, 55, 60, 70, 80, 42 35, 40, 45, 50, 55, 60, 70, 80,
43 }; 43 };
44 44
45 #define UNSTUFF_BITS(resp,start,size) \ 45 #define UNSTUFF_BITS(resp,start,size) \
46 ({ \ 46 ({ \
47 const int __size = size; \ 47 const int __size = size; \
48 const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \ 48 const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \
49 const int __off = 3 - ((start) / 32); \ 49 const int __off = 3 - ((start) / 32); \
50 const int __shft = (start) & 31; \ 50 const int __shft = (start) & 31; \
51 u32 __res; \ 51 u32 __res; \
52 \ 52 \
53 __res = resp[__off] >> __shft; \ 53 __res = resp[__off] >> __shft; \
54 if (__size + __shft > 32) \ 54 if (__size + __shft > 32) \
55 __res |= resp[__off-1] << ((32 - __shft) % 32); \ 55 __res |= resp[__off-1] << ((32 - __shft) % 32); \
56 __res & __mask; \ 56 __res & __mask; \
57 }) 57 })
58 58
59 /* 59 /*
60 * Given the decoded CSD structure, decode the raw CID to our CID structure. 60 * Given the decoded CSD structure, decode the raw CID to our CID structure.
61 */ 61 */
62 static int mmc_decode_cid(struct mmc_card *card) 62 static int mmc_decode_cid(struct mmc_card *card)
63 { 63 {
64 u32 *resp = card->raw_cid; 64 u32 *resp = card->raw_cid;
65 65
66 /* 66 /*
67 * The selection of the format here is based upon published 67 * The selection of the format here is based upon published
68 * specs from sandisk and from what people have reported. 68 * specs from sandisk and from what people have reported.
69 */ 69 */
70 switch (card->csd.mmca_vsn) { 70 switch (card->csd.mmca_vsn) {
71 case 0: /* MMC v1.0 - v1.2 */ 71 case 0: /* MMC v1.0 - v1.2 */
72 case 1: /* MMC v1.4 */ 72 case 1: /* MMC v1.4 */
73 card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); 73 card->cid.manfid = UNSTUFF_BITS(resp, 104, 24);
74 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); 74 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8);
75 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); 75 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8);
76 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); 76 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8);
77 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); 77 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8);
78 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); 78 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8);
79 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); 79 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8);
80 card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); 80 card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8);
81 card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); 81 card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4);
82 card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); 82 card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4);
83 card->cid.serial = UNSTUFF_BITS(resp, 16, 24); 83 card->cid.serial = UNSTUFF_BITS(resp, 16, 24);
84 card->cid.month = UNSTUFF_BITS(resp, 12, 4); 84 card->cid.month = UNSTUFF_BITS(resp, 12, 4);
85 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; 85 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997;
86 break; 86 break;
87 87
88 case 2: /* MMC v2.0 - v2.2 */ 88 case 2: /* MMC v2.0 - v2.2 */
89 case 3: /* MMC v3.1 - v3.3 */ 89 case 3: /* MMC v3.1 - v3.3 */
90 case 4: /* MMC v4 */ 90 case 4: /* MMC v4 */
91 card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); 91 card->cid.manfid = UNSTUFF_BITS(resp, 120, 8);
92 card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); 92 card->cid.oemid = UNSTUFF_BITS(resp, 104, 16);
93 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); 93 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8);
94 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); 94 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8);
95 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); 95 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8);
96 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); 96 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8);
97 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); 97 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8);
98 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); 98 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8);
99 card->cid.serial = UNSTUFF_BITS(resp, 16, 32); 99 card->cid.serial = UNSTUFF_BITS(resp, 16, 32);
100 card->cid.month = UNSTUFF_BITS(resp, 12, 4); 100 card->cid.month = UNSTUFF_BITS(resp, 12, 4);
101 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; 101 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997;
102 break; 102 break;
103 103
104 default: 104 default:
105 pr_err("%s: card has unknown MMCA version %d\n", 105 pr_err("%s: card has unknown MMCA version %d\n",
106 mmc_hostname(card->host), card->csd.mmca_vsn); 106 mmc_hostname(card->host), card->csd.mmca_vsn);
107 return -EINVAL; 107 return -EINVAL;
108 } 108 }
109 109
110 return 0; 110 return 0;
111 } 111 }
112 112
113 static void mmc_set_erase_size(struct mmc_card *card) 113 static void mmc_set_erase_size(struct mmc_card *card)
114 { 114 {
115 if (card->ext_csd.erase_group_def & 1) 115 if (card->ext_csd.erase_group_def & 1)
116 card->erase_size = card->ext_csd.hc_erase_size; 116 card->erase_size = card->ext_csd.hc_erase_size;
117 else 117 else
118 card->erase_size = card->csd.erase_size; 118 card->erase_size = card->csd.erase_size;
119 119
120 mmc_init_erase(card); 120 mmc_init_erase(card);
121 } 121 }
122 122
123 /* 123 /*
124 * Given a 128-bit response, decode to our card CSD structure. 124 * Given a 128-bit response, decode to our card CSD structure.
125 */ 125 */
126 static int mmc_decode_csd(struct mmc_card *card) 126 static int mmc_decode_csd(struct mmc_card *card)
127 { 127 {
128 struct mmc_csd *csd = &card->csd; 128 struct mmc_csd *csd = &card->csd;
129 unsigned int e, m, a, b; 129 unsigned int e, m, a, b;
130 u32 *resp = card->raw_csd; 130 u32 *resp = card->raw_csd;
131 131
132 /* 132 /*
133 * We only understand CSD structure v1.1 and v1.2. 133 * We only understand CSD structure v1.1 and v1.2.
134 * v1.2 has extra information in bits 15, 11 and 10. 134 * v1.2 has extra information in bits 15, 11 and 10.
135 * We also support eMMC v4.4 & v4.41. 135 * We also support eMMC v4.4 & v4.41.
136 */ 136 */
137 csd->structure = UNSTUFF_BITS(resp, 126, 2); 137 csd->structure = UNSTUFF_BITS(resp, 126, 2);
138 if (csd->structure == 0) { 138 if (csd->structure == 0) {
139 pr_err("%s: unrecognised CSD structure version %d\n", 139 pr_err("%s: unrecognised CSD structure version %d\n",
140 mmc_hostname(card->host), csd->structure); 140 mmc_hostname(card->host), csd->structure);
141 return -EINVAL; 141 return -EINVAL;
142 } 142 }
143 143
144 csd->mmca_vsn = UNSTUFF_BITS(resp, 122, 4); 144 csd->mmca_vsn = UNSTUFF_BITS(resp, 122, 4);
145 m = UNSTUFF_BITS(resp, 115, 4); 145 m = UNSTUFF_BITS(resp, 115, 4);
146 e = UNSTUFF_BITS(resp, 112, 3); 146 e = UNSTUFF_BITS(resp, 112, 3);
147 csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10; 147 csd->tacc_ns = (tacc_exp[e] * tacc_mant[m] + 9) / 10;
148 csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100; 148 csd->tacc_clks = UNSTUFF_BITS(resp, 104, 8) * 100;
149 149
150 m = UNSTUFF_BITS(resp, 99, 4); 150 m = UNSTUFF_BITS(resp, 99, 4);
151 e = UNSTUFF_BITS(resp, 96, 3); 151 e = UNSTUFF_BITS(resp, 96, 3);
152 csd->max_dtr = tran_exp[e] * tran_mant[m]; 152 csd->max_dtr = tran_exp[e] * tran_mant[m];
153 csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); 153 csd->cmdclass = UNSTUFF_BITS(resp, 84, 12);
154 154
155 e = UNSTUFF_BITS(resp, 47, 3); 155 e = UNSTUFF_BITS(resp, 47, 3);
156 m = UNSTUFF_BITS(resp, 62, 12); 156 m = UNSTUFF_BITS(resp, 62, 12);
157 csd->capacity = (1 + m) << (e + 2); 157 csd->capacity = (1 + m) << (e + 2);
158 158
159 csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4); 159 csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4);
160 csd->read_partial = UNSTUFF_BITS(resp, 79, 1); 160 csd->read_partial = UNSTUFF_BITS(resp, 79, 1);
161 csd->write_misalign = UNSTUFF_BITS(resp, 78, 1); 161 csd->write_misalign = UNSTUFF_BITS(resp, 78, 1);
162 csd->read_misalign = UNSTUFF_BITS(resp, 77, 1); 162 csd->read_misalign = UNSTUFF_BITS(resp, 77, 1);
163 csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); 163 csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3);
164 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); 164 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4);
165 csd->write_partial = UNSTUFF_BITS(resp, 21, 1); 165 csd->write_partial = UNSTUFF_BITS(resp, 21, 1);
166 166
167 if (csd->write_blkbits >= 9) { 167 if (csd->write_blkbits >= 9) {
168 a = UNSTUFF_BITS(resp, 42, 5); 168 a = UNSTUFF_BITS(resp, 42, 5);
169 b = UNSTUFF_BITS(resp, 37, 5); 169 b = UNSTUFF_BITS(resp, 37, 5);
170 csd->erase_size = (a + 1) * (b + 1); 170 csd->erase_size = (a + 1) * (b + 1);
171 csd->erase_size <<= csd->write_blkbits - 9; 171 csd->erase_size <<= csd->write_blkbits - 9;
172 } 172 }
173 173
174 return 0; 174 return 0;
175 } 175 }
176 176
177 /* 177 /*
178 * Read extended CSD. 178 * Read extended CSD.
179 */ 179 */
180 static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd) 180 static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
181 { 181 {
182 int err; 182 int err;
183 u8 *ext_csd; 183 u8 *ext_csd;
184 184
185 BUG_ON(!card); 185 BUG_ON(!card);
186 BUG_ON(!new_ext_csd); 186 BUG_ON(!new_ext_csd);
187 187
188 *new_ext_csd = NULL; 188 *new_ext_csd = NULL;
189 189
190 if (card->csd.mmca_vsn < CSD_SPEC_VER_4) 190 if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
191 return 0; 191 return 0;
192 192
193 /* 193 /*
194 * As the ext_csd is so large and mostly unused, we don't store the 194 * As the ext_csd is so large and mostly unused, we don't store the
195 * raw block in mmc_card. 195 * raw block in mmc_card.
196 */ 196 */
197 ext_csd = kmalloc(512, GFP_KERNEL); 197 ext_csd = kmalloc(512, GFP_KERNEL);
198 if (!ext_csd) { 198 if (!ext_csd) {
199 pr_err("%s: could not allocate a buffer to " 199 pr_err("%s: could not allocate a buffer to "
200 "receive the ext_csd.\n", mmc_hostname(card->host)); 200 "receive the ext_csd.\n", mmc_hostname(card->host));
201 return -ENOMEM; 201 return -ENOMEM;
202 } 202 }
203 203
204 err = mmc_send_ext_csd(card, ext_csd); 204 err = mmc_send_ext_csd(card, ext_csd);
205 if (err) { 205 if (err) {
206 kfree(ext_csd); 206 kfree(ext_csd);
207 *new_ext_csd = NULL; 207 *new_ext_csd = NULL;
208 208
209 /* If the host or the card can't do the switch, 209 /* If the host or the card can't do the switch,
210 * fail more gracefully. */ 210 * fail more gracefully. */
211 if ((err != -EINVAL) 211 if ((err != -EINVAL)
212 && (err != -ENOSYS) 212 && (err != -ENOSYS)
213 && (err != -EFAULT)) 213 && (err != -EFAULT))
214 return err; 214 return err;
215 215
216 /* 216 /*
217 * High capacity cards should have this "magic" size 217 * High capacity cards should have this "magic" size
218 * stored in their CSD. 218 * stored in their CSD.
219 */ 219 */
220 if (card->csd.capacity == (4096 * 512)) { 220 if (card->csd.capacity == (4096 * 512)) {
221 pr_err("%s: unable to read EXT_CSD " 221 pr_err("%s: unable to read EXT_CSD "
222 "on a possible high capacity card. " 222 "on a possible high capacity card. "
223 "Card will be ignored.\n", 223 "Card will be ignored.\n",
224 mmc_hostname(card->host)); 224 mmc_hostname(card->host));
225 } else { 225 } else {
226 pr_warning("%s: unable to read " 226 pr_warning("%s: unable to read "
227 "EXT_CSD, performance might " 227 "EXT_CSD, performance might "
228 "suffer.\n", 228 "suffer.\n",
229 mmc_hostname(card->host)); 229 mmc_hostname(card->host));
230 err = 0; 230 err = 0;
231 } 231 }
232 } else 232 } else
233 *new_ext_csd = ext_csd; 233 *new_ext_csd = ext_csd;
234 234
235 return err; 235 return err;
236 } 236 }
237 237
238 /* 238 /*
239 * Decode extended CSD. 239 * Decode extended CSD.
240 */ 240 */
241 static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) 241 static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
242 { 242 {
243 int err = 0, idx; 243 int err = 0, idx;
244 unsigned int part_size; 244 unsigned int part_size;
245 u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0; 245 u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
246 246
247 BUG_ON(!card); 247 BUG_ON(!card);
248 248
249 if (!ext_csd) 249 if (!ext_csd)
250 return 0; 250 return 0;
251 251
252 /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */ 252 /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */
253 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; 253 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE];
254 if (card->csd.structure == 3) { 254 if (card->csd.structure == 3) {
255 if (card->ext_csd.raw_ext_csd_structure > 2) { 255 if (card->ext_csd.raw_ext_csd_structure > 2) {
256 pr_err("%s: unrecognised EXT_CSD structure " 256 pr_err("%s: unrecognised EXT_CSD structure "
257 "version %d\n", mmc_hostname(card->host), 257 "version %d\n", mmc_hostname(card->host),
258 card->ext_csd.raw_ext_csd_structure); 258 card->ext_csd.raw_ext_csd_structure);
259 err = -EINVAL; 259 err = -EINVAL;
260 goto out; 260 goto out;
261 } 261 }
262 } 262 }
263 263
264 card->ext_csd.rev = ext_csd[EXT_CSD_REV]; 264 card->ext_csd.rev = ext_csd[EXT_CSD_REV];
265 if (card->ext_csd.rev > 7) { 265 if (card->ext_csd.rev > 8) {
266 pr_err("%s: unrecognised EXT_CSD revision %d\n", 266 pr_err("%s: unrecognised EXT_CSD revision %d\n",
267 mmc_hostname(card->host), card->ext_csd.rev); 267 mmc_hostname(card->host), card->ext_csd.rev);
268 err = -EINVAL; 268 err = -EINVAL;
269 goto out; 269 goto out;
270 } 270 }
271 271
272 card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; 272 card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0];
273 card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; 273 card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1];
274 card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; 274 card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2];
275 card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; 275 card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3];
276 if (card->ext_csd.rev >= 2) { 276 if (card->ext_csd.rev >= 2) {
277 card->ext_csd.sectors = 277 card->ext_csd.sectors =
278 ext_csd[EXT_CSD_SEC_CNT + 0] << 0 | 278 ext_csd[EXT_CSD_SEC_CNT + 0] << 0 |
279 ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | 279 ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
280 ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | 280 ext_csd[EXT_CSD_SEC_CNT + 2] << 16 |
281 ext_csd[EXT_CSD_SEC_CNT + 3] << 24; 281 ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
282 282
283 /* Cards with density > 2GiB are sector addressed */ 283 /* Cards with density > 2GiB are sector addressed */
284 if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) 284 if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512)
285 mmc_card_set_blockaddr(card); 285 mmc_card_set_blockaddr(card);
286 } 286 }
287 card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; 287 card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE];
288 switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) { 288 switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) {
289 case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_52 | 289 case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_52 |
290 EXT_CSD_CARD_TYPE_26: 290 EXT_CSD_CARD_TYPE_26:
291 card->ext_csd.hs_max_dtr = 52000000; 291 card->ext_csd.hs_max_dtr = 52000000;
292 card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_52; 292 card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_52;
293 break; 293 break;
294 case EXT_CSD_CARD_TYPE_DDR_1_2V | EXT_CSD_CARD_TYPE_52 | 294 case EXT_CSD_CARD_TYPE_DDR_1_2V | EXT_CSD_CARD_TYPE_52 |
295 EXT_CSD_CARD_TYPE_26: 295 EXT_CSD_CARD_TYPE_26:
296 card->ext_csd.hs_max_dtr = 52000000; 296 card->ext_csd.hs_max_dtr = 52000000;
297 card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_1_2V; 297 card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_1_2V;
298 break; 298 break;
299 case EXT_CSD_CARD_TYPE_DDR_1_8V | EXT_CSD_CARD_TYPE_52 | 299 case EXT_CSD_CARD_TYPE_DDR_1_8V | EXT_CSD_CARD_TYPE_52 |
300 EXT_CSD_CARD_TYPE_26: 300 EXT_CSD_CARD_TYPE_26:
301 card->ext_csd.hs_max_dtr = 52000000; 301 card->ext_csd.hs_max_dtr = 52000000;
302 card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_1_8V; 302 card->ext_csd.card_type = EXT_CSD_CARD_TYPE_DDR_1_8V;
303 break; 303 break;
304 case EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26: 304 case EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26:
305 card->ext_csd.hs_max_dtr = 52000000; 305 card->ext_csd.hs_max_dtr = 52000000;
306 break; 306 break;
307 case EXT_CSD_CARD_TYPE_26: 307 case EXT_CSD_CARD_TYPE_26:
308 card->ext_csd.hs_max_dtr = 26000000; 308 card->ext_csd.hs_max_dtr = 26000000;
309 break; 309 break;
310 default: 310 default:
311 /* MMC v4 spec says this cannot happen */ 311 /* MMC v4 spec says this cannot happen */
312 pr_warning("%s: card is mmc v4 but doesn't " 312 pr_warning("%s: card is mmc v4 but doesn't "
313 "support any high-speed modes.\n", 313 "support any high-speed modes.\n",
314 mmc_hostname(card->host)); 314 mmc_hostname(card->host));
315 } 315 }
316 316
317 card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; 317 card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT];
318 card->ext_csd.raw_erase_timeout_mult = 318 card->ext_csd.raw_erase_timeout_mult =
319 ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; 319 ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT];
320 card->ext_csd.raw_hc_erase_grp_size = 320 card->ext_csd.raw_hc_erase_grp_size =
321 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; 321 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
322 if (card->ext_csd.rev >= 3) { 322 if (card->ext_csd.rev >= 3) {
323 u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT]; 323 u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT];
324 card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; 324 card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG];
325 325
326 /* EXT_CSD value is in units of 10ms, but we store in ms */ 326 /* EXT_CSD value is in units of 10ms, but we store in ms */
327 card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; 327 card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME];
328 328
329 /* Sleep / awake timeout in 100ns units */ 329 /* Sleep / awake timeout in 100ns units */
330 if (sa_shift > 0 && sa_shift <= 0x17) 330 if (sa_shift > 0 && sa_shift <= 0x17)
331 card->ext_csd.sa_timeout = 331 card->ext_csd.sa_timeout =
332 1 << ext_csd[EXT_CSD_S_A_TIMEOUT]; 332 1 << ext_csd[EXT_CSD_S_A_TIMEOUT];
333 card->ext_csd.erase_group_def = 333 card->ext_csd.erase_group_def =
334 ext_csd[EXT_CSD_ERASE_GROUP_DEF]; 334 ext_csd[EXT_CSD_ERASE_GROUP_DEF];
335 card->ext_csd.hc_erase_timeout = 300 * 335 card->ext_csd.hc_erase_timeout = 300 *
336 ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; 336 ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT];
337 card->ext_csd.hc_erase_size = 337 card->ext_csd.hc_erase_size =
338 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10; 338 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10;
339 339
340 card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; 340 card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C];
341 341
342 /* 342 /*
343 * There are two boot regions of equal size, defined in 343 * There are two boot regions of equal size, defined in
344 * multiples of 128K. 344 * multiples of 128K.
345 */ 345 */
346 if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { 346 if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) {
347 for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) { 347 for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) {
348 part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; 348 part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17;
349 mmc_part_add(card, part_size, 349 mmc_part_add(card, part_size,
350 EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx, 350 EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx,
351 "boot%d", idx, true); 351 "boot%d", idx, true);
352 } 352 }
353 } 353 }
354 } 354 }
355 355
356 card->ext_csd.raw_hc_erase_gap_size = 356 card->ext_csd.raw_hc_erase_gap_size =
357 ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]; 357 ext_csd[EXT_CSD_PARTITION_ATTRIBUTE];
358 card->ext_csd.raw_sec_trim_mult = 358 card->ext_csd.raw_sec_trim_mult =
359 ext_csd[EXT_CSD_SEC_TRIM_MULT]; 359 ext_csd[EXT_CSD_SEC_TRIM_MULT];
360 card->ext_csd.raw_sec_erase_mult = 360 card->ext_csd.raw_sec_erase_mult =
361 ext_csd[EXT_CSD_SEC_ERASE_MULT]; 361 ext_csd[EXT_CSD_SEC_ERASE_MULT];
362 card->ext_csd.raw_sec_feature_support = 362 card->ext_csd.raw_sec_feature_support =
363 ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; 363 ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT];
364 card->ext_csd.raw_trim_mult = 364 card->ext_csd.raw_trim_mult =
365 ext_csd[EXT_CSD_TRIM_MULT]; 365 ext_csd[EXT_CSD_TRIM_MULT];
366 if (card->ext_csd.rev >= 4) { 366 if (card->ext_csd.rev >= 4) {
367 /* 367 /*
368 * Enhanced area feature support -- check whether the eMMC 368 * Enhanced area feature support -- check whether the eMMC
369 * card has the Enhanced area enabled. If so, export enhanced 369 * card has the Enhanced area enabled. If so, export enhanced
370 * area offset and size to user by adding sysfs interface. 370 * area offset and size to user by adding sysfs interface.
371 */ 371 */
372 card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; 372 card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT];
373 if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) && 373 if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
374 (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) { 374 (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
375 hc_erase_grp_sz = 375 hc_erase_grp_sz =
376 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; 376 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
377 hc_wp_grp_sz = 377 hc_wp_grp_sz =
378 ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; 378 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
379 379
380 card->ext_csd.enhanced_area_en = 1; 380 card->ext_csd.enhanced_area_en = 1;
381 /* 381 /*
382 * calculate the enhanced data area offset, in bytes 382 * calculate the enhanced data area offset, in bytes
383 */ 383 */
384 card->ext_csd.enhanced_area_offset = 384 card->ext_csd.enhanced_area_offset =
385 (ext_csd[139] << 24) + (ext_csd[138] << 16) + 385 (ext_csd[139] << 24) + (ext_csd[138] << 16) +
386 (ext_csd[137] << 8) + ext_csd[136]; 386 (ext_csd[137] << 8) + ext_csd[136];
387 if (mmc_card_blockaddr(card)) 387 if (mmc_card_blockaddr(card))
388 card->ext_csd.enhanced_area_offset <<= 9; 388 card->ext_csd.enhanced_area_offset <<= 9;
389 /* 389 /*
390 * calculate the enhanced data area size, in kilobytes 390 * calculate the enhanced data area size, in kilobytes
391 */ 391 */
392 card->ext_csd.enhanced_area_size = 392 card->ext_csd.enhanced_area_size =
393 (ext_csd[142] << 16) + (ext_csd[141] << 8) + 393 (ext_csd[142] << 16) + (ext_csd[141] << 8) +
394 ext_csd[140]; 394 ext_csd[140];
395 card->ext_csd.enhanced_area_size *= 395 card->ext_csd.enhanced_area_size *=
396 (size_t)(hc_erase_grp_sz * hc_wp_grp_sz); 396 (size_t)(hc_erase_grp_sz * hc_wp_grp_sz);
397 card->ext_csd.enhanced_area_size <<= 9; 397 card->ext_csd.enhanced_area_size <<= 9;
398 } else { 398 } else {
399 /* 399 /*
400 * If the enhanced area is not enabled, disable these 400 * If the enhanced area is not enabled, disable these
401 * device attributes. 401 * device attributes.
402 */ 402 */
403 card->ext_csd.enhanced_area_offset = -EINVAL; 403 card->ext_csd.enhanced_area_offset = -EINVAL;
404 card->ext_csd.enhanced_area_size = -EINVAL; 404 card->ext_csd.enhanced_area_size = -EINVAL;
405 } 405 }
406 406
407 /* 407 /*
408 * General purpose partition feature support -- 408 * General purpose partition feature support --
409 * If ext_csd has the size of general purpose partitions, 409 * If ext_csd has the size of general purpose partitions,
410 * set size, part_cfg, partition name in mmc_part. 410 * set size, part_cfg, partition name in mmc_part.
411 */ 411 */
412 if (ext_csd[EXT_CSD_PARTITION_SUPPORT] & 412 if (ext_csd[EXT_CSD_PARTITION_SUPPORT] &
413 EXT_CSD_PART_SUPPORT_PART_EN) { 413 EXT_CSD_PART_SUPPORT_PART_EN) {
414 if (card->ext_csd.enhanced_area_en != 1) { 414 if (card->ext_csd.enhanced_area_en != 1) {
415 hc_erase_grp_sz = 415 hc_erase_grp_sz =
416 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; 416 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
417 hc_wp_grp_sz = 417 hc_wp_grp_sz =
418 ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; 418 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
419 419
420 card->ext_csd.enhanced_area_en = 1; 420 card->ext_csd.enhanced_area_en = 1;
421 } 421 }
422 422
423 for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) { 423 for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) {
424 if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] && 424 if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] &&
425 !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] && 425 !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] &&
426 !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]) 426 !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2])
427 continue; 427 continue;
428 part_size = 428 part_size =
429 (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2] 429 (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]
430 << 16) + 430 << 16) +
431 (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] 431 (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1]
432 << 8) + 432 << 8) +
433 ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3]; 433 ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
434 part_size *= (size_t)(hc_erase_grp_sz * 434 part_size *= (size_t)(hc_erase_grp_sz *
435 hc_wp_grp_sz); 435 hc_wp_grp_sz);
436 mmc_part_add(card, part_size << 19, 436 mmc_part_add(card, part_size << 19,
437 EXT_CSD_PART_CONFIG_ACC_GP0 + idx, 437 EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
438 "gp%d", idx, false); 438 "gp%d", idx, false);
439 } 439 }
440 } 440 }
441 card->ext_csd.sec_trim_mult = 441 card->ext_csd.sec_trim_mult =
442 ext_csd[EXT_CSD_SEC_TRIM_MULT]; 442 ext_csd[EXT_CSD_SEC_TRIM_MULT];
443 card->ext_csd.sec_erase_mult = 443 card->ext_csd.sec_erase_mult =
444 ext_csd[EXT_CSD_SEC_ERASE_MULT]; 444 ext_csd[EXT_CSD_SEC_ERASE_MULT];
445 card->ext_csd.sec_feature_support = 445 card->ext_csd.sec_feature_support =
446 ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; 446 ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT];
447 card->ext_csd.trim_timeout = 300 * 447 card->ext_csd.trim_timeout = 300 *
448 ext_csd[EXT_CSD_TRIM_MULT]; 448 ext_csd[EXT_CSD_TRIM_MULT];
449 } 449 }
450 450
451 if (card->ext_csd.rev >= 5) { 451 if (card->ext_csd.rev >= 5) {
452 /* check whether the eMMC card supports HPI */ 452 /* check whether the eMMC card supports HPI */
453 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) { 453 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) {
454 card->ext_csd.hpi = 1; 454 card->ext_csd.hpi = 1;
455 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2) 455 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2)
456 card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; 456 card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION;
457 else 457 else
458 card->ext_csd.hpi_cmd = MMC_SEND_STATUS; 458 card->ext_csd.hpi_cmd = MMC_SEND_STATUS;
459 /* 459 /*
460 * Indicate the maximum timeout to close 460 * Indicate the maximum timeout to close
461 * a command interrupted by HPI 461 * a command interrupted by HPI
462 */ 462 */
463 card->ext_csd.out_of_int_time = 463 card->ext_csd.out_of_int_time =
464 ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] * 10; 464 ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] * 10;
465 } 465 }
466 466
467 card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; 467 card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM];
468 card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION]; 468 card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION];
469 } 469 }
470 470
471 card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT]; 471 card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT];
472 if (ext_csd[EXT_CSD_ERASED_MEM_CONT]) 472 if (ext_csd[EXT_CSD_ERASED_MEM_CONT])
473 card->erased_byte = 0xFF; 473 card->erased_byte = 0xFF;
474 else 474 else
475 card->erased_byte = 0x0; 475 card->erased_byte = 0x0;
476 476
477 /* eMMC v4.5 or later */ 477 /* eMMC v4.5 or later */
478 if (card->ext_csd.rev >= 6) { 478 if (card->ext_csd.rev >= 6) {
479 card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; 479 card->ext_csd.feature_support |= MMC_DISCARD_FEATURE;
480 480
481 card->ext_csd.generic_cmd6_time = 10 * 481 card->ext_csd.generic_cmd6_time = 10 *
482 ext_csd[EXT_CSD_GENERIC_CMD6_TIME]; 482 ext_csd[EXT_CSD_GENERIC_CMD6_TIME];
483 card->ext_csd.power_off_longtime = 10 * 483 card->ext_csd.power_off_longtime = 10 *
484 ext_csd[EXT_CSD_POWER_OFF_LONG_TIME]; 484 ext_csd[EXT_CSD_POWER_OFF_LONG_TIME];
485 485
486 card->ext_csd.cache_size = 486 card->ext_csd.cache_size =
487 ext_csd[EXT_CSD_CACHE_SIZE + 0] << 0 | 487 ext_csd[EXT_CSD_CACHE_SIZE + 0] << 0 |
488 ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8 | 488 ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8 |
489 ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16 | 489 ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16 |
490 ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24; 490 ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24;
491 } 491 }
492 492
493 out: 493 out:
494 return err; 494 return err;
495 } 495 }
496 496
497 static inline void mmc_free_ext_csd(u8 *ext_csd) 497 static inline void mmc_free_ext_csd(u8 *ext_csd)
498 { 498 {
499 kfree(ext_csd); 499 kfree(ext_csd);
500 } 500 }
501 501
502 502
503 static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) 503 static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width)
504 { 504 {
505 u8 *bw_ext_csd; 505 u8 *bw_ext_csd;
506 int err; 506 int err;
507 507
508 if (bus_width == MMC_BUS_WIDTH_1) 508 if (bus_width == MMC_BUS_WIDTH_1)
509 return 0; 509 return 0;
510 510
511 err = mmc_get_ext_csd(card, &bw_ext_csd); 511 err = mmc_get_ext_csd(card, &bw_ext_csd);
512 512
513 if (err || bw_ext_csd == NULL) { 513 if (err || bw_ext_csd == NULL) {
514 if (bus_width != MMC_BUS_WIDTH_1) 514 if (bus_width != MMC_BUS_WIDTH_1)
515 err = -EINVAL; 515 err = -EINVAL;
516 goto out; 516 goto out;
517 } 517 }
518 518
519 if (bus_width == MMC_BUS_WIDTH_1) 519 if (bus_width == MMC_BUS_WIDTH_1)
520 goto out; 520 goto out;
521 521
522 /* only compare read only fields */ 522 /* only compare read only fields */
523 err = (!(card->ext_csd.raw_partition_support == 523 err = (!(card->ext_csd.raw_partition_support ==
524 bw_ext_csd[EXT_CSD_PARTITION_SUPPORT]) && 524 bw_ext_csd[EXT_CSD_PARTITION_SUPPORT]) &&
525 (card->ext_csd.raw_erased_mem_count == 525 (card->ext_csd.raw_erased_mem_count ==
526 bw_ext_csd[EXT_CSD_ERASED_MEM_CONT]) && 526 bw_ext_csd[EXT_CSD_ERASED_MEM_CONT]) &&
527 (card->ext_csd.rev == 527 (card->ext_csd.rev ==
528 bw_ext_csd[EXT_CSD_REV]) && 528 bw_ext_csd[EXT_CSD_REV]) &&
529 (card->ext_csd.raw_ext_csd_structure == 529 (card->ext_csd.raw_ext_csd_structure ==
530 bw_ext_csd[EXT_CSD_STRUCTURE]) && 530 bw_ext_csd[EXT_CSD_STRUCTURE]) &&
531 (card->ext_csd.raw_card_type == 531 (card->ext_csd.raw_card_type ==
532 bw_ext_csd[EXT_CSD_CARD_TYPE]) && 532 bw_ext_csd[EXT_CSD_CARD_TYPE]) &&
533 (card->ext_csd.raw_s_a_timeout == 533 (card->ext_csd.raw_s_a_timeout ==
534 bw_ext_csd[EXT_CSD_S_A_TIMEOUT]) && 534 bw_ext_csd[EXT_CSD_S_A_TIMEOUT]) &&
535 (card->ext_csd.raw_hc_erase_gap_size == 535 (card->ext_csd.raw_hc_erase_gap_size ==
536 bw_ext_csd[EXT_CSD_HC_WP_GRP_SIZE]) && 536 bw_ext_csd[EXT_CSD_HC_WP_GRP_SIZE]) &&
537 (card->ext_csd.raw_erase_timeout_mult == 537 (card->ext_csd.raw_erase_timeout_mult ==
538 bw_ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]) && 538 bw_ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]) &&
539 (card->ext_csd.raw_hc_erase_grp_size == 539 (card->ext_csd.raw_hc_erase_grp_size ==
540 bw_ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]) && 540 bw_ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]) &&
541 (card->ext_csd.raw_sec_trim_mult == 541 (card->ext_csd.raw_sec_trim_mult ==
542 bw_ext_csd[EXT_CSD_SEC_TRIM_MULT]) && 542 bw_ext_csd[EXT_CSD_SEC_TRIM_MULT]) &&
543 (card->ext_csd.raw_sec_erase_mult == 543 (card->ext_csd.raw_sec_erase_mult ==
544 bw_ext_csd[EXT_CSD_SEC_ERASE_MULT]) && 544 bw_ext_csd[EXT_CSD_SEC_ERASE_MULT]) &&
545 (card->ext_csd.raw_sec_feature_support == 545 (card->ext_csd.raw_sec_feature_support ==
546 bw_ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]) && 546 bw_ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]) &&
547 (card->ext_csd.raw_trim_mult == 547 (card->ext_csd.raw_trim_mult ==
548 bw_ext_csd[EXT_CSD_TRIM_MULT]) && 548 bw_ext_csd[EXT_CSD_TRIM_MULT]) &&
549 (card->ext_csd.raw_sectors[0] == 549 (card->ext_csd.raw_sectors[0] ==
550 bw_ext_csd[EXT_CSD_SEC_CNT + 0]) && 550 bw_ext_csd[EXT_CSD_SEC_CNT + 0]) &&
551 (card->ext_csd.raw_sectors[1] == 551 (card->ext_csd.raw_sectors[1] ==
552 bw_ext_csd[EXT_CSD_SEC_CNT + 1]) && 552 bw_ext_csd[EXT_CSD_SEC_CNT + 1]) &&
553 (card->ext_csd.raw_sectors[2] == 553 (card->ext_csd.raw_sectors[2] ==
554 bw_ext_csd[EXT_CSD_SEC_CNT + 2]) && 554 bw_ext_csd[EXT_CSD_SEC_CNT + 2]) &&
555 (card->ext_csd.raw_sectors[3] == 555 (card->ext_csd.raw_sectors[3] ==
556 bw_ext_csd[EXT_CSD_SEC_CNT + 3])); 556 bw_ext_csd[EXT_CSD_SEC_CNT + 3]));
557 if (err) 557 if (err)
558 err = -EINVAL; 558 err = -EINVAL;
559 559
560 out: 560 out:
561 mmc_free_ext_csd(bw_ext_csd); 561 mmc_free_ext_csd(bw_ext_csd);
562 return err; 562 return err;
563 } 563 }
564 564
565 MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1], 565 MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
566 card->raw_cid[2], card->raw_cid[3]); 566 card->raw_cid[2], card->raw_cid[3]);
567 MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1], 567 MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
568 card->raw_csd[2], card->raw_csd[3]); 568 card->raw_csd[2], card->raw_csd[3]);
569 MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); 569 MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
570 MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9); 570 MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
571 MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9); 571 MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
572 MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); 572 MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
573 MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); 573 MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
574 MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); 574 MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
575 MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name); 575 MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
576 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid); 576 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
577 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial); 577 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
578 MMC_DEV_ATTR(enhanced_area_offset, "%llu\n", 578 MMC_DEV_ATTR(enhanced_area_offset, "%llu\n",
579 card->ext_csd.enhanced_area_offset); 579 card->ext_csd.enhanced_area_offset);
580 MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size); 580 MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size);
581 581
582 static struct attribute *mmc_std_attrs[] = { 582 static struct attribute *mmc_std_attrs[] = {
583 &dev_attr_cid.attr, 583 &dev_attr_cid.attr,
584 &dev_attr_csd.attr, 584 &dev_attr_csd.attr,
585 &dev_attr_date.attr, 585 &dev_attr_date.attr,
586 &dev_attr_erase_size.attr, 586 &dev_attr_erase_size.attr,
587 &dev_attr_preferred_erase_size.attr, 587 &dev_attr_preferred_erase_size.attr,
588 &dev_attr_fwrev.attr, 588 &dev_attr_fwrev.attr,
589 &dev_attr_hwrev.attr, 589 &dev_attr_hwrev.attr,
590 &dev_attr_manfid.attr, 590 &dev_attr_manfid.attr,
591 &dev_attr_name.attr, 591 &dev_attr_name.attr,
592 &dev_attr_oemid.attr, 592 &dev_attr_oemid.attr,
593 &dev_attr_serial.attr, 593 &dev_attr_serial.attr,
594 &dev_attr_enhanced_area_offset.attr, 594 &dev_attr_enhanced_area_offset.attr,
595 &dev_attr_enhanced_area_size.attr, 595 &dev_attr_enhanced_area_size.attr,
596 NULL, 596 NULL,
597 }; 597 };
598 598
599 static struct attribute_group mmc_std_attr_group = { 599 static struct attribute_group mmc_std_attr_group = {
600 .attrs = mmc_std_attrs, 600 .attrs = mmc_std_attrs,
601 }; 601 };
602 602
603 static const struct attribute_group *mmc_attr_groups[] = { 603 static const struct attribute_group *mmc_attr_groups[] = {
604 &mmc_std_attr_group, 604 &mmc_std_attr_group,
605 NULL, 605 NULL,
606 }; 606 };
607 607
608 static struct device_type mmc_type = { 608 static struct device_type mmc_type = {
609 .groups = mmc_attr_groups, 609 .groups = mmc_attr_groups,
610 }; 610 };
611 611
612 /* 612 /*
613 * Select the PowerClass for the current bus width 613 * Select the PowerClass for the current bus width
614 * If power class is defined for 4/8 bit bus in the 614 * If power class is defined for 4/8 bit bus in the
615 * extended CSD register, select it by executing the 615 * extended CSD register, select it by executing the
616 * mmc_switch command. 616 * mmc_switch command.
617 */ 617 */
618 static int mmc_select_powerclass(struct mmc_card *card, 618 static int mmc_select_powerclass(struct mmc_card *card,
619 unsigned int bus_width, u8 *ext_csd) 619 unsigned int bus_width, u8 *ext_csd)
620 { 620 {
621 int err = 0; 621 int err = 0;
622 unsigned int pwrclass_val; 622 unsigned int pwrclass_val;
623 unsigned int index = 0; 623 unsigned int index = 0;
624 struct mmc_host *host; 624 struct mmc_host *host;
625 625
626 BUG_ON(!card); 626 BUG_ON(!card);
627 627
628 host = card->host; 628 host = card->host;
629 BUG_ON(!host); 629 BUG_ON(!host);
630 630
631 if (ext_csd == NULL) 631 if (ext_csd == NULL)
632 return 0; 632 return 0;
633 633
634 /* Power class selection is supported for versions >= 4.0 */ 634 /* Power class selection is supported for versions >= 4.0 */
635 if (card->csd.mmca_vsn < CSD_SPEC_VER_4) 635 if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
636 return 0; 636 return 0;
637 637
638 /* Power class values are defined only for 4/8 bit bus */ 638 /* Power class values are defined only for 4/8 bit bus */
639 if (bus_width == EXT_CSD_BUS_WIDTH_1) 639 if (bus_width == EXT_CSD_BUS_WIDTH_1)
640 return 0; 640 return 0;
641 641
642 switch (1 << host->ios.vdd) { 642 switch (1 << host->ios.vdd) {
643 case MMC_VDD_165_195: 643 case MMC_VDD_165_195:
644 if (host->ios.clock <= 26000000) 644 if (host->ios.clock <= 26000000)
645 index = EXT_CSD_PWR_CL_26_195; 645 index = EXT_CSD_PWR_CL_26_195;
646 else if (host->ios.clock <= 52000000) 646 else if (host->ios.clock <= 52000000)
647 index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? 647 index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ?
648 EXT_CSD_PWR_CL_52_195 : 648 EXT_CSD_PWR_CL_52_195 :
649 EXT_CSD_PWR_CL_DDR_52_195; 649 EXT_CSD_PWR_CL_DDR_52_195;
650 else if (host->ios.clock <= 200000000) 650 else if (host->ios.clock <= 200000000)
651 index = EXT_CSD_PWR_CL_200_195; 651 index = EXT_CSD_PWR_CL_200_195;
652 break; 652 break;
653 case MMC_VDD_32_33: 653 case MMC_VDD_32_33:
654 case MMC_VDD_33_34: 654 case MMC_VDD_33_34:
655 case MMC_VDD_34_35: 655 case MMC_VDD_34_35:
656 case MMC_VDD_35_36: 656 case MMC_VDD_35_36:
657 if (host->ios.clock <= 26000000) 657 if (host->ios.clock <= 26000000)
658 index = EXT_CSD_PWR_CL_26_360; 658 index = EXT_CSD_PWR_CL_26_360;
659 else if (host->ios.clock <= 52000000) 659 else if (host->ios.clock <= 52000000)
660 index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? 660 index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ?
661 EXT_CSD_PWR_CL_52_360 : 661 EXT_CSD_PWR_CL_52_360 :
662 EXT_CSD_PWR_CL_DDR_52_360; 662 EXT_CSD_PWR_CL_DDR_52_360;
663 else if (host->ios.clock <= 200000000) 663 else if (host->ios.clock <= 200000000)
664 index = EXT_CSD_PWR_CL_200_360; 664 index = EXT_CSD_PWR_CL_200_360;
665 break; 665 break;
666 default: 666 default:
667 pr_warning("%s: Voltage range not supported " 667 pr_warning("%s: Voltage range not supported "
668 "for power class.\n", mmc_hostname(host)); 668 "for power class.\n", mmc_hostname(host));
669 return -EINVAL; 669 return -EINVAL;
670 } 670 }
671 671
672 pwrclass_val = ext_csd[index]; 672 pwrclass_val = ext_csd[index];
673 673
674 if (bus_width & (EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_BUS_WIDTH_8)) 674 if (bus_width & (EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_BUS_WIDTH_8))
675 pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_8BIT_MASK) >> 675 pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_8BIT_MASK) >>
676 EXT_CSD_PWR_CL_8BIT_SHIFT; 676 EXT_CSD_PWR_CL_8BIT_SHIFT;
677 else 677 else
678 pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_4BIT_MASK) >> 678 pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_4BIT_MASK) >>
679 EXT_CSD_PWR_CL_4BIT_SHIFT; 679 EXT_CSD_PWR_CL_4BIT_SHIFT;
680 680
681 /* If the power class is different from the default value */ 681 /* If the power class is different from the default value */
682 if (pwrclass_val > 0) { 682 if (pwrclass_val > 0) {
683 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 683 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
684 EXT_CSD_POWER_CLASS, 684 EXT_CSD_POWER_CLASS,
685 pwrclass_val, 685 pwrclass_val,
686 card->ext_csd.generic_cmd6_time); 686 card->ext_csd.generic_cmd6_time);
687 } 687 }
688 688
689 return err; 689 return err;
690 } 690 }
691 691
692 /* 692 /*
693 * Handle the detection and initialisation of a card. 693 * Handle the detection and initialisation of a card.
694 * 694 *
695 * In the case of a resume, "oldcard" will contain the card 695 * In the case of a resume, "oldcard" will contain the card
696 * we're trying to reinitialise. 696 * we're trying to reinitialise.
697 */ 697 */
698 static int mmc_init_card(struct mmc_host *host, u32 ocr, 698 static int mmc_init_card(struct mmc_host *host, u32 ocr,
699 struct mmc_card *oldcard) 699 struct mmc_card *oldcard)
700 { 700 {
701 struct mmc_card *card; 701 struct mmc_card *card;
702 int err, ddr = 0; 702 int err, ddr = 0;
703 u32 cid[4]; 703 u32 cid[4];
704 unsigned int max_dtr; 704 unsigned int max_dtr;
705 u32 rocr; 705 u32 rocr;
706 u8 *ext_csd = NULL; 706 u8 *ext_csd = NULL;
707 707
708 BUG_ON(!host); 708 BUG_ON(!host);
709 WARN_ON(!host->claimed); 709 WARN_ON(!host->claimed);
710 710
711 /* Set correct bus mode for MMC before attempting init */ 711 /* Set correct bus mode for MMC before attempting init */
712 if (!mmc_host_is_spi(host)) 712 if (!mmc_host_is_spi(host))
713 mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); 713 mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN);
714 714
715 /* 715 /*
716 * Since we're changing the OCR value, we seem to 716 * Since we're changing the OCR value, we seem to
717 * need to tell some cards to go back to the idle 717 * need to tell some cards to go back to the idle
718 * state. We wait 1ms to give cards time to 718 * state. We wait 1ms to give cards time to
719 * respond. 719 * respond.
720 * mmc_go_idle is needed for eMMC that are asleep 720 * mmc_go_idle is needed for eMMC that are asleep
721 */ 721 */
722 mmc_go_idle(host); 722 mmc_go_idle(host);
723 723
724 /* The extra bit indicates that we support high capacity */ 724 /* The extra bit indicates that we support high capacity */
725 err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr); 725 err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr);
726 if (err) 726 if (err)
727 goto err; 727 goto err;
728 728
729 /* 729 /*
730 * For SPI, enable CRC as appropriate. 730 * For SPI, enable CRC as appropriate.
731 */ 731 */
732 if (mmc_host_is_spi(host)) { 732 if (mmc_host_is_spi(host)) {
733 err = mmc_spi_set_crc(host, use_spi_crc); 733 err = mmc_spi_set_crc(host, use_spi_crc);
734 if (err) 734 if (err)
735 goto err; 735 goto err;
736 } 736 }
737 737
738 /* 738 /*
739 * Fetch CID from card. 739 * Fetch CID from card.
740 */ 740 */
741 if (mmc_host_is_spi(host)) 741 if (mmc_host_is_spi(host))
742 err = mmc_send_cid(host, cid); 742 err = mmc_send_cid(host, cid);
743 else 743 else
744 err = mmc_all_send_cid(host, cid); 744 err = mmc_all_send_cid(host, cid);
745 if (err) 745 if (err)
746 goto err; 746 goto err;
747 747
748 if (oldcard) { 748 if (oldcard) {
749 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { 749 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) {
750 err = -ENOENT; 750 err = -ENOENT;
751 goto err; 751 goto err;
752 } 752 }
753 753
754 card = oldcard; 754 card = oldcard;
755 } else { 755 } else {
756 /* 756 /*
757 * Allocate card structure. 757 * Allocate card structure.
758 */ 758 */
759 card = mmc_alloc_card(host, &mmc_type); 759 card = mmc_alloc_card(host, &mmc_type);
760 if (IS_ERR(card)) { 760 if (IS_ERR(card)) {
761 err = PTR_ERR(card); 761 err = PTR_ERR(card);
762 goto err; 762 goto err;
763 } 763 }
764 764
765 card->type = MMC_TYPE_MMC; 765 card->type = MMC_TYPE_MMC;
766 card->rca = 1; 766 card->rca = 1;
767 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); 767 memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
768 } 768 }
769 769
770 /* 770 /*
771 * For native busses: set card RCA and quit open drain mode. 771 * For native busses: set card RCA and quit open drain mode.
772 */ 772 */
773 if (!mmc_host_is_spi(host)) { 773 if (!mmc_host_is_spi(host)) {
774 err = mmc_set_relative_addr(card); 774 err = mmc_set_relative_addr(card);
775 if (err) 775 if (err)
776 goto free_card; 776 goto free_card;
777 777
778 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); 778 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
779 } 779 }
780 780
781 if (!oldcard) { 781 if (!oldcard) {
782 /* 782 /*
783 * Fetch CSD from card. 783 * Fetch CSD from card.
784 */ 784 */
785 err = mmc_send_csd(card, card->raw_csd); 785 err = mmc_send_csd(card, card->raw_csd);
786 if (err) 786 if (err)
787 goto free_card; 787 goto free_card;
788 788
789 err = mmc_decode_csd(card); 789 err = mmc_decode_csd(card);
790 if (err) 790 if (err)
791 goto free_card; 791 goto free_card;
792 err = mmc_decode_cid(card); 792 err = mmc_decode_cid(card);
793 if (err) 793 if (err)
794 goto free_card; 794 goto free_card;
795 } 795 }
796 796
797 /* 797 /*
798 * Select card, as all following commands rely on that. 798 * Select card, as all following commands rely on that.
799 */ 799 */
800 if (!mmc_host_is_spi(host)) { 800 if (!mmc_host_is_spi(host)) {
801 err = mmc_select_card(card); 801 err = mmc_select_card(card);
802 if (err) 802 if (err)
803 goto free_card; 803 goto free_card;
804 } 804 }
805 805
806 if (!oldcard) { 806 if (!oldcard) {
807 /* 807 /*
808 * Fetch and process extended CSD. 808 * Fetch and process extended CSD.
809 */ 809 */
810 810
811 err = mmc_get_ext_csd(card, &ext_csd); 811 err = mmc_get_ext_csd(card, &ext_csd);
812 if (err) 812 if (err)
813 goto free_card; 813 goto free_card;
814 err = mmc_read_ext_csd(card, ext_csd); 814 err = mmc_read_ext_csd(card, ext_csd);
815 if (err) 815 if (err)
816 goto free_card; 816 goto free_card;
817 817
818 /* If doing byte addressing, check if required to do sector 818 /* If doing byte addressing, check if required to do sector
819 * addressing. Handle the case of <2GB cards needing sector 819 * addressing. Handle the case of <2GB cards needing sector
820 * addressing. See section 8.1 JEDEC Standard JED84-A441; 820 * addressing. See section 8.1 JEDEC Standard JED84-A441;
821 * ocr register has bit 30 set for sector addressing. 821 * ocr register has bit 30 set for sector addressing.
822 */ 822 */
823 if (!(mmc_card_blockaddr(card)) && (rocr & (1<<30))) 823 if (!(mmc_card_blockaddr(card)) && (rocr & (1<<30)))
824 mmc_card_set_blockaddr(card); 824 mmc_card_set_blockaddr(card);
825 825
826 /* Erase size depends on CSD and Extended CSD */ 826 /* Erase size depends on CSD and Extended CSD */
827 mmc_set_erase_size(card); 827 mmc_set_erase_size(card);
828 } 828 }
829 829
830 /* 830 /*
831 * If enhanced_area_en is TRUE, host needs to enable ERASE_GRP_DEF 831 * If enhanced_area_en is TRUE, host needs to enable ERASE_GRP_DEF
832 * bit. This bit will be lost every time after a reset or power off. 832 * bit. This bit will be lost every time after a reset or power off.
833 */ 833 */
834 if (card->ext_csd.enhanced_area_en) { 834 if (card->ext_csd.enhanced_area_en) {
835 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 835 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
836 EXT_CSD_ERASE_GROUP_DEF, 1, 836 EXT_CSD_ERASE_GROUP_DEF, 1,
837 card->ext_csd.generic_cmd6_time); 837 card->ext_csd.generic_cmd6_time);
838 838
839 if (err && err != -EBADMSG) 839 if (err && err != -EBADMSG)
840 goto free_card; 840 goto free_card;
841 841
842 if (err) { 842 if (err) {
843 err = 0; 843 err = 0;
844 /* 844 /*
845 * Just disable enhanced area off & sz 845 * Just disable enhanced area off & sz
846 * will try to enable ERASE_GROUP_DEF 846 * will try to enable ERASE_GROUP_DEF
847 * during next time reinit 847 * during next time reinit
848 */ 848 */
849 card->ext_csd.enhanced_area_offset = -EINVAL; 849 card->ext_csd.enhanced_area_offset = -EINVAL;
850 card->ext_csd.enhanced_area_size = -EINVAL; 850 card->ext_csd.enhanced_area_size = -EINVAL;
851 } else { 851 } else {
852 card->ext_csd.erase_group_def = 1; 852 card->ext_csd.erase_group_def = 1;
853 /* 853 /*
854 * enable ERASE_GRP_DEF successfully. 854 * enable ERASE_GRP_DEF successfully.
855 * This will affect the erase size, so 855 * This will affect the erase size, so
856 * here need to reset erase size 856 * here need to reset erase size
857 */ 857 */
858 mmc_set_erase_size(card); 858 mmc_set_erase_size(card);
859 } 859 }
860 } 860 }
861 861
862 /* 862 /*
863 * Ensure eMMC user default partition is enabled 863 * Ensure eMMC user default partition is enabled
864 */ 864 */
865 if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { 865 if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) {
866 card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; 866 card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK;
867 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, 867 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG,
868 card->ext_csd.part_config, 868 card->ext_csd.part_config,
869 card->ext_csd.part_time); 869 card->ext_csd.part_time);
870 if (err && err != -EBADMSG) 870 if (err && err != -EBADMSG)
871 goto free_card; 871 goto free_card;
872 } 872 }
873 873
874 /* 874 /*
875 * If the host supports the power_off_notify capability then 875 * If the host supports the power_off_notify capability then
876 * set the notification byte in the ext_csd register of device 876 * set the notification byte in the ext_csd register of device
877 */ 877 */
878 if ((host->caps2 & MMC_CAP2_POWEROFF_NOTIFY) && 878 if ((host->caps2 & MMC_CAP2_POWEROFF_NOTIFY) &&
879 (card->ext_csd.rev >= 6)) { 879 (card->ext_csd.rev >= 6)) {
880 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 880 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
881 EXT_CSD_POWER_OFF_NOTIFICATION, 881 EXT_CSD_POWER_OFF_NOTIFICATION,
882 EXT_CSD_POWER_ON, 882 EXT_CSD_POWER_ON,
883 card->ext_csd.generic_cmd6_time); 883 card->ext_csd.generic_cmd6_time);
884 if (err && err != -EBADMSG) 884 if (err && err != -EBADMSG)
885 goto free_card; 885 goto free_card;
886 886
887 /* 887 /*
888 * The err can be -EBADMSG or 0, 888 * The err can be -EBADMSG or 0,
889 * so check for success and update the flag 889 * so check for success and update the flag
890 */ 890 */
891 if (!err) 891 if (!err)
892 card->poweroff_notify_state = MMC_POWERED_ON; 892 card->poweroff_notify_state = MMC_POWERED_ON;
893 } 893 }
894 894
895 /* 895 /*
896 * Activate high speed (if supported) 896 * Activate high speed (if supported)
897 */ 897 */
898 if ((card->ext_csd.hs_max_dtr != 0) && 898 if ((card->ext_csd.hs_max_dtr != 0) &&
899 (host->caps & MMC_CAP_MMC_HIGHSPEED)) { 899 (host->caps & MMC_CAP_MMC_HIGHSPEED)) {
900 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 900 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
901 EXT_CSD_HS_TIMING, 1, 901 EXT_CSD_HS_TIMING, 1,
902 card->ext_csd.generic_cmd6_time); 902 card->ext_csd.generic_cmd6_time);
903 if (err && err != -EBADMSG) 903 if (err && err != -EBADMSG)
904 goto free_card; 904 goto free_card;
905 905
906 if (err) { 906 if (err) {
907 pr_warning("%s: switch to highspeed failed\n", 907 pr_warning("%s: switch to highspeed failed\n",
908 mmc_hostname(card->host)); 908 mmc_hostname(card->host));
909 err = 0; 909 err = 0;
910 } else { 910 } else {
911 mmc_card_set_highspeed(card); 911 mmc_card_set_highspeed(card);
912 mmc_set_timing(card->host, MMC_TIMING_MMC_HS); 912 mmc_set_timing(card->host, MMC_TIMING_MMC_HS);
913 } 913 }
914 } 914 }
915 915
916 /* 916 /*
917 * Enable HPI feature (if supported) 917 * Enable HPI feature (if supported)
918 */ 918 */
919 if (card->ext_csd.hpi) { 919 if (card->ext_csd.hpi) {
920 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 920 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
921 EXT_CSD_HPI_MGMT, 1, 0); 921 EXT_CSD_HPI_MGMT, 1, 0);
922 if (err && err != -EBADMSG) 922 if (err && err != -EBADMSG)
923 goto free_card; 923 goto free_card;
924 if (err) { 924 if (err) {
925 pr_warning("%s: Enabling HPI failed\n", 925 pr_warning("%s: Enabling HPI failed\n",
926 mmc_hostname(card->host)); 926 mmc_hostname(card->host));
927 err = 0; 927 err = 0;
928 } else 928 } else
929 card->ext_csd.hpi_en = 1; 929 card->ext_csd.hpi_en = 1;
930 } 930 }
931 931
932 /* 932 /*
933 * Compute bus speed. 933 * Compute bus speed.
934 */ 934 */
935 max_dtr = (unsigned int)-1; 935 max_dtr = (unsigned int)-1;
936 936
937 if (mmc_card_highspeed(card)) { 937 if (mmc_card_highspeed(card)) {
938 if (max_dtr > card->ext_csd.hs_max_dtr) 938 if (max_dtr > card->ext_csd.hs_max_dtr)
939 max_dtr = card->ext_csd.hs_max_dtr; 939 max_dtr = card->ext_csd.hs_max_dtr;
940 } else if (max_dtr > card->csd.max_dtr) { 940 } else if (max_dtr > card->csd.max_dtr) {
941 max_dtr = card->csd.max_dtr; 941 max_dtr = card->csd.max_dtr;
942 } 942 }
943 943
944 mmc_set_clock(host, max_dtr); 944 mmc_set_clock(host, max_dtr);
945 945
946 /* 946 /*
947 * Indicate DDR mode (if supported). 947 * Indicate DDR mode (if supported).
948 */ 948 */
949 if (mmc_card_highspeed(card)) { 949 if (mmc_card_highspeed(card)) {
950 if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) 950 if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_8V)
951 && ((host->caps & (MMC_CAP_1_8V_DDR | 951 && ((host->caps & (MMC_CAP_1_8V_DDR |
952 MMC_CAP_UHS_DDR50)) 952 MMC_CAP_UHS_DDR50))
953 == (MMC_CAP_1_8V_DDR | MMC_CAP_UHS_DDR50))) 953 == (MMC_CAP_1_8V_DDR | MMC_CAP_UHS_DDR50)))
954 ddr = MMC_1_8V_DDR_MODE; 954 ddr = MMC_1_8V_DDR_MODE;
955 else if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_2V) 955 else if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_2V)
956 && ((host->caps & (MMC_CAP_1_2V_DDR | 956 && ((host->caps & (MMC_CAP_1_2V_DDR |
957 MMC_CAP_UHS_DDR50)) 957 MMC_CAP_UHS_DDR50))
958 == (MMC_CAP_1_2V_DDR | MMC_CAP_UHS_DDR50))) 958 == (MMC_CAP_1_2V_DDR | MMC_CAP_UHS_DDR50)))
959 ddr = MMC_1_2V_DDR_MODE; 959 ddr = MMC_1_2V_DDR_MODE;
960 } 960 }
961 961
962 /* 962 /*
963 * Activate wide bus and DDR (if supported). 963 * Activate wide bus and DDR (if supported).
964 */ 964 */
965 if ((card->csd.mmca_vsn >= CSD_SPEC_VER_4) && 965 if ((card->csd.mmca_vsn >= CSD_SPEC_VER_4) &&
966 (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) { 966 (host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) {
967 static unsigned ext_csd_bits[][2] = { 967 static unsigned ext_csd_bits[][2] = {
968 { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 }, 968 { EXT_CSD_BUS_WIDTH_8, EXT_CSD_DDR_BUS_WIDTH_8 },
969 { EXT_CSD_BUS_WIDTH_4, EXT_CSD_DDR_BUS_WIDTH_4 }, 969 { EXT_CSD_BUS_WIDTH_4, EXT_CSD_DDR_BUS_WIDTH_4 },
970 { EXT_CSD_BUS_WIDTH_1, EXT_CSD_BUS_WIDTH_1 }, 970 { EXT_CSD_BUS_WIDTH_1, EXT_CSD_BUS_WIDTH_1 },
971 }; 971 };
972 static unsigned bus_widths[] = { 972 static unsigned bus_widths[] = {
973 MMC_BUS_WIDTH_8, 973 MMC_BUS_WIDTH_8,
974 MMC_BUS_WIDTH_4, 974 MMC_BUS_WIDTH_4,
975 MMC_BUS_WIDTH_1 975 MMC_BUS_WIDTH_1
976 }; 976 };
977 unsigned idx, bus_width = 0; 977 unsigned idx, bus_width = 0;
978 978
979 if (host->caps & MMC_CAP_8_BIT_DATA) 979 if (host->caps & MMC_CAP_8_BIT_DATA)
980 idx = 0; 980 idx = 0;
981 else 981 else
982 idx = 1; 982 idx = 1;
983 for (; idx < ARRAY_SIZE(bus_widths); idx++) { 983 for (; idx < ARRAY_SIZE(bus_widths); idx++) {
984 bus_width = bus_widths[idx]; 984 bus_width = bus_widths[idx];
985 if (bus_width == MMC_BUS_WIDTH_1) 985 if (bus_width == MMC_BUS_WIDTH_1)
986 ddr = 0; /* no DDR for 1-bit width */ 986 ddr = 0; /* no DDR for 1-bit width */
987 err = mmc_select_powerclass(card, ext_csd_bits[idx][0], 987 err = mmc_select_powerclass(card, ext_csd_bits[idx][0],
988 ext_csd); 988 ext_csd);
989 if (err) 989 if (err)
990 pr_err("%s: power class selection to " 990 pr_err("%s: power class selection to "
991 "bus width %d failed\n", 991 "bus width %d failed\n",
992 mmc_hostname(card->host), 992 mmc_hostname(card->host),
993 1 << bus_width); 993 1 << bus_width);
994 994
995 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 995 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
996 EXT_CSD_BUS_WIDTH, 996 EXT_CSD_BUS_WIDTH,
997 ext_csd_bits[idx][0], 997 ext_csd_bits[idx][0],
998 card->ext_csd.generic_cmd6_time); 998 card->ext_csd.generic_cmd6_time);
999 if (!err) { 999 if (!err) {
1000 mmc_set_bus_width(card->host, bus_width); 1000 mmc_set_bus_width(card->host, bus_width);
1001 1001
1002 /* 1002 /*
1003 * If controller can't handle bus width test, 1003 * If controller can't handle bus width test,
1004 * compare ext_csd previously read in 1 bit mode 1004 * compare ext_csd previously read in 1 bit mode
1005 * against ext_csd at new bus width 1005 * against ext_csd at new bus width
1006 */ 1006 */
1007 if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) 1007 if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST))
1008 err = mmc_compare_ext_csds(card, 1008 err = mmc_compare_ext_csds(card,
1009 bus_width); 1009 bus_width);
1010 else 1010 else
1011 err = mmc_bus_test(card, bus_width); 1011 err = mmc_bus_test(card, bus_width);
1012 if (!err) 1012 if (!err)
1013 break; 1013 break;
1014 } 1014 }
1015 } 1015 }
1016 1016
1017 if (!err && ddr) { 1017 if (!err && ddr) {
1018 err = mmc_select_powerclass(card, ext_csd_bits[idx][1], 1018 err = mmc_select_powerclass(card, ext_csd_bits[idx][1],
1019 ext_csd); 1019 ext_csd);
1020 if (err) 1020 if (err)
1021 pr_err("%s: power class selection to " 1021 pr_err("%s: power class selection to "
1022 "bus width %d ddr %d failed\n", 1022 "bus width %d ddr %d failed\n",
1023 mmc_hostname(card->host), 1023 mmc_hostname(card->host),
1024 1 << bus_width, ddr); 1024 1 << bus_width, ddr);
1025 1025
1026 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1026 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1027 EXT_CSD_BUS_WIDTH, 1027 EXT_CSD_BUS_WIDTH,
1028 ext_csd_bits[idx][1], 1028 ext_csd_bits[idx][1],
1029 card->ext_csd.generic_cmd6_time); 1029 card->ext_csd.generic_cmd6_time);
1030 } 1030 }
1031 if (err) { 1031 if (err) {
1032 pr_warning("%s: switch to bus width %d ddr %d " 1032 pr_warning("%s: switch to bus width %d ddr %d "
1033 "failed\n", mmc_hostname(card->host), 1033 "failed\n", mmc_hostname(card->host),
1034 1 << bus_width, ddr); 1034 1 << bus_width, ddr);
1035 goto free_card; 1035 goto free_card;
1036 } else if (ddr) { 1036 } else if (ddr) {
1037 /* 1037 /*
1038 * eMMC cards can support 3.3V to 1.2V i/o (vccq) 1038 * eMMC cards can support 3.3V to 1.2V i/o (vccq)
1039 * signaling. 1039 * signaling.
1040 * 1040 *
1041 * EXT_CSD_CARD_TYPE_DDR_1_8V means 3.3V or 1.8V vccq. 1041 * EXT_CSD_CARD_TYPE_DDR_1_8V means 3.3V or 1.8V vccq.
1042 * 1042 *
1043 * 1.8V vccq at 3.3V core voltage (vcc) is not required 1043 * 1.8V vccq at 3.3V core voltage (vcc) is not required
1044 * in the JEDEC spec for DDR. 1044 * in the JEDEC spec for DDR.
1045 * 1045 *
1046 * Do not force change in vccq since we are obviously 1046 * Do not force change in vccq since we are obviously
1047 * working and no change to vccq is needed. 1047 * working and no change to vccq is needed.
1048 * 1048 *
1049 * WARNING: eMMC rules are NOT the same as SD DDR 1049 * WARNING: eMMC rules are NOT the same as SD DDR
1050 */ 1050 */
1051 if (ddr == EXT_CSD_CARD_TYPE_DDR_1_2V) { 1051 if (ddr == EXT_CSD_CARD_TYPE_DDR_1_2V) {
1052 err = mmc_set_signal_voltage(host, 1052 err = mmc_set_signal_voltage(host,
1053 MMC_SIGNAL_VOLTAGE_120, 0); 1053 MMC_SIGNAL_VOLTAGE_120, 0);
1054 if (err) 1054 if (err)
1055 goto err; 1055 goto err;
1056 } 1056 }
1057 mmc_card_set_ddr_mode(card); 1057 mmc_card_set_ddr_mode(card);
1058 mmc_set_timing(card->host, MMC_TIMING_UHS_DDR50); 1058 mmc_set_timing(card->host, MMC_TIMING_UHS_DDR50);
1059 mmc_set_bus_width(card->host, bus_width); 1059 mmc_set_bus_width(card->host, bus_width);
1060 } 1060 }
1061 } 1061 }
1062 1062
1063 /* 1063 /*
1064 * If cache size is higher than 0, this indicates 1064 * If cache size is higher than 0, this indicates
1065 * the existence of cache and it can be turned on. 1065 * the existence of cache and it can be turned on.
1066 */ 1066 */
1067 if ((host->caps2 & MMC_CAP2_CACHE_CTRL) && 1067 if ((host->caps2 & MMC_CAP2_CACHE_CTRL) &&
1068 card->ext_csd.cache_size > 0) { 1068 card->ext_csd.cache_size > 0) {
1069 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1069 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1070 EXT_CSD_CACHE_CTRL, 1, 0); 1070 EXT_CSD_CACHE_CTRL, 1, 0);
1071 if (err && err != -EBADMSG) 1071 if (err && err != -EBADMSG)
1072 goto free_card; 1072 goto free_card;
1073 1073
1074 /* 1074 /*
1075 * Only if no error, cache is turned on successfully. 1075 * Only if no error, cache is turned on successfully.
1076 */ 1076 */
1077 card->ext_csd.cache_ctrl = err ? 0 : 1; 1077 card->ext_csd.cache_ctrl = err ? 0 : 1;
1078 } 1078 }
1079 1079
1080 if (!oldcard) 1080 if (!oldcard)
1081 host->card = card; 1081 host->card = card;
1082 1082
1083 mmc_free_ext_csd(ext_csd); 1083 mmc_free_ext_csd(ext_csd);
1084 return 0; 1084 return 0;
1085 1085
1086 free_card: 1086 free_card:
1087 if (!oldcard) 1087 if (!oldcard)
1088 mmc_remove_card(card); 1088 mmc_remove_card(card);
1089 err: 1089 err:
1090 mmc_free_ext_csd(ext_csd); 1090 mmc_free_ext_csd(ext_csd);
1091 1091
1092 return err; 1092 return err;
1093 } 1093 }
1094 1094
1095 /* 1095 /*
1096 * Host is being removed. Free up the current card. 1096 * Host is being removed. Free up the current card.
1097 */ 1097 */
1098 static void mmc_remove(struct mmc_host *host) 1098 static void mmc_remove(struct mmc_host *host)
1099 { 1099 {
1100 BUG_ON(!host); 1100 BUG_ON(!host);
1101 BUG_ON(!host->card); 1101 BUG_ON(!host->card);
1102 1102
1103 mmc_remove_card(host->card); 1103 mmc_remove_card(host->card);
1104 host->card = NULL; 1104 host->card = NULL;
1105 } 1105 }
1106 1106
1107 /* 1107 /*
1108 * Card detection - card is alive. 1108 * Card detection - card is alive.
1109 */ 1109 */
1110 static int mmc_alive(struct mmc_host *host) 1110 static int mmc_alive(struct mmc_host *host)
1111 { 1111 {
1112 return mmc_send_status(host->card, NULL); 1112 return mmc_send_status(host->card, NULL);
1113 } 1113 }
1114 1114
1115 /* 1115 /*
1116 * Card detection callback from host. 1116 * Card detection callback from host.
1117 */ 1117 */
1118 static void mmc_detect(struct mmc_host *host) 1118 static void mmc_detect(struct mmc_host *host)
1119 { 1119 {
1120 int err; 1120 int err;
1121 1121
1122 BUG_ON(!host); 1122 BUG_ON(!host);
1123 BUG_ON(!host->card); 1123 BUG_ON(!host->card);
1124 1124
1125 mmc_claim_host(host); 1125 mmc_claim_host(host);
1126 1126
1127 /* 1127 /*
1128 * Just check if our card has been removed. 1128 * Just check if our card has been removed.
1129 */ 1129 */
1130 err = _mmc_detect_card_removed(host); 1130 err = _mmc_detect_card_removed(host);
1131 1131
1132 mmc_release_host(host); 1132 mmc_release_host(host);
1133 1133
1134 if (err) { 1134 if (err) {
1135 mmc_remove(host); 1135 mmc_remove(host);
1136 1136
1137 mmc_claim_host(host); 1137 mmc_claim_host(host);
1138 mmc_detach_bus(host); 1138 mmc_detach_bus(host);
1139 mmc_power_off(host); 1139 mmc_power_off(host);
1140 mmc_release_host(host); 1140 mmc_release_host(host);
1141 } 1141 }
1142 } 1142 }
1143 1143
1144 /* 1144 /*
1145 * Suspend callback from host. 1145 * Suspend callback from host.
1146 */ 1146 */
1147 static int mmc_suspend(struct mmc_host *host) 1147 static int mmc_suspend(struct mmc_host *host)
1148 { 1148 {
1149 int err = 0; 1149 int err = 0;
1150 1150
1151 BUG_ON(!host); 1151 BUG_ON(!host);
1152 BUG_ON(!host->card); 1152 BUG_ON(!host->card);
1153 1153
1154 mmc_claim_host(host); 1154 mmc_claim_host(host);
1155 if (mmc_card_can_sleep(host)) 1155 if (mmc_card_can_sleep(host))
1156 err = mmc_card_sleep(host); 1156 err = mmc_card_sleep(host);
1157 else if (!mmc_host_is_spi(host)) 1157 else if (!mmc_host_is_spi(host))
1158 mmc_deselect_cards(host); 1158 mmc_deselect_cards(host);
1159 host->card->state &= ~MMC_STATE_HIGHSPEED; 1159 host->card->state &= ~MMC_STATE_HIGHSPEED;
1160 mmc_release_host(host); 1160 mmc_release_host(host);
1161 1161
1162 return err; 1162 return err;
1163 } 1163 }
1164 1164
1165 /* 1165 /*
1166 * Resume callback from host. 1166 * Resume callback from host.
1167 * 1167 *
1168 * This function tries to determine if the same card is still present 1168 * This function tries to determine if the same card is still present
1169 * and, if so, restore all state to it. 1169 * and, if so, restore all state to it.
1170 */ 1170 */
1171 static int mmc_resume(struct mmc_host *host) 1171 static int mmc_resume(struct mmc_host *host)
1172 { 1172 {
1173 int err; 1173 int err;
1174 1174
1175 BUG_ON(!host); 1175 BUG_ON(!host);
1176 BUG_ON(!host->card); 1176 BUG_ON(!host->card);
1177 1177
1178 mmc_claim_host(host); 1178 mmc_claim_host(host);
1179 err = mmc_init_card(host, host->ocr, host->card); 1179 err = mmc_init_card(host, host->ocr, host->card);
1180 mmc_release_host(host); 1180 mmc_release_host(host);
1181 1181
1182 return err; 1182 return err;
1183 } 1183 }
1184 1184
1185 static int mmc_power_restore(struct mmc_host *host) 1185 static int mmc_power_restore(struct mmc_host *host)
1186 { 1186 {
1187 int ret; 1187 int ret;
1188 1188
1189 host->card->state &= ~MMC_STATE_HIGHSPEED; 1189 host->card->state &= ~MMC_STATE_HIGHSPEED;
1190 mmc_claim_host(host); 1190 mmc_claim_host(host);
1191 ret = mmc_init_card(host, host->ocr, host->card); 1191 ret = mmc_init_card(host, host->ocr, host->card);
1192 mmc_release_host(host); 1192 mmc_release_host(host);
1193 1193
1194 return ret; 1194 return ret;
1195 } 1195 }
1196 1196
1197 static int mmc_sleep(struct mmc_host *host) 1197 static int mmc_sleep(struct mmc_host *host)
1198 { 1198 {
1199 struct mmc_card *card = host->card; 1199 struct mmc_card *card = host->card;
1200 int err = -ENOSYS; 1200 int err = -ENOSYS;
1201 1201
1202 if (card && card->ext_csd.rev >= 3) { 1202 if (card && card->ext_csd.rev >= 3) {
1203 err = mmc_card_sleepawake(host, 1); 1203 err = mmc_card_sleepawake(host, 1);
1204 if (err < 0) 1204 if (err < 0)
1205 pr_debug("%s: Error %d while putting card into sleep", 1205 pr_debug("%s: Error %d while putting card into sleep",
1206 mmc_hostname(host), err); 1206 mmc_hostname(host), err);
1207 } 1207 }
1208 1208
1209 return err; 1209 return err;
1210 } 1210 }
1211 1211
1212 static int mmc_awake(struct mmc_host *host) 1212 static int mmc_awake(struct mmc_host *host)
1213 { 1213 {
1214 struct mmc_card *card = host->card; 1214 struct mmc_card *card = host->card;
1215 int err = -ENOSYS; 1215 int err = -ENOSYS;
1216 1216
1217 if (card && card->ext_csd.rev >= 3) { 1217 if (card && card->ext_csd.rev >= 3) {
1218 err = mmc_card_sleepawake(host, 0); 1218 err = mmc_card_sleepawake(host, 0);
1219 if (err < 0) 1219 if (err < 0)
1220 pr_debug("%s: Error %d while awaking sleeping card", 1220 pr_debug("%s: Error %d while awaking sleeping card",
1221 mmc_hostname(host), err); 1221 mmc_hostname(host), err);
1222 } 1222 }
1223 1223
1224 return err; 1224 return err;
1225 } 1225 }
1226 1226
1227 static const struct mmc_bus_ops mmc_ops = { 1227 static const struct mmc_bus_ops mmc_ops = {
1228 .awake = mmc_awake, 1228 .awake = mmc_awake,
1229 .sleep = mmc_sleep, 1229 .sleep = mmc_sleep,
1230 .remove = mmc_remove, 1230 .remove = mmc_remove,
1231 .detect = mmc_detect, 1231 .detect = mmc_detect,
1232 .suspend = NULL, 1232 .suspend = NULL,
1233 .resume = NULL, 1233 .resume = NULL,
1234 .power_restore = mmc_power_restore, 1234 .power_restore = mmc_power_restore,
1235 .alive = mmc_alive, 1235 .alive = mmc_alive,
1236 }; 1236 };
1237 1237
1238 static const struct mmc_bus_ops mmc_ops_unsafe = { 1238 static const struct mmc_bus_ops mmc_ops_unsafe = {
1239 .awake = mmc_awake, 1239 .awake = mmc_awake,
1240 .sleep = mmc_sleep, 1240 .sleep = mmc_sleep,
1241 .remove = mmc_remove, 1241 .remove = mmc_remove,
1242 .detect = mmc_detect, 1242 .detect = mmc_detect,
1243 .suspend = mmc_suspend, 1243 .suspend = mmc_suspend,
1244 .resume = mmc_resume, 1244 .resume = mmc_resume,
1245 .power_restore = mmc_power_restore, 1245 .power_restore = mmc_power_restore,
1246 .alive = mmc_alive, 1246 .alive = mmc_alive,
1247 }; 1247 };
1248 1248
1249 static void mmc_attach_bus_ops(struct mmc_host *host) 1249 static void mmc_attach_bus_ops(struct mmc_host *host)
1250 { 1250 {
1251 const struct mmc_bus_ops *bus_ops; 1251 const struct mmc_bus_ops *bus_ops;
1252 1252
1253 if (!mmc_card_is_removable(host)) 1253 if (!mmc_card_is_removable(host))
1254 bus_ops = &mmc_ops_unsafe; 1254 bus_ops = &mmc_ops_unsafe;
1255 else 1255 else
1256 bus_ops = &mmc_ops; 1256 bus_ops = &mmc_ops;
1257 mmc_attach_bus(host, bus_ops); 1257 mmc_attach_bus(host, bus_ops);
1258 } 1258 }
1259 1259
1260 /* 1260 /*
1261 * Starting point for MMC card init. 1261 * Starting point for MMC card init.
1262 */ 1262 */
1263 int mmc_attach_mmc(struct mmc_host *host) 1263 int mmc_attach_mmc(struct mmc_host *host)
1264 { 1264 {
1265 int err; 1265 int err;
1266 u32 ocr; 1266 u32 ocr;
1267 1267
1268 BUG_ON(!host); 1268 BUG_ON(!host);
1269 WARN_ON(!host->claimed); 1269 WARN_ON(!host->claimed);
1270 1270
1271 /* Set correct bus mode for MMC before attempting attach */ 1271 /* Set correct bus mode for MMC before attempting attach */
1272 if (!mmc_host_is_spi(host)) 1272 if (!mmc_host_is_spi(host))
1273 mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); 1273 mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN);
1274 1274
1275 err = mmc_send_op_cond(host, 0, &ocr); 1275 err = mmc_send_op_cond(host, 0, &ocr);
1276 if (err) 1276 if (err)
1277 return err; 1277 return err;
1278 1278
1279 mmc_attach_bus_ops(host); 1279 mmc_attach_bus_ops(host);
1280 if (host->ocr_avail_mmc) 1280 if (host->ocr_avail_mmc)
1281 host->ocr_avail = host->ocr_avail_mmc; 1281 host->ocr_avail = host->ocr_avail_mmc;
1282 1282
1283 /* 1283 /*
1284 * We need to get OCR a different way for SPI. 1284 * We need to get OCR a different way for SPI.
1285 */ 1285 */
1286 if (mmc_host_is_spi(host)) { 1286 if (mmc_host_is_spi(host)) {
1287 err = mmc_spi_read_ocr(host, 1, &ocr); 1287 err = mmc_spi_read_ocr(host, 1, &ocr);
1288 if (err) 1288 if (err)
1289 goto err; 1289 goto err;
1290 } 1290 }
1291 1291
1292 /* 1292 /*
1293 * Sanity check the voltages that the card claims to 1293 * Sanity check the voltages that the card claims to
1294 * support. 1294 * support.
1295 */ 1295 */
1296 if (ocr & 0x7F) { 1296 if (ocr & 0x7F) {
1297 pr_warning("%s: card claims to support voltages " 1297 pr_warning("%s: card claims to support voltages "
1298 "below the defined range. These will be ignored.\n", 1298 "below the defined range. These will be ignored.\n",
1299 mmc_hostname(host)); 1299 mmc_hostname(host));
1300 ocr &= ~0x7F; 1300 ocr &= ~0x7F;
1301 } 1301 }
1302 1302
1303 host->ocr = mmc_select_voltage(host, ocr); 1303 host->ocr = mmc_select_voltage(host, ocr);
1304 1304
1305 /* 1305 /*
1306 * Can we support the voltage of the card? 1306 * Can we support the voltage of the card?
1307 */ 1307 */
1308 if (!host->ocr) { 1308 if (!host->ocr) {
1309 err = -EINVAL; 1309 err = -EINVAL;
1310 goto err; 1310 goto err;
1311 } 1311 }
1312 1312
1313 /* 1313 /*
1314 * Detect and init the card. 1314 * Detect and init the card.
1315 */ 1315 */
1316 err = mmc_init_card(host, host->ocr, NULL); 1316 err = mmc_init_card(host, host->ocr, NULL);
1317 if (err) 1317 if (err)
1318 goto err; 1318 goto err;
1319 1319
1320 mmc_release_host(host); 1320 mmc_release_host(host);
1321 err = mmc_add_card(host->card); 1321 err = mmc_add_card(host->card);
1322 mmc_claim_host(host); 1322 mmc_claim_host(host);
1323 if (err) 1323 if (err)
1324 goto remove_card; 1324 goto remove_card;
1325 1325
1326 return 0; 1326 return 0;
1327 1327
1328 remove_card: 1328 remove_card:
1329 mmc_release_host(host); 1329 mmc_release_host(host);
1330 mmc_remove_card(host->card); 1330 mmc_remove_card(host->card);
1331 mmc_claim_host(host); 1331 mmc_claim_host(host);
1332 host->card = NULL; 1332 host->card = NULL;
1333 err: 1333 err:
1334 mmc_detach_bus(host); 1334 mmc_detach_bus(host);
1335 1335
1336 pr_err("%s: error %d whilst initialising MMC card\n", 1336 pr_err("%s: error %d whilst initialising MMC card\n",
1337 mmc_hostname(host), err); 1337 mmc_hostname(host), err);
1338 1338
1339 return err; 1339 return err;
1340 } 1340 }
1341 1341
drivers/net/wireless/rtlwifi/rtl8192cu/rf.c
1 /****************************************************************************** 1 /******************************************************************************
2 * 2 *
3 * Copyright(c) 2009-2010 Realtek Corporation. 3 * Copyright(c) 2009-2010 Realtek Corporation.
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as 6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT 9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details. 12 * more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License along with 14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 * 17 *
18 * The full GNU General Public License is included in this distribution in the 18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE. 19 * file called LICENSE.
20 * 20 *
21 * Contact Information: 21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com> 22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, 23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan. 24 * Hsinchu 300, Taiwan.
25 * 25 *
26 * Larry Finger <Larry.Finger@lwfinger.net> 26 * Larry Finger <Larry.Finger@lwfinger.net>
27 * 27 *
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30 #include "../wifi.h" 30 #include "../wifi.h"
31 #include "reg.h" 31 #include "reg.h"
32 #include "def.h" 32 #include "def.h"
33 #include "phy.h" 33 #include "phy.h"
34 #include "rf.h" 34 #include "rf.h"
35 #include "dm.h" 35 #include "dm.h"
36 36
37 static bool _rtl92c_phy_rf6052_config_parafile(struct ieee80211_hw *hw); 37 static bool _rtl92c_phy_rf6052_config_parafile(struct ieee80211_hw *hw);
38 38
39 void rtl92cu_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth) 39 void rtl92cu_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
40 { 40 {
41 struct rtl_priv *rtlpriv = rtl_priv(hw); 41 struct rtl_priv *rtlpriv = rtl_priv(hw);
42 struct rtl_phy *rtlphy = &(rtlpriv->phy); 42 struct rtl_phy *rtlphy = &(rtlpriv->phy);
43 43
44 switch (bandwidth) { 44 switch (bandwidth) {
45 case HT_CHANNEL_WIDTH_20: 45 case HT_CHANNEL_WIDTH_20:
46 rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] & 46 rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
47 0xfffff3ff) | 0x0400); 47 0xfffff3ff) | 0x0400);
48 rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK, 48 rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
49 rtlphy->rfreg_chnlval[0]); 49 rtlphy->rfreg_chnlval[0]);
50 break; 50 break;
51 case HT_CHANNEL_WIDTH_20_40: 51 case HT_CHANNEL_WIDTH_20_40:
52 rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] & 52 rtlphy->rfreg_chnlval[0] = ((rtlphy->rfreg_chnlval[0] &
53 0xfffff3ff)); 53 0xfffff3ff));
54 rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK, 54 rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
55 rtlphy->rfreg_chnlval[0]); 55 rtlphy->rfreg_chnlval[0]);
56 break; 56 break;
57 default: 57 default:
58 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 58 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
59 ("unknown bandwidth: %#X\n", bandwidth)); 59 ("unknown bandwidth: %#X\n", bandwidth));
60 break; 60 break;
61 } 61 }
62 } 62 }
63 63
64 void rtl92cu_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw, 64 void rtl92cu_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
65 u8 *ppowerlevel) 65 u8 *ppowerlevel)
66 { 66 {
67 struct rtl_priv *rtlpriv = rtl_priv(hw); 67 struct rtl_priv *rtlpriv = rtl_priv(hw);
68 struct rtl_phy *rtlphy = &(rtlpriv->phy); 68 struct rtl_phy *rtlphy = &(rtlpriv->phy);
69 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 69 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
70 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 70 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
71 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 71 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
72 u32 tx_agc[2] = { 0, 0 }, tmpval = 0; 72 u32 tx_agc[2] = { 0, 0 }, tmpval = 0;
73 bool turbo_scanoff = false; 73 bool turbo_scanoff = false;
74 u8 idx1, idx2; 74 u8 idx1, idx2;
75 u8 *ptr; 75 u8 *ptr;
76 76
77 if (rtlhal->interface == INTF_PCI) { 77 if (rtlhal->interface == INTF_PCI) {
78 if (rtlefuse->eeprom_regulatory != 0) 78 if (rtlefuse->eeprom_regulatory != 0)
79 turbo_scanoff = true; 79 turbo_scanoff = true;
80 } else { 80 } else {
81 if ((rtlefuse->eeprom_regulatory != 0) || 81 if ((rtlefuse->eeprom_regulatory != 0) ||
82 (rtlefuse->external_pa)) 82 (rtlefuse->external_pa))
83 turbo_scanoff = true; 83 turbo_scanoff = true;
84 } 84 }
85 if (mac->act_scanning) { 85 if (mac->act_scanning) {
86 tx_agc[RF90_PATH_A] = 0x3f3f3f3f; 86 tx_agc[RF90_PATH_A] = 0x3f3f3f3f;
87 tx_agc[RF90_PATH_B] = 0x3f3f3f3f; 87 tx_agc[RF90_PATH_B] = 0x3f3f3f3f;
88 if (turbo_scanoff) { 88 for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
89 for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) { 89 tx_agc[idx1] = ppowerlevel[idx1] |
90 tx_agc[idx1] = ppowerlevel[idx1] | 90 (ppowerlevel[idx1] << 8) |
91 (ppowerlevel[idx1] << 8) | 91 (ppowerlevel[idx1] << 16) |
92 (ppowerlevel[idx1] << 16) | 92 (ppowerlevel[idx1] << 24);
93 (ppowerlevel[idx1] << 24); 93 if (rtlhal->interface == INTF_USB) {
94 if (rtlhal->interface == INTF_USB) { 94 if (tx_agc[idx1] > 0x20 &&
95 if (tx_agc[idx1] > 0x20 && 95 rtlefuse->external_pa)
96 rtlefuse->external_pa) 96 tx_agc[idx1] = 0x20;
97 tx_agc[idx1] = 0x20;
98 }
99 } 97 }
100 } 98 }
101 } else { 99 } else {
102 if (rtlpriv->dm.dynamic_txhighpower_lvl == 100 if (rtlpriv->dm.dynamic_txhighpower_lvl ==
103 TXHIGHPWRLEVEL_LEVEL1) { 101 TXHIGHPWRLEVEL_LEVEL1) {
104 tx_agc[RF90_PATH_A] = 0x10101010; 102 tx_agc[RF90_PATH_A] = 0x10101010;
105 tx_agc[RF90_PATH_B] = 0x10101010; 103 tx_agc[RF90_PATH_B] = 0x10101010;
106 } else if (rtlpriv->dm.dynamic_txhighpower_lvl == 104 } else if (rtlpriv->dm.dynamic_txhighpower_lvl ==
107 TXHIGHPWRLEVEL_LEVEL1) { 105 TXHIGHPWRLEVEL_LEVEL1) {
108 tx_agc[RF90_PATH_A] = 0x00000000; 106 tx_agc[RF90_PATH_A] = 0x00000000;
109 tx_agc[RF90_PATH_B] = 0x00000000; 107 tx_agc[RF90_PATH_B] = 0x00000000;
110 } else{ 108 } else {
111 for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) { 109 for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
112 tx_agc[idx1] = ppowerlevel[idx1] | 110 tx_agc[idx1] = ppowerlevel[idx1] |
113 (ppowerlevel[idx1] << 8) | 111 (ppowerlevel[idx1] << 8) |
114 (ppowerlevel[idx1] << 16) | 112 (ppowerlevel[idx1] << 16) |
115 (ppowerlevel[idx1] << 24); 113 (ppowerlevel[idx1] << 24);
116 } 114 }
117 if (rtlefuse->eeprom_regulatory == 0) { 115 if (rtlefuse->eeprom_regulatory == 0) {
118 tmpval = (rtlphy->mcs_txpwrlevel_origoffset 116 tmpval = (rtlphy->mcs_txpwrlevel_origoffset
119 [0][6]) + 117 [0][6]) +
120 (rtlphy->mcs_txpwrlevel_origoffset 118 (rtlphy->mcs_txpwrlevel_origoffset
121 [0][7] << 8); 119 [0][7] << 8);
122 tx_agc[RF90_PATH_A] += tmpval; 120 tx_agc[RF90_PATH_A] += tmpval;
123 tmpval = (rtlphy->mcs_txpwrlevel_origoffset 121 tmpval = (rtlphy->mcs_txpwrlevel_origoffset
124 [0][14]) + 122 [0][14]) +
125 (rtlphy->mcs_txpwrlevel_origoffset 123 (rtlphy->mcs_txpwrlevel_origoffset
126 [0][15] << 24); 124 [0][15] << 24);
127 tx_agc[RF90_PATH_B] += tmpval; 125 tx_agc[RF90_PATH_B] += tmpval;
128 } 126 }
129 } 127 }
130 } 128 }
131 for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) { 129 for (idx1 = RF90_PATH_A; idx1 <= RF90_PATH_B; idx1++) {
132 ptr = (u8 *) (&(tx_agc[idx1])); 130 ptr = (u8 *) (&(tx_agc[idx1]));
133 for (idx2 = 0; idx2 < 4; idx2++) { 131 for (idx2 = 0; idx2 < 4; idx2++) {
134 if (*ptr > RF6052_MAX_TX_PWR) 132 if (*ptr > RF6052_MAX_TX_PWR)
135 *ptr = RF6052_MAX_TX_PWR; 133 *ptr = RF6052_MAX_TX_PWR;
136 ptr++; 134 ptr++;
137 } 135 }
138 } 136 }
139 tmpval = tx_agc[RF90_PATH_A] & 0xff; 137 tmpval = tx_agc[RF90_PATH_A] & 0xff;
140 rtl_set_bbreg(hw, RTXAGC_A_CCK1_MCS32, MASKBYTE1, tmpval); 138 rtl_set_bbreg(hw, RTXAGC_A_CCK1_MCS32, MASKBYTE1, tmpval);
141 139
142 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 140 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
143 ("CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval, 141 ("CCK PWR 1M (rf-A) = 0x%x (reg 0x%x)\n", tmpval,
144 RTXAGC_A_CCK1_MCS32)); 142 RTXAGC_A_CCK1_MCS32));
145 143
146 tmpval = tx_agc[RF90_PATH_A] >> 8; 144 tmpval = tx_agc[RF90_PATH_A] >> 8;
147 if (mac->mode == WIRELESS_MODE_B) 145 if (mac->mode == WIRELESS_MODE_B)
148 tmpval = tmpval & 0xff00ffff; 146 tmpval = tmpval & 0xff00ffff;
149 rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval); 147 rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval);
150 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 148 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
151 ("CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval, 149 ("CCK PWR 2~11M (rf-A) = 0x%x (reg 0x%x)\n", tmpval,
152 RTXAGC_B_CCK11_A_CCK2_11)); 150 RTXAGC_B_CCK11_A_CCK2_11));
153 tmpval = tx_agc[RF90_PATH_B] >> 24; 151 tmpval = tx_agc[RF90_PATH_B] >> 24;
154 rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, MASKBYTE0, tmpval); 152 rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, MASKBYTE0, tmpval);
155 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 153 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
156 ("CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval, 154 ("CCK PWR 11M (rf-B) = 0x%x (reg 0x%x)\n", tmpval,
157 RTXAGC_B_CCK11_A_CCK2_11)); 155 RTXAGC_B_CCK11_A_CCK2_11));
158 tmpval = tx_agc[RF90_PATH_B] & 0x00ffffff; 156 tmpval = tx_agc[RF90_PATH_B] & 0x00ffffff;
159 rtl_set_bbreg(hw, RTXAGC_B_CCK1_55_MCS32, 0xffffff00, tmpval); 157 rtl_set_bbreg(hw, RTXAGC_B_CCK1_55_MCS32, 0xffffff00, tmpval);
160 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 158 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
161 ("CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval, 159 ("CCK PWR 1~5.5M (rf-B) = 0x%x (reg 0x%x)\n", tmpval,
162 RTXAGC_B_CCK1_55_MCS32)); 160 RTXAGC_B_CCK1_55_MCS32));
163 } 161 }
164 162
165 static void rtl92c_phy_get_power_base(struct ieee80211_hw *hw, 163 static void rtl92c_phy_get_power_base(struct ieee80211_hw *hw,
166 u8 *ppowerlevel, u8 channel, 164 u8 *ppowerlevel, u8 channel,
167 u32 *ofdmbase, u32 *mcsbase) 165 u32 *ofdmbase, u32 *mcsbase)
168 { 166 {
169 struct rtl_priv *rtlpriv = rtl_priv(hw); 167 struct rtl_priv *rtlpriv = rtl_priv(hw);
170 struct rtl_phy *rtlphy = &(rtlpriv->phy); 168 struct rtl_phy *rtlphy = &(rtlpriv->phy);
171 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 169 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
172 u32 powerBase0, powerBase1; 170 u32 powerBase0, powerBase1;
173 u8 legacy_pwrdiff = 0, ht20_pwrdiff = 0; 171 u8 legacy_pwrdiff = 0, ht20_pwrdiff = 0;
174 u8 i, powerlevel[2]; 172 u8 i, powerlevel[2];
175 173
176 for (i = 0; i < 2; i++) { 174 for (i = 0; i < 2; i++) {
177 powerlevel[i] = ppowerlevel[i]; 175 powerlevel[i] = ppowerlevel[i];
178 legacy_pwrdiff = rtlefuse->txpwr_legacyhtdiff[i][channel - 1]; 176 legacy_pwrdiff = rtlefuse->txpwr_legacyhtdiff[i][channel - 1];
179 powerBase0 = powerlevel[i] + legacy_pwrdiff; 177 powerBase0 = powerlevel[i] + legacy_pwrdiff;
180 powerBase0 = (powerBase0 << 24) | (powerBase0 << 16) | 178 powerBase0 = (powerBase0 << 24) | (powerBase0 << 16) |
181 (powerBase0 << 8) | powerBase0; 179 (powerBase0 << 8) | powerBase0;
182 *(ofdmbase + i) = powerBase0; 180 *(ofdmbase + i) = powerBase0;
183 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 181 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
184 (" [OFDM power base index rf(%c) = 0x%x]\n", 182 (" [OFDM power base index rf(%c) = 0x%x]\n",
185 ((i == 0) ? 'A' : 'B'), *(ofdmbase + i))); 183 ((i == 0) ? 'A' : 'B'), *(ofdmbase + i)));
186 } 184 }
187 for (i = 0; i < 2; i++) { 185 for (i = 0; i < 2; i++) {
188 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20) { 186 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20) {
189 ht20_pwrdiff = rtlefuse->txpwr_ht20diff[i][channel - 1]; 187 ht20_pwrdiff = rtlefuse->txpwr_ht20diff[i][channel - 1];
190 powerlevel[i] += ht20_pwrdiff; 188 powerlevel[i] += ht20_pwrdiff;
191 } 189 }
192 powerBase1 = powerlevel[i]; 190 powerBase1 = powerlevel[i];
193 powerBase1 = (powerBase1 << 24) | 191 powerBase1 = (powerBase1 << 24) |
194 (powerBase1 << 16) | (powerBase1 << 8) | powerBase1; 192 (powerBase1 << 16) | (powerBase1 << 8) | powerBase1;
195 *(mcsbase + i) = powerBase1; 193 *(mcsbase + i) = powerBase1;
196 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 194 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
197 (" [MCS power base index rf(%c) = 0x%x]\n", 195 (" [MCS power base index rf(%c) = 0x%x]\n",
198 ((i == 0) ? 'A' : 'B'), *(mcsbase + i))); 196 ((i == 0) ? 'A' : 'B'), *(mcsbase + i)));
199 } 197 }
200 } 198 }
201 199
202 static void _rtl92c_get_txpower_writeval_by_regulatory(struct ieee80211_hw *hw, 200 static void _rtl92c_get_txpower_writeval_by_regulatory(struct ieee80211_hw *hw,
203 u8 channel, u8 index, 201 u8 channel, u8 index,
204 u32 *powerBase0, 202 u32 *powerBase0,
205 u32 *powerBase1, 203 u32 *powerBase1,
206 u32 *p_outwriteval) 204 u32 *p_outwriteval)
207 { 205 {
208 struct rtl_priv *rtlpriv = rtl_priv(hw); 206 struct rtl_priv *rtlpriv = rtl_priv(hw);
209 struct rtl_phy *rtlphy = &(rtlpriv->phy); 207 struct rtl_phy *rtlphy = &(rtlpriv->phy);
210 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 208 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
211 u8 i, chnlgroup = 0, pwr_diff_limit[4]; 209 u8 i, chnlgroup = 0, pwr_diff_limit[4];
212 u32 writeVal, customer_limit, rf; 210 u32 writeVal, customer_limit, rf;
213 211
214 for (rf = 0; rf < 2; rf++) { 212 for (rf = 0; rf < 2; rf++) {
215 switch (rtlefuse->eeprom_regulatory) { 213 switch (rtlefuse->eeprom_regulatory) {
216 case 0: 214 case 0:
217 chnlgroup = 0; 215 chnlgroup = 0;
218 writeVal = rtlphy->mcs_txpwrlevel_origoffset 216 writeVal = rtlphy->mcs_txpwrlevel_origoffset
219 [chnlgroup][index + (rf ? 8 : 0)] 217 [chnlgroup][index + (rf ? 8 : 0)]
220 + ((index < 2) ? powerBase0[rf] : powerBase1[rf]); 218 + ((index < 2) ? powerBase0[rf] : powerBase1[rf]);
221 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 219 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
222 ("RTK better performance,writeVal(%c) = 0x%x\n", 220 ("RTK better performance,writeVal(%c) = 0x%x\n",
223 ((rf == 0) ? 'A' : 'B'), writeVal)); 221 ((rf == 0) ? 'A' : 'B'), writeVal));
224 break; 222 break;
225 case 1: 223 case 1:
226 if (rtlphy->pwrgroup_cnt == 1) 224 if (rtlphy->pwrgroup_cnt == 1)
227 chnlgroup = 0; 225 chnlgroup = 0;
228 if (rtlphy->pwrgroup_cnt >= 3) { 226 if (rtlphy->pwrgroup_cnt >= 3) {
229 if (channel <= 3) 227 if (channel <= 3)
230 chnlgroup = 0; 228 chnlgroup = 0;
231 else if (channel >= 4 && channel <= 9) 229 else if (channel >= 4 && channel <= 9)
232 chnlgroup = 1; 230 chnlgroup = 1;
233 else if (channel > 9) 231 else if (channel > 9)
234 chnlgroup = 2; 232 chnlgroup = 2;
235 if (rtlphy->current_chan_bw == 233 if (rtlphy->current_chan_bw ==
236 HT_CHANNEL_WIDTH_20) 234 HT_CHANNEL_WIDTH_20)
237 chnlgroup++; 235 chnlgroup++;
238 else 236 else
239 chnlgroup += 4; 237 chnlgroup += 4;
240 } 238 }
241 writeVal = rtlphy->mcs_txpwrlevel_origoffset 239 writeVal = rtlphy->mcs_txpwrlevel_origoffset
242 [chnlgroup][index + 240 [chnlgroup][index +
243 (rf ? 8 : 0)] + 241 (rf ? 8 : 0)] +
244 ((index < 2) ? powerBase0[rf] : 242 ((index < 2) ? powerBase0[rf] :
245 powerBase1[rf]); 243 powerBase1[rf]);
246 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 244 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
247 ("Realtek regulatory, 20MHz, " 245 ("Realtek regulatory, 20MHz, "
248 "writeVal(%c) = 0x%x\n", 246 "writeVal(%c) = 0x%x\n",
249 ((rf == 0) ? 'A' : 'B'), writeVal)); 247 ((rf == 0) ? 'A' : 'B'), writeVal));
250 break; 248 break;
251 case 2: 249 case 2:
252 writeVal = ((index < 2) ? powerBase0[rf] : 250 writeVal = ((index < 2) ? powerBase0[rf] :
253 powerBase1[rf]); 251 powerBase1[rf]);
254 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 252 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
255 ("Better regulatory,writeVal(%c) = 0x%x\n", 253 ("Better regulatory,writeVal(%c) = 0x%x\n",
256 ((rf == 0) ? 'A' : 'B'), writeVal)); 254 ((rf == 0) ? 'A' : 'B'), writeVal));
257 break; 255 break;
258 case 3: 256 case 3:
259 chnlgroup = 0; 257 chnlgroup = 0;
260 if (rtlphy->current_chan_bw == 258 if (rtlphy->current_chan_bw ==
261 HT_CHANNEL_WIDTH_20_40) { 259 HT_CHANNEL_WIDTH_20_40) {
262 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 260 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
263 ("customer's limit, 40MHzrf(%c) = " 261 ("customer's limit, 40MHzrf(%c) = "
264 "0x%x\n", ((rf == 0) ? 'A' : 'B'), 262 "0x%x\n", ((rf == 0) ? 'A' : 'B'),
265 rtlefuse->pwrgroup_ht40[rf] 263 rtlefuse->pwrgroup_ht40[rf]
266 [channel - 1])); 264 [channel - 1]));
267 } else { 265 } else {
268 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 266 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
269 ("customer's limit, 20MHz rf(%c) = " 267 ("customer's limit, 20MHz rf(%c) = "
270 "0x%x\n", ((rf == 0) ? 'A' : 'B'), 268 "0x%x\n", ((rf == 0) ? 'A' : 'B'),
271 rtlefuse->pwrgroup_ht20[rf] 269 rtlefuse->pwrgroup_ht20[rf]
272 [channel - 1])); 270 [channel - 1]));
273 } 271 }
274 for (i = 0; i < 4; i++) { 272 for (i = 0; i < 4; i++) {
275 pwr_diff_limit[i] = 273 pwr_diff_limit[i] =
276 (u8) ((rtlphy->mcs_txpwrlevel_origoffset 274 (u8) ((rtlphy->mcs_txpwrlevel_origoffset
277 [chnlgroup][index + (rf ? 8 : 0)] 275 [chnlgroup][index + (rf ? 8 : 0)]
278 & (0x7f << (i * 8))) >> (i * 8)); 276 & (0x7f << (i * 8))) >> (i * 8));
279 if (rtlphy->current_chan_bw == 277 if (rtlphy->current_chan_bw ==
280 HT_CHANNEL_WIDTH_20_40) { 278 HT_CHANNEL_WIDTH_20_40) {
281 if (pwr_diff_limit[i] > 279 if (pwr_diff_limit[i] >
282 rtlefuse->pwrgroup_ht40[rf] 280 rtlefuse->pwrgroup_ht40[rf]
283 [channel - 1]) 281 [channel - 1])
284 pwr_diff_limit[i] = rtlefuse-> 282 pwr_diff_limit[i] = rtlefuse->
285 pwrgroup_ht40[rf] 283 pwrgroup_ht40[rf]
286 [channel - 1]; 284 [channel - 1];
287 } else { 285 } else {
288 if (pwr_diff_limit[i] > 286 if (pwr_diff_limit[i] >
289 rtlefuse->pwrgroup_ht20[rf] 287 rtlefuse->pwrgroup_ht20[rf]
290 [channel - 1]) 288 [channel - 1])
291 pwr_diff_limit[i] = 289 pwr_diff_limit[i] =
292 rtlefuse->pwrgroup_ht20[rf] 290 rtlefuse->pwrgroup_ht20[rf]
293 [channel - 1]; 291 [channel - 1];
294 } 292 }
295 } 293 }
296 customer_limit = (pwr_diff_limit[3] << 24) | 294 customer_limit = (pwr_diff_limit[3] << 24) |
297 (pwr_diff_limit[2] << 16) | 295 (pwr_diff_limit[2] << 16) |
298 (pwr_diff_limit[1] << 8) | (pwr_diff_limit[0]); 296 (pwr_diff_limit[1] << 8) | (pwr_diff_limit[0]);
299 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 297 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
300 ("Customer's limit rf(%c) = 0x%x\n", 298 ("Customer's limit rf(%c) = 0x%x\n",
301 ((rf == 0) ? 'A' : 'B'), customer_limit)); 299 ((rf == 0) ? 'A' : 'B'), customer_limit));
302 writeVal = customer_limit + ((index < 2) ? 300 writeVal = customer_limit + ((index < 2) ?
303 powerBase0[rf] : powerBase1[rf]); 301 powerBase0[rf] : powerBase1[rf]);
304 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 302 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
305 ("Customer, writeVal rf(%c)= 0x%x\n", 303 ("Customer, writeVal rf(%c)= 0x%x\n",
306 ((rf == 0) ? 'A' : 'B'), writeVal)); 304 ((rf == 0) ? 'A' : 'B'), writeVal));
307 break; 305 break;
308 default: 306 default:
309 chnlgroup = 0; 307 chnlgroup = 0;
310 writeVal = rtlphy->mcs_txpwrlevel_origoffset[chnlgroup] 308 writeVal = rtlphy->mcs_txpwrlevel_origoffset[chnlgroup]
311 [index + (rf ? 8 : 0)] + ((index < 2) ? 309 [index + (rf ? 8 : 0)] + ((index < 2) ?
312 powerBase0[rf] : powerBase1[rf]); 310 powerBase0[rf] : powerBase1[rf]);
313 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, ("RTK better " 311 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, ("RTK better "
314 "performance, writeValrf(%c) = 0x%x\n", 312 "performance, writeValrf(%c) = 0x%x\n",
315 ((rf == 0) ? 'A' : 'B'), writeVal)); 313 ((rf == 0) ? 'A' : 'B'), writeVal));
316 break; 314 break;
317 } 315 }
318 if (rtlpriv->dm.dynamic_txhighpower_lvl == 316 if (rtlpriv->dm.dynamic_txhighpower_lvl ==
319 TXHIGHPWRLEVEL_LEVEL1) 317 TXHIGHPWRLEVEL_LEVEL1)
320 writeVal = 0x14141414; 318 writeVal = 0x14141414;
321 else if (rtlpriv->dm.dynamic_txhighpower_lvl == 319 else if (rtlpriv->dm.dynamic_txhighpower_lvl ==
322 TXHIGHPWRLEVEL_LEVEL2) 320 TXHIGHPWRLEVEL_LEVEL2)
323 writeVal = 0x00000000; 321 writeVal = 0x00000000;
324 if (rtlpriv->dm.dynamic_txhighpower_lvl == TXHIGHPWRLEVEL_BT1) 322 if (rtlpriv->dm.dynamic_txhighpower_lvl == TXHIGHPWRLEVEL_BT1)
325 writeVal = writeVal - 0x06060606; 323 writeVal = writeVal - 0x06060606;
326 else if (rtlpriv->dm.dynamic_txhighpower_lvl == 324 else if (rtlpriv->dm.dynamic_txhighpower_lvl ==
327 TXHIGHPWRLEVEL_BT2) 325 TXHIGHPWRLEVEL_BT2)
328 writeVal = writeVal; 326 writeVal = writeVal;
329 *(p_outwriteval + rf) = writeVal; 327 *(p_outwriteval + rf) = writeVal;
330 } 328 }
331 } 329 }
332 330
333 static void _rtl92c_write_ofdm_power_reg(struct ieee80211_hw *hw, 331 static void _rtl92c_write_ofdm_power_reg(struct ieee80211_hw *hw,
334 u8 index, u32 *pValue) 332 u8 index, u32 *pValue)
335 { 333 {
336 struct rtl_priv *rtlpriv = rtl_priv(hw); 334 struct rtl_priv *rtlpriv = rtl_priv(hw);
337 struct rtl_phy *rtlphy = &(rtlpriv->phy); 335 struct rtl_phy *rtlphy = &(rtlpriv->phy);
338 u16 regoffset_a[6] = { 336 u16 regoffset_a[6] = {
339 RTXAGC_A_RATE18_06, RTXAGC_A_RATE54_24, 337 RTXAGC_A_RATE18_06, RTXAGC_A_RATE54_24,
340 RTXAGC_A_MCS03_MCS00, RTXAGC_A_MCS07_MCS04, 338 RTXAGC_A_MCS03_MCS00, RTXAGC_A_MCS07_MCS04,
341 RTXAGC_A_MCS11_MCS08, RTXAGC_A_MCS15_MCS12 339 RTXAGC_A_MCS11_MCS08, RTXAGC_A_MCS15_MCS12
342 }; 340 };
343 u16 regoffset_b[6] = { 341 u16 regoffset_b[6] = {
344 RTXAGC_B_RATE18_06, RTXAGC_B_RATE54_24, 342 RTXAGC_B_RATE18_06, RTXAGC_B_RATE54_24,
345 RTXAGC_B_MCS03_MCS00, RTXAGC_B_MCS07_MCS04, 343 RTXAGC_B_MCS03_MCS00, RTXAGC_B_MCS07_MCS04,
346 RTXAGC_B_MCS11_MCS08, RTXAGC_B_MCS15_MCS12 344 RTXAGC_B_MCS11_MCS08, RTXAGC_B_MCS15_MCS12
347 }; 345 };
348 u8 i, rf, pwr_val[4]; 346 u8 i, rf, pwr_val[4];
349 u32 writeVal; 347 u32 writeVal;
350 u16 regoffset; 348 u16 regoffset;
351 349
352 for (rf = 0; rf < 2; rf++) { 350 for (rf = 0; rf < 2; rf++) {
353 writeVal = pValue[rf]; 351 writeVal = pValue[rf];
354 for (i = 0; i < 4; i++) { 352 for (i = 0; i < 4; i++) {
355 pwr_val[i] = (u8)((writeVal & (0x7f << (i * 8))) >> 353 pwr_val[i] = (u8)((writeVal & (0x7f << (i * 8))) >>
356 (i * 8)); 354 (i * 8));
357 if (pwr_val[i] > RF6052_MAX_TX_PWR) 355 if (pwr_val[i] > RF6052_MAX_TX_PWR)
358 pwr_val[i] = RF6052_MAX_TX_PWR; 356 pwr_val[i] = RF6052_MAX_TX_PWR;
359 } 357 }
360 writeVal = (pwr_val[3] << 24) | (pwr_val[2] << 16) | 358 writeVal = (pwr_val[3] << 24) | (pwr_val[2] << 16) |
361 (pwr_val[1] << 8) | pwr_val[0]; 359 (pwr_val[1] << 8) | pwr_val[0];
362 if (rf == 0) 360 if (rf == 0)
363 regoffset = regoffset_a[index]; 361 regoffset = regoffset_a[index];
364 else 362 else
365 regoffset = regoffset_b[index]; 363 regoffset = regoffset_b[index];
366 rtl_set_bbreg(hw, regoffset, MASKDWORD, writeVal); 364 rtl_set_bbreg(hw, regoffset, MASKDWORD, writeVal);
367 RTPRINT(rtlpriv, FPHY, PHY_TXPWR, 365 RTPRINT(rtlpriv, FPHY, PHY_TXPWR,
368 ("Set 0x%x = %08x\n", regoffset, writeVal)); 366 ("Set 0x%x = %08x\n", regoffset, writeVal));
369 if (((get_rf_type(rtlphy) == RF_2T2R) && 367 if (((get_rf_type(rtlphy) == RF_2T2R) &&
370 (regoffset == RTXAGC_A_MCS15_MCS12 || 368 (regoffset == RTXAGC_A_MCS15_MCS12 ||
371 regoffset == RTXAGC_B_MCS15_MCS12)) || 369 regoffset == RTXAGC_B_MCS15_MCS12)) ||
372 ((get_rf_type(rtlphy) != RF_2T2R) && 370 ((get_rf_type(rtlphy) != RF_2T2R) &&
373 (regoffset == RTXAGC_A_MCS07_MCS04 || 371 (regoffset == RTXAGC_A_MCS07_MCS04 ||
374 regoffset == RTXAGC_B_MCS07_MCS04))) { 372 regoffset == RTXAGC_B_MCS07_MCS04))) {
375 writeVal = pwr_val[3]; 373 writeVal = pwr_val[3];
376 if (regoffset == RTXAGC_A_MCS15_MCS12 || 374 if (regoffset == RTXAGC_A_MCS15_MCS12 ||
377 regoffset == RTXAGC_A_MCS07_MCS04) 375 regoffset == RTXAGC_A_MCS07_MCS04)
378 regoffset = 0xc90; 376 regoffset = 0xc90;
379 if (regoffset == RTXAGC_B_MCS15_MCS12 || 377 if (regoffset == RTXAGC_B_MCS15_MCS12 ||
380 regoffset == RTXAGC_B_MCS07_MCS04) 378 regoffset == RTXAGC_B_MCS07_MCS04)
381 regoffset = 0xc98; 379 regoffset = 0xc98;
382 for (i = 0; i < 3; i++) { 380 for (i = 0; i < 3; i++) {
383 writeVal = (writeVal > 6) ? (writeVal - 6) : 0; 381 if (i != 2)
382 writeVal = (writeVal > 8) ?
383 (writeVal - 8) : 0;
384 else
385 writeVal = (writeVal > 6) ?
386 (writeVal - 6) : 0;
384 rtl_write_byte(rtlpriv, (u32)(regoffset + i), 387 rtl_write_byte(rtlpriv, (u32)(regoffset + i),
385 (u8)writeVal); 388 (u8)writeVal);
386 } 389 }
387 } 390 }
388 } 391 }
389 } 392 }
390 393
391 void rtl92cu_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw, 394 void rtl92cu_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw,
392 u8 *ppowerlevel, u8 channel) 395 u8 *ppowerlevel, u8 channel)
393 { 396 {
394 u32 writeVal[2], powerBase0[2], powerBase1[2]; 397 u32 writeVal[2], powerBase0[2], powerBase1[2];
395 u8 index = 0; 398 u8 index = 0;
396 399
397 rtl92c_phy_get_power_base(hw, ppowerlevel, 400 rtl92c_phy_get_power_base(hw, ppowerlevel,
398 channel, &powerBase0[0], &powerBase1[0]); 401 channel, &powerBase0[0], &powerBase1[0]);
399 for (index = 0; index < 6; index++) { 402 for (index = 0; index < 6; index++) {
400 _rtl92c_get_txpower_writeval_by_regulatory(hw, 403 _rtl92c_get_txpower_writeval_by_regulatory(hw,
401 channel, index, 404 channel, index,
402 &powerBase0[0], 405 &powerBase0[0],
403 &powerBase1[0], 406 &powerBase1[0],
404 &writeVal[0]); 407 &writeVal[0]);
405 _rtl92c_write_ofdm_power_reg(hw, index, &writeVal[0]); 408 _rtl92c_write_ofdm_power_reg(hw, index, &writeVal[0]);
406 } 409 }
407 } 410 }
408 411
409 bool rtl92cu_phy_rf6052_config(struct ieee80211_hw *hw) 412 bool rtl92cu_phy_rf6052_config(struct ieee80211_hw *hw)
410 { 413 {
411 struct rtl_priv *rtlpriv = rtl_priv(hw); 414 struct rtl_priv *rtlpriv = rtl_priv(hw);
412 struct rtl_phy *rtlphy = &(rtlpriv->phy); 415 struct rtl_phy *rtlphy = &(rtlpriv->phy);
413 bool rtstatus = true; 416 bool rtstatus = true;
414 u8 b_reg_hwparafile = 1; 417 u8 b_reg_hwparafile = 1;
415 418
416 if (rtlphy->rf_type == RF_1T1R) 419 if (rtlphy->rf_type == RF_1T1R)
417 rtlphy->num_total_rfpath = 1; 420 rtlphy->num_total_rfpath = 1;
418 else 421 else
419 rtlphy->num_total_rfpath = 2; 422 rtlphy->num_total_rfpath = 2;
420 if (b_reg_hwparafile == 1) 423 if (b_reg_hwparafile == 1)
421 rtstatus = _rtl92c_phy_rf6052_config_parafile(hw); 424 rtstatus = _rtl92c_phy_rf6052_config_parafile(hw);
422 return rtstatus; 425 return rtstatus;
423 } 426 }
424 427
425 static bool _rtl92c_phy_rf6052_config_parafile(struct ieee80211_hw *hw) 428 static bool _rtl92c_phy_rf6052_config_parafile(struct ieee80211_hw *hw)
426 { 429 {
427 struct rtl_priv *rtlpriv = rtl_priv(hw); 430 struct rtl_priv *rtlpriv = rtl_priv(hw);
428 struct rtl_phy *rtlphy = &(rtlpriv->phy); 431 struct rtl_phy *rtlphy = &(rtlpriv->phy);
429 u32 u4_regvalue = 0; 432 u32 u4_regvalue = 0;
430 u8 rfpath; 433 u8 rfpath;
431 bool rtstatus = true; 434 bool rtstatus = true;
432 struct bb_reg_def *pphyreg; 435 struct bb_reg_def *pphyreg;
433 436
434 for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) { 437 for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
435 pphyreg = &rtlphy->phyreg_def[rfpath]; 438 pphyreg = &rtlphy->phyreg_def[rfpath];
436 switch (rfpath) { 439 switch (rfpath) {
437 case RF90_PATH_A: 440 case RF90_PATH_A:
438 case RF90_PATH_C: 441 case RF90_PATH_C:
439 u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs, 442 u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
440 BRFSI_RFENV); 443 BRFSI_RFENV);
441 break; 444 break;
442 case RF90_PATH_B: 445 case RF90_PATH_B:
443 case RF90_PATH_D: 446 case RF90_PATH_D:
444 u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs, 447 u4_regvalue = rtl_get_bbreg(hw, pphyreg->rfintfs,
445 BRFSI_RFENV << 16); 448 BRFSI_RFENV << 16);
446 break; 449 break;
447 } 450 }
448 rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1); 451 rtl_set_bbreg(hw, pphyreg->rfintfe, BRFSI_RFENV << 16, 0x1);
449 udelay(1); 452 udelay(1);
450 rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1); 453 rtl_set_bbreg(hw, pphyreg->rfintfo, BRFSI_RFENV, 0x1);
451 udelay(1); 454 udelay(1);
452 rtl_set_bbreg(hw, pphyreg->rfhssi_para2, 455 rtl_set_bbreg(hw, pphyreg->rfhssi_para2,
453 B3WIREADDREAALENGTH, 0x0); 456 B3WIREADDREAALENGTH, 0x0);
454 udelay(1); 457 udelay(1);
455 rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0); 458 rtl_set_bbreg(hw, pphyreg->rfhssi_para2, B3WIREDATALENGTH, 0x0);
456 udelay(1); 459 udelay(1);
457 switch (rfpath) { 460 switch (rfpath) {
458 case RF90_PATH_A: 461 case RF90_PATH_A:
459 rtstatus = rtl92cu_phy_config_rf_with_headerfile(hw, 462 rtstatus = rtl92cu_phy_config_rf_with_headerfile(hw,
460 (enum radio_path) rfpath); 463 (enum radio_path) rfpath);
461 break; 464 break;
462 case RF90_PATH_B: 465 case RF90_PATH_B:
463 rtstatus = rtl92cu_phy_config_rf_with_headerfile(hw, 466 rtstatus = rtl92cu_phy_config_rf_with_headerfile(hw,
464 (enum radio_path) rfpath); 467 (enum radio_path) rfpath);
465 break; 468 break;
466 case RF90_PATH_C: 469 case RF90_PATH_C:
467 break; 470 break;
468 case RF90_PATH_D: 471 case RF90_PATH_D:
469 break; 472 break;
470 } 473 }
471 switch (rfpath) { 474 switch (rfpath) {
472 case RF90_PATH_A: 475 case RF90_PATH_A:
473 case RF90_PATH_C: 476 case RF90_PATH_C:
474 rtl_set_bbreg(hw, pphyreg->rfintfs, 477 rtl_set_bbreg(hw, pphyreg->rfintfs,
475 BRFSI_RFENV, u4_regvalue); 478 BRFSI_RFENV, u4_regvalue);
476 break; 479 break;
477 case RF90_PATH_B: 480 case RF90_PATH_B:
478 case RF90_PATH_D: 481 case RF90_PATH_D:
479 rtl_set_bbreg(hw, pphyreg->rfintfs, 482 rtl_set_bbreg(hw, pphyreg->rfintfs,
480 BRFSI_RFENV << 16, u4_regvalue); 483 BRFSI_RFENV << 16, u4_regvalue);
481 break; 484 break;
482 } 485 }
483 if (rtstatus != true) { 486 if (rtstatus != true) {
484 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 487 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
485 ("Radio[%d] Fail!!", rfpath)); 488 ("Radio[%d] Fail!!", rfpath));
486 goto phy_rf_cfg_fail; 489 goto phy_rf_cfg_fail;
487 } 490 }
488 } 491 }
489 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("<---\n")); 492 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("<---\n"));
490 return rtstatus; 493 return rtstatus;
491 phy_rf_cfg_fail: 494 phy_rf_cfg_fail:
492 return rtstatus; 495 return rtstatus;
drivers/net/wireless/rtlwifi/usb.c
1 /****************************************************************************** 1 /******************************************************************************
2 * 2 *
3 * Copyright(c) 2009-2011 Realtek Corporation. All rights reserved. 3 * Copyright(c) 2009-2011 Realtek Corporation. All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as 6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT 9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details. 12 * more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License along with 14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 * 17 *
18 * The full GNU General Public License is included in this distribution in the 18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE. 19 * file called LICENSE.
20 * 20 *
21 * Contact Information: 21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com> 22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, 23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan. 24 * Hsinchu 300, Taiwan.
25 * 25 *
26 *****************************************************************************/ 26 *****************************************************************************/
27 27
28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 29
30 #include <linux/usb.h> 30 #include <linux/usb.h>
31 #include <linux/export.h> 31 #include <linux/export.h>
32 #include "core.h" 32 #include "core.h"
33 #include "wifi.h" 33 #include "wifi.h"
34 #include "usb.h" 34 #include "usb.h"
35 #include "base.h" 35 #include "base.h"
36 #include "ps.h" 36 #include "ps.h"
37 37
38 #define REALTEK_USB_VENQT_READ 0xC0 38 #define REALTEK_USB_VENQT_READ 0xC0
39 #define REALTEK_USB_VENQT_WRITE 0x40 39 #define REALTEK_USB_VENQT_WRITE 0x40
40 #define REALTEK_USB_VENQT_CMD_REQ 0x05 40 #define REALTEK_USB_VENQT_CMD_REQ 0x05
41 #define REALTEK_USB_VENQT_CMD_IDX 0x00 41 #define REALTEK_USB_VENQT_CMD_IDX 0x00
42 42
43 #define REALTEK_USB_VENQT_MAX_BUF_SIZE 254 43 #define REALTEK_USB_VENQT_MAX_BUF_SIZE 254
44 44
45 static void usbctrl_async_callback(struct urb *urb) 45 static void usbctrl_async_callback(struct urb *urb)
46 { 46 {
47 if (urb) 47 if (urb)
48 kfree(urb->context); 48 kfree(urb->context);
49 } 49 }
50 50
51 static int _usbctrl_vendorreq_async_write(struct usb_device *udev, u8 request, 51 static int _usbctrl_vendorreq_async_write(struct usb_device *udev, u8 request,
52 u16 value, u16 index, void *pdata, 52 u16 value, u16 index, void *pdata,
53 u16 len) 53 u16 len)
54 { 54 {
55 int rc; 55 int rc;
56 unsigned int pipe; 56 unsigned int pipe;
57 u8 reqtype; 57 u8 reqtype;
58 struct usb_ctrlrequest *dr; 58 struct usb_ctrlrequest *dr;
59 struct urb *urb; 59 struct urb *urb;
60 struct rtl819x_async_write_data { 60 struct rtl819x_async_write_data {
61 u8 data[REALTEK_USB_VENQT_MAX_BUF_SIZE]; 61 u8 data[REALTEK_USB_VENQT_MAX_BUF_SIZE];
62 struct usb_ctrlrequest dr; 62 struct usb_ctrlrequest dr;
63 } *buf; 63 } *buf;
64 64
65 pipe = usb_sndctrlpipe(udev, 0); /* write_out */ 65 pipe = usb_sndctrlpipe(udev, 0); /* write_out */
66 reqtype = REALTEK_USB_VENQT_WRITE; 66 reqtype = REALTEK_USB_VENQT_WRITE;
67 67
68 buf = kmalloc(sizeof(*buf), GFP_ATOMIC); 68 buf = kmalloc(sizeof(*buf), GFP_ATOMIC);
69 if (!buf) 69 if (!buf)
70 return -ENOMEM; 70 return -ENOMEM;
71 71
72 urb = usb_alloc_urb(0, GFP_ATOMIC); 72 urb = usb_alloc_urb(0, GFP_ATOMIC);
73 if (!urb) { 73 if (!urb) {
74 kfree(buf); 74 kfree(buf);
75 return -ENOMEM; 75 return -ENOMEM;
76 } 76 }
77 77
78 dr = &buf->dr; 78 dr = &buf->dr;
79 79
80 dr->bRequestType = reqtype; 80 dr->bRequestType = reqtype;
81 dr->bRequest = request; 81 dr->bRequest = request;
82 dr->wValue = cpu_to_le16(value); 82 dr->wValue = cpu_to_le16(value);
83 dr->wIndex = cpu_to_le16(index); 83 dr->wIndex = cpu_to_le16(index);
84 dr->wLength = cpu_to_le16(len); 84 dr->wLength = cpu_to_le16(len);
85 memcpy(buf, pdata, len); 85 memcpy(buf, pdata, len);
86 usb_fill_control_urb(urb, udev, pipe, 86 usb_fill_control_urb(urb, udev, pipe,
87 (unsigned char *)dr, buf, len, 87 (unsigned char *)dr, buf, len,
88 usbctrl_async_callback, buf); 88 usbctrl_async_callback, buf);
89 rc = usb_submit_urb(urb, GFP_ATOMIC); 89 rc = usb_submit_urb(urb, GFP_ATOMIC);
90 if (rc < 0) 90 if (rc < 0)
91 kfree(buf); 91 kfree(buf);
92 usb_free_urb(urb); 92 usb_free_urb(urb);
93 return rc; 93 return rc;
94 } 94 }
95 95
96 static int _usbctrl_vendorreq_sync_read(struct usb_device *udev, u8 request, 96 static int _usbctrl_vendorreq_sync_read(struct usb_device *udev, u8 request,
97 u16 value, u16 index, void *pdata, 97 u16 value, u16 index, void *pdata,
98 u16 len) 98 u16 len)
99 { 99 {
100 unsigned int pipe; 100 unsigned int pipe;
101 int status; 101 int status;
102 u8 reqtype; 102 u8 reqtype;
103 103
104 pipe = usb_rcvctrlpipe(udev, 0); /* read_in */ 104 pipe = usb_rcvctrlpipe(udev, 0); /* read_in */
105 reqtype = REALTEK_USB_VENQT_READ; 105 reqtype = REALTEK_USB_VENQT_READ;
106 106
107 status = usb_control_msg(udev, pipe, request, reqtype, value, index, 107 status = usb_control_msg(udev, pipe, request, reqtype, value, index,
108 pdata, len, 0); /* max. timeout */ 108 pdata, len, 1000); /* max. timeout */
109 109
110 if (status < 0) 110 if (status < 0)
111 pr_err("reg 0x%x, usbctrl_vendorreq TimeOut! status:0x%x value=0x%x\n", 111 pr_err("reg 0x%x, usbctrl_vendorreq TimeOut! status:0x%x value=0x%x\n",
112 value, status, *(u32 *)pdata); 112 value, status, *(u32 *)pdata);
113 return status; 113 return status;
114 } 114 }
115 115
116 static u32 _usb_read_sync(struct usb_device *udev, u32 addr, u16 len) 116 static u32 _usb_read_sync(struct usb_device *udev, u32 addr, u16 len)
117 { 117 {
118 u8 request; 118 u8 request;
119 u16 wvalue; 119 u16 wvalue;
120 u16 index; 120 u16 index;
121 u32 *data; 121 u32 *data;
122 u32 ret; 122 u32 ret;
123 123
124 data = kmalloc(sizeof(u32), GFP_KERNEL); 124 data = kmalloc(sizeof(u32), GFP_KERNEL);
125 if (!data) 125 if (!data)
126 return -ENOMEM; 126 return -ENOMEM;
127 request = REALTEK_USB_VENQT_CMD_REQ; 127 request = REALTEK_USB_VENQT_CMD_REQ;
128 index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */ 128 index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */
129 129
130 wvalue = (u16)addr; 130 wvalue = (u16)addr;
131 _usbctrl_vendorreq_sync_read(udev, request, wvalue, index, data, len); 131 _usbctrl_vendorreq_sync_read(udev, request, wvalue, index, data, len);
132 ret = *data; 132 ret = *data;
133 kfree(data); 133 kfree(data);
134 return ret; 134 return ret;
135 } 135 }
136 136
137 static u8 _usb_read8_sync(struct rtl_priv *rtlpriv, u32 addr) 137 static u8 _usb_read8_sync(struct rtl_priv *rtlpriv, u32 addr)
138 { 138 {
139 struct device *dev = rtlpriv->io.dev; 139 struct device *dev = rtlpriv->io.dev;
140 140
141 return (u8)_usb_read_sync(to_usb_device(dev), addr, 1); 141 return (u8)_usb_read_sync(to_usb_device(dev), addr, 1);
142 } 142 }
143 143
144 static u16 _usb_read16_sync(struct rtl_priv *rtlpriv, u32 addr) 144 static u16 _usb_read16_sync(struct rtl_priv *rtlpriv, u32 addr)
145 { 145 {
146 struct device *dev = rtlpriv->io.dev; 146 struct device *dev = rtlpriv->io.dev;
147 147
148 return (u16)_usb_read_sync(to_usb_device(dev), addr, 2); 148 return (u16)_usb_read_sync(to_usb_device(dev), addr, 2);
149 } 149 }
150 150
151 static u32 _usb_read32_sync(struct rtl_priv *rtlpriv, u32 addr) 151 static u32 _usb_read32_sync(struct rtl_priv *rtlpriv, u32 addr)
152 { 152 {
153 struct device *dev = rtlpriv->io.dev; 153 struct device *dev = rtlpriv->io.dev;
154 154
155 return _usb_read_sync(to_usb_device(dev), addr, 4); 155 return _usb_read_sync(to_usb_device(dev), addr, 4);
156 } 156 }
157 157
158 static void _usb_write_async(struct usb_device *udev, u32 addr, u32 val, 158 static void _usb_write_async(struct usb_device *udev, u32 addr, u32 val,
159 u16 len) 159 u16 len)
160 { 160 {
161 u8 request; 161 u8 request;
162 u16 wvalue; 162 u16 wvalue;
163 u16 index; 163 u16 index;
164 u32 data; 164 u32 data;
165 165
166 request = REALTEK_USB_VENQT_CMD_REQ; 166 request = REALTEK_USB_VENQT_CMD_REQ;
167 index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */ 167 index = REALTEK_USB_VENQT_CMD_IDX; /* n/a */
168 wvalue = (u16)(addr&0x0000ffff); 168 wvalue = (u16)(addr&0x0000ffff);
169 data = val; 169 data = val;
170 _usbctrl_vendorreq_async_write(udev, request, wvalue, index, &data, 170 _usbctrl_vendorreq_async_write(udev, request, wvalue, index, &data,
171 len); 171 len);
172 } 172 }
173 173
174 static void _usb_write8_async(struct rtl_priv *rtlpriv, u32 addr, u8 val) 174 static void _usb_write8_async(struct rtl_priv *rtlpriv, u32 addr, u8 val)
175 { 175 {
176 struct device *dev = rtlpriv->io.dev; 176 struct device *dev = rtlpriv->io.dev;
177 177
178 _usb_write_async(to_usb_device(dev), addr, val, 1); 178 _usb_write_async(to_usb_device(dev), addr, val, 1);
179 } 179 }
180 180
181 static void _usb_write16_async(struct rtl_priv *rtlpriv, u32 addr, u16 val) 181 static void _usb_write16_async(struct rtl_priv *rtlpriv, u32 addr, u16 val)
182 { 182 {
183 struct device *dev = rtlpriv->io.dev; 183 struct device *dev = rtlpriv->io.dev;
184 184
185 _usb_write_async(to_usb_device(dev), addr, val, 2); 185 _usb_write_async(to_usb_device(dev), addr, val, 2);
186 } 186 }
187 187
188 static void _usb_write32_async(struct rtl_priv *rtlpriv, u32 addr, u32 val) 188 static void _usb_write32_async(struct rtl_priv *rtlpriv, u32 addr, u32 val)
189 { 189 {
190 struct device *dev = rtlpriv->io.dev; 190 struct device *dev = rtlpriv->io.dev;
191 191
192 _usb_write_async(to_usb_device(dev), addr, val, 4); 192 _usb_write_async(to_usb_device(dev), addr, val, 4);
193 } 193 }
194 194
195 static void _rtl_usb_io_handler_init(struct device *dev, 195 static void _rtl_usb_io_handler_init(struct device *dev,
196 struct ieee80211_hw *hw) 196 struct ieee80211_hw *hw)
197 { 197 {
198 struct rtl_priv *rtlpriv = rtl_priv(hw); 198 struct rtl_priv *rtlpriv = rtl_priv(hw);
199 199
200 rtlpriv->io.dev = dev; 200 rtlpriv->io.dev = dev;
201 mutex_init(&rtlpriv->io.bb_mutex); 201 mutex_init(&rtlpriv->io.bb_mutex);
202 rtlpriv->io.write8_async = _usb_write8_async; 202 rtlpriv->io.write8_async = _usb_write8_async;
203 rtlpriv->io.write16_async = _usb_write16_async; 203 rtlpriv->io.write16_async = _usb_write16_async;
204 rtlpriv->io.write32_async = _usb_write32_async; 204 rtlpriv->io.write32_async = _usb_write32_async;
205 rtlpriv->io.read8_sync = _usb_read8_sync; 205 rtlpriv->io.read8_sync = _usb_read8_sync;
206 rtlpriv->io.read16_sync = _usb_read16_sync; 206 rtlpriv->io.read16_sync = _usb_read16_sync;
207 rtlpriv->io.read32_sync = _usb_read32_sync; 207 rtlpriv->io.read32_sync = _usb_read32_sync;
208 } 208 }
209 209
210 static void _rtl_usb_io_handler_release(struct ieee80211_hw *hw) 210 static void _rtl_usb_io_handler_release(struct ieee80211_hw *hw)
211 { 211 {
212 struct rtl_priv __maybe_unused *rtlpriv = rtl_priv(hw); 212 struct rtl_priv __maybe_unused *rtlpriv = rtl_priv(hw);
213 213
214 mutex_destroy(&rtlpriv->io.bb_mutex); 214 mutex_destroy(&rtlpriv->io.bb_mutex);
215 } 215 }
216 216
217 /** 217 /**
218 * 218 *
219 * Default aggregation handler. Do nothing and just return the oldest skb. 219 * Default aggregation handler. Do nothing and just return the oldest skb.
220 */ 220 */
221 static struct sk_buff *_none_usb_tx_aggregate_hdl(struct ieee80211_hw *hw, 221 static struct sk_buff *_none_usb_tx_aggregate_hdl(struct ieee80211_hw *hw,
222 struct sk_buff_head *list) 222 struct sk_buff_head *list)
223 { 223 {
224 return skb_dequeue(list); 224 return skb_dequeue(list);
225 } 225 }
226 226
227 #define IS_HIGH_SPEED_USB(udev) \ 227 #define IS_HIGH_SPEED_USB(udev) \
228 ((USB_SPEED_HIGH == (udev)->speed) ? true : false) 228 ((USB_SPEED_HIGH == (udev)->speed) ? true : false)
229 229
230 static int _rtl_usb_init_tx(struct ieee80211_hw *hw) 230 static int _rtl_usb_init_tx(struct ieee80211_hw *hw)
231 { 231 {
232 u32 i; 232 u32 i;
233 struct rtl_priv *rtlpriv = rtl_priv(hw); 233 struct rtl_priv *rtlpriv = rtl_priv(hw);
234 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 234 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
235 235
236 rtlusb->max_bulk_out_size = IS_HIGH_SPEED_USB(rtlusb->udev) 236 rtlusb->max_bulk_out_size = IS_HIGH_SPEED_USB(rtlusb->udev)
237 ? USB_HIGH_SPEED_BULK_SIZE 237 ? USB_HIGH_SPEED_BULK_SIZE
238 : USB_FULL_SPEED_BULK_SIZE; 238 : USB_FULL_SPEED_BULK_SIZE;
239 239
240 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("USB Max Bulk-out Size=%d\n", 240 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("USB Max Bulk-out Size=%d\n",
241 rtlusb->max_bulk_out_size)); 241 rtlusb->max_bulk_out_size));
242 242
243 for (i = 0; i < __RTL_TXQ_NUM; i++) { 243 for (i = 0; i < __RTL_TXQ_NUM; i++) {
244 u32 ep_num = rtlusb->ep_map.ep_mapping[i]; 244 u32 ep_num = rtlusb->ep_map.ep_mapping[i];
245 if (!ep_num) { 245 if (!ep_num) {
246 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 246 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
247 ("Invalid endpoint map setting!\n")); 247 ("Invalid endpoint map setting!\n"));
248 return -EINVAL; 248 return -EINVAL;
249 } 249 }
250 } 250 }
251 251
252 rtlusb->usb_tx_post_hdl = 252 rtlusb->usb_tx_post_hdl =
253 rtlpriv->cfg->usb_interface_cfg->usb_tx_post_hdl; 253 rtlpriv->cfg->usb_interface_cfg->usb_tx_post_hdl;
254 rtlusb->usb_tx_cleanup = 254 rtlusb->usb_tx_cleanup =
255 rtlpriv->cfg->usb_interface_cfg->usb_tx_cleanup; 255 rtlpriv->cfg->usb_interface_cfg->usb_tx_cleanup;
256 rtlusb->usb_tx_aggregate_hdl = 256 rtlusb->usb_tx_aggregate_hdl =
257 (rtlpriv->cfg->usb_interface_cfg->usb_tx_aggregate_hdl) 257 (rtlpriv->cfg->usb_interface_cfg->usb_tx_aggregate_hdl)
258 ? rtlpriv->cfg->usb_interface_cfg->usb_tx_aggregate_hdl 258 ? rtlpriv->cfg->usb_interface_cfg->usb_tx_aggregate_hdl
259 : &_none_usb_tx_aggregate_hdl; 259 : &_none_usb_tx_aggregate_hdl;
260 260
261 init_usb_anchor(&rtlusb->tx_submitted); 261 init_usb_anchor(&rtlusb->tx_submitted);
262 for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) { 262 for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) {
263 skb_queue_head_init(&rtlusb->tx_skb_queue[i]); 263 skb_queue_head_init(&rtlusb->tx_skb_queue[i]);
264 init_usb_anchor(&rtlusb->tx_pending[i]); 264 init_usb_anchor(&rtlusb->tx_pending[i]);
265 } 265 }
266 return 0; 266 return 0;
267 } 267 }
268 268
269 static int _rtl_usb_init_rx(struct ieee80211_hw *hw) 269 static int _rtl_usb_init_rx(struct ieee80211_hw *hw)
270 { 270 {
271 struct rtl_priv *rtlpriv = rtl_priv(hw); 271 struct rtl_priv *rtlpriv = rtl_priv(hw);
272 struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw); 272 struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
273 struct rtl_usb *rtlusb = rtl_usbdev(usb_priv); 273 struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
274 274
275 rtlusb->rx_max_size = rtlpriv->cfg->usb_interface_cfg->rx_max_size; 275 rtlusb->rx_max_size = rtlpriv->cfg->usb_interface_cfg->rx_max_size;
276 rtlusb->rx_urb_num = rtlpriv->cfg->usb_interface_cfg->rx_urb_num; 276 rtlusb->rx_urb_num = rtlpriv->cfg->usb_interface_cfg->rx_urb_num;
277 rtlusb->in_ep = rtlpriv->cfg->usb_interface_cfg->in_ep_num; 277 rtlusb->in_ep = rtlpriv->cfg->usb_interface_cfg->in_ep_num;
278 rtlusb->usb_rx_hdl = rtlpriv->cfg->usb_interface_cfg->usb_rx_hdl; 278 rtlusb->usb_rx_hdl = rtlpriv->cfg->usb_interface_cfg->usb_rx_hdl;
279 rtlusb->usb_rx_segregate_hdl = 279 rtlusb->usb_rx_segregate_hdl =
280 rtlpriv->cfg->usb_interface_cfg->usb_rx_segregate_hdl; 280 rtlpriv->cfg->usb_interface_cfg->usb_rx_segregate_hdl;
281 281
282 pr_info("rx_max_size %d, rx_urb_num %d, in_ep %d\n", 282 pr_info("rx_max_size %d, rx_urb_num %d, in_ep %d\n",
283 rtlusb->rx_max_size, rtlusb->rx_urb_num, rtlusb->in_ep); 283 rtlusb->rx_max_size, rtlusb->rx_urb_num, rtlusb->in_ep);
284 init_usb_anchor(&rtlusb->rx_submitted); 284 init_usb_anchor(&rtlusb->rx_submitted);
285 return 0; 285 return 0;
286 } 286 }
287 287
288 static int _rtl_usb_init(struct ieee80211_hw *hw) 288 static int _rtl_usb_init(struct ieee80211_hw *hw)
289 { 289 {
290 struct rtl_priv *rtlpriv = rtl_priv(hw); 290 struct rtl_priv *rtlpriv = rtl_priv(hw);
291 struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw); 291 struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
292 struct rtl_usb *rtlusb = rtl_usbdev(usb_priv); 292 struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
293 int err; 293 int err;
294 u8 epidx; 294 u8 epidx;
295 struct usb_interface *usb_intf = rtlusb->intf; 295 struct usb_interface *usb_intf = rtlusb->intf;
296 u8 epnums = usb_intf->cur_altsetting->desc.bNumEndpoints; 296 u8 epnums = usb_intf->cur_altsetting->desc.bNumEndpoints;
297 297
298 rtlusb->out_ep_nums = rtlusb->in_ep_nums = 0; 298 rtlusb->out_ep_nums = rtlusb->in_ep_nums = 0;
299 for (epidx = 0; epidx < epnums; epidx++) { 299 for (epidx = 0; epidx < epnums; epidx++) {
300 struct usb_endpoint_descriptor *pep_desc; 300 struct usb_endpoint_descriptor *pep_desc;
301 pep_desc = &usb_intf->cur_altsetting->endpoint[epidx].desc; 301 pep_desc = &usb_intf->cur_altsetting->endpoint[epidx].desc;
302 302
303 if (usb_endpoint_dir_in(pep_desc)) 303 if (usb_endpoint_dir_in(pep_desc))
304 rtlusb->in_ep_nums++; 304 rtlusb->in_ep_nums++;
305 else if (usb_endpoint_dir_out(pep_desc)) 305 else if (usb_endpoint_dir_out(pep_desc))
306 rtlusb->out_ep_nums++; 306 rtlusb->out_ep_nums++;
307 307
308 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 308 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
309 ("USB EP(0x%02x), MaxPacketSize=%d ,Interval=%d.\n", 309 ("USB EP(0x%02x), MaxPacketSize=%d ,Interval=%d.\n",
310 pep_desc->bEndpointAddress, pep_desc->wMaxPacketSize, 310 pep_desc->bEndpointAddress, pep_desc->wMaxPacketSize,
311 pep_desc->bInterval)); 311 pep_desc->bInterval));
312 } 312 }
313 if (rtlusb->in_ep_nums < rtlpriv->cfg->usb_interface_cfg->in_ep_num) 313 if (rtlusb->in_ep_nums < rtlpriv->cfg->usb_interface_cfg->in_ep_num)
314 return -EINVAL ; 314 return -EINVAL ;
315 315
316 /* usb endpoint mapping */ 316 /* usb endpoint mapping */
317 err = rtlpriv->cfg->usb_interface_cfg->usb_endpoint_mapping(hw); 317 err = rtlpriv->cfg->usb_interface_cfg->usb_endpoint_mapping(hw);
318 rtlusb->usb_mq_to_hwq = rtlpriv->cfg->usb_interface_cfg->usb_mq_to_hwq; 318 rtlusb->usb_mq_to_hwq = rtlpriv->cfg->usb_interface_cfg->usb_mq_to_hwq;
319 _rtl_usb_init_tx(hw); 319 _rtl_usb_init_tx(hw);
320 _rtl_usb_init_rx(hw); 320 _rtl_usb_init_rx(hw);
321 return err; 321 return err;
322 } 322 }
323 323
324 static int _rtl_usb_init_sw(struct ieee80211_hw *hw) 324 static int _rtl_usb_init_sw(struct ieee80211_hw *hw)
325 { 325 {
326 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 326 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
327 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 327 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
328 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 328 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
329 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 329 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
330 330
331 rtlhal->hw = hw; 331 rtlhal->hw = hw;
332 ppsc->inactiveps = false; 332 ppsc->inactiveps = false;
333 ppsc->leisure_ps = false; 333 ppsc->leisure_ps = false;
334 ppsc->fwctrl_lps = false; 334 ppsc->fwctrl_lps = false;
335 ppsc->reg_fwctrl_lps = 3; 335 ppsc->reg_fwctrl_lps = 3;
336 ppsc->reg_max_lps_awakeintvl = 5; 336 ppsc->reg_max_lps_awakeintvl = 5;
337 ppsc->fwctrl_psmode = FW_PS_DTIM_MODE; 337 ppsc->fwctrl_psmode = FW_PS_DTIM_MODE;
338 338
339 /* IBSS */ 339 /* IBSS */
340 mac->beacon_interval = 100; 340 mac->beacon_interval = 100;
341 341
342 /* AMPDU */ 342 /* AMPDU */
343 mac->min_space_cfg = 0; 343 mac->min_space_cfg = 0;
344 mac->max_mss_density = 0; 344 mac->max_mss_density = 0;
345 345
346 /* set sane AMPDU defaults */ 346 /* set sane AMPDU defaults */
347 mac->current_ampdu_density = 7; 347 mac->current_ampdu_density = 7;
348 mac->current_ampdu_factor = 3; 348 mac->current_ampdu_factor = 3;
349 349
350 /* QOS */ 350 /* QOS */
351 rtlusb->acm_method = eAcmWay2_SW; 351 rtlusb->acm_method = eAcmWay2_SW;
352 352
353 /* IRQ */ 353 /* IRQ */
354 /* HIMR - turn all on */ 354 /* HIMR - turn all on */
355 rtlusb->irq_mask[0] = 0xFFFFFFFF; 355 rtlusb->irq_mask[0] = 0xFFFFFFFF;
356 /* HIMR_EX - turn all on */ 356 /* HIMR_EX - turn all on */
357 rtlusb->irq_mask[1] = 0xFFFFFFFF; 357 rtlusb->irq_mask[1] = 0xFFFFFFFF;
358 rtlusb->disableHWSM = true; 358 rtlusb->disableHWSM = true;
359 return 0; 359 return 0;
360 } 360 }
361 361
362 #define __RADIO_TAP_SIZE_RSV 32 362 #define __RADIO_TAP_SIZE_RSV 32
363 363
364 static void _rtl_rx_completed(struct urb *urb); 364 static void _rtl_rx_completed(struct urb *urb);
365 365
366 static struct sk_buff *_rtl_prep_rx_urb(struct ieee80211_hw *hw, 366 static struct sk_buff *_rtl_prep_rx_urb(struct ieee80211_hw *hw,
367 struct rtl_usb *rtlusb, 367 struct rtl_usb *rtlusb,
368 struct urb *urb, 368 struct urb *urb,
369 gfp_t gfp_mask) 369 gfp_t gfp_mask)
370 { 370 {
371 struct sk_buff *skb; 371 struct sk_buff *skb;
372 struct rtl_priv *rtlpriv = rtl_priv(hw); 372 struct rtl_priv *rtlpriv = rtl_priv(hw);
373 373
374 skb = __dev_alloc_skb((rtlusb->rx_max_size + __RADIO_TAP_SIZE_RSV), 374 skb = __dev_alloc_skb((rtlusb->rx_max_size + __RADIO_TAP_SIZE_RSV),
375 gfp_mask); 375 gfp_mask);
376 if (!skb) { 376 if (!skb) {
377 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, 377 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
378 ("Failed to __dev_alloc_skb!!\n")) 378 ("Failed to __dev_alloc_skb!!\n"))
379 return ERR_PTR(-ENOMEM); 379 return ERR_PTR(-ENOMEM);
380 } 380 }
381 381
382 /* reserve some space for mac80211's radiotap */ 382 /* reserve some space for mac80211's radiotap */
383 skb_reserve(skb, __RADIO_TAP_SIZE_RSV); 383 skb_reserve(skb, __RADIO_TAP_SIZE_RSV);
384 usb_fill_bulk_urb(urb, rtlusb->udev, 384 usb_fill_bulk_urb(urb, rtlusb->udev,
385 usb_rcvbulkpipe(rtlusb->udev, rtlusb->in_ep), 385 usb_rcvbulkpipe(rtlusb->udev, rtlusb->in_ep),
386 skb->data, min(skb_tailroom(skb), 386 skb->data, min(skb_tailroom(skb),
387 (int)rtlusb->rx_max_size), 387 (int)rtlusb->rx_max_size),
388 _rtl_rx_completed, skb); 388 _rtl_rx_completed, skb);
389 389
390 _rtl_install_trx_info(rtlusb, skb, rtlusb->in_ep); 390 _rtl_install_trx_info(rtlusb, skb, rtlusb->in_ep);
391 return skb; 391 return skb;
392 } 392 }
393 393
394 #undef __RADIO_TAP_SIZE_RSV 394 #undef __RADIO_TAP_SIZE_RSV
395 395
396 static void _rtl_usb_rx_process_agg(struct ieee80211_hw *hw, 396 static void _rtl_usb_rx_process_agg(struct ieee80211_hw *hw,
397 struct sk_buff *skb) 397 struct sk_buff *skb)
398 { 398 {
399 struct rtl_priv *rtlpriv = rtl_priv(hw); 399 struct rtl_priv *rtlpriv = rtl_priv(hw);
400 u8 *rxdesc = skb->data; 400 u8 *rxdesc = skb->data;
401 struct ieee80211_hdr *hdr; 401 struct ieee80211_hdr *hdr;
402 bool unicast = false; 402 bool unicast = false;
403 __le16 fc; 403 __le16 fc;
404 struct ieee80211_rx_status rx_status = {0}; 404 struct ieee80211_rx_status rx_status = {0};
405 struct rtl_stats stats = { 405 struct rtl_stats stats = {
406 .signal = 0, 406 .signal = 0,
407 .noise = -98, 407 .noise = -98,
408 .rate = 0, 408 .rate = 0,
409 }; 409 };
410 410
411 skb_pull(skb, RTL_RX_DESC_SIZE); 411 skb_pull(skb, RTL_RX_DESC_SIZE);
412 rtlpriv->cfg->ops->query_rx_desc(hw, &stats, &rx_status, rxdesc, skb); 412 rtlpriv->cfg->ops->query_rx_desc(hw, &stats, &rx_status, rxdesc, skb);
413 skb_pull(skb, (stats.rx_drvinfo_size + stats.rx_bufshift)); 413 skb_pull(skb, (stats.rx_drvinfo_size + stats.rx_bufshift));
414 hdr = (struct ieee80211_hdr *)(skb->data); 414 hdr = (struct ieee80211_hdr *)(skb->data);
415 fc = hdr->frame_control; 415 fc = hdr->frame_control;
416 if (!stats.crc) { 416 if (!stats.crc) {
417 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); 417 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
418 418
419 if (is_broadcast_ether_addr(hdr->addr1)) { 419 if (is_broadcast_ether_addr(hdr->addr1)) {
420 /*TODO*/; 420 /*TODO*/;
421 } else if (is_multicast_ether_addr(hdr->addr1)) { 421 } else if (is_multicast_ether_addr(hdr->addr1)) {
422 /*TODO*/ 422 /*TODO*/
423 } else { 423 } else {
424 unicast = true; 424 unicast = true;
425 rtlpriv->stats.rxbytesunicast += skb->len; 425 rtlpriv->stats.rxbytesunicast += skb->len;
426 } 426 }
427 427
428 rtl_is_special_data(hw, skb, false); 428 rtl_is_special_data(hw, skb, false);
429 429
430 if (ieee80211_is_data(fc)) { 430 if (ieee80211_is_data(fc)) {
431 rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX); 431 rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX);
432 432
433 if (unicast) 433 if (unicast)
434 rtlpriv->link_info.num_rx_inperiod++; 434 rtlpriv->link_info.num_rx_inperiod++;
435 } 435 }
436 } 436 }
437 } 437 }
438 438
439 static void _rtl_usb_rx_process_noagg(struct ieee80211_hw *hw, 439 static void _rtl_usb_rx_process_noagg(struct ieee80211_hw *hw,
440 struct sk_buff *skb) 440 struct sk_buff *skb)
441 { 441 {
442 struct rtl_priv *rtlpriv = rtl_priv(hw); 442 struct rtl_priv *rtlpriv = rtl_priv(hw);
443 u8 *rxdesc = skb->data; 443 u8 *rxdesc = skb->data;
444 struct ieee80211_hdr *hdr; 444 struct ieee80211_hdr *hdr;
445 bool unicast = false; 445 bool unicast = false;
446 __le16 fc; 446 __le16 fc;
447 struct ieee80211_rx_status rx_status = {0}; 447 struct ieee80211_rx_status rx_status = {0};
448 struct rtl_stats stats = { 448 struct rtl_stats stats = {
449 .signal = 0, 449 .signal = 0,
450 .noise = -98, 450 .noise = -98,
451 .rate = 0, 451 .rate = 0,
452 }; 452 };
453 453
454 skb_pull(skb, RTL_RX_DESC_SIZE); 454 skb_pull(skb, RTL_RX_DESC_SIZE);
455 rtlpriv->cfg->ops->query_rx_desc(hw, &stats, &rx_status, rxdesc, skb); 455 rtlpriv->cfg->ops->query_rx_desc(hw, &stats, &rx_status, rxdesc, skb);
456 skb_pull(skb, (stats.rx_drvinfo_size + stats.rx_bufshift)); 456 skb_pull(skb, (stats.rx_drvinfo_size + stats.rx_bufshift));
457 hdr = (struct ieee80211_hdr *)(skb->data); 457 hdr = (struct ieee80211_hdr *)(skb->data);
458 fc = hdr->frame_control; 458 fc = hdr->frame_control;
459 if (!stats.crc) { 459 if (!stats.crc) {
460 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); 460 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
461 461
462 if (is_broadcast_ether_addr(hdr->addr1)) { 462 if (is_broadcast_ether_addr(hdr->addr1)) {
463 /*TODO*/; 463 /*TODO*/;
464 } else if (is_multicast_ether_addr(hdr->addr1)) { 464 } else if (is_multicast_ether_addr(hdr->addr1)) {
465 /*TODO*/ 465 /*TODO*/
466 } else { 466 } else {
467 unicast = true; 467 unicast = true;
468 rtlpriv->stats.rxbytesunicast += skb->len; 468 rtlpriv->stats.rxbytesunicast += skb->len;
469 } 469 }
470 470
471 rtl_is_special_data(hw, skb, false); 471 rtl_is_special_data(hw, skb, false);
472 472
473 if (ieee80211_is_data(fc)) { 473 if (ieee80211_is_data(fc)) {
474 rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX); 474 rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX);
475 475
476 if (unicast) 476 if (unicast)
477 rtlpriv->link_info.num_rx_inperiod++; 477 rtlpriv->link_info.num_rx_inperiod++;
478 } 478 }
479 if (likely(rtl_action_proc(hw, skb, false))) { 479 if (likely(rtl_action_proc(hw, skb, false))) {
480 struct sk_buff *uskb = NULL; 480 struct sk_buff *uskb = NULL;
481 u8 *pdata; 481 u8 *pdata;
482 482
483 uskb = dev_alloc_skb(skb->len + 128); 483 uskb = dev_alloc_skb(skb->len + 128);
484 memcpy(IEEE80211_SKB_RXCB(uskb), &rx_status, 484 memcpy(IEEE80211_SKB_RXCB(uskb), &rx_status,
485 sizeof(rx_status)); 485 sizeof(rx_status));
486 pdata = (u8 *)skb_put(uskb, skb->len); 486 pdata = (u8 *)skb_put(uskb, skb->len);
487 memcpy(pdata, skb->data, skb->len); 487 memcpy(pdata, skb->data, skb->len);
488 dev_kfree_skb_any(skb); 488 dev_kfree_skb_any(skb);
489 ieee80211_rx_irqsafe(hw, uskb); 489 ieee80211_rx_irqsafe(hw, uskb);
490 } else { 490 } else {
491 dev_kfree_skb_any(skb); 491 dev_kfree_skb_any(skb);
492 } 492 }
493 } 493 }
494 } 494 }
495 495
496 static void _rtl_rx_pre_process(struct ieee80211_hw *hw, struct sk_buff *skb) 496 static void _rtl_rx_pre_process(struct ieee80211_hw *hw, struct sk_buff *skb)
497 { 497 {
498 struct sk_buff *_skb; 498 struct sk_buff *_skb;
499 struct sk_buff_head rx_queue; 499 struct sk_buff_head rx_queue;
500 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 500 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
501 501
502 skb_queue_head_init(&rx_queue); 502 skb_queue_head_init(&rx_queue);
503 if (rtlusb->usb_rx_segregate_hdl) 503 if (rtlusb->usb_rx_segregate_hdl)
504 rtlusb->usb_rx_segregate_hdl(hw, skb, &rx_queue); 504 rtlusb->usb_rx_segregate_hdl(hw, skb, &rx_queue);
505 WARN_ON(skb_queue_empty(&rx_queue)); 505 WARN_ON(skb_queue_empty(&rx_queue));
506 while (!skb_queue_empty(&rx_queue)) { 506 while (!skb_queue_empty(&rx_queue)) {
507 _skb = skb_dequeue(&rx_queue); 507 _skb = skb_dequeue(&rx_queue);
508 _rtl_usb_rx_process_agg(hw, skb); 508 _rtl_usb_rx_process_agg(hw, skb);
509 ieee80211_rx_irqsafe(hw, skb); 509 ieee80211_rx_irqsafe(hw, skb);
510 } 510 }
511 } 511 }
512 512
513 static void _rtl_rx_completed(struct urb *_urb) 513 static void _rtl_rx_completed(struct urb *_urb)
514 { 514 {
515 struct sk_buff *skb = (struct sk_buff *)_urb->context; 515 struct sk_buff *skb = (struct sk_buff *)_urb->context;
516 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 516 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
517 struct rtl_usb *rtlusb = (struct rtl_usb *)info->rate_driver_data[0]; 517 struct rtl_usb *rtlusb = (struct rtl_usb *)info->rate_driver_data[0];
518 struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf); 518 struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf);
519 struct rtl_priv *rtlpriv = rtl_priv(hw); 519 struct rtl_priv *rtlpriv = rtl_priv(hw);
520 int err = 0; 520 int err = 0;
521 521
522 if (unlikely(IS_USB_STOP(rtlusb))) 522 if (unlikely(IS_USB_STOP(rtlusb)))
523 goto free; 523 goto free;
524 524
525 if (likely(0 == _urb->status)) { 525 if (likely(0 == _urb->status)) {
526 /* If this code were moved to work queue, would CPU 526 /* If this code were moved to work queue, would CPU
527 * utilization be improved? NOTE: We shall allocate another skb 527 * utilization be improved? NOTE: We shall allocate another skb
528 * and reuse the original one. 528 * and reuse the original one.
529 */ 529 */
530 skb_put(skb, _urb->actual_length); 530 skb_put(skb, _urb->actual_length);
531 531
532 if (likely(!rtlusb->usb_rx_segregate_hdl)) { 532 if (likely(!rtlusb->usb_rx_segregate_hdl)) {
533 struct sk_buff *_skb; 533 struct sk_buff *_skb;
534 _rtl_usb_rx_process_noagg(hw, skb); 534 _rtl_usb_rx_process_noagg(hw, skb);
535 _skb = _rtl_prep_rx_urb(hw, rtlusb, _urb, GFP_ATOMIC); 535 _skb = _rtl_prep_rx_urb(hw, rtlusb, _urb, GFP_ATOMIC);
536 if (IS_ERR(_skb)) { 536 if (IS_ERR(_skb)) {
537 err = PTR_ERR(_skb); 537 err = PTR_ERR(_skb);
538 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, 538 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
539 ("Can't allocate skb for bulk IN!\n")); 539 ("Can't allocate skb for bulk IN!\n"));
540 return; 540 return;
541 } 541 }
542 skb = _skb; 542 skb = _skb;
543 } else{ 543 } else{
544 /* TO DO */ 544 /* TO DO */
545 _rtl_rx_pre_process(hw, skb); 545 _rtl_rx_pre_process(hw, skb);
546 pr_err("rx agg not supported\n"); 546 pr_err("rx agg not supported\n");
547 } 547 }
548 goto resubmit; 548 goto resubmit;
549 } 549 }
550 550
551 switch (_urb->status) { 551 switch (_urb->status) {
552 /* disconnect */ 552 /* disconnect */
553 case -ENOENT: 553 case -ENOENT:
554 case -ECONNRESET: 554 case -ECONNRESET:
555 case -ENODEV: 555 case -ENODEV:
556 case -ESHUTDOWN: 556 case -ESHUTDOWN:
557 goto free; 557 goto free;
558 default: 558 default:
559 break; 559 break;
560 } 560 }
561 561
562 resubmit: 562 resubmit:
563 skb_reset_tail_pointer(skb); 563 skb_reset_tail_pointer(skb);
564 skb_trim(skb, 0); 564 skb_trim(skb, 0);
565 565
566 usb_anchor_urb(_urb, &rtlusb->rx_submitted); 566 usb_anchor_urb(_urb, &rtlusb->rx_submitted);
567 err = usb_submit_urb(_urb, GFP_ATOMIC); 567 err = usb_submit_urb(_urb, GFP_ATOMIC);
568 if (unlikely(err)) { 568 if (unlikely(err)) {
569 usb_unanchor_urb(_urb); 569 usb_unanchor_urb(_urb);
570 goto free; 570 goto free;
571 } 571 }
572 return; 572 return;
573 573
574 free: 574 free:
575 dev_kfree_skb_irq(skb); 575 dev_kfree_skb_irq(skb);
576 } 576 }
577 577
578 static int _rtl_usb_receive(struct ieee80211_hw *hw) 578 static int _rtl_usb_receive(struct ieee80211_hw *hw)
579 { 579 {
580 struct urb *urb; 580 struct urb *urb;
581 struct sk_buff *skb; 581 struct sk_buff *skb;
582 int err; 582 int err;
583 int i; 583 int i;
584 struct rtl_priv *rtlpriv = rtl_priv(hw); 584 struct rtl_priv *rtlpriv = rtl_priv(hw);
585 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 585 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
586 586
587 WARN_ON(0 == rtlusb->rx_urb_num); 587 WARN_ON(0 == rtlusb->rx_urb_num);
588 /* 1600 == 1514 + max WLAN header + rtk info */ 588 /* 1600 == 1514 + max WLAN header + rtk info */
589 WARN_ON(rtlusb->rx_max_size < 1600); 589 WARN_ON(rtlusb->rx_max_size < 1600);
590 590
591 for (i = 0; i < rtlusb->rx_urb_num; i++) { 591 for (i = 0; i < rtlusb->rx_urb_num; i++) {
592 err = -ENOMEM; 592 err = -ENOMEM;
593 urb = usb_alloc_urb(0, GFP_KERNEL); 593 urb = usb_alloc_urb(0, GFP_KERNEL);
594 if (!urb) { 594 if (!urb) {
595 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, 595 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
596 ("Failed to alloc URB!!\n")) 596 ("Failed to alloc URB!!\n"))
597 goto err_out; 597 goto err_out;
598 } 598 }
599 599
600 skb = _rtl_prep_rx_urb(hw, rtlusb, urb, GFP_KERNEL); 600 skb = _rtl_prep_rx_urb(hw, rtlusb, urb, GFP_KERNEL);
601 if (IS_ERR(skb)) { 601 if (IS_ERR(skb)) {
602 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, 602 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
603 ("Failed to prep_rx_urb!!\n")) 603 ("Failed to prep_rx_urb!!\n"))
604 err = PTR_ERR(skb); 604 err = PTR_ERR(skb);
605 goto err_out; 605 goto err_out;
606 } 606 }
607 607
608 usb_anchor_urb(urb, &rtlusb->rx_submitted); 608 usb_anchor_urb(urb, &rtlusb->rx_submitted);
609 err = usb_submit_urb(urb, GFP_KERNEL); 609 err = usb_submit_urb(urb, GFP_KERNEL);
610 if (err) 610 if (err)
611 goto err_out; 611 goto err_out;
612 usb_free_urb(urb); 612 usb_free_urb(urb);
613 } 613 }
614 return 0; 614 return 0;
615 615
616 err_out: 616 err_out:
617 usb_kill_anchored_urbs(&rtlusb->rx_submitted); 617 usb_kill_anchored_urbs(&rtlusb->rx_submitted);
618 return err; 618 return err;
619 } 619 }
620 620
621 static int rtl_usb_start(struct ieee80211_hw *hw) 621 static int rtl_usb_start(struct ieee80211_hw *hw)
622 { 622 {
623 int err; 623 int err;
624 struct rtl_priv *rtlpriv = rtl_priv(hw); 624 struct rtl_priv *rtlpriv = rtl_priv(hw);
625 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 625 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
626 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 626 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
627 627
628 err = rtlpriv->cfg->ops->hw_init(hw); 628 err = rtlpriv->cfg->ops->hw_init(hw);
629 rtl_init_rx_config(hw); 629 rtl_init_rx_config(hw);
630 630
631 /* Enable software */ 631 /* Enable software */
632 SET_USB_START(rtlusb); 632 SET_USB_START(rtlusb);
633 /* should after adapter start and interrupt enable. */ 633 /* should after adapter start and interrupt enable. */
634 set_hal_start(rtlhal); 634 set_hal_start(rtlhal);
635 635
636 /* Start bulk IN */ 636 /* Start bulk IN */
637 _rtl_usb_receive(hw); 637 _rtl_usb_receive(hw);
638 638
639 return err; 639 return err;
640 } 640 }
641 /** 641 /**
642 * 642 *
643 * 643 *
644 */ 644 */
645 645
646 /*======================= tx =========================================*/ 646 /*======================= tx =========================================*/
647 static void rtl_usb_cleanup(struct ieee80211_hw *hw) 647 static void rtl_usb_cleanup(struct ieee80211_hw *hw)
648 { 648 {
649 u32 i; 649 u32 i;
650 struct sk_buff *_skb; 650 struct sk_buff *_skb;
651 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 651 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
652 struct ieee80211_tx_info *txinfo; 652 struct ieee80211_tx_info *txinfo;
653 653
654 SET_USB_STOP(rtlusb); 654 SET_USB_STOP(rtlusb);
655 655
656 /* clean up rx stuff. */ 656 /* clean up rx stuff. */
657 usb_kill_anchored_urbs(&rtlusb->rx_submitted); 657 usb_kill_anchored_urbs(&rtlusb->rx_submitted);
658 658
659 /* clean up tx stuff */ 659 /* clean up tx stuff */
660 for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) { 660 for (i = 0; i < RTL_USB_MAX_EP_NUM; i++) {
661 while ((_skb = skb_dequeue(&rtlusb->tx_skb_queue[i]))) { 661 while ((_skb = skb_dequeue(&rtlusb->tx_skb_queue[i]))) {
662 rtlusb->usb_tx_cleanup(hw, _skb); 662 rtlusb->usb_tx_cleanup(hw, _skb);
663 txinfo = IEEE80211_SKB_CB(_skb); 663 txinfo = IEEE80211_SKB_CB(_skb);
664 ieee80211_tx_info_clear_status(txinfo); 664 ieee80211_tx_info_clear_status(txinfo);
665 txinfo->flags |= IEEE80211_TX_STAT_ACK; 665 txinfo->flags |= IEEE80211_TX_STAT_ACK;
666 ieee80211_tx_status_irqsafe(hw, _skb); 666 ieee80211_tx_status_irqsafe(hw, _skb);
667 } 667 }
668 usb_kill_anchored_urbs(&rtlusb->tx_pending[i]); 668 usb_kill_anchored_urbs(&rtlusb->tx_pending[i]);
669 } 669 }
670 usb_kill_anchored_urbs(&rtlusb->tx_submitted); 670 usb_kill_anchored_urbs(&rtlusb->tx_submitted);
671 } 671 }
672 672
673 /** 673 /**
674 * 674 *
675 * We may add some struct into struct rtl_usb later. Do deinit here. 675 * We may add some struct into struct rtl_usb later. Do deinit here.
676 * 676 *
677 */ 677 */
678 static void rtl_usb_deinit(struct ieee80211_hw *hw) 678 static void rtl_usb_deinit(struct ieee80211_hw *hw)
679 { 679 {
680 rtl_usb_cleanup(hw); 680 rtl_usb_cleanup(hw);
681 } 681 }
682 682
683 static void rtl_usb_stop(struct ieee80211_hw *hw) 683 static void rtl_usb_stop(struct ieee80211_hw *hw)
684 { 684 {
685 struct rtl_priv *rtlpriv = rtl_priv(hw); 685 struct rtl_priv *rtlpriv = rtl_priv(hw);
686 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 686 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
687 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 687 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
688 688
689 /* should after adapter start and interrupt enable. */ 689 /* should after adapter start and interrupt enable. */
690 set_hal_stop(rtlhal); 690 set_hal_stop(rtlhal);
691 /* Enable software */ 691 /* Enable software */
692 SET_USB_STOP(rtlusb); 692 SET_USB_STOP(rtlusb);
693 rtl_usb_deinit(hw); 693 rtl_usb_deinit(hw);
694 rtlpriv->cfg->ops->hw_disable(hw); 694 rtlpriv->cfg->ops->hw_disable(hw);
695 } 695 }
696 696
697 static void _rtl_submit_tx_urb(struct ieee80211_hw *hw, struct urb *_urb) 697 static void _rtl_submit_tx_urb(struct ieee80211_hw *hw, struct urb *_urb)
698 { 698 {
699 int err; 699 int err;
700 struct rtl_priv *rtlpriv = rtl_priv(hw); 700 struct rtl_priv *rtlpriv = rtl_priv(hw);
701 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 701 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
702 702
703 usb_anchor_urb(_urb, &rtlusb->tx_submitted); 703 usb_anchor_urb(_urb, &rtlusb->tx_submitted);
704 err = usb_submit_urb(_urb, GFP_ATOMIC); 704 err = usb_submit_urb(_urb, GFP_ATOMIC);
705 if (err < 0) { 705 if (err < 0) {
706 struct sk_buff *skb; 706 struct sk_buff *skb;
707 707
708 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, 708 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
709 ("Failed to submit urb.\n")); 709 ("Failed to submit urb.\n"));
710 usb_unanchor_urb(_urb); 710 usb_unanchor_urb(_urb);
711 skb = (struct sk_buff *)_urb->context; 711 skb = (struct sk_buff *)_urb->context;
712 kfree_skb(skb); 712 kfree_skb(skb);
713 } 713 }
714 usb_free_urb(_urb); 714 usb_free_urb(_urb);
715 } 715 }
716 716
717 static int _usb_tx_post(struct ieee80211_hw *hw, struct urb *urb, 717 static int _usb_tx_post(struct ieee80211_hw *hw, struct urb *urb,
718 struct sk_buff *skb) 718 struct sk_buff *skb)
719 { 719 {
720 struct rtl_priv *rtlpriv = rtl_priv(hw); 720 struct rtl_priv *rtlpriv = rtl_priv(hw);
721 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 721 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
722 struct ieee80211_tx_info *txinfo; 722 struct ieee80211_tx_info *txinfo;
723 723
724 rtlusb->usb_tx_post_hdl(hw, urb, skb); 724 rtlusb->usb_tx_post_hdl(hw, urb, skb);
725 skb_pull(skb, RTL_TX_HEADER_SIZE); 725 skb_pull(skb, RTL_TX_HEADER_SIZE);
726 txinfo = IEEE80211_SKB_CB(skb); 726 txinfo = IEEE80211_SKB_CB(skb);
727 ieee80211_tx_info_clear_status(txinfo); 727 ieee80211_tx_info_clear_status(txinfo);
728 txinfo->flags |= IEEE80211_TX_STAT_ACK; 728 txinfo->flags |= IEEE80211_TX_STAT_ACK;
729 729
730 if (urb->status) { 730 if (urb->status) {
731 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, 731 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
732 ("Urb has error status 0x%X\n", urb->status)); 732 ("Urb has error status 0x%X\n", urb->status));
733 goto out; 733 goto out;
734 } 734 }
735 /* TODO: statistics */ 735 /* TODO: statistics */
736 out: 736 out:
737 ieee80211_tx_status_irqsafe(hw, skb); 737 ieee80211_tx_status_irqsafe(hw, skb);
738 return urb->status; 738 return urb->status;
739 } 739 }
740 740
741 static void _rtl_tx_complete(struct urb *urb) 741 static void _rtl_tx_complete(struct urb *urb)
742 { 742 {
743 struct sk_buff *skb = (struct sk_buff *)urb->context; 743 struct sk_buff *skb = (struct sk_buff *)urb->context;
744 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 744 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
745 struct rtl_usb *rtlusb = (struct rtl_usb *)info->rate_driver_data[0]; 745 struct rtl_usb *rtlusb = (struct rtl_usb *)info->rate_driver_data[0];
746 struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf); 746 struct ieee80211_hw *hw = usb_get_intfdata(rtlusb->intf);
747 int err; 747 int err;
748 748
749 if (unlikely(IS_USB_STOP(rtlusb))) 749 if (unlikely(IS_USB_STOP(rtlusb)))
750 return; 750 return;
751 err = _usb_tx_post(hw, urb, skb); 751 err = _usb_tx_post(hw, urb, skb);
752 if (err) { 752 if (err) {
753 /* Ignore error and keep issuiing other urbs */ 753 /* Ignore error and keep issuiing other urbs */
754 return; 754 return;
755 } 755 }
756 } 756 }
757 757
758 static struct urb *_rtl_usb_tx_urb_setup(struct ieee80211_hw *hw, 758 static struct urb *_rtl_usb_tx_urb_setup(struct ieee80211_hw *hw,
759 struct sk_buff *skb, u32 ep_num) 759 struct sk_buff *skb, u32 ep_num)
760 { 760 {
761 struct rtl_priv *rtlpriv = rtl_priv(hw); 761 struct rtl_priv *rtlpriv = rtl_priv(hw);
762 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 762 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
763 struct urb *_urb; 763 struct urb *_urb;
764 764
765 WARN_ON(NULL == skb); 765 WARN_ON(NULL == skb);
766 _urb = usb_alloc_urb(0, GFP_ATOMIC); 766 _urb = usb_alloc_urb(0, GFP_ATOMIC);
767 if (!_urb) { 767 if (!_urb) {
768 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, 768 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
769 ("Can't allocate URB for bulk out!\n")); 769 ("Can't allocate URB for bulk out!\n"));
770 kfree_skb(skb); 770 kfree_skb(skb);
771 return NULL; 771 return NULL;
772 } 772 }
773 _rtl_install_trx_info(rtlusb, skb, ep_num); 773 _rtl_install_trx_info(rtlusb, skb, ep_num);
774 usb_fill_bulk_urb(_urb, rtlusb->udev, usb_sndbulkpipe(rtlusb->udev, 774 usb_fill_bulk_urb(_urb, rtlusb->udev, usb_sndbulkpipe(rtlusb->udev,
775 ep_num), skb->data, skb->len, _rtl_tx_complete, skb); 775 ep_num), skb->data, skb->len, _rtl_tx_complete, skb);
776 _urb->transfer_flags |= URB_ZERO_PACKET; 776 _urb->transfer_flags |= URB_ZERO_PACKET;
777 return _urb; 777 return _urb;
778 } 778 }
779 779
780 static void _rtl_usb_transmit(struct ieee80211_hw *hw, struct sk_buff *skb, 780 static void _rtl_usb_transmit(struct ieee80211_hw *hw, struct sk_buff *skb,
781 enum rtl_txq qnum) 781 enum rtl_txq qnum)
782 { 782 {
783 struct rtl_priv *rtlpriv = rtl_priv(hw); 783 struct rtl_priv *rtlpriv = rtl_priv(hw);
784 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 784 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
785 u32 ep_num; 785 u32 ep_num;
786 struct urb *_urb = NULL; 786 struct urb *_urb = NULL;
787 struct sk_buff *_skb = NULL; 787 struct sk_buff *_skb = NULL;
788 struct sk_buff_head *skb_list; 788 struct sk_buff_head *skb_list;
789 struct usb_anchor *urb_list; 789 struct usb_anchor *urb_list;
790 790
791 WARN_ON(NULL == rtlusb->usb_tx_aggregate_hdl); 791 WARN_ON(NULL == rtlusb->usb_tx_aggregate_hdl);
792 if (unlikely(IS_USB_STOP(rtlusb))) { 792 if (unlikely(IS_USB_STOP(rtlusb))) {
793 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG, 793 RT_TRACE(rtlpriv, COMP_USB, DBG_EMERG,
794 ("USB device is stopping...\n")); 794 ("USB device is stopping...\n"));
795 kfree_skb(skb); 795 kfree_skb(skb);
796 return; 796 return;
797 } 797 }
798 ep_num = rtlusb->ep_map.ep_mapping[qnum]; 798 ep_num = rtlusb->ep_map.ep_mapping[qnum];
799 skb_list = &rtlusb->tx_skb_queue[ep_num]; 799 skb_list = &rtlusb->tx_skb_queue[ep_num];
800 _skb = skb; 800 _skb = skb;
801 _urb = _rtl_usb_tx_urb_setup(hw, _skb, ep_num); 801 _urb = _rtl_usb_tx_urb_setup(hw, _skb, ep_num);
802 if (unlikely(!_urb)) { 802 if (unlikely(!_urb)) {
803 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 803 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
804 ("Can't allocate urb. Drop skb!\n")); 804 ("Can't allocate urb. Drop skb!\n"));
805 return; 805 return;
806 } 806 }
807 urb_list = &rtlusb->tx_pending[ep_num]; 807 urb_list = &rtlusb->tx_pending[ep_num];
808 _rtl_submit_tx_urb(hw, _urb); 808 _rtl_submit_tx_urb(hw, _urb);
809 } 809 }
810 810
811 static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw, struct sk_buff *skb, 811 static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw, struct sk_buff *skb,
812 u16 hw_queue) 812 u16 hw_queue)
813 { 813 {
814 struct rtl_priv *rtlpriv = rtl_priv(hw); 814 struct rtl_priv *rtlpriv = rtl_priv(hw);
815 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 815 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
816 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 816 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
817 struct rtl_tx_desc *pdesc = NULL; 817 struct rtl_tx_desc *pdesc = NULL;
818 struct rtl_tcb_desc tcb_desc; 818 struct rtl_tcb_desc tcb_desc;
819 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); 819 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
820 __le16 fc = hdr->frame_control; 820 __le16 fc = hdr->frame_control;
821 u8 *pda_addr = hdr->addr1; 821 u8 *pda_addr = hdr->addr1;
822 /* ssn */ 822 /* ssn */
823 u8 *qc = NULL; 823 u8 *qc = NULL;
824 u8 tid = 0; 824 u8 tid = 0;
825 u16 seq_number = 0; 825 u16 seq_number = 0;
826 826
827 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); 827 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
828 if (ieee80211_is_auth(fc)) { 828 if (ieee80211_is_auth(fc)) {
829 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, ("MAC80211_LINKING\n")); 829 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, ("MAC80211_LINKING\n"));
830 rtl_ips_nic_on(hw); 830 rtl_ips_nic_on(hw);
831 } 831 }
832 832
833 if (rtlpriv->psc.sw_ps_enabled) { 833 if (rtlpriv->psc.sw_ps_enabled) {
834 if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) && 834 if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) &&
835 !ieee80211_has_pm(fc)) 835 !ieee80211_has_pm(fc))
836 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); 836 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
837 } 837 }
838 838
839 rtl_action_proc(hw, skb, true); 839 rtl_action_proc(hw, skb, true);
840 if (is_multicast_ether_addr(pda_addr)) 840 if (is_multicast_ether_addr(pda_addr))
841 rtlpriv->stats.txbytesmulticast += skb->len; 841 rtlpriv->stats.txbytesmulticast += skb->len;
842 else if (is_broadcast_ether_addr(pda_addr)) 842 else if (is_broadcast_ether_addr(pda_addr))
843 rtlpriv->stats.txbytesbroadcast += skb->len; 843 rtlpriv->stats.txbytesbroadcast += skb->len;
844 else 844 else
845 rtlpriv->stats.txbytesunicast += skb->len; 845 rtlpriv->stats.txbytesunicast += skb->len;
846 if (ieee80211_is_data_qos(fc)) { 846 if (ieee80211_is_data_qos(fc)) {
847 qc = ieee80211_get_qos_ctl(hdr); 847 qc = ieee80211_get_qos_ctl(hdr);
848 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 848 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
849 seq_number = (le16_to_cpu(hdr->seq_ctrl) & 849 seq_number = (le16_to_cpu(hdr->seq_ctrl) &
850 IEEE80211_SCTL_SEQ) >> 4; 850 IEEE80211_SCTL_SEQ) >> 4;
851 seq_number += 1; 851 seq_number += 1;
852 seq_number <<= 4; 852 seq_number <<= 4;
853 } 853 }
854 rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, info, skb, 854 rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, info, skb,
855 hw_queue, &tcb_desc); 855 hw_queue, &tcb_desc);
856 if (!ieee80211_has_morefrags(hdr->frame_control)) { 856 if (!ieee80211_has_morefrags(hdr->frame_control)) {
857 if (qc) 857 if (qc)
858 mac->tids[tid].seq_number = seq_number; 858 mac->tids[tid].seq_number = seq_number;
859 } 859 }
860 if (ieee80211_is_data(fc)) 860 if (ieee80211_is_data(fc))
861 rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX); 861 rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX);
862 } 862 }
863 863
864 static int rtl_usb_tx(struct ieee80211_hw *hw, struct sk_buff *skb, 864 static int rtl_usb_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
865 struct rtl_tcb_desc *dummy) 865 struct rtl_tcb_desc *dummy)
866 { 866 {
867 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 867 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
868 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 868 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
869 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); 869 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
870 __le16 fc = hdr->frame_control; 870 __le16 fc = hdr->frame_control;
871 u16 hw_queue; 871 u16 hw_queue;
872 872
873 if (unlikely(is_hal_stop(rtlhal))) 873 if (unlikely(is_hal_stop(rtlhal)))
874 goto err_free; 874 goto err_free;
875 hw_queue = rtlusb->usb_mq_to_hwq(fc, skb_get_queue_mapping(skb)); 875 hw_queue = rtlusb->usb_mq_to_hwq(fc, skb_get_queue_mapping(skb));
876 _rtl_usb_tx_preprocess(hw, skb, hw_queue); 876 _rtl_usb_tx_preprocess(hw, skb, hw_queue);
877 _rtl_usb_transmit(hw, skb, hw_queue); 877 _rtl_usb_transmit(hw, skb, hw_queue);
878 return NETDEV_TX_OK; 878 return NETDEV_TX_OK;
879 879
880 err_free: 880 err_free:
881 dev_kfree_skb_any(skb); 881 dev_kfree_skb_any(skb);
882 return NETDEV_TX_OK; 882 return NETDEV_TX_OK;
883 } 883 }
884 884
885 static bool rtl_usb_tx_chk_waitq_insert(struct ieee80211_hw *hw, 885 static bool rtl_usb_tx_chk_waitq_insert(struct ieee80211_hw *hw,
886 struct sk_buff *skb) 886 struct sk_buff *skb)
887 { 887 {
888 return false; 888 return false;
889 } 889 }
890 890
891 static struct rtl_intf_ops rtl_usb_ops = { 891 static struct rtl_intf_ops rtl_usb_ops = {
892 .adapter_start = rtl_usb_start, 892 .adapter_start = rtl_usb_start,
893 .adapter_stop = rtl_usb_stop, 893 .adapter_stop = rtl_usb_stop,
894 .adapter_tx = rtl_usb_tx, 894 .adapter_tx = rtl_usb_tx,
895 .waitq_insert = rtl_usb_tx_chk_waitq_insert, 895 .waitq_insert = rtl_usb_tx_chk_waitq_insert,
896 }; 896 };
897 897
898 int __devinit rtl_usb_probe(struct usb_interface *intf, 898 int __devinit rtl_usb_probe(struct usb_interface *intf,
899 const struct usb_device_id *id) 899 const struct usb_device_id *id)
900 { 900 {
901 int err; 901 int err;
902 struct ieee80211_hw *hw = NULL; 902 struct ieee80211_hw *hw = NULL;
903 struct rtl_priv *rtlpriv = NULL; 903 struct rtl_priv *rtlpriv = NULL;
904 struct usb_device *udev; 904 struct usb_device *udev;
905 struct rtl_usb_priv *usb_priv; 905 struct rtl_usb_priv *usb_priv;
906 906
907 hw = ieee80211_alloc_hw(sizeof(struct rtl_priv) + 907 hw = ieee80211_alloc_hw(sizeof(struct rtl_priv) +
908 sizeof(struct rtl_usb_priv), &rtl_ops); 908 sizeof(struct rtl_usb_priv), &rtl_ops);
909 if (!hw) { 909 if (!hw) {
910 RT_ASSERT(false, ("%s : ieee80211 alloc failed\n", __func__)); 910 RT_ASSERT(false, ("%s : ieee80211 alloc failed\n", __func__));
911 return -ENOMEM; 911 return -ENOMEM;
912 } 912 }
913 rtlpriv = hw->priv; 913 rtlpriv = hw->priv;
914 SET_IEEE80211_DEV(hw, &intf->dev); 914 SET_IEEE80211_DEV(hw, &intf->dev);
915 udev = interface_to_usbdev(intf); 915 udev = interface_to_usbdev(intf);
916 usb_get_dev(udev); 916 usb_get_dev(udev);
917 usb_priv = rtl_usbpriv(hw); 917 usb_priv = rtl_usbpriv(hw);
918 memset(usb_priv, 0, sizeof(*usb_priv)); 918 memset(usb_priv, 0, sizeof(*usb_priv));
919 usb_priv->dev.intf = intf; 919 usb_priv->dev.intf = intf;
920 usb_priv->dev.udev = udev; 920 usb_priv->dev.udev = udev;
921 usb_set_intfdata(intf, hw); 921 usb_set_intfdata(intf, hw);
922 /* init cfg & intf_ops */ 922 /* init cfg & intf_ops */
923 rtlpriv->rtlhal.interface = INTF_USB; 923 rtlpriv->rtlhal.interface = INTF_USB;
924 rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_info); 924 rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_info);
925 rtlpriv->intf_ops = &rtl_usb_ops; 925 rtlpriv->intf_ops = &rtl_usb_ops;
926 rtl_dbgp_flag_init(hw); 926 rtl_dbgp_flag_init(hw);
927 /* Init IO handler */ 927 /* Init IO handler */
928 _rtl_usb_io_handler_init(&udev->dev, hw); 928 _rtl_usb_io_handler_init(&udev->dev, hw);
929 rtlpriv->cfg->ops->read_chip_version(hw); 929 rtlpriv->cfg->ops->read_chip_version(hw);
930 /*like read eeprom and so on */ 930 /*like read eeprom and so on */
931 rtlpriv->cfg->ops->read_eeprom_info(hw); 931 rtlpriv->cfg->ops->read_eeprom_info(hw);
932 if (rtlpriv->cfg->ops->init_sw_vars(hw)) { 932 if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
933 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 933 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
934 ("Can't init_sw_vars.\n")); 934 ("Can't init_sw_vars.\n"));
935 goto error_out; 935 goto error_out;
936 } 936 }
937 rtlpriv->cfg->ops->init_sw_leds(hw); 937 rtlpriv->cfg->ops->init_sw_leds(hw);
938 err = _rtl_usb_init(hw); 938 err = _rtl_usb_init(hw);
939 err = _rtl_usb_init_sw(hw); 939 err = _rtl_usb_init_sw(hw);
940 /* Init mac80211 sw */ 940 /* Init mac80211 sw */
941 err = rtl_init_core(hw); 941 err = rtl_init_core(hw);
942 if (err) { 942 if (err) {
943 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 943 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
944 ("Can't allocate sw for mac80211.\n")); 944 ("Can't allocate sw for mac80211.\n"));
945 goto error_out; 945 goto error_out;
946 } 946 }
947 947
948 /*init rfkill */ 948 /*init rfkill */
949 /* rtl_init_rfkill(hw); */ 949 /* rtl_init_rfkill(hw); */
950 950
951 err = ieee80211_register_hw(hw); 951 err = ieee80211_register_hw(hw);
952 if (err) { 952 if (err) {
953 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, 953 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
954 ("Can't register mac80211 hw.\n")); 954 ("Can't register mac80211 hw.\n"));
955 goto error_out; 955 goto error_out;
956 } else { 956 } else {
957 rtlpriv->mac80211.mac80211_registered = 1; 957 rtlpriv->mac80211.mac80211_registered = 1;
958 } 958 }
959 set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status); 959 set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
960 return 0; 960 return 0;
961 error_out: 961 error_out:
962 rtl_deinit_core(hw); 962 rtl_deinit_core(hw);
963 _rtl_usb_io_handler_release(hw); 963 _rtl_usb_io_handler_release(hw);
964 ieee80211_free_hw(hw); 964 ieee80211_free_hw(hw);
965 usb_put_dev(udev); 965 usb_put_dev(udev);
966 return -ENODEV; 966 return -ENODEV;
967 } 967 }
968 EXPORT_SYMBOL(rtl_usb_probe); 968 EXPORT_SYMBOL(rtl_usb_probe);
969 969
970 void rtl_usb_disconnect(struct usb_interface *intf) 970 void rtl_usb_disconnect(struct usb_interface *intf)
971 { 971 {
972 struct ieee80211_hw *hw = usb_get_intfdata(intf); 972 struct ieee80211_hw *hw = usb_get_intfdata(intf);
973 struct rtl_priv *rtlpriv = rtl_priv(hw); 973 struct rtl_priv *rtlpriv = rtl_priv(hw);
974 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); 974 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
975 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 975 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
976 976
977 if (unlikely(!rtlpriv)) 977 if (unlikely(!rtlpriv))
978 return; 978 return;
979 /*ieee80211_unregister_hw will call ops_stop */ 979 /*ieee80211_unregister_hw will call ops_stop */
980 if (rtlmac->mac80211_registered == 1) { 980 if (rtlmac->mac80211_registered == 1) {
981 ieee80211_unregister_hw(hw); 981 ieee80211_unregister_hw(hw);
982 rtlmac->mac80211_registered = 0; 982 rtlmac->mac80211_registered = 0;
983 } else { 983 } else {
984 rtl_deinit_deferred_work(hw); 984 rtl_deinit_deferred_work(hw);
985 rtlpriv->intf_ops->adapter_stop(hw); 985 rtlpriv->intf_ops->adapter_stop(hw);
986 } 986 }
987 /*deinit rfkill */ 987 /*deinit rfkill */
988 /* rtl_deinit_rfkill(hw); */ 988 /* rtl_deinit_rfkill(hw); */
989 rtl_usb_deinit(hw); 989 rtl_usb_deinit(hw);
990 rtl_deinit_core(hw); 990 rtl_deinit_core(hw);
991 rtlpriv->cfg->ops->deinit_sw_leds(hw); 991 rtlpriv->cfg->ops->deinit_sw_leds(hw);
992 rtlpriv->cfg->ops->deinit_sw_vars(hw); 992 rtlpriv->cfg->ops->deinit_sw_vars(hw);
993 _rtl_usb_io_handler_release(hw); 993 _rtl_usb_io_handler_release(hw);
994 usb_put_dev(rtlusb->udev); 994 usb_put_dev(rtlusb->udev);
995 usb_set_intfdata(intf, NULL); 995 usb_set_intfdata(intf, NULL);
996 ieee80211_free_hw(hw); 996 ieee80211_free_hw(hw);
997 } 997 }
998 EXPORT_SYMBOL(rtl_usb_disconnect); 998 EXPORT_SYMBOL(rtl_usb_disconnect);
999 999
1000 int rtl_usb_suspend(struct usb_interface *pusb_intf, pm_message_t message) 1000 int rtl_usb_suspend(struct usb_interface *pusb_intf, pm_message_t message)
1001 { 1001 {
1002 return 0; 1002 return 0;
1003 } 1003 }
1004 EXPORT_SYMBOL(rtl_usb_suspend); 1004 EXPORT_SYMBOL(rtl_usb_suspend);
1005 1005
1006 int rtl_usb_resume(struct usb_interface *pusb_intf) 1006 int rtl_usb_resume(struct usb_interface *pusb_intf)
1007 { 1007 {
1008 return 0; 1008 return 0;
1009 } 1009 }
1010 EXPORT_SYMBOL(rtl_usb_resume); 1010 EXPORT_SYMBOL(rtl_usb_resume);
1011 1011