1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#include "ipath_kernel.h"
35
36struct infinipath_stats ipath_stats;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52u64 ipath_snap_cntr(struct ipath_devdata *dd, ipath_creg creg)
53{
54 u32 val, reg64 = 0;
55 u64 val64;
56 unsigned long t0, t1;
57 u64 ret;
58
59 t0 = jiffies;
60
61
62 if (!(dd->ipath_flags & IPATH_32BITCOUNTERS) &&
63 (creg == dd->ipath_cregs->cr_wordsendcnt ||
64 creg == dd->ipath_cregs->cr_wordrcvcnt ||
65 creg == dd->ipath_cregs->cr_pktsendcnt ||
66 creg == dd->ipath_cregs->cr_pktrcvcnt)) {
67 val64 = ipath_read_creg(dd, creg);
68 val = val64 == ~0ULL ? ~0U : 0;
69 reg64 = 1;
70 } else
71 val64 = val = ipath_read_creg32(dd, creg);
72
73
74
75
76
77
78
79 t1 = jiffies;
80 if (time_before(t0 + HZ, t1) && val == -1) {
81 ipath_dev_err(dd, "Error! Read counter 0x%x timed out\n",
82 creg);
83 ret = 0ULL;
84 goto bail;
85 }
86 if (reg64) {
87 ret = val64;
88 goto bail;
89 }
90
91 if (creg == dd->ipath_cregs->cr_wordsendcnt) {
92 if (val != dd->ipath_lastsword) {
93 dd->ipath_sword += val - dd->ipath_lastsword;
94 dd->ipath_lastsword = val;
95 }
96 val64 = dd->ipath_sword;
97 } else if (creg == dd->ipath_cregs->cr_wordrcvcnt) {
98 if (val != dd->ipath_lastrword) {
99 dd->ipath_rword += val - dd->ipath_lastrword;
100 dd->ipath_lastrword = val;
101 }
102 val64 = dd->ipath_rword;
103 } else if (creg == dd->ipath_cregs->cr_pktsendcnt) {
104 if (val != dd->ipath_lastspkts) {
105 dd->ipath_spkts += val - dd->ipath_lastspkts;
106 dd->ipath_lastspkts = val;
107 }
108 val64 = dd->ipath_spkts;
109 } else if (creg == dd->ipath_cregs->cr_pktrcvcnt) {
110 if (val != dd->ipath_lastrpkts) {
111 dd->ipath_rpkts += val - dd->ipath_lastrpkts;
112 dd->ipath_lastrpkts = val;
113 }
114 val64 = dd->ipath_rpkts;
115 } else
116 val64 = (u64) val;
117
118 ret = val64;
119
120bail:
121 return ret;
122}
123
124
125
126
127
128
129
130
131
132
133static void ipath_qcheck(struct ipath_devdata *dd)
134{
135 static u64 last_tot_hdrqfull;
136 size_t blen = 0;
137 char buf[128];
138
139 *buf = 0;
140 if (dd->ipath_pd[0]->port_hdrqfull != dd->ipath_p0_hdrqfull) {
141 blen = snprintf(buf, sizeof buf, "port 0 hdrqfull %u",
142 dd->ipath_pd[0]->port_hdrqfull -
143 dd->ipath_p0_hdrqfull);
144 dd->ipath_p0_hdrqfull = dd->ipath_pd[0]->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
157
158
159
160
161
162
163 if ((ipath_debug & (__IPATH_PKTDBG | __IPATH_DBG)) &&
164 ipath_stats.sps_hdrqfull != last_tot_hdrqfull) {
165 blen += snprintf(buf + blen, sizeof buf - blen,
166 "%shdrqfull %llu (all ports)",
167 blen ? ", " : "",
168 (unsigned long long)
169 (ipath_stats.sps_hdrqfull -
170 last_tot_hdrqfull));
171 last_tot_hdrqfull = ipath_stats.sps_hdrqfull;
172 }
173 if (blen)
174 ipath_dbg("%s\n", buf);
175
176 if (dd->ipath_port0head != (u32)
177 le64_to_cpu(*dd->ipath_hdrqtailptr)) {
178 if (dd->ipath_lastport0rcv_cnt ==
179 ipath_stats.sps_port0pkts) {
180 ipath_cdbg(PKT, "missing rcv interrupts? "
181 "port0 hd=%llx tl=%x; port0pkts %llx\n",
182 (unsigned long long)
183 le64_to_cpu(*dd->ipath_hdrqtailptr),
184 dd->ipath_port0head,
185 (unsigned long long)
186 ipath_stats.sps_port0pkts);
187 }
188 dd->ipath_lastport0rcv_cnt = ipath_stats.sps_port0pkts;
189 }
190}
191
192static void ipath_chk_errormask(struct ipath_devdata *dd)
193{
194 static u32 fixed;
195 u32 ctrl;
196 unsigned long errormask;
197 unsigned long hwerrs;
198
199 if (!dd->ipath_errormask || !(dd->ipath_flags & IPATH_INITTED))
200 return;
201
202 errormask = ipath_read_kreg64(dd, dd->ipath_kregs->kr_errormask);
203
204 if (errormask == dd->ipath_errormask)
205 return;
206 fixed++;
207
208 hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
209 ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
210
211 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
212 dd->ipath_errormask);
213
214 if ((hwerrs & dd->ipath_hwerrmask) ||
215 (ctrl & INFINIPATH_C_FREEZEMODE)) {
216
217 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear, 0ULL);
218 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, 0ULL);
219 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);
220 dev_info(&dd->pcidev->dev,
221 "errormask fixed(%u) %lx -> %lx, ctrl %x hwerr %lx\n",
222 fixed, errormask, (unsigned long)dd->ipath_errormask,
223 ctrl, hwerrs);
224 } else
225 ipath_dbg("errormask fixed(%u) %lx -> %lx, no freeze\n",
226 fixed, errormask,
227 (unsigned long)dd->ipath_errormask);
228}
229
230
231
232
233
234
235
236
237void ipath_get_faststats(unsigned long opaque)
238{
239 struct ipath_devdata *dd = (struct ipath_devdata *) opaque;
240 u32 val;
241 static unsigned cnt;
242 unsigned long flags;
243 u64 traffic_wds;
244
245
246
247
248
249 if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_INITTED) ||
250 ipath_diag_inuse)
251
252 goto done;
253
254
255
256
257
258
259 traffic_wds = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt) +
260 ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
261 spin_lock_irqsave(&dd->ipath_eep_st_lock, flags);
262 traffic_wds -= dd->ipath_traffic_wds;
263 dd->ipath_traffic_wds += traffic_wds;
264 if (traffic_wds >= IPATH_TRAFFIC_ACTIVE_THRESHOLD)
265 atomic_add(5, &dd->ipath_active_time);
266 spin_unlock_irqrestore(&dd->ipath_eep_st_lock, flags);
267
268 if (dd->ipath_flags & IPATH_32BITCOUNTERS) {
269 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
270 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
271 }
272
273 ipath_qcheck(dd);
274
275
276
277
278
279
280
281
282
283
284 if (dd->ipath_lasterror)
285 dd->ipath_lasterror = 0;
286 if (dd->ipath_lasthwerror)
287 dd->ipath_lasthwerror = 0;
288 if (dd->ipath_maskederrs
289 && time_after(jiffies, dd->ipath_unmasktime)) {
290 char ebuf[256];
291 int iserr;
292 iserr = ipath_decode_err(ebuf, sizeof ebuf,
293 dd->ipath_maskederrs);
294 if (dd->ipath_maskederrs &
295 ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
296 INFINIPATH_E_PKTERRS ))
297 ipath_dev_err(dd, "Re-enabling masked errors "
298 "(%s)\n", ebuf);
299 else {
300
301
302
303
304
305
306
307 if (iserr)
308 ipath_dbg("Re-enabling queue full errors (%s)\n",
309 ebuf);
310 else
311 ipath_cdbg(ERRPKT, "Re-enabling packet"
312 " problem interrupt (%s)\n", ebuf);
313 }
314
315
316 dd->ipath_errormask |= dd->ipath_maskederrs;
317 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
318 dd->ipath_errormask);
319 dd->ipath_maskederrs = 0;
320 }
321
322
323 if ((++cnt & 0x10)) {
324 for (val = dd->ipath_cfgports - 1; ((int)val) >= 0;
325 val--) {
326 if (dd->ipath_lastegrheads[val] != -1)
327 dd->ipath_lastegrheads[val] = -1;
328 if (dd->ipath_lastrcvhdrqtails[val] != -1)
329 dd->ipath_lastrcvhdrqtails[val] = -1;
330 }
331 }
332
333 ipath_chk_errormask(dd);
334done:
335 mod_timer(&dd->ipath_stats_timer, jiffies + HZ * 5);
336}
337