blob: ff0112bc247f28ea25787741fa65d440b9ff6256 [file] [log] [blame]
Courtney Cavinbdabad32016-05-06 07:09:08 -07001/*
2 * Copyright (c) 2015, Sony Mobile Communications Inc.
3 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 and
7 * only version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <linux/module.h>
16#include <linux/skbuff.h>
17#include <linux/soc/qcom/smd.h>
18
19#include "qrtr.h"
20
21struct qrtr_smd_dev {
22 struct qrtr_endpoint ep;
23 struct qcom_smd_channel *channel;
Bjorn Anderssonf79a9172016-05-13 14:36:11 -070024 struct device *dev;
Courtney Cavinbdabad32016-05-06 07:09:08 -070025};
26
27/* from smd to qrtr */
Bjorn Anderssonf79a9172016-05-13 14:36:11 -070028static int qcom_smd_qrtr_callback(struct qcom_smd_channel *channel,
Courtney Cavinbdabad32016-05-06 07:09:08 -070029 const void *data, size_t len)
30{
Bjorn Anderssonf79a9172016-05-13 14:36:11 -070031 struct qrtr_smd_dev *qdev = qcom_smd_get_drvdata(channel);
Courtney Cavinbdabad32016-05-06 07:09:08 -070032 int rc;
33
34 if (!qdev)
35 return -EAGAIN;
36
37 rc = qrtr_endpoint_post(&qdev->ep, data, len);
38 if (rc == -EINVAL) {
Bjorn Anderssonf79a9172016-05-13 14:36:11 -070039 dev_err(qdev->dev, "invalid ipcrouter packet\n");
Courtney Cavinbdabad32016-05-06 07:09:08 -070040 /* return 0 to let smd drop the packet */
41 rc = 0;
42 }
43
44 return rc;
45}
46
47/* from qrtr to smd */
48static int qcom_smd_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb)
49{
50 struct qrtr_smd_dev *qdev = container_of(ep, struct qrtr_smd_dev, ep);
51 int rc;
52
53 rc = skb_linearize(skb);
54 if (rc)
55 goto out;
56
57 rc = qcom_smd_send(qdev->channel, skb->data, skb->len);
58
59out:
60 if (rc)
61 kfree_skb(skb);
62 else
63 consume_skb(skb);
64 return rc;
65}
66
67static int qcom_smd_qrtr_probe(struct qcom_smd_device *sdev)
68{
69 struct qrtr_smd_dev *qdev;
70 int rc;
71
72 qdev = devm_kzalloc(&sdev->dev, sizeof(*qdev), GFP_KERNEL);
73 if (!qdev)
74 return -ENOMEM;
75
76 qdev->channel = sdev->channel;
Bjorn Anderssonf79a9172016-05-13 14:36:11 -070077 qdev->dev = &sdev->dev;
Courtney Cavinbdabad32016-05-06 07:09:08 -070078 qdev->ep.xmit = qcom_smd_qrtr_send;
79
80 rc = qrtr_endpoint_register(&qdev->ep, QRTR_EP_NID_AUTO);
81 if (rc)
82 return rc;
83
Bjorn Anderssonf79a9172016-05-13 14:36:11 -070084 qcom_smd_set_drvdata(sdev->channel, qdev);
Courtney Cavinbdabad32016-05-06 07:09:08 -070085 dev_set_drvdata(&sdev->dev, qdev);
86
87 dev_dbg(&sdev->dev, "Qualcomm SMD QRTR driver probed\n");
88
89 return 0;
90}
91
92static void qcom_smd_qrtr_remove(struct qcom_smd_device *sdev)
93{
94 struct qrtr_smd_dev *qdev = dev_get_drvdata(&sdev->dev);
95
96 qrtr_endpoint_unregister(&qdev->ep);
97
98 dev_set_drvdata(&sdev->dev, NULL);
99}
100
101static const struct qcom_smd_id qcom_smd_qrtr_smd_match[] = {
102 { "IPCRTR" },
103 {}
104};
105
106static struct qcom_smd_driver qcom_smd_qrtr_driver = {
107 .probe = qcom_smd_qrtr_probe,
108 .remove = qcom_smd_qrtr_remove,
109 .callback = qcom_smd_qrtr_callback,
110 .smd_match_table = qcom_smd_qrtr_smd_match,
111 .driver = {
112 .name = "qcom_smd_qrtr",
113 .owner = THIS_MODULE,
114 },
115};
116
117module_qcom_smd_driver(qcom_smd_qrtr_driver);
118
Ramon Fried9df8e112018-02-25 09:49:37 +0200119MODULE_ALIAS("rpmsg:IPCRTR");
Courtney Cavinbdabad32016-05-06 07:09:08 -0700120MODULE_DESCRIPTION("Qualcomm IPC-Router SMD interface driver");
121MODULE_LICENSE("GPL v2");