Lines Matching refs:qmi
17 static struct socket *qmi_sock_create(struct qmi_handle *qmi,
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()
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()
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()
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()
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()
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()
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()
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()
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
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()
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()
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()
659 ret = PTR_ERR(qmi->sock); in qmi_handle_init()
666 destroy_workqueue(qmi->wq); in qmi_handle_init()
668 kfree(qmi->recv_buf); in qmi_handle_init()
680 void qmi_handle_release(struct qmi_handle *qmi) in qmi_handle_release() argument
682 struct socket *sock = qmi->sock; in qmi_handle_release()
686 cancel_work_sync(&qmi->work); in qmi_handle_release()
688 qmi_recv_del_server(qmi, -1, -1); in qmi_handle_release()
690 mutex_lock(&qmi->sock_lock); in qmi_handle_release()
692 qmi->sock = NULL; in qmi_handle_release()
693 mutex_unlock(&qmi->sock_lock); in qmi_handle_release()
695 destroy_workqueue(qmi->wq); in qmi_handle_release()
697 idr_destroy(&qmi->txns); in qmi_handle_release()
699 kfree(qmi->recv_buf); in qmi_handle_release()
702 list_for_each_entry_safe(svc, tmp, &qmi->lookups, list_node) { in qmi_handle_release()
708 list_for_each_entry_safe(svc, tmp, &qmi->services, list_node) { in qmi_handle_release()
732 static ssize_t qmi_send_message(struct qmi_handle *qmi, in qmi_send_message() argument
757 mutex_lock(&qmi->sock_lock); in qmi_send_message()
758 if (qmi->sock) { in qmi_send_message()
759 ret = kernel_sendmsg(qmi->sock, &msghdr, &iv, 1, len); in qmi_send_message()
765 mutex_unlock(&qmi->sock_lock); in qmi_send_message()
784 ssize_t qmi_send_request(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, in qmi_send_request() argument
788 return qmi_send_message(qmi, sq, txn, QMI_REQUEST, msg_id, len, ei, in qmi_send_request()
805 ssize_t qmi_send_response(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, in qmi_send_response() argument
809 return qmi_send_message(qmi, sq, txn, QMI_RESPONSE, msg_id, len, ei, in qmi_send_response()
825 ssize_t qmi_send_indication(struct qmi_handle *qmi, struct sockaddr_qrtr *sq, in qmi_send_indication() argument
833 ret = qmi_txn_init(qmi, &txn, NULL, NULL); in qmi_send_indication()
837 rval = qmi_send_message(qmi, sq, &txn, QMI_INDICATION, msg_id, len, ei, in qmi_send_indication()