Thanks for your query.Based on the facts that you have posted it appears that you have developed infection of Glans Penis
and Foreskin.(Ballano Posthatitis) and deposition of smegma
behind the foreskin.
You are also not able to retract foreskin due to what is called as Phimosis
Take some antibiotics like Doxycucline foe a week along with some topical anti fungal gel for local application.
If problem persists even after this treatment you may need to get circucised by a General Surgeon
.This will solve your problem permanently.