ipath_stats.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. * Copyright (c) 2006, 2007 QLogic Corporation. All rights reserved.
  3. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include "ipath_kernel.h"
  34. struct infinipath_stats ipath_stats;
  35. /**
  36. * ipath_snap_cntr - snapshot a chip counter
  37. * @dd: the infinipath device
  38. * @creg: the counter to snapshot
  39. *
  40. * called from add_timer and user counter read calls, to deal with
  41. * counters that wrap in "human time". The words sent and received, and
  42. * the packets sent and received are all that we worry about. For now,
  43. * at least, we don't worry about error counters, because if they wrap
  44. * that quickly, we probably don't care. We may eventually just make this
  45. * handle all the counters. word counters can wrap in about 20 seconds
  46. * of full bandwidth traffic, packet counters in a few hours.
  47. */
  48. u64 ipath_snap_cntr(struct ipath_devdata *dd, ipath_creg creg)
  49. {
  50. u32 val, reg64 = 0;
  51. u64 val64;
  52. unsigned long t0, t1;
  53. u64 ret;
  54. unsigned long flags;
  55. t0 = jiffies;
  56. /* If fast increment counters are only 32 bits, snapshot them,
  57. * and maintain them as 64bit values in the driver */
  58. if (!(dd->ipath_flags & IPATH_32BITCOUNTERS) &&
  59. (creg == dd->ipath_cregs->cr_wordsendcnt ||
  60. creg == dd->ipath_cregs->cr_wordrcvcnt ||
  61. creg == dd->ipath_cregs->cr_pktsendcnt ||
  62. creg == dd->ipath_cregs->cr_pktrcvcnt)) {
  63. val64 = ipath_read_creg(dd, creg);
  64. val = val64 == ~0ULL ? ~0U : 0;
  65. reg64 = 1;
  66. } else /* val64 just to keep gcc quiet... */
  67. val64 = val = ipath_read_creg32(dd, creg);
  68. /*
  69. * See if a second has passed. This is just a way to detect things
  70. * that are quite broken. Normally this should take just a few
  71. * cycles (the check is for long enough that we don't care if we get
  72. * pre-empted.) An Opteron HT O read timeout is 4 seconds with
  73. * normal NB values
  74. */
  75. t1 = jiffies;
  76. if (time_before(t0 + HZ, t1) && val == -1) {
  77. ipath_dev_err(dd, "Error! Read counter 0x%x timed out\n",
  78. creg);
  79. ret = 0ULL;
  80. goto bail;
  81. }
  82. if (reg64) {
  83. ret = val64;
  84. goto bail;
  85. }
  86. if (creg == dd->ipath_cregs->cr_wordsendcnt) {
  87. if (val != dd->ipath_lastsword) {
  88. dd->ipath_sword += val - dd->ipath_lastsword;
  89. spin_lock_irqsave(&dd->ipath_eep_st_lock, flags);
  90. dd->ipath_traffic_wds += val - dd->ipath_lastsword;
  91. spin_unlock_irqrestore(&dd->ipath_eep_st_lock, flags);
  92. dd->ipath_lastsword = val;
  93. }
  94. val64 = dd->ipath_sword;
  95. } else if (creg == dd->ipath_cregs->cr_wordrcvcnt) {
  96. if (val != dd->ipath_lastrword) {
  97. dd->ipath_rword += val - dd->ipath_lastrword;
  98. spin_lock_irqsave(&dd->ipath_eep_st_lock, flags);
  99. dd->ipath_traffic_wds += val - dd->ipath_lastrword;
  100. spin_unlock_irqrestore(&dd->ipath_eep_st_lock, flags);
  101. dd->ipath_lastrword = val;
  102. }
  103. val64 = dd->ipath_rword;
  104. } else if (creg == dd->ipath_cregs->cr_pktsendcnt) {
  105. if (val != dd->ipath_lastspkts) {
  106. dd->ipath_spkts += val - dd->ipath_lastspkts;
  107. dd->ipath_lastspkts = val;
  108. }
  109. val64 = dd->ipath_spkts;
  110. } else if (creg == dd->ipath_cregs->cr_pktrcvcnt) {
  111. if (val != dd->ipath_lastrpkts) {
  112. dd->ipath_rpkts += val - dd->ipath_lastrpkts;
  113. dd->ipath_lastrpkts = val;
  114. }
  115. val64 = dd->ipath_rpkts;
  116. } else
  117. val64 = (u64) val;
  118. ret = val64;
  119. bail:
  120. return ret;
  121. }
  122. /**
  123. * ipath_qcheck - print delta of egrfull/hdrqfull errors for kernel ports
  124. * @dd: the infinipath device
  125. *
  126. * print the delta of egrfull/hdrqfull errors for kernel ports no more than
  127. * every 5 seconds. User processes are printed at close, but kernel doesn't
  128. * close, so... Separate routine so may call from other places someday, and
  129. * so function name when printed by _IPATH_INFO is meaningfull
  130. */
  131. static void ipath_qcheck(struct ipath_devdata *dd)
  132. {
  133. static u64 last_tot_hdrqfull;
  134. size_t blen = 0;
  135. char buf[128];
  136. *buf = 0;
  137. if (dd->ipath_pd[0]->port_hdrqfull != dd->ipath_p0_hdrqfull) {
  138. blen = snprintf(buf, sizeof buf, "port 0 hdrqfull %u",
  139. dd->ipath_pd[0]->port_hdrqfull -
  140. dd->ipath_p0_hdrqfull);
  141. dd->ipath_p0_hdrqfull = dd->ipath_pd[0]->port_hdrqfull;
  142. }
  143. if (ipath_stats.sps_etidfull != dd->ipath_last_tidfull) {
  144. blen += snprintf(buf + blen, sizeof buf - blen,
  145. "%srcvegrfull %llu",
  146. blen ? ", " : "",
  147. (unsigned long long)
  148. (ipath_stats.sps_etidfull -
  149. dd->ipath_last_tidfull));
  150. dd->ipath_last_tidfull = ipath_stats.sps_etidfull;
  151. }
  152. /*
  153. * this is actually the number of hdrq full interrupts, not actual
  154. * events, but at the moment that's mostly what I'm interested in.
  155. * Actual count, etc. is in the counters, if needed. For production
  156. * users this won't ordinarily be printed.
  157. */
  158. if ((ipath_debug & (__IPATH_PKTDBG | __IPATH_DBG)) &&
  159. ipath_stats.sps_hdrqfull != last_tot_hdrqfull) {
  160. blen += snprintf(buf + blen, sizeof buf - blen,
  161. "%shdrqfull %llu (all ports)",
  162. blen ? ", " : "",
  163. (unsigned long long)
  164. (ipath_stats.sps_hdrqfull -
  165. last_tot_hdrqfull));
  166. last_tot_hdrqfull = ipath_stats.sps_hdrqfull;
  167. }
  168. if (blen)
  169. ipath_dbg("%s\n", buf);
  170. if (dd->ipath_port0head != (u32)
  171. le64_to_cpu(*dd->ipath_hdrqtailptr)) {
  172. if (dd->ipath_lastport0rcv_cnt ==
  173. ipath_stats.sps_port0pkts) {
  174. ipath_cdbg(PKT, "missing rcv interrupts? "
  175. "port0 hd=%llx tl=%x; port0pkts %llx\n",
  176. (unsigned long long)
  177. le64_to_cpu(*dd->ipath_hdrqtailptr),
  178. dd->ipath_port0head,
  179. (unsigned long long)
  180. ipath_stats.sps_port0pkts);
  181. }
  182. dd->ipath_lastport0rcv_cnt = ipath_stats.sps_port0pkts;
  183. }
  184. }
  185. static void ipath_chk_errormask(struct ipath_devdata *dd)
  186. {
  187. static u32 fixed;
  188. u32 ctrl;
  189. unsigned long errormask;
  190. unsigned long hwerrs;
  191. if (!dd->ipath_errormask || !(dd->ipath_flags & IPATH_INITTED))
  192. return;
  193. errormask = ipath_read_kreg64(dd, dd->ipath_kregs->kr_errormask);
  194. if (errormask == dd->ipath_errormask)
  195. return;
  196. fixed++;
  197. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  198. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  199. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  200. dd->ipath_errormask);
  201. if ((hwerrs & dd->ipath_hwerrmask) ||
  202. (ctrl & INFINIPATH_C_FREEZEMODE)) {
  203. /* force re-interrupt of pending events, just in case */
  204. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear, 0ULL);
  205. ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, 0ULL);
  206. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);
  207. dev_info(&dd->pcidev->dev,
  208. "errormask fixed(%u) %lx -> %lx, ctrl %x hwerr %lx\n",
  209. fixed, errormask, (unsigned long)dd->ipath_errormask,
  210. ctrl, hwerrs);
  211. } else
  212. ipath_dbg("errormask fixed(%u) %lx -> %lx, no freeze\n",
  213. fixed, errormask,
  214. (unsigned long)dd->ipath_errormask);
  215. }
  216. /**
  217. * ipath_get_faststats - get word counters from chip before they overflow
  218. * @opaque - contains a pointer to the infinipath device ipath_devdata
  219. *
  220. * called from add_timer
  221. */
  222. void ipath_get_faststats(unsigned long opaque)
  223. {
  224. struct ipath_devdata *dd = (struct ipath_devdata *) opaque;
  225. u32 val;
  226. static unsigned cnt;
  227. unsigned long flags;
  228. /*
  229. * don't access the chip while running diags, or memory diags can
  230. * fail
  231. */
  232. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_INITTED) ||
  233. ipath_diag_inuse)
  234. /* but re-arm the timer, for diags case; won't hurt other */
  235. goto done;
  236. /*
  237. * We now try to maintain a "active timer", based on traffic
  238. * exceeding a threshold, so we need to check the word-counts
  239. * even if they are 64-bit.
  240. */
  241. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
  242. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
  243. spin_lock_irqsave(&dd->ipath_eep_st_lock, flags);
  244. if (dd->ipath_traffic_wds >= IPATH_TRAFFIC_ACTIVE_THRESHOLD)
  245. atomic_add(5, &dd->ipath_active_time); /* S/B #define */
  246. dd->ipath_traffic_wds = 0;
  247. spin_unlock_irqrestore(&dd->ipath_eep_st_lock, flags);
  248. if (dd->ipath_flags & IPATH_32BITCOUNTERS) {
  249. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
  250. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
  251. }
  252. ipath_qcheck(dd);
  253. /*
  254. * deal with repeat error suppression. Doesn't really matter if
  255. * last error was almost a full interval ago, or just a few usecs
  256. * ago; still won't get more than 2 per interval. We may want
  257. * longer intervals for this eventually, could do with mod, counter
  258. * or separate timer. Also see code in ipath_handle_errors() and
  259. * ipath_handle_hwerrors().
  260. */
  261. if (dd->ipath_lasterror)
  262. dd->ipath_lasterror = 0;
  263. if (dd->ipath_lasthwerror)
  264. dd->ipath_lasthwerror = 0;
  265. if (dd->ipath_maskederrs
  266. && time_after(jiffies, dd->ipath_unmasktime)) {
  267. char ebuf[256];
  268. int iserr;
  269. iserr = ipath_decode_err(ebuf, sizeof ebuf,
  270. dd->ipath_maskederrs);
  271. if (dd->ipath_maskederrs &
  272. ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  273. INFINIPATH_E_PKTERRS ))
  274. ipath_dev_err(dd, "Re-enabling masked errors "
  275. "(%s)\n", ebuf);
  276. else {
  277. /*
  278. * rcvegrfull and rcvhdrqfull are "normal", for some
  279. * types of processes (mostly benchmarks) that send
  280. * huge numbers of messages, while not processing
  281. * them. So only complain about these at debug
  282. * level.
  283. */
  284. if (iserr)
  285. ipath_dbg("Re-enabling queue full errors (%s)\n",
  286. ebuf);
  287. else
  288. ipath_cdbg(ERRPKT, "Re-enabling packet"
  289. " problem interrupt (%s)\n", ebuf);
  290. }
  291. /* re-enable masked errors */
  292. dd->ipath_errormask |= dd->ipath_maskederrs;
  293. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  294. dd->ipath_errormask);
  295. dd->ipath_maskederrs = 0;
  296. }
  297. /* limit qfull messages to ~one per minute per port */
  298. if ((++cnt & 0x10)) {
  299. for (val = dd->ipath_cfgports - 1; ((int)val) >= 0;
  300. val--) {
  301. if (dd->ipath_lastegrheads[val] != -1)
  302. dd->ipath_lastegrheads[val] = -1;
  303. if (dd->ipath_lastrcvhdrqtails[val] != -1)
  304. dd->ipath_lastrcvhdrqtails[val] = -1;
  305. }
  306. }
  307. ipath_chk_errormask(dd);
  308. done:
  309. mod_timer(&dd->ipath_stats_timer, jiffies + HZ * 5);
  310. }