ipath_stats.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. * Copyright (c) 2006, 2007, 2008 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. t0 = jiffies;
  55. /* If fast increment counters are only 32 bits, snapshot them,
  56. * and maintain them as 64bit values in the driver */
  57. if (!(dd->ipath_flags & IPATH_32BITCOUNTERS) &&
  58. (creg == dd->ipath_cregs->cr_wordsendcnt ||
  59. creg == dd->ipath_cregs->cr_wordrcvcnt ||
  60. creg == dd->ipath_cregs->cr_pktsendcnt ||
  61. creg == dd->ipath_cregs->cr_pktrcvcnt)) {
  62. val64 = ipath_read_creg(dd, creg);
  63. val = val64 == ~0ULL ? ~0U : 0;
  64. reg64 = 1;
  65. } else /* val64 just to keep gcc quiet... */
  66. val64 = val = ipath_read_creg32(dd, creg);
  67. /*
  68. * See if a second has passed. This is just a way to detect things
  69. * that are quite broken. Normally this should take just a few
  70. * cycles (the check is for long enough that we don't care if we get
  71. * pre-empted.) An Opteron HT O read timeout is 4 seconds with
  72. * normal NB values
  73. */
  74. t1 = jiffies;
  75. if (time_before(t0 + HZ, t1) && val == -1) {
  76. ipath_dev_err(dd, "Error! Read counter 0x%x timed out\n",
  77. creg);
  78. ret = 0ULL;
  79. goto bail;
  80. }
  81. if (reg64) {
  82. ret = val64;
  83. goto bail;
  84. }
  85. if (creg == dd->ipath_cregs->cr_wordsendcnt) {
  86. if (val != dd->ipath_lastsword) {
  87. dd->ipath_sword += val - dd->ipath_lastsword;
  88. dd->ipath_lastsword = val;
  89. }
  90. val64 = dd->ipath_sword;
  91. } else if (creg == dd->ipath_cregs->cr_wordrcvcnt) {
  92. if (val != dd->ipath_lastrword) {
  93. dd->ipath_rword += val - dd->ipath_lastrword;
  94. dd->ipath_lastrword = val;
  95. }
  96. val64 = dd->ipath_rword;
  97. } else if (creg == dd->ipath_cregs->cr_pktsendcnt) {
  98. if (val != dd->ipath_lastspkts) {
  99. dd->ipath_spkts += val - dd->ipath_lastspkts;
  100. dd->ipath_lastspkts = val;
  101. }
  102. val64 = dd->ipath_spkts;
  103. } else if (creg == dd->ipath_cregs->cr_pktrcvcnt) {
  104. if (val != dd->ipath_lastrpkts) {
  105. dd->ipath_rpkts += val - dd->ipath_lastrpkts;
  106. dd->ipath_lastrpkts = val;
  107. }
  108. val64 = dd->ipath_rpkts;
  109. } else if (creg == dd->ipath_cregs->cr_ibsymbolerrcnt) {
  110. if (dd->ibdeltainprog)
  111. val64 -= val64 - dd->ibsymsnap;
  112. val64 -= dd->ibsymdelta;
  113. } else if (creg == dd->ipath_cregs->cr_iblinkerrrecovcnt) {
  114. if (dd->ibdeltainprog)
  115. val64 -= val64 - dd->iblnkerrsnap;
  116. val64 -= dd->iblnkerrdelta;
  117. } else
  118. val64 = (u64) val;
  119. ret = val64;
  120. bail:
  121. return ret;
  122. }
  123. /**
  124. * ipath_qcheck - print delta of egrfull/hdrqfull errors for kernel ports
  125. * @dd: the infinipath device
  126. *
  127. * print the delta of egrfull/hdrqfull errors for kernel ports no more than
  128. * every 5 seconds. User processes are printed at close, but kernel doesn't
  129. * close, so... Separate routine so may call from other places someday, and
  130. * so function name when printed by _IPATH_INFO is meaningfull
  131. */
  132. static void ipath_qcheck(struct ipath_devdata *dd)
  133. {
  134. static u64 last_tot_hdrqfull;
  135. struct ipath_portdata *pd = dd->ipath_pd[0];
  136. size_t blen = 0;
  137. char buf[128];
  138. u32 hdrqtail;
  139. *buf = 0;
  140. if (pd->port_hdrqfull != dd->ipath_p0_hdrqfull) {
  141. blen = snprintf(buf, sizeof buf, "port 0 hdrqfull %u",
  142. pd->port_hdrqfull -
  143. dd->ipath_p0_hdrqfull);
  144. dd->ipath_p0_hdrqfull = pd->port_hdrqfull;
  145. }
  146. if (ipath_stats.sps_etidfull != dd->ipath_last_tidfull) {
  147. blen += snprintf(buf + blen, sizeof buf - blen,
  148. "%srcvegrfull %llu",
  149. blen ? ", " : "",
  150. (unsigned long long)
  151. (ipath_stats.sps_etidfull -
  152. dd->ipath_last_tidfull));
  153. dd->ipath_last_tidfull = ipath_stats.sps_etidfull;
  154. }
  155. /*
  156. * this is actually the number of hdrq full interrupts, not actual
  157. * events, but at the moment that's mostly what I'm interested in.
  158. * Actual count, etc. is in the counters, if needed. For production
  159. * users this won't ordinarily be printed.
  160. */
  161. if ((ipath_debug & (__IPATH_PKTDBG | __IPATH_DBG)) &&
  162. ipath_stats.sps_hdrqfull != last_tot_hdrqfull) {
  163. blen += snprintf(buf + blen, sizeof buf - blen,
  164. "%shdrqfull %llu (all ports)",
  165. blen ? ", " : "",
  166. (unsigned long long)
  167. (ipath_stats.sps_hdrqfull -
  168. last_tot_hdrqfull));
  169. last_tot_hdrqfull = ipath_stats.sps_hdrqfull;
  170. }
  171. if (blen)
  172. ipath_dbg("%s\n", buf);
  173. hdrqtail = ipath_get_hdrqtail(pd);
  174. if (pd->port_head != hdrqtail) {
  175. if (dd->ipath_lastport0rcv_cnt ==
  176. ipath_stats.sps_port0pkts) {
  177. ipath_cdbg(PKT, "missing rcv interrupts? "
  178. "port0 hd=%x tl=%x; port0pkts %llx; write"
  179. " hd (w/intr)\n",
  180. pd->port_head, hdrqtail,
  181. (unsigned long long)
  182. ipath_stats.sps_port0pkts);
  183. ipath_write_ureg(dd, ur_rcvhdrhead, hdrqtail |
  184. dd->ipath_rhdrhead_intr_off, pd->port_port);
  185. }
  186. dd->ipath_lastport0rcv_cnt = ipath_stats.sps_port0pkts;
  187. }
  188. }
  189. static void ipath_chk_errormask(struct ipath_devdata *dd)
  190. {
  191. static u32 fixed;
  192. u32 ctrl;
  193. unsigned long errormask;
  194. unsigned long hwerrs;
  195. if (!dd->ipath_errormask || !(dd->ipath_flags & IPATH_INITTED))
  196. return;
  197. errormask = ipath_read_kreg64(dd, dd->ipath_kregs->kr_errormask);
  198. if (errormask == dd->ipath_errormask)
  199. return;
  200. fixed++;
  201. hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
  202. ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
  203. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  204. dd->ipath_errormask);
  205. if ((hwerrs & dd->ipath_hwerrmask) ||
  206. (ctrl & INFINIPATH_C_FREEZEMODE)) {
  207. /* force re-interrupt of pending events, just in case */
  208. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear, 0ULL);
  209. ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, 0ULL);
  210. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);
  211. dev_info(&dd->pcidev->dev,
  212. "errormask fixed(%u) %lx -> %lx, ctrl %x hwerr %lx\n",
  213. fixed, errormask, (unsigned long)dd->ipath_errormask,
  214. ctrl, hwerrs);
  215. } else
  216. ipath_dbg("errormask fixed(%u) %lx -> %lx, no freeze\n",
  217. fixed, errormask,
  218. (unsigned long)dd->ipath_errormask);
  219. }
  220. /**
  221. * ipath_get_faststats - get word counters from chip before they overflow
  222. * @opaque - contains a pointer to the infinipath device ipath_devdata
  223. *
  224. * called from add_timer
  225. */
  226. void ipath_get_faststats(unsigned long opaque)
  227. {
  228. struct ipath_devdata *dd = (struct ipath_devdata *) opaque;
  229. int i;
  230. static unsigned cnt;
  231. unsigned long flags;
  232. u64 traffic_wds;
  233. /*
  234. * don't access the chip while running diags, or memory diags can
  235. * fail
  236. */
  237. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_INITTED) ||
  238. ipath_diag_inuse)
  239. /* but re-arm the timer, for diags case; won't hurt other */
  240. goto done;
  241. /*
  242. * We now try to maintain a "active timer", based on traffic
  243. * exceeding a threshold, so we need to check the word-counts
  244. * even if they are 64-bit.
  245. */
  246. traffic_wds = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt) +
  247. ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
  248. spin_lock_irqsave(&dd->ipath_eep_st_lock, flags);
  249. traffic_wds -= dd->ipath_traffic_wds;
  250. dd->ipath_traffic_wds += traffic_wds;
  251. if (traffic_wds >= IPATH_TRAFFIC_ACTIVE_THRESHOLD)
  252. atomic_add(5, &dd->ipath_active_time); /* S/B #define */
  253. spin_unlock_irqrestore(&dd->ipath_eep_st_lock, flags);
  254. if (dd->ipath_flags & IPATH_32BITCOUNTERS) {
  255. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
  256. ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
  257. }
  258. ipath_qcheck(dd);
  259. /*
  260. * deal with repeat error suppression. Doesn't really matter if
  261. * last error was almost a full interval ago, or just a few usecs
  262. * ago; still won't get more than 2 per interval. We may want
  263. * longer intervals for this eventually, could do with mod, counter
  264. * or separate timer. Also see code in ipath_handle_errors() and
  265. * ipath_handle_hwerrors().
  266. */
  267. if (dd->ipath_lasterror)
  268. dd->ipath_lasterror = 0;
  269. if (dd->ipath_lasthwerror)
  270. dd->ipath_lasthwerror = 0;
  271. if (dd->ipath_maskederrs
  272. && time_after(jiffies, dd->ipath_unmasktime)) {
  273. char ebuf[256];
  274. int iserr;
  275. iserr = ipath_decode_err(dd, ebuf, sizeof ebuf,
  276. dd->ipath_maskederrs);
  277. if (dd->ipath_maskederrs &
  278. ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
  279. INFINIPATH_E_PKTERRS))
  280. ipath_dev_err(dd, "Re-enabling masked errors "
  281. "(%s)\n", ebuf);
  282. else {
  283. /*
  284. * rcvegrfull and rcvhdrqfull are "normal", for some
  285. * types of processes (mostly benchmarks) that send
  286. * huge numbers of messages, while not processing
  287. * them. So only complain about these at debug
  288. * level.
  289. */
  290. if (iserr)
  291. ipath_dbg(
  292. "Re-enabling queue full errors (%s)\n",
  293. ebuf);
  294. else
  295. ipath_cdbg(ERRPKT, "Re-enabling packet"
  296. " problem interrupt (%s)\n", ebuf);
  297. }
  298. /* re-enable masked errors */
  299. dd->ipath_errormask |= dd->ipath_maskederrs;
  300. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  301. dd->ipath_errormask);
  302. dd->ipath_maskederrs = 0;
  303. }
  304. /* limit qfull messages to ~one per minute per port */
  305. if ((++cnt & 0x10)) {
  306. for (i = (int) dd->ipath_cfgports; --i >= 0; ) {
  307. struct ipath_portdata *pd = dd->ipath_pd[i];
  308. if (pd && pd->port_lastrcvhdrqtail != -1)
  309. pd->port_lastrcvhdrqtail = -1;
  310. }
  311. }
  312. ipath_chk_errormask(dd);
  313. done:
  314. mod_timer(&dd->ipath_stats_timer, jiffies + HZ * 5);
  315. }