platform/kernel/linux-rpi.git
2 years agomei: me: fix clang -Wformat warning
Justin Stitt [Fri, 8 Jul 2022 20:35:49 +0000 (13:35 -0700)]
mei: me: fix clang -Wformat warning

When building with Clang we encounter the following warning:
| drivers/misc/mei/hw-me.c:564:44: error: format specifies type 'unsigned
| short' but the argument has type 'int' [-Werror,-Wformat]
| dev_dbg(dev->dev, "empty slots = %hu.\n", empty_slots);

The format specifier used is `%hu` which specifies an unsigned short,
however, empty_slots is an int -- hence the warning.

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20220708203549.3834790-1-justinstitt@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2 years agoeeprom: idt_89hpesx: uninitialized data in idt_dbgfs_csr_write()
Dan Carpenter [Fri, 8 Jul 2022 13:46:38 +0000 (16:46 +0300)]
eeprom: idt_89hpesx: uninitialized data in idt_dbgfs_csr_write()

The simple_write_to_buffer() function will return positive/success if it
is able to write a single byte anywhere within the buffer.  However that
potentially leaves a lot of the buffer uninitialized.

In this code it's better to return 0 if the offset is non-zero.  This
code is not written to support partial writes.  And then return -EFAULT
if the buffer is not completely initialized.

Fixes: cfad6425382e ("eeprom: Add IDT 89HPESx EEPROM/CSR driver")
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/Ysg1Pu/nzSMe3r1q@kili
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2 years agoMerge tag 'iio-for-5.20a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23...
Greg Kroah-Hartman [Thu, 14 Jul 2022 13:04:49 +0000 (15:04 +0200)]
Merge tag 'iio-for-5.20a' of https://git./linux/kernel/git/jic23/iio into char-misc-next

Jonathan writes:

IIO new device support, features and minor fixes for 5.20

Several on-running cleanup efforts dominate this time, plus the DMA
safety alignment issue identified due to improved understanding of
the restrictions as a result of Catalin Marinas' efforts in that area.

One immutable branch in here due to MFD and SPMI elements needed for
the qcom-rradc driver.

Device support
* bmi088
  - Add support for bmi085 (accelerometer part of IMU)
  - Add support for bmi090l (accelerometer part of IMU)
* mcp4922
  - Add support for single channel device MCP4921
* rzg2l-adc
  - Add compatible and minor tweaks to support RZ/G2UL ADC
* sca3300
  - Add support for scl3300 including refactoring driver to support
    multiple device types and cleanup noticed whilst working on driver.
* spmi-rradc
  - New driver for Qualcomm SPMI Round Robin ADC including necessary
    additional utility functions in SPMI core and related MFD driver.
* ti-dac55781
  - Add compatible for DAC121C081 which is very similar to existing parts.

Features
* core
  - Warn on iio_trigger_get() on an unregistered IIO trigger.
* bma400
  - Triggered buffer support
  - Activity and step counting
  - Misc driver improvements such as devm and header ordering
* cm32181
  - Add PM support.
* cros_ec
  - Sensor location support
* sx9324
  - Add precharge resistor setting
  - Add internal compensation resistor setting
  - Add CS idle/sleep mode.
* sx9360
  - Add precharge resistor setting
* vl53l0x
  - Handle reset GPIO, regulator and relax handling of irq type.

Cleanup and minor fixes:

Treewide changes
- Cleanup of error handling in remove functions in many drivers.
- Update dt-binding maintainers for a number of ADI bindings.
- Several sets of conversion of drivers from device tree specific to
  generic device properties. Includes fixing up various related
  header and Kconfig issues.
- Drop include of of.h from iio.h and fix up drivers that need to include
  it directly.
- More moves of clusters of drivers into appropriate IIO_XXX namespaces.
- Tree wide fix of a long running bug around DMA safety requirements.
  IIO was using __cacheline_aligned to pad iio_priv() structures. This
  worked for a long time by coincidence, but correct alignment is
  ARCH_KMALLOC_MINALIGN.  As there is activity around this area, introduce
  an IIO local IIO_DMA_MINALIGN to allow for changing it in one place rather
  than every driver in future. Note, there have been no reports of this
  bug in the wild, and it may not happen on any platforms supported by
  upstream, so no rush to backport these fixes.

Other cleanup
* core
  - Switch to ida_alloc()/free()
  - Drop unused iio_get_time_res()
  - Octal permissions and DEVICE_ATTR_* macros.
  - Cleanup bared unsigned usage.
* MAINTAINERS
  - Add include/dt-bindings/iio/ to the main IIO entry.
* ad5380
  - Comment syntax fix.
* ad74413r
  - Call to for_each_set_bit_from(), with from value as 0 replaced.
* ad7768-1
  - Drop explicit setting of INDIO_BUFFER_TRIGGERED as now done by the core.
* adxl345
  - Fix wrong address in dt-binding example.
* adxl367
  - Drop extra update of FIFO watermark.
* at91-sama5d2
  - Limit requested watermark to the hwfifo size.
* bmg160, bme680
  - Typos
* cio-dac
  - Switch to iomap rather than direct use of ioports
* kxsd9
  - Replace CONFIG_PM guards with new PM macros that let the compiler
    cleanly remove the unused code and structures when !CONFIG_PM
* lsm6dsx
  - Use new pm_sleep_ptr() and EXPORT_SIMPLE_DEV_PM_OPS(). Then move
    to Namespace.
* meson_saradc - general cleanup.
  - Avoid attaching resources to iio_dev->dev
  - Use same struct device for all error messages
  - Convert to dev_err_probe() and use local struct device *dev to
    reduce code complexity.
  - Use devm_clk_get_optional() instead of hand rolling.
  - Use regmap_read_poll_timeout() instead of hand rolling.
* mma7660
  - Drop ACPI_PTR() use that is unhelpful.
* mpu3050
  - Stop exporting symbols not used outside of module
  - Switch to new DEFINE_RUNTIME_DEV_PM_OPS() macro and move to Namespace.
* ping
  - Typo fix
* qcom-spmi-rradc
  - Typo fix
* sc27xx
  - Convert to generic struct u32_fract
* srf08
  - Drop a redundant check on !val
* st_lsm6dsx
  - Limit the requested watermark to the hwfifo size.
* stm32-adc
  - Use generic_handle_domain_irq() instead of opencoding.
  - Fix handling of ADC disable.
* stm32-dac
  - Use str_enabled_disable() instead of open coding.
* stx104
  - Switch to iomap rather than direct use of ioports
* tsc2046
  - Drop explicit setting of INDIO_BUFFER_TRIGGERED as now done by the core.
* tsl2563
  - Replace flush_scheduled_work() with cancel_delayed_work_sync()
  - Replace cancel_delayed_work() with cancel_delayed_work_sync()
* vl53l0x
  - Make the VDD regulator optional by allowing a dummy regulator.

