Unless this is a Tesla K40c (actively cooled, with a fan) it’s designed to be integrated into servers. In which case you would buy a system with the K40 already installed from a system integrator. Any other setup is unsupported.
There are people who have built custom water-cooling or built their own forced air-cooling with fans and cooling ducts to get such server GPUs to run inside workstations. Search the Internet and Youtube in particular. I am not endorsing this approach, but here is one video where someone did this for a K80, linked here purely for entertainment purposes: https://www.youtube.com/watch?v=UcyP3ASRgBc
There may be issues other than cooling, such as insufficient BAR memory range provided by the system BIOS. Or your K40 may be defective. I have used K40s (both actively and passively cooled) but do not know what a “d4” error code is or where that is reported.
Personally, I would not bother trying to get this outdated GPU to run. It is a reasonable assumption that the next major version of CUDA will no longer support it.