diff --git a/drivers/misc/mods/mods_acpi.c b/drivers/misc/mods/mods_acpi.c index 5ae360e4..45c14fb6 100644 --- a/drivers/misc/mods/mods_acpi.c +++ b/drivers/misc/mods/mods_acpi.c @@ -2,7 +2,7 @@ /* * mods_acpi.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2008-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2008-2020, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -35,7 +35,9 @@ static acpi_status mods_acpi_find_acpi_handler(acpi_handle, *********************/ /* store handle if found. */ -static void mods_acpi_handle_init(char *method_name, acpi_handle *handler) +static void mods_acpi_handle_init(struct mods_client *client, + char *method_name, + acpi_handle *handler) { MODS_ACPI_WALK_NAMESPACE(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, @@ -45,9 +47,9 @@ static void mods_acpi_handle_init(char *method_name, acpi_handle *handler) handler); if (!(*handler)) { - mods_debug_printk(DEBUG_ACPI, "ACPI method %s not found\n", - method_name); - return; + cl_debug(DEBUG_ACPI, + "ACPI method %s not found\n", + method_name); } } @@ -66,12 +68,11 @@ static acpi_status mods_acpi_find_acpi_handler( return OK; } -static int mods_extract_acpi_object( - char *method, - union acpi_object *obj, - u8 **buf, - u8 *buf_end -) +static int mods_extract_acpi_object(struct mods_client *client, + char *method, + union acpi_object *obj, + u8 **buf, + u8 *buf_end) { int err = OK; @@ -79,8 +80,9 @@ static int mods_extract_acpi_object( case ACPI_TYPE_BUFFER: if (obj->buffer.length == 0) { - mods_error_printk("empty ACPI output buffer from ACPI method %s\n", - method); + cl_error( + "empty ACPI output buffer from ACPI method %s\n", + method); err = -EINVAL; } else if (obj->buffer.length <= buf_end-*buf) { u32 size = obj->buffer.length; @@ -88,8 +90,8 @@ static int mods_extract_acpi_object( memcpy(*buf, obj->buffer.pointer, size); *buf += size; } else { - mods_error_printk("output buffer too small for ACPI method %s\n", - method); + cl_error("output buffer too small for ACPI method %s\n", + method); err = -EINVAL; } break; @@ -97,24 +99,26 @@ static int mods_extract_acpi_object( case ACPI_TYPE_INTEGER: if (buf_end - *buf >= 4) { if (obj->integer.value > 0xFFFFFFFFU) { - mods_error_printk("integer value from ACPI method %s out of range\n", - method); + cl_error( + "integer value from ACPI method %s out of range\n", + method); err = -EINVAL; } else { memcpy(*buf, &obj->integer.value, 4); *buf += 4; } } else { - mods_error_printk("output buffer too small for ACPI method %s\n", - method); + cl_error("output buffer too small for ACPI method %s\n", + method); err = -EINVAL; } break; case ACPI_TYPE_PACKAGE: if (obj->package.count == 0) { - mods_error_printk("empty ACPI output package from ACPI method %s\n", - method); + cl_error( + "empty ACPI output package from ACPI method %s\n", + method); err = -EINVAL; } else { union acpi_object *elements = obj->package.elements; @@ -125,7 +129,8 @@ static int mods_extract_acpi_object( u8 *old_buf = *buf; u32 new_size; - err = mods_extract_acpi_object(method, + err = mods_extract_acpi_object(client, + method, &elements[i], buf, buf_end); @@ -137,8 +142,9 @@ static int mods_extract_acpi_object( if (size == 0) { size = new_size; } else if (size != new_size) { - mods_error_printk("ambiguous package element size from ACPI method %s\n", - method); + cl_error( + "ambiguous package element size from ACPI method %s\n", + method); err = -EINVAL; } } @@ -146,8 +152,9 @@ static int mods_extract_acpi_object( break; default: - mods_error_printk("unsupported ACPI output type 0x%02x from method %s\n", - (unsigned int)obj->type, method); + cl_error("unsupported ACPI output type 0x%02x from method %s\n", + (unsigned int)obj->type, + method); err = -EINVAL; break; @@ -176,42 +183,45 @@ static int mods_eval_acpi_method(struct mods_client *client, LOG_ENT(); if (p->argument_count >= ACPI_MAX_ARGUMENT_NUMBER) { - mods_error_printk("invalid argument count for ACPI call\n"); + cl_error("invalid argument count for ACPI call\n"); LOG_EXT(); return -EINVAL; } if (pdevice) { - mods_debug_printk(DEBUG_ACPI, - "ACPI %s for device %04x:%02x:%02x.%x\n", - p->method_name, - pdevice->domain, - pdevice->bus, - pdevice->device, - pdevice->function); + cl_debug(DEBUG_ACPI, + "ACPI %s for dev %04x:%02x:%02x.%x\n", + p->method_name, + pdevice->domain, + pdevice->bus, + pdevice->device, + pdevice->function); err = mods_find_pci_dev(client, pdevice, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("ACPI: PCI device %04x:%02x:%02x.%x not found\n", - pdevice->domain, - pdevice->bus, - pdevice->device, - pdevice->function); + cl_error( + "ACPI: dev %04x:%02x:%02x.%x not found\n", + pdevice->domain, + pdevice->bus, + pdevice->device, + pdevice->function); LOG_EXT(); return err; } acpi_method_handler = MODS_ACPI_HANDLE(&dev->dev); } else { - mods_debug_printk(DEBUG_ACPI, "ACPI %s\n", p->method_name); - mods_acpi_handle_init(p->method_name, &acpi_method_handler); + cl_debug(DEBUG_ACPI, "ACPI %s\n", p->method_name); + mods_acpi_handle_init(client, + p->method_name, + &acpi_method_handler); } if (acpi_id != ACPI_MODS_IGNORE_ACPI_ID) { status = acpi_bus_get_device(acpi_method_handler, &acpi_dev); if (ACPI_FAILURE(status) || !acpi_dev) { - mods_error_printk("ACPI: device for %s not found\n", - p->method_name); + cl_error("ACPI: device for %s not found\n", + p->method_name); pci_dev_put(dev); LOG_EXT(); return -EINVAL; @@ -237,22 +247,23 @@ static int mods_eval_acpi_method(struct mods_client *client, if (device_id == acpi_id) { acpi_method_handler = acpi_dev->handle; - mods_debug_printk(DEBUG_ACPI, - "ACPI: Found %s (id = 0x%x) on device %04x:%02x:%02x.%x\n", - p->method_name, - (unsigned int)device_id, - pdevice->domain, - pdevice->bus, - pdevice->device, - pdevice->function); + cl_debug(DEBUG_ACPI, + "ACPI: found %s (id = 0x%x) on dev %04x:%02x:%02x.%x\n", + p->method_name, + (unsigned int)device_id, + pdevice->domain, + pdevice->bus, + pdevice->device, + pdevice->function); break; } } } if (!acpi_method_handler) { - mods_debug_printk(DEBUG_ACPI, "ACPI: handle for %s not found\n", - p->method_name); + cl_debug(DEBUG_ACPI, + "ACPI: handle for %s not found\n", + p->method_name); pci_dev_put(dev); LOG_EXT(); return -EINVAL; @@ -275,7 +286,7 @@ static int mods_eval_acpi_method(struct mods_client *client, break; } default: { - mods_error_printk("unsupported ACPI argument type\n"); + cl_error("unsupported ACPI argument type\n"); pci_dev_put(dev); LOG_EXT(); return -EINVAL; @@ -292,7 +303,7 @@ static int mods_eval_acpi_method(struct mods_client *client, &output); if (ACPI_FAILURE(status)) { - mods_error_printk("ACPI method %s failed\n", p->method_name); + cl_error("ACPI method %s failed\n", p->method_name); pci_dev_put(dev); LOG_EXT(); return -EINVAL; @@ -300,13 +311,14 @@ static int mods_eval_acpi_method(struct mods_client *client, acpi_method = output.pointer; if (!acpi_method) { - mods_error_printk("missing output from ACPI method %s\n", - p->method_name); + cl_error("missing output from ACPI method %s\n", + p->method_name); err = -EINVAL; } else { u8 *buf = p->out_buffer; - err = mods_extract_acpi_object(p->method_name, + err = mods_extract_acpi_object(client, + p->method_name, acpi_method, &buf, buf+sizeof(p->out_buffer)); @@ -339,29 +351,28 @@ static int mods_acpi_get_ddc(struct mods_client *client, LOG_ENT(); - mods_debug_printk(DEBUG_ACPI, - "ACPI _DDC (EDID) for device %04x:%02x:%02x.%x\n", - pci_device->domain, - pci_device->bus, - pci_device->device, - pci_device->function); + cl_debug(DEBUG_ACPI, + "ACPI _DDC (EDID) for dev %04x:%02x:%02x.%x\n", + pci_device->domain, + pci_device->bus, + pci_device->device, + pci_device->function); err = mods_find_pci_dev(client, pci_device, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("ACPI: PCI device %04x:%02x:%02x.%x not found\n", - pci_device->domain, - pci_device->bus, - pci_device->device, - pci_device->function); + cl_error("ACPI: dev %04x:%02x:%02x.%x not found\n", + pci_device->domain, + pci_device->bus, + pci_device->device, + pci_device->function); LOG_EXT(); return err; } dev_handle = MODS_ACPI_HANDLE(&dev->dev); if (!dev_handle) { - mods_debug_printk(DEBUG_ACPI, - "ACPI: handle for _DDC not found\n"); + cl_debug(DEBUG_ACPI, "ACPI: handle for _DDC not found\n"); pci_dev_put(dev); LOG_EXT(); return -EINVAL; @@ -369,7 +380,7 @@ static int mods_acpi_get_ddc(struct mods_client *client, status = acpi_bus_get_device(dev_handle, &device); if (ACPI_FAILURE(status) || !device) { - mods_error_printk("ACPI: device for _DDC not found\n"); + cl_error("ACPI: device for _DDC not found\n"); pci_dev_put(dev); LOG_EXT(); return -EINVAL; @@ -399,25 +410,24 @@ static int mods_acpi_get_ddc(struct mods_client *client, (device_id == 0x0400)) { lcd_dev_handle = dev->handle; - mods_debug_printk(DEBUG_ACPI, - "ACPI: Found LCD 0x%x on device %04x:%02x:%02x.%x\n", - (unsigned int)device_id, - p->device.domain, - p->device.bus, - p->device.device, - p->device.function); + cl_debug(DEBUG_ACPI, + "ACPI: Found LCD 0x%llx on dev %04x:%02x:%02x.%x\n", + device_id, + p->device.domain, + p->device.bus, + p->device.device, + p->device.function); break; } } if (lcd_dev_handle == NULL) { - mods_error_printk( - "ACPI: LCD not found for device %04x:%02x:%02x.%x\n", - p->device.domain, - p->device.bus, - p->device.device, - p->device.function); + cl_error("ACPI: LCD not found for dev %04x:%02x:%02x.%x\n", + p->device.domain, + p->device.bus, + p->device.device, + p->device.function); pci_dev_put(dev); LOG_EXT(); return -EINVAL; @@ -439,7 +449,7 @@ static int mods_acpi_get_ddc(struct mods_client *client, } if (ACPI_FAILURE(status)) { - mods_error_printk("ACPI method _DDC (EDID) failed\n"); + cl_error("ACPI method _DDC (EDID) failed\n"); pci_dev_put(dev); LOG_EXT(); return -EINVAL; @@ -456,12 +466,12 @@ static int mods_acpi_get_ddc(struct mods_client *client, p->out_data_size); err = OK; } else { - mods_error_printk( - "output buffer too small for ACPI method _DDC (EDID)\n"); + cl_error( + "output buffer too small for ACPI method _DDC (EDID)\n"); err = -EINVAL; } } else { - mods_error_printk("unsupported ACPI output type\n"); + cl_error("unsupported ACPI output type\n"); err = -EINVAL; } diff --git a/drivers/misc/mods/mods_adsp.c b/drivers/misc/mods/mods_adsp.c index 29fb9409..b64a8ad5 100644 --- a/drivers/misc/mods/mods_adsp.c +++ b/drivers/misc/mods/mods_adsp.c @@ -1,7 +1,7 @@ /* * mods_adsp.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2014-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -48,7 +48,7 @@ int esc_mods_adsp_run_app(struct mods_client *client, handle = nvadsp_app_load(p->app_name, p->app_file_name); if (!handle) { - mods_error_printk("load adsp app fail"); + cl_error("load adsp app fail"); return -1; } @@ -60,14 +60,14 @@ int esc_mods_adsp_run_app(struct mods_client *client, p_app_info = nvadsp_app_init(handle, NULL); if (!p_app_info) { - mods_error_printk("init adsp app fail"); + cl_error("init adsp app fail"); nvadsp_app_unload(handle); return -1; } rc = nvadsp_app_start(p_app_info); if (rc) { - mods_error_printk("start adsp app fail"); + cl_error("start adsp app fail"); goto failed; } @@ -77,10 +77,10 @@ int esc_mods_adsp_run_app(struct mods_client *client, if (rc == -ERESTARTSYS) continue; else if (rc == 0) { - mods_error_printk("app timeout(%d)", p->timeout); + cl_error("app timeout(%d)", p->timeout); rc = -1; } else if (rc < 0) { - mods_error_printk("run app failed, err=%d\n", rc); + cl_error("run app failed, err=%d\n", rc); rc = -1; } else rc = 0; diff --git a/drivers/misc/mods/mods_clock.c b/drivers/misc/mods/mods_clock.c index e2ae85cd..78719404 100644 --- a/drivers/misc/mods/mods_clock.c +++ b/drivers/misc/mods/mods_clock.c @@ -1,7 +1,7 @@ /* * mods_clock.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2011-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2011-2020, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -176,12 +176,12 @@ int esc_mods_get_clock_handle(struct mods_client *client, mods_np = find_clocks_node("mods-clocks"); if (!mods_np || !of_device_is_available(mods_np)) { - mods_error_printk("'mods-clocks' node not found in device tree\n"); + cl_error("'mods-clocks' node not found in device tree\n"); goto err; } pp = of_find_property(mods_np, "clock-names", NULL); if (IS_ERR(pp)) { - mods_error_printk( + cl_error( "No 'clock-names' prop in 'mods-clocks' node for dev %s\n", p->controller_name); goto err; @@ -190,7 +190,7 @@ int esc_mods_get_clock_handle(struct mods_client *client, pclk = of_clk_get_by_name(mods_np, p->controller_name); if (IS_ERR(pclk)) - mods_error_printk("clk (%s) not found\n", p->controller_name); + cl_error("clk (%s) not found\n", p->controller_name); else { p->clock_handle = mods_get_clock_handle(pclk); ret = OK; @@ -212,18 +212,18 @@ int esc_mods_set_clock_rate(struct mods_client *client, pclk = mods_get_clock(p->clock_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else { ret = clk_set_rate(pclk, p->clock_rate_hz); if (ret) { - mods_error_printk( + cl_error( "unable to set rate %lluHz on clock 0x%x\n", p->clock_rate_hz, p->clock_handle); } else { - mods_debug_printk(DEBUG_CLOCK, - "successfuly set rate %lluHz on clock 0x%x\n", - p->clock_rate_hz, p->clock_handle); + cl_debug(DEBUG_CLOCK, + "successfuly set rate %lluHz on clock 0x%x\n", + p->clock_rate_hz, p->clock_handle); } } @@ -242,12 +242,12 @@ int esc_mods_get_clock_rate(struct mods_client *client, pclk = mods_get_clock(p->clock_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else { p->clock_rate_hz = clk_get_rate(pclk); - mods_debug_printk(DEBUG_CLOCK, "clock 0x%x has rate %lluHz\n", - p->clock_handle, p->clock_rate_hz); + cl_debug(DEBUG_CLOCK, "clock 0x%x has rate %lluHz\n", + p->clock_handle, p->clock_rate_hz); ret = OK; } @@ -265,16 +265,15 @@ int esc_mods_get_clock_max_rate(struct mods_client *client, pclk = mods_get_clock(p->clock_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", - p->clock_handle); + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else { long rate = clk_round_rate(pclk, ARBITRARY_MAX_CLK_FREQ); p->clock_rate_hz = rate < 0 ? ARBITRARY_MAX_CLK_FREQ : (unsigned long)rate; - mods_debug_printk(DEBUG_CLOCK, - "clock 0x%x has max rate %lluHz\n", - p->clock_handle, p->clock_rate_hz); + cl_debug(DEBUG_CLOCK, + "clock 0x%x has max rate %lluHz\n", + p->clock_handle, p->clock_rate_hz); ret = OK; } @@ -293,24 +292,23 @@ int esc_mods_set_clock_max_rate(struct mods_client *client, pclk = mods_get_clock(p->clock_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", - p->clock_handle); + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else { #if defined(CONFIG_TEGRA_CLOCK_DEBUG_FUNC) ret = tegra_clk_set_max(pclk, p->clock_rate_hz); if (ret) { - mods_error_printk( - "unable to override max clock rate %lluHz on clock 0x%x\n", - p->clock_rate_hz, p->clock_handle); + cl_error( + "unable to override max clock rate %lluHz on clock 0x%x\n", + p->clock_rate_hz, p->clock_handle); } else { - mods_debug_printk(DEBUG_CLOCK, - "successfuly set max rate %lluHz on clock 0x%x\n", - p->clock_rate_hz, p->clock_handle); + cl_debug(DEBUG_CLOCK, + "successfuly set max rate %lluHz on clock 0x%x\n", + p->clock_rate_hz, p->clock_handle); } #else - mods_error_printk("unable to override max clock rate\n"); - mods_error_printk( - "reconfigure kernel with CONFIG_TEGRA_CLOCK_DEBUG_FUNC=y\n"); + cl_error("unable to override max clock rate\n"); + cl_error( + "reconfigure kernel with CONFIG_TEGRA_CLOCK_DEBUG_FUNC=y\n"); ret = -EINVAL; #endif } @@ -332,21 +330,20 @@ int esc_mods_set_clock_parent(struct mods_client *client, pparent = mods_get_clock(p->clock_parent_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", - p->clock_handle); + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else if (!pparent) { - mods_error_printk("unrecognized parent clock handle: 0x%x\n", - p->clock_parent_handle); + cl_error("unrecognized parent clock handle: 0x%x\n", + p->clock_parent_handle); } else { ret = clk_set_parent(pclk, pparent); if (ret) { - mods_error_printk( - "unable to make clock 0x%x parent of clock 0x%x\n", - p->clock_parent_handle, p->clock_handle); + cl_error( + "unable to make clock 0x%x parent of clock 0x%x\n", + p->clock_parent_handle, p->clock_handle); } else { - mods_debug_printk(DEBUG_CLOCK, - "successfuly made clock 0x%x parent of clock 0x%x\n", - p->clock_parent_handle, p->clock_handle); + cl_debug(DEBUG_CLOCK, + "successfuly made clock 0x%x parent of clock 0x%x\n", + p->clock_parent_handle, p->clock_handle); } } @@ -365,15 +362,14 @@ int esc_mods_get_clock_parent(struct mods_client *client, pclk = mods_get_clock(p->clock_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", - p->clock_handle); + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else { struct clk *pparent = clk_get_parent(pclk); p->clock_parent_handle = mods_get_clock_handle(pparent); - mods_debug_printk(DEBUG_CLOCK, - "clock 0x%x is parent of clock 0x%x\n", - p->clock_parent_handle, p->clock_handle); + cl_debug(DEBUG_CLOCK, + "clock 0x%x is parent of clock 0x%x\n", + p->clock_parent_handle, p->clock_handle); ret = OK; } @@ -392,22 +388,21 @@ int esc_mods_enable_clock(struct mods_client *client, pclk = mods_get_clock(p->clock_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", - p->clock_handle); + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else { ret = clk_prepare(pclk); if (ret) { - mods_error_printk( - "unable to prepare clock 0x%x before enabling\n", - p->clock_handle); + cl_error( + "unable to prepare clock 0x%x before enabling\n", + p->clock_handle); } ret = clk_enable(pclk); if (ret) { - mods_error_printk("failed to enable clock 0x%x\n", - p->clock_handle); + cl_error("failed to enable clock 0x%x\n", + p->clock_handle); } else { - mods_debug_printk(DEBUG_CLOCK, "clock 0x%x enabled\n", - p->clock_handle); + cl_debug(DEBUG_CLOCK, "clock 0x%x enabled\n", + p->clock_handle); } } @@ -426,13 +421,12 @@ int esc_mods_disable_clock(struct mods_client *client, pclk = mods_get_clock(p->clock_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", - p->clock_handle); + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else { clk_disable(pclk); clk_unprepare(pclk); - mods_debug_printk(DEBUG_CLOCK, "clock 0x%x disabled\n", - p->clock_handle); + cl_debug(DEBUG_CLOCK, "clock 0x%x disabled\n", + p->clock_handle); ret = OK; } @@ -451,12 +445,11 @@ int esc_mods_is_clock_enabled(struct mods_client *client, pclk = mods_get_clock(p->clock_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", - p->clock_handle); + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else { p->enable_count = (u32)__clk_is_enabled(pclk); - mods_debug_printk(DEBUG_CLOCK, "clock 0x%x enable count is %u\n", - p->clock_handle, p->enable_count); + cl_debug(DEBUG_CLOCK, "clock 0x%x enable count is %u\n", + p->clock_handle, p->enable_count); ret = OK; } @@ -475,8 +468,7 @@ int esc_mods_clock_reset_assert(struct mods_client *client, pclk = mods_get_clock(p->clock_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", - p->clock_handle); + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else { const char *clk_name = 0; struct reset_control *prst = 0; @@ -485,14 +477,14 @@ int esc_mods_clock_reset_assert(struct mods_client *client, mods_np = find_clocks_node("mods-clocks"); if (!mods_np || !of_device_is_available(mods_np)) { - mods_error_printk("'mods-clocks' node not found in DTB\n"); + cl_error("'mods-clocks' node not found in DTB\n"); goto err; } pp = of_find_property(mods_np, "reset-names", NULL); if (IS_ERR(pp)) { - mods_error_printk( - "No 'reset-names' prop in 'mods-clocks' node for dev %s\n", - __clk_get_name(pclk)); + cl_error( + "No 'reset-names' prop in 'mods-clocks' node for dev %s\n", + __clk_get_name(pclk)); goto err; } @@ -500,17 +492,15 @@ int esc_mods_clock_reset_assert(struct mods_client *client, prst = of_reset_control_get(mods_np, clk_name); if (IS_ERR(prst)) { - mods_error_printk("reset device %s not found\n", - clk_name); + cl_error("reset device %s not found\n", clk_name); goto err; } ret = reset_control_assert(prst); if (ret) { - mods_error_printk("failed to assert reset on '%s'\n", - clk_name); + cl_error("failed to assert reset on '%s'\n", clk_name); } else { - mods_debug_printk(DEBUG_CLOCK, "asserted reset on '%s'", - clk_name); + cl_debug(DEBUG_CLOCK, "asserted reset on '%s'", + clk_name); } err: @@ -531,8 +521,7 @@ int esc_mods_clock_reset_deassert(struct mods_client *client, pclk = mods_get_clock(p->clock_handle); if (!pclk) { - mods_error_printk("unrecognized clock handle: 0x%x\n", - p->clock_handle); + cl_error("unrecognized clock handle: 0x%x\n", p->clock_handle); } else { const char *clk_name = 0; struct reset_control *prst = 0; @@ -541,14 +530,14 @@ int esc_mods_clock_reset_deassert(struct mods_client *client, mods_np = find_clocks_node("mods-clocks"); if (!mods_np || !of_device_is_available(mods_np)) { - mods_error_printk("'mods-clocks' node not found in DTB\n"); + cl_error("'mods-clocks' node not found in DTB\n"); goto err; } pp = of_find_property(mods_np, "reset-names", NULL); if (IS_ERR(pp)) { - mods_error_printk( - "No 'reset-names' prop in 'mods-clocks' node for dev %s\n", - __clk_get_name(pclk)); + cl_error( + "No 'reset-names' prop in 'mods-clocks' node for dev %s\n", + __clk_get_name(pclk)); goto err; } @@ -556,17 +545,15 @@ int esc_mods_clock_reset_deassert(struct mods_client *client, prst = of_reset_control_get(mods_np, clk_name); if (IS_ERR(prst)) { - mods_error_printk( - "reset device %s not found\n", clk_name); + cl_error("reset device %s not found\n", clk_name); goto err; } ret = reset_control_deassert(prst); if (ret) { - mods_error_printk("failed to assert reset on '%s'\n", - clk_name); + cl_error("failed to assert reset on '%s'\n", clk_name); } else { - mods_debug_printk(DEBUG_CLOCK, "deasserted reset on '%s'", - clk_name); + cl_debug(DEBUG_CLOCK, "deasserted reset on '%s'", + clk_name); } err: diff --git a/drivers/misc/mods/mods_dma.c b/drivers/misc/mods/mods_dma.c index 15fac63b..dbc0b930 100644 --- a/drivers/misc/mods/mods_dma.c +++ b/drivers/misc/mods/mods_dma.c @@ -1,7 +1,7 @@ /* * mods_dma.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -211,19 +211,19 @@ int esc_mods_dma_request_channel(struct mods_client *client, ret = mods_get_dma_id(&id); if (ret != OK) { - mods_error_printk("no dma handle available\n"); + cl_error("no dma handle available\n"); return ret; } ret = mods_get_chan_by_id(id, &p_mods_chan); if (ret != OK) { - mods_error_printk("get dma channel failed\n"); + cl_error("get dma channel failed\n"); return ret; } read_lock(&(p_mods_chan->lock)); if (p_mods_chan->in_use) { - mods_error_printk("mods dma channel in use\n"); + cl_error("mods dma channel in use\n"); read_unlock(&(p_mods_chan->lock)); return -EBUSY; } @@ -233,7 +233,7 @@ int esc_mods_dma_request_channel(struct mods_client *client, dma_cap_set(p_handle->dma_type, mask); chan = dma_request_channel(mask, NULL, NULL); if (!chan) { - mods_error_printk("Dma channel is not available\n"); + cl_error("dma channel is not available\n"); mods_release_dma_id(id); return -EBUSY; } @@ -244,8 +244,7 @@ int esc_mods_dma_request_channel(struct mods_client *client, write_unlock(&(p_mods_chan->lock)); p_handle->dma_id = id; - mods_debug_printk(DEBUG_TEGRADMA, - "request get dma id: %d\n", id); + cl_debug(DEBUG_TEGRADMA, "request get dma id: %d\n", id); LOG_EXT(); return 0; @@ -281,16 +280,16 @@ int esc_mods_dma_set_config(struct mods_client *client, config.device_fc = (p_config->device_fc == 0) ? false : true; config.slave_id = p_config->slave_id; - mods_debug_printk(DEBUG_TEGRADMA, - "ch: %d dir [%d], addr[%p -> %p], burst [%d %d]", - p_config->handle.dma_id, - config.direction, - (void *)config.src_addr, (void *)config.dst_addr, - config.src_maxburst, config.dst_maxburst); - mods_debug_printk(DEBUG_TEGRADMA, - "width [%d %d] slave id %d\n", - config.src_addr_width, config.dst_addr_width, - config.slave_id); + cl_debug(DEBUG_TEGRADMA, + "ch: %d dir [%d], addr[%p -> %p], burst [%d %d]", + p_config->handle.dma_id, + config.direction, + (void *)config.src_addr, (void *)config.dst_addr, + config.src_maxburst, config.dst_maxburst); + cl_debug(DEBUG_TEGRADMA, + "width [%d %d] slave id %d\n", + config.src_addr_width, config.dst_addr_width, + config.slave_id); write_lock(&(p_mods_chan->lock)); ret = dmaengine_slave_config(p_mods_chan->pch, &config); @@ -320,12 +319,11 @@ int esc_mods_dma_submit_request(struct mods_client *client, return ret; if (p_mods_desc->mode != MODS_DMA_SINGLE) { - mods_error_printk("Unsupported Mode: %d\n", p_mods_desc->mode); + cl_error("unsupported mode: %d\n", p_mods_desc->mode); return -EINVAL; } - mods_debug_printk(DEBUG_TEGRADMA, - "Submit on chan %p\n", p_mods_chan->pch); + cl_debug(DEBUG_TEGRADMA, "submit on chan %p\n", p_mods_chan->pch); write_lock(&(p_mods_chan->lock)); if (p_mods_desc->data_dir == MODS_DMA_MEM_TO_MEM) { @@ -337,21 +335,20 @@ int esc_mods_dma_submit_request(struct mods_client *client, p_mods_desc->length, flags); } else { - mods_debug_printk(DEBUG_TEGRADMA, - "Phys Addr [%p], len [%d], dir [%d]\n", - (void *)p_mods_desc->phys, - p_mods_desc->length, - p_mods_desc->data_dir); - desc = dmaengine_prep_slave_single( - p_mods_chan->pch, - p_mods_desc->phys, - p_mods_desc->length, - p_mods_desc->data_dir, - flags); + cl_debug(DEBUG_TEGRADMA, + "Phys Addr [%p], len [%d], dir [%d]\n", + (void *)p_mods_desc->phys, + p_mods_desc->length, + p_mods_desc->data_dir); + desc = dmaengine_prep_slave_single(p_mods_chan->pch, + p_mods_desc->phys, + p_mods_desc->length, + p_mods_desc->data_dir, + flags); } if (desc == NULL) { - mods_error_printk("Not able to get desc for Tx\n"); + cl_error("unable to get desc for Tx\n"); ret = -EIO; goto failed; } @@ -363,7 +360,7 @@ int esc_mods_dma_submit_request(struct mods_client *client, failed: write_unlock(&(p_mods_chan->lock)); if (dma_submit_error(cookie)) { - mods_info_printk("Submit cookie: %x Error\n", cookie); + cl_error("submit cookie: %x\n", cookie); return -EIO; } @@ -384,8 +381,8 @@ int esc_mods_dma_async_issue_pending(struct mods_client *client, if (ret != OK) return ret; - mods_debug_printk(DEBUG_TEGRADMA, - "Issue pending on chan: %p\n", p_mods_chan->pch); + cl_debug(DEBUG_TEGRADMA, "issue pending on chan: %p\n", + p_mods_chan->pch); read_lock(&(p_mods_chan->lock)); dma_async_issue_pending(p_mods_chan->pch); read_unlock(&(p_mods_chan->lock)); @@ -427,20 +424,18 @@ int esc_mods_dma_alloc_coherent(struct mods_client *client, &p_phys_addr, GFP_KERNEL); - mods_debug_printk(DEBUG_MEM, - "%s:num_bytes=%d, p_cpu_addr=%p, p_phys_addr=%p\n", - __func__, - p->num_bytes, - (void *)p_cpu_addr, - (void *)p_phys_addr); + cl_debug(DEBUG_MEM, + "num_bytes=%d, p_cpu_addr=%p, p_phys_addr=%p\n", + p->num_bytes, + (void *)p_cpu_addr, + (void *)p_phys_addr); if (!p_cpu_addr) { - mods_error_printk( - "%s:FAILED!!!num_bytes=%d, p_cpu_addr=%p, p_phys_addr=%p\n", - __func__, - p->num_bytes, - (void *)p_cpu_addr, - (void *)p_phys_addr); + cl_error( + "FAILED!!!num_bytes=%d, p_cpu_addr=%p, p_phys_addr=%p\n", + p->num_bytes, + (void *)p_cpu_addr, + (void *)p_phys_addr); LOG_EXT(); return -1; } @@ -459,12 +454,11 @@ int esc_mods_dma_free_coherent(struct mods_client *client, { LOG_ENT(); - mods_debug_printk(DEBUG_MEM, - "%s : num_bytes = %d, p_cpu_addr=%p, p_phys_addr=%p\n", - __func__, - p->num_bytes, - (void *)(p->memory_handle_virt), - (void *)(p->memory_handle_phys)); + cl_debug(DEBUG_MEM, + "num_bytes = %d, p_cpu_addr=%p, p_phys_addr=%p\n", + p->num_bytes, + (void *)(p->memory_handle_virt), + (void *)(p->memory_handle_phys)); dma_free_coherent(NULL, p->num_bytes, @@ -485,12 +479,11 @@ int esc_mods_dma_copy_to_user(struct mods_client *client, LOG_ENT(); - mods_debug_printk(DEBUG_MEM, - "%s:memory_handle_dst=%p, memory_handle_src=%p, num_bytes=%d\n", - __func__, - (void *)(p->memory_handle_dst), - (void *)(p->memory_handle_src), - p->num_bytes); + cl_debug(DEBUG_MEM, + "memory_handle_dst=%p, memory_handle_src=%p, num_bytes=%d\n", + (void *)(p->memory_handle_dst), + (void *)(p->memory_handle_src), + p->num_bytes); retval = copy_to_user((void *)(p->memory_handle_dst), (void *)(p->memory_handle_src), diff --git a/drivers/misc/mods/mods_dmabuf.c b/drivers/misc/mods/mods_dmabuf.c index 1e48ae8b..55937f40 100644 --- a/drivers/misc/mods/mods_dmabuf.c +++ b/drivers/misc/mods/mods_dmabuf.c @@ -1,7 +1,7 @@ /* * mods_dmabuf.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2014-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -29,10 +29,6 @@ #include "mods_internal.h" -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) -extern const struct dma_map_ops swiotlb_dma_ops; -#endif - static struct device *dummy_device; static bool dummy_device_registered; @@ -54,13 +50,13 @@ int esc_mods_dmabuf_get_phys_addr(struct mods_client *client, LOG_ENT(); - mods_debug_printk(DEBUG_MEM_DETAILED, "%s: fd=%d offs=0x%llx\n", - __func__, op->buf_fd, (unsigned long long)op->offset); + cl_debug(DEBUG_MEM_DETAILED, + "dmabuf get phys addr fd=%d offs=0x%llx\n", + op->buf_fd, (unsigned long long)op->offset); dmabuf = dma_buf_get(op->buf_fd); if (IS_ERR_OR_NULL(dmabuf)) { - mods_error_printk("%s: failed to get dma buf from fd %d\n", - __func__, op->buf_fd); + cl_error("failed to get dma buf from fd %d\n", op->buf_fd); LOG_EXT(); return IS_ERR(dmabuf) ? PTR_ERR(dmabuf) : -EINVAL; } @@ -68,14 +64,14 @@ int esc_mods_dmabuf_get_phys_addr(struct mods_client *client, WARN_ON(!dummy_device_registered); attachment = dma_buf_attach(dmabuf, dummy_device); if (IS_ERR_OR_NULL(attachment)) { - mods_error_printk("%s: failed to attach dma buf\n", __func__); + cl_error("failed to attach dma buf fd %d\n", op->buf_fd); err = IS_ERR(attachment) ? PTR_ERR(attachment) : -EFAULT; goto buf_attach_fail; } sgt = dma_buf_map_attachment(attachment, DMA_BIDIRECTIONAL); if (IS_ERR_OR_NULL(sgt)) { - mods_error_printk("%s: failed to map dma buf\n", __func__); + cl_error("failed to map dma buf fd %d\n", op->buf_fd); err = IS_ERR(sgt) ? PTR_ERR(sgt) : -EFAULT; goto buf_map_fail; } @@ -100,14 +96,16 @@ int esc_mods_dmabuf_get_phys_addr(struct mods_client *client, } } - mods_debug_printk(DEBUG_MEM_DETAILED, "%s: traversed %u segments, 0x%llx size\n", - __func__, total_segments, - (unsigned long long) total_size); + cl_debug(DEBUG_MEM_DETAILED, "traversed %u segments, 0x%llx size\n", + total_segments, + (unsigned long long)total_size); if (segment_size == 0) { - mods_error_printk("%s: offset 0x%llx exceeds allocation size 0x%llx\n", - __func__, (unsigned long long)op->offset, - total_size); + cl_error( + "offset 0x%llx exceeds allocation size 0x%llx, fd %d\n", + (unsigned long long)op->offset, + (unsigned long long)total_size, + op->buf_fd); err = -EINVAL; } else { op->physical_address = physical_address; diff --git a/drivers/misc/mods/mods_internal.h b/drivers/misc/mods/mods_internal.h index 433ccc6b..1a9c86df 100644 --- a/drivers/misc/mods/mods_internal.h +++ b/drivers/misc/mods/mods_internal.h @@ -59,6 +59,9 @@ struct en_dev_entry { struct msix_entry *msix_entries; u32 irq_flags; u32 nvecs; +#ifdef MODS_HAS_SRIOV + u32 num_vfs; +#endif u8 client_id; }; @@ -253,14 +256,30 @@ struct NVL_TRAINED { pr_info("mods debug: " fmt, ##args); \ }) +#define cl_debug(level, fmt, args...)\ + ({ \ + if (mods_check_debug_level(level)) \ + pr_info("mods [%u] debug: " fmt, client->client_id, \ + ##args); \ + }) + #define mods_info_printk(fmt, args...)\ pr_info("mods: " fmt, ##args) +#define cl_info(fmt, args...)\ + pr_info("mods [%u]: " fmt, client->client_id, ##args) + #define mods_error_printk(fmt, args...)\ - pr_info("mods error: " fmt, ##args) + pr_err("mods error: " fmt, ##args) + +#define cl_error(fmt, args...)\ + pr_err("mods [%u] error: " fmt, client->client_id, ##args) #define mods_warning_printk(fmt, args...)\ - pr_info("mods warning: " fmt, ##args) + pr_notice("mods warning: " fmt, ##args) + +#define cl_warn(fmt, args...)\ + pr_notice("mods [%u] warning: " fmt, client->client_id, ##args) struct irq_mask_info { u32 *dev_irq_mask_reg; /*IRQ mask register, read-only reg*/ @@ -374,7 +393,8 @@ int mods_unregister_all_nvlink_sysmem_trained(struct mods_client *client); int mods_enable_device(struct mods_client *client, struct pci_dev *dev, struct en_dev_entry **dev_entry); -void mods_disable_device(struct pci_dev *pdev); +void mods_disable_device(struct mods_client *client, + struct pci_dev *pdev); #endif #ifdef CONFIG_PCI diff --git a/drivers/misc/mods/mods_irq.c b/drivers/misc/mods/mods_irq.c index 08471bec..f84dd00d 100644 --- a/drivers/misc/mods/mods_irq.c +++ b/drivers/misc/mods/mods_irq.c @@ -65,22 +65,23 @@ int mods_enable_device(struct mods_client *client, int err = OK; struct en_dev_entry *dpriv = client->enabled_devices; - BUG_ON(!mutex_is_locked(&mp.mtx)); + WARN_ON(!mutex_is_locked(&mp.mtx)); dpriv = pci_get_drvdata(dev); - if (unlikely(dpriv)) { + if (dpriv) { if (dpriv->client_id == client->client_id) { if (dev_entry) *dev_entry = dpriv; return OK; } - mods_error_printk("invalid client %u for device %04x:%02x:%02x.%x\n", - client->client_id, - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_error( + "invalid client for dev %04x:%02x:%02x.%x, expected %u\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + dpriv->client_id); return -EBUSY; } @@ -91,16 +92,22 @@ int mods_enable_device(struct mods_client *client, err = pci_enable_device(dev); if (unlikely(err)) { - mods_error_printk("failed to enable device %04x:%02x:%02x.%x\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_error("failed to enable dev %04x:%02x:%02x.%x\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); kfree(dpriv); atomic_dec(&client->num_allocs); return err; } + cl_info("enabled dev %04x:%02x:%02x.%x\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); + dpriv->client_id = client->client_id; dpriv->dev = pci_dev_get(dev); dpriv->next = client->enabled_devices; @@ -112,11 +119,17 @@ int mods_enable_device(struct mods_client *client, return OK; } -void mods_disable_device(struct pci_dev *dev) +void mods_disable_device(struct mods_client *client, + struct pci_dev *dev) { struct en_dev_entry *dpriv = pci_get_drvdata(dev); - BUG_ON(!mutex_is_locked(&mp.mtx)); + WARN_ON(!mutex_is_locked(&mp.mtx)); + +#ifdef MODS_HAS_SRIOV + if (dpriv->num_vfs) + pci_disable_sriov(dev); +#endif if (dpriv) { pci_set_drvdata(dev, NULL); @@ -124,6 +137,12 @@ void mods_disable_device(struct pci_dev *dev) } pci_disable_device(dev); + + cl_info("disabled dev %04x:%02x:%02x.%x\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); } #endif @@ -187,7 +206,9 @@ static void mods_disable_interrupts(struct dev_irq_map *t) } } if ((ii == 0) && t->type == MODS_IRQ_TYPE_CPU) { - mods_debug_printk(DEBUG_ISR, "IRQ_DISABLE_NOSYNC "); + mods_debug_printk(DEBUG_ISR, + "disable_irq_nosync %u", + t->apic_irq); disable_irq_nosync(t->apic_irq); } } @@ -223,13 +244,12 @@ static void wake_up_client(struct dev_irq_map *t) wake_up_interruptible(&client->interrupt_event); } -static int rec_irq_done(struct dev_irq_map *t, +static int rec_irq_done(struct mods_client *client, + struct dev_irq_map *t, unsigned int irq_time) { - struct irq_q_info *q; - /* Get interrupt queue */ - q = &client_from_id(t->client_id)->irq_queue; + struct irq_q_info *q = &client->irq_queue; /* Don't do anything if the IRQ has already been recorded */ if (q->head != q->tail) { @@ -262,7 +282,7 @@ static int rec_irq_done(struct dev_irq_map *t, #ifdef CONFIG_PCI if (t->dev) { mods_debug_printk(DEBUG_ISR_DETAILED, - "%04x:%02x:%02x.%x %s IRQ 0x%x time=%uus\n", + "dev %04x:%02x:%02x.%x %s IRQ 0x%x time=%uus\n", pci_domain_nr(t->dev->bus), t->dev->bus->number, PCI_SLOT(t->dev->devfn), @@ -309,7 +329,7 @@ static irqreturn_t mods_irq_handle(int irq, void *data) mods_disable_interrupts(t); /* Record IRQ for MODS and wake MODS up */ - recorded = rec_irq_done(t, irq_time); + recorded = rec_irq_done(client, t, irq_time); serviced = true; } @@ -343,12 +363,8 @@ static int mods_lookup_cpu_irq(u8 client_id, unsigned int irq) list) { if (t->apic_irq == irq) { - if (client_id == 0) { - ret = IRQ_FOUND; - } else { - ret = (client_id == client_idx) - ? IRQ_FOUND : IRQ_NOT_FOUND; - } + ret = (!client_id || client_id == client_idx) + ? IRQ_FOUND : IRQ_NOT_FOUND; /* Break out of the outer loop */ client_idx = MODS_MAX_CLIENTS; @@ -416,10 +432,10 @@ static int add_irq_map(struct mods_client *client, u32 irq, u32 entry) { - u32 irq_type = MODS_IRQ_TYPE_FROM_FLAGS(p->irq_flags); struct dev_irq_map *newmap = NULL; - u64 irq_flags = MODS_IRQ_FLAG_FROM_FLAGS(p->irq_flags); u64 valid_mask = IRQF_TRIGGER_NONE; + u64 irq_flags = MODS_IRQ_FLAG_FROM_FLAGS(p->irq_flags); + u32 irq_type = MODS_IRQ_TYPE_FROM_FLAGS(p->irq_flags); LOG_ENT(); @@ -436,8 +452,8 @@ static int add_irq_map(struct mods_client *client, /* Either use a valid flag bit or no flags */ if (irq_flags & ~valid_mask) { - mods_error_printk("invalid Device Interrupt flag %llx\n", - (long long) irq_flags); + cl_error("invalid device interrupt flag %llx\n", + (long long)irq_flags); return -EINVAL; } break; @@ -456,24 +472,23 @@ static int add_irq_map(struct mods_client *client, atomic_inc(&client->num_allocs); /* Fill out the new entry */ - newmap->apic_irq = irq; - newmap->dev = dev; - newmap->client_id = client->client_id; + newmap->apic_irq = irq; + newmap->dev = dev; + newmap->client_id = client->client_id; newmap->dev_irq_aperture = 0; - newmap->mask_info_cnt = 0; - newmap->type = irq_type; - newmap->entry = entry; + newmap->mask_info_cnt = 0; + newmap->type = irq_type; + newmap->entry = entry; /* Enable IRQ for this device in the kernel */ - if (request_irq( - irq, + if (request_irq(irq, &mods_irq_handle, irq_flags, "nvidia mods", newmap)) { - mods_error_printk("unable to enable IRQ 0x%x with flags %llx\n", - irq, - (long long) irq_flags); + cl_error("unable to enable IRQ 0x%x with flags %llx\n", + irq, + (long long)irq_flags); kfree(newmap); atomic_dec(&client->num_allocs); LOG_EXT(); @@ -491,9 +506,10 @@ static int add_irq_map(struct mods_client *client, char *bar = ioremap_nocache(p->aperture_addr, p->aperture_size); if (!bar) { - mods_debug_printk(DEBUG_ISR, - "failed to remap aperture: 0x%llx size=0x%x\n", - p->aperture_addr, p->aperture_size); + cl_debug(DEBUG_ISR, + "failed to remap aperture: 0x%llx size=0x%x\n", + p->aperture_addr, + p->aperture_size); LOG_EXT(); return -EPERM; } @@ -508,21 +524,22 @@ static int add_irq_map(struct mods_client *client, /* Print out successful registration string */ if (irq_type == MODS_IRQ_TYPE_CPU) - mods_debug_printk(DEBUG_ISR, "registered CPU IRQ 0x%x with flags %llx\n", - irq, - (long long) irq_flags); + cl_debug(DEBUG_ISR, + "registered CPU IRQ 0x%x with flags %llx\n", + irq, + (long long)irq_flags); #ifdef CONFIG_PCI else if ((irq_type == MODS_IRQ_TYPE_INT) || (irq_type == MODS_IRQ_TYPE_MSI) || (irq_type == MODS_IRQ_TYPE_MSIX)) { - mods_debug_printk(DEBUG_ISR, - "%04x:%02x:%02x.%x registered %s IRQ 0x%x\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn), - mods_irq_type_name(irq_type), - irq); + cl_debug(DEBUG_ISR, + "dev %04x:%02x:%02x.%x registered %s IRQ 0x%x\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + mods_irq_type_name(irq_type), + irq); } #endif #ifdef CONFIG_PCI_MSI @@ -540,22 +557,22 @@ static int add_irq_map(struct mods_client *client, pci_read_config_word(dev, MSI_DATA_REG(cap_pos, 0), &data); - mods_debug_printk(DEBUG_ISR, - "%04x:%02x:%02x.%x registered MSI IRQ 0x%x data:0x%02x\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn), - irq, - data); + cl_debug(DEBUG_ISR, + "dev %04x:%02x:%02x.%x registered MSI IRQ 0x%x data:0x%02x\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + irq, + data); } else if (irq_type == MODS_IRQ_TYPE_MSIX) { - mods_debug_printk(DEBUG_ISR, - "%04x:%02x:%02x.%x registered MSI-X IRQ 0x%x\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn), - irq); + cl_debug(DEBUG_ISR, + "dev %04x:%02x:%02x.%x registered MSI-X IRQ 0x%x\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + irq); } #endif @@ -563,13 +580,15 @@ static int add_irq_map(struct mods_client *client, return OK; } -static void mods_free_map(struct dev_irq_map *del) +static void mods_free_map(struct mods_client *client, + struct dev_irq_map *del) { unsigned long flags = 0; - struct mods_client *client = client_from_id(del->client_id); LOG_ENT(); + WARN_ON(client->client_id != del->client_id); + /* Disable interrupts on the device */ spin_lock_irqsave(&client->irq_lock, flags); mods_disable_interrupts(del); @@ -645,14 +664,14 @@ struct mods_client *mods_alloc_client(void) if (!test_and_set_bit(idx - 1, &mp.client_flags)) { struct mods_client *client = client_from_id(idx); - mods_debug_printk(DEBUG_IOCTL, - "open client %u (bit mask 0x%lx)\n", - (unsigned int)idx, - mp.client_flags); - memset(client, 0, sizeof(*client)); - client->client_id = idx; + client->client_id = idx; client->access_token = MODS_ACCESS_TOKEN_NONE; + + cl_debug(DEBUG_IOCTL, + "open client (bit mask 0x%lx)\n", + mp.client_flags); + mutex_init(&client->mtx); spin_lock_init(&client->irq_lock); init_waitqueue_head(&client->interrupt_event); @@ -674,10 +693,10 @@ struct mods_client *mods_alloc_client(void) return NULL; } -static int mods_free_irqs(u8 client_id, struct pci_dev *dev) +static int mods_free_irqs(struct mods_client *client, + struct pci_dev *dev) { #ifdef CONFIG_PCI - struct mods_client *client = client_from_id(client_id); struct dev_irq_map *del = NULL; struct dev_irq_map *next; struct en_dev_entry *dpriv; @@ -699,25 +718,26 @@ static int mods_free_irqs(u8 client_id, struct pci_dev *dev) } if (dpriv->client_id != client->client_id) { - mods_error_printk("invalid client %u for device %04x:%02x:%02x.%x\n", - client->client_id, - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_error( + "invalid client for dev %04x:%02x:%02x.%x, expected %u\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + dpriv->client_id); mutex_unlock(&mp.mtx); LOG_EXT(); return -EINVAL; } - mods_debug_printk(DEBUG_ISR_DETAILED, - "(dev=%04x:%02x:%02x.%x) irq_flags=0x%x nvecs=%d\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn), - dpriv->irq_flags, - dpriv->nvecs); + cl_debug(DEBUG_ISR_DETAILED, + "free IRQ for dev %04x:%02x:%02x.%x irq_flags=0x%x nvecs=%d\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + dpriv->irq_flags, + dpriv->nvecs); /* Delete device interrupts from the list */ list_for_each_entry_safe(del, next, &client->irq_list, list) { @@ -725,24 +745,24 @@ static int mods_free_irqs(u8 client_id, struct pci_dev *dev) u8 type = del->type; list_del(&del->list); - mods_debug_printk(DEBUG_ISR, - "%04x:%02x:%02x.%x unregistered %s IRQ 0x%x\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn), - mods_irq_type_name(type), - del->apic_irq); - mods_free_map(del); + cl_debug(DEBUG_ISR, + "unregistered %s IRQ 0x%x dev %04x:%02x:%02x.%x\n", + mods_irq_type_name(type), + del->apic_irq, + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); + mods_free_map(client, del); - BUG_ON(type != - MODS_IRQ_TYPE_FROM_FLAGS(dpriv->irq_flags)); + WARN_ON(MODS_IRQ_TYPE_FROM_FLAGS(dpriv->irq_flags) + != type); if (type != MODS_IRQ_TYPE_MSIX) break; } } - mods_debug_printk(DEBUG_ISR_DETAILED, "before disable\n"); + cl_debug(DEBUG_ISR_DETAILED, "before disable\n"); #ifdef CONFIG_PCI_MSI irq_type = MODS_IRQ_TYPE_FROM_FLAGS(dpriv->irq_flags); @@ -758,7 +778,7 @@ static int mods_free_irqs(u8 client_id, struct pci_dev *dev) #endif dpriv->nvecs = 0; - mods_debug_printk(DEBUG_ISR_DETAILED, "irqs freed\n"); + cl_debug(DEBUG_ISR_DETAILED, "irqs freed\n"); #endif mutex_unlock(&mp.mtx); @@ -774,7 +794,7 @@ void mods_free_client_interrupts(struct mods_client *client) /* Release all interrupts */ while (dpriv) { - mods_free_irqs(client->client_id, dpriv->dev); + mods_free_irqs(client, dpriv->dev); dpriv = dpriv->next; } @@ -792,8 +812,7 @@ void mods_free_client(u8 client_id) /* Indicate the client_id is free */ clear_bit(client_id - 1, &mp.client_flags); - mods_debug_printk(DEBUG_IOCTL, "closed client %u\n", - (unsigned int)client_id); + cl_debug(DEBUG_IOCTL, "closed client\n"); LOG_EXT(); } @@ -809,45 +828,46 @@ static int mods_allocate_irqs(struct mods_client *client, LOG_ENT(); - mods_debug_printk(DEBUG_ISR_DETAILED, - "(dev=%04x:%02x:%02x.%x, flags=0x%x, nvecs=%d)\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn), - flags, - nvecs); + cl_debug(DEBUG_ISR_DETAILED, + "allocate %u IRQs on dev %04x:%02x:%02x.%x, flags=0x%x\n", + nvecs, + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + flags); /* Determine if the device supports requested interrupt type */ if (irq_type == MODS_IRQ_TYPE_MSI) { #ifdef CONFIG_PCI_MSI if (pci_find_capability(dev, PCI_CAP_ID_MSI) == 0) { - mods_error_printk("dev %04x:%02x:%02x.%x does not support MSI\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_error("dev %04x:%02x:%02x.%x does not support MSI\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); LOG_EXT(); return -ENOENT; } #else - mods_error_printk("the kernel does not support MSI!\n"); + cl_error("the kernel does not support MSI\n"); LOG_EXT(); return -EINVAL; #endif } else if (irq_type == MODS_IRQ_TYPE_MSIX) { #ifdef CONFIG_PCI_MSI if (pci_find_capability(dev, PCI_CAP_ID_MSIX) == 0) { - mods_error_printk("dev %04x:%02x:%02x.%x does not support MSI-X\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_error( + "dev %04x:%02x:%02x.%x does not support MSI-X\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); LOG_EXT(); return -ENOENT; } #else - mods_error_printk("the kernel does not support MSI-X!\n"); + cl_error("the kernel does not support MSI-X\n"); LOG_EXT(); return -EINVAL; #endif @@ -863,7 +883,8 @@ static int mods_allocate_irqs(struct mods_client *client, if (irq_type == MODS_IRQ_TYPE_INT) { /* use legacy irq */ if (nvecs != 1) { - mods_error_printk("INTA: only 1 INTA vector supported, requested %u!\n", + cl_error( + "INTA: only 1 INTA vector supported, requested %u\n", nvecs); LOG_EXT(); return -EINVAL; @@ -874,18 +895,20 @@ static int mods_allocate_irqs(struct mods_client *client, #ifdef CONFIG_PCI_MSI else if (irq_type == MODS_IRQ_TYPE_MSI) { if (nvecs != 1) { - mods_error_printk("MSI: only 1 MSI vector supported, requested %u!\n", + cl_error( + "MSI: only 1 MSI vector supported, requested %u\n", nvecs); LOG_EXT(); return -EINVAL; } err = pci_enable_msi(dev); if (err) { - mods_error_printk("unable to enable MSI on dev %04x:%02x:%02x.%x\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_error( + "unable to enable MSI on dev %04x:%02x:%02x.%x\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); LOG_EXT(); return err; } @@ -898,8 +921,8 @@ static int mods_allocate_irqs(struct mods_client *client, GFP_KERNEL | __GFP_NORETRY); if (!entries) { - mods_error_printk("could not allocate %d MSI-X entries!\n", - nvecs); + cl_error("could not allocate %d MSI-X entries\n", + nvecs); LOG_EXT(); return -ENOMEM; } @@ -915,7 +938,7 @@ static int mods_allocate_irqs(struct mods_client *client, /* returns number of interrupts allocated * < 0 indicates a failure. */ - mods_error_printk( + cl_error( "could not allocate the requested number of MSI-X vectors=%d return=%d!\n", nvecs, cnt); kfree(entries); @@ -932,7 +955,7 @@ static int mods_allocate_irqs(struct mods_client *client, * exceeding the number of irqs or MSI-X * vectors available */ - mods_error_printk( + cl_error( "could not allocate the requested number of MSI-X vectors=%d return=%d!\n", nvecs, cnt); kfree(entries); @@ -944,30 +967,34 @@ static int mods_allocate_irqs(struct mods_client *client, } #endif - mods_debug_printk(DEBUG_ISR, - "allocated %d irq's of type %s(%d)\n", - nvecs, mods_irq_type_name(irq_type), irq_type); + cl_debug(DEBUG_ISR, + "allocated %d irq's of type %s(%d)\n", + nvecs, + mods_irq_type_name(irq_type), + irq_type); for (i = 0; i < nvecs; i++) - mods_debug_printk(DEBUG_ISR, "vec %d %x\n", - entries[i].entry, entries[i].vector); + cl_debug(DEBUG_ISR, + "vec %d %x\n", + entries[i].entry, + entries[i].vector); dpriv->nvecs = nvecs; dpriv->msix_entries = entries; } #endif else { - mods_error_printk("unsupported irq_type %d dev: %04x:%02x:%02x.%x\n", - irq_type, - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_error("unsupported irq_type %u dev %04x:%02x:%02x.%x\n", + irq_type, + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); LOG_EXT(); return -EINVAL; } - dpriv->client_id = client->client_id; + WARN_ON(dpriv->client_id != client->client_id); dpriv->irq_flags = flags; LOG_EXT(); return OK; @@ -985,7 +1012,7 @@ static int mods_register_pci_irq(struct mods_client *client, LOG_ENT(); if (unlikely(!p->irq_count)) { - mods_error_printk("no irq's requested!\n"); + cl_error("no irq's requested\n"); LOG_EXT(); return -EINVAL; } @@ -994,11 +1021,11 @@ static int mods_register_pci_irq(struct mods_client *client, err = mods_find_pci_dev(client, &p->dev, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", - p->dev.domain, - p->dev.bus, - p->dev.device, - p->dev.function); + cl_error("dev %04x:%02x:%02x.%x not found\n", + p->dev.domain, + p->dev.bus, + p->dev.device, + p->dev.function); LOG_EXT(); return err; } @@ -1012,23 +1039,25 @@ static int mods_register_pci_irq(struct mods_client *client, dpriv = pci_get_drvdata(dev); if (dpriv) { if (dpriv->client_id != client->client_id) { - mods_error_printk("dev %04x:%02x:%02x.%x already owned by client %u\n", - p->dev.domain, - p->dev.bus, - p->dev.device, - p->dev.function, - dpriv->client_id); + cl_error( + "dev %04x:%02x:%02x.%x already owned by client %u\n", + p->dev.domain, + p->dev.bus, + p->dev.device, + p->dev.function, + dpriv->client_id); mutex_unlock(&mp.mtx); pci_dev_put(dev); LOG_EXT(); return -EBUSY; } if (dpriv->nvecs) { - mods_error_printk("interrupt for dev %04x:%02x:%02x.%x already registered\n", - p->dev.domain, - p->dev.bus, - p->dev.device, - p->dev.function); + cl_error( + "interrupt for dev %04x:%02x:%02x.%x already registered\n", + p->dev.domain, + p->dev.bus, + p->dev.device, + p->dev.function); mutex_unlock(&mp.mtx); pci_dev_put(dev); LOG_EXT(); @@ -1039,8 +1068,8 @@ static int mods_register_pci_irq(struct mods_client *client, err = mods_allocate_irqs(client, dev, p->irq_count, p->irq_flags); if (err) { - mods_error_printk("could not allocate irqs for irq_type %d\n", - irq_type); + cl_error("could not allocate irqs for irq_type %d\n", + irq_type); mutex_unlock(&mp.mtx); pci_dev_put(dev); LOG_EXT(); @@ -1088,8 +1117,7 @@ static int mods_register_cpu_irq(struct mods_client *client, /* Determine if the interrupt is already hooked */ if (mods_lookup_cpu_irq(0, irq) == IRQ_FOUND) { - mods_error_printk("CPU IRQ 0x%x has already been registered\n", - irq); + cl_error("CPU IRQ 0x%x has already been registered\n", irq); mutex_unlock(&mp.mtx); LOG_EXT(); return -EINVAL; @@ -1119,7 +1147,7 @@ static int mods_unregister_pci_irq(struct mods_client *client, return err; } - err = mods_free_irqs(client->client_id, dev); + err = mods_free_irqs(client, dev); pci_dev_put(dev); LOG_EXT(); @@ -1145,9 +1173,7 @@ static int mods_unregister_cpu_irq(struct mods_client *client, /* Determine if the interrupt is already hooked by this client */ if (mods_lookup_cpu_irq(client->client_id, irq) == IRQ_NOT_FOUND) { - mods_error_printk( - "IRQ 0x%x not hooked, can't unhook\n", - irq); + cl_error("IRQ 0x%x not hooked, can't unhook\n", irq); mutex_unlock(&mp.mtx); LOG_EXT(); return -EINVAL; @@ -1157,16 +1183,16 @@ static int mods_unregister_cpu_irq(struct mods_client *client, list_for_each_entry_safe(del, next, &client->irq_list, list) { if ((irq == del->apic_irq) && (del->dev == 0)) { if (del->type != p->type) { - mods_error_printk("wrong IRQ type passed\n"); + cl_error("wrong IRQ type passed\n"); mutex_unlock(&mp.mtx); LOG_EXT(); return -EINVAL; } list_del(&del->list); - mods_debug_printk(DEBUG_ISR, - "unregistered CPU IRQ 0x%x\n", - irq); - mods_free_map(del); + cl_debug(DEBUG_ISR, + "unregistered CPU IRQ 0x%x\n", + irq); + mods_free_map(client, del); break; } } @@ -1190,7 +1216,7 @@ int esc_mods_register_irq_4(struct mods_client *client, #ifdef CONFIG_PCI return mods_register_pci_irq(client, p); #else - mods_error_printk("PCI not available\n"); + cl_error("PCI not available\n"); return -EINVAL; #endif } @@ -1336,21 +1362,21 @@ int esc_mods_query_irq_3(struct mods_client *client, /* Print info about IRQ status returned */ if (dev) { - mods_debug_printk(DEBUG_ISR_DETAILED, - "retrieved IRQ index=%d dev %04x:%02x:%02x.%x, time=%uus, delay=%uus\n", - p->irq_list[i].irq_index, - p->irq_list[i].dev.domain, - p->irq_list[i].dev.bus, - p->irq_list[i].dev.device, - p->irq_list[i].dev.function, - q->data[index].time, - p->irq_list[i].delay); + cl_debug(DEBUG_ISR_DETAILED, + "retrieved IRQ index=%d dev %04x:%02x:%02x.%x, time=%uus, delay=%uus\n", + p->irq_list[i].irq_index, + p->irq_list[i].dev.domain, + p->irq_list[i].dev.bus, + p->irq_list[i].dev.device, + p->irq_list[i].dev.function, + q->data[index].time, + p->irq_list[i].delay); } else { - mods_debug_printk(DEBUG_ISR_DETAILED, - "retrieved IRQ 0x%x, time=%uus, delay=%uus\n", - (unsigned int)p->irq_list[i].dev.bus, - q->data[index].time, - p->irq_list[i].delay); + cl_debug(DEBUG_ISR_DETAILED, + "retrieved IRQ 0x%x, time=%uus, delay=%uus\n", + (unsigned int)p->irq_list[i].dev.bus, + q->data[index].time, + p->irq_list[i].delay); } } @@ -1419,8 +1445,7 @@ int esc_mods_irq_handled_2(struct mods_client *client, LOG_ENT(); /* Print info */ - mods_debug_printk(DEBUG_ISR_DETAILED, - "mark CPU IRQ 0x%x handled\n", irq); + cl_debug(DEBUG_ISR_DETAILED, "mark CPU IRQ 0x%x handled\n", irq); /* Lock IRQ queue */ spin_lock_irqsave(&client->irq_lock, flags); @@ -1428,8 +1453,8 @@ int esc_mods_irq_handled_2(struct mods_client *client, list_for_each_entry_safe(t, next, &client->irq_list, list) { if (t->apic_irq == irq) { if (t->type != p->type) { - mods_error_printk( - "IRQ type doesn't match registered IRQ\n"); + cl_error( + "IRQ type doesn't match registered IRQ\n"); } else { enable_irq(irq); err = OK; @@ -1474,7 +1499,7 @@ int esc_mods_map_irq(struct mods_client *client, struct device_node *np = of_find_node_by_name(NULL, p->dt_name); if (!np) { - mods_error_printk("node %s is not valid\n", p->full_name); + cl_error("node %s is not valid\n", p->full_name); err = -EINVAL; goto error; } @@ -1486,8 +1511,7 @@ int esc_mods_map_irq(struct mods_client *client, while (of_node_cmp(np->full_name, p->full_name)) { np = of_find_node_by_name(np, p->dt_name); if (!np) { - mods_error_printk("node %s is not valid\n", - p->full_name); + cl_error("node %s is not valid\n", p->full_name); err = -EINVAL; goto error; } @@ -1496,7 +1520,7 @@ int esc_mods_map_irq(struct mods_client *client, p->irq = irq_of_parse_and_map(np, p->index); err = of_irq_parse_one(np, p->index, &oirq); if (err) { - mods_error_printk("could not parse IRQ\n"); + cl_error("could not parse IRQ\n"); goto error; } @@ -1524,8 +1548,8 @@ error: return err; } -int esc_mods_map_irq_to_gpio(struct mods_client *client, - struct MODS_GPIO_INFO *p) +int esc_mods_map_irq_to_gpio(struct mods_client *client, + struct MODS_GPIO_INFO *p) { //TODO: Make sure you are allocating gpio properly int gpio_handle; @@ -1535,7 +1559,7 @@ int esc_mods_map_irq_to_gpio(struct mods_client *client, struct device_node *np = of_find_node_by_name(NULL, p->dt_name); if (!np) { - mods_error_printk("node %s is not valid\n", p->full_name); + cl_error("node %s is not valid\n", p->full_name); err = -EINVAL; goto error; } @@ -1543,8 +1567,7 @@ int esc_mods_map_irq_to_gpio(struct mods_client *client, while (of_node_cmp(np->full_name, p->full_name)) { np = of_find_node_by_name(np, p->dt_name); if (!np) { - mods_error_printk("node %s is not valid\n", - p->full_name); + cl_error("node %s is not valid\n", p->full_name); err = -EINVAL; goto error; } @@ -1552,20 +1575,20 @@ int esc_mods_map_irq_to_gpio(struct mods_client *client, gpio_handle = of_get_named_gpio(np, p->name, 0); if (!gpio_is_valid(gpio_handle)) { - mods_error_printk("gpio %s is missing\n", p->name); + cl_error("gpio %s is missing\n", p->name); err = gpio_handle; goto error; } err = gpio_direction_input(gpio_handle); if (err < 0) { - mods_error_printk("pex_rst_gpio input direction change failed\n"); + cl_error("pex_rst_gpio input direction change failed\n"); goto error; } irq = gpio_to_irq(gpio_handle); if (irq < 0) { - mods_error_printk("Unable to get irq for pex_rst_gpio\n"); + cl_error("Unable to get irq for pex_rst_gpio\n"); err = -EINVAL; goto error; } diff --git a/drivers/misc/mods/mods_krnl.c b/drivers/misc/mods/mods_krnl.c index eae3096e..69f7923c 100644 --- a/drivers/misc/mods/mods_krnl.c +++ b/drivers/misc/mods/mods_krnl.c @@ -109,8 +109,13 @@ static const struct pci_device_id mods_pci_table[] = { static int mods_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { - mods_debug_printk(DEBUG_PCI, "probed vendor %x device %x devfn %x\n", - dev->vendor, dev->device, dev->devfn); + mods_debug_printk(DEBUG_PCI, + "probed dev %04x:%02x:%02x.%x vendor %04x device %04x\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + dev->vendor, dev->device); return 0; } @@ -138,25 +143,68 @@ static u32 access_token = MODS_ACCESS_TOKEN_NONE; #ifdef MODS_HAS_SRIOV static int mods_pci_sriov_configure(struct pci_dev *dev, int numvfs) { + int totalvfs; + struct en_dev_entry *dpriv; + LOG_ENT(); - mods_debug_printk(DEBUG_PCI, - "(numvfs=%d, totalvfs=%d, dev->is_physfn=%d)\n", - numvfs, - pci_sriov_get_totalvfs(dev), - dev->is_physfn); + dpriv = pci_get_drvdata(dev); + if (!dpriv) { + mods_error_printk( + "failed to enable sriov, dev %04x:%02x:%02x.%x was not enabled\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); + + LOG_EXT(); + return -EBUSY; + } + + totalvfs = pci_sriov_get_totalvfs(dev); if (numvfs > 0) { int err = pci_enable_sriov(dev, numvfs); - if (err) { - mods_error_printk("pci_enable_sriov failed with %d\n", - err); - numvfs = 0; + if (unlikely(err)) { + mods_error_printk( + "failed to enable sriov on dev %04x:%02x:%02x.%x %s numvfs=%d (totalvfs=%d), err=%d\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + dev->is_physfn ? "physfn" : "virtfn", + numvfs, + totalvfs, + err); + numvfs = err; + } else { + dpriv->num_vfs = numvfs; + + mods_info_printk( + "enabled sriov on dev %04x:%02x:%02x.%x %s numvfs=%d (totalvfs=%d)\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + dev->is_physfn ? "physfn" : "virtfn", + numvfs, + totalvfs); } + } else { pci_disable_sriov(dev); numvfs = 0; + dpriv->num_vfs = 0; + + mods_info_printk( + "disabled sriov on dev %04x:%02x:%02x.%x %s (totalvfs=%d)\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + dev->is_physfn ? "physfn" : "virtfn", + totalvfs); } LOG_EXT(); @@ -166,8 +214,9 @@ static int mods_pci_sriov_configure(struct pci_dev *dev, int numvfs) static int esc_mods_set_num_vf(struct mods_client *client, struct MODS_SET_NUM_VF *p) { - int err; - struct pci_dev *dev = NULL; + int err; + struct pci_dev *dev = NULL; + struct en_dev_entry *dpriv; LOG_ENT(); @@ -175,17 +224,41 @@ static int esc_mods_set_num_vf(struct mods_client *client, err = mods_find_pci_dev(client, &p->dev, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", - p->dev.domain, - p->dev.bus, - p->dev.device, - p->dev.function); + cl_error("dev %04x:%02x:%02x.%x not found\n", + p->dev.domain, + p->dev.bus, + p->dev.device, + p->dev.function); LOG_EXT(); return err; } + dpriv = pci_get_drvdata(dev); + if (!dpriv) { + cl_error( + "failed to enable sriov, dev %04x:%02x:%02x.%x was not enabled\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); + err = -EBUSY; + goto error; + } + if (dpriv->client_id != client->client_id) { + cl_error( + "invalid client for dev %04x:%02x:%02x.%x, expected %u\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + dpriv->client_id); + err = -EBUSY; + goto error; + } + err = mods_pci_sriov_configure(dev, p->numvfs); +error: pci_dev_put(dev); LOG_EXT(); return err; @@ -194,32 +267,68 @@ static int esc_mods_set_num_vf(struct mods_client *client, static int esc_mods_set_total_vf(struct mods_client *client, struct MODS_SET_NUM_VF *p) { - int err; - struct pci_dev *dev = NULL; + int err; + struct pci_dev *dev = NULL; + struct en_dev_entry *dpriv; LOG_ENT(); - mods_debug_printk(DEBUG_PCI, - "pci_sriov_set_totalvfs(totalvfs=%d)\n", p->numvfs); - /* Get the PCI device structure for the specified device from kernel */ err = mods_find_pci_dev(client, &p->dev, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", - p->dev.domain, - p->dev.bus, - p->dev.device, - p->dev.function); + cl_error("dev %04x:%02x:%02x.%x not found\n", + p->dev.domain, + p->dev.bus, + p->dev.device, + p->dev.function); LOG_EXT(); return -EINVAL; } - err = pci_sriov_set_totalvfs(dev, p->numvfs); - if (err) - mods_error_printk("pci_sriov_set_totalvfs failed with %d\n", - err); + dpriv = pci_get_drvdata(dev); + if (!dpriv) { + cl_error( + "failed to enable sriov, dev %04x:%02x:%02x.%x was not enabled\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); + err = -EBUSY; + goto error; + } + if (dpriv->client_id != client->client_id) { + cl_error( + "invalid client for dev %04x:%02x:%02x.%x, expected %u\n", + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + dpriv->client_id); + err = -EBUSY; + goto error; + } + err = pci_sriov_set_totalvfs(dev, p->numvfs); + + if (unlikely(err)) { + cl_error( + "failed to set totalvfs=%d on dev %04x:%02x:%02x.%x, err=%d\n", + p->numvfs, + p->dev.domain, + p->dev.bus, + p->dev.device, + p->dev.function, + err); + } else + cl_info("set totalvfs %d on dev %04x:%02x:%02x.%x\n", + p->numvfs, + p->dev.domain, + p->dev.bus, + p->dev.device, + p->dev.function); + +error: pci_dev_put(dev); LOG_EXT(); return err; @@ -278,7 +387,7 @@ static int validate_client(struct mods_client *client) } if (client->client_id < 1 || client->client_id > MODS_MAX_CLIENTS) { - mods_error_printk("invalid client id %u\n", client->client_id); + cl_error("invalid client id\n"); return false; } @@ -302,8 +411,10 @@ static int mods_set_access_token(u32 tok) static int mods_check_access_token(struct mods_client *client) { - if (client->access_token != mods_get_access_token()) + if (client->access_token != mods_get_access_token()) { + cl_error("invalid access token %u\n", client->access_token); return -EFAULT; + } return OK; } @@ -348,8 +459,8 @@ static int __init mods_init_module(void) mods_info_printk("*** WARNING: DIAGNOSTIC DRIVER LOADED ***\n"); mods_info_printk("driver loaded, version %x.%02x\n", - (MODS_DRIVER_VERSION>>8), - (MODS_DRIVER_VERSION&0xFF)); + (MODS_DRIVER_VERSION >> 8), + (MODS_DRIVER_VERSION & 0xFF)); if (debug) mods_info_printk("debug level 0x%x\n", debug); @@ -397,7 +508,7 @@ MODULE_VERSION(MAKE_MODULE_VERSION(MODS_DRIVER_VERSION_MAJOR, module_param(debug, int, 0644); MODULE_PARM_DESC(debug, -"debug bitflags (2=ioctl 4=pci 8=acpi 16=irq 32=mem 64=fun +256=detailed)"); + "debug bitflags (2=ioctl 4=pci 8=acpi 16=irq 32=mem 64=fun +256=detailed)"); module_param(multi_instance, int, 0644); MODULE_PARM_DESC(multi_instance, @@ -421,7 +532,7 @@ static void mods_disable_all_devices(struct mods_client *client) while (client->enabled_devices != NULL) { struct en_dev_entry *old = client->enabled_devices; - mods_disable_device(old->dev); + mods_disable_device(client, old->dev); client->enabled_devices = old->next; kfree(old); atomic_dec(&client->num_allocs); @@ -468,9 +579,13 @@ static int mods_register_mapping( list_add(&p_map_mem->list, &client->mem_map_list); - mods_debug_printk(DEBUG_MEM_DETAILED, - "map alloc %p as %p: phys 0x%llx, virt 0x%llx, size 0x%llx\n", - p_mem_info, p_map_mem, dma_addr, virtual_address, mapping_length); + cl_debug(DEBUG_MEM_DETAILED, + "map alloc %p as %p: phys 0x%llx, virt 0x%llx, size 0x%llx\n", + p_mem_info, + p_map_mem, + dma_addr, + virtual_address, + mapping_length); LOG_EXT(); return OK; @@ -545,7 +660,9 @@ static void mods_unregister_all_mappings(struct mods_client *client) LOG_EXT(); } -static pgprot_t mods_get_prot(u8 mem_type, pgprot_t prot) +static pgprot_t mods_get_prot(struct mods_client *client, + u8 mem_type, + pgprot_t prot) { switch (mem_type) { case MODS_ALLOC_CACHED: @@ -558,8 +675,7 @@ static pgprot_t mods_get_prot(u8 mem_type, pgprot_t prot) return MODS_PGPROT_WC(prot); default: - mods_warning_printk("unsupported memory type: %u\n", - mem_type); + cl_warn("unsupported memory type: %u\n", mem_type); return prot; } } @@ -572,7 +688,7 @@ static pgprot_t mods_get_prot_for_range(struct mods_client *client, if ((dma_addr == client->mem_type.dma_addr) && (size == client->mem_type.size)) { - return mods_get_prot(client->mem_type.type, prot); + return mods_get_prot(client, client->mem_type.type, prot); } return prot; } @@ -613,7 +729,7 @@ static pci_ers_result_t mods_pci_error_detected(struct pci_dev *dev, enum pci_channel_state state) { mods_debug_printk(DEBUG_PCI, - "pci_error_detected %04x:%02x:%02x.%x\n", + "pci_error_detected dev %04x:%02x:%02x.%x\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -625,7 +741,7 @@ static pci_ers_result_t mods_pci_error_detected(struct pci_dev *dev, static pci_ers_result_t mods_pci_mmio_enabled(struct pci_dev *dev) { mods_debug_printk(DEBUG_PCI, - "pci_mmio_enabled %04x:%02x:%02x.%x\n", + "pci_mmio_enabled dev %04x:%02x:%02x.%x\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -637,7 +753,7 @@ static pci_ers_result_t mods_pci_mmio_enabled(struct pci_dev *dev) static void mods_pci_resume(struct pci_dev *dev) { mods_debug_printk(DEBUG_PCI, - "pci_resume %04x:%02x:%02x.%x\n", + "pci_resume dev %04x:%02x:%02x.%x\n", pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn), @@ -716,13 +832,13 @@ static int mods_krnl_vma_access(struct vm_area_struct *vma, return -EINVAL; } - mods_debug_printk(DEBUG_MEM_DETAILED, - "access vma, virt 0x%lx, phys 0x%llx\n", - vma->vm_start, - (u64)vma->vm_pgoff << PAGE_SHIFT); - client = priv->client; + cl_debug(DEBUG_MEM_DETAILED, + "access vma, virt 0x%lx, phys 0x%llx\n", + vma->vm_start, + (u64)vma->vm_pgoff << PAGE_SHIFT); + if (unlikely(mutex_lock_interruptible(&client->mtx))) { LOG_EXT(); return -EINTR; @@ -843,7 +959,7 @@ static int mods_krnl_open(struct inode *ip, struct file *fp) fp->private_data = client; - mods_info_printk("driver opened\n"); + cl_info("driver opened, pid=%d\n", current->pid); LOG_EXT(); return OK; } @@ -853,6 +969,7 @@ static int mods_krnl_close(struct inode *ip, struct file *fp) struct mods_client *client = fp->private_data; int final_err = OK; int err = OK; + u8 client_id; LOG_ENT(); @@ -861,6 +978,8 @@ static int mods_krnl_close(struct inode *ip, struct file *fp) return -EINVAL; } + client_id = client->client_id; + mods_free_client_interrupts(client); mods_resume_console(client); @@ -868,19 +987,19 @@ static int mods_krnl_close(struct inode *ip, struct file *fp) mods_unregister_all_mappings(client); err = mods_unregister_all_alloc(client); if (err) - mods_error_printk("failed to free all memory\n"); + cl_error("failed to free all memory\n"); final_err = err; #if defined(CONFIG_PPC64) err = mods_unregister_all_ppc_tce_bypass(client); if (err) - mods_error_printk("failed to restore dma bypass\n"); + cl_error("failed to restore dma bypass\n"); if (!final_err) final_err = err; err = mods_unregister_all_nvlink_sysmem_trained(client); if (err) - mods_error_printk("failed to free nvlink trained\n"); + cl_error("failed to free nvlink trained\n"); if (!final_err) final_err = err; #endif @@ -892,16 +1011,18 @@ static int mods_krnl_close(struct inode *ip, struct file *fp) unsigned long num_pages = atomic_read(&client->num_pages); if (num_allocs || num_pages) { - mods_error_printk("not all allocations have been freed, allocs=%lu, pages=%lu\n", - num_allocs, num_pages); + cl_error( + "not all allocations have been freed, allocs=%lu, pages=%lu\n", + num_allocs, num_pages); if (!final_err) final_err = -ENOMEM; } } - mods_free_client(client->client_id); + mods_free_client(client_id); + + pr_info("mods [%d]: driver closed\n", client_id); - mods_info_printk("driver closed\n"); LOG_EXT(); return final_err; } @@ -920,12 +1041,15 @@ static unsigned int mods_krnl_poll(struct file *fp, poll_table *wait) return err; if (!(fp->f_flags & O_NONBLOCK)) { - mods_debug_printk(DEBUG_ISR_DETAILED, "poll wait\n"); + cl_debug(DEBUG_ISR_DETAILED, "poll wait\n"); poll_wait(fp, &client->interrupt_event, wait); } + /* if any interrupts pending then check intr, POLLIN on irq */ mask |= mods_irq_event_check(client->client_id); - mods_debug_printk(DEBUG_ISR_DETAILED, "poll mask 0x%x\n", mask); + + cl_debug(DEBUG_ISR_DETAILED, "poll mask 0x%x\n", mask); + return mask; } @@ -993,7 +1117,7 @@ static int mods_krnl_map_inner(struct mods_client *client, if ((req_pa & ~PAGE_MASK) != 0 || (vma_size & ~PAGE_MASK) != 0) { - mods_error_printk("requested mapping is not page-aligned\n"); + cl_error("requested mapping is not page-aligned\n"); return -EINVAL; } @@ -1003,8 +1127,8 @@ static int mods_krnl_map_inner(struct mods_client *client, struct MODS_PHYS_CHUNK *chunks = p_mem_info->pages; u32 have_pages = 0; unsigned long map_va = 0; - const pgprot_t prot = - mods_get_prot(p_mem_info->cache_type, vma->vm_page_prot); + const pgprot_t prot = mods_get_prot(client, + p_mem_info->cache_type, vma->vm_page_prot); /* Find the beginning of the requested range */ for (first = 0; first < p_mem_info->num_chunks; first++) { @@ -1018,7 +1142,7 @@ static int mods_krnl_map_inner(struct mods_client *client, } if (first == p_mem_info->num_chunks) { - mods_error_printk("can't satisfy requested mapping\n"); + cl_error("can't satisfy requested mapping\n"); return -EINVAL; } @@ -1034,7 +1158,7 @@ static int mods_krnl_map_inner(struct mods_client *client, } if (have_pages < req_pages) { - mods_error_printk("requested mapping exceeds bounds\n"); + cl_error("requested mapping exceeds bounds\n"); return -EINVAL; } @@ -1059,17 +1183,18 @@ static int mods_krnl_map_inner(struct mods_client *client, map_pages = have_pages; } - mods_debug_printk(DEBUG_MEM_DETAILED, - "remap va 0x%lx pfn 0x%x size 0x%x pages 0x%x\n", - map_va, (unsigned int)(map_pa>>PAGE_SHIFT), - map_size, map_pages); + cl_debug(DEBUG_MEM_DETAILED, + "remap va 0x%lx pfn 0x%x size 0x%x pages 0x%x\n", + map_va, (unsigned int)(map_pa>>PAGE_SHIFT), + map_size, + map_pages); if (remap_pfn_range(vma, map_va, map_pa>>PAGE_SHIFT, map_size, prot)) { - mods_error_printk("failed to map memory\n"); + cl_error("failed to map memory\n"); return -EAGAIN; } @@ -1086,12 +1211,12 @@ static int mods_krnl_map_inner(struct mods_client *client, } else { /* device memory */ - mods_debug_printk(DEBUG_MEM, - "map dev: phys 0x%llx, virt 0x%lx, size 0x%lx, %s\n", - req_pa, - (unsigned long)vma->vm_start, - (unsigned long)vma_size, - mods_get_prot_str_for_range(client, req_pa, vma_size)); + cl_debug(DEBUG_MEM, + "map dev: phys 0x%llx, virt 0x%lx, size 0x%lx, %s\n", + req_pa, + (unsigned long)vma->vm_start, + (unsigned long)vma_size, + mods_get_prot_str_for_range(client, req_pa, vma_size)); if (io_remap_pfn_range( vma, @@ -1103,7 +1228,7 @@ static int mods_krnl_map_inner(struct mods_client *client, req_pa, vma_size, vma->vm_page_prot))) { - mods_error_printk("failed to map device memory\n"); + cl_error("failed to map device memory\n"); return -EAGAIN; } @@ -1296,18 +1421,20 @@ static int esc_mods_acquire_access_token(struct mods_client *client, LOG_ENT(); if (mods_get_multi_instance()) { + cl_error( + "access token ops not supported with multi_instance=1\n"); LOG_EXT(); - mods_error_printk( - "access token ops not supported with multi_instance=1!\n"); return err; } get_random_bytes(&ptoken->token, sizeof(ptoken->token)); err = mods_set_access_token(ptoken->token); if (err) - mods_error_printk("unable to set access token!\n"); - else + cl_error("unable to set access token\n"); + else { + cl_info("set access token %u\n", ptoken->token); client->access_token = ptoken->token; + } LOG_EXT(); @@ -1322,17 +1449,19 @@ static int esc_mods_release_access_token(struct mods_client *client, LOG_ENT(); if (mods_get_multi_instance()) { + cl_error( + "access token ops not supported with multi_instance=1\n"); LOG_EXT(); - mods_error_printk( - "access token ops not supported with multi_instance=1!\n"); return err; } err = mods_set_access_token(MODS_ACCESS_TOKEN_NONE); if (err) - mods_error_printk("unable to clear access token!\n"); - else + cl_error("unable to clear access token\n"); + else { + cl_info("released access token %u\n", client->access_token); client->access_token = MODS_ACCESS_TOKEN_NONE; + } LOG_EXT(); @@ -1350,7 +1479,7 @@ static int esc_mods_verify_access_token(struct mods_client *client, client->access_token = ptoken->token; err = OK; } else - mods_error_printk("invalid access token\n"); + cl_error("invalid access token %u\n", client->access_token); LOG_EXT(); @@ -1439,7 +1568,7 @@ static int esc_mods_read_msr(struct mods_client *client, struct MODS_MSR *p) err = rdmsr_safe_on_cpu(p->cpu_num, p->reg, &p->low, &p->high); if (err) - mods_error_printk("Could not read MSR %u\n", p->reg); + cl_error("could not read MSR %u\n", p->reg); LOG_EXT(); return err; @@ -1453,7 +1582,7 @@ static int esc_mods_write_msr(struct mods_client *client, struct MODS_MSR *p) err = wrmsr_safe_on_cpu(p->cpu_num, p->reg, p->low, p->high); if (err) - mods_error_printk("Could not write MSR %u\n", p->reg); + cl_error("could not write MSR %u\n", p->reg); LOG_EXT(); return err; @@ -1504,7 +1633,7 @@ static long mods_krnl_ioctl(struct file *fp, arg_copy = buf; if ((arg_size > 0) && copy_from_user(arg_copy, arg, arg_size)) { - mods_error_printk("failed to copy ioctl data\n"); + cl_error("failed to copy ioctl data\n"); if (arg_size > (int)sizeof(buf)) { kfree(arg_copy); atomic_dec(&client->num_allocs); @@ -1516,20 +1645,18 @@ static long mods_krnl_ioctl(struct file *fp, #define MODS_IOCTL(code, function, argtype)\ ({\ do {\ - mods_debug_printk(DEBUG_IOCTL, "ioctl(" #code ")\n");\ + cl_debug(DEBUG_IOCTL, "ioctl(" #code ")\n");\ if (arg_size != sizeof(struct argtype)) {\ err = -EINVAL;\ - mods_error_printk( \ - "invalid parameter passed to ioctl " #code \ - "\n");\ + cl_error("invalid parameter passed to ioctl " #code\ + "\n");\ } else {\ err = function(client, (struct argtype *)arg_copy);\ if ((err == OK) && \ copy_to_user(arg, arg_copy, arg_size)) {\ err = -EFAULT;\ - mods_error_printk( \ - "copying return value for ioctl " \ - #code " to user space failed\n");\ + cl_error("copying return value for ioctl " \ + #code " to user space failed\n");\ } \ } \ } while (0);\ @@ -1538,12 +1665,11 @@ static long mods_krnl_ioctl(struct file *fp, #define MODS_IOCTL_NORETVAL(code, function, argtype)\ ({\ do {\ - mods_debug_printk(DEBUG_IOCTL, "ioctl(" #code ")\n");\ + cl_debug(DEBUG_IOCTL, "ioctl(" #code ")\n");\ if (arg_size != sizeof(struct argtype)) {\ err = -EINVAL;\ - mods_error_printk( \ - "invalid parameter passed to ioctl " #code \ - "\n");\ + cl_error("invalid parameter passed to ioctl " #code\ + "\n");\ } else {\ err = function(client, (struct argtype *)arg_copy);\ } \ @@ -1553,12 +1679,11 @@ static long mods_krnl_ioctl(struct file *fp, #define MODS_IOCTL_VOID(code, function)\ ({\ do {\ - mods_debug_printk(DEBUG_IOCTL, "ioctl(" #code ")\n");\ + cl_debug(DEBUG_IOCTL, "ioctl(" #code ")\n");\ if (arg_size != 0) {\ err = -EINVAL;\ - mods_error_printk( \ - "invalid parameter passed to ioctl " #code \ - "\n");\ + cl_error("invalid parameter passed to ioctl " #code\ + "\n");\ } else {\ err = function(client);\ } \ @@ -2236,9 +2361,13 @@ static long mods_krnl_ioctl(struct file *fp, #endif default: - mods_error_printk("unrecognized ioctl (0x%x) dir(0x%x) type (0x%x) nr (0x%x) size (0x%x)\n", - cmd, _IOC_DIR(cmd), _IOC_TYPE(cmd), - _IOC_NR(cmd), _IOC_SIZE(cmd)); + cl_error( + "unrecognized ioctl (0x%x) dir(0x%x) type (0x%x) nr (0x%x) size (0x%x)\n", + cmd, + _IOC_DIR(cmd), + _IOC_TYPE(cmd), + _IOC_NR(cmd), + _IOC_SIZE(cmd)); err = -EINVAL; break; } diff --git a/drivers/misc/mods/mods_mem.c b/drivers/misc/mods/mods_mem.c index c577a52a..e988f118 100644 --- a/drivers/misc/mods/mods_mem.c +++ b/drivers/misc/mods/mods_mem.c @@ -2,7 +2,7 @@ /* * mods_mem.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2008-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2008-2020, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -27,8 +27,9 @@ #include #endif -static int mods_post_alloc(struct MODS_PHYS_CHUNK *chunk, - u64 phys_addr, +static int mods_post_alloc(struct mods_client *client, + struct MODS_PHYS_CHUNK *chunk, + u64 phys_addr, struct MODS_MEM_INFO *p_mem_info); /**************************** @@ -98,9 +99,10 @@ static u64 mods_expand_nvlink_addr(struct pci_dev *dev, u64 addr47) #ifdef CONFIG_PCI /* Unmap a page if it was mapped */ -static void mods_dma_unmap_page(struct pci_dev *dev, - u64 dev_addr, - u32 order) +static void mods_dma_unmap_page(struct mods_client *client, + struct pci_dev *dev, + u64 dev_addr, + u32 order) { dev_addr = mods_expand_nvlink_addr(dev, dev_addr); @@ -109,13 +111,13 @@ static void mods_dma_unmap_page(struct pci_dev *dev, PAGE_SIZE << order, DMA_BIDIRECTIONAL); - mods_debug_printk(DEBUG_MEM_DETAILED, - "dma unmap dev_addr=0x%llx on dev %04x:%02x:%02x.%x\n", - (unsigned long long)dev_addr, - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_debug(DEBUG_MEM_DETAILED, + "dma unmap dev_addr=0x%llx on dev %04x:%02x:%02x.%x\n", + (unsigned long long)dev_addr, + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); } /* Unmap and delete the specified DMA mapping */ @@ -141,8 +143,7 @@ static int mods_dma_unmap_and_free(struct mods_client *client, } if (!found) { - mods_error_printk("failed to unmap and free %p\n", - p_del_map); + cl_error("failed to unmap and free %p\n", p_del_map); return -EINVAL; } @@ -153,7 +154,8 @@ static int mods_dma_unmap_and_free(struct mods_client *client, int i; for (i = 0; i < p_mem_info->num_chunks; i++) - mods_dma_unmap_page(p_del_map->dev, + mods_dma_unmap_page(client, + p_del_map->dev, p_del_map->dev_addr[i], p_mem_info->pages[i].order); pci_dev_put(p_del_map->dev); @@ -199,7 +201,8 @@ int mods_dma_unmap_all(struct mods_client *client, #ifdef CONFIG_PCI /* DMA map all pages in an allocation */ -static int mods_dma_map_pages(struct MODS_MEM_INFO *p_mem_info, +static int mods_dma_map_pages(struct mods_client *client, + struct MODS_MEM_INFO *p_mem_info, struct MODS_DMA_MAP *p_dma_map) { int i; @@ -216,14 +219,19 @@ static int mods_dma_map_pages(struct MODS_MEM_INFO *p_mem_info, DMA_BIDIRECTIONAL); if (pci_dma_mapping_error(dev, dev_addr)) { - mods_error_printk("failed to map page to device %04x:%02x:%02x.%x\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_error( + "failed to map 2^%u pages at 0x%llx to dev %04x:%02x:%02x.%x with dma mask 0x%llx\n", + chunk->order, + (unsigned long long)chunk->dma_addr, + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + (unsigned long long)dma_get_mask(&dev->dev)); while (--i >= 0) - mods_dma_unmap_page(dev, + mods_dma_unmap_page(client, + dev, p_dma_map->dev_addr[i], chunk->order); @@ -234,14 +242,14 @@ static int mods_dma_map_pages(struct MODS_MEM_INFO *p_mem_info, p_dma_map->dev_addr[i] = dev_addr; - mods_debug_printk(DEBUG_MEM_DETAILED, - "dma map dev_addr=0x%llx, phys_addr=0x%llx on dev %04x:%02x:%02x.%x\n", - (unsigned long long)dev_addr, - (unsigned long long)chunk->dma_addr, - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_debug(DEBUG_MEM_DETAILED, + "dma map dev_addr=0x%llx, phys_addr=0x%llx on dev %04x:%02x:%02x.%x\n", + (unsigned long long)dev_addr, + (unsigned long long)chunk->dma_addr, + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); } return OK; @@ -263,13 +271,13 @@ static int mods_create_dma_map(struct mods_client *client, p_dma_map = kzalloc(alloc_size, GFP_KERNEL | __GFP_NORETRY); if (unlikely(!p_dma_map)) { - mods_error_printk("failed to allocate device map data\n"); + cl_error("failed to allocate device map data\n"); return -ENOMEM; } atomic_inc(&client->num_allocs); p_dma_map->dev = pci_dev_get(dev); - err = mods_dma_map_pages(p_mem_info, p_dma_map); + err = mods_dma_map_pages(client, p_mem_info, p_dma_map); if (unlikely(err)) { pci_dev_put(dev); @@ -281,7 +289,8 @@ static int mods_create_dma_map(struct mods_client *client, return err; } -static int mods_dma_map_default_page(struct MODS_PHYS_CHUNK *chunk, +static int mods_dma_map_default_page(struct mods_client *client, + struct MODS_PHYS_CHUNK *chunk, struct pci_dev *dev) { u64 dev_addr = pci_map_page(dev, @@ -291,11 +300,15 @@ static int mods_dma_map_default_page(struct MODS_PHYS_CHUNK *chunk, DMA_BIDIRECTIONAL); if (pci_dma_mapping_error(dev, dev_addr)) { - mods_error_printk("failed to map page to device %04x:%02x:%02x.%x\n", - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_error( + "failed to map 2^%u pages at 0x%llx to dev %04x:%02x:%02x.%x with dma mask 0x%llx\n", + chunk->order, + (unsigned long long)chunk->dma_addr, + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn), + (unsigned long long)dma_get_mask(&dev->dev)); return -EINVAL; } @@ -303,14 +316,14 @@ static int mods_dma_map_default_page(struct MODS_PHYS_CHUNK *chunk, chunk->dev_addr = dev_addr; chunk->mapped = 1; - mods_debug_printk(DEBUG_MEM_DETAILED, - "auto dma map dev_addr=0x%llx, phys_addr=0x%llx on dev %04x:%02x:%02x.%x\n", - (unsigned long long)dev_addr, - (unsigned long long)chunk->dma_addr, - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_debug(DEBUG_MEM_DETAILED, + "auto dma map dev_addr=0x%llx, phys_addr=0x%llx on dev %04x:%02x:%02x.%x\n", + (unsigned long long)dev_addr, + (unsigned long long)chunk->dma_addr, + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); return OK; } @@ -318,7 +331,8 @@ static int mods_dma_map_default_page(struct MODS_PHYS_CHUNK *chunk, /* DMA-map memory to the device for which it has been allocated, if it hasn't * been mapped already. */ -static int mods_create_default_dma_map(struct MODS_MEM_INFO *p_mem_info) +static int mods_create_default_dma_map(struct mods_client *client, + struct MODS_MEM_INFO *p_mem_info) { int err = OK; unsigned int i; @@ -328,17 +342,17 @@ static int mods_create_default_dma_map(struct MODS_MEM_INFO *p_mem_info) struct MODS_PHYS_CHUNK *chunk = &p_mem_info->pages[i]; if (chunk->mapped) { - mods_debug_printk(DEBUG_MEM_DETAILED, - "memory %p already mapped to dev %04x:%02x:%02x.%x\n", - p_mem_info, - pci_domain_nr(dev->bus), - dev->bus->number, - PCI_SLOT(dev->devfn), - PCI_FUNC(dev->devfn)); + cl_debug(DEBUG_MEM_DETAILED, + "memory %p already mapped to dev %04x:%02x:%02x.%x\n", + p_mem_info, + pci_domain_nr(dev->bus), + dev->bus->number, + PCI_SLOT(dev->devfn), + PCI_FUNC(dev->devfn)); return OK; } - err = mods_dma_map_default_page(chunk, dev); + err = mods_dma_map_default_page(client, chunk, dev); if (err) break; } @@ -423,16 +437,17 @@ static int save_non_wb_chunks(struct mods_client *client, chunk->p_page = NULL; - mods_debug_printk(DEBUG_MEM_DETAILED, - "save 0x%llx 2^%d pages %s\n", - (unsigned long long)(size_t)free_chunk->p_page, - chunk->order, - p_mem_info->cache_type == MODS_ALLOC_WRITECOMBINE - ? "WC" : "UC"); + cl_debug(DEBUG_MEM_DETAILED, + "save 0x%llx 2^%u pages %s\n", + (unsigned long long)(size_t)free_chunk->p_page, + chunk->order, + p_mem_info->cache_type == MODS_ALLOC_WRITECOMBINE + ? "WC" : "UC"); #ifdef CONFIG_PCI if (chunk->mapped) { - mods_dma_unmap_page(p_mem_info->dev, + mods_dma_unmap_page(client, + p_mem_info->dev, chunk->dev_addr, chunk->order); chunk->mapped = 0; @@ -552,7 +567,8 @@ static void mods_free_pages(struct mods_client *client, #ifdef CONFIG_PCI if (chunk->mapped) { - mods_dma_unmap_page(p_mem_info->dev, + mods_dma_unmap_page(client, + p_mem_info->dev, chunk->dev_addr, chunk->order); chunk->mapped = 0; @@ -628,12 +644,12 @@ static struct page *mods_alloc_pages(struct mods_client *client, kfree(free_chunk); atomic_dec(&client->num_allocs); - mods_debug_printk(DEBUG_MEM_DETAILED, - "reuse 0x%llx 2^%d pages %s\n", - (unsigned long long)(size_t)p_page, - order, - cache_type == MODS_ALLOC_WRITECOMBINE - ? "WC" : "UC"); + cl_debug(DEBUG_MEM_DETAILED, + "reuse 0x%llx 2^%u pages %s\n", + (unsigned long long)(size_t)p_page, + order, + cache_type == MODS_ALLOC_WRITECOMBINE + ? "WC" : "UC"); *need_cup = 0; return p_page; @@ -682,7 +698,7 @@ static int mods_alloc_contig_sys_pages(struct mods_client *client, phys_addr = page_to_phys(p_page); if (phys_addr == 0) { - mods_error_printk("failed to determine physical address\n"); + cl_error("failed to determine physical address\n"); mods_free_pages(client, p_mem_info); LOG_EXT(); return -ENOMEM; @@ -690,8 +706,8 @@ static int mods_alloc_contig_sys_pages(struct mods_client *client, dma_addr = MODS_PHYS_TO_DMA(phys_addr); if (dma_addr >= (1ULL << DMA_BITS)) { - mods_error_printk("dma_addr 0x%llx exceeds supported range\n", - dma_addr); + cl_error("dma_addr 0x%llx exceeds supported range\n", + dma_addr); mods_free_pages(client, p_mem_info); LOG_EXT(); return -ENOMEM; @@ -699,26 +715,26 @@ static int mods_alloc_contig_sys_pages(struct mods_client *client, p_mem_info->pages[0].dma_addr = dma_addr; - mods_debug_printk(DEBUG_MEM, - "alloc contig 0x%lx bytes, 2^%u pages, %s, node %d,%s phys 0x%llx\n", - (unsigned long)p_mem_info->num_pages << PAGE_SHIFT, - p_mem_info->pages[0].order, - mods_get_prot_str(p_mem_info->cache_type), - p_mem_info->numa_node, - p_mem_info->dma32 ? " dma32," : "", - (unsigned long long)dma_addr); + cl_debug(DEBUG_MEM, + "alloc contig 0x%lx bytes, 2^%u pages, %s, node %d,%s phys 0x%llx\n", + (unsigned long)p_mem_info->num_pages << PAGE_SHIFT, + p_mem_info->pages[0].order, + mods_get_prot_str(p_mem_info->cache_type), + p_mem_info->numa_node, + p_mem_info->dma32 ? " dma32," : "", + (unsigned long long)dma_addr); end_addr = dma_addr + ((unsigned long)p_mem_info->num_pages << PAGE_SHIFT); if ((p_mem_info->dma32) && (end_addr > 0x100000000ULL)) { - mods_error_printk("allocation exceeds 32-bit addressing\n"); + cl_error("allocation exceeds 32-bit addressing\n"); mods_free_pages(client, p_mem_info); LOG_EXT(); return -ENOMEM; } - if (mods_post_alloc(p_mem_info->pages, phys_addr, p_mem_info)) { + if (mods_post_alloc(client, p_mem_info->pages, phys_addr, p_mem_info)) { mods_free_pages(client, p_mem_info); LOG_EXT(); return -EINVAL; @@ -768,7 +784,7 @@ static int mods_alloc_noncontig_sys_pages(struct mods_client *client, } if (!chunk->p_page) { - mods_error_printk("out of memory\n"); + cl_error("out of memory\n"); goto failed; } @@ -780,31 +796,31 @@ static int mods_alloc_noncontig_sys_pages(struct mods_client *client, phys_addr = page_to_phys(chunk->p_page); if (phys_addr == 0) { - mods_error_printk("phys addr lookup failed\n"); + cl_error("phys addr lookup failed\n"); goto failed; } dma_addr = MODS_PHYS_TO_DMA(phys_addr); if (dma_addr >= (1ULL << DMA_BITS)) { - mods_error_printk("dma_addr 0x%llx exceeds supported range\n", - dma_addr); + cl_error("dma_addr 0x%llx exceeds supported range\n", + dma_addr); goto failed; } chunk->dma_addr = dma_addr; - mods_debug_printk(DEBUG_MEM, - "alloc 0x%lx bytes [%u], 2^%u pages, %s, node %d,%s phys 0x%llx\n", - (unsigned long)p_mem_info->num_pages << PAGE_SHIFT, - (unsigned int)num_chunks, - chunk->order, - mods_get_prot_str(p_mem_info->cache_type), - p_mem_info->numa_node, - p_mem_info->dma32 ? " dma32," : "", - (unsigned long long)chunk->dma_addr); + cl_debug(DEBUG_MEM, + "alloc 0x%lx bytes [%u], 2^%u pages, %s, node %d,%s phys 0x%llx\n", + (unsigned long)p_mem_info->num_pages << PAGE_SHIFT, + (unsigned int)num_chunks, + chunk->order, + mods_get_prot_str(p_mem_info->cache_type), + p_mem_info->numa_node, + p_mem_info->dma32 ? " dma32," : "", + (unsigned long long)chunk->dma_addr); ++num_chunks; - if (mods_post_alloc(chunk, phys_addr, p_mem_info)) + if (mods_post_alloc(client, chunk, phys_addr, p_mem_info)) goto failed; } @@ -850,7 +866,7 @@ static int mods_unregister_and_free(struct mods_client *client, struct list_head *head; struct list_head *iter; - mods_debug_printk(DEBUG_MEM_DETAILED, "free %p\n", p_del_mem); + cl_debug(DEBUG_MEM_DETAILED, "free %p\n", p_del_mem); if (unlikely(mutex_lock_interruptible(&client->mtx))) return -EINTR; @@ -879,8 +895,7 @@ static int mods_unregister_and_free(struct mods_client *client, mutex_unlock(&client->mtx); - mods_error_printk("failed to unregister allocation %p\n", - p_del_mem); + cl_error("failed to unregister allocation %p\n", p_del_mem); return -EINVAL; } @@ -926,18 +941,18 @@ static int get_addr_range(struct mods_client *client, p_mem_info = (struct MODS_MEM_INFO *)(size_t)p->memory_handle; if (unlikely(!p_mem_info)) { - mods_error_printk("no allocation given\n"); + cl_error("no allocation given\n"); LOG_EXT(); return -EINVAL; } if (unlikely(pcidev && (pcidev->bus > 0xFFU || pcidev->device > 0xFFU))) { - mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", - pcidev->domain, - pcidev->bus, - pcidev->device, - pcidev->function); + cl_error("dev %04x:%02x:%02x.%x not found\n", + pcidev->domain, + pcidev->bus, + pcidev->device, + pcidev->function); LOG_EXT(); return -EINVAL; } @@ -955,12 +970,13 @@ static int get_addr_range(struct mods_client *client, } if (err) { - mods_error_printk("allocation %p is not mapped to device %04x:%02x:%02x.%x\n", - p_mem_info, - pcidev->domain, - pcidev->bus, - pcidev->device, - pcidev->function); + cl_error( + "allocation %p is not mapped to dev %04x:%02x:%02x.%x\n", + p_mem_info, + pcidev->domain, + pcidev->bus, + pcidev->device, + pcidev->function); LOG_EXT(); return err; } @@ -1003,9 +1019,8 @@ static int get_addr_range(struct mods_client *client, } if (unlikely(num_out)) { - mods_error_printk("invalid offset 0x%llx requested for allocation %p\n", - p->offset, - p_mem_info); + cl_error("invalid offset 0x%llx requested for allocation %p\n", + p->offset, p_mem_info); err = -EINVAL; } @@ -1138,30 +1153,29 @@ int esc_mods_alloc_pages_2(struct mods_client *client, LOG_ENT(); + cl_debug(DEBUG_MEM_DETAILED, + "alloc 0x%llx bytes flags=0x%x (%s %s%s%s%s%s) node=%d on dev %04x:%02x:%02x.%x\n", + (unsigned long long)p->num_bytes, + p->flags, + mods_get_prot_str(p->flags & MODS_ALLOC_CACHE_MASK), + (p->flags & MODS_ALLOC_CONTIGUOUS) ? "contiguous" : + "noncontiguous", + (p->flags & MODS_ALLOC_DMA32) ? " dma32" : "", + (p->flags & MODS_ALLOC_USE_NUMA) ? " usenuma" : "", + (p->flags & MODS_ALLOC_FORCE_NUMA) ? " forcenuma" : "", + (p->flags & MODS_ALLOC_MAP_DEV) ? " dmamap" : "", + p->numa_node, + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); + if (!p->num_bytes) { - mods_error_printk("zero bytes requested\n"); + cl_error("zero bytes requested\n"); err = -EINVAL; goto failed; } - mods_debug_printk(DEBUG_MEM_DETAILED, - "alloc 0x%llx bytes flags=0x%x (%s %s%s%s%s%s) node=%d on %04x:%02x:%02x.%x\n", - (unsigned long long)p->num_bytes, - p->flags, - mods_get_prot_str(p->flags & MODS_ALLOC_CACHE_MASK), - (p->flags & MODS_ALLOC_CONTIGUOUS) - ? "contiguous" : "noncontiguous", - (p->flags & MODS_ALLOC_DMA32) ? " dma32" : "", - (p->flags & MODS_ALLOC_USE_NUMA) ? " usenuma" : "", - (p->flags & MODS_ALLOC_FORCE_NUMA) - ? " forcenuma" : "", - (p->flags & MODS_ALLOC_MAP_DEV) ? " dmamap" : "", - p->numa_node, - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); - num_pages = (u32)((p->num_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT); if (p->flags & MODS_ALLOC_CONTIGUOUS) num_chunks = 1; @@ -1171,8 +1185,8 @@ int esc_mods_alloc_pages_2(struct mods_client *client, (num_chunks - 1) * sizeof(struct MODS_PHYS_CHUNK); if (((u64)num_pages << PAGE_SHIFT) < p->num_bytes) { - mods_error_printk("invalid allocation size requested: 0x%llx\n", - (unsigned long long)p->num_bytes); + cl_error("invalid allocation size requested: 0x%llx\n", + (unsigned long long)p->num_bytes); err = -EINVAL; goto failed; } @@ -1182,16 +1196,16 @@ int esc_mods_alloc_pages_2(struct mods_client *client, ((unsigned int)p->numa_node >= (unsigned int)num_possible_nodes())) { - mods_error_printk("invalid NUMA node: %d\n", p->numa_node); + cl_error("invalid NUMA node: %d\n", p->numa_node); err = -EINVAL; goto failed; } #ifdef CONFIG_PPC64 if ((p->flags & MODS_ALLOC_CACHE_MASK) != MODS_ALLOC_CACHED) { - mods_error_printk("unsupported cache attr %u (%s)\n", - p->flags & MODS_ALLOC_CACHE_MASK, - mods_get_prot_str(p->flags & MODS_ALLOC_CACHE_MASK)); + cl_error("unsupported cache attr %u (%s)\n", + p->flags & MODS_ALLOC_CACHE_MASK, + mods_get_prot_str(p->flags & MODS_ALLOC_CACHE_MASK)); err = -ENOMEM; goto failed; } @@ -1199,8 +1213,8 @@ int esc_mods_alloc_pages_2(struct mods_client *client, p_mem_info = kzalloc(alloc_size, GFP_KERNEL | __GFP_NORETRY); if (unlikely(!p_mem_info)) { - mods_error_printk("failed to allocate auxiliary 0x%x bytes\n", - alloc_size); + cl_error("failed to allocate auxiliary 0x%x bytes\n", + alloc_size); err = -ENOMEM; goto failed; } @@ -1235,11 +1249,11 @@ int esc_mods_alloc_pages_2(struct mods_client *client, err = mods_find_pci_dev(client, &p->pci_device, &dev); if (unlikely(err)) { - mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_error("dev %04x:%02x:%02x.%x not found\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); goto failed; } @@ -1256,13 +1270,13 @@ int esc_mods_alloc_pages_2(struct mods_client *client, p_mem_info->numa_node = 0; } #endif - mods_debug_printk(DEBUG_MEM_DETAILED, - "affinity %04x:%02x:%02x.%x node %d\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function, - p_mem_info->numa_node); + cl_debug(DEBUG_MEM_DETAILED, + "affinity dev %04x:%02x:%02x.%x node %d\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function, + p_mem_info->numa_node); if (!(p->flags & MODS_ALLOC_MAP_DEV)) { pci_dev_put(p_mem_info->dev); @@ -1283,20 +1297,19 @@ int esc_mods_alloc_pages_2(struct mods_client *client, } if (err) { - mods_error_printk( - "failed to alloc 0x%lx %s bytes, %s, node %d%s\n", - (unsigned long)p_mem_info->num_pages << PAGE_SHIFT, - (p->flags & MODS_ALLOC_CONTIGUOUS) - ? "contiguous" : "non-contiguous", - mods_get_prot_str(p_mem_info->cache_type), - p_mem_info->numa_node, - p_mem_info->dma32 ? ", dma32" : ""); + cl_error("failed to alloc 0x%lx %s bytes, %s, node %d%s\n", + (unsigned long)p_mem_info->num_pages << PAGE_SHIFT, + (p->flags & MODS_ALLOC_CONTIGUOUS) ? "contiguous" : + "non-contiguous", + mods_get_prot_str(p_mem_info->cache_type), + p_mem_info->numa_node, + p_mem_info->dma32 ? ", dma32" : ""); goto failed; } p->memory_handle = (u64)(size_t)p_mem_info; - mods_debug_printk(DEBUG_MEM_DETAILED, "alloc %p\n", p_mem_info); + cl_debug(DEBUG_MEM_DETAILED, "alloc %p\n", p_mem_info); err = mods_register_alloc(client, p_mem_info); @@ -1332,7 +1345,7 @@ int esc_mods_device_alloc_pages_2(struct mods_client *client, else if (p->attrib == MODS_MEMORY_WRITECOMBINE) flags |= MODS_ALLOC_WRITECOMBINE; else if (p->attrib != MODS_MEMORY_CACHED) { - mods_error_printk("invalid cache attrib: %u\n", p->attrib); + cl_error("invalid cache attrib: %u\n", p->attrib); LOG_EXT(); return -ENOMEM; } @@ -1375,7 +1388,7 @@ int esc_mods_device_alloc_pages(struct mods_client *client, else if (p->attrib == MODS_MEMORY_WRITECOMBINE) flags |= MODS_ALLOC_WRITECOMBINE; else if (p->attrib != MODS_MEMORY_CACHED) { - mods_error_printk("invalid cache attrib: %u\n", p->attrib); + cl_error("invalid cache attrib: %u\n", p->attrib); LOG_EXT(); return -ENOMEM; } @@ -1420,7 +1433,7 @@ int esc_mods_alloc_pages(struct mods_client *client, struct MODS_ALLOC_PAGES *p) else if (p->attrib == MODS_MEMORY_WRITECOMBINE) flags |= MODS_ALLOC_WRITECOMBINE; else if (p->attrib != MODS_MEMORY_CACHED) { - mods_error_printk("invalid cache attrib: %u\n", p->attrib); + cl_error("invalid cache attrib: %u\n", p->attrib); LOG_EXT(); return -ENOMEM; } @@ -1468,8 +1481,8 @@ int esc_mods_merge_pages(struct mods_client *client, if (unlikely(p->num_in_handles < 2 || p->num_in_handles > MODS_MAX_MERGE_HANDLES)) { - mods_error_printk("invalid number of input handles: %u\n", - p->num_in_handles); + cl_error("invalid number of input handles: %u\n", + p->num_in_handles); LOG_EXT(); return -EINVAL; } @@ -1486,14 +1499,13 @@ int esc_mods_merge_pages(struct mods_client *client, p->in_memory_handles[0]; if (!validate_mem_handle(client, p_mem_info)) { - mods_error_printk("handle 0: invalid handle %p\n", - p_mem_info); + cl_error("handle 0: invalid handle %p\n", p_mem_info); err = -EINVAL; goto failed; } if (unlikely(!list_empty(&p_mem_info->dma_map_list))) { - mods_error_printk("handle 0: found dma mappings\n"); + cl_error("handle 0: found dma mappings\n"); err = -EINVAL; goto failed; } @@ -1507,8 +1519,8 @@ int esc_mods_merge_pages(struct mods_client *client, p->in_memory_handles[i]; if (!validate_mem_handle(client, p_other)) { - mods_error_printk("handle %u: invalid handle %p\n", - i, p); + cl_error("handle %u: invalid handle %p\n", + i, p); err = -EINVAL; goto failed; } @@ -1563,8 +1575,7 @@ int esc_mods_merge_pages(struct mods_client *client, } if (unlikely(err_msg)) { - mods_error_printk("merging handle %u: %s\n", - i, err_msg); + cl_error("merging handle %u: %s\n", i, err_msg); err = -EINVAL; goto failed; } @@ -1640,7 +1651,7 @@ int esc_mods_set_mem_type(struct mods_client *client, break; default: - mods_error_printk("unsupported memory type: %u\n", p->type); + cl_error("unsupported memory type: %u\n", p->type); LOG_EXT(); return -EINVAL; } @@ -1653,8 +1664,8 @@ int esc_mods_set_mem_type(struct mods_client *client, p_mem_info = mods_find_alloc(client, p->physical_address); if (p_mem_info) { mutex_unlock(&client->mtx); - mods_error_printk("cannot set mem type on phys addr 0x%llx\n", - p->physical_address); + cl_error("cannot set mem type on phys addr 0x%llx\n", + p->physical_address); LOG_EXT(); return -EINVAL; } @@ -1826,10 +1837,11 @@ int esc_mods_virtual_to_phys(struct mods_client *client, + virt_offs; mutex_unlock(&client->mtx); - mods_debug_printk(DEBUG_MEM_DETAILED, - "get phys: map %p virt 0x%llx -> 0x%llx\n", - p_map_mem, p->virtual_address, - p->physical_address); + cl_debug(DEBUG_MEM_DETAILED, + "get phys: map %p virt 0x%llx -> 0x%llx\n", + p_map_mem, + p->virtual_address, + p->physical_address); LOG_EXT(); return OK; @@ -1852,9 +1864,11 @@ int esc_mods_virtual_to_phys(struct mods_client *client, p->physical_address = get_phys_addr.physical_address; - mods_debug_printk(DEBUG_MEM_DETAILED, - "get phys: map %p virt 0x%llx -> 0x%llx\n", - p_map_mem, p->virtual_address, p->physical_address); + cl_debug(DEBUG_MEM_DETAILED, + "get phys: map %p virt 0x%llx -> 0x%llx\n", + p_map_mem, + p->virtual_address, + p->physical_address); LOG_EXT(); return OK; @@ -1863,8 +1877,7 @@ int esc_mods_virtual_to_phys(struct mods_client *client, mutex_unlock(&client->mtx); - mods_error_printk("invalid virtual address 0x%llx\n", - p->virtual_address); + cl_error("invalid virtual address 0x%llx\n", p->virtual_address); return -EINVAL; } @@ -1903,9 +1916,11 @@ int esc_mods_phys_to_virtual(struct mods_client *client, + offset; mutex_unlock(&client->mtx); - mods_debug_printk(DEBUG_MEM_DETAILED, - "get virt: map %p phys 0x%llx -> 0x%llx\n", - p_map_mem, p->physical_address, p->virtual_address); + cl_debug(DEBUG_MEM_DETAILED, + "get virt: map %p phys 0x%llx -> 0x%llx\n", + p_map_mem, + p->physical_address, + p->virtual_address); LOG_EXT(); return OK; @@ -1929,17 +1944,18 @@ int esc_mods_phys_to_virtual(struct mods_client *client, + offset - map_offset; mutex_unlock(&client->mtx); - mods_debug_printk(DEBUG_MEM_DETAILED, - "get virt: map %p phys 0x%llx -> 0x%llx\n", - p_map_mem, p->physical_address, p->virtual_address); + cl_debug(DEBUG_MEM_DETAILED, + "get virt: map %p phys 0x%llx -> 0x%llx\n", + p_map_mem, + p->physical_address, + p->virtual_address); LOG_EXT(); return OK; } } mutex_unlock(&client->mtx); - mods_error_printk("phys addr 0x%llx is not mapped\n", - p->physical_address); + cl_error("phys addr 0x%llx is not mapped\n", p->physical_address); return -EINVAL; } @@ -1967,26 +1983,26 @@ int esc_mods_dma_map_memory(struct mods_client *client, p_mem_info = (struct MODS_MEM_INFO *)(size_t)p->memory_handle; if (unlikely(!p_mem_info)) { - mods_error_printk("no allocation given\n"); + cl_error("no allocation given\n"); LOG_EXT(); return -EINVAL; } if (mods_is_pci_dev(p_mem_info->dev, &p->pci_device)) { - err = mods_create_default_dma_map(p_mem_info); + err = mods_create_default_dma_map(client, p_mem_info); LOG_EXT(); return err; } p_dma_map = find_dma_map(p_mem_info, &p->pci_device); if (p_dma_map) { - mods_debug_printk(DEBUG_MEM_DETAILED, - "memory %p already mapped to dev %04x:%02x:%02x.%x\n", - p_mem_info, - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_debug(DEBUG_MEM_DETAILED, + "memory %p already mapped to dev %04x:%02x:%02x.%x\n", + p_mem_info, + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); LOG_EXT(); return 0; } @@ -1994,11 +2010,11 @@ int esc_mods_dma_map_memory(struct mods_client *client, err = mods_find_pci_dev(client, &p->pci_device, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_error("dev %04x:%02x:%02x.%x not found\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); LOG_EXT(); return err; } @@ -2021,7 +2037,7 @@ int esc_mods_dma_unmap_memory(struct mods_client *client, p_mem_info = (struct MODS_MEM_INFO *)(size_t)p->memory_handle; if (unlikely(!p_mem_info)) { - mods_error_printk("no allocation given\n"); + cl_error("no allocation given\n"); LOG_EXT(); return -EINVAL; } @@ -2029,11 +2045,11 @@ int esc_mods_dma_unmap_memory(struct mods_client *client, err = mods_find_pci_dev(client, &p->pci_device, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_error("dev %04x:%02x:%02x.%x not found\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); } else err = mods_dma_unmap_all(client, p_mem_info, dev); @@ -2045,16 +2061,14 @@ int esc_mods_dma_unmap_memory(struct mods_client *client, #ifdef MODS_TEGRA -static void clear_contiguous_cache -( - u64 virt_start, - u64 phys_start, - u32 size -) +static void clear_contiguous_cache(struct mods_client *client, + u64 virt_start, + u64 phys_start, + u32 size) { - mods_debug_printk(DEBUG_MEM_DETAILED, - "clear cache virt 0x%llx phys 0x%llx size 0x%x\n", - virt_start, phys_start, size); + cl_debug(DEBUG_MEM_DETAILED, + "clear cache virt 0x%llx phys 0x%llx size 0x%x\n", + virt_start, phys_start, size); #ifdef CONFIG_ARM64 /* Flush L1 cache */ @@ -2068,12 +2082,10 @@ static void clear_contiguous_cache #endif } -static void clear_entry_cache_mappings -( - struct SYS_MAP_MEMORY *p_map_mem, - u64 virt_offs, - u64 virt_offs_end -) +static void clear_entry_cache_mappings(struct mods_client *client, + struct SYS_MAP_MEMORY *p_map_mem, + u64 virt_offs, + u64 virt_offs_end) { struct MODS_MEM_INFO *p_mem_info = p_map_mem->p_mem_info; u64 cur_vo = p_map_mem->virtual_addr; @@ -2105,8 +2117,10 @@ static void clear_entry_cache_mappings if (virt_offs_end < cur_vo_end) chunk_offs_end -= (u32)(cur_vo_end - virt_offs_end); - mods_debug_printk(DEBUG_MEM_DETAILED, - "clear cache %p [%u]\n", p_mem_info, i); + cl_debug(DEBUG_MEM_DETAILED, + "clear cache %p [%u]\n", + p_mem_info, + i); while (chunk_offs < chunk_offs_end) { u32 i_page = chunk_offs >> PAGE_SHIFT; @@ -2122,11 +2136,16 @@ static void clear_entry_cache_mappings if ((u64)clear_size > remaining) clear_size = (u32)remaining; - mods_debug_printk(DEBUG_MEM_DETAILED, - "clear page %u, chunk offs 0x%x, page va 0x%llx\n", - i_page, chunk_offs, page_va); + cl_debug(DEBUG_MEM_DETAILED, + "clear page %u, chunk offs 0x%x, page va 0x%llx\n", + i_page, + chunk_offs, + page_va); - clear_contiguous_cache(clear_va, clear_pa, clear_size); + clear_contiguous_cache(client, + clear_va, + clear_pa, + clear_size); kunmap((void *)(size_t)page_va); @@ -2147,7 +2166,7 @@ int esc_mods_flush_cpu_cache_range(struct mods_client *client, p->virt_addr_start > p->virt_addr_end || p->flags == MODS_INVALIDATE_CPU_CACHE) { - mods_debug_printk(DEBUG_MEM_DETAILED, "cannot clear cache\n"); + cl_debug(DEBUG_MEM_DETAILED, "cannot clear cache\n"); return -EINVAL; } @@ -2187,7 +2206,8 @@ int esc_mods_flush_cpu_cache_range(struct mods_client *client, virt_start = p_map_mem->virtual_addr; if (!end_on_page) virt_end = mapping_end; - clear_entry_cache_mappings(p_map_mem, + clear_entry_cache_mappings(client, + p_map_mem, virt_start, virt_end); } @@ -2198,7 +2218,8 @@ int esc_mods_flush_cpu_cache_range(struct mods_client *client, #endif -static int mods_post_alloc(struct MODS_PHYS_CHUNK *chunk, +static int mods_post_alloc(struct mods_client *client, + struct MODS_PHYS_CHUNK *chunk, u64 phys_addr, struct MODS_MEM_INFO *p_mem_info) { @@ -2212,11 +2233,12 @@ static int mods_post_alloc(struct MODS_PHYS_CHUNK *chunk, ptr = (u64)(size_t)kmap(chunk->p_page + i); if (!ptr) { - mods_error_printk("kmap failed\n"); + cl_error("kmap failed\n"); return -EINVAL; } #if defined(MODS_TEGRA) && !defined(CONFIG_CPA) - clear_contiguous_cache(ptr, + clear_contiguous_cache(client, + ptr, phys_addr + (i << PAGE_SHIFT), PAGE_SIZE); #else @@ -2224,7 +2246,7 @@ static int mods_post_alloc(struct MODS_PHYS_CHUNK *chunk, #endif kunmap((void *)(size_t)ptr); if (err) { - mods_error_printk("set cache type failed\n"); + cl_error("set cache type failed\n"); return -EINVAL; } } @@ -2247,7 +2269,7 @@ static int mods_post_alloc(struct MODS_PHYS_CHUNK *chunk, if (ops->map_sg == swiotlb_map_sg_attrs) return OK; #endif - err = mods_dma_map_default_page(chunk, dev); + err = mods_dma_map_default_page(client, chunk, dev); if (err) return err; } diff --git a/drivers/misc/mods/mods_netdevice.c b/drivers/misc/mods/mods_netdevice.c index 2206246f..90c57086 100644 --- a/drivers/misc/mods/mods_netdevice.c +++ b/drivers/misc/mods/mods_netdevice.c @@ -1,7 +1,7 @@ /* * mods_net.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2015-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2015-2020, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -29,19 +29,17 @@ int esc_mods_net_force_link(struct mods_client *client, if (!p || (strnlen(p->device_name, MAX_NET_DEVICE_NAME_LENGTH) == 0) || (!memchr(p->device_name, '\0', MAX_NET_DEVICE_NAME_LENGTH))) { - mods_error_printk("invalid device name\n"); + cl_error("invalid device name\n"); return -EINVAL; } for_each_netdev(&init_net, ndev) if (!strcmp(ndev->name, p->device_name)) { netif_carrier_on(ndev); - mods_info_printk("carrier forced on: %s\n", - p->device_name); + cl_info("carrier forced on: %s\n", p->device_name); return OK; } - mods_error_printk("failed to find network device %s\n", - p->device_name); + cl_error("failed to find network device %s\n", p->device_name); return -EINVAL; } diff --git a/drivers/misc/mods/mods_pci.c b/drivers/misc/mods/mods_pci.c index 59aaec93..6548c657 100644 --- a/drivers/misc/mods/mods_pci.c +++ b/drivers/misc/mods/mods_pci.c @@ -2,7 +2,7 @@ /* * mods_pci.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2008-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2008-2020, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -100,11 +100,11 @@ static int find_pci_dev_impl(struct mods_client *client, LOG_ENT(); - mods_debug_printk(DEBUG_PCI, - "find pci dev %04x:%04x, index %d\n", - (int) p->vendor_id, - (int) p->device_id, - (int) p->index); + cl_debug(DEBUG_PCI, + "find pci dev %04x:%04x, index %u\n", + p->vendor_id, + p->device_id, + p->index); do { dev = pci_get_device(p->vendor_id, p->device_id, dev); @@ -163,8 +163,10 @@ static int mods_find_pci_class_code(struct mods_client *client, LOG_ENT(); - mods_debug_printk(DEBUG_PCI, "find pci class code %04x, index %d\n", - (unsigned int)p->class_code, (int)p->index); + cl_debug(DEBUG_PCI, + "find pci class code %04x, index %u\n", + p->class_code, + p->index); do { dev = pci_get_class(p->class_code, dev); @@ -232,13 +234,13 @@ int esc_mods_pci_get_bar_info_2(struct mods_client *client, return err; } - mods_debug_printk(DEBUG_PCI, - "pci get bar info %04x:%02x:%02x:%x, bar index %d\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function, - p->bar_index); + cl_debug(DEBUG_PCI, + "pci get bar info dev %04x:%02x:%02x:%x, bar index %u\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function, + p->bar_index); #if defined(CONFIG_PPC64) if (unlikely(mutex_lock_interruptible(mods_get_irq_mutex()))) { @@ -250,11 +252,11 @@ int esc_mods_pci_get_bar_info_2(struct mods_client *client, /* Enable device on the PCI bus */ err = mods_enable_device(client, dev, NULL); if (err) { - mods_error_printk("unable to enable dev %04x:%02x:%02x.%x\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_error("unable to enable dev %04x:%02x:%02x.%x\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); mutex_unlock(mods_get_irq_mutex()); pci_dev_put(dev); LOG_EXT(); @@ -325,13 +327,13 @@ int esc_mods_pci_get_irq_2(struct mods_client *client, return err; } - mods_debug_printk(DEBUG_PCI, - "pci get irq %04x:%02x:%02x:%x irq=%u\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function, - dev->irq); + cl_debug(DEBUG_PCI, + "pci get irq dev %04x:%02x:%02x:%x irq=%u\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function, + dev->irq); p->irq = dev->irq; @@ -372,15 +374,6 @@ int esc_mods_pci_read_2(struct mods_client *client, struct MODS_PCI_READ_2 *p) return err; } - mods_debug_printk(DEBUG_PCI, - "pci read %04x:%02x:%02x.%x, addr 0x%04x, size %d\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function, - p->address, - p->data_size); - p->data = 0; switch (p->data_size) { case 1: { @@ -405,6 +398,30 @@ int esc_mods_pci_read_2(struct mods_client *client, struct MODS_PCI_READ_2 *p) break; } + cl_debug(DEBUG_PCI | DEBUG_DETAILED, + "pci read dev %04x:%02x:%02x.%x, addr 0x%04x, size %u, data 0x%x\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function, + p->address, + p->data_size, + p->data); + + /* Usually one of the first reads from PCI config space occurs + * at address 0 and or 2 to read PCI device vendor/id. + * If this reads all Fs, the device probably fell off the bus. + */ + if (p->address <= 4 && (p->data == ~0U || p->data == 0xFFFFU)) + cl_warn("pci read dev %04x:%02x:%02x.%x, addr 0x%04x, size %u, data 0x%x\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function, + p->address, + p->data_size, + p->data); + pci_dev_put(dev); LOG_EXT(); return err; @@ -437,24 +454,24 @@ int esc_mods_pci_write_2(struct mods_client *client, struct MODS_PCI_WRITE_2 *p) LOG_ENT(); - mods_debug_printk(DEBUG_PCI, - "pci write %04x:%02x:%02x.%x, addr 0x%04x, size %d, data 0x%x\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function, - p->address, - p->data_size, - p->data); + cl_debug(DEBUG_PCI | DEBUG_DETAILED, + "pci write dev %04x:%02x:%02x.%x, addr 0x%04x, size %u, data 0x%x\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function, + p->address, + p->data_size, + p->data); err = mods_find_pci_dev(client, &p->pci_device, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_error("dev %04x:%02x:%02x.%x not found\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); LOG_EXT(); return err; } @@ -512,8 +529,7 @@ int esc_mods_pci_bus_rescan(struct mods_client *client, LOG_ENT(); - mods_info_printk("scanning pci bus %04x:%02x\n", - rescan->domain, rescan->bus); + cl_info("scanning pci bus %04x:%02x\n", rescan->domain, rescan->bus); bus = pci_find_bus(rescan->domain, rescan->bus); @@ -526,8 +542,9 @@ int esc_mods_pci_bus_rescan(struct mods_client *client, pci_unlock_rescan_remove(); #endif } else { - mods_error_printk("bus %04x:%02x not found\n", - rescan->domain, rescan->bus); + cl_error("bus %04x:%02x not found\n", + rescan->domain, + rescan->bus); err = -EINVAL; } @@ -548,41 +565,43 @@ int esc_mods_pci_hot_reset(struct mods_client *client, LOG_ENT(); - mods_debug_printk(DEBUG_PCI, - "pci_hot_reset %04x:%02x:%02x.%x\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_debug(DEBUG_PCI, + "pci_hot_reset dev %04x:%02x:%02x.%x\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); err = mods_find_pci_dev(client, &p->pci_device, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("pci_hot_reset cannot find pci device %04x:%02x:%02x.%x\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_error( + "pci_hot_reset cannot find dev %04x:%02x:%02x.%x\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); LOG_EXT(); return err; } err = pci_set_pcie_reset_state(dev, pcie_hot_reset); if (unlikely(err)) - mods_error_printk("pci_hot_reset failed on %04x:%02x:%02x.%x\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_error("pci_hot_reset failed on dev %04x:%02x:%02x.%x\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); else { err = pci_set_pcie_reset_state(dev, pcie_deassert_reset); if (unlikely(err)) - mods_error_printk("pci_hot_reset deassert failed on %04x:%02x:%02x.%x\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_error( + "pci_hot_reset deassert failed on dev %04x:%02x:%02x.%x\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); } pci_dev_put(dev); @@ -605,21 +624,22 @@ int esc_mods_pci_bus_remove_dev(struct mods_client *client, err = mods_find_pci_dev(client, &p->pci_device, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("pci_remove cannot find pci device %04x:%02x:%02x.%x\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_error( + "pci_remove cannot find dev %04x:%02x:%02x.%x\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); LOG_EXT(); return err; } - mods_debug_printk(DEBUG_PCI, - "pci remove on %04x:%02x:%02x.%x\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_debug(DEBUG_PCI, + "pci remove on dev %04x:%02x:%02x.%x\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); pci_stop_and_remove_bus_device(dev); LOG_EXT(); @@ -684,11 +704,11 @@ int esc_mods_device_numa_info_3(struct mods_client *client, err = mods_find_pci_dev(client, &p->pci_device, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", - p->pci_device.domain, - p->pci_device.bus, - p->pci_device.device, - p->pci_device.function); + cl_error("dev %04x:%02x:%02x.%x not found\n", + p->pci_device.domain, + p->pci_device.bus, + p->pci_device.device, + p->pci_device.function); LOG_EXT(); return err; } @@ -722,8 +742,8 @@ int esc_mods_device_numa_info_3(struct mods_client *client, if (cur_mask && mask_idx >= MAX_CPU_MASKS_3) { - mods_error_printk("too many CPUs (%d) for mask bits\n", - nr_cpumask_bits); + cl_error("too many CPUs (%d) for mask bits\n", + nr_cpumask_bits); pci_dev_put(dev); LOG_EXT(); return -EINVAL; @@ -770,8 +790,8 @@ int esc_mods_device_numa_info_2(struct mods_client *client, numa_info.first_cpu_mask_offset; if (cur_mask && dst >= MAX_CPU_MASKS) { - mods_error_printk("too many CPUs (%d) for mask bits\n", - nr_cpumask_bits); + cl_error("too many CPUs (%d) for mask bits\n", + nr_cpumask_bits); err = -EINVAL; break; } @@ -814,8 +834,8 @@ int esc_mods_device_numa_info(struct mods_client *client, numa_info.first_cpu_mask_offset; if (cur_mask && dst >= MAX_CPU_MASKS) { - mods_error_printk("too many CPUs (%d) for mask bits\n", - nr_cpumask_bits); + cl_error("too many CPUs (%d) for mask bits\n", + nr_cpumask_bits); err = -EINVAL; break; } @@ -893,8 +913,8 @@ int esc_mods_pci_set_dma_mask(struct mods_client *client, LOG_ENT(); if (unlikely(dma_mask->num_bits > 64)) { - mods_error_printk("num_bits=%u exceeds 64\n", - dma_mask->num_bits); + cl_error("num_bits=%u exceeds 64\n", + dma_mask->num_bits); LOG_EXT(); return -EINVAL; } @@ -902,11 +922,11 @@ int esc_mods_pci_set_dma_mask(struct mods_client *client, err = mods_find_pci_dev(client, &dma_mask->pci_device, &dev); if (unlikely(err)) { if (err == -ENODEV) - mods_error_printk("PCI device %04x:%02x:%02x.%x not found\n", - dma_mask->pci_device.domain, - dma_mask->pci_device.bus, - dma_mask->pci_device.device, - dma_mask->pci_device.function); + cl_error("dev %04x:%02x:%02x.%x not found\n", + dma_mask->pci_device.domain, + dma_mask->pci_device.bus, + dma_mask->pci_device.device, + dma_mask->pci_device.function); LOG_EXT(); return err; } @@ -915,19 +935,39 @@ int esc_mods_pci_set_dma_mask(struct mods_client *client, err = pci_set_dma_mask(dev, mask); if (err) { - mods_error_printk("failed to set dma mask 0x%llx for dev %04x:%02x:%02x.%x\n", - mask, - dma_mask->pci_device.domain, - dma_mask->pci_device.bus, - dma_mask->pci_device.device, - dma_mask->pci_device.function); + cl_error( + "failed to set dma mask 0x%llx (%u) for dev %04x:%02x:%02x.%x\n", + mask, + dma_mask->num_bits, + dma_mask->pci_device.domain, + dma_mask->pci_device.bus, + dma_mask->pci_device.device, + dma_mask->pci_device.function); #if defined(CONFIG_PPC64) /* Ignore error if TCE bypass is on */ if (dev->dma_mask == ~0ULL) err = OK; #endif - } else + } else { err = pci_set_consistent_dma_mask(dev, mask); + if (err) + cl_error( + "failed to set consistent dma mask 0x%llx (%u) for dev %04x:%02x:%02x.%x\n", + mask, + dma_mask->num_bits, + dma_mask->pci_device.domain, + dma_mask->pci_device.bus, + dma_mask->pci_device.device, + dma_mask->pci_device.function); + } + + if (!err) + cl_info("set dma mask %u for dev %04x:%02x:%02x.%x\n", + dma_mask->num_bits, + dma_mask->pci_device.domain, + dma_mask->pci_device.bus, + dma_mask->pci_device.device, + dma_mask->pci_device.function); pci_dev_put(dev); LOG_EXT(); diff --git a/drivers/misc/mods/mods_tegradc.c b/drivers/misc/mods/mods_tegradc.c index b6fdad56..543de217 100644 --- a/drivers/misc/mods/mods_tegradc.c +++ b/drivers/misc/mods/mods_tegradc.c @@ -1,7 +1,7 @@ /* * mods_tegradc.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2014-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -23,8 +23,10 @@ #include #include "mods_internal.h" -static void mods_tegra_dc_set_windowattr_basic(struct tegra_dc_win *win, - const struct MODS_TEGRA_DC_WINDOW *mods_win) +static void mods_tegra_dc_set_windowattr_basic( + struct mods_client *client, + struct tegra_dc_win *win, + const struct MODS_TEGRA_DC_WINDOW *mods_win) { win->global_alpha = 0; win->z = 0; @@ -48,16 +50,16 @@ static void mods_tegra_dc_set_windowattr_basic(struct tegra_dc_win *win, win->out_w = mods_win->out_w; win->out_h = mods_win->out_h; - mods_debug_printk(DEBUG_TEGRADC, - "set_windowattr_basic window %u:\n" - "\tflags : 0x%08x\n" - "\tfmt : %u\n" - "\tinput : (%u, %u, %u, %u)\n" - "\toutput: (%u, %u, %u, %u)\n", - win->idx, win->flags, win->fmt, dfixed_trunc(win->x), - dfixed_trunc(win->y), dfixed_trunc(win->w), - dfixed_trunc(win->h), win->out_x, win->out_y, win->out_w, - win->out_h); + cl_debug(DEBUG_TEGRADC, + "set_windowattr_basic window %u:\n" + "\tflags : 0x%08x\n" + "\tfmt : %u\n" + "\tinput : (%u, %u, %u, %u)\n" + "\toutput: (%u, %u, %u, %u)\n", + win->idx, win->flags, win->fmt, dfixed_trunc(win->x), + dfixed_trunc(win->y), dfixed_trunc(win->w), + dfixed_trunc(win->h), win->out_x, win->out_y, win->out_w, + win->out_h); } int esc_mods_tegra_dc_config_possible(struct mods_client *client, @@ -89,28 +91,29 @@ int esc_mods_tegra_dc_config_possible(struct mods_client *client, if (args->windows[i].flags & MODS_TEGRA_DC_WINDOW_FLAG_ENABLED) { - mods_tegra_dc_set_windowattr_basic(&dc->tmp_wins[idx], - &args->windows[i]); + mods_tegra_dc_set_windowattr_basic(client, + &dc->tmp_wins[idx], + &args->windows[i]); } else { dc->tmp_wins[idx].flags = 0; } dc_wins[i] = &dc->tmp_wins[idx]; - mods_debug_printk(DEBUG_TEGRADC, - "head %u, using index %d for win %d\n", - args->head, i, idx); + cl_debug(DEBUG_TEGRADC, + "head %u, using index %d for win %d\n", + args->head, i, idx); } - mods_debug_printk(DEBUG_TEGRADC, - "head %u, dc->mode.pclk %u\n", - args->head, dc->mode.pclk); + cl_debug(DEBUG_TEGRADC, + "head %u, dc->mode.pclk %u\n", + args->head, dc->mode.pclk); #ifndef CONFIG_TEGRA_ISOMGR max_bandwidth = tegra_dc_get_bandwidth(dc_wins, args->win_num); emc_clk = clk_get_sys("tegra_emc", "emc"); if (IS_ERR(emc_clk)) { - mods_debug_printk(DEBUG_TEGRADC, - "invalid clock specified when fetching EMC clock\n"); + cl_debug(DEBUG_TEGRADC, + "invalid clock specified when fetching EMC clock\n"); } else { current_emc_freq = clk_get_rate(emc_clk); current_emc_freq /= 1000; @@ -119,9 +122,9 @@ int esc_mods_tegra_dc_config_possible(struct mods_client *client, max_available_bandwidth = (max_available_bandwidth / 100) * 50; } - mods_debug_printk(DEBUG_TEGRADC, - "b/w needed %lu, b/w available %lu\n", - max_bandwidth, max_available_bandwidth); + cl_debug(DEBUG_TEGRADC, + "b/w needed %lu, b/w available %lu\n", + max_bandwidth, max_available_bandwidth); args->possible = (max_bandwidth <= max_available_bandwidth); #else @@ -130,9 +133,11 @@ int esc_mods_tegra_dc_config_possible(struct mods_client *client, #endif for (i = 0; i < args->win_num; i++) { args->windows[i].bandwidth = dc_wins[i]->new_bandwidth; - mods_debug_printk(DEBUG_TEGRADC, - "head %u, win %d, b/w %d\n", - args->head, dc_wins[i]->idx, dc_wins[i]->new_bandwidth); + cl_debug(DEBUG_TEGRADC, + "head %u, win %d, b/w %d\n", + args->head, + dc_wins[i]->idx, + dc_wins[i]->new_bandwidth); } LOG_EXT(); diff --git a/drivers/misc/mods/mods_tegraprod.c b/drivers/misc/mods/mods_tegraprod.c index 9ff05228..87cc4dc0 100644 --- a/drivers/misc/mods/mods_tegraprod.c +++ b/drivers/misc/mods/mods_tegraprod.c @@ -1,7 +1,7 @@ /* * mods_tegraprod.c - This file is part of NVIDIA MODS kernel driver. * - * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved. * * NVIDIA MODS kernel driver is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License, @@ -79,12 +79,11 @@ int esc_mods_tegra_prod_iterate_dt( dev_node = (struct device_node *)iterator->device_handle; if (!iterator->name[0]) { - mods_error_printk( - "node name is missing for tegra prod value\n"); + cl_error("node name is missing for tegra prod value\n"); return -EINVAL; } if (!iterator->next_name[0] && !iterator->is_leaf) { - mods_error_printk("inner node with empty next_name\n"); + cl_error("inner node with empty next_name\n"); return -EINVAL; } @@ -93,8 +92,8 @@ int esc_mods_tegra_prod_iterate_dt( /* Search from Left to Right in DT */ dev_node = of_find_node_by_name(dev_node, iterator->name); if (!dev_node) { - mods_error_printk("node %s not found in device tree\n", - iterator->name); + cl_error("node %s not found in device tree\n", + iterator->name); return -EINVAL; } @@ -137,14 +136,13 @@ int esc_mods_tegra_prod_iterate_dt( * Others - ERROR * */ -static int mods_read_reg_info( - const struct device_node *dev_node, - __u32 *reg_info, - __u32 *count_reg_cells, - __u32 *count_addrsize_pair, - __u32 *count_address_cells, - __u32 *count_size_cells -) +static int mods_read_reg_info(struct mods_client *client, + const struct device_node *dev_node, + __u32 *reg_info, + __u32 *count_reg_cells, + __u32 *count_addrsize_pair, + __u32 *count_address_cells, + __u32 *count_size_cells) { struct device_node *parent_node; int ret; @@ -154,22 +152,22 @@ static int mods_read_reg_info( ret = of_property_read_u32(parent_node, "#address-cells", count_address_cells); if (ret < 0) { - mods_error_printk("Read #address-cells failed\n"); + cl_error("read #address-cells failed\n"); return ret; } else if (*count_address_cells == 0) { - mods_error_printk("#address-cells cannot be 0\n"); + cl_error("#address-cells cannot be 0\n"); return -EINVAL; } ret = of_property_read_u32(parent_node, "#size-cells", count_size_cells); if (ret < 0) { - mods_error_printk("Read #size-cells failed\n"); + cl_error("read #size-cells failed\n"); return ret; } else if (*count_size_cells == 0) { - mods_error_printk("#size-cells cannot be 0\n"); + cl_error("#size-cells cannot be 0\n"); return -EINVAL; } *count_addrsize_pair = *count_address_cells + *count_size_cells; @@ -177,15 +175,15 @@ static int mods_read_reg_info( /* Read count of cells in "reg" property */ ret = of_property_count_u32_elems(dev_node, "reg"); if (ret < 0) { - mods_error_printk( - "Unable to get count of cells in \"reg\" of node %s\n", + cl_error( + "unable to get count of cells in \"reg\" of node %s\n", dev_node->name); return ret; } *count_reg_cells = (__u32)ret; if (*count_reg_cells == 0) { - mods_error_printk("No \"reg\" info is available\n"); + cl_error("no \"reg\" info is available\n"); return -EINVAL; } else if (*count_reg_cells % *count_addrsize_pair != 0) { @@ -198,9 +196,8 @@ static int mods_read_reg_info( * "count_addrsize_pair", the read "reg" information is * incomplete or incorrect. */ - mods_error_printk( - "\"reg\" property has invalid length : %d\n", - *count_reg_cells); + cl_error("\"reg\" property has invalid length : %d\n", + *count_reg_cells); return -EINVAL; } @@ -208,9 +205,8 @@ static int mods_read_reg_info( ret = of_property_read_u32_array(dev_node, "reg", reg_info, (size_t)(*count_reg_cells)); if (ret < 0) { - mods_error_printk( - "Unable to read \"reg\" property of node %s\n", - dev_node->name); + cl_error("Unable to read \"reg\" property of node %s\n", + dev_node->name); return ret; } @@ -223,15 +219,14 @@ static int mods_read_reg_info( * @count_io_base: Count of IO addresses are mapped * */ -static void mods_batch_iounmap( - void __iomem **io_base, - __u32 count_io_base -) +static void mods_batch_iounmap(struct mods_client *client, + void __iomem **io_base, + __u32 count_io_base) { int i; if (!io_base) { - mods_error_printk("IO base address array is NULL\n"); + cl_error("IO base address array is NULL\n"); return; } @@ -251,11 +246,10 @@ static void mods_batch_iounmap( * Others - ERROR (NOTE: partially mapped IO memory will be unmapped on error) * */ -static int mods_batch_iomap( - const struct device_node *dev_node, - void __iomem **io_base, - __u32 *count_io_base -) +static int mods_batch_iomap(struct mods_client *client, + const struct device_node *dev_node, + void __iomem **io_base, + __u32 *count_io_base) { __u32 reg_info[MAX_REG_INFO_ENTRY]; __u32 count_reg_cells = 0; @@ -267,27 +261,26 @@ static int mods_batch_iomap( /* Check arguments */ if (!dev_node) { - mods_error_printk("Controller device handle is NULL\n"); + cl_error("controller device handle is NULL\n"); return -EINVAL; } if (!io_base) { - mods_error_printk("IO base address array is NULL\n"); + cl_error("IO base address array is NULL\n"); return -EINVAL; } if (!count_io_base) { - mods_error_printk("Count of IO base address array is NULL\n"); + cl_error("count of IO base address array is NULL\n"); return -EINVAL; } /* Get registers information */ - ret = mods_read_reg_info( - dev_node, - reg_info, - &count_reg_cells, - &count_addrsize_pair, - &count_address_cells, - &count_size_cells - ); + ret = mods_read_reg_info(client, + dev_node, + reg_info, + &count_reg_cells, + &count_addrsize_pair, + &count_address_cells, + &count_size_cells); if (ret < 0) return ret; @@ -318,13 +311,14 @@ static int mods_batch_iomap( io_addr_mapped = ioremap((resource_size_t)io_addr_base, (resource_size_t)io_addr_length); if (io_addr_mapped == NULL) { - mods_error_printk( - "Unable to map io address 0x%llx, length 0x%llx\n", - io_addr_base, io_addr_length); + cl_error( + "Unable to map io address 0x%llx, length 0x%llx\n", + io_addr_base, + io_addr_length); /* Clean : * Unmap the IO memory that have already been mapped */ - mods_batch_iounmap(io_base, *count_io_base); + mods_batch_iounmap(client, io_base, *count_io_base); return -ENXIO; } io_base[*count_io_base] = io_addr_mapped; @@ -340,24 +334,25 @@ static int mods_batch_iomap( * * Returns non-NULL on success, NULL on error. */ -static struct tegra_prod *mods_tegra_get_prod_list(struct device_node *dev_node) +static struct tegra_prod *mods_tegra_get_prod_list(struct mods_client *client, + struct device_node *dev_node) { struct tegra_prod *prod_list; if (!mods_tegra_prod_dev) { - mods_error_printk("tegra prod is not initialized\n"); + cl_error("tegra prod is not initialized\n"); return NULL; } if (!dev_node) { - mods_error_printk("device node is NULL\n"); + cl_error("device node is NULL\n"); return NULL; } prod_list = devm_tegra_prod_get_from_node(mods_tegra_prod_dev, dev_node); if (IS_ERR(prod_list)) { - mods_error_printk("failed to get prod_list : %s\n", + cl_error("failed to get prod_list : %s\n", dev_node->name); return NULL; } @@ -381,40 +376,39 @@ static struct tegra_prod *mods_tegra_get_prod_list(struct device_node *dev_node) * */ static int mods_tegra_get_prod_info( + struct mods_client *client, const struct MODS_TEGRA_PROD_SET_TUPLE *tuple, - struct tegra_prod **tegra_prod_list, - void __iomem **ctrl_base, - __u32 *count_ctrl_base -) + struct tegra_prod **tegra_prod_list, + void __iomem **ctrl_base, + __u32 *count_ctrl_base) { struct device_node *prod_node, *ctrl_node; if (!tegra_prod_list || !ctrl_base || !count_ctrl_base) { - mods_error_printk("Detected NULL pointer for out value."); + cl_error("detected NULL pointer for out value."); return -EINVAL; } prod_node = (struct device_node *)tuple->prod_dev_handle; if (!prod_node) { - mods_error_printk("Prod device handle is NULL\n"); + cl_error("prod device handle is NULL\n"); return -EINVAL; } - *tegra_prod_list = mods_tegra_get_prod_list(prod_node); + *tegra_prod_list = mods_tegra_get_prod_list(client, prod_node); if (!(*tegra_prod_list)) { - mods_error_printk( - "Failed to get prod_list with prod handle 0x%llx\n", - tuple->prod_dev_handle); + cl_error("failed to get prod_list with prod handle 0x%llx\n", + tuple->prod_dev_handle); return -EINVAL; } ctrl_node = (struct device_node *)tuple->ctrl_dev_handle; if (!ctrl_node) { - mods_error_printk("Controller device handle is NULL\n"); + cl_error("controller device handle is NULL\n"); return -EINVAL; } - return mods_batch_iomap(ctrl_node, ctrl_base, count_ctrl_base); + return mods_batch_iomap(client, ctrl_node, ctrl_base, count_ctrl_base); } /** @@ -442,15 +436,14 @@ int esc_mods_tegra_prod_is_supported( prod_node = (struct device_node *)tuple->prod_dev_handle; if (!prod_node) { - mods_error_printk("Prod device handle is NULL\n"); + cl_error("prod device handle is NULL\n"); return -EINVAL; } - tegra_prod = mods_tegra_get_prod_list(prod_node); + tegra_prod = mods_tegra_get_prod_list(client, prod_node); if (!tegra_prod) { - mods_error_printk( - "Failed to get prod_list with prod handle 0x%llx\n", - tuple->prod_dev_handle); + cl_error("failed to get prod_list with prod handle 0x%llx\n", + tuple->prod_dev_handle); return -EINVAL; } @@ -485,16 +478,19 @@ int esc_mods_tegra_prod_set_prod_all( void __iomem *ctrl_base[MAX_IO_MAP_ENTRY]; __u32 count_ctrl_base; - ret = mods_tegra_get_prod_info(tuple, &tegra_prod_list, - ctrl_base, &count_ctrl_base); + ret = mods_tegra_get_prod_info(client, + tuple, + &tegra_prod_list, + ctrl_base, + &count_ctrl_base); if (ret < 0) return ret; ret = tegra_prod_set_list(ctrl_base, tegra_prod_list); if (ret < 0) - mods_error_printk("Set prod failed\n"); + cl_error("set prod failed\n"); - mods_batch_iounmap(ctrl_base, count_ctrl_base); + mods_batch_iounmap(client, ctrl_base, count_ctrl_base); return ret; } @@ -524,16 +520,19 @@ int esc_mods_tegra_prod_set_prod_boot( void __iomem *ctrl_base[MAX_IO_MAP_ENTRY]; __u32 count_ctrl_base; - ret = mods_tegra_get_prod_info(tuple, &tegra_prod_list, - ctrl_base, &count_ctrl_base); + ret = mods_tegra_get_prod_info(client, + tuple, + &tegra_prod_list, + ctrl_base, + &count_ctrl_base); if (ret < 0) return ret; ret = tegra_prod_set_boot_init(ctrl_base, tegra_prod_list); if (ret < 0) - mods_error_printk("Set boot init prod failed\n"); + cl_error("set boot init prod failed\n"); - mods_batch_iounmap(ctrl_base, count_ctrl_base); + mods_batch_iounmap(client, ctrl_base, count_ctrl_base); return ret; } @@ -564,19 +563,22 @@ int esc_mods_tegra_prod_set_prod_by_name( void __iomem *ctrl_base[MAX_IO_MAP_ENTRY]; __u32 count_ctrl_base; - ret = mods_tegra_get_prod_info(tuple, &tegra_prod_list, - ctrl_base, &count_ctrl_base); + ret = mods_tegra_get_prod_info(client, + tuple, + &tegra_prod_list, + ctrl_base, + &count_ctrl_base); if (ret < 0) return ret; ret = tegra_prod_set_by_name(ctrl_base, tuple->prod_name, tegra_prod_list); if (ret < 0) { - mods_error_printk("Set prod by name \"%s\" failed\n", + cl_error("set prod by name \"%s\" failed\n", tuple->prod_name); } - mods_batch_iounmap(ctrl_base, count_ctrl_base); + mods_batch_iounmap(client, ctrl_base, count_ctrl_base); return ret; } @@ -610,8 +612,11 @@ int esc_mods_tegra_prod_set_prod_exact( void __iomem *ctrl_base[MAX_IO_MAP_ENTRY]; __u32 count_ctrl_base; - ret = mods_tegra_get_prod_info(tuple, &tegra_prod_list, - ctrl_base, &count_ctrl_base); + ret = mods_tegra_get_prod_info(client, + tuple, + &tegra_prod_list, + ctrl_base, + &count_ctrl_base); if (ret < 0) return ret; @@ -619,13 +624,13 @@ int esc_mods_tegra_prod_set_prod_exact( tegra_prod_list, tuple->index, tuple->offset, tuple->mask); if (ret < 0) { - mods_error_printk("Set prod exact by name \"%s\" failed\n", - tuple->prod_name); - mods_error_printk("index [%x]; offset [%x]; mask [%x]\n", - tuple->index, tuple->offset, tuple->mask); + cl_error("set prod exact by name \"%s\" failed\n", + tuple->prod_name); + cl_error("index [%x]; offset [%x]; mask [%x]\n", + tuple->index, tuple->offset, tuple->mask); } - mods_batch_iounmap(ctrl_base, count_ctrl_base); + mods_batch_iounmap(client, ctrl_base, count_ctrl_base); return ret; }