Skip to contentSkip to conversation

soc / drm: mediatek: cmdq: Remove timeout handler in helper function

PATCH Applied Chun-Kuang Hu 2 participants 5 messages Nov 2, 2020 – Nov 27, 2020

Subsystems (3)
lore
Share & tools
lore

Chun-Kuang Hu

author maintainer
#0 lore raw

PATCH v2 1/1 soc / drm: mediatek: cmdq: Remove timeout handler in helper function

For each client driver, its timeout handler need to dump hardware register or its state machine information, and their way to detect timeout are also different, so remove timeout handler in helper function and let client driver implement its own timeout handler.

---
v1 is one patch in series "Mediatek DRM driver detect CMDQ execution timeout by vblank IRQ", but according to Jassi's suggestion [1], send each patch in different series.

[2] is an example that different client has different way to calculate timeout. Some client driver care about each packet's execution time, but some client driver care about the total execution time for all packets.

[1]
https://patchwork.kernel.org/project/linux-mediatek/cover/[email protected]/
[2]
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

Changes in v2:
1. Rebase onto Linux 5.10-rc1

---
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c |  3 +-
 drivers/soc/mediatek/mtk-cmdq-helper.c  | 41 +------------------------
 include/linux/soc/mediatek/mtk-cmdq.h   | 10 +-----
 3 files changed, 3 insertions(+), 51 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1 -2