* tag 'iio-for-5.20a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (244 commits)
  iio: adc: xilinx-xadc: Drop duplicate NULL check in xadc_parse_dt()
  iio: adc: xilinx-xadc: Make use of device properties
  iio: light: cm32181: Add PM support
  iio: adc: ad778-1: do not explicity set INDIO_BUFFER_TRIGGERED mode
  iio: adc: ti-tsc2046: do not explicity set INDIO_BUFFER_TRIGGERED mode
  iio: adc: stm32-adc: disable adc before calibration
  iio: adc: stm32-adc: make safe adc disable
  iio: dac: ad5380: align '*' each line and drop unneeded blank line
  iio: adc: qcom-spmi-rradc: Fix spelling mistake "coherrency" -> "coherency"
  iio: Don't use bare "unsigned"
  dt-bindings: iio: dac: mcp4922: expand for mcp4921 support
  iio: dac: mcp4922: add support to mcp4921
  iio: chemical: sps30: Move symbol exports into IIO_SPS30 namespace
  iio: pressure: bmp280: Move symbol exports to IIO_BMP280 namespace
  iio: imu: bmi160: Move exported symbols to IIO_BMI160 namespace
  iio: adc: stm32-adc: Use generic_handle_domain_irq()
  proximity: vl53l0x: Make VDD regulator actually optional
  MAINTAINERS: add include/dt-bindings/iio to IIO SUBSYSTEM AND DRIVERS
  dt-bindings: iio/accel: Fix adi,adxl345/6 example I2C address
  iio: gyro: bmg160: Fix typo in comment
  ...

2 years agoiio: adc: xilinx-xadc: Drop duplicate NULL check in xadc_parse_dt()
Andy Shevchenko [Tue, 31 May 2022 14:11:18 +0000 (17:11 +0300)]
iio: adc: xilinx-xadc: Drop duplicate NULL check in xadc_parse_dt()

The fwnode_for_each_child_node() is NULL-aware, no need to check
its parameters outside. Drop duplicate NULL check in xadc_parse_dt().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20220531141118.64540-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2 years agoiio: adc: xilinx-xadc: Make use of device properties
Andy Shevchenko [Tue, 31 May 2022 14:11:17 +0000 (17:11 +0300)]
iio: adc: xilinx-xadc: Make use of device properties

Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.

Add mod_devicetable.h include.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Michal Simek <michal.simek@amd.com>
Link: https://lore.kernel.org/r/20220531141118.64540-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2 years agoMerge tag 'misc-habanalabs-next-2022-07-12' of https://git.kernel.org/pub/scm/linux...
Greg Kroah-Hartman [Tue, 12 Jul 2022 08:53:21 +0000 (10:53 +0200)]
Merge tag 'misc-habanalabs-next-2022-07-12' of https://git./linux/kernel/git/ogabbay/linux into char-misc-next

Oded writes:

This tag contains habanalabs driver changes for v5.20:

- Add Gaudi2 ASIC support. All the features required for Gaudi2 are included
  in this tag (except the networking aspect).

- Add more events to the eventfd support in the driver. With the new code, we
  expose three events that the user can register to get notification about them.

- re-factor soft reset code and replace its name to compute reset to better
  reflect the actual reset done in new ASICs

- Change the way Gaudi2 triggers an MSI-X interrupt due to h/w bug.

- Improve the code of the debugfs node that scrubs the device's memory.

- Add mechanism for better compatibility with older f/w versions

- Cleanup kernel log prints by moving some prints to debug and removing others.

- Many small bug fixes and minor changes.

* tag 'misc-habanalabs-next-2022-07-12' of https://git.kernel.org/pub/scm/linux/kernel/git/ogabbay/linux: (88 commits)
  habanalabs: move h/w dirty message to debug
  habanalabs: rename soft reset to compute reset
  habanalabs: add status of reset after device release
  habanalabs: fix update of is_in_soft_reset
  habanalabs: expose only valid debugfs nodes
  habanalabs/gaudi2: map virtual MSI-X doorbell memory for user
  habanalabs/gaudi2: modify decoder to use virtual MSI-X doorbell
  habanalabs/gaudi2: modify CS completion CQ to use virtual MSI-X doorbell
  habanalabs/gaudi2: replace defines for reserved sob/mob with enums
  habanalabs/gaudi2: configure virtual MSI-X doorbell interface
  habanalabs: add a value field to hl_fw_send_pci_access_msg()
  habanalabs: fixes to the poll-timeout macros
  habanalabs/gaudi2: use DIV_ROUND_UP_SECTOR_T instead of roundup
  habanalabs: initialize variable explicitly
  habanalabs: Use the bitmap API to allocate bitmaps
  habanalabs/gaudi2: remove unused defines
  habanalabs: make sure variable is set before used
  habanalabs: don't declare tmp twice in same function
  habanalabs: do not set max power on a secured device
  habanalabs/gaudi2: SM mask can only be 8-bit
  ...

2 years agodrivers: mcb: directly use ida_alloc()/free()
keliu [Tue, 12 Jul 2022 06:50:08 +0000 (23:50 -0700)]
drivers: mcb: directly use ida_alloc()/free()

Use ida_alloc()/ida_free() instead of deprecated
ida_simple_get()/ida_simple_remove() .

Signed-off-by: keliu <liuke94@huawei.com>
Signed-off-by: Johannes Thumshirn <jth@kernel.org>
Link: https://lore.kernel.org/r/480676bee970da16bf1fa8565277240014395ba3.1657607743.git.johannes.thumshirn@wdc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2 years agohabanalabs: move h/w dirty message to debug
Oded Gabbay [Sun, 10 Jul 2022 11:14:04 +0000 (14:14 +0300)]
habanalabs: move h/w dirty message to debug

H/W being dirty during initialization is completely expected in case
f/w tools are used before loading the driver. As it is not an error,
and as it doesn't give any meaningful information to the user,
no point of printing it.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: rename soft reset to compute reset
Oded Gabbay [Thu, 7 Jul 2022 09:00:24 +0000 (12:00 +0300)]
habanalabs: rename soft reset to compute reset

Doing compute reset can be the traditional inference soft reset
that is supported only in Goya.

Or it can be the new reset upon device release, which is supported
in Gaudi2 and above.

Therefore, wherever suitable, use the terminology of compute reset
instead of soft reset.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add status of reset after device release
Oded Gabbay [Thu, 7 Jul 2022 08:42:15 +0000 (11:42 +0300)]
habanalabs: add status of reset after device release

The user might want to know the device is in reset after device
release, which is not an erroneous event as a regular reset.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: fix update of is_in_soft_reset
Oded Gabbay [Thu, 7 Jul 2022 08:39:19 +0000 (11:39 +0300)]
habanalabs: fix update of is_in_soft_reset

reset_info.is_in_soft_reset should be updated both before in_reset
and inside the spin lock of the reset info structure.

The reasons are:

- When we are inside soft reset, it implies we are in reset. Therefore,
  if someone checks if we are in soft reset, he can deduce we are
  in reset, while the opposite is not correct and might be misleading.

- Both these flags are changed together so they must be changed
  inside the reset info spinlock.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: expose only valid debugfs nodes
Ofir Bitton [Thu, 30 Jun 2022 06:54:59 +0000 (09:54 +0300)]
habanalabs: expose only valid debugfs nodes

