diff options
author | Nrithya Kanakasabapathy <nrithya@google.com> | 2021-06-08 01:46:59 +0000 |
---|---|---|
committer | Nrithya Kanakasabapathy <nrithya@google.com> | 2021-06-10 00:30:33 +0000 |
commit | 999ed278b24d70532caea9ca790c2c5ab95d010c (patch) | |
tree | 32e706dd84d7a8de9cbea468b13c24350872e1ba | |
parent | 575b29558f6422cf203aa2ba6e56c44a7cde592f (diff) | |
download | edgetpu-999ed278b24d70532caea9ca790c2c5ab95d010c.tar.gz |
Merge branch 'whitechapel' into android-gs-pixel-5.10
* whitechapel:
edgetpu: move mailbox disable out from mbox remove
edgetpu: export mailbox enable and disable functions
edgetpu: fix error checking while creating debufs dir
edgetpu: check for error after creating debugfs dir
edgetpu: dmabuf map add debug logs for diagnosing errors
edgetpu: make various usage metrics group writeable
Bug: 190662132
Signed-off-by: Nrithya Kanakasabapathy <nrithya@google.com>
Change-Id: Id4b139ef3d08ef1615bc51844058107ebda4a55e
-rw-r--r-- | drivers/edgetpu/abrolhos-pm.c | 2 | ||||
-rw-r--r-- | drivers/edgetpu/abrolhos-thermal.c | 2 | ||||
-rw-r--r-- | drivers/edgetpu/edgetpu-dmabuf.c | 53 | ||||
-rw-r--r-- | drivers/edgetpu/edgetpu-fs.c | 14 | ||||
-rw-r--r-- | drivers/edgetpu/edgetpu-kci.c | 4 | ||||
-rw-r--r-- | drivers/edgetpu/edgetpu-mailbox.c | 21 | ||||
-rw-r--r-- | drivers/edgetpu/edgetpu-mailbox.h | 26 | ||||
-rw-r--r-- | drivers/edgetpu/edgetpu-usage-stats.c | 33 |
8 files changed, 108 insertions, 47 deletions
diff --git a/drivers/edgetpu/abrolhos-pm.c b/drivers/edgetpu/abrolhos-pm.c index b8a12eb..75a3c59 100644 --- a/drivers/edgetpu/abrolhos-pm.c +++ b/drivers/edgetpu/abrolhos-pm.c @@ -639,7 +639,7 @@ static int abrolhos_pm_after_create(struct edgetpu_pm *etpm) return ret; abrolhos_pwr_debugfs_dir = debugfs_create_dir("power", edgetpu_fs_debugfs_dir()); - if (!abrolhos_pwr_debugfs_dir) { + if (IS_ERR_OR_NULL(abrolhos_pwr_debugfs_dir)) { etdev_warn(etdev, "Failed to create debug FS power"); /* don't fail the procedure on debug FS creation fails */ return 0; diff --git a/drivers/edgetpu/abrolhos-thermal.c b/drivers/edgetpu/abrolhos-thermal.c index 106af86..572518b 100644 --- a/drivers/edgetpu/abrolhos-thermal.c +++ b/drivers/edgetpu/abrolhos-thermal.c @@ -303,7 +303,7 @@ static int tpu_thermal_init(struct edgetpu_thermal *thermal, struct device *dev) d = debugfs_create_dir("cooling", edgetpu_fs_debugfs_dir()); /* don't let debugfs creation failure abort the init procedure */ - if (!d) + if (IS_ERR_OR_NULL(d)) dev_warn(dev, "failed to create debug fs for cooling"); thermal->dev = dev; thermal->cooling_root = d; diff --git a/drivers/edgetpu/edgetpu-dmabuf.c b/drivers/edgetpu/edgetpu-dmabuf.c index a540763..3d1c190 100644 --- a/drivers/edgetpu/edgetpu-dmabuf.c +++ b/drivers/edgetpu/edgetpu-dmabuf.c @@ -646,21 +646,36 @@ int edgetpu_map_dmabuf(struct edgetpu_device_group *group, uint i; /* invalid DMA direction or offset is not page-aligned */ - if (!valid_dma_direction(dir) || offset_in_page(offset)) + if (!valid_dma_direction(dir) || offset_in_page(offset)) { + etdev_dbg(group->etdev, + "%s: valid=%d offset_in_page=%lu offset=0x%llx\n", + __func__, valid_dma_direction(dir), + offset_in_page(offset), offset); return -EINVAL; + } /* TODO(b/189278468): entirely ignore @offset */ if (offset != 0) etdev_warn_ratelimited(group->etdev, "Non-zero offset for dmabuf mapping is deprecated"); dmabuf = dma_buf_get(arg->dmabuf_fd); - if (IS_ERR(dmabuf)) + if (IS_ERR(dmabuf)) { + etdev_dbg(group->etdev, "%s: dma_buf_get returns %ld\n", + __func__, PTR_ERR(dmabuf)); return PTR_ERR(dmabuf); - if (offset >= dmabuf->size) + } + if (offset >= dmabuf->size) { + etdev_dbg(group->etdev, + "%s: offset=0x%llx > dmabuf size=%zx\n", + __func__, offset, dmabuf->size); goto err_put; + } mutex_lock(&group->lock); if (!edgetpu_device_group_is_finalized(group)) { ret = edgetpu_group_errno(group); + etdev_dbg(group->etdev, + "%s: edgetpu_device_group_is_finalized returns %d\n", + __func__, ret); goto err_unlock_group; } @@ -679,31 +694,53 @@ int edgetpu_map_dmabuf(struct edgetpu_device_group *group, etdev = edgetpu_device_group_nth_etdev(group, i); ret = etdev_attach_dmabuf_to_entry(etdev, dmabuf, &dmap->entries[i], size, dir); - if (ret) + if (ret) { + etdev_dbg(group->etdev, + "%s: etdev_attach_dmabuf_to_entry returns %d\n", + __func__, ret); goto err_release_map; + } } ret = group_map_dmabuf(group, dmap, dir, &tpu_addr); - if (ret) + if (ret) { + etdev_dbg(group->etdev, + "%s: group_map_dmabuf returns %d\n", + __func__, ret); goto err_release_map; + } dmap->map.die_index = ALL_DIES; } else { etdev = edgetpu_device_group_nth_etdev(group, arg->die_index); if (!etdev) { + etdev_dbg(group->etdev, + "%s: edgetpu_device_group_nth_etdev returns NULL\n", + __func__); ret = -EINVAL; goto err_release_map; } ret = etdev_attach_dmabuf_to_entry(etdev, dmabuf, &dmap->entries[0], size, dir); - if (ret) + if (ret) { + etdev_dbg(group->etdev, + "%s: etdev_attach_dmabuf_to_entry returns %d\n", + __func__, ret); goto err_release_map; + } ret = etdev_map_dmabuf(etdev, dmap, dir, &tpu_addr); - if (ret) + if (ret) { + etdev_dbg(group->etdev, + "%s: etdev_map_dmabuf returns %d\n", + __func__, ret); goto err_release_map; + } dmap->map.die_index = arg->die_index; } dmap->map.device_address = tpu_addr + offset; ret = edgetpu_mapping_add(&group->dmabuf_mappings, &dmap->map); - if (ret) + if (ret) { + etdev_dbg(group->etdev, "%s: edgetpu_mapping_add returns %d\n", + __func__, ret); goto err_release_map; + } arg->device_address = dmap->map.device_address; mutex_unlock(&group->lock); dma_buf_put(dmabuf); diff --git a/drivers/edgetpu/edgetpu-fs.c b/drivers/edgetpu/edgetpu-fs.c index 5b07632..1fd9106 100644 --- a/drivers/edgetpu/edgetpu-fs.c +++ b/drivers/edgetpu/edgetpu-fs.c @@ -933,8 +933,10 @@ static void edgetpu_fs_setup_debugfs(struct edgetpu_dev *etdev) { etdev->d_entry = debugfs_create_dir(etdev->dev_name, edgetpu_debugfs_dir); - if (!etdev->d_entry) + if (IS_ERR_OR_NULL(etdev->d_entry)) { + etdev_warn(etdev, "Failed to setup debugfs\n"); return; + } debugfs_create_file("mappings", 0440, etdev->d_entry, etdev, &mappings_ops); debugfs_create_file("statusregs", 0440, etdev->d_entry, etdev, @@ -1036,18 +1038,16 @@ static const struct file_operations syncfences_ops = { .release = single_release, }; -static int edgetpu_debugfs_global_setup(void) +static void edgetpu_debugfs_global_setup(void) { edgetpu_debugfs_dir = debugfs_create_dir("edgetpu", NULL); - if (IS_ERR(edgetpu_debugfs_dir)) { - pr_err(DRIVER_NAME " error creating edgetpu debugfs dir: %ld\n", - PTR_ERR(edgetpu_debugfs_dir)); - return PTR_ERR(edgetpu_debugfs_dir); + if (IS_ERR_OR_NULL(edgetpu_debugfs_dir)) { + pr_warn(DRIVER_NAME " error creating edgetpu debugfs dir\n"); + return; } debugfs_create_file("syncfences", 0440, edgetpu_debugfs_dir, NULL, &syncfences_ops); - return 0; } int __init edgetpu_fs_init(void) diff --git a/drivers/edgetpu/edgetpu-kci.c b/drivers/edgetpu/edgetpu-kci.c index e467fac..c62ac73 100644 --- a/drivers/edgetpu/edgetpu-kci.c +++ b/drivers/edgetpu/edgetpu-kci.c @@ -487,7 +487,7 @@ int edgetpu_kci_init(struct edgetpu_mailbox_manager *mgr, INIT_WORK(&kci->work, edgetpu_kci_consume_responses_work); edgetpu_reverse_kci_init(&kci->rkci); INIT_WORK(&kci->usage_work, edgetpu_kci_update_usage_work); - EDGETPU_MAILBOX_CONTEXT_WRITE(mailbox, context_enable, 1); + edgetpu_mailbox_enable(mailbox); return 0; } @@ -509,7 +509,7 @@ int edgetpu_kci_reinit(struct edgetpu_kci *kci) if (ret) return ret; edgetpu_mailbox_init_doorbells(mailbox); - EDGETPU_MAILBOX_CONTEXT_WRITE(mailbox, context_enable, 1); + edgetpu_mailbox_enable(mailbox); return 0; } diff --git a/drivers/edgetpu/edgetpu-mailbox.c b/drivers/edgetpu/edgetpu-mailbox.c index 11b6fe2..606b246 100644 --- a/drivers/edgetpu/edgetpu-mailbox.c +++ b/drivers/edgetpu/edgetpu-mailbox.c @@ -80,12 +80,6 @@ edgetpu_mailbox_create_locked(struct edgetpu_mailbox_manager *mgr, uint index) return mailbox; } -/* Disables a mailbox via setting CSR. */ -static void edgetpu_mailbox_disable(struct edgetpu_mailbox *mailbox) -{ - EDGETPU_MAILBOX_CONTEXT_WRITE(mailbox, context_enable, 0); -} - /* * Disables the @index-th mailbox via setting CSR. Doesn't need * @mgr->mailboxes[index] be allocated. @@ -203,12 +197,12 @@ int edgetpu_mailbox_set_queue(struct edgetpu_mailbox *mailbox, /* Reset mailbox queues, clear out any commands/responses left from before. */ void edgetpu_mailbox_reset(struct edgetpu_mailbox *mailbox) { - EDGETPU_MAILBOX_CONTEXT_WRITE(mailbox, context_enable, 0); + edgetpu_mailbox_disable(mailbox); EDGETPU_MAILBOX_CMD_QUEUE_WRITE(mailbox, head, 0); edgetpu_mailbox_set_cmd_queue_tail(mailbox, 0); edgetpu_mailbox_set_resp_queue_head(mailbox, 0); EDGETPU_MAILBOX_RESP_QUEUE_WRITE(mailbox, tail, 0); - EDGETPU_MAILBOX_CONTEXT_WRITE(mailbox, context_enable, 1); + edgetpu_mailbox_enable(mailbox); } /* Sets the priority of @mailbox. */ @@ -263,6 +257,8 @@ edgetpu_mailbox_vii_add(struct edgetpu_mailbox_manager *mgr, uint id) * * Returns 0 on success, or a negative errno on error. * Returns -EBUSY if any mailbox is using. + * + * Caller calls edgetpu_mailbox_enable() to enable the returned mailboxes. */ int edgetpu_mailbox_p2p_batch(struct edgetpu_mailbox_manager *mgr, uint n, uint skip_i, struct edgetpu_mailbox **mailboxes) @@ -343,8 +339,7 @@ out: * Removes a mailbox from the manager. * Returns 0 on success. */ -int edgetpu_mailbox_remove(struct edgetpu_mailbox_manager *mgr, - struct edgetpu_mailbox *mailbox) +int edgetpu_mailbox_remove(struct edgetpu_mailbox_manager *mgr, struct edgetpu_mailbox *mailbox) { unsigned long flags; @@ -357,7 +352,6 @@ int edgetpu_mailbox_remove(struct edgetpu_mailbox_manager *mgr, } mgr->mailboxes[mailbox->mailbox_id] = NULL; - edgetpu_mailbox_disable(mailbox); /* KCI mailbox is a special case */ if (mailbox->mailbox_id == KERNEL_MAILBOX_INDEX) edgetpu_kci_release(mgr->etdev, mailbox->internal.kci); @@ -467,7 +461,7 @@ int edgetpu_mailbox_init_vii(struct edgetpu_vii *vii, mailbox->internal.group = edgetpu_device_group_get(group); vii->etdev = group->etdev; vii->mailbox = mailbox; - EDGETPU_MAILBOX_CONTEXT_WRITE(mailbox, context_enable, 1); + edgetpu_mailbox_enable(mailbox); return 0; } @@ -479,6 +473,7 @@ void edgetpu_mailbox_remove_vii(struct edgetpu_vii *vii) edgetpu_mailbox_free_queue(etdev, vii->mailbox, &vii->cmd_queue_mem); edgetpu_mailbox_free_queue(etdev, vii->mailbox, &vii->resp_queue_mem); if (vii->mailbox) { + edgetpu_mailbox_disable(vii->mailbox); edgetpu_device_group_put(vii->mailbox->internal.group); edgetpu_mailbox_remove(etdev->mailbox_manager, vii->mailbox); vii->mailbox = NULL; @@ -704,7 +699,7 @@ void edgetpu_mailbox_reinit_vii(struct edgetpu_device_group *group) edgetpu_mailbox_set_queue(mailbox, MAILBOX_RESP_QUEUE, group->vii.resp_queue_mem.tpu_addr, resp_queue_size); - EDGETPU_MAILBOX_CONTEXT_WRITE(mailbox, context_enable, 1); + edgetpu_mailbox_enable(mailbox); } void edgetpu_mailbox_restore_active_vii_queues(struct edgetpu_dev *etdev) diff --git a/drivers/edgetpu/edgetpu-mailbox.h b/drivers/edgetpu/edgetpu-mailbox.h index c212a8a..8425807 100644 --- a/drivers/edgetpu/edgetpu-mailbox.h +++ b/drivers/edgetpu/edgetpu-mailbox.h @@ -192,10 +192,13 @@ edgetpu_mailbox_create_mgr(struct edgetpu_dev *etdev, /* interrupt handler */ irqreturn_t edgetpu_mailbox_handle_irq(struct edgetpu_mailbox_manager *mgr); -/* removes the mailbox previously requested from a mailbox manager */ -int edgetpu_mailbox_remove(struct edgetpu_mailbox_manager *mgr, - struct edgetpu_mailbox *mailbox); -/* removes all the mailboxes previously requested */ +/* + * Removes the mailbox previously requested from a mailbox manager. + * + * This function doesn't change the state of mailbox enable/disable. + */ +int edgetpu_mailbox_remove(struct edgetpu_mailbox_manager *mgr, struct edgetpu_mailbox *mailbox); +/* Removes and disables all the mailboxes previously requested. */ void edgetpu_mailbox_remove_all(struct edgetpu_mailbox_manager *mgr); /* configure mailbox */ @@ -231,11 +234,14 @@ void edgetpu_mailbox_inc_resp_queue_head(struct edgetpu_mailbox *mailbox, * Request the mailbox with mailbox_id equals @id. * @id = 0 means there is no preference, @mgr will return a spare mailbox. * + * Caller calls edgetpu_mailbox_enable() to enable the returned mailbox. + * * -EBUSY is returned if the requested @id is used or there is no mailbox * available. */ struct edgetpu_mailbox * edgetpu_mailbox_vii_add(struct edgetpu_mailbox_manager *mgr, uint id); + /* * Validates the mailbox attributes. * Returns 0 if valid, otherwise a negative errno. @@ -425,4 +431,16 @@ static inline u32 circular_queue_inc(u32 index, u32 inc, u32 queue_size) struct edgetpu_mailbox_resp_queue_csr, field, \ value) +/* Enables a mailbox by setting CSR. */ +static inline void edgetpu_mailbox_enable(struct edgetpu_mailbox *mailbox) +{ + EDGETPU_MAILBOX_CONTEXT_WRITE(mailbox, context_enable, 1); +} + +/* Disables a mailbox by setting CSR. */ +static inline void edgetpu_mailbox_disable(struct edgetpu_mailbox *mailbox) +{ + EDGETPU_MAILBOX_CONTEXT_WRITE(mailbox, context_enable, 0); +} + #endif /* __EDGETPU_MAILBOX_H__ */ diff --git a/drivers/edgetpu/edgetpu-usage-stats.c b/drivers/edgetpu/edgetpu-usage-stats.c index 6c94372..c13b42e 100644 --- a/drivers/edgetpu/edgetpu-usage-stats.c +++ b/drivers/edgetpu/edgetpu-usage-stats.c @@ -381,7 +381,7 @@ static ssize_t tpu_usage_clear(struct device *dev, return count; } -static DEVICE_ATTR(tpu_usage, 0644, tpu_usage_show, tpu_usage_clear); +static DEVICE_ATTR(tpu_usage, 0664, tpu_usage_show, tpu_usage_clear); static ssize_t device_utilization_show(struct device *dev, struct device_attribute *attr, @@ -431,7 +431,8 @@ static ssize_t tpu_active_cycle_count_store(struct device *dev, edgetpu_counter_clear(etdev, EDGETPU_COUNTER_TPU_ACTIVE_CYCLES); return count; } -static DEVICE_ATTR_RW(tpu_active_cycle_count); +static DEVICE_ATTR(tpu_active_cycle_count, 0664, tpu_active_cycle_count_show, + tpu_active_cycle_count_store); static ssize_t tpu_throttle_stall_count_show(struct device *dev, struct device_attribute *attr, @@ -455,7 +456,9 @@ static ssize_t tpu_throttle_stall_count_store(struct device *dev, edgetpu_counter_clear(etdev, EDGETPU_COUNTER_TPU_THROTTLE_STALLS); return count; } -static DEVICE_ATTR_RW(tpu_throttle_stall_count); +static DEVICE_ATTR(tpu_throttle_stall_count, 0664, + tpu_throttle_stall_count_show, + tpu_throttle_stall_count_store); static ssize_t inference_count_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -478,7 +481,8 @@ static ssize_t inference_count_store(struct device *dev, edgetpu_counter_clear(etdev, EDGETPU_COUNTER_INFERENCES); return count; } -static DEVICE_ATTR_RW(inference_count); +static DEVICE_ATTR(inference_count, 0664, inference_count_show, + inference_count_store); static ssize_t tpu_op_count_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -501,7 +505,7 @@ static ssize_t tpu_op_count_store(struct device *dev, edgetpu_counter_clear(etdev, EDGETPU_COUNTER_TPU_OPS); return count; } -static DEVICE_ATTR_RW(tpu_op_count); +static DEVICE_ATTR(tpu_op_count, 0664, tpu_op_count_show, tpu_op_count_store); static ssize_t param_cache_hit_count_show(struct device *dev, struct device_attribute *attr, @@ -525,7 +529,8 @@ static ssize_t param_cache_hit_count_store(struct device *dev, edgetpu_counter_clear(etdev, EDGETPU_COUNTER_PARAM_CACHE_HITS); return count; } -static DEVICE_ATTR_RW(param_cache_hit_count); +static DEVICE_ATTR(param_cache_hit_count, 0664, param_cache_hit_count_show, + param_cache_hit_count_store); static ssize_t param_cache_miss_count_show(struct device *dev, struct device_attribute *attr, @@ -549,7 +554,8 @@ static ssize_t param_cache_miss_count_store(struct device *dev, edgetpu_counter_clear(etdev, EDGETPU_COUNTER_PARAM_CACHE_MISSES); return count; } -static DEVICE_ATTR_RW(param_cache_miss_count); +static DEVICE_ATTR(param_cache_miss_count, 0664, param_cache_miss_count_show, + param_cache_miss_count_store); static ssize_t context_preempt_count_show(struct device *dev, struct device_attribute *attr, @@ -573,7 +579,8 @@ static ssize_t context_preempt_count_store(struct device *dev, edgetpu_counter_clear(etdev, EDGETPU_COUNTER_CONTEXT_PREEMPTS); return count; } -static DEVICE_ATTR_RW(context_preempt_count); +static DEVICE_ATTR(context_preempt_count, 0664, context_preempt_count_show, + context_preempt_count_store); static ssize_t outstanding_commands_max_show( struct device *dev, struct device_attribute *attr, char *buf) @@ -601,7 +608,9 @@ static ssize_t outstanding_commands_max_store( return count; } -static DEVICE_ATTR_RW(outstanding_commands_max); +static DEVICE_ATTR(outstanding_commands_max, 0664, + outstanding_commands_max_show, + outstanding_commands_max_store); static ssize_t preempt_depth_max_show( struct device *dev, struct device_attribute *attr, char *buf) @@ -629,7 +638,8 @@ static ssize_t preempt_depth_max_store( return count; } -static DEVICE_ATTR_RW(preempt_depth_max); +static DEVICE_ATTR(preempt_depth_max, 0664, preempt_depth_max_show, + preempt_depth_max_store); static ssize_t fw_thread_stats_show( struct device *dev, struct device_attribute *attr, char *buf) @@ -668,7 +678,8 @@ static ssize_t fw_thread_stats_store( mutex_unlock(&ustats->usage_stats_lock); return count; } -static DEVICE_ATTR_RW(fw_thread_stats); +static DEVICE_ATTR(fw_thread_stats, 0664, fw_thread_stats_show, + fw_thread_stats_store); static struct attribute *usage_stats_dev_attrs[] = { &dev_attr_tpu_usage.attr, |