hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/infiniband/hw/hfi1/debugfs.c
....@@ -379,7 +379,7 @@
379379 struct hfi1_devdata *dd = dd_from_dev(ibd);
380380
381381 ++*pos;
382
- if (!dd->rcd || *pos >= dd->n_krcv_queues)
382
+ if (!dd->rcd || *pos >= dd->num_rcv_contexts)
383383 return NULL;
384384 return pos;
385385 }
....@@ -406,6 +406,54 @@
406406 DEBUGFS_SEQ_FILE_OPS(rcds);
407407 DEBUGFS_SEQ_FILE_OPEN(rcds)
408408 DEBUGFS_FILE_OPS(rcds);
409
+
410
+static void *_pios_seq_start(struct seq_file *s, loff_t *pos)
411
+{
412
+ struct hfi1_ibdev *ibd;
413
+ struct hfi1_devdata *dd;
414
+
415
+ ibd = (struct hfi1_ibdev *)s->private;
416
+ dd = dd_from_dev(ibd);
417
+ if (!dd->send_contexts || *pos >= dd->num_send_contexts)
418
+ return NULL;
419
+ return pos;
420
+}
421
+
422
+static void *_pios_seq_next(struct seq_file *s, void *v, loff_t *pos)
423
+{
424
+ struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
425
+ struct hfi1_devdata *dd = dd_from_dev(ibd);
426
+
427
+ ++*pos;
428
+ if (!dd->send_contexts || *pos >= dd->num_send_contexts)
429
+ return NULL;
430
+ return pos;
431
+}
432
+
433
+static void _pios_seq_stop(struct seq_file *s, void *v)
434
+{
435
+}
436
+
437
+static int _pios_seq_show(struct seq_file *s, void *v)
438
+{
439
+ struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
440
+ struct hfi1_devdata *dd = dd_from_dev(ibd);
441
+ struct send_context_info *sci;
442
+ loff_t *spos = v;
443
+ loff_t i = *spos;
444
+ unsigned long flags;
445
+
446
+ spin_lock_irqsave(&dd->sc_lock, flags);
447
+ sci = &dd->send_contexts[i];
448
+ if (sci && sci->type != SC_USER && sci->allocated && sci->sc)
449
+ seqfile_dump_sci(s, i, sci);
450
+ spin_unlock_irqrestore(&dd->sc_lock, flags);
451
+ return 0;
452
+}
453
+
454
+DEBUGFS_SEQ_FILE_OPS(pios);
455
+DEBUGFS_SEQ_FILE_OPEN(pios)
456
+DEBUGFS_FILE_OPS(pios);
409457
410458 /* read the per-device counters */
411459 static ssize_t dev_counters_read(struct file *file, char __user *buf,
....@@ -937,18 +985,10 @@
937985 static int __i2c_debugfs_open(struct inode *in, struct file *fp, u32 target)
938986 {
939987 struct hfi1_pportdata *ppd;
940
- int ret;
941
-
942
- if (!try_module_get(THIS_MODULE))
943
- return -ENODEV;
944988
945989 ppd = private2ppd(fp);
946990
947
- ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
948
- if (ret) /* failed - release the module */
949
- module_put(THIS_MODULE);
950
-
951
- return ret;
991
+ return acquire_chip_resource(ppd->dd, i2c_target(target), 0);
952992 }
953993
954994 static int i2c1_debugfs_open(struct inode *in, struct file *fp)
....@@ -968,7 +1008,6 @@
9681008 ppd = private2ppd(fp);
9691009
9701010 release_chip_resource(ppd->dd, i2c_target(target));
971
- module_put(THIS_MODULE);
9721011
9731012 return 0;
9741013 }
....@@ -986,18 +1025,10 @@
9861025 static int __qsfp_debugfs_open(struct inode *in, struct file *fp, u32 target)
9871026 {
9881027 struct hfi1_pportdata *ppd;
989
- int ret;
990
-
991
- if (!try_module_get(THIS_MODULE))
992
- return -ENODEV;
9931028
9941029 ppd = private2ppd(fp);
9951030
996
- ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
997
- if (ret) /* failed - release the module */
998
- module_put(THIS_MODULE);
999
-
1000
- return ret;
1031
+ return acquire_chip_resource(ppd->dd, i2c_target(target), 0);
10011032 }
10021033
10031034 static int qsfp1_debugfs_open(struct inode *in, struct file *fp)
....@@ -1017,7 +1048,6 @@
10171048 ppd = private2ppd(fp);
10181049
10191050 release_chip_resource(ppd->dd, i2c_target(target));
1020
- module_put(THIS_MODULE);
10211051
10221052 return 0;
10231053 }
....@@ -1032,10 +1062,82 @@
10321062 return __qsfp_debugfs_release(in, fp, 1);
10331063 }
10341064
1065
+#define EXPROM_WRITE_ENABLE BIT_ULL(14)
1066
+
1067
+static bool exprom_wp_disabled;
1068
+
1069
+static int exprom_wp_set(struct hfi1_devdata *dd, bool disable)
1070
+{
1071
+ u64 gpio_val = 0;
1072
+
1073
+ if (disable) {
1074
+ gpio_val = EXPROM_WRITE_ENABLE;
1075
+ exprom_wp_disabled = true;
1076
+ dd_dev_info(dd, "Disable Expansion ROM Write Protection\n");
1077
+ } else {
1078
+ exprom_wp_disabled = false;
1079
+ dd_dev_info(dd, "Enable Expansion ROM Write Protection\n");
1080
+ }
1081
+
1082
+ write_csr(dd, ASIC_GPIO_OUT, gpio_val);
1083
+ write_csr(dd, ASIC_GPIO_OE, gpio_val);
1084
+
1085
+ return 0;
1086
+}
1087
+
1088
+static ssize_t exprom_wp_debugfs_read(struct file *file, char __user *buf,
1089
+ size_t count, loff_t *ppos)
1090
+{
1091
+ return 0;
1092
+}
1093
+
1094
+static ssize_t exprom_wp_debugfs_write(struct file *file,
1095
+ const char __user *buf, size_t count,
1096
+ loff_t *ppos)
1097
+{
1098
+ struct hfi1_pportdata *ppd = private2ppd(file);
1099
+ char cdata;
1100
+
1101
+ if (count != 1)
1102
+ return -EINVAL;
1103
+ if (get_user(cdata, buf))
1104
+ return -EFAULT;
1105
+ if (cdata == '0')
1106
+ exprom_wp_set(ppd->dd, false);
1107
+ else if (cdata == '1')
1108
+ exprom_wp_set(ppd->dd, true);
1109
+ else
1110
+ return -EINVAL;
1111
+
1112
+ return 1;
1113
+}
1114
+
1115
+static unsigned long exprom_in_use;
1116
+
1117
+static int exprom_wp_debugfs_open(struct inode *in, struct file *fp)
1118
+{
1119
+ if (test_and_set_bit(0, &exprom_in_use))
1120
+ return -EBUSY;
1121
+
1122
+ return 0;
1123
+}
1124
+
1125
+static int exprom_wp_debugfs_release(struct inode *in, struct file *fp)
1126
+{
1127
+ struct hfi1_pportdata *ppd = private2ppd(fp);
1128
+
1129
+ if (exprom_wp_disabled)
1130
+ exprom_wp_set(ppd->dd, false);
1131
+ clear_bit(0, &exprom_in_use);
1132
+
1133
+ return 0;
1134
+}
1135
+
10351136 #define DEBUGFS_OPS(nm, readroutine, writeroutine) \
10361137 { \
10371138 .name = nm, \
10381139 .ops = { \
1140
+ .owner = THIS_MODULE, \
10391141 .read = readroutine, \
10401142 .write = writeroutine, \
10411143 .llseek = generic_file_llseek, \
....@@ -1046,6 +1148,7 @@
10461148 { \
10471149 .name = nm, \
10481150 .ops = { \
1151
+ .owner = THIS_MODULE, \
10491152 .read = readf, \
10501153 .write = writef, \
10511154 .llseek = generic_file_llseek, \
....@@ -1071,6 +1174,9 @@
10711174 qsfp1_debugfs_open, qsfp1_debugfs_release),
10721175 DEBUGFS_XOPS("qsfp2", qsfp2_debugfs_read, qsfp2_debugfs_write,
10731176 qsfp2_debugfs_open, qsfp2_debugfs_release),
1177
+ DEBUGFS_XOPS("exprom_wp", exprom_wp_debugfs_read,
1178
+ exprom_wp_debugfs_write, exprom_wp_debugfs_open,
1179
+ exprom_wp_debugfs_release),
10741180 DEBUGFS_OPS("asic_flags", asic_flags_read, asic_flags_write),
10751181 DEBUGFS_OPS("dc8051_memory", dc8051_memory_read, NULL),
10761182 DEBUGFS_OPS("lcb", debugfs_lcb_read, debugfs_lcb_write),
....@@ -1119,6 +1225,7 @@
11191225 char link[10];
11201226 struct hfi1_devdata *dd = dd_from_dev(ibd);
11211227 struct hfi1_pportdata *ppd;
1228
+ struct dentry *root;
11221229 int unit = dd->unit;
11231230 int i, j;
11241231
....@@ -1126,30 +1233,29 @@
11261233 return;
11271234 snprintf(name, sizeof(name), "%s_%d", class_name(), unit);
11281235 snprintf(link, sizeof(link), "%d", unit);
1129
- ibd->hfi1_ibdev_dbg = debugfs_create_dir(name, hfi1_dbg_root);
1130
- if (!ibd->hfi1_ibdev_dbg) {
1131
- pr_warn("create of %s failed\n", name);
1132
- return;
1133
- }
1236
+ root = debugfs_create_dir(name, hfi1_dbg_root);
1237
+ ibd->hfi1_ibdev_dbg = root;
1238
+
11341239 ibd->hfi1_ibdev_link =
11351240 debugfs_create_symlink(link, hfi1_dbg_root, name);
1136
- if (!ibd->hfi1_ibdev_link) {
1137
- pr_warn("create of %s symlink failed\n", name);
1138
- return;
1139
- }
1140
- DEBUGFS_SEQ_FILE_CREATE(opcode_stats, ibd->hfi1_ibdev_dbg, ibd);
1141
- DEBUGFS_SEQ_FILE_CREATE(tx_opcode_stats, ibd->hfi1_ibdev_dbg, ibd);
1142
- DEBUGFS_SEQ_FILE_CREATE(ctx_stats, ibd->hfi1_ibdev_dbg, ibd);
1143
- DEBUGFS_SEQ_FILE_CREATE(qp_stats, ibd->hfi1_ibdev_dbg, ibd);
1144
- DEBUGFS_SEQ_FILE_CREATE(sdes, ibd->hfi1_ibdev_dbg, ibd);
1145
- DEBUGFS_SEQ_FILE_CREATE(rcds, ibd->hfi1_ibdev_dbg, ibd);
1146
- DEBUGFS_SEQ_FILE_CREATE(sdma_cpu_list, ibd->hfi1_ibdev_dbg, ibd);
1241
+
1242
+ debugfs_create_file("opcode_stats", 0444, root, ibd,
1243
+ &_opcode_stats_file_ops);
1244
+ debugfs_create_file("tx_opcode_stats", 0444, root, ibd,
1245
+ &_tx_opcode_stats_file_ops);
1246
+ debugfs_create_file("ctx_stats", 0444, root, ibd, &_ctx_stats_file_ops);
1247
+ debugfs_create_file("qp_stats", 0444, root, ibd, &_qp_stats_file_ops);
1248
+ debugfs_create_file("sdes", 0444, root, ibd, &_sdes_file_ops);
1249
+ debugfs_create_file("rcds", 0444, root, ibd, &_rcds_file_ops);
1250
+ debugfs_create_file("pios", 0444, root, ibd, &_pios_file_ops);
1251
+ debugfs_create_file("sdma_cpu_list", 0444, root, ibd,
1252
+ &_sdma_cpu_list_file_ops);
1253
+
11471254 /* dev counter files */
11481255 for (i = 0; i < ARRAY_SIZE(cntr_ops); i++)
1149
- DEBUGFS_FILE_CREATE(cntr_ops[i].name,
1150
- ibd->hfi1_ibdev_dbg,
1151
- dd,
1152
- &cntr_ops[i].ops, S_IRUGO);
1256
+ debugfs_create_file(cntr_ops[i].name, 0444, root, dd,
1257
+ &cntr_ops[i].ops);
1258
+
11531259 /* per port files */
11541260 for (ppd = dd->pport, j = 0; j < dd->num_pports; j++, ppd++)
11551261 for (i = 0; i < ARRAY_SIZE(port_cntr_ops); i++) {
....@@ -1157,12 +1263,11 @@
11571263 sizeof(name),
11581264 port_cntr_ops[i].name,
11591265 j + 1);
1160
- DEBUGFS_FILE_CREATE(name,
1161
- ibd->hfi1_ibdev_dbg,
1162
- ppd,
1163
- &port_cntr_ops[i].ops,
1266
+ debugfs_create_file(name,
11641267 !port_cntr_ops[i].ops.write ?
1165
- S_IRUGO : S_IRUGO | S_IWUSR);
1268
+ S_IRUGO :
1269
+ S_IRUGO | S_IWUSR,
1270
+ root, ppd, &port_cntr_ops[i].ops);
11661271 }
11671272
11681273 hfi1_fault_init_debugfs(ibd);
....@@ -1255,15 +1360,15 @@
12551360
12561361 static u64 hfi1_sps_ints(void)
12571362 {
1258
- unsigned long flags;
1363
+ unsigned long index, flags;
12591364 struct hfi1_devdata *dd;
12601365 u64 sps_ints = 0;
12611366
1262
- spin_lock_irqsave(&hfi1_devs_lock, flags);
1263
- list_for_each_entry(dd, &hfi1_dev_list, list) {
1367
+ xa_lock_irqsave(&hfi1_dev_table, flags);
1368
+ xa_for_each(&hfi1_dev_table, index, dd) {
12641369 sps_ints += get_all_cpu_total(dd->int_counter);
12651370 }
1266
- spin_unlock_irqrestore(&hfi1_devs_lock, flags);
1371
+ xa_unlock_irqrestore(&hfi1_dev_table, flags);
12671372 return sps_ints;
12681373 }
12691374
....@@ -1292,10 +1397,10 @@
12921397 void hfi1_dbg_init(void)
12931398 {
12941399 hfi1_dbg_root = debugfs_create_dir(DRIVER_NAME, NULL);
1295
- if (!hfi1_dbg_root)
1296
- pr_warn("init of debugfs failed\n");
1297
- DEBUGFS_SEQ_FILE_CREATE(driver_stats_names, hfi1_dbg_root, NULL);
1298
- DEBUGFS_SEQ_FILE_CREATE(driver_stats, hfi1_dbg_root, NULL);
1400
+ debugfs_create_file("driver_stats_names", 0444, hfi1_dbg_root, NULL,
1401
+ &_driver_stats_names_file_ops);
1402
+ debugfs_create_file("driver_stats", 0444, hfi1_dbg_root, NULL,
1403
+ &_driver_stats_file_ops);
12991404 }
13001405
13011406 void hfi1_dbg_exit(void)