My dalmatian does this often and it is related to him having urinary crystals. He is on a low protein diet and has stopped "attacking" his penis with such vigor. I think he did it because it was causing a stinging burning sensation. If your dog continues I would recommend getting his urine tested for crystals.