In case security is enabled on the device, some debugfs nodes will
fail. Hence, we do not expose them.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: map virtual MSI-X doorbell memory for user
Tomer Tayar [Thu, 30 Jun 2022 19:05:51 +0000 (22:05 +0300)]
habanalabs/gaudi2: map virtual MSI-X doorbell memory for user

Upon the initialization of a user context, map the host memory page of
the virtual MSI-X doorbell in the device MMU.
A reserved VA is used for this purpose, so user can use it directly
without any allocation/map operation.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: modify decoder to use virtual MSI-X doorbell
Tomer Tayar [Thu, 30 Jun 2022 08:22:54 +0000 (11:22 +0300)]
habanalabs/gaudi2: modify decoder to use virtual MSI-X doorbell

Modify the decoder wrapper blocks to generate interrupts using the
virtual MSI-X doorbell.

As a decoder wrapper block cannot write directly to HBW upon completion,
it writes instead to SOB which is monitored by a master monitor.
When resolved, this monitor will be the one to actually write to the
virtual MSI-X doorbell.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: modify CS completion CQ to use virtual MSI-X doorbell
Tomer Tayar [Thu, 30 Jun 2022 15:40:59 +0000 (18:40 +0300)]
habanalabs/gaudi2: modify CS completion CQ to use virtual MSI-X doorbell

Modify the CQ which is used for CS completion, to use the virtual MSI-X
doorbell.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: replace defines for reserved sob/mob with enums
Tomer Tayar [Wed, 29 Jun 2022 16:20:38 +0000 (19:20 +0300)]
habanalabs/gaudi2: replace defines for reserved sob/mob with enums

Following patches are going to add more reserved sync objects and
monitors.
To make the counting of these reserved resources simpler, replace the
existing RESERVED_* defines with enumerations.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: configure virtual MSI-X doorbell interface
Tomer Tayar [Wed, 29 Jun 2022 13:37:55 +0000 (16:37 +0300)]
habanalabs/gaudi2: configure virtual MSI-X doorbell interface

Due to a watchdog timer in the LBW path, writes to the MSI-X doorbell
can return sporadic error responses.
To work-around this issue, a virtual MSI-X doorbell on the HBW path is
configured, using the MSI-X AXI slave interface in the PCIe controller.
Upon an access to a configured HBW host address, the controller will
generate MSI-X interrupt instead of treating the access as regular host
memory access.

This patch allocates the dedicate host memory page, and communicate the
address to F/W, so it will configure the relevant address match
registers in the controller, and will use this address to generate MSI-X
interrupts for F/W events.

Following patches will handle other initiators in the device, to move
them to use the virtual MSI-X doorbell.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add a value field to hl_fw_send_pci_access_msg()
Tomer Tayar [Wed, 6 Jul 2022 07:20:54 +0000 (10:20 +0300)]
habanalabs: add a value field to hl_fw_send_pci_access_msg()

For gaudi2 we need to send a value to F/W as part of the
PCI_ACCESS packet.
As a preparation, modify hl_fw_send_pci_access_msg() to have a 'value'
field.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: fixes to the poll-timeout macros
Ohad Sharabi [Mon, 4 Jul 2022 05:33:57 +0000 (08:33 +0300)]
habanalabs: fixes to the poll-timeout macros

- use conventional internal macro variables (double underscore prefix)
- adjust address casting
- on register poll using ELBI use ELBI read rather than BAR read on
  error condition
- remove unused macro

Signed-off-by: Ohad Sharabi <osharabi@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: use DIV_ROUND_UP_SECTOR_T instead of roundup
Ohad Sharabi [Thu, 7 Jul 2022 13:03:14 +0000 (16:03 +0300)]
habanalabs/gaudi2: use DIV_ROUND_UP_SECTOR_T instead of roundup

roundup will create an error in 32-bit architectures as we use
64-bit variables.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Ohad Sharabi <osharabi@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: initialize variable explicitly
Oded Gabbay [Tue, 5 Jul 2022 08:04:56 +0000 (11:04 +0300)]
habanalabs: initialize variable explicitly

Fix warning of
"warning: ‘old_base’ may be used uninitialized in this function"

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: Use the bitmap API to allocate bitmaps
Christophe JAILLET [Sun, 3 Jul 2022 20:36:30 +0000 (22:36 +0200)]
habanalabs: Use the bitmap API to allocate bitmaps

Use bitmap_zalloc()/bitmap_free() instead of hand-writing them.

It is less verbose and it improves the semantic.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: remove unused defines
Oded Gabbay [Mon, 4 Jul 2022 09:05:30 +0000 (12:05 +0300)]
habanalabs/gaudi2: remove unused defines

There were some defines that are unused in the current upstreamed
code.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: make sure variable is set before used
Oded Gabbay [Mon, 4 Jul 2022 08:53:57 +0000 (11:53 +0300)]
habanalabs: make sure variable is set before used

timestamp could be unset in both _hl_interrupt_wait_ioctl() and
_hl_interrupt_wait_ioctl_user_addr() so it is better to explicitly
initialize it to 0 when declaring it.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: don't declare tmp twice in same function
Oded Gabbay [Mon, 4 Jul 2022 08:51:55 +0000 (11:51 +0300)]
habanalabs: don't declare tmp twice in same function

tmp is declared in the scope of the function cs_do_release() and
inside a block inside that function.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: do not set max power on a secured device
Ofir Bitton [Thu, 30 Jun 2022 11:37:03 +0000 (14:37 +0300)]
habanalabs: do not set max power on a secured device

Max power API is not supported in secured devices. Hence, we should
skip setting it during boot.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: SM mask can only be 8-bit
Oded Gabbay [Thu, 30 Jun 2022 08:53:33 +0000 (11:53 +0300)]
habanalabs/gaudi2: SM mask can only be 8-bit

Otherwise, due to how we calculate it, we might fail in FIELD_PREP
checks.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: remove unused variable
Oded Gabbay [Thu, 30 Jun 2022 08:07:59 +0000 (11:07 +0300)]
habanalabs/gaudi2: remove unused variable

glbl_sts_clr_val was set but never used

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: allow detection of unsupported f/w packets
Oded Gabbay [Thu, 30 Jun 2022 06:30:49 +0000 (09:30 +0300)]
habanalabs: allow detection of unsupported f/w packets

If we send a packet to the f/w, and that packet is unsupported, we
want to be able to identify this situation and possibly ignore this.

Therefore, if the f/w returned an error, we need to propagate it
to the callers in the result value, if those callers were interested
in it.

In addition, no point of printing the error code here because each
caller prints its own error with a specific message.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: save f/w preboot minor version
Sagiv Ozeri [Tue, 28 Jun 2022 10:25:48 +0000 (13:25 +0300)]
habanalabs: save f/w preboot minor version

We need this property for backward compatibility against the f/w.

Signed-off-by: Sagiv Ozeri <sozeri@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add support for common decoder interrupts
Ofir Bitton [Tue, 28 Jun 2022 15:34:58 +0000 (18:34 +0300)]
habanalabs: add support for common decoder interrupts

User application should be able to get notification for any decoder
completion. Hence, we introduce a new interface in which a user
can wait for all current decoder pending interrupts.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: naming refactor of user interrupt flow
Ofir Bitton [Tue, 28 Jun 2022 18:05:28 +0000 (21:05 +0300)]
habanalabs: naming refactor of user interrupt flow

Current naming convention can be misleading. Hence renaming some
variables and defines in order to be more explicit.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: wait for preboot ready after hard reset
Ohad Sharabi [Tue, 28 Jun 2022 09:09:21 +0000 (12:09 +0300)]
habanalabs: wait for preboot ready after hard reset

Currently we are not waiting for preboot ready after hard reset.
This leads to a race in which COMMs protocol begins but will get no
response from the f/w.

Signed-off-by: Ohad Sharabi <osharabi@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: reset device upon critical ECC event
Ofir Bitton [Tue, 28 Jun 2022 05:34:28 +0000 (08:34 +0300)]
habanalabs/gaudi2: reset device upon critical ECC event

Correctable ECC events are not fatal, but as they accumulate, the f/w
can decide that a hard-rest is required. This indication is
propagated to the host using the existing ECC event interface.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: enable gaudi2 code in driver
Oded Gabbay [Mon, 27 Jun 2022 19:32:07 +0000 (22:32 +0300)]
habanalabs: enable gaudi2 code in driver

Enable the Gaudi2 ASIC code in the pci probe callback of the driver so
the driver will handle Gaudi2 ASICs.

Add the PCI ID to the PCI table and add the ASIC enum value to all
relevant places.

Fixup the device parameters initialization for Gaudi2.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add gaudi2 MMU support
Moti Haimovski [Mon, 27 Jun 2022 14:21:39 +0000 (17:21 +0300)]
habanalabs: add gaudi2 MMU support

Gaudi2 has new MMU units. A PMMU for device->host accesses, and HMMU
for HBM accesses.

The page tables of both MMUs are located in the host's memory (referred
to in the code as host-resident pgt).

Signed-off-by: Moti Haimovski <mhaimovski@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add gaudi2 wait-for-CS support
Oded Gabbay [Mon, 27 Jun 2022 12:05:28 +0000 (15:05 +0300)]
habanalabs: add gaudi2 wait-for-CS support

In Gaudi2 we moved to a different wait for command submission
completion model. Instead of receiving interrupt only on external
queues, we use the device's sync manager to notify us when the
entire command submission finishes.

This enables us to remove the categorization of queues to external
and internal, and treat each queue equally, without the need to parse
and patch any command buffer.

This change also requires refactoring to the IRQ handling of
CS completions.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: add gaudi2 profiler module
Benjamin Dotan [Sun, 26 Jun 2022 18:35:07 +0000 (21:35 +0300)]
habanalabs/gaudi2: add gaudi2 profiler module

Add the Gaudi2 code to initialize the ASIC's profiler. The profile
receives its initialization values from the user, same as in Gaudi2,
but the code to initialize is in the driver because the configuration
space of the device is not directly exposed to the user.

Signed-off-by: Benjamin Dotan <bdotan@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: add gaudi2 security module
Ofir Bitton [Sun, 26 Jun 2022 18:30:25 +0000 (21:30 +0300)]
habanalabs/gaudi2: add gaudi2 security module

Use the generic security module to block all registers in the ASIC and
then open only those that are needed to be accessed by the user.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add generic security module
Ofir Bitton [Sun, 26 Jun 2022 18:24:50 +0000 (21:24 +0300)]
habanalabs: add generic security module

As the ASICs become more complex and have many more registers, we need
a better way to configure the security properties.

As a reminder, we have two dedicated mechanisms for security:
Range Registers and Protection bits. Those mechanisms protect sensitive
memory and configuration areas inside the device.

The generic module handles the low-level part of the configuration,
because the configuration mechanism is identical in all ASICs. The
difference is the address ranges and register names.

Any ASIC that use this block should first block all the register
blocks in the ASIC. Then, it should open only the registers that
need to be accessed by the user (This is opposed to Goya and Gaudi,
where we blocked only what should not be accesses by the user).

The module contains several functions, to unblock single register,
multiple registers, entire blocks, ranges, ranges with mask.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: remove obsolete device variables used for testing
Oded Gabbay [Tue, 28 Jun 2022 07:53:17 +0000 (10:53 +0300)]
habanalabs: remove obsolete device variables used for testing

There are a couple of device variables that are used for testing
purposes and they are set to fixed values.

Remove the variables that are not relevant anymore and document the
remaining variables.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: initialize new asic properties
Oded Gabbay [Fri, 24 Jun 2022 13:58:23 +0000 (16:58 +0300)]
habanalabs: initialize new asic properties

New asic properties were added for Gaudi2. We want to initialize
and use them, when relevant, also for Goya and Gaudi.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add unsupported functions
Oded Gabbay [Fri, 24 Jun 2022 13:47:13 +0000 (16:47 +0300)]
habanalabs: add unsupported functions

There are a number of new ASIC-specific functions that were added
for Gaudi2. To make the common code work, we need to define empty
implementations of those functions for Goya and Gaudi.

Some functions will return error if called with Goya/Gaudi.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add gaudi2 asic-specific code
Oded Gabbay [Sun, 26 Jun 2022 15:20:03 +0000 (18:20 +0300)]
habanalabs: add gaudi2 asic-specific code

Add the ASIC-specific code for Gaudi2. Supply (almost) all of the
function callbacks that the driver's common code need to initialize,
finalize and submit workloads to the Gaudi2 ASIC.

It also contains the code to initialize the F/W of the Gaudi2 ASIC
and to receive events from the F/W.

It contains new debugfs entry to dump razwi events. razwi is a case
where the device's engines create a transaction that reaches an
invalid destination.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agouapi: habanalabs: add gaudi2 defines
Oded Gabbay [Fri, 24 Jun 2022 10:38:57 +0000 (13:38 +0300)]
uapi: habanalabs: add gaudi2 defines

Add the new defines for GAUDI2 uapi interface.

It includes the following:
1. Enums of engines and PLLs.
2. New information in the info IOCTL that is retrieved by the driver.
3. Update comments regarding the CB/CS/wait for CS ioctls.
4. New fields in the debug IOCTL for configuring the profiler for
   Gaudi2.

There is no new IOCTL.

Some of the changes are also relevant for Greco (which will be
upstreamed later this year). When ever it says "Greco and onwards",
it means it is also for Gaudi2.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi2: add asic registers header files
Oded Gabbay [Fri, 24 Jun 2022 15:56:42 +0000 (18:56 +0300)]
habanalabs/gaudi2: add asic registers header files

Add the relevant GAUDI2 ASIC registers header files. These files are
generated automatically from a tool maintained by the VLSI engineers.

There are more files which are not upstreamed because only very few
defines from those files are used in the driver. For those files, I
copied the relevant defines into gaudi2_regs.h and gaudi2_masks.h, to
reduce the size of this patch.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: remove redundant argument in access_dev_mem APIs
Ofir Bitton [Mon, 27 Jun 2022 13:59:02 +0000 (16:59 +0300)]
habanalabs: remove redundant argument in access_dev_mem APIs

