hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/infiniband/hw/hfi1/sysfs.c
....@@ -494,20 +494,21 @@
494494 * Start of per-unit (or driver, in some cases, but replicated
495495 * per unit) functions (these get a device *)
496496 */
497
-static ssize_t show_rev(struct device *device, struct device_attribute *attr,
498
- char *buf)
497
+static ssize_t hw_rev_show(struct device *device, struct device_attribute *attr,
498
+ char *buf)
499499 {
500500 struct hfi1_ibdev *dev =
501
- container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
501
+ rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
502502
503503 return sprintf(buf, "%x\n", dd_from_dev(dev)->minrev);
504504 }
505
+static DEVICE_ATTR_RO(hw_rev);
505506
506
-static ssize_t show_hfi(struct device *device, struct device_attribute *attr,
507
- char *buf)
507
+static ssize_t board_id_show(struct device *device,
508
+ struct device_attribute *attr, char *buf)
508509 {
509510 struct hfi1_ibdev *dev =
510
- container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
511
+ rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
511512 struct hfi1_devdata *dd = dd_from_dev(dev);
512513 int ret;
513514
....@@ -517,23 +518,25 @@
517518 ret = scnprintf(buf, PAGE_SIZE, "%s\n", dd->boardname);
518519 return ret;
519520 }
521
+static DEVICE_ATTR_RO(board_id);
520522
521
-static ssize_t show_boardversion(struct device *device,
523
+static ssize_t boardversion_show(struct device *device,
522524 struct device_attribute *attr, char *buf)
523525 {
524526 struct hfi1_ibdev *dev =
525
- container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
527
+ rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
526528 struct hfi1_devdata *dd = dd_from_dev(dev);
527529
528530 /* The string printed here is already newline-terminated. */
529531 return scnprintf(buf, PAGE_SIZE, "%s", dd->boardversion);
530532 }
533
+static DEVICE_ATTR_RO(boardversion);
531534
532
-static ssize_t show_nctxts(struct device *device,
535
+static ssize_t nctxts_show(struct device *device,
533536 struct device_attribute *attr, char *buf)
534537 {
535538 struct hfi1_ibdev *dev =
536
- container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
539
+ rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
537540 struct hfi1_devdata *dd = dd_from_dev(dev);
538541
539542 /*
....@@ -546,34 +549,37 @@
546549 min(dd->num_user_contexts,
547550 (u32)dd->sc_sizes[SC_USER].count));
548551 }
552
+static DEVICE_ATTR_RO(nctxts);
549553
550
-static ssize_t show_nfreectxts(struct device *device,
554
+static ssize_t nfreectxts_show(struct device *device,
551555 struct device_attribute *attr, char *buf)
552556 {
553557 struct hfi1_ibdev *dev =
554
- container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
558
+ rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
555559 struct hfi1_devdata *dd = dd_from_dev(dev);
556560
557561 /* Return the number of free user ports (contexts) available. */
558562 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->freectxts);
559563 }
564
+static DEVICE_ATTR_RO(nfreectxts);
560565
561
-static ssize_t show_serial(struct device *device,
566
+static ssize_t serial_show(struct device *device,
562567 struct device_attribute *attr, char *buf)
563568 {
564569 struct hfi1_ibdev *dev =
565
- container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
570
+ rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
566571 struct hfi1_devdata *dd = dd_from_dev(dev);
567572
568573 return scnprintf(buf, PAGE_SIZE, "%s", dd->serial);
569574 }
575
+static DEVICE_ATTR_RO(serial);
570576
571
-static ssize_t store_chip_reset(struct device *device,
577
+static ssize_t chip_reset_store(struct device *device,
572578 struct device_attribute *attr, const char *buf,
573579 size_t count)
574580 {
575581 struct hfi1_ibdev *dev =
576
- container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
582
+ rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
577583 struct hfi1_devdata *dd = dd_from_dev(dev);
578584 int ret;
579585
....@@ -586,6 +592,7 @@
586592 bail:
587593 return ret < 0 ? ret : count;
588594 }
595
+static DEVICE_ATTR_WO(chip_reset);
589596
590597 /*
591598 * Convert the reported temperature from an integer (reported in
....@@ -598,11 +605,11 @@
598605 /*
599606 * Dump tempsense values, in decimal, to ease shell-scripts.
600607 */
601
-static ssize_t show_tempsense(struct device *device,
608
+static ssize_t tempsense_show(struct device *device,
602609 struct device_attribute *attr, char *buf)
603610 {
604611 struct hfi1_ibdev *dev =
605
- container_of(device, struct hfi1_ibdev, rdi.ibdev.dev);
612
+ rdma_device_to_drv_device(device, struct hfi1_ibdev, rdi.ibdev);
606613 struct hfi1_devdata *dd = dd_from_dev(dev);
607614 struct hfi1_temp temp;
608615 int ret;
....@@ -622,6 +629,7 @@
622629 }
623630 return ret;
624631 }
632
+static DEVICE_ATTR_RO(tempsense);
625633
626634 /*
627635 * end of per-unit (or driver, in some cases, but replicated
....@@ -629,24 +637,20 @@
629637 */
630638
631639 /* start of per-unit file structures and support code */
632
-static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
633
-static DEVICE_ATTR(board_id, S_IRUGO, show_hfi, NULL);
634
-static DEVICE_ATTR(nctxts, S_IRUGO, show_nctxts, NULL);
635
-static DEVICE_ATTR(nfreectxts, S_IRUGO, show_nfreectxts, NULL);
636
-static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
637
-static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
638
-static DEVICE_ATTR(tempsense, S_IRUGO, show_tempsense, NULL);
639
-static DEVICE_ATTR(chip_reset, S_IWUSR, NULL, store_chip_reset);
640
+static struct attribute *hfi1_attributes[] = {
641
+ &dev_attr_hw_rev.attr,
642
+ &dev_attr_board_id.attr,
643
+ &dev_attr_nctxts.attr,
644
+ &dev_attr_nfreectxts.attr,
645
+ &dev_attr_serial.attr,
646
+ &dev_attr_boardversion.attr,
647
+ &dev_attr_tempsense.attr,
648
+ &dev_attr_chip_reset.attr,
649
+ NULL,
650
+};
640651
641
-static struct device_attribute *hfi1_attributes[] = {
642
- &dev_attr_hw_rev,
643
- &dev_attr_board_id,
644
- &dev_attr_nctxts,
645
- &dev_attr_nfreectxts,
646
- &dev_attr_serial,
647
- &dev_attr_boardversion,
648
- &dev_attr_tempsense,
649
- &dev_attr_chip_reset,
652
+const struct attribute_group ib_hfi1_attr_group = {
653
+ .attrs = hfi1_attributes,
650654 };
651655
652656 int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
....@@ -835,12 +839,6 @@
835839 struct device *class_dev = &dev->dev;
836840 int i, j, ret;
837841
838
- for (i = 0; i < ARRAY_SIZE(hfi1_attributes); ++i) {
839
- ret = device_create_file(&dev->dev, hfi1_attributes[i]);
840
- if (ret)
841
- goto bail;
842
- }
843
-
844842 for (i = 0; i < dd->num_sdma; i++) {
845843 ret = kobject_init_and_add(&dd->per_sdma[i].kobj,
846844 &sde_ktype, &class_dev->kobj,
....@@ -858,9 +856,6 @@
858856
859857 return 0;
860858 bail:
861
- for (i = 0; i < ARRAY_SIZE(hfi1_attributes); ++i)
862
- device_remove_file(&dev->dev, hfi1_attributes[i]);
863
-
864859 /*
865860 * The function kobject_put() will call kobject_del() if the kobject
866861 * has been added successfully. The sysfs files created under the