index ac038572164d..4be5d1fccf2e 100644
@@ -824,8 +824,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
 	mtk_crtc->cmdq_client =
 			cmdq_mbox_create(mtk_crtc->mmsys_dev,
-					 drm_crtc_index(&mtk_crtc->base),
-					 2000);
+					 drm_crtc_index(&mtk_crtc->base));
 	if (IS_ERR(mtk_crtc->cmdq_client)) {
 		dev_dbg(dev, "mtk_crtc %d failed to create mailbox client, writing register by CPU now\n",
 			drm_crtc_index(&mtk_crtc->base));
drivers/soc/mediatek/mtk-cmdq-helper.c +1 -40

77 lines not on this page · raw message

include/linux/soc/mediatek/mtk-cmdq.h +1 -9
index 960704d75994..8e9996610978 100644
@@ -11,7 +11,6 @@
 #include <linux/mailbox/mtk-cmdq-mailbox.h>
 #include <linux/timer.h>
 
-#define CMDQ_NO_TIMEOUT		0xffffffffu
 #define CMDQ_ADDR_HIGH(addr)	((u32)(((addr) >> 16) & GENMASK(31, 0)))
 #define CMDQ_ADDR_LOW(addr)	((u16)(addr) | BIT(1))
 
@@ -24,12 +23,8 @@ struct cmdq_client_reg {
 };
 
 struct cmdq_client {
-	spinlock_t lock;
-	u32 pkt_cnt;
 	struct mbox_client client;
 	struct mbox_chan *chan;
-	struct timer_list timer;
-	u32 timeout_ms; /* in unit of microsecond */
 };
 
 /**
@@ -51,13 +46,10 @@ int cmdq_dev_get_client_reg(struct device *dev,
  * cmdq_mbox_create() - create CMDQ mailbox client and channel
  * @dev:	device of CMDQ mailbox client
  * @index:	index of CMDQ mailbox channel
- * @timeout:	timeout of a pkt execution by GCE, in unit of microsecond, set
- *		CMDQ_NO_TIMEOUT if a timer is not used.
  *
  * Return: CMDQ mailbox client pointer
  */
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index,
-				     u32 timeout);
+struct cmdq_client *cmdq_mbox_create(struct device *dev, int index);
 
 /**
  * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#1 lore raw

Hi, Matthias:

I've provided the example for why of this patch. How do you think about this patch?

Regards,
Chun-Kuang.

Chun-Kuang Hu <[email protected]> 於 2020年11月2日 週一 上午8:04寫道:

Quoted 171 lines

For each client driver, its timeout handler need to dump hardware register or its state machine information, and their way to detect timeout are also different, so remove timeout handler in helper function and let client driver implement its own timeout handler.

---
v1 is one patch in series "Mediatek DRM driver detect CMDQ execution timeout by vblank IRQ", but according to Jassi's suggestion [1], send each patch in different series.

[2] is an example that different client has different way to calculate timeout. Some client driver care about each packet's execution time, but some client driver care about the total execution time for all packets.

[1]
https://patchwork.kernel.org/project/linux-mediatek/cover/[email protected]/
[2]
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

Changes in v2:
1. Rebase onto Linux 5.10-rc1

---
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c |  3 +-
 drivers/soc/mediatek/mtk-cmdq-helper.c  | 41 +------------------------
 include/linux/soc/mediatek/mtk-cmdq.h   | 10 +-----
 3 files changed, 3 insertions(+), 51 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1 -2
index ac038572164d..4be5d1fccf2e 100644
@@ -824,8 +824,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
        mtk_crtc->cmdq_client =
                        cmdq_mbox_create(mtk_crtc->mmsys_dev,
-                                        drm_crtc_index(&mtk_crtc->base),
-                                        2000);
+                                        drm_crtc_index(&mtk_crtc->base));
        if (IS_ERR(mtk_crtc->cmdq_client)) {
                dev_dbg(dev, "mtk_crtc %d failed to create mailbox client, writing register by CPU now\n",
                        drm_crtc_index(&mtk_crtc->base));
drivers/soc/mediatek/mtk-cmdq-helper.c +1 -40
index 505651b0d715..280d3bd9f675 100644
@@ -70,14 +70,7 @@ int cmdq_dev_get_client_reg(struct device *dev,
 }
 EXPORT_SYMBOL(cmdq_dev_get_client_reg);
 
-static void cmdq_client_timeout(struct timer_list *t)
-{
-       struct cmdq_client *client = from_timer(client, t, timer);
-
-       dev_err(client->client.dev, "cmdq timeout!\n");
-}
-
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, u32 timeout)
+struct cmdq_client *cmdq_mbox_create(struct device *dev, int index)
 {
        struct cmdq_client *client;
 
@@ -85,12 +78,6 @@ struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, u32 timeout)
        if (!client)
                return (struct cmdq_client *)-ENOMEM;
 
-       client->timeout_ms = timeout;
-       if (timeout != CMDQ_NO_TIMEOUT) {
-               spin_lock_init(&client->lock);
-               timer_setup(&client->timer, cmdq_client_timeout, 0);
-       }
-       client->pkt_cnt = 0;
        client->client.dev = dev;
        client->client.tx_block = false;
        client->client.knows_txdone = true;
@@ -112,11 +99,6 @@ EXPORT_SYMBOL(cmdq_mbox_create);
 
 void cmdq_mbox_destroy(struct cmdq_client *client)
 {
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               spin_lock(&client->lock);
-               del_timer_sync(&client->timer);
-               spin_unlock(&client->lock);
-       }
        mbox_free_channel(client->chan);
        kfree(client);
 }
@@ -449,18 +431,6 @@ static void cmdq_pkt_flush_async_cb(struct cmdq_cb_data data)
        struct cmdq_task_cb *cb = &pkt->cb;
        struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
 
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               unsigned long flags = 0;
-
-               spin_lock_irqsave(&client->lock, flags);
-               if (--client->pkt_cnt == 0)
-                       del_timer(&client->timer);
-               else
-                       mod_timer(&client->timer, jiffies +
-                                 msecs_to_jiffies(client->timeout_ms));
-               spin_unlock_irqrestore(&client->lock, flags);
-       }
-
        dma_sync_single_for_cpu(client->chan->mbox->dev, pkt->pa_base,
                                pkt->cmd_buf_size, DMA_TO_DEVICE);
        if (cb->cb) {
@@ -473,7 +443,6 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
                         void *data)
 {
        int err;
-       unsigned long flags = 0;
        struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
 
        pkt->cb.cb = cb;
@@ -484,14 +453,6 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
        dma_sync_single_for_device(client->chan->mbox->dev, pkt->pa_base,
                                   pkt->cmd_buf_size, DMA_TO_DEVICE);
 
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               spin_lock_irqsave(&client->lock, flags);
-               if (client->pkt_cnt++ == 0)
-                       mod_timer(&client->timer, jiffies +
-                                 msecs_to_jiffies(client->timeout_ms));
-               spin_unlock_irqrestore(&client->lock, flags);
-       }
-
        err = mbox_send_message(client->chan, pkt);
        if (err < 0)
                return err;
include/linux/soc/mediatek/mtk-cmdq.h +1 -10
index 960704d75994..8e9996610978 100644
@@ -11,7 +11,6 @@
 #include <linux/mailbox/mtk-cmdq-mailbox.h>
 #include <linux/timer.h>
 
-#define CMDQ_NO_TIMEOUT                0xffffffffu
 #define CMDQ_ADDR_HIGH(addr)   ((u32)(((addr) >> 16) & GENMASK(31, 0)))
 #define CMDQ_ADDR_LOW(addr)    ((u16)(addr) | BIT(1))
 
@@ -24,12 +23,8 @@ struct cmdq_client_reg {
 };
 
 struct cmdq_client {
-       spinlock_t lock;
-       u32 pkt_cnt;
        struct mbox_client client;
        struct mbox_chan *chan;
-       struct timer_list timer;
-       u32 timeout_ms; /* in unit of microsecond */
 };
 
 /**
@@ -51,13 +46,10 @@ int cmdq_dev_get_client_reg(struct device *dev,
  * cmdq_mbox_create() - create CMDQ mailbox client and channel
  * @dev:       device of CMDQ mailbox client
  * @index:     index of CMDQ mailbox channel
- * @timeout:   timeout of a pkt execution by GCE, in unit of microsecond, set
- *             CMDQ_NO_TIMEOUT if a timer is not used.
  *
  * Return: CMDQ mailbox client pointer
  */
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index,
-                                    u32 timeout);
+struct cmdq_client *cmdq_mbox_create(struct device *dev, int index);
 
 /**
  * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
--
Quoted 2 lines

2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer Acked-by
#2 lore raw

Hi Chun-Kuang,

Quoted 5 lines · Chun-Kuang Hu

Hi, Matthias:

I've provided the example for why of this patch. How do you think about this patch?

Patch looks good to me. If you want to take it through your tree you can add my

Beware that you might need a stable tag for it, so that I can merge it into my soc branch, in case there are more changes to cmdq-helper.

Regards,
Matthias

Quoted 177 lines

Regards,
Chun-Kuang.

Chun-Kuang Hu <[email protected]> 於 2020年11月2日 週一 上午8:04寫道:

Quoted 173 lines

For each client driver, its timeout handler need to dump hardware register or its state machine information, and their way to detect timeout are also different, so remove timeout handler in helper function and let client driver implement its own timeout handler.

---
v1 is one patch in series "Mediatek DRM driver detect CMDQ execution timeout by vblank IRQ", but according to Jassi's suggestion [1], send each patch in different series.

[2] is an example that different client has different way to calculate timeout. Some client driver care about each packet's execution time, but some client driver care about the total execution time for all packets.

[1]
https://patchwork.kernel.org/project/linux-mediatek/cover/[email protected]/
[2]
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

Changes in v2:
1. Rebase onto Linux 5.10-rc1

---
  drivers/gpu/drm/mediatek/mtk_drm_crtc.c |  3 +-
  drivers/soc/mediatek/mtk-cmdq-helper.c  | 41 +------------------------
  include/linux/soc/mediatek/mtk-cmdq.h   | 10 +-----
  3 files changed, 3 insertions(+), 51 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1 -2
index ac038572164d..4be5d1fccf2e 100644
@@ -824,8 +824,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
         mtk_crtc->cmdq_client =
                         cmdq_mbox_create(mtk_crtc->mmsys_dev,
-                                        drm_crtc_index(&mtk_crtc->base),
-                                        2000);
+                                        drm_crtc_index(&mtk_crtc->base));
         if (IS_ERR(mtk_crtc->cmdq_client)) {
                 dev_dbg(dev, "mtk_crtc %d failed to create mailbox client, writing register by CPU now\n",
                         drm_crtc_index(&mtk_crtc->base));
drivers/soc/mediatek/mtk-cmdq-helper.c +1 -40
index 505651b0d715..280d3bd9f675 100644
@@ -70,14 +70,7 @@ int cmdq_dev_get_client_reg(struct device *dev,
  }
  EXPORT_SYMBOL(cmdq_dev_get_client_reg);
 
-static void cmdq_client_timeout(struct timer_list *t)
-{
-       struct cmdq_client *client = from_timer(client, t, timer);
-
-       dev_err(client->client.dev, "cmdq timeout!\n");
-}
-
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, u32 timeout)
+struct cmdq_client *cmdq_mbox_create(struct device *dev, int index)
  {
         struct cmdq_client *client;
 
@@ -85,12 +78,6 @@ struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, u32 timeout)
         if (!client)
                 return (struct cmdq_client *)-ENOMEM;
 
-       client->timeout_ms = timeout;
-       if (timeout != CMDQ_NO_TIMEOUT) {
-               spin_lock_init(&client->lock);
-               timer_setup(&client->timer, cmdq_client_timeout, 0);
-       }
-       client->pkt_cnt = 0;
         client->client.dev = dev;
         client->client.tx_block = false;
         client->client.knows_txdone = true;
@@ -112,11 +99,6 @@ EXPORT_SYMBOL(cmdq_mbox_create);
 
  void cmdq_mbox_destroy(struct cmdq_client *client)
  {
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               spin_lock(&client->lock);
-               del_timer_sync(&client->timer);
-               spin_unlock(&client->lock);
-       }
         mbox_free_channel(client->chan);
         kfree(client);
  }
@@ -449,18 +431,6 @@ static void cmdq_pkt_flush_async_cb(struct cmdq_cb_data data)
         struct cmdq_task_cb *cb = &pkt->cb;
         struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
 
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               unsigned long flags = 0;
-
-               spin_lock_irqsave(&client->lock, flags);
-               if (--client->pkt_cnt == 0)
-                       del_timer(&client->timer);
-               else
-                       mod_timer(&client->timer, jiffies +
-                                 msecs_to_jiffies(client->timeout_ms));
-               spin_unlock_irqrestore(&client->lock, flags);
-       }
-
         dma_sync_single_for_cpu(client->chan->mbox->dev, pkt->pa_base,
                                 pkt->cmd_buf_size, DMA_TO_DEVICE);
         if (cb->cb) {
@@ -473,7 +443,6 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
                          void *data)
  {
         int err;
-       unsigned long flags = 0;
         struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
 
         pkt->cb.cb = cb;
@@ -484,14 +453,6 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
         dma_sync_single_for_device(client->chan->mbox->dev, pkt->pa_base,
                                    pkt->cmd_buf_size, DMA_TO_DEVICE);
 
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               spin_lock_irqsave(&client->lock, flags);
-               if (client->pkt_cnt++ == 0)
-                       mod_timer(&client->timer, jiffies +
-                                 msecs_to_jiffies(client->timeout_ms));
-               spin_unlock_irqrestore(&client->lock, flags);
-       }
-
         err = mbox_send_message(client->chan, pkt);
         if (err < 0)
                 return err;
include/linux/soc/mediatek/mtk-cmdq.h +1 -10
index 960704d75994..8e9996610978 100644
@@ -11,7 +11,6 @@
  #include <linux/mailbox/mtk-cmdq-mailbox.h>
  #include <linux/timer.h>
 
-#define CMDQ_NO_TIMEOUT                0xffffffffu
  #define CMDQ_ADDR_HIGH(addr)   ((u32)(((addr) >> 16) & GENMASK(31, 0)))
  #define CMDQ_ADDR_LOW(addr)    ((u16)(addr) | BIT(1))
 
@@ -24,12 +23,8 @@ struct cmdq_client_reg {
  };
 
  struct cmdq_client {
-       spinlock_t lock;
-       u32 pkt_cnt;
         struct mbox_client client;
         struct mbox_chan *chan;
-       struct timer_list timer;
-       u32 timeout_ms; /* in unit of microsecond */
  };
 
  /**
@@ -51,13 +46,10 @@ int cmdq_dev_get_client_reg(struct device *dev,
   * cmdq_mbox_create() - create CMDQ mailbox client and channel
   * @dev:       device of CMDQ mailbox client
   * @index:     index of CMDQ mailbox channel
- * @timeout:   timeout of a pkt execution by GCE, in unit of microsecond, set
- *             CMDQ_NO_TIMEOUT if a timer is not used.
   *
   * Return: CMDQ mailbox client pointer
   */
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index,
-                                    u32 timeout);
+struct cmdq_client *cmdq_mbox_create(struct device *dev, int index);
 
  /**
   * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
--

2.17.1

author maintainer
#3 lore raw

Hi, Matthias:

Matthias Brugger <[email protected]> 於 2020年11月27日 週五 下午8:40寫道:

Quoted 10 lines

Hi Chun-Kuang,

Quoted 5 lines · Chun-Kuang Hu

Hi, Matthias:

I've provided the example for why of this patch. How do you think about this patch?

Quoted 5 lines

Patch looks good to me. If you want to take it through your tree you can add my

Beware that you might need a stable tag for it, so that I can merge it into my soc branch, in case there are more changes to cmdq-helper.

I would like this patch to go into your tree because this patch mainly modify cmdq helper. Even though this patch is one of the series "Mediatek DRM driver detect CMDQ execution timeout by vblank IRQ" [1], I would wait for this patch get into mainline then send the next patch.

Regards,
Chun-Kuang.

Quoted 176 lines

Regards,
Matthias

Quoted 172 lines

Regards,
Chun-Kuang.

Chun-Kuang Hu <[email protected]> 於 2020年11月2日 週一 上午8:04寫道:

Quoted 168 lines

For each client driver, its timeout handler need to dump hardware register or its state machine information, and their way to detect timeout are also different, so remove timeout handler in helper function and let client driver implement its own timeout handler.

---
v1 is one patch in series "Mediatek DRM driver detect CMDQ execution timeout by vblank IRQ", but according to Jassi's suggestion [1], send each patch in different series.

[2] is an example that different client has different way to calculate timeout. Some client driver care about each packet's execution time, but some client driver care about the total execution time for all packets.

[1]
https://patchwork.kernel.org/project/linux-mediatek/cover/[email protected]/
[2]
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

Changes in v2:
1. Rebase onto Linux 5.10-rc1

---
  drivers/gpu/drm/mediatek/mtk_drm_crtc.c |  3 +-
  drivers/soc/mediatek/mtk-cmdq-helper.c  | 41 +------------------------
  include/linux/soc/mediatek/mtk-cmdq.h   | 10 +-----
  3 files changed, 3 insertions(+), 51 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1 -2
index ac038572164d..4be5d1fccf2e 100644
@@ -824,8 +824,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
         mtk_crtc->cmdq_client =
                         cmdq_mbox_create(mtk_crtc->mmsys_dev,
-                                        drm_crtc_index(&mtk_crtc->base),
-                                        2000);
+                                        drm_crtc_index(&mtk_crtc->base));
         if (IS_ERR(mtk_crtc->cmdq_client)) {
                 dev_dbg(dev, "mtk_crtc %d failed to create mailbox client, writing register by CPU now\n",
                         drm_crtc_index(&mtk_crtc->base));
drivers/soc/mediatek/mtk-cmdq-helper.c +1 -40
index 505651b0d715..280d3bd9f675 100644
@@ -70,14 +70,7 @@ int cmdq_dev_get_client_reg(struct device *dev,
  }
  EXPORT_SYMBOL(cmdq_dev_get_client_reg);
 
-static void cmdq_client_timeout(struct timer_list *t)
-{
-       struct cmdq_client *client = from_timer(client, t, timer);
-
-       dev_err(client->client.dev, "cmdq timeout!\n");
-}
-
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, u32 timeout)
+struct cmdq_client *cmdq_mbox_create(struct device *dev, int index)
  {
         struct cmdq_client *client;
 
@@ -85,12 +78,6 @@ struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, u32 timeout)
         if (!client)
                 return (struct cmdq_client *)-ENOMEM;
 
-       client->timeout_ms = timeout;
-       if (timeout != CMDQ_NO_TIMEOUT) {
-               spin_lock_init(&client->lock);
-               timer_setup(&client->timer, cmdq_client_timeout, 0);
-       }
-       client->pkt_cnt = 0;
         client->client.dev = dev;
         client->client.tx_block = false;
         client->client.knows_txdone = true;
@@ -112,11 +99,6 @@ EXPORT_SYMBOL(cmdq_mbox_create);
 
  void cmdq_mbox_destroy(struct cmdq_client *client)
  {
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               spin_lock(&client->lock);
-               del_timer_sync(&client->timer);
-               spin_unlock(&client->lock);
-       }
         mbox_free_channel(client->chan);
         kfree(client);
  }
@@ -449,18 +431,6 @@ static void cmdq_pkt_flush_async_cb(struct cmdq_cb_data data)
         struct cmdq_task_cb *cb = &pkt->cb;
         struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
 
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               unsigned long flags = 0;
-
-               spin_lock_irqsave(&client->lock, flags);
-               if (--client->pkt_cnt == 0)
-                       del_timer(&client->timer);
-               else
-                       mod_timer(&client->timer, jiffies +
-                                 msecs_to_jiffies(client->timeout_ms));
-               spin_unlock_irqrestore(&client->lock, flags);
-       }
-
         dma_sync_single_for_cpu(client->chan->mbox->dev, pkt->pa_base,
                                 pkt->cmd_buf_size, DMA_TO_DEVICE);
         if (cb->cb) {
@@ -473,7 +443,6 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
                          void *data)
  {
         int err;
-       unsigned long flags = 0;
         struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
 
         pkt->cb.cb = cb;
@@ -484,14 +453,6 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
         dma_sync_single_for_device(client->chan->mbox->dev, pkt->pa_base,
                                    pkt->cmd_buf_size, DMA_TO_DEVICE);
 
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               spin_lock_irqsave(&client->lock, flags);
-               if (client->pkt_cnt++ == 0)
-                       mod_timer(&client->timer, jiffies +
-                                 msecs_to_jiffies(client->timeout_ms));
-               spin_unlock_irqrestore(&client->lock, flags);
-       }
-
         err = mbox_send_message(client->chan, pkt);
         if (err < 0)
                 return err;
include/linux/soc/mediatek/mtk-cmdq.h +1 -9
index 960704d75994..8e9996610978 100644
@@ -11,7 +11,6 @@
  #include <linux/mailbox/mtk-cmdq-mailbox.h>
  #include <linux/timer.h>
 
-#define CMDQ_NO_TIMEOUT                0xffffffffu
  #define CMDQ_ADDR_HIGH(addr)   ((u32)(((addr) >> 16) & GENMASK(31, 0)))
  #define CMDQ_ADDR_LOW(addr)    ((u16)(addr) | BIT(1))
 
@@ -24,12 +23,8 @@ struct cmdq_client_reg {
  };
 
  struct cmdq_client {
-       spinlock_t lock;
-       u32 pkt_cnt;
         struct mbox_client client;
         struct mbox_chan *chan;
-       struct timer_list timer;
-       u32 timeout_ms; /* in unit of microsecond */
  };
 
  /**
@@ -51,13 +46,10 @@ int cmdq_dev_get_client_reg(struct device *dev,
   * cmdq_mbox_create() - create CMDQ mailbox client and channel
   * @dev:       device of CMDQ mailbox client
   * @index:     index of CMDQ mailbox channel
- * @timeout:   timeout of a pkt execution by GCE, in unit of microsecond, set
- *             CMDQ_NO_TIMEOUT if a timer is not used.
   *
   * Return: CMDQ mailbox client pointer
   */
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index,
-                                    u32 timeout);
+struct cmdq_client *cmdq_mbox_create(struct device *dev, int index);
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
include/linux/soc/mediatek/mtk-cmdq.h +0 -1
  /**
   * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
--

2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer Applied
#4 lore raw
Quoted 16 lines · Chun-Kuang Hu

Hi, Matthias:

Matthias Brugger <[email protected]> 於 2020年11月27日 週五 下午8:40寫道:

Quoted 13 lines

Hi Chun-Kuang,

Quoted 5 lines · Chun-Kuang Hu

Hi, Matthias:

I've provided the example for why of this patch. How do you think about this patch?

Patch looks good to me. If you want to take it through your tree you can add my

Quoted 9 lines
Quoted 2 lines

Beware that you might need a stable tag for it, so that I can merge it into my soc branch, in case there are more changes to cmdq-helper.

I would like this patch to go into your tree because this patch mainly modify cmdq helper. Even though this patch is one of the series "Mediatek DRM driver detect CMDQ execution timeout by vblank IRQ" [1], I would wait for this patch get into mainline then send the next patch.

Applied to v5.10-next/soc

Thanks!

Quoted 179 lines

Regards,
Chun-Kuang.

Quoted 176 lines

Regards,
Matthias

Quoted 172 lines

Regards,
Chun-Kuang.

Chun-Kuang Hu <[email protected]> 於 2020年11月2日 週一 上午8:04寫道:

Quoted 168 lines

For each client driver, its timeout handler need to dump hardware register or its state machine information, and their way to detect timeout are also different, so remove timeout handler in helper function and let client driver implement its own timeout handler.

---
v1 is one patch in series "Mediatek DRM driver detect CMDQ execution timeout by vblank IRQ", but according to Jassi's suggestion [1], send each patch in different series.

[2] is an example that different client has different way to calculate timeout. Some client driver care about each packet's execution time, but some client driver care about the total execution time for all packets.

[1]
https://patchwork.kernel.org/project/linux-mediatek/cover/[email protected]/
[2]
https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

Changes in v2:
1. Rebase onto Linux 5.10-rc1

---
   drivers/gpu/drm/mediatek/mtk_drm_crtc.c |  3 +-
   drivers/soc/mediatek/mtk-cmdq-helper.c  | 41 +------------------------
   include/linux/soc/mediatek/mtk-cmdq.h   | 10 +-----
   3 files changed, 3 insertions(+), 51 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1 -2
index ac038572164d..4be5d1fccf2e 100644
@@ -824,8 +824,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
   #if IS_REACHABLE(CONFIG_MTK_CMDQ)
          mtk_crtc->cmdq_client =
                          cmdq_mbox_create(mtk_crtc->mmsys_dev,
-                                        drm_crtc_index(&mtk_crtc->base),
-                                        2000);
+                                        drm_crtc_index(&mtk_crtc->base));
          if (IS_ERR(mtk_crtc->cmdq_client)) {
                  dev_dbg(dev, "mtk_crtc %d failed to create mailbox client, writing register by CPU now\n",
                          drm_crtc_index(&mtk_crtc->base));
drivers/soc/mediatek/mtk-cmdq-helper.c +1 -40
index 505651b0d715..280d3bd9f675 100644
@@ -70,14 +70,7 @@ int cmdq_dev_get_client_reg(struct device *dev,
   }
   EXPORT_SYMBOL(cmdq_dev_get_client_reg);
 
-static void cmdq_client_timeout(struct timer_list *t)
-{
-       struct cmdq_client *client = from_timer(client, t, timer);
-
-       dev_err(client->client.dev, "cmdq timeout!\n");
-}
-
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, u32 timeout)
+struct cmdq_client *cmdq_mbox_create(struct device *dev, int index)
   {
          struct cmdq_client *client;
 
@@ -85,12 +78,6 @@ struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, u32 timeout)
          if (!client)
                  return (struct cmdq_client *)-ENOMEM;
 
-       client->timeout_ms = timeout;
-       if (timeout != CMDQ_NO_TIMEOUT) {
-               spin_lock_init(&client->lock);
-               timer_setup(&client->timer, cmdq_client_timeout, 0);
-       }
-       client->pkt_cnt = 0;
          client->client.dev = dev;
          client->client.tx_block = false;
          client->client.knows_txdone = true;
@@ -112,11 +99,6 @@ EXPORT_SYMBOL(cmdq_mbox_create);
 
   void cmdq_mbox_destroy(struct cmdq_client *client)
   {
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               spin_lock(&client->lock);
-               del_timer_sync(&client->timer);
-               spin_unlock(&client->lock);
-       }
          mbox_free_channel(client->chan);
          kfree(client);
   }
@@ -449,18 +431,6 @@ static void cmdq_pkt_flush_async_cb(struct cmdq_cb_data data)
          struct cmdq_task_cb *cb = &pkt->cb;
          struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
 
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               unsigned long flags = 0;
-
-               spin_lock_irqsave(&client->lock, flags);
-               if (--client->pkt_cnt == 0)
-                       del_timer(&client->timer);
-               else
-                       mod_timer(&client->timer, jiffies +
-                                 msecs_to_jiffies(client->timeout_ms));
-               spin_unlock_irqrestore(&client->lock, flags);
-       }
-
          dma_sync_single_for_cpu(client->chan->mbox->dev, pkt->pa_base,
                                  pkt->cmd_buf_size, DMA_TO_DEVICE);
          if (cb->cb) {
@@ -473,7 +443,6 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
                           void *data)
   {
          int err;
-       unsigned long flags = 0;
          struct cmdq_client *client = (struct cmdq_client *)pkt->cl;
 
          pkt->cb.cb = cb;
@@ -484,14 +453,6 @@ int cmdq_pkt_flush_async(struct cmdq_pkt *pkt, cmdq_async_flush_cb cb,
          dma_sync_single_for_device(client->chan->mbox->dev, pkt->pa_base,
                                     pkt->cmd_buf_size, DMA_TO_DEVICE);
 
-       if (client->timeout_ms != CMDQ_NO_TIMEOUT) {
-               spin_lock_irqsave(&client->lock, flags);
-               if (client->pkt_cnt++ == 0)
-                       mod_timer(&client->timer, jiffies +
-                                 msecs_to_jiffies(client->timeout_ms));
-               spin_unlock_irqrestore(&client->lock, flags);
-       }
-
          err = mbox_send_message(client->chan, pkt);
          if (err < 0)
                  return err;
include/linux/soc/mediatek/mtk-cmdq.h +1 -9
index 960704d75994..8e9996610978 100644
@@ -11,7 +11,6 @@
   #include <linux/mailbox/mtk-cmdq-mailbox.h>
   #include <linux/timer.h>
 
-#define CMDQ_NO_TIMEOUT                0xffffffffu
   #define CMDQ_ADDR_HIGH(addr)   ((u32)(((addr) >> 16) & GENMASK(31, 0)))
   #define CMDQ_ADDR_LOW(addr)    ((u16)(addr) | BIT(1))
 
@@ -24,12 +23,8 @@ struct cmdq_client_reg {
   };
 
   struct cmdq_client {
-       spinlock_t lock;
-       u32 pkt_cnt;
          struct mbox_client client;
          struct mbox_chan *chan;
-       struct timer_list timer;
-       u32 timeout_ms; /* in unit of microsecond */
   };
 
   /**
@@ -51,13 +46,10 @@ int cmdq_dev_get_client_reg(struct device *dev,
    * cmdq_mbox_create() - create CMDQ mailbox client and channel
    * @dev:       device of CMDQ mailbox client
    * @index:     index of CMDQ mailbox channel
- * @timeout:   timeout of a pkt execution by GCE, in unit of microsecond, set
- *             CMDQ_NO_TIMEOUT if a timer is not used.
    *
    * Return: CMDQ mailbox client pointer
    */
-struct cmdq_client *cmdq_mbox_create(struct device *dev, int index,
-                                    u32 timeout);
+struct cmdq_client *cmdq_mbox_create(struct device *dev, int index);
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
include/linux/soc/mediatek/mtk-cmdq.h +0 -1
   /**
    * cmdq_mbox_destroy() - destroy CMDQ mailbox client and channel
--

2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel