Since the D40 doesn't have in-body focusing motor, you would only be able to use it as a manual focus lens. Also, the effective focal length on your D40 is 122. I have a D300s and a D700. The focus is fast on the D700, slightly slower on the D300s. It is a superb lens, but overkill for a D40. Buy the DX 85 mm f/3.5 or the 85 mm f/1.8 for well less than half the price.
DX describes the crop that most digital SLRs have because their sensor is smaller than a piece of 35mm film. It is roughly 1.6x smaller. "Effective focal length" describes this difference for any particular lens focal length. FX is used to describe a digital SLR camera that has a sensor roughly the same size as a 35mm piece of film. DX and SX are also used to describe lenses, because some only make a circle of light large enough to cover a DX camera's small sensor. This makes the lenses lighter, cheaper, and has no disadvantage with a DX camera, but they don't cover a FX sensor.
A small point of clarification (sorry, personal mission) on Craigs comment, "It is roughly 1.6x smaller." Firstly, 1.6x is for Canon only; Nikon (who actually uses the name DX) and Sony are closer to 1.5x (i.e., they are bigger than Canon's.) Secondly, and more importantly, it is the DIAGONAL that is about 1.5-1.6x smaller. That is, if you take the diagonal of a Nikon APS-C sensor and increase it by 50%, you get a Full-Frame (which Nikon call FX) sensor's diagonal. In terms of area of the sensor, which is what I think about when one says "size", the Full-Frame sensor is 2.3-2.6x the area of an APS-C sensor. Put another way, an APS-C sensor is 38-42% of the size (area) of a Full-Frame sensor. APS-C is not even "half-frame".
It's a great portrait lens. It will be wonderful on the a d40. I think that it really comes into it's own on fx though. That way you can really take advantage of the narrow depth of field as well as precise focus .