Region structure is derived from region type, hence no need to pass
it as an argument.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: use %pa to print pci bar size
Oded Gabbay [Mon, 27 Jun 2022 08:30:43 +0000 (11:30 +0300)]
habanalabs: use %pa to print pci bar size

PCI bar size is resource_size_t so we should use %pa to make it work
correctly on all architectures.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: replace hl_poll_timeout with while loop
Dafna Hirschfeld [Sun, 26 Jun 2022 13:18:40 +0000 (16:18 +0300)]
habanalabs/gaudi: replace hl_poll_timeout with while loop

in gaudi_scrub_device_mem, replace call to hl_poll_timeout
with a while loop to avoid using dummy variables.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: communicate supported page sizes to user
Ohad Sharabi [Sat, 25 Jun 2022 20:36:13 +0000 (23:36 +0300)]
habanalabs: communicate supported page sizes to user

Because in future ASICs the driver will allow the user to set the
page size we need to make sure this data is propagated in all APIs.

In addition, since this is already an ASIC property we no longer need
ASIC function for it.

Signed-off-by: Ohad Sharabi <osharabi@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: remove dead code from free_device_memory()
Tomer Tayar [Fri, 24 Jun 2022 10:05:23 +0000 (13:05 +0300)]
habanalabs: remove dead code from free_device_memory()

free_device_memory() ends with if and else, each has a return statement,
followed by another return statement that can never be reached.
Restructure the function and remove this dead code.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: enable error interrupt on ARB WDT
Oded Gabbay [Fri, 24 Jun 2022 16:11:38 +0000 (19:11 +0300)]
habanalabs/gaudi: enable error interrupt on ARB WDT

We want to receive an error interrupt in case the watchdog timer
expires on arbitration event in the queues.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: page size can only be a power of 2
Ohad Sharabi [Wed, 22 Jun 2022 12:38:56 +0000 (15:38 +0300)]
habanalabs: page size can only be a power of 2

We dropped support for page sizes that are not power of 2.

Signed-off-by: Ohad Sharabi <osharabi@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: refactor dma asic-specific functions
Ohad Sharabi [Sun, 12 Jun 2022 12:00:29 +0000 (15:00 +0300)]
habanalabs: refactor dma asic-specific functions

This is a pre-requisite patch for adding tracepoints to the DMA memory
operations (allocation/free) in the driver.

The main purpose is to be able to cross data with the map operations and
determine whether memory violation occurred, for example free DMA
allocation before unmapping it from device memory.

To achieve this the DMA alloc/free code flows were refactored so that a
single DMA tracepoint will catch many flows.

Signed-off-by: Ohad Sharabi <osharabi@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: remove unused enum
Oded Gabbay [Fri, 24 Jun 2022 13:49:26 +0000 (16:49 +0300)]
habanalabs/gaudi: remove unused enum

Also beautify code by preferring single line wherever possible.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: mask constant value before cast
Oded Gabbay [Fri, 24 Jun 2022 13:45:02 +0000 (16:45 +0300)]
habanalabs/gaudi: mask constant value before cast

This fixes a sparse warning of
"cast truncates bits from constant value"

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: use correct type in assignment
Oded Gabbay [Fri, 24 Jun 2022 13:05:59 +0000 (16:05 +0300)]
habanalabs/gaudi: use correct type in assignment

packets are defined as LE so we need to convert before assigning
values to them.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: fix function name in comment
Oded Gabbay [Fri, 24 Jun 2022 13:04:30 +0000 (16:04 +0300)]
habanalabs/gaudi: fix function name in comment

function name in comment didn't match actual function name.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/goya: move dma direction enum to uapi file
Oded Gabbay [Fri, 24 Jun 2022 10:36:10 +0000 (13:36 +0300)]
habanalabs/goya: move dma direction enum to uapi file

The values in this enum are not used by h/w but are a contract
between userspace and the kernel driver so they must be defined
in the uapi file.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: set default value for memory_scrub
Dafna Hirschfeld [Thu, 12 May 2022 13:16:25 +0000 (16:16 +0300)]
habanalabs: set default value for memory_scrub

Set a default value for memory scrubbing

Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: move call to scrub_device_mem after ctx_fini
Dafna Hirschfeld [Thu, 12 May 2022 12:20:55 +0000 (15:20 +0300)]
habanalabs: move call to scrub_device_mem after ctx_fini

In future ASICs, it would be possible to have a non-idle
device when context is released. We thus need to postpone the
scrubbing. Postpone it to hpriv release if reset is not executed
or to device late init if reset is executed.

Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: use memory_scrub_val from debugfs
Dafna Hirschfeld [Thu, 23 Jun 2022 04:47:48 +0000 (07:47 +0300)]
habanalabs/gaudi: use memory_scrub_val from debugfs

In the callback scrub_device_mem, use 'memory_scrub_val'
from debugfs for the scrubbing value.

Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: don't send addr and size to scrub_device_mem cb
Dafna Hirschfeld [Thu, 23 Jun 2022 04:28:17 +0000 (07:28 +0300)]
habanalabs: don't send addr and size to scrub_device_mem cb

We use scrub_device_mem only to scrub the entire SRAM and entire
DRAM. Therefore there is no need to send addr and size
args to the callback.

Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: don't do memory scrubbing when unmapping
Dafna Hirschfeld [Tue, 10 May 2022 13:36:02 +0000 (16:36 +0300)]
habanalabs: don't do memory scrubbing when unmapping

There is no need to do memory scrub when unmapping anymore as it is
an overhead as long as we have a single user at any given time.

Remove that code and change return value of free_phys_pg_pack to void

Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: print if firmware is secured during load
Ofir Bitton [Wed, 22 Jun 2022 12:10:08 +0000 (15:10 +0300)]
habanalabs: print if firmware is secured during load

For easier debug, it is desirable to have a simple way
to know whether the device is secured or not, hence we dump this
indication during boot.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: fix a race condition causing DMAR error
Yuri Nudelman [Wed, 22 Jun 2022 09:52:34 +0000 (12:52 +0300)]
habanalabs/gaudi: fix a race condition causing DMAR error

There is a rare race condition in CB completion mechanism, that can
occur under a very high pressure of command submissions.
The preconditions for this to happen are:

 1. There should be enough command submissions for the pre-allocated
    patched CB pool to run out of commands. At this stage we start
    allocating new patched CBs as they arrive.
 2. CB size has to be exactly (128*n + 104)B for some n, i.e. 24B below
    a cache line end.

The flow:

 1. Two command buffers being completed on different streams, at the
    same time. Denote those CB1 and CB2.
 2. Each command buffer is injected with two messages, 16B each - one
    for a HBW update of the completion queue, another to raise
    interrupt.
 3. Assume CB1 updated the completion queue and raise the interrupt.
 4. Assume CB2 updated the completion queue but did not raise the
    interrupt yet.
 5. The host receives the interrupt. It goes over the completion queue
    and sees two completions - CB1 and CB2. Release them both.
 6. CB2 performs the last command. The problem is that the last command
    is split between 2 cache lines. So to read the last 8B of the last
    command, it has to access the host again. Problem is - CB2 is
    already released. This causes a DMAR error.

The solution to this problem is simply to make sure the last two
commands in the CB are always in the same cache line, using NOP padding.

Signed-off-by: Yuri Nudelman <ynudelman@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: fix warning: var might be used uninitialized
Koby Elbaz [Wed, 22 Jun 2022 07:42:42 +0000 (10:42 +0300)]
habanalabs/gaudi: fix warning: var might be used uninitialized

kernel test robot:
"warning: variable 'index' is used uninitialized whenever 'if' condition
is false"

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Koby Elbaz <kelbaz@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: move memory_scrub_val to hdev struct
Dafna Hirschfeld [Thu, 2 Jun 2022 08:55:00 +0000 (11:55 +0300)]
habanalabs: move memory_scrub_val to hdev struct

move the field memory_scrub_val from struct hl_dbg_device_entry
to struct hl_device. This is because we want to use
this field also if debugfs is off.

Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: fix comment style
Oded Gabbay [Sun, 19 Jun 2022 09:41:19 +0000 (12:41 +0300)]
habanalabs: fix comment style

function name should not be preceded with @

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: use kvcalloc when possible
Oded Gabbay [Sun, 19 Jun 2022 09:40:19 +0000 (12:40 +0300)]
habanalabs: use kvcalloc when possible

kvcalloc is same as kvmalloc_array with GFP_ZERO.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: print pointer with correct modifier
Oded Gabbay [Sun, 19 Jun 2022 09:37:01 +0000 (12:37 +0300)]
habanalabs: print pointer with correct modifier

Use %p instead of %llx for printing pointers.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: check fence pointer before use
Oded Gabbay [Sun, 19 Jun 2022 09:35:06 +0000 (12:35 +0300)]
habanalabs: check fence pointer before use

fence pointer can be NULL in this path, as shown by an earlier check.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add critical indication in sram ecc
ran shalit [Wed, 15 Jun 2022 18:24:38 +0000 (21:24 +0300)]
habanalabs: add critical indication in sram ecc

Multiple SRAM SERR events are treated as critical events,
and host should be notified about it. Thus, adding is_critical
indication as part of SRAM ECC failure packet.

Signed-off-by: ran shalit <rshalit@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: notify user process on device unavailable
Tal Cohen [Thu, 9 Jun 2022 15:08:31 +0000 (18:08 +0300)]
habanalabs/gaudi: notify user process on device unavailable

When a device error occurs, user process would like to get some
indication on the error by reading some device HW info. If the
device is unavailable, user process can't perform any HW device
reading.

Signed-off-by: Tal Cohen <talcohen@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: remove unused get_dma_desc_list_size
Oded Gabbay [Sat, 18 Jun 2022 18:27:07 +0000 (21:27 +0300)]
habanalabs: remove unused get_dma_desc_list_size

This asic callback function is not called anymore from the common code.
The asic-specific function itself is called but from within the
asic-specific code.

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: fix NULL dereference on cs timeout
Yuri Nudelman [Tue, 14 Jun 2022 12:14:20 +0000 (15:14 +0300)]
habanalabs: fix NULL dereference on cs timeout

Device descriptor is accessed before an assignment

Signed-off-by: Yuri Nudelman <ynudelman@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: fix shift out of bounds
Ofir Bitton [Wed, 15 Jun 2022 13:11:31 +0000 (16:11 +0300)]
habanalabs/gaudi: fix shift out of bounds

When validating NIC queues, queue offset calculation must be
performed only for NIC queues.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add validity check for cq counter offset
farah kassabri [Mon, 13 Jun 2022 13:22:20 +0000 (16:22 +0300)]
habanalabs: add validity check for cq counter offset

Driver performs no validity check for the user cq counter offset
used in both wait_for_interrupt and register_for_timestamp APIs.

Signed-off-by: farah kassabri <fkassabri@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: fix incorrect MME offset calculation
Koby Elbaz [Sun, 12 Jun 2022 19:16:25 +0000 (22:16 +0300)]
habanalabs/gaudi: fix incorrect MME offset calculation

Once FW raised an event following a MME2 QMAN error, the driver should
have gone to the corresponding status registers, trying to gather more
info on the error, yet it was accidentally accessing MME1 QMAN address
space.

Generally, we have x4 MMEs, while 0 & 2 are marked MASTER, and
1 & 3 are marked SLAVE. The former can be addressed, yet addressing
the latter is considered an access violation, and will result in a
hung system, which is what unintentionally happened above.
Note that this cannot happen in a secured system, since these registers
are protected with range registers.

Signed-off-by: Koby Elbaz <kelbaz@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: avoid unnecessary error print
Dani Liberman [Thu, 2 Jun 2022 13:15:03 +0000 (16:15 +0300)]
habanalabs: avoid unnecessary error print

When sending a packet to FW right after it made reset, we will get
packet timeout. Since it is expected behavior, we don't need to
print an error in such case.
Hence, when driver is in hard reset it will avoid from printing error
messages about packet timeout.

Signed-off-by: Dani Liberman <dliberman@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: send an event notification when CS timeout occurs
Tal Cohen [Thu, 19 May 2022 15:00:55 +0000 (18:00 +0300)]
habanalabs: send an event notification when CS timeout occurs

The Driver needs to inform the User process whenever one of its
CS is timed out. The Driver shall recognize the CS timeout and shall
send an eventfd notification, towards user space, whenever a timeout
is expired on a CS.

Signed-off-by: Tal Cohen <talcohen@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: send device reset notification
Tal Cohen [Wed, 8 Jun 2022 14:34:54 +0000 (17:34 +0300)]
habanalabs/gaudi: send device reset notification

Device reset event, indicates that the device shall be reset -
after a short delay. In such case, the driver sends a notification
towards the User process. This allows the User process
to be able to take several debug actions for system
diagnostic purposes.

Signed-off-by: Tal Cohen <talcohen@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: invoke device reset from one code block
Tal Cohen [Wed, 8 Jun 2022 13:02:09 +0000 (16:02 +0300)]
habanalabs/gaudi: invoke device reset from one code block

In order to prepare the driver code for device reset event
notification, change the event handler function flow to call
device reset from one code block.

In addition, the commit fixes an issue that reset was performed
w/o checking the 'hard_reset_on_fw_event' state and w/o setting
the HL_DRV_RESET_DELAY flag.

Signed-off-by: Tal Cohen <talcohen@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: expose undefined opcode status via info ioctl
Tal Cohen [Thu, 12 May 2022 08:59:41 +0000 (11:59 +0300)]
habanalabs: expose undefined opcode status via info ioctl

The info ioctl retrieves information on the last undefined opcode
occurred.

Signed-off-by: Tal Cohen <talcohen@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: collect undefined opcode error info
Tal Cohen [Wed, 11 May 2022 15:02:39 +0000 (18:02 +0300)]
habanalabs/gaudi: collect undefined opcode error info

