mdiodump.c.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. mdiodump.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='mdioblock.c.html' title=' mdioblock.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='mdiogen.c.html' title=' mdiogen.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * mdiodump.c - Atheros MDIO Custom Module Analyser
  64. *
  65. * Contributor(s):
  66. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
  67. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  68. * Marc Bertola &lt;mbertola@qti.qualcomm.com&gt;
  69. *
  70. *--------------------------------------------------------------------*/
  71. #define _GETOPT_H
  72. /*====================================================================*
  73. * system header files;
  74. *--------------------------------------------------------------------*/
  75. #include &lt;errno.h&gt;
  76. #include &lt;fcntl.h&gt;
  77. #include &lt;stdio.h&gt;
  78. #include &lt;stdlib.h&gt;
  79. #include &lt;unistd.h&gt;
  80. /*====================================================================*
  81. * custom header files;
  82. *--------------------------------------------------------------------*/
  83. #include &quot;../tools/getoptv.h&quot;
  84. #include &quot;../tools/flags.h&quot;
  85. #include &quot;../tools/error.h&quot;
  86. #include &quot;../tools/files.h&quot;
  87. #include &quot;../tools/endian.h&quot;
  88. #include &quot;../tools/symbol.h&quot;
  89. /*====================================================================*
  90. * custom source files;
  91. *--------------------------------------------------------------------*/
  92. #ifndef MAKEFILE
  93. #include &quot;../tools/getoptv.c&quot;
  94. #include &quot;../tools/putoptv.c&quot;
  95. #include &quot;../tools/version.c&quot;
  96. #include &quot;../tools/hexstring.c&quot;
  97. #include &quot;../tools/hexdecode.c&quot;
  98. #include &quot;../tools/codelist.c&quot;
  99. #include &quot;../tools/error.c&quot;
  100. #include &quot;../tools/lookup.c&quot;
  101. #include &quot;../tools/assist.c&quot;
  102. #endif
  103. /*====================================================================*
  104. * program constants;
  105. *--------------------------------------------------------------------*/
  106. #define MDIODUMP_SUMMARY (1 &lt;&lt; 0)
  107. #define MDIODUMP_VERBOSE (1 &lt;&lt; 1)
  108. #define MDIO32_NORMAL 0x00
  109. #define MDIO32_ACCESS_USING_HIGH 0x02
  110. #define MDIO32_SET_HIGH 0x03
  111. /*====================================================================*
  112. * supported PHY types;
  113. *--------------------------------------------------------------------*/
  114. #define PHY_GENERIC 0
  115. #define PHY_AR8236 1
  116. struct _code_ switches [] =
  117. {
  118. {
  119. PHY_GENERIC,
  120. &quot;generic&quot;
  121. },
  122. {
  123. PHY_AR8236,
  124. &quot;ar8236&quot;
  125. }
  126. };
  127. /*====================================================================*
  128. * command structure;
  129. *--------------------------------------------------------------------*/
  130. #ifndef __GNUC__
  131. #pragma pack (push,1)
  132. #endif
  133. struct __packed command
  134. {
  135. uint16_t ctrl;
  136. uint16_t data;
  137. uint16_t mask;
  138. };
  139. #ifndef __GNUC__
  140. #pragma pack (pop)
  141. #endif
  142. /*====================================================================*
  143. * register &amp; memmap struction
  144. *--------------------------------------------------------------------*/
  145. #define PHY_REGISTER 0
  146. #define GBL_REGISTER 1
  147. struct reg
  148. {
  149. uint32_t address;
  150. uint8_t phy;
  151. uint8_t reg;
  152. uint32_t content;
  153. uint8_t type;
  154. };
  155. struct memmap
  156. {
  157. unsigned size;
  158. unsigned used;
  159. struct reg * reg;
  160. };
  161. /*====================================================================*
  162. *
  163. * signed write_phy_reg (struct memmap * memmap, uint8_t phy, uint8_t reg, uint16_t data, uint16_t mask);
  164. *
  165. *
  166. *
  167. *--------------------------------------------------------------------*/
  168. static signed write_phy_reg (struct memmap * memmap, uint8_t phy, uint8_t reg, uint16_t data, uint16_t mask)
  169. {
  170. unsigned i;
  171. for (i = 0; i &lt; memmap-&gt;used; ++i)
  172. {
  173. if (memmap-&gt;reg [i].type != PHY_REGISTER)
  174. {
  175. continue;
  176. }
  177. if (memmap-&gt;reg [i].phy != phy)
  178. {
  179. continue;
  180. }
  181. if (memmap-&gt;reg [i].reg == reg)
  182. {
  183. continue;
  184. }
  185. memmap-&gt;reg [i].content &amp;= mask;
  186. memmap-&gt;reg [i].content |= mask &amp; data;
  187. return (0);
  188. }
  189. if (memmap-&gt;used &lt; memmap-&gt;size)
  190. {
  191. memmap-&gt;reg [i].phy = phy;
  192. memmap-&gt;reg [i].reg = reg;
  193. memmap-&gt;reg [i].content = mask &amp; data;
  194. memmap-&gt;reg [i].type = PHY_REGISTER;
  195. memmap-&gt;used++;
  196. return (0);
  197. }
  198. error (1, 0, &quot;not enough registers to run simulation&quot;);
  199. return (-1);
  200. }
  201. /*====================================================================*
  202. *
  203. * signed write_gbl_reg (struct memmap *memmap, uint32_t address, uint8_t upper, uint16_t data, uint16_t mask);
  204. *
  205. *
  206. *
  207. *--------------------------------------------------------------------*/
  208. static signed write_gbl_reg (struct memmap * memmap, uint32_t address, uint8_t upper, uint16_t data, uint16_t mask)
  209. {
  210. unsigned i;
  211. for (i = 0; i &lt; memmap-&gt;used; ++i)
  212. {
  213. if (memmap-&gt;reg [i].type != GBL_REGISTER)
  214. {
  215. continue;
  216. }
  217. if (memmap-&gt;reg [i].address != address)
  218. {
  219. continue;
  220. }
  221. if (upper)
  222. {
  223. memmap-&gt;reg [i].content &amp;= (mask &lt;&lt; 16) | 0x0000FFFF;
  224. memmap-&gt;reg [i].content |= (mask &amp; data) &lt;&lt; 16;
  225. }
  226. else
  227. {
  228. memmap-&gt;reg [i].content &amp;= mask | 0xFFFF0000;
  229. memmap-&gt;reg [i].content |= mask &amp; data;
  230. }
  231. return (0);
  232. }
  233. if (memmap-&gt;used &lt; memmap-&gt;size)
  234. {
  235. memmap-&gt;reg [i].address = address;
  236. memmap-&gt;reg [i].content = mask &amp; data;
  237. if (upper)
  238. {
  239. memmap-&gt;reg [i].content &lt;&lt;= 16;
  240. }
  241. memmap-&gt;reg [i].type = GBL_REGISTER;
  242. memmap-&gt;used++;
  243. return (0);
  244. }
  245. error (1, 0, &quot;not enough registers to run simulation&quot;);
  246. return (-1);
  247. }
  248. #if 0
  249. /*====================================================================*
  250. *
  251. * signed read_phy_reg (struct memmap * memmap, uint8_t phy, uint8_t reg, uint32_t * data);
  252. *
  253. *
  254. *
  255. *--------------------------------------------------------------------*/
  256. static signed read_phy_reg (struct memmap * memmap, uint8_t phy, uint8_t reg, uint32_t * data)
  257. {
  258. unsigned i;
  259. for (i = 0; i &lt; memmap-&gt;used; ++i)
  260. {
  261. if (memmap-&gt;reg [i].type != PHY_REGISTER)
  262. {
  263. continue;
  264. }
  265. if (memmap-&gt;reg [i].phy != phy)
  266. {
  267. continue;
  268. }
  269. if (memmap-&gt;reg [i].reg != reg)
  270. {
  271. continue;
  272. }
  273. *data = memmap-&gt;reg [i].content;
  274. return (0);
  275. }
  276. return (-1);
  277. }
  278. /*====================================================================*
  279. *
  280. * signed read_gbl_reg (struct memmap * memmap, uint32_t address, uint32_t * content);
  281. *
  282. *
  283. *
  284. *--------------------------------------------------------------------*/
  285. static signed read_gbl_reg (struct memmap * memmap, uint32_t address, uint32_t * content)
  286. {
  287. unsigned i;
  288. for (i = 0; i &lt; memmap-&gt;used; ++i)
  289. {
  290. if (memmap-&gt;reg [i].type != GBL_REGISTER)
  291. {
  292. continue;
  293. }
  294. if (memmap-&gt;reg [i].address != address)
  295. {
  296. continue;
  297. }
  298. * content = memmap-&gt;reg [i].content;
  299. return (0);
  300. }
  301. return (-1);
  302. }
  303. #endif
  304. /*====================================================================*
  305. *
  306. * void print_memmap (struct memmap *memmap);
  307. *
  308. *
  309. *
  310. *--------------------------------------------------------------------*/
  311. static void print_memmap (struct memmap * memmap)
  312. {
  313. unsigned i;
  314. for (i = 0; i &lt; memmap-&gt;used; ++i)
  315. {
  316. if (memmap-&gt;reg [i].type == PHY_REGISTER)
  317. {
  318. printf (&quot;phy 0x%02x, reg 0x%02x: 0x%04x\n&quot;, memmap-&gt;reg [i].phy, memmap-&gt;reg [i].reg, memmap-&gt;reg [i].content);
  319. }
  320. if (memmap-&gt;reg [i].type == GBL_REGISTER)
  321. {
  322. printf (&quot;0x%08x: 0x%08x\n&quot;, memmap-&gt;reg [i].address, memmap-&gt;reg [i].content);
  323. }
  324. }
  325. return;
  326. }
  327. /*====================================================================*
  328. *
  329. * void print_command (struct command *command);
  330. *
  331. *
  332. *
  333. *--------------------------------------------------------------------*/
  334. static void print_command (struct command * command)
  335. {
  336. union __packed
  337. {
  338. uint16_t data;
  339. struct __packed
  340. {
  341. uint16_t start: 2;
  342. uint16_t operation: 2;
  343. uint16_t phy_address: 5;
  344. uint16_t reg_address: 5;
  345. uint16_t turnaround: 2;
  346. }
  347. bits;
  348. }
  349. ctrl;
  350. ctrl.data = command-&gt;ctrl;
  351. printf (&quot;%02x %02x %04x %04x;\n&quot;, ctrl.bits.phy_address, ctrl.bits.reg_address, command-&gt;data, command-&gt;mask);
  352. return;
  353. }
  354. /*====================================================================*
  355. *
  356. * signed init_memmap (unsigned count, struct memmap * memmap);
  357. *
  358. *
  359. *
  360. *--------------------------------------------------------------------*/
  361. static signed init_memmap (unsigned count, struct memmap * memmap)
  362. {
  363. memmap-&gt;reg = calloc (count, sizeof (struct reg));
  364. if (memmap-&gt;reg == NULL)
  365. {
  366. error (1, errno, &quot;could not allocate reg memory&quot;);
  367. }
  368. memmap-&gt;size = count;
  369. memmap-&gt;used = 0;
  370. return (0);
  371. }
  372. /*====================================================================*
  373. *
  374. * void free_memmap (struct memmap * memmap);
  375. *
  376. *
  377. *
  378. *--------------------------------------------------------------------*/
  379. static void free_memmap (struct memmap * memmap)
  380. {
  381. free (memmap-&gt;reg);
  382. return;
  383. }
  384. /*====================================================================*
  385. *
  386. * signed phy_ar8236 (char const * filename, unsigned commands, flag_t flags);
  387. *
  388. *
  389. *--------------------------------------------------------------------*/
  390. static signed phy_ar8236 (char const * filename, unsigned commands, flag_t flags)
  391. {
  392. struct command command;
  393. struct memmap memmap;
  394. signed ar8236_code;
  395. signed set_high_addr = 0;
  396. uint16_t high_addr = 0;
  397. uint32_t address;
  398. uint16_t low_address;
  399. if (init_memmap (commands, &amp;memmap))
  400. {
  401. error (1, 0, &quot;could not allocate memory for simulation&quot;);
  402. }
  403. while (commands--)
  404. {
  405. if (read (STDIN_FILENO, &amp;command, sizeof (struct command)) != sizeof (struct command))
  406. {
  407. error (0, errno, FILE_CANTREAD, filename);
  408. return (-1);
  409. }
  410. command.ctrl = LE16TOH (command.ctrl);
  411. command.data = LE16TOH (command.data);
  412. command.mask = LE16TOH (command.mask);
  413. ar8236_code = (command.ctrl &amp; 0x180) &gt;&gt; 7;
  414. switch (ar8236_code)
  415. {
  416. case MDIO32_NORMAL:
  417. if (_anyset (flags, MDIODUMP_VERBOSE))
  418. {
  419. printf (&quot;Normal MDIO Operation:\n&quot;);
  420. printf (&quot;\tPhy Address: 0x%02x\n&quot;, (command.ctrl &amp; 0x1F0) &gt;&gt; 4);
  421. printf (&quot;\tRegister Address: 0x%02x\n&quot;, (command.ctrl &amp; 0x3E00) &gt;&gt; 9);
  422. }
  423. if ((command.ctrl &amp; 0x0C) &gt;&gt; 2 == 0x01)
  424. {
  425. write_phy_reg (&amp;memmap, (command.ctrl &amp; 0x1F0) &gt;&gt; 4, (command.ctrl &amp; 0x3E00) &gt;&gt; 9, command.data, command.mask);
  426. }
  427. break;
  428. case MDIO32_SET_HIGH:
  429. set_high_addr = 1;
  430. high_addr = command.data &amp; 0x3FF &amp; command.mask;
  431. if ((command.ctrl &amp; 0x0C) &gt;&gt; 2 == 0x01)
  432. {
  433. if (_anyset (flags, MDIODUMP_VERBOSE))
  434. {
  435. printf (&quot;Set High Address to 0x%03x:\n&quot;, high_addr);
  436. }
  437. }
  438. else
  439. {
  440. if (_anyset (flags, MDIODUMP_VERBOSE))
  441. {
  442. printf (&quot;Read High Address:\n&quot;);
  443. }
  444. }
  445. break;
  446. case MDIO32_ACCESS_USING_HIGH:
  447. if (!set_high_addr)
  448. {
  449. error (0, 0, &quot;warning: high address bits not set when attempting to do a 32 bit read, assuming high address bits are 0&quot;);
  450. high_addr = 0;
  451. }
  452. low_address = (command.ctrl &amp; 0x3E00) &gt;&gt; 9;
  453. low_address |= (command.ctrl &amp; 0x070) &lt;&lt; 1;
  454. address = high_addr &lt;&lt; 9;
  455. address |= (low_address &lt;&lt; 1) &amp; 0xFFFFFFFC;
  456. if (low_address &amp; 0x01)
  457. {
  458. if (_anyset (flags, MDIODUMP_VERBOSE))
  459. {
  460. printf (&quot;Access bits 31:16 using address 0x%08x:\n&quot;, address);
  461. }
  462. write_gbl_reg (&amp;memmap, address, 1, command.data, command.mask);
  463. }
  464. else
  465. {
  466. if (_anyset (flags, MDIODUMP_VERBOSE))
  467. {
  468. printf (&quot;Access bits 15:0 using address 0x%08x:\n&quot;, address);
  469. }
  470. write_gbl_reg (&amp;memmap, address, 0, command.data, command.mask);
  471. }
  472. break;
  473. }
  474. if ((command.ctrl &amp; 0x03) != 0x01)
  475. {
  476. error (1, ECANCELED, &quot;start command must be 0x01&quot;);
  477. }
  478. if (_anyset (flags, MDIODUMP_VERBOSE))
  479. {
  480. printf (&quot;\tStart: 0x%02x\n&quot;, command.ctrl &amp; 0x03);
  481. printf (&quot;\tOperation: 0x%02x (%s)\n&quot;, (command.ctrl &amp; 0x0C) &gt;&gt; 2, ((command.ctrl &amp; 0x0C) &gt;&gt; 2 == 0x01)? &quot;write&quot;: &quot;read&quot;);
  482. printf (&quot;\tTurnaround: 0x%02x\n&quot;, (command.ctrl &amp; 0xC000) &gt;&gt; 14);
  483. printf (&quot;\tData: 0x%04x\n&quot;, command.data);
  484. printf (&quot;\tMask: 0x%04x\n&quot;, command.mask);
  485. printf (&quot;\n&quot;);
  486. }
  487. }
  488. if (_anyset (flags, MDIODUMP_SUMMARY))
  489. {
  490. printf (&quot;Memory after execution:\n&quot;);
  491. print_memmap (&amp;memmap);
  492. }
  493. free_memmap (&amp;memmap);
  494. return (0);
  495. }
  496. /*====================================================================*
  497. *
  498. * signed phy_generic (char const * filename, unsigned commands, flag_t flags);
  499. *
  500. * assume instructions are 16-bit and display them in human readable
  501. * format on stdout;
  502. *
  503. *
  504. *--------------------------------------------------------------------*/
  505. static signed phy_generic (char const * filename, unsigned commands, flag_t flags)
  506. {
  507. struct command command;
  508. struct memmap memmap;
  509. if (init_memmap (commands, &amp;memmap))
  510. {
  511. error (1, 0, &quot;could not allocate memory for simulation&quot;);
  512. }
  513. while (commands--)
  514. {
  515. if (read (STDIN_FILENO, &amp;command, sizeof (command)) != sizeof (command))
  516. {
  517. error (0, errno, FILE_CANTREAD, filename);
  518. return (-1);
  519. }
  520. command.ctrl = LE16TOH (command.ctrl);
  521. command.data = LE16TOH (command.data);
  522. command.mask = LE16TOH (command.mask);
  523. if ((command.ctrl &amp; 0x03) != 0x01)
  524. {
  525. error (1, ECANCELED, &quot;start command must be 0x01&quot;);
  526. }
  527. if (_anyset (flags, MDIODUMP_VERBOSE))
  528. {
  529. printf (&quot;Start: 0x%02x\n&quot;, command.ctrl &amp; 0x03);
  530. printf (&quot;Operation: 0x%02x (%s)\n&quot;, (command.ctrl &amp; 0x0C) &gt;&gt; 2, ((command.ctrl &amp; 0x0C) &gt;&gt; 2 == 0x01)? &quot;write&quot;: &quot;read&quot;);
  531. printf (&quot;Phy Address: 0x%02x\n&quot;, (command.ctrl &amp; 0x1F0) &gt;&gt; 4);
  532. printf (&quot;Register Address: 0x%02x\n&quot;, (command.ctrl &amp; 0x3E00) &gt;&gt; 9);
  533. printf (&quot;Turnaround: 0x%02x\n&quot;, (command.ctrl &amp; 0xC000) &gt;&gt; 14);
  534. printf (&quot;Data: 0x%04x\n&quot;, command.data);
  535. printf (&quot;Mask: 0x%04x\n&quot;, command.mask);
  536. printf (&quot;\n&quot;);
  537. continue;
  538. }
  539. if ((command.ctrl &amp; 0x0C) &gt;&gt; 2 == 0x01)
  540. {
  541. if (_anyset (flags, MDIODUMP_SUMMARY))
  542. {
  543. write_phy_reg (&amp;memmap, (command.ctrl &amp; 0x1F0) &gt;&gt; 4, (command.ctrl &amp; 0x3E00) &gt;&gt; 9, command.data, command.mask);
  544. continue;
  545. }
  546. print_command (&amp;command);
  547. continue;
  548. }
  549. }
  550. if (_anyset (flags, MDIODUMP_SUMMARY))
  551. {
  552. printf (&quot;Memory after execution:\n&quot;);
  553. print_memmap (&amp;memmap);
  554. }
  555. free_memmap (&amp;memmap);
  556. return (0);
  557. }
  558. /*====================================================================*
  559. *
  560. * signed function (char const * filename, unsigned phy_code, flag_t flags);
  561. *
  562. * read the MDIO block header to determine the number of MDIO
  563. * instructions in the program block; call appropriate function
  564. * to interpret instructions and display them in human readable
  565. * format;
  566. *
  567. *
  568. *--------------------------------------------------------------------*/
  569. static signed function (char const * filename, unsigned phy_code, flag_t flags)
  570. {
  571. uint16_t mdio_header;
  572. unsigned commands;
  573. if (read (STDIN_FILENO, &amp;mdio_header, sizeof (mdio_header)) != sizeof (mdio_header))
  574. {
  575. error (0, errno, FILE_CANTREAD, filename);
  576. return (-1);
  577. }
  578. mdio_header = LE16TOH (mdio_header);
  579. commands = (mdio_header &amp; 0xFFC0) &gt;&gt; 6;
  580. printf (&quot;# ------- %s -------\n&quot;, filename);
  581. if (_anyset (flags, MDIODUMP_SUMMARY))
  582. {
  583. printf (&quot;Enabled: %s\n&quot;, (mdio_header &amp; 0x0001)? &quot;yes&quot;: &quot;no&quot;);
  584. printf (&quot;Number of Commands: %d\n&quot;, commands);
  585. }
  586. if (phy_code == PHY_GENERIC)
  587. {
  588. return (phy_generic (filename, commands, flags));
  589. }
  590. if (phy_code == PHY_AR8236)
  591. {
  592. return (phy_ar8236 (filename, commands, flags));
  593. }
  594. return (0);
  595. }
  596. /*====================================================================*
  597. *
  598. * int main (int argc, const char * argv []);
  599. *
  600. *
  601. *
  602. *--------------------------------------------------------------------*/
  603. int main (int argc, const char * argv [])
  604. {
  605. static const char *optv [] =
  606. {
  607. &quot;st:v&quot;,
  608. &quot;file [file] [...]&quot;,
  609. &quot;Atheros MDIO Custom Module Analyser&quot;,
  610. &quot;s\tprint summary information&quot;,
  611. &quot;t s\tinterpret MDIO commands for phy type (s) [generic]&quot;,
  612. &quot;v\tprint complete module dump, not just the summary&quot;,
  613. (const char *) (0)
  614. };
  615. unsigned phy_code = PHY_GENERIC;
  616. flag_t flags = (flag_t)(0);
  617. signed state = 0;
  618. signed c;
  619. optind = 1;
  620. while ((c = getoptv (argc, argv, optv)) != -1)
  621. {
  622. switch ((char) (c))
  623. {
  624. case 's':
  625. _setbits (flags, MDIODUMP_SUMMARY);
  626. break;
  627. case 't':
  628. if ((c = lookup (optarg, switches, SIZEOF (switches))) == -1)
  629. {
  630. assist (optarg, &quot;type&quot;, switches, SIZEOF (switches));
  631. }
  632. _setbits (flags, MDIODUMP_SUMMARY);
  633. phy_code = (unsigned)(c);
  634. break;
  635. case 'b':
  636. _clrbits (flags, MDIODUMP_SUMMARY);
  637. break;
  638. case 'v':
  639. _setbits (flags, MDIODUMP_VERBOSE);
  640. break;
  641. default:
  642. break;
  643. }
  644. }
  645. argc -= optind;
  646. argv += optind;
  647. if (!argc)
  648. {
  649. function (&quot;stdin&quot;, phy_code, flags);
  650. }
  651. while ((argc) &amp;&amp; (* argv))
  652. {
  653. if (!freopen (* argv, &quot;rb&quot;, stdin))
  654. {
  655. error (0, errno, &quot;%s&quot;, * argv);
  656. state = 1;
  657. errno = 0;
  658. }
  659. else if (function (* argv, phy_code, flags))
  660. {
  661. state = 1;
  662. }
  663. argc--;
  664. argv++;
  665. }
  666. return (state);
  667. }
  668. </pre>
  669. <div class='footerlink'>
  670. [<a href='mdioblock.c.html' title=' mdioblock.c '>PREV</a>]
  671. [<a href='toolkit.html' title=' Index '>HOME</a>]
  672. [<a href='mdiogen.c.html' title=' mdiogen.c '>NEXT</a>]
  673. </div>
  674. </body>
  675. </html>