smd.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  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. #include <linux/module.h>
  15. #include <linux/skbuff.h>
  16. #include <linux/soc/qcom/smd.h>
  17. #include "qrtr.h"
  18. struct qrtr_smd_dev {
  19. struct qrtr_endpoint ep;
  20. struct qcom_smd_channel *channel;
  21. struct device *dev;
  22. };
  23. /* from smd to qrtr */
  24. static int qcom_smd_qrtr_callback(struct qcom_smd_channel *channel,
  25. const void *data, size_t len)
  26. {
  27. struct qrtr_smd_dev *qdev = qcom_smd_get_drvdata(channel);
  28. int rc;
  29. if (!qdev)
  30. return -EAGAIN;
  31. rc = qrtr_endpoint_post(&qdev->ep, data, len);
  32. if (rc == -EINVAL) {
  33. dev_err(qdev->dev, "invalid ipcrouter packet\n");
  34. /* return 0 to let smd drop the packet */
  35. rc = 0;
  36. }
  37. return rc;
  38. }
  39. /* from qrtr to smd */
  40. static int qcom_smd_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb)
  41. {
  42. struct qrtr_smd_dev *qdev = container_of(ep, struct qrtr_smd_dev, ep);
  43. int rc;
  44. rc = skb_linearize(skb);
  45. if (rc)
  46. goto out;
  47. rc = qcom_smd_send(qdev->channel, skb->data, skb->len);
  48. out:
  49. if (rc)
  50. kfree_skb(skb);
  51. else
  52. consume_skb(skb);
  53. return rc;
  54. }
  55. static int qcom_smd_qrtr_probe(struct qcom_smd_device *sdev)
  56. {
  57. struct qrtr_smd_dev *qdev;
  58. int rc;
  59. qdev = devm_kzalloc(&sdev->dev, sizeof(*qdev), GFP_KERNEL);
  60. if (!qdev)
  61. return -ENOMEM;
  62. qdev->channel = sdev->channel;
  63. qdev->dev = &sdev->dev;
  64. qdev->ep.xmit = qcom_smd_qrtr_send;
  65. rc = qrtr_endpoint_register(&qdev->ep, QRTR_EP_NID_AUTO);
  66. if (rc)
  67. return rc;
  68. qcom_smd_set_drvdata(sdev->channel, qdev);
  69. dev_set_drvdata(&sdev->dev, qdev);
  70. dev_dbg(&sdev->dev, "Qualcomm SMD QRTR driver probed\n");
  71. return 0;
  72. }
  73. static void qcom_smd_qrtr_remove(struct qcom_smd_device *sdev)
  74. {
  75. struct qrtr_smd_dev *qdev = dev_get_drvdata(&sdev->dev);
  76. qrtr_endpoint_unregister(&qdev->ep);
  77. dev_set_drvdata(&sdev->dev, NULL);
  78. }
  79. static const struct qcom_smd_id qcom_smd_qrtr_smd_match[] = {
  80. { "IPCRTR" },
  81. {}
  82. };
  83. static struct qcom_smd_driver qcom_smd_qrtr_driver = {
  84. .probe = qcom_smd_qrtr_probe,
  85. .remove = qcom_smd_qrtr_remove,
  86. .callback = qcom_smd_qrtr_callback,
  87. .smd_match_table = qcom_smd_qrtr_smd_match,
  88. .driver = {
  89. .name = "qcom_smd_qrtr",
  90. .owner = THIS_MODULE,
  91. },
  92. };
  93. module_qcom_smd_driver(qcom_smd_qrtr_driver);
  94. MODULE_ALIAS("rpmsg:IPCRTR");
  95. MODULE_DESCRIPTION("Qualcomm IPC-Router SMD interface driver");
  96. MODULE_LICENSE("GPL v2");