when an undefined opcode error occurres, the driver collects
the relevant information from the Qman and stores it inside
the hdev data structure. An event fd indication is sent towards the
user space.

Note: another commit shall be followed which will add support to
read the error info by an ioctl.

Signed-off-by: Tal Cohen <talcohen@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: fix race between hl_get_compute_ctx() and hl_ctx_put()
Tomer Tayar [Sun, 22 May 2022 06:43:54 +0000 (09:43 +0300)]
habanalabs: fix race between hl_get_compute_ctx() and hl_ctx_put()

hl_get_compute_ctx() is used to get the pointer to the compute context
from the hpriv object.
The function is called in code paths that are not necessarily initiated
by user, so it is possible that a context release process will happen in
parallel.
This can lead to a race condition in which hl_get_compute_ctx()
retrieves the context pointer, and just before it increments the context
refcount, the context object is released and a freed memory is accessed.

To avoid this race, add a mutex to protect the context pointer in hpriv.
With this lock, hl_get_compute_ctx() will be able to detect if the
context has been released or is about to be released.

struct hl_ctx_mgr has a mutex for contexts IDR with a similar "ctx_lock"
name, so rename it to just "lock" to avoid a confusion with the new
lock.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: keep a record of completed CS outcomes
Yuri Nudelman [Tue, 24 May 2022 13:29:03 +0000 (16:29 +0300)]
habanalabs: keep a record of completed CS outcomes

Often, the user is not interested in the completion timestamp of all
command submissions.
A common situation is, for example, when the user submits a burst of,
possibly, several thousands of commands, then request the completion
timestamp of only couple of specific key commands from all the burst.
The problem is that currently, the outcome of the early commands may be
lost, due to a large amount of later commands, that the user does not
really care about.

This patch creates a separate store with the outcomes of commands the
user has mark explicitly as interested in. This store does not mix the
marked commands with the unmarked ones, hence the data there will
survive for much longer.

Signed-off-by: Yuri Nudelman <ynudelman@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: fix comment to reflect current code
Oded Gabbay [Sun, 5 Jun 2022 09:56:36 +0000 (12:56 +0300)]
habanalabs/gaudi: fix comment to reflect current code

Due to code changes in the past few years, the original comment of
how parser->user_cb_size is checked was not correct anymore.

Fix it to reflect current code and add more explanation as the code
is more complex now.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: change the write flag name of error info structs
Tal Cohen [Wed, 1 Jun 2022 08:32:35 +0000 (11:32 +0300)]
habanalabs: change the write flag name of error info structs

positive flags naming will make more clear code while adding
more 'error info' structures

Signed-off-by: Tal Cohen <talcohen@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs/gaudi: move tpc assert raise into internal func
Tal Cohen [Wed, 1 Jun 2022 20:14:16 +0000 (23:14 +0300)]
habanalabs/gaudi: move tpc assert raise into internal func

raising the tpc assert event in an internal function will make
the code cleaner as we are going to be adding more events

Signed-off-by: Tal Cohen <talcohen@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: align ioctl uapi structures to 64-bit
Dan Rapaport [Mon, 30 May 2022 11:11:45 +0000 (14:11 +0300)]
habanalabs: align ioctl uapi structures to 64-bit

The compiler is padding the members of the struct to be aligned to
64-bit. The content of the padded bytes is and not zeroed explicitly,
hence might copy undefined data. We add a padding member to the struct
to get a zeroed 64-bit align struct.

Signed-off-by: Dan Rapaport <drapaport@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: add terminating NULL to attrs arrays
Dafna Hirschfeld [Thu, 19 May 2022 07:54:30 +0000 (10:54 +0300)]
habanalabs: add terminating NULL to attrs arrays

Arrays of struct attribute are expected to be NULL terminated.
This is required by API methods such as device_add_groups.
This fixes a crash when loading the driver for Goya device.

Signed-off-by: Dafna Hirschfeld <dhirschfeld@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: Fix kernel-doc
Jiapeng Chong [Thu, 2 Jun 2022 03:58:27 +0000 (11:58 +0800)]
habanalabs: Fix kernel-doc

Fix the following W=1 kernel warnings:

drivers/misc/habanalabs/common/mmu/mmu_v1.c:425: warning: expecting
prototype for hl_mmu_fini(). Prototype was for hl_mmu_v1_fini() instead.

drivers/misc/habanalabs/common/mmu/mmu_v1.c:449: warning: expecting
prototype for hl_mmu_ctx_init(). Prototype was for hl_mmu_v1_ctx_init()
instead.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: Fix kernel-doc
Jiapeng Chong [Thu, 2 Jun 2022 03:58:26 +0000 (11:58 +0800)]
habanalabs: Fix kernel-doc

Fix the following W=1 kernel warnings:

drivers/misc/habanalabs/common/pci/pci.c:454: warning: expecting
prototype for hl_fw_fini(). Prototype was for hl_pci_fini() instead.

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agohabanalabs: fix double unlock on error in map_device_va()
Dan Carpenter [Wed, 25 May 2022 12:25:06 +0000 (15:25 +0300)]
habanalabs: fix double unlock on error in map_device_va()

If hl_mmu_prefetch_cache_range() fails then this code calls
mutex_unlock(&ctx->mmu_lock) when it's no longer holding the mutex.

Fixes: 9e495e24003e ("habanalabs: do MMU prefetch as deferred work")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
2 years agoMerge tag 'coresight-next-v5.20' of git://git.kernel.org/pub/scm/linux/kernel/git...
Greg Kroah-Hartman [Mon, 11 Jul 2022 18:54:28 +0000 (20:54 +0200)]
Merge tag 'coresight-next-v5.20' of git://git./linux/kernel/git/coresight/linux into char-misc-next

Suzuki writes:

CoreSight self-hosted tracing changes for v5.20.

 - Fixes LOCKDEP warnings on module unload with configfs
 - Conversion of DT bindings to DT schema
 - Branch broadcast support for perf cs_etm
 - Etm4x driver fixes for build failures with Clang and unrolled loops

Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
* tag 'coresight-next-v5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/coresight/linux:
  coresight: etm4x: avoid build failure with unrolled loops
  Documentation: coresight: Expand branch broadcast documentation
  Documentation: coresight: Link config options to existing documentation
  Documentation: coresight: Turn numbered subsections into real subsections
  coresight: Add config flag to enable branch broadcast
  Documentation: coresight: Escape coresight bindings file wildcard
  dt-bindings: arm: Convert CoreSight CPU debug to DT schema
  dt-bindings: arm: Convert CoreSight bindings to DT schema
  dt-bindings: arm: Rename Coresight filenames to match compatible
  coresight: syscfg: Update load and unload operations
  coresight: configfs: Fix unload of configurations on module exit
  coresight: Clear the connection field properly

2 years agoMerge tag 'fpga-late-for-5.20-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel...
Greg Kroah-Hartman [Mon, 11 Jul 2022 10:30:24 +0000 (12:30 +0200)]
Merge tag 'fpga-late-for-5.20-rc1' of ssh://gitolite./linux/kernel/git/fpga/linux-fpga into char-misc-next

