1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015, Sony Mobile Communications Inc.
4 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
7 #include <linux/module.h>
8 #include <linux/skbuff.h>
9 #include <linux/rpmsg.h>
14 struct qrtr_endpoint ep
;
15 struct rpmsg_endpoint
*channel
;
19 /* from smd to qrtr */
20 static int qcom_smd_qrtr_callback(struct rpmsg_device
*rpdev
,
21 void *data
, int len
, void *priv
, u32 addr
)
23 struct qrtr_smd_dev
*qdev
= dev_get_drvdata(&rpdev
->dev
);
29 rc
= qrtr_endpoint_post(&qdev
->ep
, data
, len
);
31 dev_err(qdev
->dev
, "invalid ipcrouter packet\n");
32 /* return 0 to let smd drop the packet */
39 /* from qrtr to smd */
40 static int qcom_smd_qrtr_send(struct qrtr_endpoint
*ep
, struct sk_buff
*skb
)
42 struct qrtr_smd_dev
*qdev
= container_of(ep
, struct qrtr_smd_dev
, ep
);
45 rc
= skb_linearize(skb
);
49 rc
= rpmsg_send(qdev
->channel
, skb
->data
, skb
->len
);
59 static int qcom_smd_qrtr_probe(struct rpmsg_device
*rpdev
)
61 struct qrtr_smd_dev
*qdev
;
64 qdev
= devm_kzalloc(&rpdev
->dev
, sizeof(*qdev
), GFP_KERNEL
);
68 qdev
->channel
= rpdev
->ept
;
69 qdev
->dev
= &rpdev
->dev
;
70 qdev
->ep
.xmit
= qcom_smd_qrtr_send
;
72 rc
= qrtr_endpoint_register(&qdev
->ep
, QRTR_EP_NID_AUTO
);
76 dev_set_drvdata(&rpdev
->dev
, qdev
);
78 dev_dbg(&rpdev
->dev
, "Qualcomm SMD QRTR driver probed\n");
83 static void qcom_smd_qrtr_remove(struct rpmsg_device
*rpdev
)
85 struct qrtr_smd_dev
*qdev
= dev_get_drvdata(&rpdev
->dev
);
87 qrtr_endpoint_unregister(&qdev
->ep
);
89 dev_set_drvdata(&rpdev
->dev
, NULL
);
92 static const struct rpmsg_device_id qcom_smd_qrtr_smd_match
[] = {
97 static struct rpmsg_driver qcom_smd_qrtr_driver
= {
98 .probe
= qcom_smd_qrtr_probe
,
99 .remove
= qcom_smd_qrtr_remove
,
100 .callback
= qcom_smd_qrtr_callback
,
101 .id_table
= qcom_smd_qrtr_smd_match
,
103 .name
= "qcom_smd_qrtr",
107 module_rpmsg_driver(qcom_smd_qrtr_driver
);
109 MODULE_ALIAS("rpmsg:IPCRTR");
110 MODULE_DESCRIPTION("Qualcomm IPC-Router SMD interface driver");
111 MODULE_LICENSE("GPL v2");