Advertisement
Guest User

Untitled

a guest
Mar 25th, 2021
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 24.28 KB | None | 0 0
  1. Date: Mon, 19 Nov 2018 11:00:22 -0700
  2. Subject: [PATCH] Added sysfs files to enable/disable logging dynamically for
  3.  RPMSG related functionality.  Disabled by default for performance reasons.
  4.  
  5. ---
  6. arch/arm/mach-imx/mu.c           |  46 ++++++++++++--
  7.  drivers/rpmsg/imx_rpmsg.c        |  79 ++++++++++++++++++------
  8.  drivers/rpmsg/imx_rpmsg_tty.c    |  47 ++++++++++++---
  9.  drivers/rpmsg/virtio_rpmsg_bus.c | 127 +++++++++++++++++++++++++++++----------
  10.  4 files changed, 236 insertions(+), 63 deletions(-)
  11.  
  12. diff --git a/arch/arm/mach-imx/mu.c b/arch/arm/mach-imx/mu.c
  13. index 7088d07..394ffef 100644
  14. --- a/arch/arm/mach-imx/mu.c
  15. +++ b/arch/arm/mach-imx/mu.c
  16. @@ -65,6 +65,7 @@ struct irq_domain *domain;
  17.  static bool m4_in_stop;
  18.  static struct clk *clk;
  19.  static DEFINE_SPINLOCK(mu_lock);
  20. +static bool logging_enabled = true;
  21.  
  22.  void imx_mu_set_m4_run_mode(void)
  23.  {
  24. @@ -165,7 +166,7 @@ static int imx_mu_send_message(unsigned int index, unsigned int data)
  25.             break;
  26.         }
  27.     }
  28. -   if (te_flag == 0)
  29. +   if (te_flag == 0 && logging_enabled)
  30.         pr_info("BUG: TEn is not changed immediately"
  31.                 "when ATRn is filled up.\n");
  32.  
  33. @@ -184,7 +185,9 @@ static void mu_work_handler(struct work_struct *work)
  34.     message = m4_message[out_idx % MAX_NUM];
  35.     spin_unlock_irqrestore(&mu_lock, flags);
  36.  
  37. -   pr_debug("receive M4 message 0x%x\n", message);
  38. +        if (logging_enabled) {
  39. +           pr_debug("receive M4 message 0x%x\n", message);
  40. +        }
  41.  
  42.     switch (message) {
  43.     case MU_LPM_M4_RUN_MODE:
  44. @@ -342,8 +345,10 @@ int imx_mu_rpmsg_reset(const struct device *dev)
  45.          /* Monitor bit7(BRS) of MU_ASR to know when reset sequence has ended */
  46.          do {
  47.                  val = readl_relaxed(mu_base + MU_ASR);
  48. -                dev_dbg(dev, "Waiting for ASR bit7 to go low. ASR: 0x%x\n",
  49. -                        val);
  50. +                if (logging_enabled) {
  51. +                        dev_dbg(dev, "Waiting for ASR bit7 to go low. ASR: 0x%x\n",
  52. +                                val);
  53. +                }
  54.                  val &= BIT(7);
  55.          } while (val);
  56.  
  57. @@ -388,7 +393,9 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
  58.                  return -EINVAL;
  59.          }
  60.  
  61. -        dev_info(dev, "MU Reset\n");
  62. +        if (logging_enabled) {
  63. +                dev_info(dev, "MU Reset\n");
  64. +        }
  65.          imx_mu_rpmsg_reset(dev);
  66.          return count;
  67.  }
  68. @@ -464,11 +471,24 @@ static int imx_mu_probe(struct platform_device *pdev)
  69.         writel_relaxed(readl_relaxed(mu_base + MU_ACR) |
  70.             BIT(26) | BIT(27), mu_base + MU_ACR);
  71.  
  72. -   pr_info("MU is ready for cross core communication!\n");
  73. +        if (logging_enabled) {
  74. +           pr_info("MU is ready for cross core communication!\n");
  75. +        }
  76.  
  77.     return 0;
  78.  }
  79.  
  80. +static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
  81. +{
  82. +        return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
  83. +}
  84. +
  85. +static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
  86. +{
  87. +         logging_enabled = logging_enabled ? false : true;
  88. +         return count;
  89. +}
  90. +
  91.  static const struct of_device_id imx_mu_ids[] = {
  92.     { .compatible = "fsl,imx6sx-mu" },
  93.     { .compatible = "fsl,imx7d-mu" },
  94. @@ -476,6 +496,19 @@ static const struct of_device_id imx_mu_ids[] = {
  95.     { }
  96.  };
  97.  
  98. +static DEVICE_ATTR(log_enabled, 0644, show_log_level, toggle_log_level);
  99. +static struct attribute* dev_attrs[] = {
  100. +  &dev_attr_log_enabled.attr,
  101. +  NULL,
  102. +};
  103. +static struct attribute_group dev_attr_group = {
  104. +  .attrs = dev_attrs,
  105. +};
  106. +static const struct attribute_group* dev_attr_groups[] = {
  107. +  &dev_attr_group,
  108. +  NULL,
  109. +};
  110. +
  111.  #ifdef CONFIG_PM_SLEEP
  112.  static int mu_suspend(struct device *dev)
  113.  {
  114. @@ -503,6 +536,7 @@ static struct platform_driver imx_mu_driver = {
  115.         .owner  = THIS_MODULE,
  116.         .pm = &mu_pm_ops,
  117.         .of_match_table = imx_mu_ids,
  118. +                .groups = dev_attr_groups,
  119.     },
  120.     .probe = imx_mu_probe,
  121.  };
  122. diff --git a/drivers/rpmsg/imx_rpmsg.c b/drivers/rpmsg/imx_rpmsg.c
  123. index d63e353..2b9b81b 100644
  124. --- a/drivers/rpmsg/imx_rpmsg.c
  125. +++ b/drivers/rpmsg/imx_rpmsg.c
  126. @@ -105,6 +105,8 @@ struct imx_rpmsg_vq_info {
  127.     struct imx_rpmsg_vproc *rpdev;
  128.  };
  129.  
  130. +static bool logging_enabled = true;
  131. +
  132.  static u64 imx_rpmsg_get_features(struct virtio_device *vdev)
  133.  {
  134.     /* VIRTIO_RPMSG_F_NS has been made private */
  135. @@ -141,11 +143,15 @@ static int imx_mu_rpmsg_callback(struct notifier_block *this,
  136.  
  137.     virdev = container_of(this, struct imx_virdev, nb);
  138.  
  139. -   pr_debug("%s mu_msg: 0x%x\n", __func__, mu_msg);
  140. +   if (logging_enabled) {
  141. +           dev_info(&virdev->vdev.dev, "%s mu_msg: 0x%x\n", __func__, mu_msg);
  142. +   }
  143.     /* ignore vq indices which are clearly not for us */
  144.     mu_msg = mu_msg >> 16;
  145.     if (mu_msg < virdev->base_vq_id || mu_msg > virdev->base_vq_id + 1) {
  146. -       pr_debug("mu_msg: 0x%x is invalid\n", mu_msg);
  147. +           if (logging_enabled) {
  148. +               dev_info(&virdev->vdev.dev, "mu_msg: 0x%x is invalid\n", mu_msg);
  149. +       }
  150.         return NOTIFY_DONE;
  151.     }
  152.  
  153. @@ -216,14 +222,16 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev,
  154.  
  155.     memset(rpvq->addr, 0, RPMSG_RING_SIZE);
  156.  
  157. -   pr_debug("vring%d: phys 0x%x, virt 0x%p\n", index, virdev->vring[index],
  158. +        if (logging_enabled) {
  159. +           dev_info(&vdev->dev, "vring%d: phys 0x%x, virt 0x%p\n", index, virdev->vring[index],
  160.                     rpvq->addr);
  161. +        }
  162.  
  163.     vq = vring_new_virtqueue(index, RPMSG_NUM_BUFS / 2, RPMSG_VRING_ALIGN,
  164.             vdev, true, rpvq->addr, imx_rpmsg_notify, callback,
  165.             name);
  166.     if (!vq) {
  167. -       pr_err("vring_new_virtqueue failed\n");
  168. +       dev_err(&vdev->dev, "vring_new_virtqueue failed\n");
  169.         err = -ENOMEM;
  170.         goto unmap_vring;
  171.     }
  172. @@ -301,7 +309,9 @@ static int imx_rpmsg_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
  173.  
  174.  static void imx_rpmsg_reset(struct virtio_device *vdev)
  175.  {
  176. -   dev_dbg(&vdev->dev, "reset !\n");
  177. +        if (logging_enabled) {
  178. +           dev_dbg(&vdev->dev, "reset !\n");
  179. +        }
  180.  }
  181.  
  182.  static u8 imx_rpmsg_get_status(struct virtio_device *vdev)
  183. @@ -311,7 +321,9 @@ static u8 imx_rpmsg_get_status(struct virtio_device *vdev)
  184.  
  185.  static void imx_rpmsg_set_status(struct virtio_device *vdev, u8 status)
  186.  {
  187. -   dev_dbg(&vdev->dev, "%s new status: %d\n", __func__, status);
  188. +        if (logging_enabled) {
  189. +           dev_dbg(&vdev->dev, "%s new status: %d\n", __func__, status);
  190. +        }
  191.  }
  192.  
  193.  static void imx_rpmsg_vproc_release(struct device *dev)
  194. @@ -440,8 +452,8 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
  195.  
  196.     /* Initialize the mu unit used by rpmsg */
  197.     np_mu = of_find_compatible_node(NULL, NULL, "fsl,imx6sx-mu");
  198. -   if (!np_mu)
  199. -       pr_info("Cannot find MU-RPMSG entry in device tree\n");
  200. +   if (!np_mu && logging_enabled)
  201. +       dev_info(dev, "Cannot find MU-RPMSG entry in device tree\n");
  202.     mu_base = of_iomap(np_mu, 0);
  203.     WARN_ON(!mu_base);
  204.  
  205. @@ -454,7 +466,7 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
  206.               IRQF_EARLY_RESUME | IRQF_SHARED,
  207.               "imx-mu-rpmsg", dev);
  208.     if (ret) {
  209. -       pr_err("%s: register interrupt %d failed, rc %d\n",
  210. +       dev_err(dev, "%s: register interrupt %d failed, rc %d\n",
  211.             __func__, irq, ret);
  212.         return ret;
  213.     }
  214. @@ -462,12 +474,12 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
  215.     if (variant == IMX7D) {
  216.         clk = of_clk_get(np_mu, 0);
  217.         if (IS_ERR(clk)) {
  218. -           pr_err("mu clock source missing or invalid\n");
  219. +           dev_err(dev, "mu clock source missing or invalid\n");
  220.             return PTR_ERR(clk);
  221.         }
  222.         ret = clk_prepare_enable(clk);
  223.         if (ret) {
  224. -           pr_err("unable to enable mu clock\n");
  225. +           dev_err(dev, "unable to enable mu clock\n");
  226.             return ret;
  227.         }
  228.     }
  229. @@ -485,7 +497,9 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
  230.     }
  231.     BLOCKING_INIT_NOTIFIER_HEAD(&(mu_rpmsg_box.notifier));
  232.  
  233. -   pr_info("MU is ready for cross core communication!\n");
  234. +   if (logging_enabled) {
  235. +           dev_info(dev, "MU is ready for cross core communication!\n");
  236. +        }
  237.  
  238.     for (i = 0; i < ARRAY_SIZE(imx_rpmsg_vprocs); i++) {
  239.         struct imx_rpmsg_vproc *rpdev = &imx_rpmsg_vprocs[i];
  240. @@ -495,7 +509,7 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
  241.         if (ret)
  242.             rpdev->vdev_nums = 1;
  243.         if (rpdev->vdev_nums > MAX_VDEV_NUMS) {
  244. -           pr_err("vdev-nums exceed the max %d\n", MAX_VDEV_NUMS);
  245. +           dev_err(dev, "vdev-nums exceed the max %d\n", MAX_VDEV_NUMS);
  246.             return -EINVAL;
  247.         }
  248.  
  249. @@ -503,7 +517,7 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
  250.             ret = set_vring_phy_buf(pdev, rpdev,
  251.                         rpdev->vdev_nums);
  252.             if (ret) {
  253. -               pr_err("No vring buffer.\n");
  254. +               dev_err(dev, "No vring buffer.\n");
  255.                 return -ENOMEM;
  256.             }
  257.         } else {
  258. @@ -512,10 +526,12 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
  259.         }
  260.  
  261.         for (j = 0; j < rpdev->vdev_nums; j++) {
  262. -           pr_debug("%s rpdev%d vdev%d: vring0 0x%x, vring1 0x%x\n",
  263. -                __func__, i, rpdev->vdev_nums,
  264. -                rpdev->ivdev[j].vring[0],
  265. -                rpdev->ivdev[j].vring[1]);
  266. +                        if (logging_enabled) {
  267. +                    dev_dbg(dev, "%s rpdev%d vdev%d: vring0 0x%x, vring1 0x%x\n",
  268. +                        __func__, i, rpdev->vdev_nums,
  269. +                        rpdev->ivdev[j].vring[0],
  270. +                        rpdev->ivdev[j].vring[1]);
  271. +                        }
  272.             rpdev->ivdev[j].vdev.id.device = VIRTIO_ID_RPMSG;
  273.             rpdev->ivdev[j].vdev.config = &imx_rpmsg_config_ops;
  274.             rpdev->ivdev[j].vdev.dev.parent = &pdev->dev;
  275. @@ -524,7 +540,7 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
  276.  
  277.             ret = register_virtio_device(&rpdev->ivdev[j].vdev);
  278.             if (ret) {
  279. -               pr_err("%s failed to register rpdev: %d\n",
  280. +               dev_err(dev, "%s failed to register rpdev: %d\n",
  281.                         __func__, ret);
  282.                 return ret;
  283.             }
  284. @@ -535,11 +551,36 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
  285.     return ret;
  286.  }
  287.  
  288. +static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
  289. +{
  290. +  return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
  291. +}
  292. +
  293. +static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
  294. +{
  295. +  logging_enabled = logging_enabled ? false : true;
  296. +  return count;
  297. +}
  298. +
  299. +static DEVICE_ATTR(log_enabled, 0644, show_log_level, toggle_log_level);
  300. +static struct attribute *dev_attrs[] = {
  301. +  &dev_attr_log_enabled.attr,
  302. +  NULL,
  303. +};
  304. +static struct attribute_group dev_attr_group = {
  305. +  .attrs = dev_attrs,
  306. +};
  307. +static const struct attribute_group *dev_attr_groups[] = {
  308. +  &dev_attr_group,
  309. +  NULL,
  310. +};
  311. +
  312.  static struct platform_driver imx_rpmsg_driver = {
  313.     .driver = {
  314.            .owner = THIS_MODULE,
  315.            .name = "imx-rpmsg",
  316.            .of_match_table = imx_rpmsg_dt_ids,
  317. +          .groups = dev_attr_groups,
  318.            },
  319.     .probe = imx_rpmsg_probe,
  320.  };
  321. diff --git a/drivers/rpmsg/imx_rpmsg_tty.c b/drivers/rpmsg/imx_rpmsg_tty.c
  322. index 42b245d..42bbf99 100644
  323. --- a/drivers/rpmsg/imx_rpmsg_tty.c
  324. +++ b/drivers/rpmsg/imx_rpmsg_tty.c
  325. @@ -38,6 +38,19 @@ static struct rpmsgtty_port rpmsg_tty_port;
  326.  #define RPMSG_MAX_SIZE     256
  327.  #define MSG        "hello world!"
  328.  
  329. +static bool logging_enabled = true;
  330. +
  331. +static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
  332. +{
  333. +        return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
  334. +}
  335. +
  336. +static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
  337. +{
  338. +         logging_enabled = logging_enabled ? false : true;
  339. +         return count;
  340. +}
  341. +
  342.  static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len,
  343.                         void *priv, u32 src)
  344.  {
  345. @@ -49,10 +62,12 @@ static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len,
  346.     if (len == 0)
  347.         return 0;
  348.  
  349. -   dev_dbg(&rpdev->dev, "msg(<- src 0x%x) len %d\n", src, len);
  350. +        if (logging_enabled) {
  351. +           dev_dbg(&rpdev->dev, "msg(<- src 0x%x) len %d\n", src, len);
  352.  
  353. -   print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1,
  354. -           data, len,  true);
  355. +           print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1,
  356. +                   data, len,  true);
  357. +        }
  358.  
  359.     spin_lock_bh(&cport->rx_lock);
  360.     space = tty_prepare_flip_string(&cport->port, &cbuf, len);
  361. @@ -143,8 +158,10 @@ static int rpmsg_tty_probe(struct rpmsg_device *rpdev)
  362.     int err;
  363.     struct rpmsgtty_port *cport = &rpmsg_tty_port;
  364.  
  365. -   dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
  366. -           rpdev->src, rpdev->dst);
  367. +        if (logging_enabled) {
  368. +           dev_info(&rpdev->dev, "new channel: 0x%x -> 0x%x!\n",
  369. +                   rpdev->src, rpdev->dst);
  370. +        }
  371.  
  372.     /*
  373.      * send a message to our remote processor, and tell remote
  374. @@ -178,7 +195,7 @@ static int rpmsg_tty_probe(struct rpmsg_device *rpdev)
  375.     if (err < 0) {
  376.         pr_err("Couldn't install rpmsg tty driver: err %d\n", err);
  377.         goto error;
  378. -   } else
  379. +   } else if (logging_enabled)
  380.         pr_info("Install rpmsg tty driver!\n");
  381.     cport->rpdev = rpdev;
  382.  
  383. @@ -197,7 +214,9 @@ static void rpmsg_tty_remove(struct rpmsg_device *rpdev)
  384.  {
  385.     struct rpmsgtty_port *cport = &rpmsg_tty_port;
  386.  
  387. -   dev_info(&rpdev->dev, "rpmsg tty driver is removed\n");
  388. +        if (logging_enabled) {
  389. +           dev_info(&rpdev->dev, "rpmsg tty driver is removed\n");
  390. +        }
  391.  
  392.     tty_unregister_driver(rpmsgtty_driver);
  393.     put_tty_driver(rpmsgtty_driver);
  394. @@ -205,6 +224,19 @@ static void rpmsg_tty_remove(struct rpmsg_device *rpdev)
  395.     rpmsgtty_driver = NULL;
  396.  }
  397.  
  398. +static DEVICE_ATTR(logging_enabled, 0644, show_log_level, toggle_log_level);
  399. +static struct attribute* dev_attrs[] = {
  400. +  &dev_attr_logging_enabled.attr,
  401. +  NULL,
  402. +};
  403. +static struct attribute_group dev_attr_group = {
  404. +  .attrs = dev_attrs,
  405. +};
  406. +static const struct attribute_group* dev_attr_groups[] = {
  407. +  &dev_attr_group,
  408. +  NULL,
  409. +};
  410. +
  411.  static struct rpmsg_device_id rpmsg_driver_tty_id_table[] = {
  412.     { .name = "rpmsg-virtual-tty-channel" },
  413.     { .name = "rpmsg-openamp-demo-channel" },
  414. @@ -215,6 +247,7 @@ MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_tty_id_table);
  415.  static struct rpmsg_driver rpmsg_tty_driver = {
  416.     .drv.name   = KBUILD_MODNAME,
  417.     .drv.owner  = THIS_MODULE,
  418. +        .drv.groups     = dev_attr_groups,
  419.     .id_table   = rpmsg_driver_tty_id_table,
  420.     .probe      = rpmsg_tty_probe,
  421.     .callback   = rpmsg_tty_cb,
  422. diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
  423. index 15a8fa7..c804e82 100644
  424. --- a/drivers/rpmsg/virtio_rpmsg_bus.c
  425. +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
  426. @@ -192,6 +192,19 @@ static const struct rpmsg_endpoint_ops virtio_endpoint_ops = {
  427.     .trysend_offchannel = virtio_rpmsg_trysend_offchannel,
  428.  };
  429.  
  430. +static bool logging_enabled = true;
  431. +
  432. +static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
  433. +{
  434. +        return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
  435. +}
  436. +
  437. +static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
  438. +{
  439. +         logging_enabled = logging_enabled ? false : true;
  440. +         return count;
  441. +}
  442. +
  443.  /**
  444.   * __ept_release() - deallocate an rpmsg endpoint
  445.   * @kref: the ept's reference count
  446. @@ -563,7 +576,9 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
  447.  
  448.     /* bcasting isn't allowed */
  449.     if (src == RPMSG_ADDR_ANY || dst == RPMSG_ADDR_ANY) {
  450. -       dev_err(dev, "invalid addr (src 0x%x, dst 0x%x)\n", src, dst);
  451. +                if (logging_enabled) {
  452. +               dev_err(dev, "invalid addr (src 0x%x, dst 0x%x)\n", src, dst);
  453. +                }
  454.         return -EINVAL;
  455.     }
  456.  
  457. @@ -577,7 +592,9 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
  458.      * variable-length buffer sizes.
  459.      */
  460.     if (len > RPMSG_BUF_SIZE - sizeof(struct rpmsg_hdr)) {
  461. -       dev_err(dev, "message is too big (%d)\n", len);
  462. +                if (logging_enabled) {
  463. +               dev_err(dev, "message is too big (%d)\n", len);
  464. +                }
  465.         return -EMSGSIZE;
  466.     }
  467.  
  468. @@ -606,7 +623,9 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
  469.  
  470.         /* timeout ? */
  471.         if (!err) {
  472. -           dev_err(dev, "timeout waiting for a tx buffer\n");
  473. +                        if (logging_enabled) {
  474. +                   dev_err(dev, "timeout waiting for a tx buffer\n");
  475. +                        }
  476.             return -ERESTARTSYS;
  477.         }
  478.     }
  479. @@ -618,16 +637,20 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
  480.     msg->reserved = 0;
  481.     memcpy(msg->data, data, len);
  482.  
  483. -   dev_dbg(dev, "TX From 0x%x, To 0x%x, Len %d, Flags %d, Reserved %d\n",
  484. -       msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
  485. +        if (logging_enabled) {
  486. +           dev_dbg(dev, "TX From 0x%x, To 0x%x, Len %d, Flags %d, Reserved %d\n",
  487. +               msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
  488.  #if defined(CONFIG_DYNAMIC_DEBUG)
  489. -   dynamic_hex_dump("rpmsg_virtio TX: ", DUMP_PREFIX_NONE, 16, 1,
  490. -            msg, sizeof(*msg) + msg->len, true);
  491. +           dynamic_hex_dump("rpmsg_virtio TX: ", DUMP_PREFIX_NONE, 16, 1,
  492. +               msg, sizeof(*msg) + msg->len, true);
  493.  #endif
  494. +        }
  495.  
  496.     err = sg_init_one_full(&sg, msg, sizeof(*msg) + len);
  497.     if (err) {
  498. -       dev_err(dev, "virtqueue_add_outbuf sg_init failed: %d\n", err);
  499. +                if (logging_enabled) {
  500. +               dev_err(dev, "virtqueue_add_outbuf sg_init failed: %d\n", err);
  501. +                }
  502.         return err;
  503.     }
  504.  
  505. @@ -641,7 +664,9 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
  506.          * (memory won't leak, but rpmsg won't use it again for TX).
  507.          * this will wait for a buffer management overhaul.
  508.          */
  509. -       dev_err(dev, "virtqueue_add_outbuf failed: %d\n", err);
  510. +                if (logging_enabled) {
  511. +               dev_err(dev, "virtqueue_add_outbuf failed: %d\n", err);
  512. +                }
  513.         goto out;
  514.     }
  515.  
  516. @@ -710,12 +735,14 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
  517.     struct scatterlist sg;
  518.     int err;
  519.  
  520. -   dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n",
  521. -       msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
  522. +        if (logging_enabled) {
  523. +            dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n",
  524. +                msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
  525.  #if defined(CONFIG_DYNAMIC_DEBUG)
  526. -   dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1,
  527. +            dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1,
  528.              msg, sizeof(*msg) + msg->len, true);
  529.  #endif
  530. +        }
  531.  
  532.     /*
  533.      * We currently use fixed-sized buffers, so trivially sanitize
  534. @@ -723,7 +750,9 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
  535.      */
  536.     if (len > RPMSG_BUF_SIZE ||
  537.         msg->len > (len - sizeof(struct rpmsg_hdr))) {
  538. -       dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len);
  539. +                if (logging_enabled) {
  540. +               dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len);
  541. +                }
  542.         return -EINVAL;
  543.     }
  544.  
  545. @@ -750,20 +779,24 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
  546.  
  547.         /* farewell, ept, we don't need you anymore */
  548.         kref_put(&ept->refcount, __ept_release);
  549. -   } else
  550. +   } else if (logging_enabled)
  551.         dev_warn(dev, "msg received with no recipient\n");
  552.  
  553.     /* publish the real size of the buffer */
  554.     err = sg_init_one_full(&sg, msg, RPMSG_BUF_SIZE);
  555.     if (err) {
  556. -       dev_err(dev, "rpmsg_recv_done sg_init failed: %d\n", err);
  557. +                if (logging_enabled) {
  558. +               dev_err(dev, "rpmsg_recv_done sg_init failed: %d\n", err);
  559. +                }
  560.         return err;
  561.     }
  562.  
  563.     /* add the buffer back to the remote processor's virtqueue */
  564.     err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL);
  565.     if (err < 0) {
  566. -       dev_err(dev, "failed to add a virtqueue buffer: %d\n", err);
  567. +                if (logging_enabled) {
  568. +               dev_err(dev, "failed to add a virtqueue buffer: %d\n", err);
  569. +                }
  570.         return err;
  571.     }
  572.  
  573. @@ -781,7 +814,9 @@ static void rpmsg_recv_done(struct virtqueue *rvq)
  574.  
  575.     msg = virtqueue_get_buf(rvq, &len);
  576.     if (!msg) {
  577. -       dev_err(dev, "uhm, incoming signal, but no used buffer ?\n");
  578. +                if (logging_enabled) {
  579. +               dev_err(dev, "uhm, incoming signal, but no used buffer ?\n");
  580. +                }
  581.         return;
  582.     }
  583.  
  584. @@ -795,7 +830,9 @@ static void rpmsg_recv_done(struct virtqueue *rvq)
  585.         msg = virtqueue_get_buf(rvq, &len);
  586.     }
  587.  
  588. -   dev_dbg(dev, "Received %u messages\n", msgs_received);
  589. +        if (logging_enabled) {
  590. +           dev_dbg(dev, "Received %u messages\n", msgs_received);
  591. +        }
  592.  
  593.     /* tell the remote processor we added another available rx buffer */
  594.     if (msgs_received)
  595. @@ -813,7 +850,9 @@ static void rpmsg_xmit_done(struct virtqueue *svq)
  596.  {
  597.     struct virtproc_info *vrp = svq->vdev->priv;
  598.  
  599. -   dev_dbg(&svq->vdev->dev, "%s\n", __func__);
  600. +        if (logging_enabled) {
  601. +           dev_dbg(&svq->vdev->dev, "%s\n", __func__);
  602. +        }
  603.  
  604.     /* wake up potential senders that are waiting for a tx buffer */
  605.     wake_up_interruptible(&vrp->sendq);
  606. @@ -831,12 +870,16 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
  607.     int ret;
  608.  
  609.  #if defined(CONFIG_DYNAMIC_DEBUG)
  610. -   dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1,
  611. -            data, len, true);
  612. +        if (logging_enabled) {
  613. +           dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1,
  614. +                    data, len, true);
  615. +        }
  616.  #endif
  617.  
  618.     if (len != sizeof(*msg)) {
  619. -       dev_err(dev, "malformed ns msg (%d)\n", len);
  620. +                if (logging_enabled) {
  621. +               dev_err(dev, "malformed ns msg (%d)\n", len);
  622. +                }
  623.         return -EINVAL;
  624.     }
  625.  
  626. @@ -847,16 +890,20 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
  627.      * in somehow.
  628.      */
  629.     if (rpdev) {
  630. -       dev_err(dev, "anomaly: ns ept has an rpdev handle\n");
  631. +                if (logging_enabled) {
  632. +               dev_err(dev, "anomaly: ns ept has an rpdev handle\n");
  633. +                }
  634.         return -EINVAL;
  635.     }
  636.  
  637.     /* don't trust the remote processor for null terminating the name */
  638.     msg->name[RPMSG_NAME_SIZE - 1] = '\0';
  639.  
  640. -   dev_info(dev, "%sing channel %s addr 0x%x\n",
  641. -        msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat",
  642. -        msg->name, msg->addr);
  643. +        if (logging_enabled) {
  644. +           dev_info(dev, "%sing channel %s addr 0x%x\n",
  645. +                msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat",
  646. +                msg->name, msg->addr);
  647. +        }
  648.  
  649.     strncpy(chinfo.name, msg->name, sizeof(chinfo.name));
  650.     chinfo.src = RPMSG_ADDR_ANY;
  651. @@ -864,11 +911,11 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
  652.  
  653.     if (msg->flags & RPMSG_NS_DESTROY) {
  654.         ret = rpmsg_unregister_device(&vrp->vdev->dev, &chinfo);
  655. -       if (ret)
  656. +       if (ret && logging_enabled)
  657.             dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret);
  658.     } else {
  659.         newch = rpmsg_create_channel(vrp, &chinfo);
  660. -       if (!newch)
  661. +       if (!newch && logging_enabled)
  662.             dev_err(dev, "rpmsg_create_channel failed\n");
  663.     }
  664.  
  665. @@ -926,8 +973,10 @@ static int rpmsg_probe(struct virtio_device *vdev)
  666.         goto vqs_del;
  667.     }
  668.  
  669. -   dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n",
  670. -       bufs_va, &vrp->bufs_dma);
  671. +        if (logging_enabled) {
  672. +           dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n",
  673. +               bufs_va, &vrp->bufs_dma);
  674. +        }
  675.  
  676.     /* half of the buffers is dedicated for RX */
  677.     vrp->rbufs = bufs_va;
  678. @@ -985,7 +1034,9 @@ static int rpmsg_probe(struct virtio_device *vdev)
  679.     if (notify)
  680.         virtqueue_notify(vrp->rvq);
  681.  
  682. -   dev_info(&vdev->dev, "rpmsg host is online\n");
  683. +        if (logging_enabled) {
  684. +           dev_info(&vdev->dev, "rpmsg host is online\n");
  685. +        }
  686.  
  687.     return 0;
  688.  
  689. @@ -1040,11 +1091,25 @@ static unsigned int features[] = {
  690.     VIRTIO_RPMSG_F_NS,
  691.  };
  692.  
  693. +static DEVICE_ATTR(logging_enabled, 0644, show_log_level, toggle_log_level);
  694. +static struct attribute* dev_attrs[] = {
  695. +  &dev_attr_logging_enabled.attr,
  696. +  NULL,
  697. +};
  698. +static struct attribute_group dev_attr_group = {
  699. +  .attrs = dev_attrs,
  700. +};
  701. +static const struct attribute_group* dev_attr_groups[] = {
  702. +  &dev_attr_group,
  703. +  NULL,
  704. +};
  705. +
  706.  static struct virtio_driver virtio_ipc_driver = {
  707.     .feature_table  = features,
  708.     .feature_table_size = ARRAY_SIZE(features),
  709.     .driver.name    = KBUILD_MODNAME,
  710.     .driver.owner   = THIS_MODULE,
  711. +        .driver.groups  = dev_attr_groups,
  712.     .id_table   = id_table,
  713.     .probe      = rpmsg_probe,
  714.     .remove     = rpmsg_remove,
  715. --
  716. 2.7.4
  717.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement