1. Disconnect the negative battery cable.
2. Remove the headliner.
3. Disconnect the connector.
4. Remove the screws, and then remove the sunroof motor.

Sunroof unit disassembly/assembly
Sunroof motor installationMazda 6 Service Manual: Radar Sensors (Rear) (Some models)
Your vehicle is equipped with radar sensors (rear). The following systems also
use the radar sensors (rear).
Blind Spot Monitoring system (BSM)
Rear Cross Traffic Alert (RCTA)
The radar sensors (rear) function by detecting the radio waves reflected off
a vehicle approaching from the rea ...
Mazda 6 Service Manual: Immobilizer system reprogram procedure
Note
When an error occurs during the reprogram procedures, except when
the PCM is replaced, repeat the procedure from Step 1. If you still cannot
reprogram, confirm how many keys can start the engine. Then, perform the key
replacement or addition reprogram procedure according to the val ...