Lines Matching refs:hdev

19 bool hl_device_disabled_or_in_reset(struct hl_device *hdev)  in hl_device_disabled_or_in_reset()  argument
21 if ((hdev->disabled) || (atomic_read(&hdev->in_reset))) in hl_device_disabled_or_in_reset()
27 enum hl_device_status hl_device_status(struct hl_device *hdev) in hl_device_status() argument
31 if (hdev->disabled) in hl_device_status()
33 else if (atomic_read(&hdev->in_reset)) in hl_device_status()
44 struct hl_device *hdev; in hpriv_release() local
49 hdev = hpriv->hdev; in hpriv_release()
58 mutex_lock(&hdev->fpriv_list_lock); in hpriv_release()
60 hdev->compute_ctx = NULL; in hpriv_release()
61 mutex_unlock(&hdev->fpriv_list_lock); in hpriv_release()
88 hl_cb_mgr_fini(hpriv->hdev, &hpriv->cb_mgr); in hl_device_release()
89 hl_ctx_mgr_fini(hpriv->hdev, &hpriv->ctx_mgr); in hl_device_release()
101 struct hl_device *hdev; in hl_device_release_ctrl() local
105 hdev = hpriv->hdev; in hl_device_release_ctrl()
107 mutex_lock(&hdev->fpriv_list_lock); in hl_device_release_ctrl()
109 mutex_unlock(&hdev->fpriv_list_lock); in hl_device_release_ctrl()
172 static int device_init_cdev(struct hl_device *hdev, struct class *hclass, in device_init_cdev() argument
185 (*dev)->devt = MKDEV(hdev->major, minor); in device_init_cdev()
188 dev_set_drvdata(*dev, hdev); in device_init_cdev()
194 static int device_cdev_sysfs_add(struct hl_device *hdev) in device_cdev_sysfs_add() argument
198 rc = cdev_device_add(&hdev->cdev, hdev->dev); in device_cdev_sysfs_add()
200 dev_err(hdev->dev, in device_cdev_sysfs_add()
205 rc = cdev_device_add(&hdev->cdev_ctrl, hdev->dev_ctrl); in device_cdev_sysfs_add()
207 dev_err(hdev->dev, in device_cdev_sysfs_add()
213 rc = hl_sysfs_init(hdev); in device_cdev_sysfs_add()
215 dev_err(hdev->dev, "failed to initialize sysfs\n"); in device_cdev_sysfs_add()
219 hdev->cdev_sysfs_created = true; in device_cdev_sysfs_add()
224 cdev_device_del(&hdev->cdev_ctrl, hdev->dev_ctrl); in device_cdev_sysfs_add()
226 cdev_device_del(&hdev->cdev, hdev->dev); in device_cdev_sysfs_add()
230 static void device_cdev_sysfs_del(struct hl_device *hdev) in device_cdev_sysfs_del() argument
233 if (!hdev->cdev_sysfs_created) { in device_cdev_sysfs_del()
234 kfree(hdev->dev_ctrl); in device_cdev_sysfs_del()
235 kfree(hdev->dev); in device_cdev_sysfs_del()
239 hl_sysfs_fini(hdev); in device_cdev_sysfs_del()
240 cdev_device_del(&hdev->cdev_ctrl, hdev->dev_ctrl); in device_cdev_sysfs_del()
241 cdev_device_del(&hdev->cdev, hdev->dev); in device_cdev_sysfs_del()
252 static int device_early_init(struct hl_device *hdev) in device_early_init() argument
256 switch (hdev->asic_type) { in device_early_init()
258 goya_set_asic_funcs(hdev); in device_early_init()
259 strlcpy(hdev->asic_name, "GOYA", sizeof(hdev->asic_name)); in device_early_init()
262 dev_err(hdev->dev, "Unrecognized ASIC type %d\n", in device_early_init()
263 hdev->asic_type); in device_early_init()
267 rc = hdev->asic_funcs->early_init(hdev); in device_early_init()
271 rc = hl_asid_init(hdev); in device_early_init()
275 hdev->cq_wq = alloc_workqueue("hl-free-jobs", WQ_UNBOUND, 0); in device_early_init()
276 if (hdev->cq_wq == NULL) { in device_early_init()
277 dev_err(hdev->dev, "Failed to allocate CQ workqueue\n"); in device_early_init()
282 hdev->eq_wq = alloc_workqueue("hl-events", WQ_UNBOUND, 0); in device_early_init()
283 if (hdev->eq_wq == NULL) { in device_early_init()
284 dev_err(hdev->dev, "Failed to allocate EQ workqueue\n"); in device_early_init()
289 hdev->hl_chip_info = kzalloc(sizeof(struct hwmon_chip_info), in device_early_init()
291 if (!hdev->hl_chip_info) { in device_early_init()
296 hdev->idle_busy_ts_arr = kmalloc_array(HL_IDLE_BUSY_TS_ARR_SIZE, in device_early_init()
299 if (!hdev->idle_busy_ts_arr) { in device_early_init()
304 hl_cb_mgr_init(&hdev->kernel_cb_mgr); in device_early_init()
306 mutex_init(&hdev->send_cpu_message_lock); in device_early_init()
307 mutex_init(&hdev->debug_lock); in device_early_init()
308 mutex_init(&hdev->mmu_cache_lock); in device_early_init()
309 INIT_LIST_HEAD(&hdev->hw_queues_mirror_list); in device_early_init()
310 spin_lock_init(&hdev->hw_queues_mirror_lock); in device_early_init()
311 INIT_LIST_HEAD(&hdev->fpriv_list); in device_early_init()
312 mutex_init(&hdev->fpriv_list_lock); in device_early_init()
313 atomic_set(&hdev->in_reset, 0); in device_early_init()
318 kfree(hdev->hl_chip_info); in device_early_init()
320 destroy_workqueue(hdev->eq_wq); in device_early_init()
322 destroy_workqueue(hdev->cq_wq); in device_early_init()
324 hl_asid_fini(hdev); in device_early_init()
326 if (hdev->asic_funcs->early_fini) in device_early_init()
327 hdev->asic_funcs->early_fini(hdev); in device_early_init()
338 static void device_early_fini(struct hl_device *hdev) in device_early_fini() argument
340 mutex_destroy(&hdev->mmu_cache_lock); in device_early_fini()
341 mutex_destroy(&hdev->debug_lock); in device_early_fini()
342 mutex_destroy(&hdev->send_cpu_message_lock); in device_early_fini()
344 mutex_destroy(&hdev->fpriv_list_lock); in device_early_fini()
346 hl_cb_mgr_fini(hdev, &hdev->kernel_cb_mgr); in device_early_fini()
348 kfree(hdev->idle_busy_ts_arr); in device_early_fini()
349 kfree(hdev->hl_chip_info); in device_early_fini()
351 destroy_workqueue(hdev->eq_wq); in device_early_fini()
352 destroy_workqueue(hdev->cq_wq); in device_early_fini()
354 hl_asid_fini(hdev); in device_early_fini()
356 if (hdev->asic_funcs->early_fini) in device_early_fini()
357 hdev->asic_funcs->early_fini(hdev); in device_early_fini()
362 struct hl_device *hdev = container_of(work, struct hl_device, in set_freq_to_low_job() local
365 mutex_lock(&hdev->fpriv_list_lock); in set_freq_to_low_job()
367 if (!hdev->compute_ctx) in set_freq_to_low_job()
368 hl_device_set_frequency(hdev, PLL_LOW); in set_freq_to_low_job()
370 mutex_unlock(&hdev->fpriv_list_lock); in set_freq_to_low_job()
372 schedule_delayed_work(&hdev->work_freq, in set_freq_to_low_job()
378 struct hl_device *hdev = container_of(work, struct hl_device, in hl_device_heartbeat() local
381 if (hl_device_disabled_or_in_reset(hdev)) in hl_device_heartbeat()
384 if (!hdev->asic_funcs->send_heartbeat(hdev)) in hl_device_heartbeat()
387 dev_err(hdev->dev, "Device heartbeat failed!\n"); in hl_device_heartbeat()
388 hl_device_reset(hdev, true, false); in hl_device_heartbeat()
393 schedule_delayed_work(&hdev->work_heartbeat, in hl_device_heartbeat()
405 static int device_late_init(struct hl_device *hdev) in device_late_init() argument
409 if (hdev->asic_funcs->late_init) { in device_late_init()
410 rc = hdev->asic_funcs->late_init(hdev); in device_late_init()
412 dev_err(hdev->dev, in device_late_init()
418 hdev->high_pll = hdev->asic_prop.high_pll; in device_late_init()
421 hdev->curr_pll_profile = PLL_LOW; in device_late_init()
423 if (hdev->pm_mng_profile == PM_AUTO) in device_late_init()
424 hdev->asic_funcs->set_pll_profile(hdev, PLL_LOW); in device_late_init()
426 hdev->asic_funcs->set_pll_profile(hdev, PLL_LAST); in device_late_init()
428 INIT_DELAYED_WORK(&hdev->work_freq, set_freq_to_low_job); in device_late_init()
429 schedule_delayed_work(&hdev->work_freq, in device_late_init()
432 if (hdev->heartbeat) { in device_late_init()
433 INIT_DELAYED_WORK(&hdev->work_heartbeat, hl_device_heartbeat); in device_late_init()
434 schedule_delayed_work(&hdev->work_heartbeat, in device_late_init()
438 hdev->late_init_done = true; in device_late_init()
449 static void device_late_fini(struct hl_device *hdev) in device_late_fini() argument
451 if (!hdev->late_init_done) in device_late_fini()
454 cancel_delayed_work_sync(&hdev->work_freq); in device_late_fini()
455 if (hdev->heartbeat) in device_late_fini()
456 cancel_delayed_work_sync(&hdev->work_heartbeat); in device_late_fini()
458 if (hdev->asic_funcs->late_fini) in device_late_fini()
459 hdev->asic_funcs->late_fini(hdev); in device_late_fini()
461 hdev->late_init_done = false; in device_late_fini()
464 uint32_t hl_device_utilization(struct hl_device *hdev, uint32_t period_ms) in hl_device_utilization() argument
468 u32 overlap_cnt = 0, last_index = hdev->idle_busy_ts_idx; in hl_device_utilization()
474 ts = &hdev->idle_busy_ts_arr[last_index]; in hl_device_utilization()
485 ts = &hdev->idle_busy_ts_arr[last_index]; in hl_device_utilization()
549 ts = &hdev->idle_busy_ts_arr[last_index]; in hl_device_utilization()
573 int hl_device_set_frequency(struct hl_device *hdev, enum hl_pll_frequency freq) in hl_device_set_frequency() argument
575 if ((hdev->pm_mng_profile == PM_MANUAL) || in hl_device_set_frequency()
576 (hdev->curr_pll_profile == freq)) in hl_device_set_frequency()
579 dev_dbg(hdev->dev, "Changing device frequency to %s\n", in hl_device_set_frequency()
582 hdev->asic_funcs->set_pll_profile(hdev, freq); in hl_device_set_frequency()
584 hdev->curr_pll_profile = freq; in hl_device_set_frequency()
589 int hl_device_set_debug_mode(struct hl_device *hdev, bool enable) in hl_device_set_debug_mode() argument
593 mutex_lock(&hdev->debug_lock); in hl_device_set_debug_mode()
596 if (!hdev->in_debug) { in hl_device_set_debug_mode()
597 dev_err(hdev->dev, in hl_device_set_debug_mode()
603 hdev->asic_funcs->halt_coresight(hdev); in hl_device_set_debug_mode()
604 hdev->in_debug = 0; in hl_device_set_debug_mode()
609 if (hdev->in_debug) { in hl_device_set_debug_mode()
610 dev_err(hdev->dev, in hl_device_set_debug_mode()
616 hdev->in_debug = 1; in hl_device_set_debug_mode()
619 mutex_unlock(&hdev->debug_lock); in hl_device_set_debug_mode()
633 int hl_device_suspend(struct hl_device *hdev) in hl_device_suspend() argument
637 pci_save_state(hdev->pdev); in hl_device_suspend()
640 rc = atomic_cmpxchg(&hdev->in_reset, 0, 1); in hl_device_suspend()
642 dev_err(hdev->dev, "Can't suspend while in reset\n"); in hl_device_suspend()
647 hdev->disabled = true; in hl_device_suspend()
653 hdev->asic_funcs->hw_queues_lock(hdev); in hl_device_suspend()
654 hdev->asic_funcs->hw_queues_unlock(hdev); in hl_device_suspend()
657 mutex_lock(&hdev->send_cpu_message_lock); in hl_device_suspend()
658 mutex_unlock(&hdev->send_cpu_message_lock); in hl_device_suspend()
660 rc = hdev->asic_funcs->suspend(hdev); in hl_device_suspend()
662 dev_err(hdev->dev, in hl_device_suspend()
666 pci_disable_device(hdev->pdev); in hl_device_suspend()
667 pci_set_power_state(hdev->pdev, PCI_D3hot); in hl_device_suspend()
681 int hl_device_resume(struct hl_device *hdev) in hl_device_resume() argument
685 pci_set_power_state(hdev->pdev, PCI_D0); in hl_device_resume()
686 pci_restore_state(hdev->pdev); in hl_device_resume()
687 rc = pci_enable_device_mem(hdev->pdev); in hl_device_resume()
689 dev_err(hdev->dev, in hl_device_resume()
694 pci_set_master(hdev->pdev); in hl_device_resume()
696 rc = hdev->asic_funcs->resume(hdev); in hl_device_resume()
698 dev_err(hdev->dev, "Failed to resume device after suspend\n"); in hl_device_resume()
703 hdev->disabled = false; in hl_device_resume()
704 atomic_set(&hdev->in_reset, 0); in hl_device_resume()
706 rc = hl_device_reset(hdev, true, false); in hl_device_resume()
708 dev_err(hdev->dev, "Failed to reset device during resume\n"); in hl_device_resume()
715 pci_clear_master(hdev->pdev); in hl_device_resume()
716 pci_disable_device(hdev->pdev); in hl_device_resume()
721 static void device_kill_open_processes(struct hl_device *hdev) in device_kill_open_processes() argument
727 if (hdev->pldm) in device_kill_open_processes()
735 if (!list_empty(&hdev->fpriv_list)) in device_kill_open_processes()
738 mutex_lock(&hdev->fpriv_list_lock); in device_kill_open_processes()
743 list_for_each_entry(hpriv, &hdev->fpriv_list, dev_node) { in device_kill_open_processes()
746 dev_info(hdev->dev, "Killing user process pid=%d\n", in device_kill_open_processes()
755 mutex_unlock(&hdev->fpriv_list_lock); in device_kill_open_processes()
765 while ((!list_empty(&hdev->fpriv_list)) && (pending_cnt)) { in device_kill_open_processes()
766 dev_info(hdev->dev, in device_kill_open_processes()
774 if (!list_empty(&hdev->fpriv_list)) in device_kill_open_processes()
775 dev_crit(hdev->dev, in device_kill_open_processes()
783 struct hl_device *hdev = device_reset_work->hdev; in device_hard_reset_pending() local
785 hl_device_reset(hdev, true, true); in device_hard_reset_pending()
807 int hl_device_reset(struct hl_device *hdev, bool hard_reset, in hl_device_reset() argument
812 if (!hdev->init_done) { in hl_device_reset()
813 dev_err(hdev->dev, in hl_device_reset()
825 rc = atomic_cmpxchg(&hdev->in_reset, 0, 1); in hl_device_reset()
830 hdev->disabled = true; in hl_device_reset()
835 hdev->asic_funcs->hw_queues_lock(hdev); in hl_device_reset()
836 hdev->asic_funcs->hw_queues_unlock(hdev); in hl_device_reset()
839 mutex_lock(&hdev->fpriv_list_lock); in hl_device_reset()
840 mutex_unlock(&hdev->fpriv_list_lock); in hl_device_reset()
842 dev_err(hdev->dev, "Going to RESET device!\n"); in hl_device_reset()
849 hdev->hard_reset_pending = true; in hl_device_reset()
865 device_reset_work->hdev = hdev; in hl_device_reset()
872 device_late_fini(hdev); in hl_device_reset()
878 mutex_lock(&hdev->send_cpu_message_lock); in hl_device_reset()
879 mutex_unlock(&hdev->send_cpu_message_lock); in hl_device_reset()
887 hdev->asic_funcs->halt_engines(hdev, hard_reset); in hl_device_reset()
890 hl_cs_rollback_all(hdev); in hl_device_reset()
897 device_kill_open_processes(hdev); in hl_device_reset()
900 if ((hard_reset) && (hl_ctx_put(hdev->kernel_ctx) == 1)) in hl_device_reset()
901 hdev->kernel_ctx = NULL; in hl_device_reset()
904 hdev->asic_funcs->hw_fini(hdev, hard_reset); in hl_device_reset()
907 hl_vm_fini(hdev); in hl_device_reset()
908 hl_mmu_fini(hdev); in hl_device_reset()
909 hl_eq_reset(hdev, &hdev->event_queue); in hl_device_reset()
913 hl_hw_queue_reset(hdev, hard_reset); in hl_device_reset()
914 for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) in hl_device_reset()
915 hl_cq_reset(hdev, &hdev->completion_queue[i]); in hl_device_reset()
917 hdev->idle_busy_ts_idx = 0; in hl_device_reset()
918 hdev->idle_busy_ts_arr[0].busy_to_idle_ts = ktime_set(0, 0); in hl_device_reset()
919 hdev->idle_busy_ts_arr[0].idle_to_busy_ts = ktime_set(0, 0); in hl_device_reset()
921 if (hdev->cs_active_cnt) in hl_device_reset()
922 dev_crit(hdev->dev, "CS active cnt %d is not 0 during reset\n", in hl_device_reset()
923 hdev->cs_active_cnt); in hl_device_reset()
925 mutex_lock(&hdev->fpriv_list_lock); in hl_device_reset()
928 if (hdev->compute_ctx) { in hl_device_reset()
929 atomic_set(&hdev->compute_ctx->thread_ctx_switch_token, 1); in hl_device_reset()
930 hdev->compute_ctx->thread_ctx_switch_wait_token = 0; in hl_device_reset()
933 mutex_unlock(&hdev->fpriv_list_lock); in hl_device_reset()
938 hdev->device_cpu_disabled = false; in hl_device_reset()
939 hdev->hard_reset_pending = false; in hl_device_reset()
941 if (hdev->kernel_ctx) { in hl_device_reset()
942 dev_crit(hdev->dev, in hl_device_reset()
948 rc = hl_mmu_init(hdev); in hl_device_reset()
950 dev_err(hdev->dev, in hl_device_reset()
956 hdev->kernel_ctx = kzalloc(sizeof(*hdev->kernel_ctx), in hl_device_reset()
958 if (!hdev->kernel_ctx) { in hl_device_reset()
963 hdev->compute_ctx = NULL; in hl_device_reset()
965 rc = hl_ctx_init(hdev, hdev->kernel_ctx, true); in hl_device_reset()
967 dev_err(hdev->dev, in hl_device_reset()
969 kfree(hdev->kernel_ctx); in hl_device_reset()
970 hdev->kernel_ctx = NULL; in hl_device_reset()
975 rc = hdev->asic_funcs->hw_init(hdev); in hl_device_reset()
977 dev_err(hdev->dev, in hl_device_reset()
982 hdev->disabled = false; in hl_device_reset()
985 rc = hdev->asic_funcs->test_queues(hdev); in hl_device_reset()
987 dev_err(hdev->dev, in hl_device_reset()
993 rc = device_late_init(hdev); in hl_device_reset()
995 dev_err(hdev->dev, in hl_device_reset()
1000 rc = hl_vm_init(hdev); in hl_device_reset()
1002 dev_err(hdev->dev, in hl_device_reset()
1007 hl_set_max_power(hdev, hdev->max_power); in hl_device_reset()
1009 rc = hdev->asic_funcs->soft_reset_late_init(hdev); in hl_device_reset()
1011 dev_err(hdev->dev, in hl_device_reset()
1017 atomic_set(&hdev->in_reset, 0); in hl_device_reset()
1020 hdev->hard_reset_cnt++; in hl_device_reset()
1022 hdev->soft_reset_cnt++; in hl_device_reset()
1024 dev_warn(hdev->dev, "Successfully finished resetting the device\n"); in hl_device_reset()
1029 hdev->disabled = true; in hl_device_reset()
1032 dev_err(hdev->dev, in hl_device_reset()
1034 hdev->hard_reset_cnt++; in hl_device_reset()
1036 dev_err(hdev->dev, in hl_device_reset()
1038 hdev->soft_reset_cnt++; in hl_device_reset()
1043 atomic_set(&hdev->in_reset, 0); in hl_device_reset()
1057 int hl_device_init(struct hl_device *hdev, struct class *hclass) in hl_device_init() argument
1063 name = kasprintf(GFP_KERNEL, "hl%d", hdev->id / 2); in hl_device_init()
1070 rc = device_init_cdev(hdev, hclass, hdev->id, &hl_ops, name, in hl_device_init()
1071 &hdev->cdev, &hdev->dev); in hl_device_init()
1078 name = kasprintf(GFP_KERNEL, "hl_controlD%d", hdev->id / 2); in hl_device_init()
1085 rc = device_init_cdev(hdev, hclass, hdev->id_control, &hl_ctrl_ops, in hl_device_init()
1086 name, &hdev->cdev_ctrl, &hdev->dev_ctrl); in hl_device_init()
1094 rc = device_early_init(hdev); in hl_device_init()
1102 rc = hdev->asic_funcs->sw_init(hdev); in hl_device_init()
1111 rc = hl_hw_queues_create(hdev); in hl_device_init()
1113 dev_err(hdev->dev, "failed to initialize kernel queues\n"); in hl_device_init()
1122 hdev->completion_queue = in hl_device_init()
1123 kcalloc(hdev->asic_prop.completion_queues_count, in hl_device_init()
1124 sizeof(*hdev->completion_queue), GFP_KERNEL); in hl_device_init()
1126 if (!hdev->completion_queue) { in hl_device_init()
1127 dev_err(hdev->dev, "failed to allocate completion queues\n"); in hl_device_init()
1133 i < hdev->asic_prop.completion_queues_count; in hl_device_init()
1135 rc = hl_cq_init(hdev, &hdev->completion_queue[i], i); in hl_device_init()
1137 dev_err(hdev->dev, in hl_device_init()
1148 rc = hl_eq_init(hdev, &hdev->event_queue); in hl_device_init()
1150 dev_err(hdev->dev, "failed to initialize event queue\n"); in hl_device_init()
1155 rc = hl_mmu_init(hdev); in hl_device_init()
1157 dev_err(hdev->dev, "Failed to initialize MMU S/W structures\n"); in hl_device_init()
1162 hdev->kernel_ctx = kzalloc(sizeof(*hdev->kernel_ctx), GFP_KERNEL); in hl_device_init()
1163 if (!hdev->kernel_ctx) { in hl_device_init()
1168 hdev->compute_ctx = NULL; in hl_device_init()
1170 rc = hl_ctx_init(hdev, hdev->kernel_ctx, true); in hl_device_init()
1172 dev_err(hdev->dev, "failed to initialize kernel context\n"); in hl_device_init()
1173 kfree(hdev->kernel_ctx); in hl_device_init()
1177 rc = hl_cb_pool_init(hdev); in hl_device_init()
1179 dev_err(hdev->dev, "failed to initialize CB pool\n"); in hl_device_init()
1183 hl_debugfs_add_device(hdev); in hl_device_init()
1185 if (hdev->asic_funcs->get_hw_state(hdev) == HL_DEVICE_HW_STATE_DIRTY) { in hl_device_init()
1186 dev_info(hdev->dev, in hl_device_init()
1188 hdev->asic_funcs->hw_fini(hdev, true); in hl_device_init()
1197 rc = hdev->asic_funcs->hw_init(hdev); in hl_device_init()
1199 dev_err(hdev->dev, "failed to initialize the H/W\n"); in hl_device_init()
1204 hdev->disabled = false; in hl_device_init()
1207 rc = hdev->asic_funcs->test_queues(hdev); in hl_device_init()
1209 dev_err(hdev->dev, "Failed to detect if device is alive\n"); in hl_device_init()
1214 rc = device_late_init(hdev); in hl_device_init()
1216 dev_err(hdev->dev, "Failed late initialization\n"); in hl_device_init()
1221 dev_info(hdev->dev, "Found %s device with %lluGB DRAM\n", in hl_device_init()
1222 hdev->asic_name, in hl_device_init()
1223 hdev->asic_prop.dram_size / 1024 / 1024 / 1024); in hl_device_init()
1225 rc = hl_vm_init(hdev); in hl_device_init()
1227 dev_err(hdev->dev, "Failed to initialize memory module\n"); in hl_device_init()
1238 rc = device_cdev_sysfs_add(hdev); in hl_device_init()
1240 dev_err(hdev->dev, in hl_device_init()
1252 rc = hl_hwmon_init(hdev); in hl_device_init()
1254 dev_err(hdev->dev, "Failed to initialize hwmon\n"); in hl_device_init()
1259 dev_notice(hdev->dev, in hl_device_init()
1262 hdev->init_done = true; in hl_device_init()
1267 if (hl_ctx_put(hdev->kernel_ctx) != 1) in hl_device_init()
1268 dev_err(hdev->dev, in hl_device_init()
1271 hl_mmu_fini(hdev); in hl_device_init()
1273 hl_eq_fini(hdev, &hdev->event_queue); in hl_device_init()
1276 hl_cq_fini(hdev, &hdev->completion_queue[i]); in hl_device_init()
1277 kfree(hdev->completion_queue); in hl_device_init()
1279 hl_hw_queues_destroy(hdev); in hl_device_init()
1281 hdev->asic_funcs->sw_fini(hdev); in hl_device_init()
1283 device_early_fini(hdev); in hl_device_init()
1285 kfree(hdev->dev_ctrl); in hl_device_init()
1287 kfree(hdev->dev); in hl_device_init()
1289 hdev->disabled = true; in hl_device_init()
1291 device_cdev_sysfs_add(hdev); in hl_device_init()
1292 if (hdev->pdev) in hl_device_init()
1293 dev_err(&hdev->pdev->dev, in hl_device_init()
1295 hdev->id / 2); in hl_device_init()
1298 hdev->id / 2); in hl_device_init()
1310 void hl_device_fini(struct hl_device *hdev) in hl_device_fini() argument
1315 dev_info(hdev->dev, "Removing device\n"); in hl_device_fini()
1326 rc = atomic_cmpxchg(&hdev->in_reset, 0, 1); in hl_device_fini()
1329 rc = atomic_cmpxchg(&hdev->in_reset, 0, 1); in hl_device_fini()
1337 hdev->disabled = true; in hl_device_fini()
1342 hdev->asic_funcs->hw_queues_lock(hdev); in hl_device_fini()
1343 hdev->asic_funcs->hw_queues_unlock(hdev); in hl_device_fini()
1346 mutex_lock(&hdev->fpriv_list_lock); in hl_device_fini()
1347 mutex_unlock(&hdev->fpriv_list_lock); in hl_device_fini()
1349 hdev->hard_reset_pending = true; in hl_device_fini()
1351 hl_hwmon_fini(hdev); in hl_device_fini()
1353 device_late_fini(hdev); in hl_device_fini()
1355 hl_debugfs_remove_device(hdev); in hl_device_fini()
1362 hdev->asic_funcs->halt_engines(hdev, true); in hl_device_fini()
1365 hl_cs_rollback_all(hdev); in hl_device_fini()
1371 device_kill_open_processes(hdev); in hl_device_fini()
1373 hl_cb_pool_fini(hdev); in hl_device_fini()
1376 if ((hdev->kernel_ctx) && (hl_ctx_put(hdev->kernel_ctx) != 1)) in hl_device_fini()
1377 dev_err(hdev->dev, "kernel ctx is still alive\n"); in hl_device_fini()
1380 hdev->asic_funcs->hw_fini(hdev, true); in hl_device_fini()
1382 hl_vm_fini(hdev); in hl_device_fini()
1384 hl_mmu_fini(hdev); in hl_device_fini()
1386 hl_eq_fini(hdev, &hdev->event_queue); in hl_device_fini()
1388 for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) in hl_device_fini()
1389 hl_cq_fini(hdev, &hdev->completion_queue[i]); in hl_device_fini()
1390 kfree(hdev->completion_queue); in hl_device_fini()
1392 hl_hw_queues_destroy(hdev); in hl_device_fini()
1395 hdev->asic_funcs->sw_fini(hdev); in hl_device_fini()
1397 device_early_fini(hdev); in hl_device_fini()
1400 device_cdev_sysfs_del(hdev); in hl_device_fini()
1418 inline u32 hl_rreg(struct hl_device *hdev, u32 reg) in hl_rreg() argument
1420 return readl(hdev->rmmio + reg); in hl_rreg()
1433 inline void hl_wreg(struct hl_device *hdev, u32 reg, u32 val) in hl_wreg() argument
1435 writel(val, hdev->rmmio + reg); in hl_wreg()