Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2016-2019 HabanaLabs, Ltd. |
| 5 | * All Rights Reserved. |
| 6 | */ |
| 7 | |
| 8 | #include <uapi/misc/habanalabs.h> |
| 9 | #include "habanalabs.h" |
| 10 | |
| 11 | #include <linux/fs.h> |
| 12 | #include <linux/uaccess.h> |
| 13 | #include <linux/slab.h> |
| 14 | |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 15 | static u32 hl_debug_struct_size[HL_DEBUG_OP_TIMESTAMP + 1] = { |
| 16 | [HL_DEBUG_OP_ETR] = sizeof(struct hl_debug_params_etr), |
| 17 | [HL_DEBUG_OP_ETF] = sizeof(struct hl_debug_params_etf), |
| 18 | [HL_DEBUG_OP_STM] = sizeof(struct hl_debug_params_stm), |
| 19 | [HL_DEBUG_OP_FUNNEL] = 0, |
| 20 | [HL_DEBUG_OP_BMON] = sizeof(struct hl_debug_params_bmon), |
| 21 | [HL_DEBUG_OP_SPMU] = sizeof(struct hl_debug_params_spmu), |
| 22 | [HL_DEBUG_OP_TIMESTAMP] = 0 |
| 23 | |
| 24 | }; |
| 25 | |
Dalit Ben Zoor | aa95708 | 2019-03-24 10:15:44 +0200 | [diff] [blame] | 26 | static int device_status_info(struct hl_device *hdev, struct hl_info_args *args) |
| 27 | { |
| 28 | struct hl_info_device_status dev_stat = {0}; |
| 29 | u32 size = args->return_size; |
| 30 | void __user *out = (void __user *) (uintptr_t) args->return_pointer; |
| 31 | |
| 32 | if ((!size) || (!out)) |
| 33 | return -EINVAL; |
| 34 | |
| 35 | dev_stat.status = hl_device_status(hdev); |
| 36 | |
| 37 | return copy_to_user(out, &dev_stat, |
| 38 | min((size_t)size, sizeof(dev_stat))) ? -EFAULT : 0; |
| 39 | } |
| 40 | |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 41 | static int hw_ip_info(struct hl_device *hdev, struct hl_info_args *args) |
| 42 | { |
| 43 | struct hl_info_hw_ip_info hw_ip = {0}; |
| 44 | u32 size = args->return_size; |
| 45 | void __user *out = (void __user *) (uintptr_t) args->return_pointer; |
| 46 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
| 47 | u64 sram_kmd_size, dram_kmd_size; |
| 48 | |
| 49 | if ((!size) || (!out)) |
| 50 | return -EINVAL; |
| 51 | |
| 52 | sram_kmd_size = (prop->sram_user_base_address - |
| 53 | prop->sram_base_address); |
| 54 | dram_kmd_size = (prop->dram_user_base_address - |
| 55 | prop->dram_base_address); |
| 56 | |
| 57 | hw_ip.device_id = hdev->asic_funcs->get_pci_id(hdev); |
| 58 | hw_ip.sram_base_address = prop->sram_user_base_address; |
| 59 | hw_ip.dram_base_address = prop->dram_user_base_address; |
| 60 | hw_ip.tpc_enabled_mask = prop->tpc_enabled_mask; |
| 61 | hw_ip.sram_size = prop->sram_size - sram_kmd_size; |
| 62 | hw_ip.dram_size = prop->dram_size - dram_kmd_size; |
| 63 | if (hw_ip.dram_size > 0) |
| 64 | hw_ip.dram_enabled = 1; |
| 65 | hw_ip.num_of_events = prop->num_of_events; |
| 66 | memcpy(hw_ip.armcp_version, |
| 67 | prop->armcp_info.armcp_version, VERSION_MAX_LEN); |
Oded Gabbay | 8c84487 | 2019-02-28 10:46:24 +0200 | [diff] [blame] | 68 | hw_ip.armcp_cpld_version = __le32_to_cpu(prop->armcp_info.cpld_version); |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 69 | hw_ip.psoc_pci_pll_nr = prop->psoc_pci_pll_nr; |
| 70 | hw_ip.psoc_pci_pll_nf = prop->psoc_pci_pll_nf; |
| 71 | hw_ip.psoc_pci_pll_od = prop->psoc_pci_pll_od; |
| 72 | hw_ip.psoc_pci_pll_div_factor = prop->psoc_pci_pll_div_factor; |
| 73 | |
| 74 | return copy_to_user(out, &hw_ip, |
| 75 | min((size_t)size, sizeof(hw_ip))) ? -EFAULT : 0; |
| 76 | } |
| 77 | |
| 78 | static int hw_events_info(struct hl_device *hdev, struct hl_info_args *args) |
| 79 | { |
| 80 | u32 size, max_size = args->return_size; |
| 81 | void __user *out = (void __user *) (uintptr_t) args->return_pointer; |
| 82 | void *arr; |
| 83 | |
| 84 | if ((!max_size) || (!out)) |
| 85 | return -EINVAL; |
| 86 | |
| 87 | arr = hdev->asic_funcs->get_events_stat(hdev, &size); |
| 88 | |
| 89 | return copy_to_user(out, arr, min(max_size, size)) ? -EFAULT : 0; |
| 90 | } |
| 91 | |
Oded Gabbay | 02e921e | 2019-07-30 11:48:02 +0300 | [diff] [blame] | 92 | static int dram_usage_info(struct hl_fpriv *hpriv, struct hl_info_args *args) |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 93 | { |
Oded Gabbay | 02e921e | 2019-07-30 11:48:02 +0300 | [diff] [blame] | 94 | struct hl_device *hdev = hpriv->hdev; |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 95 | struct hl_info_dram_usage dram_usage = {0}; |
| 96 | u32 max_size = args->return_size; |
| 97 | void __user *out = (void __user *) (uintptr_t) args->return_pointer; |
| 98 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
| 99 | u64 dram_kmd_size; |
| 100 | |
| 101 | if ((!max_size) || (!out)) |
| 102 | return -EINVAL; |
| 103 | |
| 104 | dram_kmd_size = (prop->dram_user_base_address - |
| 105 | prop->dram_base_address); |
| 106 | dram_usage.dram_free_mem = (prop->dram_size - dram_kmd_size) - |
| 107 | atomic64_read(&hdev->dram_used_mem); |
Oded Gabbay | 02e921e | 2019-07-30 11:48:02 +0300 | [diff] [blame] | 108 | if (hpriv->ctx) |
| 109 | dram_usage.ctx_dram_mem = |
| 110 | atomic64_read(&hpriv->ctx->dram_phys_mem); |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 111 | |
| 112 | return copy_to_user(out, &dram_usage, |
| 113 | min((size_t) max_size, sizeof(dram_usage))) ? -EFAULT : 0; |
| 114 | } |
| 115 | |
| 116 | static int hw_idle(struct hl_device *hdev, struct hl_info_args *args) |
| 117 | { |
| 118 | struct hl_info_hw_idle hw_idle = {0}; |
| 119 | u32 max_size = args->return_size; |
| 120 | void __user *out = (void __user *) (uintptr_t) args->return_pointer; |
| 121 | |
| 122 | if ((!max_size) || (!out)) |
| 123 | return -EINVAL; |
| 124 | |
Tomer Tayar | e8960ca | 2019-07-01 13:59:45 +0000 | [diff] [blame] | 125 | hw_idle.is_idle = hdev->asic_funcs->is_device_idle(hdev, |
| 126 | &hw_idle.busy_engines_mask, NULL); |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 127 | |
| 128 | return copy_to_user(out, &hw_idle, |
| 129 | min((size_t) max_size, sizeof(hw_idle))) ? -EFAULT : 0; |
| 130 | } |
| 131 | |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 132 | static int debug_coresight(struct hl_device *hdev, struct hl_debug_args *args) |
| 133 | { |
| 134 | struct hl_debug_params *params; |
| 135 | void *input = NULL, *output = NULL; |
| 136 | int rc; |
| 137 | |
| 138 | params = kzalloc(sizeof(*params), GFP_KERNEL); |
| 139 | if (!params) |
| 140 | return -ENOMEM; |
| 141 | |
| 142 | params->reg_idx = args->reg_idx; |
| 143 | params->enable = args->enable; |
| 144 | params->op = args->op; |
| 145 | |
| 146 | if (args->input_ptr && args->input_size) { |
Omer Shpigelman | 8d17593 | 2019-08-06 07:37:59 +0000 | [diff] [blame^] | 147 | input = kzalloc(hl_debug_struct_size[args->op], GFP_KERNEL); |
| 148 | if (!input) { |
| 149 | rc = -ENOMEM; |
| 150 | goto out; |
| 151 | } |
| 152 | |
| 153 | if (copy_from_user(input, u64_to_user_ptr(args->input_ptr), |
| 154 | args->input_size)) { |
| 155 | rc = -EFAULT; |
| 156 | dev_err(hdev->dev, "failed to copy input debug data\n"); |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 157 | goto out; |
| 158 | } |
| 159 | |
| 160 | params->input = input; |
| 161 | } |
| 162 | |
| 163 | if (args->output_ptr && args->output_size) { |
| 164 | output = kzalloc(args->output_size, GFP_KERNEL); |
| 165 | if (!output) { |
| 166 | rc = -ENOMEM; |
| 167 | goto out; |
| 168 | } |
| 169 | |
| 170 | params->output = output; |
| 171 | params->output_size = args->output_size; |
| 172 | } |
| 173 | |
| 174 | rc = hdev->asic_funcs->debug_coresight(hdev, params); |
| 175 | if (rc) { |
| 176 | dev_err(hdev->dev, |
| 177 | "debug coresight operation failed %d\n", rc); |
| 178 | goto out; |
| 179 | } |
| 180 | |
| 181 | if (output) { |
| 182 | if (copy_to_user((void __user *) (uintptr_t) args->output_ptr, |
| 183 | output, |
| 184 | args->output_size)) { |
| 185 | dev_err(hdev->dev, |
| 186 | "copy to user failed in debug ioctl\n"); |
| 187 | rc = -EFAULT; |
| 188 | goto out; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | out: |
| 193 | kfree(params); |
| 194 | kfree(output); |
| 195 | kfree(input); |
| 196 | |
| 197 | return rc; |
| 198 | } |
| 199 | |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 200 | static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data, |
| 201 | struct device *dev) |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 202 | { |
| 203 | struct hl_info_args *args = data; |
| 204 | struct hl_device *hdev = hpriv->hdev; |
| 205 | int rc; |
| 206 | |
Dalit Ben Zoor | aa95708 | 2019-03-24 10:15:44 +0200 | [diff] [blame] | 207 | /* We want to return device status even if it disabled or in reset */ |
| 208 | if (args->op == HL_INFO_DEVICE_STATUS) |
| 209 | return device_status_info(hdev, args); |
| 210 | |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 211 | if (hl_device_disabled_or_in_reset(hdev)) { |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 212 | dev_warn_ratelimited(dev, |
Oded Gabbay | 3f5398c | 2019-04-06 15:41:35 +0300 | [diff] [blame] | 213 | "Device is %s. Can't execute INFO IOCTL\n", |
| 214 | atomic_read(&hdev->in_reset) ? "in_reset" : "disabled"); |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 215 | return -EBUSY; |
| 216 | } |
| 217 | |
| 218 | switch (args->op) { |
| 219 | case HL_INFO_HW_IP_INFO: |
| 220 | rc = hw_ip_info(hdev, args); |
| 221 | break; |
| 222 | |
| 223 | case HL_INFO_HW_EVENTS: |
| 224 | rc = hw_events_info(hdev, args); |
| 225 | break; |
| 226 | |
| 227 | case HL_INFO_DRAM_USAGE: |
Oded Gabbay | 02e921e | 2019-07-30 11:48:02 +0300 | [diff] [blame] | 228 | rc = dram_usage_info(hpriv, args); |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 229 | break; |
| 230 | |
| 231 | case HL_INFO_HW_IDLE: |
| 232 | rc = hw_idle(hdev, args); |
| 233 | break; |
| 234 | |
| 235 | default: |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 236 | dev_err(dev, "Invalid request %d\n", args->op); |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 237 | rc = -ENOTTY; |
| 238 | break; |
| 239 | } |
| 240 | |
| 241 | return rc; |
| 242 | } |
| 243 | |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 244 | static int hl_info_ioctl(struct hl_fpriv *hpriv, void *data) |
| 245 | { |
| 246 | return _hl_info_ioctl(hpriv, data, hpriv->hdev->dev); |
| 247 | } |
| 248 | |
| 249 | static int hl_info_ioctl_control(struct hl_fpriv *hpriv, void *data) |
| 250 | { |
| 251 | return _hl_info_ioctl(hpriv, data, hpriv->hdev->dev_ctrl); |
| 252 | } |
| 253 | |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 254 | static int hl_debug_ioctl(struct hl_fpriv *hpriv, void *data) |
| 255 | { |
| 256 | struct hl_debug_args *args = data; |
| 257 | struct hl_device *hdev = hpriv->hdev; |
| 258 | int rc = 0; |
| 259 | |
| 260 | if (hl_device_disabled_or_in_reset(hdev)) { |
| 261 | dev_warn_ratelimited(hdev->dev, |
| 262 | "Device is %s. Can't execute DEBUG IOCTL\n", |
| 263 | atomic_read(&hdev->in_reset) ? "in_reset" : "disabled"); |
| 264 | return -EBUSY; |
| 265 | } |
| 266 | |
| 267 | switch (args->op) { |
| 268 | case HL_DEBUG_OP_ETR: |
| 269 | case HL_DEBUG_OP_ETF: |
| 270 | case HL_DEBUG_OP_STM: |
| 271 | case HL_DEBUG_OP_FUNNEL: |
| 272 | case HL_DEBUG_OP_BMON: |
| 273 | case HL_DEBUG_OP_SPMU: |
| 274 | case HL_DEBUG_OP_TIMESTAMP: |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 275 | if (!hdev->in_debug) { |
Oded Gabbay | 29a7aad | 2019-06-06 09:28:45 +0300 | [diff] [blame] | 276 | dev_err_ratelimited(hdev->dev, |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 277 | "Rejecting debug configuration request because device not in debug mode\n"); |
| 278 | return -EFAULT; |
| 279 | } |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 280 | args->input_size = |
| 281 | min(args->input_size, hl_debug_struct_size[args->op]); |
| 282 | rc = debug_coresight(hdev, args); |
| 283 | break; |
Oded Gabbay | 1973497 | 2019-05-04 17:36:06 +0300 | [diff] [blame] | 284 | case HL_DEBUG_OP_SET_MODE: |
| 285 | rc = hl_device_set_debug_mode(hdev, (bool) args->enable); |
| 286 | break; |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 287 | default: |
| 288 | dev_err(hdev->dev, "Invalid request %d\n", args->op); |
| 289 | rc = -ENOTTY; |
| 290 | break; |
| 291 | } |
| 292 | |
| 293 | return rc; |
| 294 | } |
| 295 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 296 | #define HL_IOCTL_DEF(ioctl, _func) \ |
| 297 | [_IOC_NR(ioctl)] = {.cmd = ioctl, .func = _func} |
| 298 | |
| 299 | static const struct hl_ioctl_desc hl_ioctls[] = { |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 300 | HL_IOCTL_DEF(HL_IOCTL_INFO, hl_info_ioctl), |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 301 | HL_IOCTL_DEF(HL_IOCTL_CB, hl_cb_ioctl), |
| 302 | HL_IOCTL_DEF(HL_IOCTL_CS, hl_cs_ioctl), |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 303 | HL_IOCTL_DEF(HL_IOCTL_WAIT_CS, hl_cs_wait_ioctl), |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 304 | HL_IOCTL_DEF(HL_IOCTL_MEMORY, hl_mem_ioctl), |
| 305 | HL_IOCTL_DEF(HL_IOCTL_DEBUG, hl_debug_ioctl) |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 306 | }; |
| 307 | |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 308 | static const struct hl_ioctl_desc hl_ioctls_control[] = { |
| 309 | HL_IOCTL_DEF(HL_IOCTL_INFO, hl_info_ioctl_control) |
| 310 | }; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 311 | |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 312 | static long _hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg, |
| 313 | const struct hl_ioctl_desc *ioctl, struct device *dev) |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 314 | { |
| 315 | struct hl_fpriv *hpriv = filep->private_data; |
| 316 | struct hl_device *hdev = hpriv->hdev; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 317 | unsigned int nr = _IOC_NR(cmd); |
| 318 | char stack_kdata[128] = {0}; |
| 319 | char *kdata = NULL; |
| 320 | unsigned int usize, asize; |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 321 | hl_ioctl_t *func; |
| 322 | u32 hl_size; |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 323 | int retcode; |
| 324 | |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 325 | if (hdev->hard_reset_pending) { |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 326 | dev_crit_ratelimited(hdev->dev_ctrl, |
Oded Gabbay | f8c8c7d5 | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 327 | "Device HARD reset pending! Please close FD\n"); |
| 328 | return -ENODEV; |
| 329 | } |
| 330 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 331 | /* Do not trust userspace, use our own definition */ |
| 332 | func = ioctl->func; |
| 333 | |
| 334 | if (unlikely(!func)) { |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 335 | dev_dbg(dev, "no function\n"); |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 336 | retcode = -ENOTTY; |
| 337 | goto out_err; |
| 338 | } |
| 339 | |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 340 | hl_size = _IOC_SIZE(ioctl->cmd); |
| 341 | usize = asize = _IOC_SIZE(cmd); |
| 342 | if (hl_size > asize) |
| 343 | asize = hl_size; |
| 344 | |
| 345 | cmd = ioctl->cmd; |
| 346 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 347 | if (cmd & (IOC_IN | IOC_OUT)) { |
| 348 | if (asize <= sizeof(stack_kdata)) { |
| 349 | kdata = stack_kdata; |
| 350 | } else { |
| 351 | kdata = kzalloc(asize, GFP_KERNEL); |
| 352 | if (!kdata) { |
| 353 | retcode = -ENOMEM; |
| 354 | goto out_err; |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | if (cmd & IOC_IN) { |
| 360 | if (copy_from_user(kdata, (void __user *)arg, usize)) { |
| 361 | retcode = -EFAULT; |
| 362 | goto out_err; |
| 363 | } |
| 364 | } else if (cmd & IOC_OUT) { |
| 365 | memset(kdata, 0, usize); |
| 366 | } |
| 367 | |
| 368 | retcode = func(hpriv, kdata); |
| 369 | |
| 370 | if (cmd & IOC_OUT) |
| 371 | if (copy_to_user((void __user *)arg, kdata, usize)) |
| 372 | retcode = -EFAULT; |
| 373 | |
| 374 | out_err: |
| 375 | if (retcode) |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 376 | dev_dbg(dev, "error in ioctl: pid=%d, cmd=0x%02x, nr=0x%02x\n", |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 377 | task_pid_nr(current), cmd, nr); |
| 378 | |
| 379 | if (kdata != stack_kdata) |
| 380 | kfree(kdata); |
| 381 | |
| 382 | return retcode; |
| 383 | } |
Oded Gabbay | 4d6a775 | 2019-07-30 09:10:50 +0300 | [diff] [blame] | 384 | |
| 385 | long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) |
| 386 | { |
| 387 | struct hl_fpriv *hpriv = filep->private_data; |
| 388 | struct hl_device *hdev = hpriv->hdev; |
| 389 | const struct hl_ioctl_desc *ioctl = NULL; |
| 390 | unsigned int nr = _IOC_NR(cmd); |
| 391 | |
| 392 | if ((nr >= HL_COMMAND_START) && (nr < HL_COMMAND_END)) { |
| 393 | ioctl = &hl_ioctls[nr]; |
| 394 | } else { |
| 395 | dev_err(hdev->dev, "invalid ioctl: pid=%d, nr=0x%02x\n", |
| 396 | task_pid_nr(current), nr); |
| 397 | return -ENOTTY; |
| 398 | } |
| 399 | |
| 400 | return _hl_ioctl(filep, cmd, arg, ioctl, hdev->dev); |
| 401 | } |
| 402 | |
| 403 | long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg) |
| 404 | { |
| 405 | struct hl_fpriv *hpriv = filep->private_data; |
| 406 | struct hl_device *hdev = hpriv->hdev; |
| 407 | const struct hl_ioctl_desc *ioctl = NULL; |
| 408 | unsigned int nr = _IOC_NR(cmd); |
| 409 | |
| 410 | if (nr == _IOC_NR(HL_IOCTL_INFO)) { |
| 411 | ioctl = &hl_ioctls_control[nr]; |
| 412 | } else { |
| 413 | dev_err(hdev->dev_ctrl, "invalid ioctl: pid=%d, nr=0x%02x\n", |
| 414 | task_pid_nr(current), nr); |
| 415 | return -ENOTTY; |
| 416 | } |
| 417 | |
| 418 | return _hl_ioctl(filep, cmd, arg, ioctl, hdev->dev_ctrl); |
| 419 | } |