chipset.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. #ifndef CHIPSET_SOURCE
  42. #define CHIPSET_SOURCE
  43. /*====================================================================*
  44. * custom header files;
  45. *--------------------------------------------------------------------*/
  46. #include "../plc/plc.h"
  47. #include "../tools/types.h"
  48. #include "../tools/symbol.h"
  49. /*====================================================================*
  50. *
  51. * char const * chipsetname (uint8_t MDEVICE)
  52. *
  53. * plc.h
  54. *
  55. * return the ASCII name string associated with the MDEVICE_CLASS
  56. * field in the VS_SW_VER.CNF message; this field represents the
  57. * chipset family or class of device;
  58. *
  59. * the MDEVICE_CLASS field was named MDEVICEID at one time;
  60. *
  61. * Contributor(s):
  62. * Charles Maier
  63. *
  64. *--------------------------------------------------------------------*/
  65. char const * chipsetname (uint8_t MDEVICE_CLASS)
  66. {
  67. static const struct _type_ chipname [] =
  68. {
  69. {
  70. CHIPSET_UNKNOWN,
  71. "UNKNOWN"
  72. },
  73. {
  74. CHIPSET_INT6000A1,
  75. "INT6000"
  76. },
  77. {
  78. CHIPSET_INT6300A0,
  79. "INT6300"
  80. },
  81. {
  82. CHIPSET_INT6400A0,
  83. "INT6400"
  84. },
  85. {
  86. CHIPSET_AR7400A0,
  87. " AR7400"
  88. },
  89. {
  90. CHIPSET_AR6405A0,
  91. " AR6405"
  92. },
  93. {
  94. CHIPSET_PANTHER_LYNX,
  95. "PANTHER/LYNX"
  96. },
  97. {
  98. CHIPSET_QCA7450A0,
  99. "QCA7450"
  100. },
  101. {
  102. CHIPSET_QCA7451A0,
  103. "QCA7451"
  104. },
  105. {
  106. CHIPSET_QCA7420A0,
  107. "QCA7420"
  108. },
  109. {
  110. CHIPSET_QCA6410A0,
  111. "QCA6410"
  112. },
  113. {
  114. CHIPSET_QCA7000A0,
  115. "QCA7000"
  116. },
  117. {
  118. CHIPSET_QCA7005A0,
  119. "QCA7005"
  120. },
  121. {
  122. CHIPSET_QCA7500A0,
  123. "QCA7500"
  124. }
  125. };
  126. return (typename (chipname, SIZEOF (chipname), MDEVICE_CLASS, chipname [0].name));
  127. }
  128. /*====================================================================*
  129. *
  130. * void chipset (void const * memory);
  131. *
  132. * Chipset.h
  133. *
  134. * replace VS_SW_VER message MDEVICE_CLASS field with correct value;
  135. * the MDEVICE_CLASS field was named MDEVICEID at one time;
  136. *
  137. * Atheros chipsets are identified by code in the VS_SW_VER vendor
  138. * specific management message; the chipset [] vector translates a
  139. * chipset code to a chipset name;
  140. *
  141. * the basic assumption is that the firmware always tells the truth
  142. * but the bootrom does not; because of engineering changes, the
  143. * firmware uses a different device identification scheme than that
  144. * used by the bootrom and that information appears in different
  145. * locations depending on the source of the VS_SW_VER confirmation;
  146. * see the Programmer's Guide for more information.
  147. *
  148. * INT6000 0x01 / 0x01 0x00000042 / NA
  149. * INT6300 0x01 / 0x02 0x00006300 / NA
  150. * INT6400 0x03 / 0x03 0x00006400 / NA
  151. * AR7400 0x03 / 0x04 0x00007400 / NA
  152. * AR6405 0x03 / 0x05 0x00006400 / NA
  153. * QCA7450 0x03 / 0x20 0x0F001D1A / NA
  154. * QCA7420 0x06 / 0x20 0x001CFCFC
  155. * QCA6410 0x06 / 0x21 0x001B58EC
  156. * QCA6411 0x06 / 0x21 0x001B58BC
  157. * QCA7000 0x06 / 0x22 0x001B589C
  158. * QCA7000 0x06 / 0x22 0x001B58DC
  159. * QCA7005 0x06 / 0x22 0x001B587C
  160. * QCA7500 0x06 / 0x30 0x001D4C0F
  161. *
  162. * some chipsets have have multiple STRAP field values; this is
  163. * not an error; there may be multiple versions of a chipset;
  164. *
  165. *--------------------------------------------------------------------*/
  166. void chipset (void const * memory)
  167. {
  168. #ifndef __GNUC__
  169. #pragma pack (push,1)
  170. #endif
  171. struct __packed vs_sw_ver_confirm
  172. {
  173. struct ethernet_hdr ethernet;
  174. struct qualcomm_hdr qualcomm;
  175. uint8_t MSTATUS;
  176. uint8_t MDEVICE_CLASS;
  177. uint8_t MVERLENGTH;
  178. char MVERSION [254];
  179. }
  180. * confirm = (struct vs_sw_ver_confirm *) (memory);
  181. struct __packed chipinfo
  182. {
  183. uint8_t RESVD;
  184. uint32_t STRAP;
  185. uint32_t STEP_NUMBER;
  186. }
  187. * chipinfo = (struct chipinfo *) (& confirm->MVERSION [64]);
  188. typedef struct __packed
  189. {
  190. uint32_t STRAP;
  191. uint8_t CLASS;
  192. uint8_t DEVICE;
  193. }
  194. chipdata;
  195. #ifndef __GNUC__
  196. #pragma pack (pop)
  197. #endif
  198. chipdata bootrom [] =
  199. {
  200. {
  201. 0x00000042,
  202. 0x01,
  203. CHIPSET_INT6000A1
  204. },
  205. {
  206. 0x00006300,
  207. 0x01,
  208. CHIPSET_INT6300A0
  209. },
  210. {
  211. 0x00006400,
  212. 0x03,
  213. CHIPSET_INT6400A0
  214. },
  215. {
  216. 0x00007400,
  217. 0x03,
  218. CHIPSET_AR7400A0
  219. },
  220. {
  221. 0x0F001D1A,
  222. 0x03,
  223. CHIPSET_QCA7450A0
  224. },
  225. {
  226. 0x0E001D1A,
  227. 0x03,
  228. CHIPSET_QCA7451A0
  229. },
  230. {
  231. 0x001CFC00,
  232. 0x05,
  233. CHIPSET_QCA7420A0
  234. },
  235. {
  236. 0x001CFCFC,
  237. 0x05,
  238. CHIPSET_QCA7420A0
  239. },
  240. {
  241. 0x001CFCFC,
  242. 0x06,
  243. CHIPSET_QCA7420A0
  244. },
  245. {
  246. 0x001B58EC,
  247. 0x06,
  248. CHIPSET_QCA6410A0
  249. },
  250. {
  251. 0x001B58BC,
  252. 0x06,
  253. CHIPSET_QCA6411A0
  254. },
  255. {
  256. 0x001B58DC,
  257. 0x06,
  258. CHIPSET_QCA7000A0
  259. },
  260. {
  261. 0x001B587C,
  262. 0x06,
  263. CHIPSET_QCA7005A0
  264. },
  265. {
  266. 0x001D4C00,
  267. 0x06,
  268. CHIPSET_QCA7500A0
  269. },
  270. {
  271. 0x001D4C0F,
  272. 0x06,
  273. CHIPSET_QCA7500A0
  274. }
  275. };
  276. chipdata firmware [] =
  277. {
  278. {
  279. 0x00000000,
  280. 0x01,
  281. CHIPSET_INT6000A1
  282. },
  283. {
  284. 0x00000000,
  285. 0x02,
  286. CHIPSET_INT6300A0
  287. },
  288. {
  289. 0x00000000,
  290. 0x03,
  291. CHIPSET_INT6400A0
  292. },
  293. {
  294. 0x00000000,
  295. 0x05,
  296. CHIPSET_AR6405A0
  297. },
  298. {
  299. 0x00000000,
  300. 0x04,
  301. CHIPSET_AR7400A0
  302. },
  303. {
  304. 0x0F001D1A,
  305. 0x20,
  306. CHIPSET_QCA7450A0
  307. },
  308. {
  309. 0x0E001D1A,
  310. 0x20,
  311. CHIPSET_QCA7451A0
  312. },
  313. {
  314. 0x001CFCFC,
  315. 0x20,
  316. CHIPSET_QCA7420A0
  317. },
  318. {
  319. 0x001B58EC,
  320. 0x21,
  321. CHIPSET_QCA6410A0
  322. },
  323. {
  324. 0x001B58BC,
  325. 0x21,
  326. CHIPSET_QCA6411A0
  327. },
  328. {
  329. 0x001B58DC,
  330. 0x22,
  331. CHIPSET_QCA7000A0
  332. },
  333. {
  334. 0x001D4C00,
  335. 0x30,
  336. CHIPSET_QCA7500A0
  337. },
  338. {
  339. 0x001D4C0F,
  340. 0x30,
  341. CHIPSET_QCA7500A0
  342. }
  343. };
  344. unsigned chip;
  345. if (! strcmp (confirm->MVERSION, "BootLoader"))
  346. {
  347. for (chip = 0; chip < SIZEOF (bootrom); chip++)
  348. {
  349. if (bootrom [chip].CLASS != confirm->MDEVICE_CLASS)
  350. {
  351. continue;
  352. }
  353. if (bootrom [chip].STRAP != LE32TOH (chipinfo->STRAP))
  354. {
  355. continue;
  356. }
  357. confirm->MDEVICE_CLASS = bootrom [chip].DEVICE;
  358. return;
  359. }
  360. }
  361. else
  362. {
  363. for (chip = 0; chip < SIZEOF (firmware); chip++)
  364. {
  365. if (firmware [chip].CLASS != confirm->MDEVICE_CLASS)
  366. {
  367. continue;
  368. }
  369. if (firmware [chip].STRAP < CHIPSET_PANTHER_LYNX)
  370. {
  371. confirm->MDEVICE_CLASS = firmware [chip].DEVICE;
  372. return;
  373. }
  374. chipinfo = (struct chipinfo *) (& confirm->MVERSION [64]);
  375. if (firmware [chip].STRAP == LE32TOH (chipinfo->STRAP))
  376. {
  377. confirm->MDEVICE_CLASS = firmware [chip].DEVICE;
  378. return;
  379. }
  380. chipinfo = (struct chipinfo *) (& confirm->MVERSION [128]);
  381. if (firmware [chip].STRAP == LE32TOH (chipinfo->STRAP))
  382. {
  383. confirm->MDEVICE_CLASS = firmware [chip].DEVICE;
  384. return;
  385. }
  386. chipinfo = (struct chipinfo *) (& confirm->MVERSION [253]);
  387. if (firmware [chip].STRAP == LE32TOH (chipinfo->STRAP))
  388. {
  389. confirm->MDEVICE_CLASS = firmware [chip].DEVICE;
  390. return;
  391. }
  392. }
  393. }
  394. return;
  395. }
  396. #endif