MDUTrafficStats.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * signed MDUTrafficStats (struct plc * plc);
  11. *
  12. * plc.h
  13. *
  14. * See the Atheros HomePlug AV Firmware Technical Reference Manual
  15. * for more information;
  16. *
  17. * Contributor(s):
  18. * Charles Maier <cmaier@qca.qualcomm.com>
  19. *
  20. *--------------------------------------------------------------------*/
  21. #ifndef MDUTRAFFICSTATS_SOURCE
  22. #define MDUTRAFFICSTATS_SOURCE
  23. #include <stdint.h>
  24. #include <memory.h>
  25. #include "../plc/plc.h"
  26. #include "../tools/flags.h"
  27. #include "../tools/error.h"
  28. #include "../tools/memory.h"
  29. /*====================================================================*
  30. * constants;
  31. *--------------------------------------------------------------------*/
  32. #define CC1_RDRP (1 << 0)
  33. #define CC1_RJBR (1 << 1)
  34. #define CC1_RFRG (1 << 2)
  35. #define CC1_ROVR (1 << 3)
  36. #define CC1_RUND (1 << 4)
  37. #define CC1_RCSE (1 << 5)
  38. #define CC1_RCDE (1 << 6)
  39. #define CC1_RFLR (1 << 7)
  40. #define CC1_RALN (1 << 8)
  41. #define CC1_RXUO (1 << 9)
  42. #define CC1_RXPF (1 << 10)
  43. #define CC1_RXCF (1 << 11)
  44. #define CC1_RBCA (1 << 12)
  45. #define CC1_RMCA (1 << 13)
  46. #define CC1_RFCS (1 << 14)
  47. #define CC1_RPTK (1 << 15)
  48. #define CC1_TRMGV (1 << 25)
  49. #define CC1_TRMAX (1 << 26)
  50. #define CC1_TR1K (1 << 27)
  51. #define CC1_TR511 (1 << 28)
  52. #define CC1_TR255 (1 << 29)
  53. #define CC1_TR127 (1 << 30)
  54. #define CC1_TR64 (1 << 31)
  55. #define CC2_TDRP (1 << 0)
  56. #define CC2_TPFH (1 << 1)
  57. #define CC2_TNCL (1 << 2)
  58. #define CC2_TXCL (1 << 3)
  59. #define CC2_TLCL (1 << 4)
  60. #define CC2_TMCL (1 << 5)
  61. #define CC2_TSCL (1 << 6)
  62. #define CC2_TEDF (1 << 7)
  63. #define CC2_TDFR (1 << 8)
  64. #define CC2_TXPF (1 << 9)
  65. #define CC2_TBCA (1 << 10)
  66. #define CC2_TMCA (1 << 11)
  67. #define CC2_TPKT (1 << 12)
  68. #define CC2_TBYT (1 << 13)
  69. #define CC2_TFRG (1 << 14)
  70. #define CC2_TUND (1 << 15)
  71. #define CC2_TOVR (1 << 16)
  72. #define CC2_TXCF (1 << 17)
  73. #define CC2_TFCS (1 << 18)
  74. #define CC2_TJBR (1 << 19)
  75. #define MASTER_TX_RX (1 << 0)
  76. #define SLAVE_TX_RX (1 << 1)
  77. #define MASTER_FETCH (1 << 2)
  78. #define SLAVE_CLEAR (1 << 3)
  79. #define ETHERNET_STATS (1 << 4)
  80. /*====================================================================*
  81. * variables;
  82. *--------------------------------------------------------------------*/
  83. /*
  84. * Station Statistics;
  85. */
  86. #ifndef __GNUC__
  87. #pragma pack (push,1)
  88. #endif
  89. typedef struct __packed station_stats
  90. {
  91. uint8_t TEI;
  92. uint8_t RESULT_CODE;
  93. uint32_t UPSTREAM_MME_FRAMES;
  94. uint32_t UPSTREAM_ETH_FRAMES_UNI;
  95. uint32_t UPSTREAM_ETH_FRAMES_MULTI;
  96. uint32_t UPSTREAM_ETH_FRAMES_BROAD;
  97. uint32_t UPSTREAM_DROP_MME_FROM_HOST;
  98. uint32_t UPSTREAM_DROP_MME_FW_GEN;
  99. uint32_t UPSTREAM_DROP_ETH_FROM_HOST;
  100. uint32_t DOWNSTREAM_MME_FRAMES;
  101. uint32_t DOWNSTREAM_ETH_FRAMES_UNI;
  102. uint32_t DOWNSTREAM_ETH_FRAMES_MULTI;
  103. uint32_t DOWNSTREAM_ETH_FRAMES_BROAD;
  104. uint32_t DOWNSTREAM_DROP_MME_FROM_HOST;
  105. uint32_t DOWNSTREAM_DROP_MME_FW_GEN;
  106. uint32_t DOWNSTREAM_DROP_ETH_FROM_HOST;
  107. }
  108. statistics;
  109. #ifndef __GNUC__
  110. #pragma pack (pop)
  111. #endif
  112. /*
  113. * Ethernet Statistics;
  114. */
  115. #ifndef __GNUC__
  116. #pragma pack (push,1)
  117. #endif
  118. typedef struct __packed ethernet_stats
  119. {
  120. uint16_t HW_MODULE_TYPE;
  121. uint16_t HW_MODULE_STATS_LEN;
  122. uint32_t TR64;
  123. uint32_t TR127;
  124. uint32_t TR255;
  125. uint32_t TR511;
  126. uint32_t TR1K;
  127. uint32_t TRMAX;
  128. uint32_t TRMGV;
  129. uint32_t RBYT;
  130. uint32_t RBKT;
  131. uint32_t RFCS;
  132. uint32_t RFCA;
  133. uint32_t RBCA;
  134. uint32_t RXCF;
  135. uint32_t RXPF;
  136. uint32_t RXUO;
  137. uint32_t RALN;
  138. uint32_t RFLR;
  139. uint32_t RCDE;
  140. uint32_t RCSE;
  141. uint32_t RUND;
  142. uint32_t ROVR;
  143. uint32_t RFRG;
  144. uint32_t RJBR;
  145. uint32_t RDRP;
  146. uint32_t TBYT;
  147. uint32_t TPKT;
  148. uint32_t TMCA;
  149. uint32_t TBCA;
  150. uint32_t TXPF;
  151. uint32_t TDFR;
  152. uint32_t TEDF;
  153. uint32_t TSCL;
  154. uint32_t TMCL;
  155. uint32_t TLCL;
  156. uint32_t TXCL;
  157. uint32_t TNCL;
  158. uint32_t TPFH;
  159. uint32_t TDRP;
  160. uint32_t TJBR;
  161. uint32_t TFCS;
  162. uint32_t TXCF;
  163. uint32_t TOVR;
  164. uint32_t TUND;
  165. uint32_t TFRG;
  166. uint32_t CARRY1;
  167. uint32_t CARRY2;
  168. }
  169. ethernet_stats;
  170. #ifndef __GNUC__
  171. #pragma pack (pop)
  172. #endif
  173. /*
  174. * Classification Counters
  175. */
  176. #ifndef __GNUC__
  177. #pragma pack (push,1)
  178. #endif
  179. typedef struct __packed class_counters
  180. {
  181. uint16_t HW_MODULE_TYPE;
  182. uint16_t HW_MODULE_STATS_LEN;
  183. uint32_t IcvFailure;
  184. uint32_t InvalidMacFrame;
  185. uint32_t CorruptedMacFrameHeader;
  186. uint32_t MacDaCompareRule;
  187. uint32_t PriorityOrTHresholdLessWatermark;
  188. uint32_t OversizePacket;
  189. uint32_t Other;
  190. uint32_t SA_Learning;
  191. }
  192. class_counters;
  193. #ifndef __GNUC__
  194. #pragma pack (pop)
  195. #endif
  196. /*====================================================================*
  197. *
  198. * void StationStats (struct plc * plc, struct station_stats * stats);
  199. *
  200. * display station statistics in human readable format; there may
  201. * be one or more such functions depending on the audience; this
  202. * output was designed by the Product Verification Team in Ocala;
  203. *
  204. *--------------------------------------------------------------------*/
  205. static void StationStats (struct plc * plc, struct station_stats * stats)
  206. {
  207. fprintf (stderr, "TEI %d\n", stats->TEI);
  208. fprintf (stderr, "ERR 0x%02X\n", stats->RESULT_CODE);
  209. fprintf (stderr, "UPSTREAM_MME 0x%08X\n", stats->UPSTREAM_MME_FRAMES);
  210. fprintf (stderr, "UPSTREAM_UNICAST 0x%08X\n", stats->UPSTREAM_ETH_FRAMES_UNI);
  211. fprintf (stderr, "UPSTREAM_MULTICAST 0x%08X\n", stats->UPSTREAM_ETH_FRAMES_MULTI);
  212. fprintf (stderr, "UPSTREAM_BROADCAST 0x%08X\n", stats->UPSTREAM_ETH_FRAMES_BROAD);
  213. fprintf (stderr, "UPSTREAM_DROP_HOST_MME 0x%08X\n", stats->UPSTREAM_DROP_MME_FROM_HOST);
  214. fprintf (stderr, "UPSTREAM_DROP_FW_MME 0x%08X\n", stats->UPSTREAM_DROP_MME_FW_GEN);
  215. fprintf (stderr, "UPSTREAM_DROP_HOST_ETH 0x%08X\n", stats->UPSTREAM_DROP_ETH_FROM_HOST);
  216. fprintf (stderr, "DOWNSTREAM_MME 0x%08X\n", stats->DOWNSTREAM_MME_FRAMES);
  217. fprintf (stderr, "DOWNSTREAM_UNICAST 0x%08X\n", stats->DOWNSTREAM_ETH_FRAMES_UNI);
  218. fprintf (stderr, "DOWNSTREAM_MULTICAST 0x%08X\n", stats->DOWNSTREAM_ETH_FRAMES_MULTI);
  219. fprintf (stderr, "DOWNSTREAM_BROADCAST 0x%08X\n", stats->DOWNSTREAM_ETH_FRAMES_BROAD);
  220. fprintf (stderr, "DOWNSTREAM_DROP_HOST_MME 0x%08X\n", stats->DOWNSTREAM_DROP_MME_FROM_HOST);
  221. fprintf (stderr, "DOWNSTREAM_DROP_FW_MME 0x%08X\n", stats->DOWNSTREAM_DROP_MME_FW_GEN);
  222. fprintf (stderr, "DOWNSTREAM_DROP_HOST_ETH 0x%08X\n", stats->DOWNSTREAM_DROP_ETH_FROM_HOST);
  223. fprintf (stderr, "\n");
  224. return;
  225. }
  226. /*====================================================================*
  227. *
  228. * void EthernetStats (struct plc * plc, struct ethernet_stats * stats);
  229. *
  230. *--------------------------------------------------------------------*/
  231. static void EthernetStats (struct plc * plc, struct ethernet_stats * stats)
  232. {
  233. return;
  234. }
  235. /*====================================================================*
  236. *
  237. * void ClassificationCounters (struct plc * plc, struct class_counters * counters);
  238. *
  239. *--------------------------------------------------------------------*/
  240. #if 0
  241. static void ClassificationCounters (struct plc * plc, struct class_counters * counters)
  242. {
  243. return;
  244. }
  245. #endif
  246. /*====================================================================*
  247. *
  248. * signed MDUTrafficStats (struct plc * plc, uint8_t command, uint8_t session, uint8_t slave);
  249. *
  250. * request MDU traffic statistics using one VS_MDU_TRAFFIC_STATS
  251. * request type; different types of confirmations are returned
  252. * depending on the type of request;
  253. *
  254. *--------------------------------------------------------------------*/
  255. signed MDUTrafficStats (struct plc * plc, uint8_t command, uint8_t session, uint8_t slave)
  256. {
  257. struct channel * channel = (struct channel *) (plc->channel);
  258. struct message * message = (struct message *) (plc->message);
  259. #ifndef __GNUC__
  260. #pragma pack (push,1)
  261. #endif
  262. struct __packed vs_mdu_station_stats_request
  263. {
  264. struct ethernet_hdr ethernet;
  265. struct qualcomm_hdr qualcomm;
  266. uint8_t COMMAND;
  267. uint8_t SESSION;
  268. uint32_t SLAVE_BITMAP [8];
  269. }
  270. * request = (struct vs_mdu_station_stats_request *) (message);
  271. struct __packed vs_mdu_traffic_master_confirm
  272. {
  273. struct ethernet_hdr ethernet;
  274. struct qualcomm_hdr qualcomm;
  275. uint8_t COMMAND;
  276. uint8_t SESSION;
  277. uint16_t RESERVED;
  278. uint8_t NUM_SLAVES;
  279. uint8_t NUM_SLAVES_LEFT;
  280. uint16_t STATS_LEN;
  281. struct station_stats STATS [1];
  282. }
  283. * master_confirm = (struct vs_mdu_traffic_master_confirm *) (message);
  284. struct __packed vs_mdu_traffic_slave_confirm
  285. {
  286. struct ethernet_hdr ethernet;
  287. struct qualcomm_hdr qualcomm;
  288. uint8_t COMMAND;
  289. uint8_t SESSION;
  290. uint16_t STATS_LEN;
  291. struct station_stats STATS [1];
  292. }
  293. * slave_confirm = (struct vs_mdu_traffic_slave_confirm *) (message);
  294. #if 1
  295. struct __packed vs_eth_hardware_stats_confirm
  296. {
  297. struct ethernet_hdr ethernet;
  298. struct qualcomm_hdr qualcomm;
  299. uint8_t COMMAND;
  300. uint8_t SESSION;
  301. uint8_t CHIPTYPE;
  302. uint8_t STATUS;
  303. uint16_t STATS_LEN;
  304. struct ethernet_stats STATS [1];
  305. }
  306. * ether_confirm = (struct vs_eth_hardware_stats_confirm *) (message);
  307. #endif
  308. #ifndef __GNUC__
  309. #pragma pack (pop)
  310. #endif
  311. Request (plc, "Request MDU Traffic Statistics (1)");
  312. memset (message, 0, sizeof (* message));
  313. EthernetHeader (& request->ethernet, channel->peer, channel->host, channel->type);
  314. QualcommHeader (& request->qualcomm, 0, (VS_MDU_TRAFFIC_STATS | MMTYPE_REQ));
  315. request->COMMAND = command;
  316. request->SESSION = session;
  317. set32bitmap (request->SLAVE_BITMAP, slave);
  318. plc->packetsize = sizeof (* request);
  319. if (SendMME (plc) <= 0)
  320. {
  321. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  322. return (-1);
  323. }
  324. while (ReadMME (plc, 0, (VS_MDU_TRAFFIC_STATS | MMTYPE_CNF)) > 0)
  325. {
  326. if ((request->COMMAND > 0x00) && (request->COMMAND < 0x0020))
  327. {
  328. struct station_stats * stats;
  329. unsigned count;
  330. if (_anyset (request->COMMAND, MASTER_TX_RX | SLAVE_TX_RX))
  331. {
  332. stats = master_confirm->STATS;
  333. count = LE16TOH (master_confirm->STATS_LEN);
  334. }
  335. else
  336. {
  337. stats = slave_confirm->STATS;
  338. count = LE16TOH (slave_confirm->STATS_LEN);
  339. }
  340. while (count >= sizeof (struct station_stats))
  341. {
  342. StationStats (plc, stats++);
  343. count -= sizeof (struct station_stats);
  344. }
  345. continue;
  346. }
  347. if ((request->COMMAND >= 0x20) && (request->COMMAND < 0x24))
  348. {
  349. EthernetStats (plc, ether_confirm->STATS);
  350. continue;
  351. }
  352. if ((request->COMMAND >= 0x24) && (request->COMMAND < 0x28))
  353. {
  354. EthernetStats (plc, ether_confirm->STATS);
  355. continue;
  356. }
  357. if ((request->COMMAND >= 0x28) && (request->COMMAND < 0x32))
  358. {
  359. EthernetStats (plc, ether_confirm->STATS);
  360. continue;
  361. }
  362. }
  363. return (0);
  364. }
  365. #endif