blob: 2651701ce1b5d1e6f3713816f4f0857fd724298f [file] [log] [blame]
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08001/*
Bryan O'Sullivan759d5762006-07-01 04:35:49 -07002 * Copyright (c) 2006 QLogic, Inc. All rights reserved.
Bryan O'Sullivan108ecf02006-03-29 15:23:29 -08003 * 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
34#include <linux/pci.h>
35
36#include "ipath_kernel.h"
37
38struct infinipath_stats ipath_stats;
39
40/**
41 * ipath_snap_cntr - snapshot a chip counter
42 * @dd: the infinipath device
43 * @creg: the counter to snapshot
44 *
45 * called from add_timer and user counter read calls, to deal with
46 * counters that wrap in "human time". The words sent and received, and
47 * the packets sent and received are all that we worry about. For now,
48 * at least, we don't worry about error counters, because if they wrap
49 * that quickly, we probably don't care. We may eventually just make this
50 * handle all the counters. word counters can wrap in about 20 seconds
51 * of full bandwidth traffic, packet counters in a few hours.
52 */
53
54u64 ipath_snap_cntr(struct ipath_devdata *dd, ipath_creg creg)
55{
56 u32 val, reg64 = 0;
57 u64 val64;
58 unsigned long t0, t1;
59 u64 ret;
60
61 t0 = jiffies;
62 /* If fast increment counters are only 32 bits, snapshot them,
63 * and maintain them as 64bit values in the driver */
64 if (!(dd->ipath_flags & IPATH_32BITCOUNTERS) &&
65 (creg == dd->ipath_cregs->cr_wordsendcnt ||
66 creg == dd->ipath_cregs->cr_wordrcvcnt ||
67 creg == dd->ipath_cregs->cr_pktsendcnt ||
68 creg == dd->ipath_cregs->cr_pktrcvcnt)) {
69 val64 = ipath_read_creg(dd, creg);
70 val = val64 == ~0ULL ? ~0U : 0;
71 reg64 = 1;
72 } else /* val64 just to keep gcc quiet... */
73 val64 = val = ipath_read_creg32(dd, creg);
74 /*
75 * See if a second has passed. This is just a way to detect things
76 * that are quite broken. Normally this should take just a few
77 * cycles (the check is for long enough that we don't care if we get
78 * pre-empted.) An Opteron HT O read timeout is 4 seconds with
79 * normal NB values
80 */
81 t1 = jiffies;
82 if (time_before(t0 + HZ, t1) && val == -1) {
83 ipath_dev_err(dd, "Error! Read counter 0x%x timed out\n",
84 creg);
85 ret = 0ULL;
86 goto bail;
87 }
88 if (reg64) {
89 ret = val64;
90 goto bail;
91 }
92
93 if (creg == dd->ipath_cregs->cr_wordsendcnt) {
94 if (val != dd->ipath_lastsword) {
95 dd->ipath_sword += val - dd->ipath_lastsword;
96 dd->ipath_lastsword = val;
97 }
98 val64 = dd->ipath_sword;
99 } else if (creg == dd->ipath_cregs->cr_wordrcvcnt) {
100 if (val != dd->ipath_lastrword) {
101 dd->ipath_rword += val - dd->ipath_lastrword;
102 dd->ipath_lastrword = val;
103 }
104 val64 = dd->ipath_rword;
105 } else if (creg == dd->ipath_cregs->cr_pktsendcnt) {
106 if (val != dd->ipath_lastspkts) {
107 dd->ipath_spkts += val - dd->ipath_lastspkts;
108 dd->ipath_lastspkts = val;
109 }
110 val64 = dd->ipath_spkts;
111 } else if (creg == dd->ipath_cregs->cr_pktrcvcnt) {
112 if (val != dd->ipath_lastrpkts) {
113 dd->ipath_rpkts += val - dd->ipath_lastrpkts;
114 dd->ipath_lastrpkts = val;
115 }
116 val64 = dd->ipath_rpkts;
117 } else
118 val64 = (u64) val;
119
120 ret = val64;
121
122bail:
123 return ret;
124}
125
126/**
127 * ipath_qcheck - print delta of egrfull/hdrqfull errors for kernel ports
128 * @dd: the infinipath device
129 *
130 * print the delta of egrfull/hdrqfull errors for kernel ports no more than
131 * every 5 seconds. User processes are printed at close, but kernel doesn't
132 * close, so... Separate routine so may call from other places someday, and
133 * so function name when printed by _IPATH_INFO is meaningfull
134 */
135static void ipath_qcheck(struct ipath_devdata *dd)
136{
137 static u64 last_tot_hdrqfull;
138 size_t blen = 0;
139 char buf[128];
140
141 *buf = 0;
142 if (dd->ipath_pd[0]->port_hdrqfull != dd->ipath_p0_hdrqfull) {
143 blen = snprintf(buf, sizeof buf, "port 0 hdrqfull %u",
144 dd->ipath_pd[0]->port_hdrqfull -
145 dd->ipath_p0_hdrqfull);
146 dd->ipath_p0_hdrqfull = dd->ipath_pd[0]->port_hdrqfull;
147 }
148 if (ipath_stats.sps_etidfull != dd->ipath_last_tidfull) {
149 blen += snprintf(buf + blen, sizeof buf - blen,
150 "%srcvegrfull %llu",
151 blen ? ", " : "",
152 (unsigned long long)
153 (ipath_stats.sps_etidfull -
154 dd->ipath_last_tidfull));
155 dd->ipath_last_tidfull = ipath_stats.sps_etidfull;
156 }
157
158 /*
159 * this is actually the number of hdrq full interrupts, not actual
160 * events, but at the moment that's mostly what I'm interested in.
161 * Actual count, etc. is in the counters, if needed. For production
162 * users this won't ordinarily be printed.
163 */
164
165 if ((ipath_debug & (__IPATH_PKTDBG | __IPATH_DBG)) &&
166 ipath_stats.sps_hdrqfull != last_tot_hdrqfull) {
167 blen += snprintf(buf + blen, sizeof buf - blen,
168 "%shdrqfull %llu (all ports)",
169 blen ? ", " : "",
170 (unsigned long long)
171 (ipath_stats.sps_hdrqfull -
172 last_tot_hdrqfull));
173 last_tot_hdrqfull = ipath_stats.sps_hdrqfull;
174 }
175 if (blen)
176 ipath_dbg("%s\n", buf);
177
178 if (dd->ipath_port0head != (u32)
179 le64_to_cpu(*dd->ipath_hdrqtailptr)) {
180 if (dd->ipath_lastport0rcv_cnt ==
181 ipath_stats.sps_port0pkts) {
182 ipath_cdbg(PKT, "missing rcv interrupts? "
183 "port0 hd=%llx tl=%x; port0pkts %llx\n",
184 (unsigned long long)
185 le64_to_cpu(*dd->ipath_hdrqtailptr),
186 dd->ipath_port0head,
187 (unsigned long long)
188 ipath_stats.sps_port0pkts);
189 ipath_kreceive(dd);
190 }
191 dd->ipath_lastport0rcv_cnt = ipath_stats.sps_port0pkts;
192 }
193}
194
195/**
196 * ipath_get_faststats - get word counters from chip before they overflow
197 * @opaque - contains a pointer to the infinipath device ipath_devdata
198 *
199 * called from add_timer
200 */
201void ipath_get_faststats(unsigned long opaque)
202{
203 struct ipath_devdata *dd = (struct ipath_devdata *) opaque;
204 u32 val;
205 static unsigned cnt;
206
207 /*
208 * don't access the chip while running diags, or memory diags can
209 * fail
210 */
211 if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT) ||
212 ipath_diag_inuse)
213 /* but re-arm the timer, for diags case; won't hurt other */
214 goto done;
215
216 if (dd->ipath_flags & IPATH_32BITCOUNTERS) {
217 ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
218 ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
219 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
220 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
221 }
222
223 ipath_qcheck(dd);
224
225 /*
226 * deal with repeat error suppression. Doesn't really matter if
227 * last error was almost a full interval ago, or just a few usecs
228 * ago; still won't get more than 2 per interval. We may want
229 * longer intervals for this eventually, could do with mod, counter
230 * or separate timer. Also see code in ipath_handle_errors() and
231 * ipath_handle_hwerrors().
232 */
233
234 if (dd->ipath_lasterror)
235 dd->ipath_lasterror = 0;
236 if (dd->ipath_lasthwerror)
237 dd->ipath_lasthwerror = 0;
238 if ((dd->ipath_maskederrs & ~dd->ipath_ignorederrs)
239 && time_after(jiffies, dd->ipath_unmasktime)) {
240 char ebuf[256];
241 ipath_decode_err(ebuf, sizeof ebuf,
242 (dd->ipath_maskederrs & ~dd->
243 ipath_ignorederrs));
244 if ((dd->ipath_maskederrs & ~dd->ipath_ignorederrs) &
245 ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL))
246 ipath_dev_err(dd, "Re-enabling masked errors "
247 "(%s)\n", ebuf);
248 else {
249 /*
250 * rcvegrfull and rcvhdrqfull are "normal", for some
251 * types of processes (mostly benchmarks) that send
252 * huge numbers of messages, while not processing
253 * them. So only complain about these at debug
254 * level.
255 */
256 ipath_dbg("Disabling frequent queue full errors "
257 "(%s)\n", ebuf);
258 }
259 dd->ipath_maskederrs = dd->ipath_ignorederrs;
260 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
261 ~dd->ipath_maskederrs);
262 }
263
264 /* limit qfull messages to ~one per minute per port */
265 if ((++cnt & 0x10)) {
266 for (val = dd->ipath_cfgports - 1; ((int)val) >= 0;
267 val--) {
268 if (dd->ipath_lastegrheads[val] != -1)
269 dd->ipath_lastegrheads[val] = -1;
270 if (dd->ipath_lastrcvhdrqtails[val] != -1)
271 dd->ipath_lastrcvhdrqtails[val] = -1;
272 }
273 }
274
275 if (dd->ipath_nosma_bufs) {
276 dd->ipath_nosma_secs += 5;
277 if (dd->ipath_nosma_secs >= 30) {
278 ipath_cdbg(SMA, "No SMA bufs avail %u seconds; "
279 "cancelling pending sends\n",
280 dd->ipath_nosma_secs);
281 /*
282 * issue an abort as well, in case we have a packet
283 * stuck in launch fifo. This could corrupt an
284 * outgoing user packet in the worst case,
285 * but this is a pretty catastrophic, anyway.
286 */
287 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
288 INFINIPATH_S_ABORT);
289 ipath_disarm_piobufs(dd, dd->ipath_lastport_piobuf,
290 dd->ipath_piobcnt2k +
291 dd->ipath_piobcnt4k -
292 dd->ipath_lastport_piobuf);
293 /* start again, if necessary */
294 dd->ipath_nosma_secs = 0;
295 } else
296 ipath_cdbg(SMA, "No SMA bufs avail %u tries, "
297 "after %u seconds\n",
298 dd->ipath_nosma_bufs,
299 dd->ipath_nosma_secs);
300 }
301
302done:
303 mod_timer(&dd->ipath_stats_timer, jiffies + HZ * 5);
304}