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