diff options
-rw-r--r-- | drivers/ntb/ntb_hw.c | 27 | ||||
-rw-r--r-- | drivers/ntb/ntb_hw.h | 16 | ||||
-rw-r--r-- | drivers/ntb/ntb_transport.c | 17 |
3 files changed, 48 insertions, 12 deletions
diff --git a/drivers/ntb/ntb_hw.c b/drivers/ntb/ntb_hw.c index 26b808b4d3a0..b9bf8b551e3c 100644 --- a/drivers/ntb/ntb_hw.c +++ b/drivers/ntb/ntb_hw.c | |||
@@ -78,6 +78,8 @@ enum { | |||
78 | BWD_HW, | 78 | BWD_HW, |
79 | }; | 79 | }; |
80 | 80 | ||
81 | static struct dentry *debugfs_dir; | ||
82 | |||
81 | /* Translate memory window 0,1 to BAR 2,4 */ | 83 | /* Translate memory window 0,1 to BAR 2,4 */ |
82 | #define MW_TO_BAR(mw) (mw * 2 + 2) | 84 | #define MW_TO_BAR(mw) (mw * 2 + 2) |
83 | 85 | ||
@@ -998,6 +1000,28 @@ static void ntb_free_callbacks(struct ntb_device *ndev) | |||
998 | kfree(ndev->db_cb); | 1000 | kfree(ndev->db_cb); |
999 | } | 1001 | } |
1000 | 1002 | ||
1003 | static void ntb_setup_debugfs(struct ntb_device *ndev) | ||
1004 | { | ||
1005 | if (!debugfs_initialized()) | ||
1006 | return; | ||
1007 | |||
1008 | if (!debugfs_dir) | ||
1009 | debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL); | ||
1010 | |||
1011 | ndev->debugfs_dir = debugfs_create_dir(pci_name(ndev->pdev), | ||
1012 | debugfs_dir); | ||
1013 | } | ||
1014 | |||
1015 | static void ntb_free_debugfs(struct ntb_device *ndev) | ||
1016 | { | ||
1017 | debugfs_remove_recursive(ndev->debugfs_dir); | ||
1018 | |||
1019 | if (debugfs_dir && simple_empty(debugfs_dir)) { | ||
1020 | debugfs_remove_recursive(debugfs_dir); | ||
1021 | debugfs_dir = NULL; | ||
1022 | } | ||
1023 | } | ||
1024 | |||
1001 | static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) | 1025 | static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
1002 | { | 1026 | { |
1003 | struct ntb_device *ndev; | 1027 | struct ntb_device *ndev; |
@@ -1010,6 +1034,7 @@ static int ntb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) | |||
1010 | ndev->pdev = pdev; | 1034 | ndev->pdev = pdev; |
1011 | ndev->link_status = NTB_LINK_DOWN; | 1035 | ndev->link_status = NTB_LINK_DOWN; |
1012 | pci_set_drvdata(pdev, ndev); | 1036 | pci_set_drvdata(pdev, ndev); |
1037 | ntb_setup_debugfs(ndev); | ||
1013 | 1038 | ||
1014 | rc = pci_enable_device(pdev); | 1039 | rc = pci_enable_device(pdev); |
1015 | if (rc) | 1040 | if (rc) |
@@ -1106,6 +1131,7 @@ err2: | |||
1106 | err1: | 1131 | err1: |
1107 | pci_disable_device(pdev); | 1132 | pci_disable_device(pdev); |
1108 | err: | 1133 | err: |
1134 | ntb_free_debugfs(ndev); | ||
1109 | kfree(ndev); | 1135 | kfree(ndev); |
1110 | 1136 | ||
1111 | dev_err(&pdev->dev, "Error loading %s module\n", KBUILD_MODNAME); | 1137 | dev_err(&pdev->dev, "Error loading %s module\n", KBUILD_MODNAME); |
@@ -1135,6 +1161,7 @@ static void ntb_pci_remove(struct pci_dev *pdev) | |||
1135 | iounmap(ndev->reg_base); | 1161 | iounmap(ndev->reg_base); |
1136 | pci_release_selected_regions(pdev, NTB_BAR_MASK); | 1162 | pci_release_selected_regions(pdev, NTB_BAR_MASK); |
1137 | pci_disable_device(pdev); | 1163 | pci_disable_device(pdev); |
1164 | ntb_free_debugfs(ndev); | ||
1138 | kfree(ndev); | 1165 | kfree(ndev); |
1139 | } | 1166 | } |
1140 | 1167 | ||
diff --git a/drivers/ntb/ntb_hw.h b/drivers/ntb/ntb_hw.h index 3a3038ca83e6..6a4f56f564ee 100644 --- a/drivers/ntb/ntb_hw.h +++ b/drivers/ntb/ntb_hw.h | |||
@@ -127,6 +127,8 @@ struct ntb_device { | |||
127 | unsigned char link_status; | 127 | unsigned char link_status; |
128 | struct delayed_work hb_timer; | 128 | struct delayed_work hb_timer; |
129 | unsigned long last_ts; | 129 | unsigned long last_ts; |
130 | |||
131 | struct dentry *debugfs_dir; | ||
130 | }; | 132 | }; |
131 | 133 | ||
132 | /** | 134 | /** |
@@ -155,6 +157,20 @@ static inline struct pci_dev *ntb_query_pdev(struct ntb_device *ndev) | |||
155 | return ndev->pdev; | 157 | return ndev->pdev; |
156 | } | 158 | } |
157 | 159 | ||
160 | /** | ||
161 | * ntb_query_debugfs() - return the debugfs pointer | ||
162 | * @ndev: pointer to ntb_device instance | ||
163 | * | ||
164 | * Given the ntb pointer, return the debugfs directory pointer for the NTB | ||
165 | * hardware device | ||
166 | * | ||
167 | * RETURNS: a pointer to the debugfs directory | ||
168 | */ | ||
169 | static inline struct dentry *ntb_query_debugfs(struct ntb_device *ndev) | ||
170 | { | ||
171 | return ndev->debugfs_dir; | ||
172 | } | ||
173 | |||
158 | struct ntb_device *ntb_register_transport(struct pci_dev *pdev, | 174 | struct ntb_device *ntb_register_transport(struct pci_dev *pdev, |
159 | void *transport); | 175 | void *transport); |
160 | void ntb_unregister_transport(struct ntb_device *ndev); | 176 | void ntb_unregister_transport(struct ntb_device *ndev); |
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c index f8d7081ee301..c3089151aa49 100644 --- a/drivers/ntb/ntb_transport.c +++ b/drivers/ntb/ntb_transport.c | |||
@@ -157,7 +157,6 @@ struct ntb_transport { | |||
157 | bool transport_link; | 157 | bool transport_link; |
158 | struct delayed_work link_work; | 158 | struct delayed_work link_work; |
159 | struct work_struct link_cleanup; | 159 | struct work_struct link_cleanup; |
160 | struct dentry *debugfs_dir; | ||
161 | }; | 160 | }; |
162 | 161 | ||
163 | enum { | 162 | enum { |
@@ -824,12 +823,12 @@ static void ntb_transport_init_queue(struct ntb_transport *nt, | |||
824 | qp->tx_max_frame = min(transport_mtu, tx_size / 2); | 823 | qp->tx_max_frame = min(transport_mtu, tx_size / 2); |
825 | qp->tx_max_entry = tx_size / qp->tx_max_frame; | 824 | qp->tx_max_entry = tx_size / qp->tx_max_frame; |
826 | 825 | ||
827 | if (nt->debugfs_dir) { | 826 | if (ntb_query_debugfs(nt->ndev)) { |
828 | char debugfs_name[4]; | 827 | char debugfs_name[4]; |
829 | 828 | ||
830 | snprintf(debugfs_name, 4, "qp%d", qp_num); | 829 | snprintf(debugfs_name, 4, "qp%d", qp_num); |
831 | qp->debugfs_dir = debugfs_create_dir(debugfs_name, | 830 | qp->debugfs_dir = debugfs_create_dir(debugfs_name, |
832 | nt->debugfs_dir); | 831 | ntb_query_debugfs(nt->ndev)); |
833 | 832 | ||
834 | qp->debugfs_stats = debugfs_create_file("stats", S_IRUSR, | 833 | qp->debugfs_stats = debugfs_create_file("stats", S_IRUSR, |
835 | qp->debugfs_dir, qp, | 834 | qp->debugfs_dir, qp, |
@@ -857,11 +856,6 @@ int ntb_transport_init(struct pci_dev *pdev) | |||
857 | if (!nt) | 856 | if (!nt) |
858 | return -ENOMEM; | 857 | return -ENOMEM; |
859 | 858 | ||
860 | if (debugfs_initialized()) | ||
861 | nt->debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL); | ||
862 | else | ||
863 | nt->debugfs_dir = NULL; | ||
864 | |||
865 | nt->ndev = ntb_register_transport(pdev, nt); | 859 | nt->ndev = ntb_register_transport(pdev, nt); |
866 | if (!nt->ndev) { | 860 | if (!nt->ndev) { |
867 | rc = -EIO; | 861 | rc = -EIO; |
@@ -907,7 +901,6 @@ err2: | |||
907 | err1: | 901 | err1: |
908 | ntb_unregister_transport(nt->ndev); | 902 | ntb_unregister_transport(nt->ndev); |
909 | err: | 903 | err: |
910 | debugfs_remove_recursive(nt->debugfs_dir); | ||
911 | kfree(nt); | 904 | kfree(nt); |
912 | return rc; | 905 | return rc; |
913 | } | 906 | } |
@@ -921,16 +914,16 @@ void ntb_transport_free(void *transport) | |||
921 | nt->transport_link = NTB_LINK_DOWN; | 914 | nt->transport_link = NTB_LINK_DOWN; |
922 | 915 | ||
923 | /* verify that all the qp's are freed */ | 916 | /* verify that all the qp's are freed */ |
924 | for (i = 0; i < nt->max_qps; i++) | 917 | for (i = 0; i < nt->max_qps; i++) { |
925 | if (!test_bit(i, &nt->qp_bitmap)) | 918 | if (!test_bit(i, &nt->qp_bitmap)) |
926 | ntb_transport_free_queue(&nt->qps[i]); | 919 | ntb_transport_free_queue(&nt->qps[i]); |
920 | debugfs_remove_recursive(nt->qps[i].debugfs_dir); | ||
921 | } | ||
927 | 922 | ||
928 | ntb_bus_remove(nt); | 923 | ntb_bus_remove(nt); |
929 | 924 | ||
930 | cancel_delayed_work_sync(&nt->link_work); | 925 | cancel_delayed_work_sync(&nt->link_work); |
931 | 926 | ||
932 | debugfs_remove_recursive(nt->debugfs_dir); | ||
933 | |||
934 | ntb_unregister_event_callback(nt->ndev); | 927 | ntb_unregister_event_callback(nt->ndev); |
935 | 928 | ||
936 | pdev = ntb_query_pdev(nt->ndev); | 929 | pdev = ntb_query_pdev(nt->ndev); |