• Home
  • Raw
  • Download

Lines Matching full:qmi

15 #include <linux/soc/qcom/qmi.h>
17 static struct socket *qmi_sock_create(struct qmi_handle *qmi,
22 * @qmi: qmi handle
31 static void qmi_recv_new_server(struct qmi_handle *qmi, in qmi_recv_new_server() argument
35 struct qmi_ops *ops = &qmi->ops; in qmi_recv_new_server()
56 ret = ops->new_server(qmi, svc); in qmi_recv_new_server()
60 list_add(&svc->list_node, &qmi->lookup_results); in qmi_recv_new_server()
65 * @qmi: qmi handle
72 static void qmi_recv_del_server(struct qmi_handle *qmi, in qmi_recv_del_server() argument
75 struct qmi_ops *ops = &qmi->ops; in qmi_recv_del_server()
79 list_for_each_entry_safe(svc, tmp, &qmi->lookup_results, list_node) { in qmi_recv_del_server()
86 ops->del_server(qmi, svc); in qmi_recv_del_server()
95 * @qmi: qmi handle
102 static void qmi_recv_bye(struct qmi_handle *qmi, in qmi_recv_bye() argument
105 struct qmi_ops *ops = &qmi->ops; in qmi_recv_bye()
107 qmi_recv_del_server(qmi, node, -1); in qmi_recv_bye()
110 ops->bye(qmi, node); in qmi_recv_bye()
115 * @qmi: qmi handle
121 static void qmi_recv_del_client(struct qmi_handle *qmi, in qmi_recv_del_client() argument
124 struct qmi_ops *ops = &qmi->ops; in qmi_recv_del_client()
127 ops->del_client(qmi, node, port); in qmi_recv_del_client()
130 static void qmi_recv_ctrl_pkt(struct qmi_handle *qmi, in qmi_recv_ctrl_pkt() argument
142 qmi_recv_bye(qmi, le32_to_cpu(pkt->client.node)); in qmi_recv_ctrl_pkt()
145 qmi_recv_new_server(qmi, in qmi_recv_ctrl_pkt()
152 qmi_recv_del_server(qmi, in qmi_recv_ctrl_pkt()
157 qmi_recv_del_client(qmi, in qmi_recv_ctrl_pkt()
164 static void qmi_send_new_lookup(struct qmi_handle *qmi, struct qmi_service *svc) in qmi_send_new_lookup() argument
177 sq.sq_family = qmi->sq.sq_family; in qmi_send_new_lookup()
178 sq.sq_node = qmi->sq.sq_node; in qmi_send_new_lookup()
184 mutex_lock(&qmi->sock_lock); in qmi_send_new_lookup()
185 if (qmi->sock) { in qmi_send_new_lookup()
186 ret = kernel_sendmsg(qmi->sock, &msg, &iv, 1, sizeof(pkt)); in qmi_send_new_lookup()
190 mutex_unlock(&qmi->sock_lock); in qmi_send_new_lookup()
195 * @qmi: qmi handle
206 int qmi_add_lookup(struct qmi_handle *qmi, unsigned int service, in qmi_add_lookup() argument
219 list_add(&svc->list_node, &qmi->lookups); in qmi_add_lookup()
221 qmi_send_new_lookup(qmi, svc); in qmi_add_lookup()
227 static void qmi_send_new_server(struct qmi_handle *qmi, struct qmi_service *svc) in qmi_send_new_server() argument
239 pkt.server.node = cpu_to_le32(qmi->sq.sq_node); in qmi_send_new_server()
240 pkt.server.port = cpu_to_le32(qmi->sq.sq_port); in qmi_send_new_server()
242 sq.sq_family = qmi->sq.sq_family; in qmi_send_new_server()
243 sq.sq_node = qmi->sq.sq_node; in qmi_send_new_server()
249 mutex_lock(&qmi->sock_lock); in qmi_send_new_server()
250 if (qmi->sock) { in qmi_send_new_server()
251 ret = kernel_sendmsg(qmi->sock, &msg, &iv, 1, sizeof(pkt)); in qmi_send_new_server()
255 mutex_unlock(&qmi->sock_lock); in qmi_send_new_server()
260 * @qmi: qmi handle
266 * and start sending messages to the client associated with @qmi.
270 int qmi_add_server(struct qmi_handle *qmi, unsigned int service, in qmi_add_server() argument
283 list_add(&svc->list_node, &qmi->services); in qmi_add_server()
285 qmi_send_new_server(qmi, svc); in qmi_add_server()
292 * qmi_txn_init() - allocate transaction id within the given QMI handle
293 * @qmi: QMI handle
298 * This allocates a transaction id within the QMI handle. If @ei and @c_struct
307 int qmi_txn_init(struct qmi_handle *qmi, struct qmi_txn *txn, in qmi_txn_init() argument
316 txn->qmi = qmi; in qmi_txn_init()
320 mutex_lock(&qmi->txn_lock); in qmi_txn_init()
321 ret = idr_alloc_cyclic(&qmi->txns, txn, 0, U16_MAX, GFP_KERNEL); in qmi_txn_init()
326 mutex_unlock(&qmi->txn_lock); in qmi_txn_init()
345 struct qmi_handle *qmi = txn->qmi; in qmi_txn_wait() local
350 mutex_lock(&qmi->txn_lock); in qmi_txn_wait()
352 idr_remove(&qmi->txns, txn->id); in qmi_txn_wait()
354 mutex_unlock(&qmi->txn_lock); in qmi_txn_wait()
369 struct qmi_handle *qmi = txn->qmi; in qmi_txn_cancel() local
371 mutex_lock(&qmi->txn_lock); in qmi_txn_cancel()
373 idr_remove(&qmi->txns, txn->id); in qmi_txn_cancel()
375 mutex_unlock(&qmi->txn_lock); in qmi_txn_cancel()
381 * @qmi: qmi handle
389 static void qmi_invoke_handler(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, in qmi_invoke_handler() argument
397 if (!qmi->handlers) in qmi_invoke_handler()
400 for (handler = qmi->handlers; handler->fn; handler++) { in qmi_invoke_handler()
417 handler->fn(qmi, sq, txn, dest); in qmi_invoke_handler()
423 * qmi_handle_net_reset() - invoked to handle ENETRESET on a QMI handle
424 * @qmi: the QMI context
436 * Finally the QMI handle will send out registration requests for any lookups
439 static void qmi_handle_net_reset(struct qmi_handle *qmi) in qmi_handle_net_reset() argument
445 sock = qmi_sock_create(qmi, &sq); in qmi_handle_net_reset()
449 mutex_lock(&qmi->sock_lock); in qmi_handle_net_reset()
450 sock_release(qmi->sock); in qmi_handle_net_reset()
451 qmi->sock = NULL; in qmi_handle_net_reset()
452 mutex_unlock(&qmi->sock_lock); in qmi_handle_net_reset()
454 qmi_recv_del_server(qmi, -1, -1); in qmi_handle_net_reset()
456 if (qmi->ops.net_reset) in qmi_handle_net_reset()
457 qmi->ops.net_reset(qmi); in qmi_handle_net_reset()
459 mutex_lock(&qmi->sock_lock); in qmi_handle_net_reset()
460 qmi->sock = sock; in qmi_handle_net_reset()
461 qmi->sq = sq; in qmi_handle_net_reset()
462 mutex_unlock(&qmi->sock_lock); in qmi_handle_net_reset()
464 list_for_each_entry(svc, &qmi->lookups, list_node) in qmi_handle_net_reset()
465 qmi_send_new_lookup(qmi, svc); in qmi_handle_net_reset()
467 list_for_each_entry(svc, &qmi->services, list_node) in qmi_handle_net_reset()
468 qmi_send_new_server(qmi, svc); in qmi_handle_net_reset()
471 static void qmi_handle_message(struct qmi_handle *qmi, in qmi_handle_message() argument
481 pr_err("ignoring short QMI packet\n"); in qmi_handle_message()
489 mutex_lock(&qmi->txn_lock); in qmi_handle_message()
490 txn = idr_find(&qmi->txns, hdr->txn_id); in qmi_handle_message()
494 mutex_unlock(&qmi->txn_lock); in qmi_handle_message()
499 mutex_unlock(&qmi->txn_lock); in qmi_handle_message()
509 qmi_invoke_handler(qmi, sq, txn, buf, len); in qmi_handle_message()
518 qmi_invoke_handler(qmi, sq, &tmp_txn, buf, len); in qmi_handle_message()
524 struct qmi_handle *qmi = container_of(work, struct qmi_handle, work); in qmi_data_ready_work() local
525 struct qmi_ops *ops = &qmi->ops; in qmi_data_ready_work()
532 iv.iov_base = qmi->recv_buf; in qmi_data_ready_work()
533 iv.iov_len = qmi->recv_buf_size; in qmi_data_ready_work()
535 mutex_lock(&qmi->sock_lock); in qmi_data_ready_work()
536 if (qmi->sock) in qmi_data_ready_work()
537 msglen = kernel_recvmsg(qmi->sock, &msg, &iv, 1, in qmi_data_ready_work()
541 mutex_unlock(&qmi->sock_lock); in qmi_data_ready_work()
546 qmi_handle_net_reset(qmi); in qmi_data_ready_work()
548 /* The old qmi->sock is gone, our work is done */ in qmi_data_ready_work()
553 pr_err("qmi recvmsg failed: %zd\n", msglen); in qmi_data_ready_work()
557 if (sq.sq_node == qmi->sq.sq_node && in qmi_data_ready_work()
559 qmi_recv_ctrl_pkt(qmi, qmi->recv_buf, msglen); in qmi_data_ready_work()
561 ops->msg_handler(qmi, &sq, qmi->recv_buf, msglen); in qmi_data_ready_work()
563 qmi_handle_message(qmi, &sq, qmi->recv_buf, msglen); in qmi_data_ready_work()
570 struct qmi_handle *qmi = sk->sk_user_data; in qmi_data_ready() local
576 if (!qmi) in qmi_data_ready()
579 queue_work(qmi->wq, &qmi->work); in qmi_data_ready()
582 static struct socket *qmi_sock_create(struct qmi_handle *qmi, in qmi_sock_create() argument
599 sock->sk->sk_user_data = qmi; in qmi_sock_create()
607 * qmi_handle_init() - initialize a QMI client handle
608 * @qmi: QMI handle to initialize
611 * @handlers: NULL-terminated list of QMI message handlers
613 * This initializes the QMI client handle to allow sending and receiving QMI
618 int qmi_handle_init(struct qmi_handle *qmi, size_t recv_buf_size, in qmi_handle_init() argument
624 mutex_init(&qmi->txn_lock); in qmi_handle_init()
625 mutex_init(&qmi->sock_lock); in qmi_handle_init()
627 idr_init(&qmi->txns); in qmi_handle_init()
629 INIT_LIST_HEAD(&qmi->lookups); in qmi_handle_init()
630 INIT_LIST_HEAD(&qmi->lookup_results); in qmi_handle_init()
631 INIT_LIST_HEAD(&qmi->services); in qmi_handle_init()
633 INIT_WORK(&qmi->work, qmi_data_ready_work); in qmi_handle_init()
635 qmi->handlers = handlers; in qmi_handle_init()
637 qmi->ops = *ops; in qmi_handle_init()
645 qmi->recv_buf_size = recv_buf_size; in qmi_handle_init()
646 qmi->recv_buf = kzalloc(recv_buf_size, GFP_KERNEL); in qmi_handle_init()
647 if (!qmi->recv_buf) in qmi_handle_init()
650 qmi->wq = alloc_workqueue("qmi_msg_handler", WQ_UNBOUND, 1); in qmi_handle_init()
651 if (!qmi->wq) { in qmi_handle_init()
656 qmi->sock = qmi_sock_create(qmi, &qmi->sq); in qmi_handle_init()
657 if (IS_ERR(qmi->sock)) { in qmi_handle_init()
658 if (PTR_ERR(qmi->sock) == -EAFNOSUPPORT) { in qmi_handle_init()
661 pr_err("failed to create QMI socket\n"); in qmi_handle_init()
662 ret = PTR_ERR(qmi->sock); in qmi_handle_init()
670 destroy_workqueue(qmi->wq); in qmi_handle_init()
672 kfree(qmi->recv_buf); in qmi_handle_init()
679 * qmi_handle_release() - release the QMI client handle
680 * @qmi: QMI client handle
682 * This closes the underlying socket and stops any handling of QMI messages.
684 void qmi_handle_release(struct qmi_handle *qmi) in qmi_handle_release() argument
686 struct socket *sock = qmi->sock; in qmi_handle_release()
690 cancel_work_sync(&qmi->work); in qmi_handle_release()
692 qmi_recv_del_server(qmi, -1, -1); in qmi_handle_release()
694 mutex_lock(&qmi->sock_lock); in qmi_handle_release()
696 qmi->sock = NULL; in qmi_handle_release()
697 mutex_unlock(&qmi->sock_lock); in qmi_handle_release()
699 destroy_workqueue(qmi->wq); in qmi_handle_release()
701 idr_destroy(&qmi->txns); in qmi_handle_release()
703 kfree(qmi->recv_buf); in qmi_handle_release()
706 list_for_each_entry_safe(svc, tmp, &qmi->lookups, list_node) { in qmi_handle_release()
712 list_for_each_entry_safe(svc, tmp, &qmi->services, list_node) { in qmi_handle_release()
720 * qmi_send_message() - send a QMI message
721 * @qmi: QMI client handle
726 * @len: max length of the QMI message
727 * @ei: QMI message description
736 static ssize_t qmi_send_message(struct qmi_handle *qmi, in qmi_send_message() argument
761 mutex_lock(&qmi->sock_lock); in qmi_send_message()
762 if (qmi->sock) { in qmi_send_message()
763 ret = kernel_sendmsg(qmi->sock, &msghdr, &iv, 1, len); in qmi_send_message()
765 pr_err("failed to send QMI message\n"); in qmi_send_message()
769 mutex_unlock(&qmi->sock_lock); in qmi_send_message()
777 * qmi_send_request() - send a request QMI message
778 * @qmi: QMI client handle
782 * @len: max length of the QMI message
783 * @ei: QMI message description
788 ssize_t qmi_send_request(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, in qmi_send_request() argument
792 return qmi_send_message(qmi, sq, txn, QMI_REQUEST, msg_id, len, ei, in qmi_send_request()
798 * qmi_send_response() - send a response QMI message
799 * @qmi: QMI client handle
803 * @len: max length of the QMI message
804 * @ei: QMI message description
809 ssize_t qmi_send_response(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, in qmi_send_response() argument
813 return qmi_send_message(qmi, sq, txn, QMI_RESPONSE, msg_id, len, ei, in qmi_send_response()
819 * qmi_send_indication() - send an indication QMI message
820 * @qmi: QMI client handle
823 * @len: max length of the QMI message
824 * @ei: QMI message description
829 ssize_t qmi_send_indication(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, in qmi_send_indication() argument
837 ret = qmi_txn_init(qmi, &txn, NULL, NULL); in qmi_send_indication()
841 rval = qmi_send_message(qmi, sq, &txn, QMI_INDICATION, msg_id, len, ei, in qmi_send_indication()