Lines Matching refs:rtl

102 	struct ssh_rtl *rtl = ssh_request_rtl(rqst);  in ssh_rtl_queue_remove()  local
104 spin_lock(&rtl->queue.lock); in ssh_rtl_queue_remove()
107 spin_unlock(&rtl->queue.lock); in ssh_rtl_queue_remove()
113 spin_unlock(&rtl->queue.lock); in ssh_rtl_queue_remove()
117 static bool ssh_rtl_queue_empty(struct ssh_rtl *rtl) in ssh_rtl_queue_empty() argument
121 spin_lock(&rtl->queue.lock); in ssh_rtl_queue_empty()
122 empty = list_empty(&rtl->queue.head); in ssh_rtl_queue_empty()
123 spin_unlock(&rtl->queue.lock); in ssh_rtl_queue_empty()
130 struct ssh_rtl *rtl = ssh_request_rtl(rqst); in ssh_rtl_pending_remove() local
132 spin_lock(&rtl->pending.lock); in ssh_rtl_pending_remove()
135 spin_unlock(&rtl->pending.lock); in ssh_rtl_pending_remove()
139 atomic_dec(&rtl->pending.count); in ssh_rtl_pending_remove()
142 spin_unlock(&rtl->pending.lock); in ssh_rtl_pending_remove()
149 struct ssh_rtl *rtl = ssh_request_rtl(rqst); in ssh_rtl_tx_pending_push() local
151 spin_lock(&rtl->pending.lock); in ssh_rtl_tx_pending_push()
154 spin_unlock(&rtl->pending.lock); in ssh_rtl_tx_pending_push()
159 spin_unlock(&rtl->pending.lock); in ssh_rtl_tx_pending_push()
163 atomic_inc(&rtl->pending.count); in ssh_rtl_tx_pending_push()
164 list_add_tail(&ssh_request_get(rqst)->node, &rtl->pending.head); in ssh_rtl_tx_pending_push()
166 spin_unlock(&rtl->pending.lock); in ssh_rtl_tx_pending_push()
172 struct ssh_rtl *rtl = ssh_request_rtl(rqst); in ssh_rtl_complete_with_status() local
177 rtl_dbg_cond(rtl, "rtl: completing request (rqid: %#06x, status: %d)\n", in ssh_rtl_complete_with_status()
187 struct ssh_rtl *rtl = ssh_request_rtl(rqst); in ssh_rtl_complete_with_rsp() local
191 rtl_dbg(rtl, "rtl: completing request with response (rqid: %#06x)\n", in ssh_rtl_complete_with_rsp()
199 struct ssh_rtl *rtl = ssh_request_rtl(rqst); in ssh_rtl_tx_can_process() local
202 return !atomic_read(&rtl->pending.count); in ssh_rtl_tx_can_process()
204 return atomic_read(&rtl->pending.count) < SSH_RTL_MAX_PENDING; in ssh_rtl_tx_can_process()
207 static struct ssh_request *ssh_rtl_tx_next(struct ssh_rtl *rtl) in ssh_rtl_tx_next() argument
212 spin_lock(&rtl->queue.lock); in ssh_rtl_tx_next()
215 list_for_each_entry_safe(p, n, &rtl->queue.head, node) { in ssh_rtl_tx_next()
236 spin_unlock(&rtl->queue.lock); in ssh_rtl_tx_next()
240 static int ssh_rtl_tx_try_process_one(struct ssh_rtl *rtl) in ssh_rtl_tx_try_process_one() argument
246 rqst = ssh_rtl_tx_next(rtl); in ssh_rtl_tx_try_process_one()
258 status = ssh_ptl_submit(&rtl->ptl, &rqst->packet); in ssh_rtl_tx_try_process_one()
305 static bool ssh_rtl_tx_schedule(struct ssh_rtl *rtl) in ssh_rtl_tx_schedule() argument
307 if (atomic_read(&rtl->pending.count) >= SSH_RTL_MAX_PENDING) in ssh_rtl_tx_schedule()
310 if (ssh_rtl_queue_empty(rtl)) in ssh_rtl_tx_schedule()
313 return schedule_work(&rtl->tx.work); in ssh_rtl_tx_schedule()
318 struct ssh_rtl *rtl = to_ssh_rtl(work, tx.work); in ssh_rtl_tx_work_fn() local
328 status = ssh_rtl_tx_try_process_one(rtl); in ssh_rtl_tx_work_fn()
345 ssh_rtl_tx_schedule(rtl); in ssh_rtl_tx_work_fn()
361 int ssh_rtl_submit(struct ssh_rtl *rtl, struct ssh_request *rqst) in ssh_rtl_submit() argument
374 spin_lock(&rtl->queue.lock); in ssh_rtl_submit()
391 if (cmpxchg(&rqst->packet.ptl, NULL, &rtl->ptl)) { in ssh_rtl_submit()
392 spin_unlock(&rtl->queue.lock); in ssh_rtl_submit()
407 if (test_bit(SSH_RTL_SF_SHUTDOWN_BIT, &rtl->state)) { in ssh_rtl_submit()
408 spin_unlock(&rtl->queue.lock); in ssh_rtl_submit()
413 spin_unlock(&rtl->queue.lock); in ssh_rtl_submit()
418 list_add_tail(&ssh_request_get(rqst)->node, &rtl->queue.head); in ssh_rtl_submit()
420 spin_unlock(&rtl->queue.lock); in ssh_rtl_submit()
422 ssh_rtl_tx_schedule(rtl); in ssh_rtl_submit()
426 static void ssh_rtl_timeout_reaper_mod(struct ssh_rtl *rtl, ktime_t now, in ssh_rtl_timeout_reaper_mod() argument
432 spin_lock(&rtl->rtx_timeout.lock); in ssh_rtl_timeout_reaper_mod()
435 if (ktime_before(aexp, rtl->rtx_timeout.expires)) { in ssh_rtl_timeout_reaper_mod()
436 rtl->rtx_timeout.expires = expires; in ssh_rtl_timeout_reaper_mod()
437 mod_delayed_work(system_wq, &rtl->rtx_timeout.reaper, delta); in ssh_rtl_timeout_reaper_mod()
440 spin_unlock(&rtl->rtx_timeout.lock); in ssh_rtl_timeout_reaper_mod()
445 struct ssh_rtl *rtl = ssh_request_rtl(rqst); in ssh_rtl_timeout_start() local
447 ktime_t timeout = rtl->rtx_timeout.timeout; in ssh_rtl_timeout_start()
464 ssh_rtl_timeout_reaper_mod(rtl, timestamp, timestamp + timeout); in ssh_rtl_timeout_start()
467 static void ssh_rtl_complete(struct ssh_rtl *rtl, in ssh_rtl_complete() argument
481 spin_lock(&rtl->pending.lock); in ssh_rtl_complete()
482 list_for_each_entry_safe(p, n, &rtl->pending.head, node) { in ssh_rtl_complete()
489 spin_unlock(&rtl->pending.lock); in ssh_rtl_complete()
492 rtl_info(rtl, "request error injection: dropping response for request %p\n", in ssh_rtl_complete()
507 atomic_dec(&rtl->pending.count); in ssh_rtl_complete()
513 spin_unlock(&rtl->pending.lock); in ssh_rtl_complete()
516 rtl_warn(rtl, "rtl: dropping unexpected command message (rqid = %#06x)\n", in ssh_rtl_complete()
524 ssh_rtl_tx_schedule(rtl); in ssh_rtl_complete()
549 rtl_err(rtl, "rtl: received response before ACK for request (rqid = %#06x)\n", in ssh_rtl_complete()
563 ssh_rtl_tx_schedule(rtl); in ssh_rtl_complete()
578 ssh_rtl_tx_schedule(rtl); in ssh_rtl_complete()
583 struct ssh_rtl *rtl; in ssh_rtl_cancel_nonpending() local
627 rtl = ssh_request_rtl(r); in ssh_rtl_cancel_nonpending()
628 spin_lock(&rtl->queue.lock); in ssh_rtl_cancel_nonpending()
639 spin_unlock(&rtl->queue.lock); in ssh_rtl_cancel_nonpending()
646 spin_unlock(&rtl->queue.lock); in ssh_rtl_cancel_nonpending()
730 struct ssh_rtl *rtl; in ssh_rtl_cancel() local
744 rtl = ssh_request_rtl(rqst); in ssh_rtl_cancel()
745 if (canceled && rtl) in ssh_rtl_cancel()
746 ssh_rtl_tx_schedule(rtl); in ssh_rtl_cancel()
822 struct ssh_rtl *rtl = to_ssh_rtl(work, rtx_timeout.reaper.work); in ssh_rtl_timeout_reap() local
826 ktime_t timeout = rtl->rtx_timeout.timeout; in ssh_rtl_timeout_reap()
829 trace_ssam_rtl_timeout_reap(atomic_read(&rtl->pending.count)); in ssh_rtl_timeout_reap()
835 spin_lock(&rtl->rtx_timeout.lock); in ssh_rtl_timeout_reap()
836 rtl->rtx_timeout.expires = KTIME_MAX; in ssh_rtl_timeout_reap()
837 spin_unlock(&rtl->rtx_timeout.lock); in ssh_rtl_timeout_reap()
839 spin_lock(&rtl->pending.lock); in ssh_rtl_timeout_reap()
840 list_for_each_entry_safe(r, n, &rtl->pending.head, node) { in ssh_rtl_timeout_reap()
865 atomic_dec(&rtl->pending.count); in ssh_rtl_timeout_reap()
868 spin_unlock(&rtl->pending.lock); in ssh_rtl_timeout_reap()
893 ssh_rtl_timeout_reaper_mod(rtl, now, next); in ssh_rtl_timeout_reap()
895 ssh_rtl_tx_schedule(rtl); in ssh_rtl_timeout_reap()
898 static void ssh_rtl_rx_event(struct ssh_rtl *rtl, const struct ssh_command *cmd, in ssh_rtl_rx_event() argument
903 rtl_dbg(rtl, "rtl: handling event (rqid: %#06x)\n", in ssh_rtl_rx_event()
906 rtl->ops.handle_event(rtl, cmd, data); in ssh_rtl_rx_event()
911 struct ssh_rtl *rtl = to_ssh_rtl(p, ptl); in ssh_rtl_rx_command() local
929 rtl_warn(rtl, "rtl: dropping message not intended for us (tid = %#04x)\n", in ssh_rtl_rx_command()
935 ssh_rtl_rx_event(rtl, command, &command_data); in ssh_rtl_rx_command()
937 ssh_rtl_complete(rtl, command, &command_data); in ssh_rtl_rx_command()
1025 int ssh_rtl_init(struct ssh_rtl *rtl, struct serdev_device *serdev, in ssh_rtl_init() argument
1033 status = ssh_ptl_init(&rtl->ptl, serdev, &ptl_ops); in ssh_rtl_init()
1037 spin_lock_init(&rtl->queue.lock); in ssh_rtl_init()
1038 INIT_LIST_HEAD(&rtl->queue.head); in ssh_rtl_init()
1040 spin_lock_init(&rtl->pending.lock); in ssh_rtl_init()
1041 INIT_LIST_HEAD(&rtl->pending.head); in ssh_rtl_init()
1042 atomic_set_release(&rtl->pending.count, 0); in ssh_rtl_init()
1044 INIT_WORK(&rtl->tx.work, ssh_rtl_tx_work_fn); in ssh_rtl_init()
1046 spin_lock_init(&rtl->rtx_timeout.lock); in ssh_rtl_init()
1047 rtl->rtx_timeout.timeout = SSH_RTL_REQUEST_TIMEOUT; in ssh_rtl_init()
1048 rtl->rtx_timeout.expires = KTIME_MAX; in ssh_rtl_init()
1049 INIT_DELAYED_WORK(&rtl->rtx_timeout.reaper, ssh_rtl_timeout_reap); in ssh_rtl_init()
1051 rtl->ops = *ops; in ssh_rtl_init()
1065 void ssh_rtl_destroy(struct ssh_rtl *rtl) in ssh_rtl_destroy() argument
1067 ssh_ptl_destroy(&rtl->ptl); in ssh_rtl_destroy()
1076 int ssh_rtl_start(struct ssh_rtl *rtl) in ssh_rtl_start() argument
1080 status = ssh_ptl_tx_start(&rtl->ptl); in ssh_rtl_start()
1084 ssh_rtl_tx_schedule(rtl); in ssh_rtl_start()
1086 status = ssh_ptl_rx_start(&rtl->ptl); in ssh_rtl_start()
1088 ssh_rtl_flush(rtl, msecs_to_jiffies(5000)); in ssh_rtl_start()
1089 ssh_ptl_tx_stop(&rtl->ptl); in ssh_rtl_start()
1154 int ssh_rtl_flush(struct ssh_rtl *rtl, unsigned long timeout) in ssh_rtl_flush() argument
1167 status = ssh_rtl_submit(rtl, &rqst.base); in ssh_rtl_flush()
1197 void ssh_rtl_shutdown(struct ssh_rtl *rtl) in ssh_rtl_shutdown() argument
1203 set_bit(SSH_RTL_SF_SHUTDOWN_BIT, &rtl->state); in ssh_rtl_shutdown()
1213 spin_lock(&rtl->queue.lock); in ssh_rtl_shutdown()
1214 list_for_each_entry_safe(r, n, &rtl->queue.head, node) { in ssh_rtl_shutdown()
1222 spin_unlock(&rtl->queue.lock); in ssh_rtl_shutdown()
1234 cancel_work_sync(&rtl->tx.work); in ssh_rtl_shutdown()
1235 ssh_ptl_shutdown(&rtl->ptl); in ssh_rtl_shutdown()
1236 cancel_delayed_work_sync(&rtl->rtx_timeout.reaper); in ssh_rtl_shutdown()
1244 pending = atomic_read(&rtl->pending.count); in ssh_rtl_shutdown()
1246 spin_lock(&rtl->pending.lock); in ssh_rtl_shutdown()
1247 list_for_each_entry_safe(r, n, &rtl->pending.head, node) { in ssh_rtl_shutdown()
1255 spin_unlock(&rtl->pending.lock); in ssh_rtl_shutdown()