You can check the device’s maximum discard sizes, e.g.
$ cat /sys/block/X/queue/discard_max_hw_bytes
X as appropriate).
If this shows a value greater than 0, the device supports discards:
discard_max_hw_bytes value of 0 means that the device does not
support discard functionality.
The maximum supported discard size is indicated by
discard_max_bytes in the same directory; this can be smaller than the hardware-supported value to limit discard latencies (and can be written to to change the limit):
discard_max_hw_bytes is the hardware limit for the
device, this setting is the software limit. Some devices exhibit
large latencies when large discards are issued, setting this
value lower will make Linux issue smaller discards and
potentially help reduce latencies induced by large discard
This works on many different block devices, not just disks: loop devices, device mapper devices, etc.