Mazdaspeed started as a seperate entity to Mazda in Japan and was integrated into the company. It is the racing division of Mazda. Mazdaspeed NA is also seperate from Mazdaspeed Japan.
Similar to how AMG became MB in house tuning division after being a seperate entity.
The MSP and MSM(I am talking North America) were produced under Mazdaspeed NA. Lots of manufacturers farm out work. The MSP being the first car Mazdaspeed NA released, lots was farmed out. The MSM was produced in house for the most part.