0001
0002
0003
0004
0005
0006 #include <linux/debugfs.h>
0007 #include <linux/seq_file.h>
0008 #include <linux/kernel.h>
0009 #include <linux/export.h>
0010 #include <linux/string.h>
0011 #include <linux/types.h>
0012 #include <linux/ratelimit.h>
0013 #include <linux/fault-inject.h>
0014
0015 #include "hfi.h"
0016 #include "trace.h"
0017 #include "debugfs.h"
0018 #include "device.h"
0019 #include "qp.h"
0020 #include "sdma.h"
0021 #include "fault.h"
0022
0023 static struct dentry *hfi1_dbg_root;
0024
0025
0026 ssize_t hfi1_seq_read(struct file *file, char __user *buf, size_t size,
0027 loff_t *ppos)
0028 {
0029 struct dentry *d = file->f_path.dentry;
0030 ssize_t r;
0031
0032 r = debugfs_file_get(d);
0033 if (unlikely(r))
0034 return r;
0035 r = seq_read(file, buf, size, ppos);
0036 debugfs_file_put(d);
0037 return r;
0038 }
0039
0040 loff_t hfi1_seq_lseek(struct file *file, loff_t offset, int whence)
0041 {
0042 struct dentry *d = file->f_path.dentry;
0043 loff_t r;
0044
0045 r = debugfs_file_get(d);
0046 if (unlikely(r))
0047 return r;
0048 r = seq_lseek(file, offset, whence);
0049 debugfs_file_put(d);
0050 return r;
0051 }
0052
0053 #define private2dd(file) (file_inode(file)->i_private)
0054 #define private2ppd(file) (file_inode(file)->i_private)
0055
0056 static void *_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
0057 {
0058 struct hfi1_opcode_stats_perctx *opstats;
0059
0060 if (*pos >= ARRAY_SIZE(opstats->stats))
0061 return NULL;
0062 return pos;
0063 }
0064
0065 static void *_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
0066 {
0067 struct hfi1_opcode_stats_perctx *opstats;
0068
0069 ++*pos;
0070 if (*pos >= ARRAY_SIZE(opstats->stats))
0071 return NULL;
0072 return pos;
0073 }
0074
0075 static void _opcode_stats_seq_stop(struct seq_file *s, void *v)
0076 {
0077 }
0078
0079 static int opcode_stats_show(struct seq_file *s, u8 i, u64 packets, u64 bytes)
0080 {
0081 if (!packets && !bytes)
0082 return SEQ_SKIP;
0083 seq_printf(s, "%02x %llu/%llu\n", i,
0084 (unsigned long long)packets,
0085 (unsigned long long)bytes);
0086
0087 return 0;
0088 }
0089
0090 static int _opcode_stats_seq_show(struct seq_file *s, void *v)
0091 {
0092 loff_t *spos = v;
0093 loff_t i = *spos, j;
0094 u64 n_packets = 0, n_bytes = 0;
0095 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0096 struct hfi1_devdata *dd = dd_from_dev(ibd);
0097 struct hfi1_ctxtdata *rcd;
0098
0099 for (j = 0; j < dd->first_dyn_alloc_ctxt; j++) {
0100 rcd = hfi1_rcd_get_by_index(dd, j);
0101 if (rcd) {
0102 n_packets += rcd->opstats->stats[i].n_packets;
0103 n_bytes += rcd->opstats->stats[i].n_bytes;
0104 }
0105 hfi1_rcd_put(rcd);
0106 }
0107 return opcode_stats_show(s, i, n_packets, n_bytes);
0108 }
0109
0110 DEBUGFS_SEQ_FILE_OPS(opcode_stats);
0111 DEBUGFS_SEQ_FILE_OPEN(opcode_stats)
0112 DEBUGFS_FILE_OPS(opcode_stats);
0113
0114 static void *_tx_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
0115 {
0116 return _opcode_stats_seq_start(s, pos);
0117 }
0118
0119 static void *_tx_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
0120 {
0121 return _opcode_stats_seq_next(s, v, pos);
0122 }
0123
0124 static void _tx_opcode_stats_seq_stop(struct seq_file *s, void *v)
0125 {
0126 }
0127
0128 static int _tx_opcode_stats_seq_show(struct seq_file *s, void *v)
0129 {
0130 loff_t *spos = v;
0131 loff_t i = *spos;
0132 int j;
0133 u64 n_packets = 0, n_bytes = 0;
0134 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0135 struct hfi1_devdata *dd = dd_from_dev(ibd);
0136
0137 for_each_possible_cpu(j) {
0138 struct hfi1_opcode_stats_perctx *s =
0139 per_cpu_ptr(dd->tx_opstats, j);
0140 n_packets += s->stats[i].n_packets;
0141 n_bytes += s->stats[i].n_bytes;
0142 }
0143 return opcode_stats_show(s, i, n_packets, n_bytes);
0144 }
0145
0146 DEBUGFS_SEQ_FILE_OPS(tx_opcode_stats);
0147 DEBUGFS_SEQ_FILE_OPEN(tx_opcode_stats)
0148 DEBUGFS_FILE_OPS(tx_opcode_stats);
0149
0150 static void *_ctx_stats_seq_start(struct seq_file *s, loff_t *pos)
0151 {
0152 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0153 struct hfi1_devdata *dd = dd_from_dev(ibd);
0154
0155 if (!*pos)
0156 return SEQ_START_TOKEN;
0157 if (*pos >= dd->first_dyn_alloc_ctxt)
0158 return NULL;
0159 return pos;
0160 }
0161
0162 static void *_ctx_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
0163 {
0164 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0165 struct hfi1_devdata *dd = dd_from_dev(ibd);
0166
0167 if (v == SEQ_START_TOKEN)
0168 return pos;
0169
0170 ++*pos;
0171 if (*pos >= dd->first_dyn_alloc_ctxt)
0172 return NULL;
0173 return pos;
0174 }
0175
0176 static void _ctx_stats_seq_stop(struct seq_file *s, void *v)
0177 {
0178
0179 }
0180
0181 static int _ctx_stats_seq_show(struct seq_file *s, void *v)
0182 {
0183 loff_t *spos;
0184 loff_t i, j;
0185 u64 n_packets = 0;
0186 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0187 struct hfi1_devdata *dd = dd_from_dev(ibd);
0188 struct hfi1_ctxtdata *rcd;
0189
0190 if (v == SEQ_START_TOKEN) {
0191 seq_puts(s, "Ctx:npkts\n");
0192 return 0;
0193 }
0194
0195 spos = v;
0196 i = *spos;
0197
0198 rcd = hfi1_rcd_get_by_index_safe(dd, i);
0199 if (!rcd)
0200 return SEQ_SKIP;
0201
0202 for (j = 0; j < ARRAY_SIZE(rcd->opstats->stats); j++)
0203 n_packets += rcd->opstats->stats[j].n_packets;
0204
0205 hfi1_rcd_put(rcd);
0206
0207 if (!n_packets)
0208 return SEQ_SKIP;
0209
0210 seq_printf(s, " %llu:%llu\n", i, n_packets);
0211 return 0;
0212 }
0213
0214 DEBUGFS_SEQ_FILE_OPS(ctx_stats);
0215 DEBUGFS_SEQ_FILE_OPEN(ctx_stats)
0216 DEBUGFS_FILE_OPS(ctx_stats);
0217
0218 static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
0219 __acquires(RCU)
0220 {
0221 struct rvt_qp_iter *iter;
0222 loff_t n = *pos;
0223
0224 iter = rvt_qp_iter_init(s->private, 0, NULL);
0225
0226
0227 rcu_read_lock();
0228
0229 if (!iter)
0230 return NULL;
0231
0232 do {
0233 if (rvt_qp_iter_next(iter)) {
0234 kfree(iter);
0235 return NULL;
0236 }
0237 } while (n--);
0238
0239 return iter;
0240 }
0241
0242 static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
0243 loff_t *pos)
0244 __must_hold(RCU)
0245 {
0246 struct rvt_qp_iter *iter = iter_ptr;
0247
0248 (*pos)++;
0249
0250 if (rvt_qp_iter_next(iter)) {
0251 kfree(iter);
0252 return NULL;
0253 }
0254
0255 return iter;
0256 }
0257
0258 static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr)
0259 __releases(RCU)
0260 {
0261 rcu_read_unlock();
0262 }
0263
0264 static int _qp_stats_seq_show(struct seq_file *s, void *iter_ptr)
0265 {
0266 struct rvt_qp_iter *iter = iter_ptr;
0267
0268 if (!iter)
0269 return 0;
0270
0271 qp_iter_print(s, iter);
0272
0273 return 0;
0274 }
0275
0276 DEBUGFS_SEQ_FILE_OPS(qp_stats);
0277 DEBUGFS_SEQ_FILE_OPEN(qp_stats)
0278 DEBUGFS_FILE_OPS(qp_stats);
0279
0280 static void *_sdes_seq_start(struct seq_file *s, loff_t *pos)
0281 {
0282 struct hfi1_ibdev *ibd;
0283 struct hfi1_devdata *dd;
0284
0285 ibd = (struct hfi1_ibdev *)s->private;
0286 dd = dd_from_dev(ibd);
0287 if (!dd->per_sdma || *pos >= dd->num_sdma)
0288 return NULL;
0289 return pos;
0290 }
0291
0292 static void *_sdes_seq_next(struct seq_file *s, void *v, loff_t *pos)
0293 {
0294 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0295 struct hfi1_devdata *dd = dd_from_dev(ibd);
0296
0297 ++*pos;
0298 if (!dd->per_sdma || *pos >= dd->num_sdma)
0299 return NULL;
0300 return pos;
0301 }
0302
0303 static void _sdes_seq_stop(struct seq_file *s, void *v)
0304 {
0305 }
0306
0307 static int _sdes_seq_show(struct seq_file *s, void *v)
0308 {
0309 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0310 struct hfi1_devdata *dd = dd_from_dev(ibd);
0311 loff_t *spos = v;
0312 loff_t i = *spos;
0313
0314 sdma_seqfile_dump_sde(s, &dd->per_sdma[i]);
0315 return 0;
0316 }
0317
0318 DEBUGFS_SEQ_FILE_OPS(sdes);
0319 DEBUGFS_SEQ_FILE_OPEN(sdes)
0320 DEBUGFS_FILE_OPS(sdes);
0321
0322 static void *_rcds_seq_start(struct seq_file *s, loff_t *pos)
0323 {
0324 struct hfi1_ibdev *ibd;
0325 struct hfi1_devdata *dd;
0326
0327 ibd = (struct hfi1_ibdev *)s->private;
0328 dd = dd_from_dev(ibd);
0329 if (!dd->rcd || *pos >= dd->n_krcv_queues)
0330 return NULL;
0331 return pos;
0332 }
0333
0334 static void *_rcds_seq_next(struct seq_file *s, void *v, loff_t *pos)
0335 {
0336 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0337 struct hfi1_devdata *dd = dd_from_dev(ibd);
0338
0339 ++*pos;
0340 if (!dd->rcd || *pos >= dd->num_rcv_contexts)
0341 return NULL;
0342 return pos;
0343 }
0344
0345 static void _rcds_seq_stop(struct seq_file *s, void *v)
0346 {
0347 }
0348
0349 static int _rcds_seq_show(struct seq_file *s, void *v)
0350 {
0351 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0352 struct hfi1_devdata *dd = dd_from_dev(ibd);
0353 struct hfi1_ctxtdata *rcd;
0354 loff_t *spos = v;
0355 loff_t i = *spos;
0356
0357 rcd = hfi1_rcd_get_by_index_safe(dd, i);
0358 if (rcd)
0359 seqfile_dump_rcd(s, rcd);
0360 hfi1_rcd_put(rcd);
0361 return 0;
0362 }
0363
0364 DEBUGFS_SEQ_FILE_OPS(rcds);
0365 DEBUGFS_SEQ_FILE_OPEN(rcds)
0366 DEBUGFS_FILE_OPS(rcds);
0367
0368 static void *_pios_seq_start(struct seq_file *s, loff_t *pos)
0369 {
0370 struct hfi1_ibdev *ibd;
0371 struct hfi1_devdata *dd;
0372
0373 ibd = (struct hfi1_ibdev *)s->private;
0374 dd = dd_from_dev(ibd);
0375 if (!dd->send_contexts || *pos >= dd->num_send_contexts)
0376 return NULL;
0377 return pos;
0378 }
0379
0380 static void *_pios_seq_next(struct seq_file *s, void *v, loff_t *pos)
0381 {
0382 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0383 struct hfi1_devdata *dd = dd_from_dev(ibd);
0384
0385 ++*pos;
0386 if (!dd->send_contexts || *pos >= dd->num_send_contexts)
0387 return NULL;
0388 return pos;
0389 }
0390
0391 static void _pios_seq_stop(struct seq_file *s, void *v)
0392 {
0393 }
0394
0395 static int _pios_seq_show(struct seq_file *s, void *v)
0396 {
0397 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
0398 struct hfi1_devdata *dd = dd_from_dev(ibd);
0399 struct send_context_info *sci;
0400 loff_t *spos = v;
0401 loff_t i = *spos;
0402 unsigned long flags;
0403
0404 spin_lock_irqsave(&dd->sc_lock, flags);
0405 sci = &dd->send_contexts[i];
0406 if (sci && sci->type != SC_USER && sci->allocated && sci->sc)
0407 seqfile_dump_sci(s, i, sci);
0408 spin_unlock_irqrestore(&dd->sc_lock, flags);
0409 return 0;
0410 }
0411
0412 DEBUGFS_SEQ_FILE_OPS(pios);
0413 DEBUGFS_SEQ_FILE_OPEN(pios)
0414 DEBUGFS_FILE_OPS(pios);
0415
0416
0417 static ssize_t dev_counters_read(struct file *file, char __user *buf,
0418 size_t count, loff_t *ppos)
0419 {
0420 u64 *counters;
0421 size_t avail;
0422 struct hfi1_devdata *dd;
0423 ssize_t rval;
0424
0425 dd = private2dd(file);
0426 avail = hfi1_read_cntrs(dd, NULL, &counters);
0427 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
0428 return rval;
0429 }
0430
0431
0432 static ssize_t dev_names_read(struct file *file, char __user *buf,
0433 size_t count, loff_t *ppos)
0434 {
0435 char *names;
0436 size_t avail;
0437 struct hfi1_devdata *dd;
0438 ssize_t rval;
0439
0440 dd = private2dd(file);
0441 avail = hfi1_read_cntrs(dd, &names, NULL);
0442 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
0443 return rval;
0444 }
0445
0446 struct counter_info {
0447 char *name;
0448 const struct file_operations ops;
0449 };
0450
0451
0452
0453
0454
0455
0456
0457 static ssize_t portnames_read(struct file *file, char __user *buf,
0458 size_t count, loff_t *ppos)
0459 {
0460 char *names;
0461 size_t avail;
0462 struct hfi1_devdata *dd;
0463 ssize_t rval;
0464
0465 dd = private2dd(file);
0466 avail = hfi1_read_portcntrs(dd->pport, &names, NULL);
0467 rval = simple_read_from_buffer(buf, count, ppos, names, avail);
0468 return rval;
0469 }
0470
0471
0472 static ssize_t portcntrs_debugfs_read(struct file *file, char __user *buf,
0473 size_t count, loff_t *ppos)
0474 {
0475 u64 *counters;
0476 size_t avail;
0477 struct hfi1_pportdata *ppd;
0478 ssize_t rval;
0479
0480 ppd = private2ppd(file);
0481 avail = hfi1_read_portcntrs(ppd, NULL, &counters);
0482 rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
0483 return rval;
0484 }
0485
0486 static void check_dyn_flag(u64 scratch0, char *p, int size, int *used,
0487 int this_hfi, int hfi, u32 flag, const char *what)
0488 {
0489 u32 mask;
0490
0491 mask = flag << (hfi ? CR_DYN_SHIFT : 0);
0492 if (scratch0 & mask) {
0493 *used += scnprintf(p + *used, size - *used,
0494 " 0x%08x - HFI%d %s in use, %s device\n",
0495 mask, hfi, what,
0496 this_hfi == hfi ? "this" : "other");
0497 }
0498 }
0499
0500 static ssize_t asic_flags_read(struct file *file, char __user *buf,
0501 size_t count, loff_t *ppos)
0502 {
0503 struct hfi1_pportdata *ppd;
0504 struct hfi1_devdata *dd;
0505 u64 scratch0;
0506 char *tmp;
0507 int ret = 0;
0508 int size;
0509 int used;
0510 int i;
0511
0512 ppd = private2ppd(file);
0513 dd = ppd->dd;
0514 size = PAGE_SIZE;
0515 used = 0;
0516 tmp = kmalloc(size, GFP_KERNEL);
0517 if (!tmp)
0518 return -ENOMEM;
0519
0520 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
0521 used += scnprintf(tmp + used, size - used,
0522 "Resource flags: 0x%016llx\n", scratch0);
0523
0524
0525 if (scratch0 & CR_THERM_INIT) {
0526 used += scnprintf(tmp + used, size - used,
0527 " 0x%08x - thermal monitoring initialized\n",
0528 (u32)CR_THERM_INIT);
0529 }
0530
0531
0532 for (i = 0; i < 2; i++) {
0533 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
0534 CR_SBUS, "SBus");
0535 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
0536 CR_EPROM, "EPROM");
0537 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
0538 CR_I2C1, "i2c chain 1");
0539 check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
0540 CR_I2C2, "i2c chain 2");
0541 }
0542 used += scnprintf(tmp + used, size - used, "Write bits to clear\n");
0543
0544 ret = simple_read_from_buffer(buf, count, ppos, tmp, used);
0545 kfree(tmp);
0546 return ret;
0547 }
0548
0549 static ssize_t asic_flags_write(struct file *file, const char __user *buf,
0550 size_t count, loff_t *ppos)
0551 {
0552 struct hfi1_pportdata *ppd;
0553 struct hfi1_devdata *dd;
0554 char *buff;
0555 int ret;
0556 unsigned long long value;
0557 u64 scratch0;
0558 u64 clear;
0559
0560 ppd = private2ppd(file);
0561 dd = ppd->dd;
0562
0563
0564 buff = memdup_user_nul(buf, count);
0565 if (IS_ERR(buff))
0566 return PTR_ERR(buff);
0567
0568 ret = kstrtoull(buff, 0, &value);
0569 if (ret)
0570 goto do_free;
0571 clear = value;
0572
0573
0574 mutex_lock(&dd->asic_data->asic_resource_mutex);
0575 acquire_hw_mutex(dd);
0576
0577 scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
0578 scratch0 &= ~clear;
0579 write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
0580
0581 (void)read_csr(dd, ASIC_CFG_SCRATCH);
0582
0583 release_hw_mutex(dd);
0584 mutex_unlock(&dd->asic_data->asic_resource_mutex);
0585
0586
0587 ret = count;
0588
0589 do_free:
0590 kfree(buff);
0591 return ret;
0592 }
0593
0594
0595 static ssize_t dc8051_memory_read(struct file *file, char __user *buf,
0596 size_t count, loff_t *ppos)
0597 {
0598 struct hfi1_pportdata *ppd = private2ppd(file);
0599 ssize_t rval;
0600 void *tmp;
0601 loff_t start, end;
0602
0603
0604 if (*ppos < 0)
0605 return -EINVAL;
0606
0607 tmp = kzalloc(DC8051_DATA_MEM_SIZE, GFP_KERNEL);
0608 if (!tmp)
0609 return -ENOMEM;
0610
0611
0612
0613
0614
0615
0616
0617 start = *ppos & ~0x7;
0618 if (start < DC8051_DATA_MEM_SIZE) {
0619 end = (*ppos + count + 7) & ~0x7;
0620 if (end > DC8051_DATA_MEM_SIZE)
0621 end = DC8051_DATA_MEM_SIZE;
0622 rval = read_8051_data(ppd->dd, start, end - start,
0623 (u64 *)(tmp + start));
0624 if (rval)
0625 goto done;
0626 }
0627
0628 rval = simple_read_from_buffer(buf, count, ppos, tmp,
0629 DC8051_DATA_MEM_SIZE);
0630 done:
0631 kfree(tmp);
0632 return rval;
0633 }
0634
0635 static ssize_t debugfs_lcb_read(struct file *file, char __user *buf,
0636 size_t count, loff_t *ppos)
0637 {
0638 struct hfi1_pportdata *ppd = private2ppd(file);
0639 struct hfi1_devdata *dd = ppd->dd;
0640 unsigned long total, csr_off;
0641 u64 data;
0642
0643 if (*ppos < 0)
0644 return -EINVAL;
0645
0646 if ((count % 8) != 0)
0647 return -EINVAL;
0648
0649 if ((*ppos % 8) != 0)
0650 return -EINVAL;
0651
0652 if (*ppos >= (LCB_END - LCB_START) || !count)
0653 return 0;
0654
0655 if (*ppos + count > LCB_END - LCB_START)
0656 count = (LCB_END - LCB_START) - *ppos;
0657
0658 csr_off = LCB_START + *ppos;
0659 for (total = 0; total < count; total += 8, csr_off += 8) {
0660 if (read_lcb_csr(dd, csr_off, (u64 *)&data))
0661 break;
0662 if (put_user(data, (unsigned long __user *)(buf + total)))
0663 break;
0664 }
0665 *ppos += total;
0666 return total;
0667 }
0668
0669 static ssize_t debugfs_lcb_write(struct file *file, const char __user *buf,
0670 size_t count, loff_t *ppos)
0671 {
0672 struct hfi1_pportdata *ppd = private2ppd(file);
0673 struct hfi1_devdata *dd = ppd->dd;
0674 unsigned long total, csr_off, data;
0675
0676 if (*ppos < 0)
0677 return -EINVAL;
0678
0679 if ((count % 8) != 0)
0680 return -EINVAL;
0681
0682 if ((*ppos % 8) != 0)
0683 return -EINVAL;
0684
0685 if (*ppos >= (LCB_END - LCB_START) || !count)
0686 return 0;
0687
0688 if (*ppos + count > LCB_END - LCB_START)
0689 count = (LCB_END - LCB_START) - *ppos;
0690
0691 csr_off = LCB_START + *ppos;
0692 for (total = 0; total < count; total += 8, csr_off += 8) {
0693 if (get_user(data, (unsigned long __user *)(buf + total)))
0694 break;
0695 if (write_lcb_csr(dd, csr_off, data))
0696 break;
0697 }
0698 *ppos += total;
0699 return total;
0700 }
0701
0702
0703
0704
0705 static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf,
0706 size_t count, loff_t *ppos)
0707 {
0708 struct hfi1_pportdata *ppd;
0709 char *tmp;
0710 int ret;
0711
0712 ppd = private2ppd(file);
0713 tmp = kmalloc(PAGE_SIZE, GFP_KERNEL);
0714 if (!tmp)
0715 return -ENOMEM;
0716
0717 ret = qsfp_dump(ppd, tmp, PAGE_SIZE);
0718 if (ret > 0)
0719 ret = simple_read_from_buffer(buf, count, ppos, tmp, ret);
0720 kfree(tmp);
0721 return ret;
0722 }
0723
0724
0725 static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
0726 size_t count, loff_t *ppos, u32 target)
0727 {
0728 struct hfi1_pportdata *ppd;
0729 char *buff;
0730 int ret;
0731 int i2c_addr;
0732 int offset;
0733 int total_written;
0734
0735 ppd = private2ppd(file);
0736
0737
0738 i2c_addr = (*ppos >> 16) & 0xffff;
0739 offset = *ppos & 0xffff;
0740
0741
0742 if (i2c_addr == 0)
0743 return -EINVAL;
0744
0745 buff = memdup_user(buf, count);
0746 if (IS_ERR(buff))
0747 return PTR_ERR(buff);
0748
0749 total_written = i2c_write(ppd, target, i2c_addr, offset, buff, count);
0750 if (total_written < 0) {
0751 ret = total_written;
0752 goto _free;
0753 }
0754
0755 *ppos += total_written;
0756
0757 ret = total_written;
0758
0759 _free:
0760 kfree(buff);
0761 return ret;
0762 }
0763
0764
0765 static ssize_t i2c1_debugfs_write(struct file *file, const char __user *buf,
0766 size_t count, loff_t *ppos)
0767 {
0768 return __i2c_debugfs_write(file, buf, count, ppos, 0);
0769 }
0770
0771
0772 static ssize_t i2c2_debugfs_write(struct file *file, const char __user *buf,
0773 size_t count, loff_t *ppos)
0774 {
0775 return __i2c_debugfs_write(file, buf, count, ppos, 1);
0776 }
0777
0778
0779 static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
0780 size_t count, loff_t *ppos, u32 target)
0781 {
0782 struct hfi1_pportdata *ppd;
0783 char *buff;
0784 int ret;
0785 int i2c_addr;
0786 int offset;
0787 int total_read;
0788
0789 ppd = private2ppd(file);
0790
0791
0792 i2c_addr = (*ppos >> 16) & 0xffff;
0793 offset = *ppos & 0xffff;
0794
0795
0796 if (i2c_addr == 0)
0797 return -EINVAL;
0798
0799 buff = kmalloc(count, GFP_KERNEL);
0800 if (!buff)
0801 return -ENOMEM;
0802
0803 total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count);
0804 if (total_read < 0) {
0805 ret = total_read;
0806 goto _free;
0807 }
0808
0809 *ppos += total_read;
0810
0811 ret = copy_to_user(buf, buff, total_read);
0812 if (ret > 0) {
0813 ret = -EFAULT;
0814 goto _free;
0815 }
0816
0817 ret = total_read;
0818
0819 _free:
0820 kfree(buff);
0821 return ret;
0822 }
0823
0824
0825 static ssize_t i2c1_debugfs_read(struct file *file, char __user *buf,
0826 size_t count, loff_t *ppos)
0827 {
0828 return __i2c_debugfs_read(file, buf, count, ppos, 0);
0829 }
0830
0831
0832 static ssize_t i2c2_debugfs_read(struct file *file, char __user *buf,
0833 size_t count, loff_t *ppos)
0834 {
0835 return __i2c_debugfs_read(file, buf, count, ppos, 1);
0836 }
0837
0838
0839 static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
0840 size_t count, loff_t *ppos, u32 target)
0841 {
0842 struct hfi1_pportdata *ppd;
0843 char *buff;
0844 int ret;
0845 int total_written;
0846
0847 if (*ppos + count > QSFP_PAGESIZE * 4)
0848 return -EINVAL;
0849
0850 ppd = private2ppd(file);
0851
0852 buff = memdup_user(buf, count);
0853 if (IS_ERR(buff))
0854 return PTR_ERR(buff);
0855
0856 total_written = qsfp_write(ppd, target, *ppos, buff, count);
0857 if (total_written < 0) {
0858 ret = total_written;
0859 goto _free;
0860 }
0861
0862 *ppos += total_written;
0863
0864 ret = total_written;
0865
0866 _free:
0867 kfree(buff);
0868 return ret;
0869 }
0870
0871
0872 static ssize_t qsfp1_debugfs_write(struct file *file, const char __user *buf,
0873 size_t count, loff_t *ppos)
0874 {
0875 return __qsfp_debugfs_write(file, buf, count, ppos, 0);
0876 }
0877
0878
0879 static ssize_t qsfp2_debugfs_write(struct file *file, const char __user *buf,
0880 size_t count, loff_t *ppos)
0881 {
0882 return __qsfp_debugfs_write(file, buf, count, ppos, 1);
0883 }
0884
0885
0886 static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
0887 size_t count, loff_t *ppos, u32 target)
0888 {
0889 struct hfi1_pportdata *ppd;
0890 char *buff;
0891 int ret;
0892 int total_read;
0893
0894 if (*ppos + count > QSFP_PAGESIZE * 4) {
0895 ret = -EINVAL;
0896 goto _return;
0897 }
0898
0899 ppd = private2ppd(file);
0900
0901 buff = kmalloc(count, GFP_KERNEL);
0902 if (!buff) {
0903 ret = -ENOMEM;
0904 goto _return;
0905 }
0906
0907 total_read = qsfp_read(ppd, target, *ppos, buff, count);
0908 if (total_read < 0) {
0909 ret = total_read;
0910 goto _free;
0911 }
0912
0913 *ppos += total_read;
0914
0915 ret = copy_to_user(buf, buff, total_read);
0916 if (ret > 0) {
0917 ret = -EFAULT;
0918 goto _free;
0919 }
0920
0921 ret = total_read;
0922
0923 _free:
0924 kfree(buff);
0925 _return:
0926 return ret;
0927 }
0928
0929
0930 static ssize_t qsfp1_debugfs_read(struct file *file, char __user *buf,
0931 size_t count, loff_t *ppos)
0932 {
0933 return __qsfp_debugfs_read(file, buf, count, ppos, 0);
0934 }
0935
0936
0937 static ssize_t qsfp2_debugfs_read(struct file *file, char __user *buf,
0938 size_t count, loff_t *ppos)
0939 {
0940 return __qsfp_debugfs_read(file, buf, count, ppos, 1);
0941 }
0942
0943 static int __i2c_debugfs_open(struct inode *in, struct file *fp, u32 target)
0944 {
0945 struct hfi1_pportdata *ppd;
0946
0947 ppd = private2ppd(fp);
0948
0949 return acquire_chip_resource(ppd->dd, i2c_target(target), 0);
0950 }
0951
0952 static int i2c1_debugfs_open(struct inode *in, struct file *fp)
0953 {
0954 return __i2c_debugfs_open(in, fp, 0);
0955 }
0956
0957 static int i2c2_debugfs_open(struct inode *in, struct file *fp)
0958 {
0959 return __i2c_debugfs_open(in, fp, 1);
0960 }
0961
0962 static int __i2c_debugfs_release(struct inode *in, struct file *fp, u32 target)
0963 {
0964 struct hfi1_pportdata *ppd;
0965
0966 ppd = private2ppd(fp);
0967
0968 release_chip_resource(ppd->dd, i2c_target(target));
0969
0970 return 0;
0971 }
0972
0973 static int i2c1_debugfs_release(struct inode *in, struct file *fp)
0974 {
0975 return __i2c_debugfs_release(in, fp, 0);
0976 }
0977
0978 static int i2c2_debugfs_release(struct inode *in, struct file *fp)
0979 {
0980 return __i2c_debugfs_release(in, fp, 1);
0981 }
0982
0983 static int __qsfp_debugfs_open(struct inode *in, struct file *fp, u32 target)
0984 {
0985 struct hfi1_pportdata *ppd;
0986
0987 ppd = private2ppd(fp);
0988
0989 return acquire_chip_resource(ppd->dd, i2c_target(target), 0);
0990 }
0991
0992 static int qsfp1_debugfs_open(struct inode *in, struct file *fp)
0993 {
0994 return __qsfp_debugfs_open(in, fp, 0);
0995 }
0996
0997 static int qsfp2_debugfs_open(struct inode *in, struct file *fp)
0998 {
0999 return __qsfp_debugfs_open(in, fp, 1);
1000 }
1001
1002 static int __qsfp_debugfs_release(struct inode *in, struct file *fp, u32 target)
1003 {
1004 struct hfi1_pportdata *ppd;
1005
1006 ppd = private2ppd(fp);
1007
1008 release_chip_resource(ppd->dd, i2c_target(target));
1009
1010 return 0;
1011 }
1012
1013 static int qsfp1_debugfs_release(struct inode *in, struct file *fp)
1014 {
1015 return __qsfp_debugfs_release(in, fp, 0);
1016 }
1017
1018 static int qsfp2_debugfs_release(struct inode *in, struct file *fp)
1019 {
1020 return __qsfp_debugfs_release(in, fp, 1);
1021 }
1022
1023 #define EXPROM_WRITE_ENABLE BIT_ULL(14)
1024
1025 static bool exprom_wp_disabled;
1026
1027 static int exprom_wp_set(struct hfi1_devdata *dd, bool disable)
1028 {
1029 u64 gpio_val = 0;
1030
1031 if (disable) {
1032 gpio_val = EXPROM_WRITE_ENABLE;
1033 exprom_wp_disabled = true;
1034 dd_dev_info(dd, "Disable Expansion ROM Write Protection\n");
1035 } else {
1036 exprom_wp_disabled = false;
1037 dd_dev_info(dd, "Enable Expansion ROM Write Protection\n");
1038 }
1039
1040 write_csr(dd, ASIC_GPIO_OUT, gpio_val);
1041 write_csr(dd, ASIC_GPIO_OE, gpio_val);
1042
1043 return 0;
1044 }
1045
1046 static ssize_t exprom_wp_debugfs_read(struct file *file, char __user *buf,
1047 size_t count, loff_t *ppos)
1048 {
1049 return 0;
1050 }
1051
1052 static ssize_t exprom_wp_debugfs_write(struct file *file,
1053 const char __user *buf, size_t count,
1054 loff_t *ppos)
1055 {
1056 struct hfi1_pportdata *ppd = private2ppd(file);
1057 char cdata;
1058
1059 if (count != 1)
1060 return -EINVAL;
1061 if (get_user(cdata, buf))
1062 return -EFAULT;
1063 if (cdata == '0')
1064 exprom_wp_set(ppd->dd, false);
1065 else if (cdata == '1')
1066 exprom_wp_set(ppd->dd, true);
1067 else
1068 return -EINVAL;
1069
1070 return 1;
1071 }
1072
1073 static unsigned long exprom_in_use;
1074
1075 static int exprom_wp_debugfs_open(struct inode *in, struct file *fp)
1076 {
1077 if (test_and_set_bit(0, &exprom_in_use))
1078 return -EBUSY;
1079
1080 return 0;
1081 }
1082
1083 static int exprom_wp_debugfs_release(struct inode *in, struct file *fp)
1084 {
1085 struct hfi1_pportdata *ppd = private2ppd(fp);
1086
1087 if (exprom_wp_disabled)
1088 exprom_wp_set(ppd->dd, false);
1089 clear_bit(0, &exprom_in_use);
1090
1091 return 0;
1092 }
1093
1094 #define DEBUGFS_OPS(nm, readroutine, writeroutine) \
1095 { \
1096 .name = nm, \
1097 .ops = { \
1098 .owner = THIS_MODULE, \
1099 .read = readroutine, \
1100 .write = writeroutine, \
1101 .llseek = generic_file_llseek, \
1102 }, \
1103 }
1104
1105 #define DEBUGFS_XOPS(nm, readf, writef, openf, releasef) \
1106 { \
1107 .name = nm, \
1108 .ops = { \
1109 .owner = THIS_MODULE, \
1110 .read = readf, \
1111 .write = writef, \
1112 .llseek = generic_file_llseek, \
1113 .open = openf, \
1114 .release = releasef \
1115 }, \
1116 }
1117
1118 static const struct counter_info cntr_ops[] = {
1119 DEBUGFS_OPS("counter_names", dev_names_read, NULL),
1120 DEBUGFS_OPS("counters", dev_counters_read, NULL),
1121 DEBUGFS_OPS("portcounter_names", portnames_read, NULL),
1122 };
1123
1124 static const struct counter_info port_cntr_ops[] = {
1125 DEBUGFS_OPS("port%dcounters", portcntrs_debugfs_read, NULL),
1126 DEBUGFS_XOPS("i2c1", i2c1_debugfs_read, i2c1_debugfs_write,
1127 i2c1_debugfs_open, i2c1_debugfs_release),
1128 DEBUGFS_XOPS("i2c2", i2c2_debugfs_read, i2c2_debugfs_write,
1129 i2c2_debugfs_open, i2c2_debugfs_release),
1130 DEBUGFS_OPS("qsfp_dump%d", qsfp_debugfs_dump, NULL),
1131 DEBUGFS_XOPS("qsfp1", qsfp1_debugfs_read, qsfp1_debugfs_write,
1132 qsfp1_debugfs_open, qsfp1_debugfs_release),
1133 DEBUGFS_XOPS("qsfp2", qsfp2_debugfs_read, qsfp2_debugfs_write,
1134 qsfp2_debugfs_open, qsfp2_debugfs_release),
1135 DEBUGFS_XOPS("exprom_wp", exprom_wp_debugfs_read,
1136 exprom_wp_debugfs_write, exprom_wp_debugfs_open,
1137 exprom_wp_debugfs_release),
1138 DEBUGFS_OPS("asic_flags", asic_flags_read, asic_flags_write),
1139 DEBUGFS_OPS("dc8051_memory", dc8051_memory_read, NULL),
1140 DEBUGFS_OPS("lcb", debugfs_lcb_read, debugfs_lcb_write),
1141 };
1142
1143 static void *_sdma_cpu_list_seq_start(struct seq_file *s, loff_t *pos)
1144 {
1145 if (*pos >= num_online_cpus())
1146 return NULL;
1147
1148 return pos;
1149 }
1150
1151 static void *_sdma_cpu_list_seq_next(struct seq_file *s, void *v, loff_t *pos)
1152 {
1153 ++*pos;
1154 if (*pos >= num_online_cpus())
1155 return NULL;
1156
1157 return pos;
1158 }
1159
1160 static void _sdma_cpu_list_seq_stop(struct seq_file *s, void *v)
1161 {
1162
1163 }
1164
1165 static int _sdma_cpu_list_seq_show(struct seq_file *s, void *v)
1166 {
1167 struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
1168 struct hfi1_devdata *dd = dd_from_dev(ibd);
1169 loff_t *spos = v;
1170 loff_t i = *spos;
1171
1172 sdma_seqfile_dump_cpu_list(s, dd, (unsigned long)i);
1173 return 0;
1174 }
1175
1176 DEBUGFS_SEQ_FILE_OPS(sdma_cpu_list);
1177 DEBUGFS_SEQ_FILE_OPEN(sdma_cpu_list)
1178 DEBUGFS_FILE_OPS(sdma_cpu_list);
1179
1180 void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
1181 {
1182 char name[sizeof("port0counters") + 1];
1183 char link[10];
1184 struct hfi1_devdata *dd = dd_from_dev(ibd);
1185 struct hfi1_pportdata *ppd;
1186 struct dentry *root;
1187 int unit = dd->unit;
1188 int i, j;
1189
1190 if (!hfi1_dbg_root)
1191 return;
1192 snprintf(name, sizeof(name), "%s_%d", class_name(), unit);
1193 snprintf(link, sizeof(link), "%d", unit);
1194 root = debugfs_create_dir(name, hfi1_dbg_root);
1195 ibd->hfi1_ibdev_dbg = root;
1196
1197 ibd->hfi1_ibdev_link =
1198 debugfs_create_symlink(link, hfi1_dbg_root, name);
1199
1200 debugfs_create_file("opcode_stats", 0444, root, ibd,
1201 &_opcode_stats_file_ops);
1202 debugfs_create_file("tx_opcode_stats", 0444, root, ibd,
1203 &_tx_opcode_stats_file_ops);
1204 debugfs_create_file("ctx_stats", 0444, root, ibd, &_ctx_stats_file_ops);
1205 debugfs_create_file("qp_stats", 0444, root, ibd, &_qp_stats_file_ops);
1206 debugfs_create_file("sdes", 0444, root, ibd, &_sdes_file_ops);
1207 debugfs_create_file("rcds", 0444, root, ibd, &_rcds_file_ops);
1208 debugfs_create_file("pios", 0444, root, ibd, &_pios_file_ops);
1209 debugfs_create_file("sdma_cpu_list", 0444, root, ibd,
1210 &_sdma_cpu_list_file_ops);
1211
1212
1213 for (i = 0; i < ARRAY_SIZE(cntr_ops); i++)
1214 debugfs_create_file(cntr_ops[i].name, 0444, root, dd,
1215 &cntr_ops[i].ops);
1216
1217
1218 for (ppd = dd->pport, j = 0; j < dd->num_pports; j++, ppd++)
1219 for (i = 0; i < ARRAY_SIZE(port_cntr_ops); i++) {
1220 snprintf(name,
1221 sizeof(name),
1222 port_cntr_ops[i].name,
1223 j + 1);
1224 debugfs_create_file(name,
1225 !port_cntr_ops[i].ops.write ?
1226 S_IRUGO :
1227 S_IRUGO | S_IWUSR,
1228 root, ppd, &port_cntr_ops[i].ops);
1229 }
1230
1231 hfi1_fault_init_debugfs(ibd);
1232 }
1233
1234 void hfi1_dbg_ibdev_exit(struct hfi1_ibdev *ibd)
1235 {
1236 if (!hfi1_dbg_root)
1237 goto out;
1238 hfi1_fault_exit_debugfs(ibd);
1239 debugfs_remove(ibd->hfi1_ibdev_link);
1240 debugfs_remove_recursive(ibd->hfi1_ibdev_dbg);
1241 out:
1242 ibd->hfi1_ibdev_dbg = NULL;
1243 }
1244
1245
1246
1247
1248
1249
1250
1251
1252 static const char * const hfi1_statnames[] = {
1253
1254 "KernIntr",
1255 "ErrorIntr",
1256 "Tx_Errs",
1257 "Rcv_Errs",
1258 "H/W_Errs",
1259 "NoPIOBufs",
1260 "CtxtsOpen",
1261 "RcvLen_Errs",
1262 "EgrBufFull",
1263 "EgrHdrFull"
1264 };
1265
1266 static void *_driver_stats_names_seq_start(struct seq_file *s, loff_t *pos)
1267 {
1268 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1269 return NULL;
1270 return pos;
1271 }
1272
1273 static void *_driver_stats_names_seq_next(
1274 struct seq_file *s,
1275 void *v,
1276 loff_t *pos)
1277 {
1278 ++*pos;
1279 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1280 return NULL;
1281 return pos;
1282 }
1283
1284 static void _driver_stats_names_seq_stop(struct seq_file *s, void *v)
1285 {
1286 }
1287
1288 static int _driver_stats_names_seq_show(struct seq_file *s, void *v)
1289 {
1290 loff_t *spos = v;
1291
1292 seq_printf(s, "%s\n", hfi1_statnames[*spos]);
1293 return 0;
1294 }
1295
1296 DEBUGFS_SEQ_FILE_OPS(driver_stats_names);
1297 DEBUGFS_SEQ_FILE_OPEN(driver_stats_names)
1298 DEBUGFS_FILE_OPS(driver_stats_names);
1299
1300 static void *_driver_stats_seq_start(struct seq_file *s, loff_t *pos)
1301 {
1302 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1303 return NULL;
1304 return pos;
1305 }
1306
1307 static void *_driver_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
1308 {
1309 ++*pos;
1310 if (*pos >= ARRAY_SIZE(hfi1_statnames))
1311 return NULL;
1312 return pos;
1313 }
1314
1315 static void _driver_stats_seq_stop(struct seq_file *s, void *v)
1316 {
1317 }
1318
1319 static void hfi1_sps_show_ints(struct seq_file *s)
1320 {
1321 unsigned long index, flags;
1322 struct hfi1_devdata *dd;
1323 u64 sps_ints = 0;
1324
1325 xa_lock_irqsave(&hfi1_dev_table, flags);
1326 xa_for_each(&hfi1_dev_table, index, dd) {
1327 sps_ints += get_all_cpu_total(dd->int_counter);
1328 }
1329 xa_unlock_irqrestore(&hfi1_dev_table, flags);
1330 seq_write(s, &sps_ints, sizeof(u64));
1331 }
1332
1333 static int _driver_stats_seq_show(struct seq_file *s, void *v)
1334 {
1335 loff_t *spos = v;
1336 u64 *stats = (u64 *)&hfi1_stats;
1337
1338
1339 if (*spos == 0)
1340 hfi1_sps_show_ints(s);
1341 else
1342 seq_write(s, stats + *spos, sizeof(u64));
1343 return 0;
1344 }
1345
1346 DEBUGFS_SEQ_FILE_OPS(driver_stats);
1347 DEBUGFS_SEQ_FILE_OPEN(driver_stats)
1348 DEBUGFS_FILE_OPS(driver_stats);
1349
1350 void hfi1_dbg_init(void)
1351 {
1352 hfi1_dbg_root = debugfs_create_dir(DRIVER_NAME, NULL);
1353 debugfs_create_file("driver_stats_names", 0444, hfi1_dbg_root, NULL,
1354 &_driver_stats_names_file_ops);
1355 debugfs_create_file("driver_stats", 0444, hfi1_dbg_root, NULL,
1356 &_driver_stats_file_ops);
1357 }
1358
1359 void hfi1_dbg_exit(void)
1360 {
1361 debugfs_remove_recursive(hfi1_dbg_root);
1362 hfi1_dbg_root = NULL;
1363 }