MDUTrafficStats.c 12 KB

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