smsdvb-debugfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /***********************************************************************
  2. *
  3. * Copyright(c) 2013 Mauro Carvalho Chehab
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. ***********************************************************************/
  18. #include "smscoreapi.h"
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include <linux/init.h>
  22. #include <linux/debugfs.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/usb.h>
  25. #include "dmxdev.h"
  26. #include "dvbdev.h"
  27. #include "dvb_demux.h"
  28. #include "dvb_frontend.h"
  29. #include "smsdvb.h"
  30. static struct dentry *smsdvb_debugfs_usb_root;
  31. struct smsdvb_debugfs {
  32. struct kref refcount;
  33. spinlock_t lock;
  34. char stats_data[PAGE_SIZE];
  35. unsigned stats_count;
  36. bool stats_was_read;
  37. wait_queue_head_t stats_queue;
  38. };
  39. static void smsdvb_print_dvb_stats(struct smsdvb_debugfs *debug_data,
  40. struct sms_stats *p)
  41. {
  42. int n = 0;
  43. char *buf;
  44. spin_lock(&debug_data->lock);
  45. if (debug_data->stats_count) {
  46. spin_unlock(&debug_data->lock);
  47. return;
  48. }
  49. buf = debug_data->stats_data;
  50. n += snprintf(&buf[n], PAGE_SIZE - n,
  51. "is_rf_locked = %d\n", p->is_rf_locked);
  52. n += snprintf(&buf[n], PAGE_SIZE - n,
  53. "is_demod_locked = %d\n", p->is_demod_locked);
  54. n += snprintf(&buf[n], PAGE_SIZE - n,
  55. "is_external_lna_on = %d\n", p->is_external_lna_on);
  56. n += snprintf(&buf[n], PAGE_SIZE - n,
  57. "SNR = %d\n", p->SNR);
  58. n += snprintf(&buf[n], PAGE_SIZE - n,
  59. "ber = %d\n", p->ber);
  60. n += snprintf(&buf[n], PAGE_SIZE - n,
  61. "FIB_CRC = %d\n", p->FIB_CRC);
  62. n += snprintf(&buf[n], PAGE_SIZE - n,
  63. "ts_per = %d\n", p->ts_per);
  64. n += snprintf(&buf[n], PAGE_SIZE - n,
  65. "MFER = %d\n", p->MFER);
  66. n += snprintf(&buf[n], PAGE_SIZE - n,
  67. "RSSI = %d\n", p->RSSI);
  68. n += snprintf(&buf[n], PAGE_SIZE - n,
  69. "in_band_pwr = %d\n", p->in_band_pwr);
  70. n += snprintf(&buf[n], PAGE_SIZE - n,
  71. "carrier_offset = %d\n", p->carrier_offset);
  72. n += snprintf(&buf[n], PAGE_SIZE - n,
  73. "modem_state = %d\n", p->modem_state);
  74. n += snprintf(&buf[n], PAGE_SIZE - n,
  75. "frequency = %d\n", p->frequency);
  76. n += snprintf(&buf[n], PAGE_SIZE - n,
  77. "bandwidth = %d\n", p->bandwidth);
  78. n += snprintf(&buf[n], PAGE_SIZE - n,
  79. "transmission_mode = %d\n", p->transmission_mode);
  80. n += snprintf(&buf[n], PAGE_SIZE - n,
  81. "modem_state = %d\n", p->modem_state);
  82. n += snprintf(&buf[n], PAGE_SIZE - n,
  83. "guard_interval = %d\n", p->guard_interval);
  84. n += snprintf(&buf[n], PAGE_SIZE - n,
  85. "code_rate = %d\n", p->code_rate);
  86. n += snprintf(&buf[n], PAGE_SIZE - n,
  87. "lp_code_rate = %d\n", p->lp_code_rate);
  88. n += snprintf(&buf[n], PAGE_SIZE - n,
  89. "hierarchy = %d\n", p->hierarchy);
  90. n += snprintf(&buf[n], PAGE_SIZE - n,
  91. "constellation = %d\n", p->constellation);
  92. n += snprintf(&buf[n], PAGE_SIZE - n,
  93. "burst_size = %d\n", p->burst_size);
  94. n += snprintf(&buf[n], PAGE_SIZE - n,
  95. "burst_duration = %d\n", p->burst_duration);
  96. n += snprintf(&buf[n], PAGE_SIZE - n,
  97. "burst_cycle_time = %d\n", p->burst_cycle_time);
  98. n += snprintf(&buf[n], PAGE_SIZE - n,
  99. "calc_burst_cycle_time = %d\n",
  100. p->calc_burst_cycle_time);
  101. n += snprintf(&buf[n], PAGE_SIZE - n,
  102. "num_of_rows = %d\n", p->num_of_rows);
  103. n += snprintf(&buf[n], PAGE_SIZE - n,
  104. "num_of_padd_cols = %d\n", p->num_of_padd_cols);
  105. n += snprintf(&buf[n], PAGE_SIZE - n,
  106. "num_of_punct_cols = %d\n", p->num_of_punct_cols);
  107. n += snprintf(&buf[n], PAGE_SIZE - n,
  108. "error_ts_packets = %d\n", p->error_ts_packets);
  109. n += snprintf(&buf[n], PAGE_SIZE - n,
  110. "total_ts_packets = %d\n", p->total_ts_packets);
  111. n += snprintf(&buf[n], PAGE_SIZE - n,
  112. "num_of_valid_mpe_tlbs = %d\n", p->num_of_valid_mpe_tlbs);
  113. n += snprintf(&buf[n], PAGE_SIZE - n,
  114. "num_of_invalid_mpe_tlbs = %d\n", p->num_of_invalid_mpe_tlbs);
  115. n += snprintf(&buf[n], PAGE_SIZE - n,
  116. "num_of_corrected_mpe_tlbs = %d\n", p->num_of_corrected_mpe_tlbs);
  117. n += snprintf(&buf[n], PAGE_SIZE - n,
  118. "ber_error_count = %d\n", p->ber_error_count);
  119. n += snprintf(&buf[n], PAGE_SIZE - n,
  120. "ber_bit_count = %d\n", p->ber_bit_count);
  121. n += snprintf(&buf[n], PAGE_SIZE - n,
  122. "sms_to_host_tx_errors = %d\n", p->sms_to_host_tx_errors);
  123. n += snprintf(&buf[n], PAGE_SIZE - n,
  124. "pre_ber = %d\n", p->pre_ber);
  125. n += snprintf(&buf[n], PAGE_SIZE - n,
  126. "cell_id = %d\n", p->cell_id);
  127. n += snprintf(&buf[n], PAGE_SIZE - n,
  128. "dvbh_srv_ind_hp = %d\n", p->dvbh_srv_ind_hp);
  129. n += snprintf(&buf[n], PAGE_SIZE - n,
  130. "dvbh_srv_ind_lp = %d\n", p->dvbh_srv_ind_lp);
  131. n += snprintf(&buf[n], PAGE_SIZE - n,
  132. "num_mpe_received = %d\n", p->num_mpe_received);
  133. debug_data->stats_count = n;
  134. spin_unlock(&debug_data->lock);
  135. wake_up(&debug_data->stats_queue);
  136. }
  137. static void smsdvb_print_isdb_stats(struct smsdvb_debugfs *debug_data,
  138. struct sms_isdbt_stats *p)
  139. {
  140. int i, n = 0;
  141. char *buf;
  142. spin_lock(&debug_data->lock);
  143. if (debug_data->stats_count) {
  144. spin_unlock(&debug_data->lock);
  145. return;
  146. }
  147. buf = debug_data->stats_data;
  148. n += snprintf(&buf[n], PAGE_SIZE - n,
  149. "statistics_type = %d\t", p->statistics_type);
  150. n += snprintf(&buf[n], PAGE_SIZE - n,
  151. "full_size = %d\n", p->full_size);
  152. n += snprintf(&buf[n], PAGE_SIZE - n,
  153. "is_rf_locked = %d\t\t", p->is_rf_locked);
  154. n += snprintf(&buf[n], PAGE_SIZE - n,
  155. "is_demod_locked = %d\t", p->is_demod_locked);
  156. n += snprintf(&buf[n], PAGE_SIZE - n,
  157. "is_external_lna_on = %d\n", p->is_external_lna_on);
  158. n += snprintf(&buf[n], PAGE_SIZE - n,
  159. "SNR = %d dB\t\t", p->SNR);
  160. n += snprintf(&buf[n], PAGE_SIZE - n,
  161. "RSSI = %d dBm\t\t", p->RSSI);
  162. n += snprintf(&buf[n], PAGE_SIZE - n,
  163. "in_band_pwr = %d dBm\n", p->in_band_pwr);
  164. n += snprintf(&buf[n], PAGE_SIZE - n,
  165. "carrier_offset = %d\t", p->carrier_offset);
  166. n += snprintf(&buf[n], PAGE_SIZE - n,
  167. "bandwidth = %d\t\t", p->bandwidth);
  168. n += snprintf(&buf[n], PAGE_SIZE - n,
  169. "frequency = %d Hz\n", p->frequency);
  170. n += snprintf(&buf[n], PAGE_SIZE - n,
  171. "transmission_mode = %d\t", p->transmission_mode);
  172. n += snprintf(&buf[n], PAGE_SIZE - n,
  173. "modem_state = %d\t\t", p->modem_state);
  174. n += snprintf(&buf[n], PAGE_SIZE - n,
  175. "guard_interval = %d\n", p->guard_interval);
  176. n += snprintf(&buf[n], PAGE_SIZE - n,
  177. "system_type = %d\t\t", p->system_type);
  178. n += snprintf(&buf[n], PAGE_SIZE - n,
  179. "partial_reception = %d\t", p->partial_reception);
  180. n += snprintf(&buf[n], PAGE_SIZE - n,
  181. "num_of_layers = %d\n", p->num_of_layers);
  182. n += snprintf(&buf[n], PAGE_SIZE - n,
  183. "sms_to_host_tx_errors = %d\n", p->sms_to_host_tx_errors);
  184. for (i = 0; i < 3; i++) {
  185. if (p->layer_info[i].number_of_segments < 1 ||
  186. p->layer_info[i].number_of_segments > 13)
  187. continue;
  188. n += snprintf(&buf[n], PAGE_SIZE - n, "\nLayer %d\n", i);
  189. n += snprintf(&buf[n], PAGE_SIZE - n, "\tcode_rate = %d\t",
  190. p->layer_info[i].code_rate);
  191. n += snprintf(&buf[n], PAGE_SIZE - n, "constellation = %d\n",
  192. p->layer_info[i].constellation);
  193. n += snprintf(&buf[n], PAGE_SIZE - n, "\tber = %-5d\t",
  194. p->layer_info[i].ber);
  195. n += snprintf(&buf[n], PAGE_SIZE - n, "\tber_error_count = %-5d\t",
  196. p->layer_info[i].ber_error_count);
  197. n += snprintf(&buf[n], PAGE_SIZE - n, "ber_bit_count = %-5d\n",
  198. p->layer_info[i].ber_bit_count);
  199. n += snprintf(&buf[n], PAGE_SIZE - n, "\tpre_ber = %-5d\t",
  200. p->layer_info[i].pre_ber);
  201. n += snprintf(&buf[n], PAGE_SIZE - n, "\tts_per = %-5d\n",
  202. p->layer_info[i].ts_per);
  203. n += snprintf(&buf[n], PAGE_SIZE - n, "\terror_ts_packets = %-5d\t",
  204. p->layer_info[i].error_ts_packets);
  205. n += snprintf(&buf[n], PAGE_SIZE - n, "total_ts_packets = %-5d\t",
  206. p->layer_info[i].total_ts_packets);
  207. n += snprintf(&buf[n], PAGE_SIZE - n, "ti_ldepth_i = %d\n",
  208. p->layer_info[i].ti_ldepth_i);
  209. n += snprintf(&buf[n], PAGE_SIZE - n,
  210. "\tnumber_of_segments = %d\t",
  211. p->layer_info[i].number_of_segments);
  212. n += snprintf(&buf[n], PAGE_SIZE - n, "tmcc_errors = %d\n",
  213. p->layer_info[i].tmcc_errors);
  214. }
  215. debug_data->stats_count = n;
  216. spin_unlock(&debug_data->lock);
  217. wake_up(&debug_data->stats_queue);
  218. }
  219. static void smsdvb_print_isdb_stats_ex(struct smsdvb_debugfs *debug_data,
  220. struct sms_isdbt_stats_ex *p)
  221. {
  222. int i, n = 0;
  223. char *buf;
  224. spin_lock(&debug_data->lock);
  225. if (debug_data->stats_count) {
  226. spin_unlock(&debug_data->lock);
  227. return;
  228. }
  229. buf = debug_data->stats_data;
  230. n += snprintf(&buf[n], PAGE_SIZE - n,
  231. "statistics_type = %d\t", p->statistics_type);
  232. n += snprintf(&buf[n], PAGE_SIZE - n,
  233. "full_size = %d\n", p->full_size);
  234. n += snprintf(&buf[n], PAGE_SIZE - n,
  235. "is_rf_locked = %d\t\t", p->is_rf_locked);
  236. n += snprintf(&buf[n], PAGE_SIZE - n,
  237. "is_demod_locked = %d\t", p->is_demod_locked);
  238. n += snprintf(&buf[n], PAGE_SIZE - n,
  239. "is_external_lna_on = %d\n", p->is_external_lna_on);
  240. n += snprintf(&buf[n], PAGE_SIZE - n,
  241. "SNR = %d dB\t\t", p->SNR);
  242. n += snprintf(&buf[n], PAGE_SIZE - n,
  243. "RSSI = %d dBm\t\t", p->RSSI);
  244. n += snprintf(&buf[n], PAGE_SIZE - n,
  245. "in_band_pwr = %d dBm\n", p->in_band_pwr);
  246. n += snprintf(&buf[n], PAGE_SIZE - n,
  247. "carrier_offset = %d\t", p->carrier_offset);
  248. n += snprintf(&buf[n], PAGE_SIZE - n,
  249. "bandwidth = %d\t\t", p->bandwidth);
  250. n += snprintf(&buf[n], PAGE_SIZE - n,
  251. "frequency = %d Hz\n", p->frequency);
  252. n += snprintf(&buf[n], PAGE_SIZE - n,
  253. "transmission_mode = %d\t", p->transmission_mode);
  254. n += snprintf(&buf[n], PAGE_SIZE - n,
  255. "modem_state = %d\t\t", p->modem_state);
  256. n += snprintf(&buf[n], PAGE_SIZE - n,
  257. "guard_interval = %d\n", p->guard_interval);
  258. n += snprintf(&buf[n], PAGE_SIZE - n,
  259. "system_type = %d\t\t", p->system_type);
  260. n += snprintf(&buf[n], PAGE_SIZE - n,
  261. "partial_reception = %d\t", p->partial_reception);
  262. n += snprintf(&buf[n], PAGE_SIZE - n,
  263. "num_of_layers = %d\n", p->num_of_layers);
  264. n += snprintf(&buf[n], PAGE_SIZE - n, "segment_number = %d\t",
  265. p->segment_number);
  266. n += snprintf(&buf[n], PAGE_SIZE - n, "tune_bw = %d\n",
  267. p->tune_bw);
  268. for (i = 0; i < 3; i++) {
  269. if (p->layer_info[i].number_of_segments < 1 ||
  270. p->layer_info[i].number_of_segments > 13)
  271. continue;
  272. n += snprintf(&buf[n], PAGE_SIZE - n, "\nLayer %d\n", i);
  273. n += snprintf(&buf[n], PAGE_SIZE - n, "\tcode_rate = %d\t",
  274. p->layer_info[i].code_rate);
  275. n += snprintf(&buf[n], PAGE_SIZE - n, "constellation = %d\n",
  276. p->layer_info[i].constellation);
  277. n += snprintf(&buf[n], PAGE_SIZE - n, "\tber = %-5d\t",
  278. p->layer_info[i].ber);
  279. n += snprintf(&buf[n], PAGE_SIZE - n, "\tber_error_count = %-5d\t",
  280. p->layer_info[i].ber_error_count);
  281. n += snprintf(&buf[n], PAGE_SIZE - n, "ber_bit_count = %-5d\n",
  282. p->layer_info[i].ber_bit_count);
  283. n += snprintf(&buf[n], PAGE_SIZE - n, "\tpre_ber = %-5d\t",
  284. p->layer_info[i].pre_ber);
  285. n += snprintf(&buf[n], PAGE_SIZE - n, "\tts_per = %-5d\n",
  286. p->layer_info[i].ts_per);
  287. n += snprintf(&buf[n], PAGE_SIZE - n, "\terror_ts_packets = %-5d\t",
  288. p->layer_info[i].error_ts_packets);
  289. n += snprintf(&buf[n], PAGE_SIZE - n, "total_ts_packets = %-5d\t",
  290. p->layer_info[i].total_ts_packets);
  291. n += snprintf(&buf[n], PAGE_SIZE - n, "ti_ldepth_i = %d\n",
  292. p->layer_info[i].ti_ldepth_i);
  293. n += snprintf(&buf[n], PAGE_SIZE - n,
  294. "\tnumber_of_segments = %d\t",
  295. p->layer_info[i].number_of_segments);
  296. n += snprintf(&buf[n], PAGE_SIZE - n, "tmcc_errors = %d\n",
  297. p->layer_info[i].tmcc_errors);
  298. }
  299. debug_data->stats_count = n;
  300. spin_unlock(&debug_data->lock);
  301. wake_up(&debug_data->stats_queue);
  302. }
  303. static int smsdvb_stats_open(struct inode *inode, struct file *file)
  304. {
  305. struct smsdvb_client_t *client = inode->i_private;
  306. struct smsdvb_debugfs *debug_data = client->debug_data;
  307. kref_get(&debug_data->refcount);
  308. spin_lock(&debug_data->lock);
  309. debug_data->stats_count = 0;
  310. debug_data->stats_was_read = false;
  311. spin_unlock(&debug_data->lock);
  312. file->private_data = debug_data;
  313. return 0;
  314. }
  315. static void smsdvb_debugfs_data_release(struct kref *ref)
  316. {
  317. struct smsdvb_debugfs *debug_data;
  318. debug_data = container_of(ref, struct smsdvb_debugfs, refcount);
  319. kfree(debug_data);
  320. }
  321. static int smsdvb_stats_wait_read(struct smsdvb_debugfs *debug_data)
  322. {
  323. int rc = 1;
  324. spin_lock(&debug_data->lock);
  325. if (debug_data->stats_was_read)
  326. goto exit;
  327. rc = debug_data->stats_count;
  328. exit:
  329. spin_unlock(&debug_data->lock);
  330. return rc;
  331. }
  332. static unsigned int smsdvb_stats_poll(struct file *file, poll_table *wait)
  333. {
  334. struct smsdvb_debugfs *debug_data = file->private_data;
  335. int rc;
  336. kref_get(&debug_data->refcount);
  337. poll_wait(file, &debug_data->stats_queue, wait);
  338. rc = smsdvb_stats_wait_read(debug_data);
  339. if (rc > 0)
  340. rc = POLLIN | POLLRDNORM;
  341. kref_put(&debug_data->refcount, smsdvb_debugfs_data_release);
  342. return rc;
  343. }
  344. static ssize_t smsdvb_stats_read(struct file *file, char __user *user_buf,
  345. size_t nbytes, loff_t *ppos)
  346. {
  347. int rc = 0, len;
  348. struct smsdvb_debugfs *debug_data = file->private_data;
  349. kref_get(&debug_data->refcount);
  350. if (file->f_flags & O_NONBLOCK) {
  351. rc = smsdvb_stats_wait_read(debug_data);
  352. if (!rc) {
  353. rc = -EWOULDBLOCK;
  354. goto ret;
  355. }
  356. } else {
  357. rc = wait_event_interruptible(debug_data->stats_queue,
  358. smsdvb_stats_wait_read(debug_data));
  359. if (rc < 0)
  360. goto ret;
  361. }
  362. if (debug_data->stats_was_read) {
  363. rc = 0; /* EOF */
  364. goto ret;
  365. }
  366. len = debug_data->stats_count - *ppos;
  367. if (len >= 0)
  368. rc = simple_read_from_buffer(user_buf, nbytes, ppos,
  369. debug_data->stats_data, len);
  370. else
  371. rc = 0;
  372. if (*ppos >= debug_data->stats_count) {
  373. spin_lock(&debug_data->lock);
  374. debug_data->stats_was_read = true;
  375. spin_unlock(&debug_data->lock);
  376. }
  377. ret:
  378. kref_put(&debug_data->refcount, smsdvb_debugfs_data_release);
  379. return rc;
  380. }
  381. static int smsdvb_stats_release(struct inode *inode, struct file *file)
  382. {
  383. struct smsdvb_debugfs *debug_data = file->private_data;
  384. spin_lock(&debug_data->lock);
  385. debug_data->stats_was_read = true; /* return EOF to read() */
  386. spin_unlock(&debug_data->lock);
  387. wake_up_interruptible_sync(&debug_data->stats_queue);
  388. kref_put(&debug_data->refcount, smsdvb_debugfs_data_release);
  389. file->private_data = NULL;
  390. return 0;
  391. }
  392. static const struct file_operations debugfs_stats_ops = {
  393. .open = smsdvb_stats_open,
  394. .poll = smsdvb_stats_poll,
  395. .read = smsdvb_stats_read,
  396. .release = smsdvb_stats_release,
  397. .llseek = generic_file_llseek,
  398. };
  399. /*
  400. * Functions used by smsdvb, in order to create the interfaces
  401. */
  402. int smsdvb_debugfs_create(struct smsdvb_client_t *client)
  403. {
  404. struct smscore_device_t *coredev = client->coredev;
  405. struct dentry *d;
  406. struct smsdvb_debugfs *debug_data;
  407. if (!smsdvb_debugfs_usb_root || !coredev->is_usb_device)
  408. return -ENODEV;
  409. client->debugfs = debugfs_create_dir(coredev->devpath,
  410. smsdvb_debugfs_usb_root);
  411. if (IS_ERR_OR_NULL(client->debugfs)) {
  412. pr_info("Unable to create debugfs %s directory.\n",
  413. coredev->devpath);
  414. return -ENODEV;
  415. }
  416. d = debugfs_create_file("stats", S_IRUGO | S_IWUSR, client->debugfs,
  417. client, &debugfs_stats_ops);
  418. if (!d) {
  419. debugfs_remove(client->debugfs);
  420. return -ENOMEM;
  421. }
  422. debug_data = kzalloc(sizeof(*client->debug_data), GFP_KERNEL);
  423. if (!debug_data)
  424. return -ENOMEM;
  425. client->debug_data = debug_data;
  426. client->prt_dvb_stats = smsdvb_print_dvb_stats;
  427. client->prt_isdb_stats = smsdvb_print_isdb_stats;
  428. client->prt_isdb_stats_ex = smsdvb_print_isdb_stats_ex;
  429. init_waitqueue_head(&debug_data->stats_queue);
  430. spin_lock_init(&debug_data->lock);
  431. kref_init(&debug_data->refcount);
  432. return 0;
  433. }
  434. void smsdvb_debugfs_release(struct smsdvb_client_t *client)
  435. {
  436. if (!client->debugfs)
  437. return;
  438. client->prt_dvb_stats = NULL;
  439. client->prt_isdb_stats = NULL;
  440. client->prt_isdb_stats_ex = NULL;
  441. debugfs_remove_recursive(client->debugfs);
  442. kref_put(&client->debug_data->refcount, smsdvb_debugfs_data_release);
  443. client->debug_data = NULL;
  444. client->debugfs = NULL;
  445. }
  446. int smsdvb_debugfs_register(void)
  447. {
  448. struct dentry *d;
  449. /*
  450. * FIXME: This was written to debug Siano USB devices. So, it creates
  451. * the debugfs node under <debugfs>/usb.
  452. * A similar logic would be needed for Siano sdio devices, but, in that
  453. * case, usb_debug_root is not a good choice.
  454. *
  455. * Perhaps the right fix here would be to create another sysfs root
  456. * node for sdio-based boards, but this may need some logic at sdio
  457. * subsystem.
  458. */
  459. d = debugfs_create_dir("smsdvb", usb_debug_root);
  460. if (IS_ERR_OR_NULL(d)) {
  461. pr_err("Couldn't create sysfs node for smsdvb\n");
  462. return PTR_ERR(d);
  463. } else {
  464. smsdvb_debugfs_usb_root = d;
  465. }
  466. return 0;
  467. }
  468. void smsdvb_debugfs_unregister(void)
  469. {
  470. debugfs_remove_recursive(smsdvb_debugfs_usb_root);
  471. smsdvb_debugfs_usb_root = NULL;
  472. }