Xu writes:

Here is the second set of FPGA changes for 5.20-rc1

FPGA Manager core:
- Ivan's change to support image offset and data size setting for
reprograming. A parse_header() callback is introduced for drivers to
specify these info.
- Colin's immediate spelling fix for Ivan's patch.

Microchip:
- Ivan's change to add Microchip MPF FPGA manager driver. And MAINTAINERS
entry added for the driver.

All patches have been reviewed on the mailing list, and have been in the
last linux-next releases (as part of our for-next branch).

Signed-off-by: Xu Yilun <yilun.xu@intel.com>
* tag 'fpga-late-for-5.20-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/fpga/linux-fpga:
  fpga: fpga-mgr: Fix spelling mistake "bitsream" -> "bitstream"
  MAINTAINERS: add Microchip PolarFire FPGA drivers entry
  dt-bindings: fpga: add binding doc for microchip-spi fpga mgr
  fpga: microchip-spi: add Microchip MPF FPGA manager
  docs: fpga: mgr: document parse_header() callback
  fpga: fpga-mgr: support bitstream offset in image buffer

2 years agoMerge tag 'mhi-for-v5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/mani/mhi...
Greg Kroah-Hartman [Mon, 11 Jul 2022 10:28:46 +0000 (12:28 +0200)]
Merge tag 'mhi-for-v5.20' of git://git./linux/kernel/git/mani/mhi into char-misc-next

Manivannan writes:

MHI Host
--------

Support for new modems:

 - Quectel EM120 FCCL based on SDX24. This product MHI configuration is same
   as EM120R-GL modem.
 - Foxconn Cinterion MV31-W. This product is same as the existing MV31-W
   modem but sold as a separate product as it uses a different firmware
   baseline.
 - Foxconn T99W175 based on SDX55.

Core changes:

 - Moved the IRQ allocation to MHI controller registration phase. Since the
   MHI endpoint may be powered up/down several times during runtime, it
   makes sense to move the IRQ allocation to registration phase and just
   enable/disable IRQs during endpoint power up/down.

MHI endpoint
------------

Core changes:

 - Added error check for dev_set_name()

* tag 'mhi-for-v5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/mani/mhi:
  bus: mhi: ep: Check dev_set_name() return value
  bus: mhi: host: pci_generic: Add another Foxconn T99W175
  bus: mhi: host: Move IRQ allocation to controller registration phase
  bus: mhi: host: pci_generic: Add Cinterion MV31-W with new baseline
  bus: mhi: host: pci_generic: Add support for Quectel EM120 FCCL modem

2 years agocoresight: etm4x: avoid build failure with unrolled loops
Nick Desaulniers [Fri, 8 Jul 2022 23:15:20 +0000 (16:15 -0700)]
coresight: etm4x: avoid build failure with unrolled loops

When the following configs are enabled:
* CORESIGHT
* CORESIGHT_SOURCE_ETM4X
* UBSAN
* UBSAN_TRAP

Clang fails assemble the kernel with the error:
<instantiation>:1:7: error: expected constant expression in '.inst' directive
.inst (0xd5200000|((((2) << 19) | ((1) << 16) | (((((((((((0x160 + (i * 4))))) >> 2))) >> 7) & 0x7)) << 12) | ((((((((((0x160 + (i * 4))))) >> 2))) & 0xf)) << 8) | (((((((((((0x160 + (i * 4))))) >> 2))) >> 4) & 0x7)) << 5)))|(.L__reg_num_x8))
      ^
drivers/hwtracing/coresight/coresight-etm4x-core.c:702:4: note: while in
macro instantiation
etm4x_relaxed_read32(csa, TRCCNTVRn(i));
^
drivers/hwtracing/coresight/coresight-etm4x.h:403:4: note: expanded from
macro 'etm4x_relaxed_read32'
read_etm4x_sysreg_offset((offset), false)))
^
drivers/hwtracing/coresight/coresight-etm4x.h:383:12: note: expanded
from macro 'read_etm4x_sysreg_offset'
__val = read_etm4x_sysreg_const_offset((offset));       \
        ^
drivers/hwtracing/coresight/coresight-etm4x.h:149:2: note: expanded from
macro 'read_etm4x_sysreg_const_offset'
READ_ETM4x_REG(ETM4x_OFFSET_TO_REG(offset))
^
drivers/hwtracing/coresight/coresight-etm4x.h:144:2: note: expanded from
macro 'READ_ETM4x_REG'
read_sysreg_s(ETM4x_REG_NUM_TO_SYSREG((reg)))
^
arch/arm64/include/asm/sysreg.h:1108:15: note: expanded from macro
'read_sysreg_s'
asm volatile(__mrs_s("%0", r) : "=r" (__val));                  \
             ^
arch/arm64/include/asm/sysreg.h:1074:2: note: expanded from macro '__mrs_s'
"       mrs_s " v ", " __stringify(r) "\n"                      \
 ^

Consider the definitions of TRCSSCSRn and TRCCNTVRn:
drivers/hwtracing/coresight/coresight-etm4x.h:56
 #define TRCCNTVRn(n)      (0x160 + (n * 4))
drivers/hwtracing/coresight/coresight-etm4x.h:81
 #define TRCSSCSRn(n)      (0x2A0 + (n * 4))

Where the macro parameter is expanded to i; a loop induction variable
from etm4_disable_hw.

When any compiler can determine that loops may be unrolled, then the
__builtin_constant_p check in read_etm4x_sysreg_offset() defined in
drivers/hwtracing/coresight/coresight-etm4x.h may evaluate to true. This
can lead to the expression `(0x160 + (i * 4))` being passed to
read_etm4x_sysreg_const_offset. Via the trace above, this is passed
through READ_ETM4x_REG, read_sysreg_s, and finally to __mrs_s where it
is string-ified and used directly in inline asm.

Regardless of which compiler or compiler options determine whether a
loop can or can't be unrolled, which determines whether
__builtin_constant_p evaluates to true when passed an expression using a
loop induction variable, it is NEVER safe to allow the preprocessor to
construct inline asm like:
  asm volatile (".inst (0x160 + (i * 4))" : "=r"(__val));
                                 ^ expected constant expression

Instead of read_etm4x_sysreg_offset() using __builtin_constant_p(), use
__is_constexpr from include/linux/const.h instead to ensure only
expressions that are valid integer constant expressions get passed
through to read_sysreg_s().

This is not a bug in clang; it's a potentially unsafe use of the macro
arguments in read_etm4x_sysreg_offset dependent on __builtin_constant_p.

Link: https://github.com/ClangBuiltLinux/linux/issues/1310
Reported-by: Arnd Bergmann <arnd@kernel.org>
Reported-by: Tao Zhang <quic_taozha@quicinc.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20220708231520.3958391-1-ndesaulniers@google.com
2 years agoMerge 5.19-rc6 into char-misc-next
Greg Kroah-Hartman [Mon, 11 Jul 2022 06:32:58 +0000 (08:32 +0200)]
Merge 5.19-rc6 into char-misc-next

We need the misc driver fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>