xref: /wlan-driver/qcacld-3.0/os_if/qmi/src/os_if_qmi.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /**
18  * DOC: os_if_qmi.c
19  *
20  * This file contains definitions of wrapper APIs for QMI HLOS APIs
21  */
22 
23 #include "os_if_qmi.h"
24 #include "wlan_qmi_ucfg_api.h"
25 
os_if_qmi_handle_init(struct qmi_handle * qmi_hdl,qdf_size_t recv_buf_size,const struct qmi_ops * ops,const struct qmi_msg_handler * qmi_msg_handlers)26 QDF_STATUS os_if_qmi_handle_init(struct qmi_handle *qmi_hdl,
27 				 qdf_size_t recv_buf_size,
28 				 const struct qmi_ops *ops,
29 				 const struct qmi_msg_handler *qmi_msg_handlers)
30 {
31 	int ret;
32 
33 	ret = qmi_handle_init(qmi_hdl, recv_buf_size, ops, qmi_msg_handlers);
34 	if (ret < 0) {
35 		osif_err("QMI handle initialization failed %d", ret);
36 		return qdf_status_from_os_return(ret);
37 	}
38 
39 	return QDF_STATUS_SUCCESS;
40 }
41 
os_if_qmi_handle_release(struct qmi_handle * qmi_hdl)42 void os_if_qmi_handle_release(struct qmi_handle *qmi_hdl)
43 {
44 	qmi_handle_release(qmi_hdl);
45 }
46 
os_if_qmi_add_lookup(struct qmi_handle * qmi_hdl,unsigned int service,unsigned int version,unsigned int instance)47 QDF_STATUS os_if_qmi_add_lookup(struct qmi_handle *qmi_hdl,
48 				unsigned int service, unsigned int version,
49 				unsigned int instance)
50 {
51 	int ret;
52 
53 	ret = qmi_add_lookup(qmi_hdl, service, version, instance);
54 	if (ret < 0) {
55 		osif_err("QMI add lookup failed %d", ret);
56 		return qdf_status_from_os_return(ret);
57 	}
58 
59 	return QDF_STATUS_SUCCESS;
60 }
61 
os_if_qmi_connect_to_svc(struct qmi_handle * qmi_hdl,struct qmi_service * qmi_svc)62 QDF_STATUS os_if_qmi_connect_to_svc(struct qmi_handle *qmi_hdl,
63 				    struct qmi_service *qmi_svc)
64 {
65 	struct sockaddr_qrtr sq = { 0 };
66 	int ret;
67 
68 	osif_debug("QMI server arriving: node %u port %u", qmi_svc->node,
69 		   qmi_svc->port);
70 
71 	sq.sq_family = AF_QIPCRTR;
72 	sq.sq_node = qmi_svc->node;
73 	sq.sq_port = qmi_svc->port;
74 
75 	ret = kernel_connect(qmi_hdl->sock, (struct sockaddr *)&sq,
76 			     sizeof(sq), 0);
77 	if (ret < 0) {
78 		osif_err("Failed to connect to QMI remote service %d", ret);
79 		return qdf_status_from_os_return(ret);
80 	}
81 
82 	return QDF_STATUS_SUCCESS;
83 }
84 
os_if_qmi_txn_init(struct qmi_handle * qmi_hdl,struct qmi_txn * qmi_txn,struct qmi_elem_info * qmi_ei,void * resp)85 QDF_STATUS os_if_qmi_txn_init(struct qmi_handle *qmi_hdl,
86 			      struct qmi_txn *qmi_txn,
87 			      struct qmi_elem_info *qmi_ei, void *resp)
88 {
89 	int ret;
90 
91 	ret = qmi_txn_init(qmi_hdl, qmi_txn, qmi_ei, resp);
92 	if (ret < 0)
93 		return qdf_status_from_os_return(ret);
94 
95 	return QDF_STATUS_SUCCESS;
96 }
97 
os_if_qmi_send_request(struct qmi_handle * qmi_hdl,struct sockaddr_qrtr * sq,struct qmi_txn * qmi_txn,int msg_id,uint32_t len,struct qmi_elem_info * ei,const void * req)98 QDF_STATUS os_if_qmi_send_request(struct qmi_handle *qmi_hdl,
99 				  struct sockaddr_qrtr *sq,
100 				  struct qmi_txn *qmi_txn, int msg_id,
101 				  uint32_t len, struct qmi_elem_info *ei,
102 				  const void *req)
103 {
104 	int ret;
105 
106 	ret = qmi_send_request(qmi_hdl, sq, qmi_txn, msg_id, len, ei, req);
107 	if (ret < 0)
108 		return qdf_status_from_os_return(ret);
109 
110 	return QDF_STATUS_SUCCESS;
111 }
112 
os_if_qmi_txn_wait(struct qmi_txn * qmi_txn,unsigned long timeout)113 QDF_STATUS os_if_qmi_txn_wait(struct qmi_txn *qmi_txn, unsigned long timeout)
114 {
115 	int ret;
116 
117 	ret = qmi_txn_wait(qmi_txn, timeout);
118 	if (ret < 0)
119 		return qdf_status_from_os_return(ret);
120 
121 	return QDF_STATUS_SUCCESS;
122 }
123 
os_if_qmi_txn_cancel(struct qmi_txn * qmi_txn)124 void os_if_qmi_txn_cancel(struct qmi_txn *qmi_txn)
125 {
126 	qmi_txn_cancel(qmi_txn);
127 }
128 
os_if_qmi_register_callbacks(struct wlan_objmgr_psoc * psoc,struct wlan_qmi_psoc_callbacks * cb_obj)129 void os_if_qmi_register_callbacks(struct wlan_objmgr_psoc *psoc,
130 				  struct wlan_qmi_psoc_callbacks *cb_obj)
131 {
132 	os_if_qmi_wfds_register_callbacks(cb_obj);
133 	ucfg_qmi_register_os_if_callbacks(psoc, cb_obj);
134 }
135