17 #include <linux/slab.h>
69 delta = (val < fraction) ? (fraction - val) : (val - fraction);
71 if (delta <= tolerance)
75 factor = val / fraction;
76 remainder = val % fraction;
77 if (remainder > tolerance) {
79 if ((fraction - remainder) <= tolerance)
97 static u32 singleton_pool_references;
102 static void pool_register_ref(
void)
104 spin_lock_bh(&pool_lock);
105 singleton_pool_references++;
107 spin_unlock_bh(&pool_lock);
110 static void pool_deregister_ref(
void)
112 spin_lock_bh(&pool_lock);
113 singleton_pool_references--;
115 if (singleton_pool_references == 0) {
131 spin_unlock_bh(&pool_lock);
134 static void pool_put_pulse_elem(
struct pulse_elem *pe)
136 spin_lock_bh(&pool_lock);
137 list_add(&pe->
head, &pulse_pool);
139 spin_unlock_bh(&pool_lock);
142 static void pool_put_pseq_elem(
struct pri_sequence *pse)
144 spin_lock_bh(&pool_lock);
145 list_add(&pse->
head, &pseq_pool);
147 spin_unlock_bh(&pool_lock);
153 spin_lock_bh(&pool_lock);
154 if (!list_empty(&pseq_pool)) {
159 spin_unlock_bh(&pool_lock);
163 static struct pulse_elem *pool_get_pulse_elem(
void)
166 spin_lock_bh(&pool_lock);
167 if (!list_empty(&pulse_pool)) {
172 spin_unlock_bh(&pool_lock);
184 static bool pulse_queue_dequeue(
struct pri_detector *pde)
188 list_del_init(&p->
head);
191 pool_put_pulse_elem(p);
193 return (pde->
count > 0);
197 static void pulse_queue_check_window(
struct pri_detector *pde)
210 while ((p = pulse_queue_get_tail(pde)) !=
NULL) {
211 if (p->
ts >= min_valid_ts)
213 pulse_queue_dequeue(pde);
229 INIT_LIST_HEAD(&p->
head);
234 pulse_queue_check_window(pde);
236 pulse_queue_dequeue(pde);
240 static bool pseq_handler_create_sequences(
struct pri_detector *pde,
249 u32 delta_ts = ts - p->
ts;
251 if (delta_ts < pde->
rs->pri_min)
255 if (delta_ts > pde->
rs->pri_max)
265 ps.dur =
ps.pri * (pde->
rs->ppb - 1)
266 + 2 * pde->
rs->max_pri_tolerance;
270 min_valid_ts = ts -
ps.dur;
274 if (p2->
ts < min_valid_ts)
278 factor = pde_get_multiple(
ps.last_ts - p2->
ts,
ps.pri,
279 pde->
rs->max_pri_tolerance);
282 ps.first_ts = p2->
ts;
287 ps.count_falses += tmp_false_count;
294 if (
ps.count < min_count)
299 ps.deadline_ts =
ps.first_ts +
ps.dur;
300 new_ps = pool_get_pseq_elem();
301 if (new_ps ==
NULL) {
303 if (new_ps ==
NULL) {
311 INIT_LIST_HEAD(&new_ps->
head);
329 list_del_init(&ps->
head);
330 pool_put_pseq_elem(ps);
335 factor = pde_get_multiple(delta_ts, ps->
pri,
336 pde->
rs->max_pri_tolerance);
341 if (max_count < ps->
count)
342 max_count = ps->
count;
364 if ((ps->
count >= pde->
rs->ppb_thresh) &&
378 list_del_init(&ps->
head);
379 pool_put_pseq_elem(ps);
382 list_del_init(&p->
head);
383 pool_put_pulse_elem(p);
391 pri_detector_reset(de, 0);
392 pool_deregister_ref();
396 static bool pri_detector_add_pulse(
struct pri_detector *de,
413 max_updated_seq = pseq_handler_add_to_existing_seqs(de, ts);
415 if (!pseq_handler_create_sequences(de, ts, max_updated_seq)) {
416 pr_err(
"failed to create pulse sequences\n");
417 pri_detector_reset(de, ts);
421 ps = pseq_handler_check_detection(de);
424 pr_info(
"DFS: radar found: pri=%d, count=%d, count_false=%d\n",
426 pri_detector_reset(de, ts);
429 pulse_queue_enqueue(de, ts);
440 de->
exit = pri_detector_exit;
442 de->
reset = pri_detector_reset;
445 INIT_LIST_HEAD(&de->
pulses);