Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Bluetooth: hci_core: Move all debugfs handling to hci_debugfs.c

This moves hci_debugfs_create_basic to hci_debugfs.c which is where all
the others debugfs entries are handled.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>

authored by

Luiz Augusto von Dentz and committed by
Marcel Holtmann
8331dc48 3e5f2d90

+128 -124
-124
net/bluetooth/hci_core.c
··· 62 62 /* HCI ID Numbering */ 63 63 static DEFINE_IDA(hci_index_ida); 64 64 65 - /* ---- HCI debugfs entries ---- */ 66 - 67 - static ssize_t dut_mode_read(struct file *file, char __user *user_buf, 68 - size_t count, loff_t *ppos) 69 - { 70 - struct hci_dev *hdev = file->private_data; 71 - char buf[3]; 72 - 73 - buf[0] = hci_dev_test_flag(hdev, HCI_DUT_MODE) ? 'Y' : 'N'; 74 - buf[1] = '\n'; 75 - buf[2] = '\0'; 76 - return simple_read_from_buffer(user_buf, count, ppos, buf, 2); 77 - } 78 - 79 - static ssize_t dut_mode_write(struct file *file, const char __user *user_buf, 80 - size_t count, loff_t *ppos) 81 - { 82 - struct hci_dev *hdev = file->private_data; 83 - struct sk_buff *skb; 84 - bool enable; 85 - int err; 86 - 87 - if (!test_bit(HCI_UP, &hdev->flags)) 88 - return -ENETDOWN; 89 - 90 - err = kstrtobool_from_user(user_buf, count, &enable); 91 - if (err) 92 - return err; 93 - 94 - if (enable == hci_dev_test_flag(hdev, HCI_DUT_MODE)) 95 - return -EALREADY; 96 - 97 - hci_req_sync_lock(hdev); 98 - if (enable) 99 - skb = __hci_cmd_sync(hdev, HCI_OP_ENABLE_DUT_MODE, 0, NULL, 100 - HCI_CMD_TIMEOUT); 101 - else 102 - skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, 103 - HCI_CMD_TIMEOUT); 104 - hci_req_sync_unlock(hdev); 105 - 106 - if (IS_ERR(skb)) 107 - return PTR_ERR(skb); 108 - 109 - kfree_skb(skb); 110 - 111 - hci_dev_change_flag(hdev, HCI_DUT_MODE); 112 - 113 - return count; 114 - } 115 - 116 - static const struct file_operations dut_mode_fops = { 117 - .open = simple_open, 118 - .read = dut_mode_read, 119 - .write = dut_mode_write, 120 - .llseek = default_llseek, 121 - }; 122 - 123 - static ssize_t vendor_diag_read(struct file *file, char __user *user_buf, 124 - size_t count, loff_t *ppos) 125 - { 126 - struct hci_dev *hdev = file->private_data; 127 - char buf[3]; 128 - 129 - buf[0] = hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) ? 'Y' : 'N'; 130 - buf[1] = '\n'; 131 - buf[2] = '\0'; 132 - return simple_read_from_buffer(user_buf, count, ppos, buf, 2); 133 - } 134 - 135 - static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf, 136 - size_t count, loff_t *ppos) 137 - { 138 - struct hci_dev *hdev = file->private_data; 139 - bool enable; 140 - int err; 141 - 142 - err = kstrtobool_from_user(user_buf, count, &enable); 143 - if (err) 144 - return err; 145 - 146 - /* When the diagnostic flags are not persistent and the transport 147 - * is not active or in user channel operation, then there is no need 148 - * for the vendor callback. Instead just store the desired value and 149 - * the setting will be programmed when the controller gets powered on. 150 - */ 151 - if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && 152 - (!test_bit(HCI_RUNNING, &hdev->flags) || 153 - hci_dev_test_flag(hdev, HCI_USER_CHANNEL))) 154 - goto done; 155 - 156 - hci_req_sync_lock(hdev); 157 - err = hdev->set_diag(hdev, enable); 158 - hci_req_sync_unlock(hdev); 159 - 160 - if (err < 0) 161 - return err; 162 - 163 - done: 164 - if (enable) 165 - hci_dev_set_flag(hdev, HCI_VENDOR_DIAG); 166 - else 167 - hci_dev_clear_flag(hdev, HCI_VENDOR_DIAG); 168 - 169 - return count; 170 - } 171 - 172 - static const struct file_operations vendor_diag_fops = { 173 - .open = simple_open, 174 - .read = vendor_diag_read, 175 - .write = vendor_diag_write, 176 - .llseek = default_llseek, 177 - }; 178 - 179 - static void hci_debugfs_create_basic(struct hci_dev *hdev) 180 - { 181 - debugfs_create_file("dut_mode", 0644, hdev->debugfs, hdev, 182 - &dut_mode_fops); 183 - 184 - if (hdev->set_diag) 185 - debugfs_create_file("vendor_diag", 0644, hdev->debugfs, hdev, 186 - &vendor_diag_fops); 187 - } 188 - 189 65 static int hci_reset_req(struct hci_request *req, unsigned long opt) 190 66 { 191 67 BT_DBG("%s %ld", req->hdev->name, opt);
+123
net/bluetooth/hci_debugfs.c
··· 27 27 #include <net/bluetooth/hci_core.h> 28 28 29 29 #include "smp.h" 30 + #include "hci_request.h" 30 31 #include "hci_debugfs.h" 31 32 32 33 #define DEFINE_QUIRK_ATTRIBUTE(__name, __quirk) \ ··· 1250 1249 1251 1250 snprintf(name, sizeof(name), "%u", conn->handle); 1252 1251 conn->debugfs = debugfs_create_dir(name, hdev->debugfs); 1252 + } 1253 + 1254 + static ssize_t dut_mode_read(struct file *file, char __user *user_buf, 1255 + size_t count, loff_t *ppos) 1256 + { 1257 + struct hci_dev *hdev = file->private_data; 1258 + char buf[3]; 1259 + 1260 + buf[0] = hci_dev_test_flag(hdev, HCI_DUT_MODE) ? 'Y' : 'N'; 1261 + buf[1] = '\n'; 1262 + buf[2] = '\0'; 1263 + return simple_read_from_buffer(user_buf, count, ppos, buf, 2); 1264 + } 1265 + 1266 + static ssize_t dut_mode_write(struct file *file, const char __user *user_buf, 1267 + size_t count, loff_t *ppos) 1268 + { 1269 + struct hci_dev *hdev = file->private_data; 1270 + struct sk_buff *skb; 1271 + bool enable; 1272 + int err; 1273 + 1274 + if (!test_bit(HCI_UP, &hdev->flags)) 1275 + return -ENETDOWN; 1276 + 1277 + err = kstrtobool_from_user(user_buf, count, &enable); 1278 + if (err) 1279 + return err; 1280 + 1281 + if (enable == hci_dev_test_flag(hdev, HCI_DUT_MODE)) 1282 + return -EALREADY; 1283 + 1284 + hci_req_sync_lock(hdev); 1285 + if (enable) 1286 + skb = __hci_cmd_sync(hdev, HCI_OP_ENABLE_DUT_MODE, 0, NULL, 1287 + HCI_CMD_TIMEOUT); 1288 + else 1289 + skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, 1290 + HCI_CMD_TIMEOUT); 1291 + hci_req_sync_unlock(hdev); 1292 + 1293 + if (IS_ERR(skb)) 1294 + return PTR_ERR(skb); 1295 + 1296 + kfree_skb(skb); 1297 + 1298 + hci_dev_change_flag(hdev, HCI_DUT_MODE); 1299 + 1300 + return count; 1301 + } 1302 + 1303 + static const struct file_operations dut_mode_fops = { 1304 + .open = simple_open, 1305 + .read = dut_mode_read, 1306 + .write = dut_mode_write, 1307 + .llseek = default_llseek, 1308 + }; 1309 + 1310 + static ssize_t vendor_diag_read(struct file *file, char __user *user_buf, 1311 + size_t count, loff_t *ppos) 1312 + { 1313 + struct hci_dev *hdev = file->private_data; 1314 + char buf[3]; 1315 + 1316 + buf[0] = hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) ? 'Y' : 'N'; 1317 + buf[1] = '\n'; 1318 + buf[2] = '\0'; 1319 + return simple_read_from_buffer(user_buf, count, ppos, buf, 2); 1320 + } 1321 + 1322 + static ssize_t vendor_diag_write(struct file *file, const char __user *user_buf, 1323 + size_t count, loff_t *ppos) 1324 + { 1325 + struct hci_dev *hdev = file->private_data; 1326 + bool enable; 1327 + int err; 1328 + 1329 + err = kstrtobool_from_user(user_buf, count, &enable); 1330 + if (err) 1331 + return err; 1332 + 1333 + /* When the diagnostic flags are not persistent and the transport 1334 + * is not active or in user channel operation, then there is no need 1335 + * for the vendor callback. Instead just store the desired value and 1336 + * the setting will be programmed when the controller gets powered on. 1337 + */ 1338 + if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && 1339 + (!test_bit(HCI_RUNNING, &hdev->flags) || 1340 + hci_dev_test_flag(hdev, HCI_USER_CHANNEL))) 1341 + goto done; 1342 + 1343 + hci_req_sync_lock(hdev); 1344 + err = hdev->set_diag(hdev, enable); 1345 + hci_req_sync_unlock(hdev); 1346 + 1347 + if (err < 0) 1348 + return err; 1349 + 1350 + done: 1351 + if (enable) 1352 + hci_dev_set_flag(hdev, HCI_VENDOR_DIAG); 1353 + else 1354 + hci_dev_clear_flag(hdev, HCI_VENDOR_DIAG); 1355 + 1356 + return count; 1357 + } 1358 + 1359 + static const struct file_operations vendor_diag_fops = { 1360 + .open = simple_open, 1361 + .read = vendor_diag_read, 1362 + .write = vendor_diag_write, 1363 + .llseek = default_llseek, 1364 + }; 1365 + 1366 + void hci_debugfs_create_basic(struct hci_dev *hdev) 1367 + { 1368 + debugfs_create_file("dut_mode", 0644, hdev->debugfs, hdev, 1369 + &dut_mode_fops); 1370 + 1371 + if (hdev->set_diag) 1372 + debugfs_create_file("vendor_diag", 0644, hdev->debugfs, hdev, 1373 + &vendor_diag_fops); 1253 1374 }
+5
net/bluetooth/hci_debugfs.h
··· 26 26 void hci_debugfs_create_bredr(struct hci_dev *hdev); 27 27 void hci_debugfs_create_le(struct hci_dev *hdev); 28 28 void hci_debugfs_create_conn(struct hci_conn *conn); 29 + void hci_debugfs_create_basic(struct hci_dev *hdev); 29 30 30 31 #else 31 32 ··· 43 42 } 44 43 45 44 static inline void hci_debugfs_create_conn(struct hci_conn *conn) 45 + { 46 + } 47 + 48 + static inline void hci_debugfs_create_basic(struct hci_dev *hdev) 46 49 { 47 50 } 48 51