srom.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/string.h>
  18. #include <linux/io.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/crc8.h>
  21. #include <stdarg.h>
  22. #include <chipcommon.h>
  23. #include <brcmu_utils.h>
  24. #include "pub.h"
  25. #include "nicpci.h"
  26. #include "aiutils.h"
  27. #include "otp.h"
  28. #include "srom.h"
  29. #include "soc.h"
  30. /*
  31. * SROM CRC8 polynomial value:
  32. *
  33. * x^8 + x^7 +x^6 + x^4 + x^2 + 1
  34. */
  35. #define SROM_CRC8_POLY 0xAB
  36. /* Maximum srom: 6 Kilobits == 768 bytes */
  37. #define SROM_MAX 768
  38. /* PCI fields */
  39. #define PCI_F0DEVID 48
  40. #define SROM_WORDS 64
  41. #define SROM_SSID 2
  42. #define SROM_WL1LHMAXP 29
  43. #define SROM_WL1LPAB0 30
  44. #define SROM_WL1LPAB1 31
  45. #define SROM_WL1LPAB2 32
  46. #define SROM_WL1HPAB0 33
  47. #define SROM_WL1HPAB1 34
  48. #define SROM_WL1HPAB2 35
  49. #define SROM_MACHI_IL0 36
  50. #define SROM_MACMID_IL0 37
  51. #define SROM_MACLO_IL0 38
  52. #define SROM_MACHI_ET1 42
  53. #define SROM_MACMID_ET1 43
  54. #define SROM_MACLO_ET1 44
  55. #define SROM_BXARSSI2G 40
  56. #define SROM_BXARSSI5G 41
  57. #define SROM_TRI52G 42
  58. #define SROM_TRI5GHL 43
  59. #define SROM_RXPO52G 45
  60. #define SROM_AABREV 46
  61. /* Fields in AABREV */
  62. #define SROM_BR_MASK 0x00ff
  63. #define SROM_CC_MASK 0x0f00
  64. #define SROM_CC_SHIFT 8
  65. #define SROM_AA0_MASK 0x3000
  66. #define SROM_AA0_SHIFT 12
  67. #define SROM_AA1_MASK 0xc000
  68. #define SROM_AA1_SHIFT 14
  69. #define SROM_WL0PAB0 47
  70. #define SROM_WL0PAB1 48
  71. #define SROM_WL0PAB2 49
  72. #define SROM_LEDBH10 50
  73. #define SROM_LEDBH32 51
  74. #define SROM_WL10MAXP 52
  75. #define SROM_WL1PAB0 53
  76. #define SROM_WL1PAB1 54
  77. #define SROM_WL1PAB2 55
  78. #define SROM_ITT 56
  79. #define SROM_BFL 57
  80. #define SROM_BFL2 28
  81. #define SROM_AG10 58
  82. #define SROM_CCODE 59
  83. #define SROM_OPO 60
  84. #define SROM_CRCREV 63
  85. #define SROM4_WORDS 220
  86. #define SROM4_TXCHAIN_MASK 0x000f
  87. #define SROM4_RXCHAIN_MASK 0x00f0
  88. #define SROM4_SWITCH_MASK 0xff00
  89. /* Per-path fields */
  90. #define MAX_PATH_SROM 4
  91. #define SROM4_CRCREV 219
  92. /* SROM Rev 8: Make space for a 48word hardware header for PCIe rev >= 6.
  93. * This is acombined srom for both MIMO and SISO boards, usable in
  94. * the .130 4Kilobit OTP with hardware redundancy.
  95. */
  96. #define SROM8_BREV 65
  97. #define SROM8_BFL0 66
  98. #define SROM8_BFL1 67
  99. #define SROM8_BFL2 68
  100. #define SROM8_BFL3 69
  101. #define SROM8_MACHI 70
  102. #define SROM8_MACMID 71
  103. #define SROM8_MACLO 72
  104. #define SROM8_CCODE 73
  105. #define SROM8_REGREV 74
  106. #define SROM8_LEDBH10 75
  107. #define SROM8_LEDBH32 76
  108. #define SROM8_LEDDC 77
  109. #define SROM8_AA 78
  110. #define SROM8_AG10 79
  111. #define SROM8_AG32 80
  112. #define SROM8_TXRXC 81
  113. #define SROM8_BXARSSI2G 82
  114. #define SROM8_BXARSSI5G 83
  115. #define SROM8_TRI52G 84
  116. #define SROM8_TRI5GHL 85
  117. #define SROM8_RXPO52G 86
  118. #define SROM8_FEM2G 87
  119. #define SROM8_FEM5G 88
  120. #define SROM8_FEM_ANTSWLUT_MASK 0xf800
  121. #define SROM8_FEM_ANTSWLUT_SHIFT 11
  122. #define SROM8_FEM_TR_ISO_MASK 0x0700
  123. #define SROM8_FEM_TR_ISO_SHIFT 8
  124. #define SROM8_FEM_PDET_RANGE_MASK 0x00f8
  125. #define SROM8_FEM_PDET_RANGE_SHIFT 3
  126. #define SROM8_FEM_EXTPA_GAIN_MASK 0x0006
  127. #define SROM8_FEM_EXTPA_GAIN_SHIFT 1
  128. #define SROM8_FEM_TSSIPOS_MASK 0x0001
  129. #define SROM8_FEM_TSSIPOS_SHIFT 0
  130. #define SROM8_THERMAL 89
  131. /* Temp sense related entries */
  132. #define SROM8_MPWR_RAWTS 90
  133. #define SROM8_TS_SLP_OPT_CORRX 91
  134. /* FOC: freiquency offset correction, HWIQ: H/W IOCAL enable,
  135. * IQSWP: IQ CAL swap disable */
  136. #define SROM8_FOC_HWIQ_IQSWP 92
  137. /* Temperature delta for PHY calibration */
  138. #define SROM8_PHYCAL_TEMPDELTA 93
  139. /* Per-path offsets & fields */
  140. #define SROM8_PATH0 96
  141. #define SROM8_PATH1 112
  142. #define SROM8_PATH2 128
  143. #define SROM8_PATH3 144
  144. #define SROM8_2G_ITT_MAXP 0
  145. #define SROM8_2G_PA 1
  146. #define SROM8_5G_ITT_MAXP 4
  147. #define SROM8_5GLH_MAXP 5
  148. #define SROM8_5G_PA 6
  149. #define SROM8_5GL_PA 9
  150. #define SROM8_5GH_PA 12
  151. /* All the miriad power offsets */
  152. #define SROM8_2G_CCKPO 160
  153. #define SROM8_2G_OFDMPO 161
  154. #define SROM8_5G_OFDMPO 163
  155. #define SROM8_5GL_OFDMPO 165
  156. #define SROM8_5GH_OFDMPO 167
  157. #define SROM8_2G_MCSPO 169
  158. #define SROM8_5G_MCSPO 177
  159. #define SROM8_5GL_MCSPO 185
  160. #define SROM8_5GH_MCSPO 193
  161. #define SROM8_CDDPO 201
  162. #define SROM8_STBCPO 202
  163. #define SROM8_BW40PO 203
  164. #define SROM8_BWDUPPO 204
  165. /* SISO PA parameters are in the path0 spaces */
  166. #define SROM8_SISO 96
  167. /* Legacy names for SISO PA paramters */
  168. #define SROM8_W0_ITTMAXP (SROM8_SISO + SROM8_2G_ITT_MAXP)
  169. #define SROM8_W0_PAB0 (SROM8_SISO + SROM8_2G_PA)
  170. #define SROM8_W0_PAB1 (SROM8_SISO + SROM8_2G_PA + 1)
  171. #define SROM8_W0_PAB2 (SROM8_SISO + SROM8_2G_PA + 2)
  172. #define SROM8_W1_ITTMAXP (SROM8_SISO + SROM8_5G_ITT_MAXP)
  173. #define SROM8_W1_MAXP_LCHC (SROM8_SISO + SROM8_5GLH_MAXP)
  174. #define SROM8_W1_PAB0 (SROM8_SISO + SROM8_5G_PA)
  175. #define SROM8_W1_PAB1 (SROM8_SISO + SROM8_5G_PA + 1)
  176. #define SROM8_W1_PAB2 (SROM8_SISO + SROM8_5G_PA + 2)
  177. #define SROM8_W1_PAB0_LC (SROM8_SISO + SROM8_5GL_PA)
  178. #define SROM8_W1_PAB1_LC (SROM8_SISO + SROM8_5GL_PA + 1)
  179. #define SROM8_W1_PAB2_LC (SROM8_SISO + SROM8_5GL_PA + 2)
  180. #define SROM8_W1_PAB0_HC (SROM8_SISO + SROM8_5GH_PA)
  181. #define SROM8_W1_PAB1_HC (SROM8_SISO + SROM8_5GH_PA + 1)
  182. #define SROM8_W1_PAB2_HC (SROM8_SISO + SROM8_5GH_PA + 2)
  183. /* SROM REV 9 */
  184. #define SROM9_2GPO_CCKBW20 160
  185. #define SROM9_2GPO_CCKBW20UL 161
  186. #define SROM9_2GPO_LOFDMBW20 162
  187. #define SROM9_2GPO_LOFDMBW20UL 164
  188. #define SROM9_5GLPO_LOFDMBW20 166
  189. #define SROM9_5GLPO_LOFDMBW20UL 168
  190. #define SROM9_5GMPO_LOFDMBW20 170
  191. #define SROM9_5GMPO_LOFDMBW20UL 172
  192. #define SROM9_5GHPO_LOFDMBW20 174
  193. #define SROM9_5GHPO_LOFDMBW20UL 176
  194. #define SROM9_2GPO_MCSBW20 178
  195. #define SROM9_2GPO_MCSBW20UL 180
  196. #define SROM9_2GPO_MCSBW40 182
  197. #define SROM9_5GLPO_MCSBW20 184
  198. #define SROM9_5GLPO_MCSBW20UL 186
  199. #define SROM9_5GLPO_MCSBW40 188
  200. #define SROM9_5GMPO_MCSBW20 190
  201. #define SROM9_5GMPO_MCSBW20UL 192
  202. #define SROM9_5GMPO_MCSBW40 194
  203. #define SROM9_5GHPO_MCSBW20 196
  204. #define SROM9_5GHPO_MCSBW20UL 198
  205. #define SROM9_5GHPO_MCSBW40 200
  206. #define SROM9_PO_MCS32 202
  207. #define SROM9_PO_LOFDM40DUP 203
  208. /* SROM flags (see sromvar_t) */
  209. /* value continues as described by the next entry */
  210. #define SRFL_MORE 1
  211. #define SRFL_NOFFS 2 /* value bits can't be all one's */
  212. #define SRFL_PRHEX 4 /* value is in hexdecimal format */
  213. #define SRFL_PRSIGN 8 /* value is in signed decimal format */
  214. #define SRFL_CCODE 0x10 /* value is in country code format */
  215. #define SRFL_ETHADDR 0x20 /* value is an Ethernet address */
  216. #define SRFL_LEDDC 0x40 /* value is an LED duty cycle */
  217. /* do not generate a nvram param, entry is for mfgc */
  218. #define SRFL_NOVAR 0x80
  219. /* Max. nvram variable table size */
  220. #define MAXSZ_NVRAM_VARS 4096
  221. /*
  222. * indicates type of value.
  223. */
  224. enum brcms_srom_var_type {
  225. BRCMS_SROM_STRING,
  226. BRCMS_SROM_SNUMBER,
  227. BRCMS_SROM_UNUMBER
  228. };
  229. /*
  230. * storage type for srom variable.
  231. *
  232. * var_list: for linked list operations.
  233. * varid: identifier of the variable.
  234. * var_type: type of variable.
  235. * buf: variable value when var_type == BRCMS_SROM_STRING.
  236. * uval: unsigned variable value when var_type == BRCMS_SROM_UNUMBER.
  237. * sval: signed variable value when var_type == BRCMS_SROM_SNUMBER.
  238. */
  239. struct brcms_srom_list_head {
  240. struct list_head var_list;
  241. enum brcms_srom_id varid;
  242. enum brcms_srom_var_type var_type;
  243. union {
  244. char buf[0];
  245. u32 uval;
  246. s32 sval;
  247. };
  248. };
  249. struct brcms_sromvar {
  250. enum brcms_srom_id varid;
  251. u32 revmask;
  252. u32 flags;
  253. u16 off;
  254. u16 mask;
  255. };
  256. struct brcms_varbuf {
  257. char *base; /* pointer to buffer base */
  258. char *buf; /* pointer to current position */
  259. unsigned int size; /* current (residual) size in bytes */
  260. };
  261. /*
  262. * Assumptions:
  263. * - Ethernet address spans across 3 consecutive words
  264. *
  265. * Table rules:
  266. * - Add multiple entries next to each other if a value spans across multiple
  267. * words (even multiple fields in the same word) with each entry except the
  268. * last having it's SRFL_MORE bit set.
  269. * - Ethernet address entry does not follow above rule and must not have
  270. * SRFL_MORE bit set. Its SRFL_ETHADDR bit implies it takes multiple words.
  271. * - The last entry's name field must be NULL to indicate the end of the table.
  272. * Other entries must have non-NULL name.
  273. */
  274. static const struct brcms_sromvar pci_sromvars[] = {
  275. {BRCMS_SROM_DEVID, 0xffffff00, SRFL_PRHEX | SRFL_NOVAR, PCI_F0DEVID,
  276. 0xffff},
  277. {BRCMS_SROM_BOARDREV, 0xffffff00, SRFL_PRHEX, SROM8_BREV, 0xffff},
  278. {BRCMS_SROM_BOARDFLAGS, 0xffffff00, SRFL_PRHEX | SRFL_MORE, SROM8_BFL0,
  279. 0xffff},
  280. {BRCMS_SROM_CONT, 0, 0, SROM8_BFL1, 0xffff},
  281. {BRCMS_SROM_BOARDFLAGS2, 0xffffff00, SRFL_PRHEX | SRFL_MORE, SROM8_BFL2,
  282. 0xffff},
  283. {BRCMS_SROM_CONT, 0, 0, SROM8_BFL3, 0xffff},
  284. {BRCMS_SROM_BOARDTYPE, 0xfffffffc, SRFL_PRHEX, SROM_SSID, 0xffff},
  285. {BRCMS_SROM_BOARDNUM, 0xffffff00, 0, SROM8_MACLO, 0xffff},
  286. {BRCMS_SROM_REGREV, 0xffffff00, 0, SROM8_REGREV, 0x00ff},
  287. {BRCMS_SROM_LEDBH0, 0xffffff00, SRFL_NOFFS, SROM8_LEDBH10, 0x00ff},
  288. {BRCMS_SROM_LEDBH1, 0xffffff00, SRFL_NOFFS, SROM8_LEDBH10, 0xff00},
  289. {BRCMS_SROM_LEDBH2, 0xffffff00, SRFL_NOFFS, SROM8_LEDBH32, 0x00ff},
  290. {BRCMS_SROM_LEDBH3, 0xffffff00, SRFL_NOFFS, SROM8_LEDBH32, 0xff00},
  291. {BRCMS_SROM_PA0B0, 0xffffff00, SRFL_PRHEX, SROM8_W0_PAB0, 0xffff},
  292. {BRCMS_SROM_PA0B1, 0xffffff00, SRFL_PRHEX, SROM8_W0_PAB1, 0xffff},
  293. {BRCMS_SROM_PA0B2, 0xffffff00, SRFL_PRHEX, SROM8_W0_PAB2, 0xffff},
  294. {BRCMS_SROM_PA0ITSSIT, 0xffffff00, 0, SROM8_W0_ITTMAXP, 0xff00},
  295. {BRCMS_SROM_PA0MAXPWR, 0xffffff00, 0, SROM8_W0_ITTMAXP, 0x00ff},
  296. {BRCMS_SROM_OPO, 0xffffff00, 0, SROM8_2G_OFDMPO, 0x00ff},
  297. {BRCMS_SROM_AA2G, 0xffffff00, 0, SROM8_AA, 0x00ff},
  298. {BRCMS_SROM_AA5G, 0xffffff00, 0, SROM8_AA, 0xff00},
  299. {BRCMS_SROM_AG0, 0xffffff00, 0, SROM8_AG10, 0x00ff},
  300. {BRCMS_SROM_AG1, 0xffffff00, 0, SROM8_AG10, 0xff00},
  301. {BRCMS_SROM_AG2, 0xffffff00, 0, SROM8_AG32, 0x00ff},
  302. {BRCMS_SROM_AG3, 0xffffff00, 0, SROM8_AG32, 0xff00},
  303. {BRCMS_SROM_PA1B0, 0xffffff00, SRFL_PRHEX, SROM8_W1_PAB0, 0xffff},
  304. {BRCMS_SROM_PA1B1, 0xffffff00, SRFL_PRHEX, SROM8_W1_PAB1, 0xffff},
  305. {BRCMS_SROM_PA1B2, 0xffffff00, SRFL_PRHEX, SROM8_W1_PAB2, 0xffff},
  306. {BRCMS_SROM_PA1LOB0, 0xffffff00, SRFL_PRHEX, SROM8_W1_PAB0_LC, 0xffff},
  307. {BRCMS_SROM_PA1LOB1, 0xffffff00, SRFL_PRHEX, SROM8_W1_PAB1_LC, 0xffff},
  308. {BRCMS_SROM_PA1LOB2, 0xffffff00, SRFL_PRHEX, SROM8_W1_PAB2_LC, 0xffff},
  309. {BRCMS_SROM_PA1HIB0, 0xffffff00, SRFL_PRHEX, SROM8_W1_PAB0_HC, 0xffff},
  310. {BRCMS_SROM_PA1HIB1, 0xffffff00, SRFL_PRHEX, SROM8_W1_PAB1_HC, 0xffff},
  311. {BRCMS_SROM_PA1HIB2, 0xffffff00, SRFL_PRHEX, SROM8_W1_PAB2_HC, 0xffff},
  312. {BRCMS_SROM_PA1ITSSIT, 0xffffff00, 0, SROM8_W1_ITTMAXP, 0xff00},
  313. {BRCMS_SROM_PA1MAXPWR, 0xffffff00, 0, SROM8_W1_ITTMAXP, 0x00ff},
  314. {BRCMS_SROM_PA1LOMAXPWR, 0xffffff00, 0, SROM8_W1_MAXP_LCHC, 0xff00},
  315. {BRCMS_SROM_PA1HIMAXPWR, 0xffffff00, 0, SROM8_W1_MAXP_LCHC, 0x00ff},
  316. {BRCMS_SROM_BXA2G, 0xffffff00, 0, SROM8_BXARSSI2G, 0x1800},
  317. {BRCMS_SROM_RSSISAV2G, 0xffffff00, 0, SROM8_BXARSSI2G, 0x0700},
  318. {BRCMS_SROM_RSSISMC2G, 0xffffff00, 0, SROM8_BXARSSI2G, 0x00f0},
  319. {BRCMS_SROM_RSSISMF2G, 0xffffff00, 0, SROM8_BXARSSI2G, 0x000f},
  320. {BRCMS_SROM_BXA5G, 0xffffff00, 0, SROM8_BXARSSI5G, 0x1800},
  321. {BRCMS_SROM_RSSISAV5G, 0xffffff00, 0, SROM8_BXARSSI5G, 0x0700},
  322. {BRCMS_SROM_RSSISMC5G, 0xffffff00, 0, SROM8_BXARSSI5G, 0x00f0},
  323. {BRCMS_SROM_RSSISMF5G, 0xffffff00, 0, SROM8_BXARSSI5G, 0x000f},
  324. {BRCMS_SROM_TRI2G, 0xffffff00, 0, SROM8_TRI52G, 0x00ff},
  325. {BRCMS_SROM_TRI5G, 0xffffff00, 0, SROM8_TRI52G, 0xff00},
  326. {BRCMS_SROM_TRI5GL, 0xffffff00, 0, SROM8_TRI5GHL, 0x00ff},
  327. {BRCMS_SROM_TRI5GH, 0xffffff00, 0, SROM8_TRI5GHL, 0xff00},
  328. {BRCMS_SROM_RXPO2G, 0xffffff00, SRFL_PRSIGN, SROM8_RXPO52G, 0x00ff},
  329. {BRCMS_SROM_RXPO5G, 0xffffff00, SRFL_PRSIGN, SROM8_RXPO52G, 0xff00},
  330. {BRCMS_SROM_TXCHAIN, 0xffffff00, SRFL_NOFFS, SROM8_TXRXC,
  331. SROM4_TXCHAIN_MASK},
  332. {BRCMS_SROM_RXCHAIN, 0xffffff00, SRFL_NOFFS, SROM8_TXRXC,
  333. SROM4_RXCHAIN_MASK},
  334. {BRCMS_SROM_ANTSWITCH, 0xffffff00, SRFL_NOFFS, SROM8_TXRXC,
  335. SROM4_SWITCH_MASK},
  336. {BRCMS_SROM_TSSIPOS2G, 0xffffff00, 0, SROM8_FEM2G,
  337. SROM8_FEM_TSSIPOS_MASK},
  338. {BRCMS_SROM_EXTPAGAIN2G, 0xffffff00, 0, SROM8_FEM2G,
  339. SROM8_FEM_EXTPA_GAIN_MASK},
  340. {BRCMS_SROM_PDETRANGE2G, 0xffffff00, 0, SROM8_FEM2G,
  341. SROM8_FEM_PDET_RANGE_MASK},
  342. {BRCMS_SROM_TRISO2G, 0xffffff00, 0, SROM8_FEM2G, SROM8_FEM_TR_ISO_MASK},
  343. {BRCMS_SROM_ANTSWCTL2G, 0xffffff00, 0, SROM8_FEM2G,
  344. SROM8_FEM_ANTSWLUT_MASK},
  345. {BRCMS_SROM_TSSIPOS5G, 0xffffff00, 0, SROM8_FEM5G,
  346. SROM8_FEM_TSSIPOS_MASK},
  347. {BRCMS_SROM_EXTPAGAIN5G, 0xffffff00, 0, SROM8_FEM5G,
  348. SROM8_FEM_EXTPA_GAIN_MASK},
  349. {BRCMS_SROM_PDETRANGE5G, 0xffffff00, 0, SROM8_FEM5G,
  350. SROM8_FEM_PDET_RANGE_MASK},
  351. {BRCMS_SROM_TRISO5G, 0xffffff00, 0, SROM8_FEM5G, SROM8_FEM_TR_ISO_MASK},
  352. {BRCMS_SROM_ANTSWCTL5G, 0xffffff00, 0, SROM8_FEM5G,
  353. SROM8_FEM_ANTSWLUT_MASK},
  354. {BRCMS_SROM_TEMPTHRESH, 0xffffff00, 0, SROM8_THERMAL, 0xff00},
  355. {BRCMS_SROM_TEMPOFFSET, 0xffffff00, 0, SROM8_THERMAL, 0x00ff},
  356. {BRCMS_SROM_CCODE, 0xffffff00, SRFL_CCODE, SROM8_CCODE, 0xffff},
  357. {BRCMS_SROM_MACADDR, 0xffffff00, SRFL_ETHADDR, SROM8_MACHI, 0xffff},
  358. {BRCMS_SROM_LEDDC, 0xffffff00, SRFL_NOFFS | SRFL_LEDDC, SROM8_LEDDC,
  359. 0xffff},
  360. {BRCMS_SROM_RAWTEMPSENSE, 0xffffff00, SRFL_PRHEX, SROM8_MPWR_RAWTS,
  361. 0x01ff},
  362. {BRCMS_SROM_MEASPOWER, 0xffffff00, SRFL_PRHEX, SROM8_MPWR_RAWTS,
  363. 0xfe00},
  364. {BRCMS_SROM_TEMPSENSE_SLOPE, 0xffffff00, SRFL_PRHEX,
  365. SROM8_TS_SLP_OPT_CORRX, 0x00ff},
  366. {BRCMS_SROM_TEMPCORRX, 0xffffff00, SRFL_PRHEX, SROM8_TS_SLP_OPT_CORRX,
  367. 0xfc00},
  368. {BRCMS_SROM_TEMPSENSE_OPTION, 0xffffff00, SRFL_PRHEX,
  369. SROM8_TS_SLP_OPT_CORRX, 0x0300},
  370. {BRCMS_SROM_FREQOFFSET_CORR, 0xffffff00, SRFL_PRHEX,
  371. SROM8_FOC_HWIQ_IQSWP, 0x000f},
  372. {BRCMS_SROM_IQCAL_SWP_DIS, 0xffffff00, SRFL_PRHEX, SROM8_FOC_HWIQ_IQSWP,
  373. 0x0010},
  374. {BRCMS_SROM_HW_IQCAL_EN, 0xffffff00, SRFL_PRHEX, SROM8_FOC_HWIQ_IQSWP,
  375. 0x0020},
  376. {BRCMS_SROM_PHYCAL_TEMPDELTA, 0xffffff00, 0, SROM8_PHYCAL_TEMPDELTA,
  377. 0x00ff},
  378. {BRCMS_SROM_CCK2GPO, 0x00000100, 0, SROM8_2G_CCKPO, 0xffff},
  379. {BRCMS_SROM_OFDM2GPO, 0x00000100, SRFL_MORE, SROM8_2G_OFDMPO, 0xffff},
  380. {BRCMS_SROM_CONT, 0, 0, SROM8_2G_OFDMPO + 1, 0xffff},
  381. {BRCMS_SROM_OFDM5GPO, 0x00000100, SRFL_MORE, SROM8_5G_OFDMPO, 0xffff},
  382. {BRCMS_SROM_CONT, 0, 0, SROM8_5G_OFDMPO + 1, 0xffff},
  383. {BRCMS_SROM_OFDM5GLPO, 0x00000100, SRFL_MORE, SROM8_5GL_OFDMPO, 0xffff},
  384. {BRCMS_SROM_CONT, 0, 0, SROM8_5GL_OFDMPO + 1, 0xffff},
  385. {BRCMS_SROM_OFDM5GHPO, 0x00000100, SRFL_MORE, SROM8_5GH_OFDMPO, 0xffff},
  386. {BRCMS_SROM_CONT, 0, 0, SROM8_5GH_OFDMPO + 1, 0xffff},
  387. {BRCMS_SROM_MCS2GPO0, 0x00000100, 0, SROM8_2G_MCSPO, 0xffff},
  388. {BRCMS_SROM_MCS2GPO1, 0x00000100, 0, SROM8_2G_MCSPO + 1, 0xffff},
  389. {BRCMS_SROM_MCS2GPO2, 0x00000100, 0, SROM8_2G_MCSPO + 2, 0xffff},
  390. {BRCMS_SROM_MCS2GPO3, 0x00000100, 0, SROM8_2G_MCSPO + 3, 0xffff},
  391. {BRCMS_SROM_MCS2GPO4, 0x00000100, 0, SROM8_2G_MCSPO + 4, 0xffff},
  392. {BRCMS_SROM_MCS2GPO5, 0x00000100, 0, SROM8_2G_MCSPO + 5, 0xffff},
  393. {BRCMS_SROM_MCS2GPO6, 0x00000100, 0, SROM8_2G_MCSPO + 6, 0xffff},
  394. {BRCMS_SROM_MCS2GPO7, 0x00000100, 0, SROM8_2G_MCSPO + 7, 0xffff},
  395. {BRCMS_SROM_MCS5GPO0, 0x00000100, 0, SROM8_5G_MCSPO, 0xffff},
  396. {BRCMS_SROM_MCS5GPO1, 0x00000100, 0, SROM8_5G_MCSPO + 1, 0xffff},
  397. {BRCMS_SROM_MCS5GPO2, 0x00000100, 0, SROM8_5G_MCSPO + 2, 0xffff},
  398. {BRCMS_SROM_MCS5GPO3, 0x00000100, 0, SROM8_5G_MCSPO + 3, 0xffff},
  399. {BRCMS_SROM_MCS5GPO4, 0x00000100, 0, SROM8_5G_MCSPO + 4, 0xffff},
  400. {BRCMS_SROM_MCS5GPO5, 0x00000100, 0, SROM8_5G_MCSPO + 5, 0xffff},
  401. {BRCMS_SROM_MCS5GPO6, 0x00000100, 0, SROM8_5G_MCSPO + 6, 0xffff},
  402. {BRCMS_SROM_MCS5GPO7, 0x00000100, 0, SROM8_5G_MCSPO + 7, 0xffff},
  403. {BRCMS_SROM_MCS5GLPO0, 0x00000100, 0, SROM8_5GL_MCSPO, 0xffff},
  404. {BRCMS_SROM_MCS5GLPO1, 0x00000100, 0, SROM8_5GL_MCSPO + 1, 0xffff},
  405. {BRCMS_SROM_MCS5GLPO2, 0x00000100, 0, SROM8_5GL_MCSPO + 2, 0xffff},
  406. {BRCMS_SROM_MCS5GLPO3, 0x00000100, 0, SROM8_5GL_MCSPO + 3, 0xffff},
  407. {BRCMS_SROM_MCS5GLPO4, 0x00000100, 0, SROM8_5GL_MCSPO + 4, 0xffff},
  408. {BRCMS_SROM_MCS5GLPO5, 0x00000100, 0, SROM8_5GL_MCSPO + 5, 0xffff},
  409. {BRCMS_SROM_MCS5GLPO6, 0x00000100, 0, SROM8_5GL_MCSPO + 6, 0xffff},
  410. {BRCMS_SROM_MCS5GLPO7, 0x00000100, 0, SROM8_5GL_MCSPO + 7, 0xffff},
  411. {BRCMS_SROM_MCS5GHPO0, 0x00000100, 0, SROM8_5GH_MCSPO, 0xffff},
  412. {BRCMS_SROM_MCS5GHPO1, 0x00000100, 0, SROM8_5GH_MCSPO + 1, 0xffff},
  413. {BRCMS_SROM_MCS5GHPO2, 0x00000100, 0, SROM8_5GH_MCSPO + 2, 0xffff},
  414. {BRCMS_SROM_MCS5GHPO3, 0x00000100, 0, SROM8_5GH_MCSPO + 3, 0xffff},
  415. {BRCMS_SROM_MCS5GHPO4, 0x00000100, 0, SROM8_5GH_MCSPO + 4, 0xffff},
  416. {BRCMS_SROM_MCS5GHPO5, 0x00000100, 0, SROM8_5GH_MCSPO + 5, 0xffff},
  417. {BRCMS_SROM_MCS5GHPO6, 0x00000100, 0, SROM8_5GH_MCSPO + 6, 0xffff},
  418. {BRCMS_SROM_MCS5GHPO7, 0x00000100, 0, SROM8_5GH_MCSPO + 7, 0xffff},
  419. {BRCMS_SROM_CDDPO, 0x00000100, 0, SROM8_CDDPO, 0xffff},
  420. {BRCMS_SROM_STBCPO, 0x00000100, 0, SROM8_STBCPO, 0xffff},
  421. {BRCMS_SROM_BW40PO, 0x00000100, 0, SROM8_BW40PO, 0xffff},
  422. {BRCMS_SROM_BWDUPPO, 0x00000100, 0, SROM8_BWDUPPO, 0xffff},
  423. /* power per rate from sromrev 9 */
  424. {BRCMS_SROM_CCKBW202GPO, 0xfffffe00, 0, SROM9_2GPO_CCKBW20, 0xffff},
  425. {BRCMS_SROM_CCKBW20UL2GPO, 0xfffffe00, 0, SROM9_2GPO_CCKBW20UL, 0xffff},
  426. {BRCMS_SROM_LEGOFDMBW202GPO, 0xfffffe00, SRFL_MORE,
  427. SROM9_2GPO_LOFDMBW20, 0xffff},
  428. {BRCMS_SROM_CONT, 0, 0, SROM9_2GPO_LOFDMBW20 + 1, 0xffff},
  429. {BRCMS_SROM_LEGOFDMBW20UL2GPO, 0xfffffe00, SRFL_MORE,
  430. SROM9_2GPO_LOFDMBW20UL, 0xffff},
  431. {BRCMS_SROM_CONT, 0, 0, SROM9_2GPO_LOFDMBW20UL + 1, 0xffff},
  432. {BRCMS_SROM_LEGOFDMBW205GLPO, 0xfffffe00, SRFL_MORE,
  433. SROM9_5GLPO_LOFDMBW20, 0xffff},
  434. {BRCMS_SROM_CONT, 0, 0, SROM9_5GLPO_LOFDMBW20 + 1, 0xffff},
  435. {BRCMS_SROM_LEGOFDMBW20UL5GLPO, 0xfffffe00, SRFL_MORE,
  436. SROM9_5GLPO_LOFDMBW20UL, 0xffff},
  437. {BRCMS_SROM_CONT, 0, 0, SROM9_5GLPO_LOFDMBW20UL + 1, 0xffff},
  438. {BRCMS_SROM_LEGOFDMBW205GMPO, 0xfffffe00, SRFL_MORE,
  439. SROM9_5GMPO_LOFDMBW20, 0xffff},
  440. {BRCMS_SROM_CONT, 0, 0, SROM9_5GMPO_LOFDMBW20 + 1, 0xffff},
  441. {BRCMS_SROM_LEGOFDMBW20UL5GMPO, 0xfffffe00, SRFL_MORE,
  442. SROM9_5GMPO_LOFDMBW20UL, 0xffff},
  443. {BRCMS_SROM_CONT, 0, 0, SROM9_5GMPO_LOFDMBW20UL + 1, 0xffff},
  444. {BRCMS_SROM_LEGOFDMBW205GHPO, 0xfffffe00, SRFL_MORE,
  445. SROM9_5GHPO_LOFDMBW20, 0xffff},
  446. {BRCMS_SROM_CONT, 0, 0, SROM9_5GHPO_LOFDMBW20 + 1, 0xffff},
  447. {BRCMS_SROM_LEGOFDMBW20UL5GHPO, 0xfffffe00, SRFL_MORE,
  448. SROM9_5GHPO_LOFDMBW20UL, 0xffff},
  449. {BRCMS_SROM_CONT, 0, 0, SROM9_5GHPO_LOFDMBW20UL + 1, 0xffff},
  450. {BRCMS_SROM_MCSBW202GPO, 0xfffffe00, SRFL_MORE, SROM9_2GPO_MCSBW20,
  451. 0xffff},
  452. {BRCMS_SROM_CONT, 0, 0, SROM9_2GPO_MCSBW20 + 1, 0xffff},
  453. {BRCMS_SROM_MCSBW20UL2GPO, 0xfffffe00, SRFL_MORE, SROM9_2GPO_MCSBW20UL,
  454. 0xffff},
  455. {BRCMS_SROM_CONT, 0, 0, SROM9_2GPO_MCSBW20UL + 1, 0xffff},
  456. {BRCMS_SROM_MCSBW402GPO, 0xfffffe00, SRFL_MORE, SROM9_2GPO_MCSBW40,
  457. 0xffff},
  458. {BRCMS_SROM_CONT, 0, 0, SROM9_2GPO_MCSBW40 + 1, 0xffff},
  459. {BRCMS_SROM_MCSBW205GLPO, 0xfffffe00, SRFL_MORE, SROM9_5GLPO_MCSBW20,
  460. 0xffff},
  461. {BRCMS_SROM_CONT, 0, 0, SROM9_5GLPO_MCSBW20 + 1, 0xffff},
  462. {BRCMS_SROM_MCSBW20UL5GLPO, 0xfffffe00, SRFL_MORE,
  463. SROM9_5GLPO_MCSBW20UL, 0xffff},
  464. {BRCMS_SROM_CONT, 0, 0, SROM9_5GLPO_MCSBW20UL + 1, 0xffff},
  465. {BRCMS_SROM_MCSBW405GLPO, 0xfffffe00, SRFL_MORE, SROM9_5GLPO_MCSBW40,
  466. 0xffff},
  467. {BRCMS_SROM_CONT, 0, 0, SROM9_5GLPO_MCSBW40 + 1, 0xffff},
  468. {BRCMS_SROM_MCSBW205GMPO, 0xfffffe00, SRFL_MORE, SROM9_5GMPO_MCSBW20,
  469. 0xffff},
  470. {BRCMS_SROM_CONT, 0, 0, SROM9_5GMPO_MCSBW20 + 1, 0xffff},
  471. {BRCMS_SROM_MCSBW20UL5GMPO, 0xfffffe00, SRFL_MORE,
  472. SROM9_5GMPO_MCSBW20UL, 0xffff},
  473. {BRCMS_SROM_CONT, 0, 0, SROM9_5GMPO_MCSBW20UL + 1, 0xffff},
  474. {BRCMS_SROM_MCSBW405GMPO, 0xfffffe00, SRFL_MORE, SROM9_5GMPO_MCSBW40,
  475. 0xffff},
  476. {BRCMS_SROM_CONT, 0, 0, SROM9_5GMPO_MCSBW40 + 1, 0xffff},
  477. {BRCMS_SROM_MCSBW205GHPO, 0xfffffe00, SRFL_MORE, SROM9_5GHPO_MCSBW20,
  478. 0xffff},
  479. {BRCMS_SROM_CONT, 0, 0, SROM9_5GHPO_MCSBW20 + 1, 0xffff},
  480. {BRCMS_SROM_MCSBW20UL5GHPO, 0xfffffe00, SRFL_MORE,
  481. SROM9_5GHPO_MCSBW20UL, 0xffff},
  482. {BRCMS_SROM_CONT, 0, 0, SROM9_5GHPO_MCSBW20UL + 1, 0xffff},
  483. {BRCMS_SROM_MCSBW405GHPO, 0xfffffe00, SRFL_MORE, SROM9_5GHPO_MCSBW40,
  484. 0xffff},
  485. {BRCMS_SROM_CONT, 0, 0, SROM9_5GHPO_MCSBW40 + 1, 0xffff},
  486. {BRCMS_SROM_MCS32PO, 0xfffffe00, 0, SROM9_PO_MCS32, 0xffff},
  487. {BRCMS_SROM_LEGOFDM40DUPPO, 0xfffffe00, 0, SROM9_PO_LOFDM40DUP, 0xffff},
  488. {BRCMS_SROM_NULL, 0, 0, 0, 0}
  489. };
  490. static const struct brcms_sromvar perpath_pci_sromvars[] = {
  491. {BRCMS_SROM_MAXP2GA0, 0xffffff00, 0, SROM8_2G_ITT_MAXP, 0x00ff},
  492. {BRCMS_SROM_ITT2GA0, 0xffffff00, 0, SROM8_2G_ITT_MAXP, 0xff00},
  493. {BRCMS_SROM_ITT5GA0, 0xffffff00, 0, SROM8_5G_ITT_MAXP, 0xff00},
  494. {BRCMS_SROM_PA2GW0A0, 0xffffff00, SRFL_PRHEX, SROM8_2G_PA, 0xffff},
  495. {BRCMS_SROM_PA2GW1A0, 0xffffff00, SRFL_PRHEX, SROM8_2G_PA + 1, 0xffff},
  496. {BRCMS_SROM_PA2GW2A0, 0xffffff00, SRFL_PRHEX, SROM8_2G_PA + 2, 0xffff},
  497. {BRCMS_SROM_MAXP5GA0, 0xffffff00, 0, SROM8_5G_ITT_MAXP, 0x00ff},
  498. {BRCMS_SROM_MAXP5GHA0, 0xffffff00, 0, SROM8_5GLH_MAXP, 0x00ff},
  499. {BRCMS_SROM_MAXP5GLA0, 0xffffff00, 0, SROM8_5GLH_MAXP, 0xff00},
  500. {BRCMS_SROM_PA5GW0A0, 0xffffff00, SRFL_PRHEX, SROM8_5G_PA, 0xffff},
  501. {BRCMS_SROM_PA5GW1A0, 0xffffff00, SRFL_PRHEX, SROM8_5G_PA + 1, 0xffff},
  502. {BRCMS_SROM_PA5GW2A0, 0xffffff00, SRFL_PRHEX, SROM8_5G_PA + 2, 0xffff},
  503. {BRCMS_SROM_PA5GLW0A0, 0xffffff00, SRFL_PRHEX, SROM8_5GL_PA, 0xffff},
  504. {BRCMS_SROM_PA5GLW1A0, 0xffffff00, SRFL_PRHEX, SROM8_5GL_PA + 1,
  505. 0xffff},
  506. {BRCMS_SROM_PA5GLW2A0, 0xffffff00, SRFL_PRHEX, SROM8_5GL_PA + 2,
  507. 0xffff},
  508. {BRCMS_SROM_PA5GHW0A0, 0xffffff00, SRFL_PRHEX, SROM8_5GH_PA, 0xffff},
  509. {BRCMS_SROM_PA5GHW1A0, 0xffffff00, SRFL_PRHEX, SROM8_5GH_PA + 1,
  510. 0xffff},
  511. {BRCMS_SROM_PA5GHW2A0, 0xffffff00, SRFL_PRHEX, SROM8_5GH_PA + 2,
  512. 0xffff},
  513. {BRCMS_SROM_NULL, 0, 0, 0, 0}
  514. };
  515. /* crc table has the same contents for every device instance, so it can be
  516. * shared between devices. */
  517. static u8 brcms_srom_crc8_table[CRC8_TABLE_SIZE];
  518. static uint mask_shift(u16 mask)
  519. {
  520. uint i;
  521. for (i = 0; i < (sizeof(mask) << 3); i++) {
  522. if (mask & (1 << i))
  523. return i;
  524. }
  525. return 0;
  526. }
  527. static uint mask_width(u16 mask)
  528. {
  529. int i;
  530. for (i = (sizeof(mask) << 3) - 1; i >= 0; i--) {
  531. if (mask & (1 << i))
  532. return (uint) (i - mask_shift(mask) + 1);
  533. }
  534. return 0;
  535. }
  536. static inline void le16_to_cpu_buf(u16 *buf, uint nwords)
  537. {
  538. while (nwords--)
  539. *(buf + nwords) = le16_to_cpu(*(__le16 *)(buf + nwords));
  540. }
  541. static inline void cpu_to_le16_buf(u16 *buf, uint nwords)
  542. {
  543. while (nwords--)
  544. *(__le16 *)(buf + nwords) = cpu_to_le16(*(buf + nwords));
  545. }
  546. /*
  547. * convert binary srom data into linked list of srom variable items.
  548. */
  549. static int
  550. _initvars_srom_pci(u8 sromrev, u16 *srom, struct list_head *var_list)
  551. {
  552. struct brcms_srom_list_head *entry;
  553. enum brcms_srom_id id;
  554. u16 w;
  555. u32 val = 0;
  556. const struct brcms_sromvar *srv;
  557. uint width;
  558. uint flags;
  559. u32 sr = (1 << sromrev);
  560. uint p;
  561. uint pb = SROM8_PATH0;
  562. const uint psz = SROM8_PATH1 - SROM8_PATH0;
  563. /* first store the srom revision */
  564. entry = kzalloc(sizeof(struct brcms_srom_list_head), GFP_KERNEL);
  565. if (!entry)
  566. return -ENOMEM;
  567. entry->varid = BRCMS_SROM_REV;
  568. entry->var_type = BRCMS_SROM_UNUMBER;
  569. entry->uval = sromrev;
  570. list_add(&entry->var_list, var_list);
  571. for (srv = pci_sromvars; srv->varid != BRCMS_SROM_NULL; srv++) {
  572. enum brcms_srom_var_type type;
  573. u8 ea[ETH_ALEN];
  574. u8 extra_space = 0;
  575. if ((srv->revmask & sr) == 0)
  576. continue;
  577. flags = srv->flags;
  578. id = srv->varid;
  579. /* This entry is for mfgc only. Don't generate param for it, */
  580. if (flags & SRFL_NOVAR)
  581. continue;
  582. if (flags & SRFL_ETHADDR) {
  583. /*
  584. * stored in string format XX:XX:XX:XX:XX:XX (17 chars)
  585. */
  586. ea[0] = (srom[srv->off] >> 8) & 0xff;
  587. ea[1] = srom[srv->off] & 0xff;
  588. ea[2] = (srom[srv->off + 1] >> 8) & 0xff;
  589. ea[3] = srom[srv->off + 1] & 0xff;
  590. ea[4] = (srom[srv->off + 2] >> 8) & 0xff;
  591. ea[5] = srom[srv->off + 2] & 0xff;
  592. /* 17 characters + string terminator - union size */
  593. extra_space = 18 - sizeof(s32);
  594. type = BRCMS_SROM_STRING;
  595. } else {
  596. w = srom[srv->off];
  597. val = (w & srv->mask) >> mask_shift(srv->mask);
  598. width = mask_width(srv->mask);
  599. while (srv->flags & SRFL_MORE) {
  600. srv++;
  601. if (srv->off == 0)
  602. continue;
  603. w = srom[srv->off];
  604. val +=
  605. ((w & srv->mask) >> mask_shift(srv->
  606. mask)) <<
  607. width;
  608. width += mask_width(srv->mask);
  609. }
  610. if ((flags & SRFL_NOFFS)
  611. && ((int)val == (1 << width) - 1))
  612. continue;
  613. if (flags & SRFL_CCODE) {
  614. type = BRCMS_SROM_STRING;
  615. } else if (flags & SRFL_LEDDC) {
  616. /* LED Powersave duty cycle has to be scaled:
  617. *(oncount >> 24) (offcount >> 8)
  618. */
  619. u32 w32 = /* oncount */
  620. (((val >> 8) & 0xff) << 24) |
  621. /* offcount */
  622. (((val & 0xff)) << 8);
  623. type = BRCMS_SROM_UNUMBER;
  624. val = w32;
  625. } else if ((flags & SRFL_PRSIGN)
  626. && (val & (1 << (width - 1)))) {
  627. type = BRCMS_SROM_SNUMBER;
  628. val |= ~0 << width;
  629. } else
  630. type = BRCMS_SROM_UNUMBER;
  631. }
  632. entry = kzalloc(sizeof(struct brcms_srom_list_head) +
  633. extra_space, GFP_KERNEL);
  634. if (!entry)
  635. return -ENOMEM;
  636. entry->varid = id;
  637. entry->var_type = type;
  638. if (flags & SRFL_ETHADDR) {
  639. snprintf(entry->buf, 18, "%pM", ea);
  640. } else if (flags & SRFL_CCODE) {
  641. if (val == 0)
  642. entry->buf[0] = '\0';
  643. else
  644. snprintf(entry->buf, 3, "%c%c",
  645. (val >> 8), (val & 0xff));
  646. } else {
  647. entry->uval = val;
  648. }
  649. list_add(&entry->var_list, var_list);
  650. }
  651. for (p = 0; p < MAX_PATH_SROM; p++) {
  652. for (srv = perpath_pci_sromvars;
  653. srv->varid != BRCMS_SROM_NULL; srv++) {
  654. if ((srv->revmask & sr) == 0)
  655. continue;
  656. if (srv->flags & SRFL_NOVAR)
  657. continue;
  658. w = srom[pb + srv->off];
  659. val = (w & srv->mask) >> mask_shift(srv->mask);
  660. width = mask_width(srv->mask);
  661. /* Cheating: no per-path var is more than
  662. * 1 word */
  663. if ((srv->flags & SRFL_NOFFS)
  664. && ((int)val == (1 << width) - 1))
  665. continue;
  666. entry =
  667. kzalloc(sizeof(struct brcms_srom_list_head),
  668. GFP_KERNEL);
  669. if (!entry)
  670. return -ENOMEM;
  671. entry->varid = srv->varid+p;
  672. entry->var_type = BRCMS_SROM_UNUMBER;
  673. entry->uval = val;
  674. list_add(&entry->var_list, var_list);
  675. }
  676. pb += psz;
  677. }
  678. return 0;
  679. }
  680. /*
  681. * The crc check is done on a little-endian array, we need
  682. * to switch the bytes around before checking crc (and
  683. * then switch it back).
  684. */
  685. static int do_crc_check(u16 *buf, unsigned nwords)
  686. {
  687. u8 crc;
  688. cpu_to_le16_buf(buf, nwords);
  689. crc = crc8(brcms_srom_crc8_table, (void *)buf, nwords << 1, CRC8_INIT_VALUE);
  690. le16_to_cpu_buf(buf, nwords);
  691. return crc == CRC8_GOOD_VALUE(brcms_srom_crc8_table);
  692. }
  693. /*
  694. * Read in and validate sprom.
  695. * Return 0 on success, nonzero on error.
  696. */
  697. static int
  698. sprom_read_pci(struct si_pub *sih, u16 *buf, uint nwords, bool check_crc)
  699. {
  700. int err = 0;
  701. uint i;
  702. struct bcma_device *core;
  703. uint sprom_offset;
  704. /* determine core to read */
  705. if (ai_get_ccrev(sih) < 32) {
  706. core = ai_findcore(sih, BCMA_CORE_80211, 0);
  707. sprom_offset = PCI_BAR0_SPROM_OFFSET;
  708. } else {
  709. core = ai_findcore(sih, BCMA_CORE_CHIPCOMMON, 0);
  710. sprom_offset = CHIPCREGOFFS(sromotp);
  711. }
  712. /* read the sprom */
  713. for (i = 0; i < nwords; i++)
  714. buf[i] = bcma_read16(core, sprom_offset+i*2);
  715. if (buf[0] == 0xffff)
  716. /*
  717. * The hardware thinks that an srom that starts with
  718. * 0xffff is blank, regardless of the rest of the
  719. * content, so declare it bad.
  720. */
  721. return -ENODATA;
  722. if (check_crc && !do_crc_check(buf, nwords))
  723. err = -EIO;
  724. return err;
  725. }
  726. static int otp_read_pci(struct si_pub *sih, u16 *buf, uint nwords)
  727. {
  728. u8 *otp;
  729. uint sz = OTP_SZ_MAX / 2; /* size in words */
  730. int err = 0;
  731. otp = kzalloc(OTP_SZ_MAX, GFP_ATOMIC);
  732. if (otp == NULL)
  733. return -ENOMEM;
  734. err = otp_read_region(sih, OTP_HW_RGN, (u16 *) otp, &sz);
  735. sz = min_t(uint, sz, nwords);
  736. memcpy(buf, otp, sz * 2);
  737. kfree(otp);
  738. /* Check CRC */
  739. if (buf[0] == 0xffff)
  740. /* The hardware thinks that an srom that starts with 0xffff
  741. * is blank, regardless of the rest of the content, so declare
  742. * it bad.
  743. */
  744. return -ENODATA;
  745. /* fixup the endianness so crc8 will pass */
  746. cpu_to_le16_buf(buf, sz);
  747. if (crc8(brcms_srom_crc8_table, (u8 *) buf, sz * 2,
  748. CRC8_INIT_VALUE) != CRC8_GOOD_VALUE(brcms_srom_crc8_table))
  749. err = -EIO;
  750. else
  751. /* now correct the endianness of the byte array */
  752. le16_to_cpu_buf(buf, sz);
  753. return err;
  754. }
  755. /*
  756. * Initialize nonvolatile variable table from sprom.
  757. * Return 0 on success, nonzero on error.
  758. */
  759. int srom_var_init(struct si_pub *sih)
  760. {
  761. u16 *srom;
  762. u8 sromrev = 0;
  763. u32 sr;
  764. int err = 0;
  765. /*
  766. * Apply CRC over SROM content regardless SROM is present or not.
  767. */
  768. srom = kmalloc(SROM_MAX, GFP_ATOMIC);
  769. if (!srom)
  770. return -ENOMEM;
  771. crc8_populate_lsb(brcms_srom_crc8_table, SROM_CRC8_POLY);
  772. if (ai_is_sprom_available(sih)) {
  773. err = sprom_read_pci(sih, srom, SROM4_WORDS, true);
  774. if (err == 0)
  775. /* srom read and passed crc */
  776. /* top word of sprom contains version and crc8 */
  777. sromrev = srom[SROM4_CRCREV] & 0xff;
  778. } else {
  779. /* Use OTP if SPROM not available */
  780. err = otp_read_pci(sih, srom, SROM4_WORDS);
  781. if (err == 0)
  782. /* OTP only contain SROM rev8/rev9 for now */
  783. sromrev = srom[SROM4_CRCREV] & 0xff;
  784. }
  785. if (!err) {
  786. struct si_info *sii = (struct si_info *)sih;
  787. /* Bitmask for the sromrev */
  788. sr = 1 << sromrev;
  789. /*
  790. * srom version check: Current valid versions: 8, 9
  791. */
  792. if ((sr & 0x300) == 0) {
  793. err = -EINVAL;
  794. goto errout;
  795. }
  796. INIT_LIST_HEAD(&sii->var_list);
  797. /* parse SROM into name=value pairs. */
  798. err = _initvars_srom_pci(sromrev, srom, &sii->var_list);
  799. if (err)
  800. srom_free_vars(sih);
  801. }
  802. errout:
  803. kfree(srom);
  804. return err;
  805. }
  806. void srom_free_vars(struct si_pub *sih)
  807. {
  808. struct si_info *sii;
  809. struct brcms_srom_list_head *entry, *next;
  810. sii = (struct si_info *)sih;
  811. list_for_each_entry_safe(entry, next, &sii->var_list, var_list) {
  812. list_del(&entry->var_list);
  813. kfree(entry);
  814. }
  815. }
  816. /*
  817. * Search the name=value vars for a specific one and return its value.
  818. * Returns NULL if not found.
  819. */
  820. char *getvar(struct si_pub *sih, enum brcms_srom_id id)
  821. {
  822. struct si_info *sii;
  823. struct brcms_srom_list_head *entry;
  824. sii = (struct si_info *)sih;
  825. list_for_each_entry(entry, &sii->var_list, var_list)
  826. if (entry->varid == id)
  827. return &entry->buf[0];
  828. /* nothing found */
  829. return NULL;
  830. }
  831. /*
  832. * Search the vars for a specific one and return its value as
  833. * an integer. Returns 0 if not found.-
  834. */
  835. int getintvar(struct si_pub *sih, enum brcms_srom_id id)
  836. {
  837. struct si_info *sii;
  838. struct brcms_srom_list_head *entry;
  839. unsigned long res;
  840. sii = (struct si_info *)sih;
  841. list_for_each_entry(entry, &sii->var_list, var_list)
  842. if (entry->varid == id) {
  843. if (entry->var_type == BRCMS_SROM_SNUMBER ||
  844. entry->var_type == BRCMS_SROM_UNUMBER)
  845. return (int)entry->sval;
  846. else if (!kstrtoul(&entry->buf[0], 0, &res))
  847. return (int)res;
  848. }
  849. return 0;
  850. }