"And I will make My covenant between Me and you" (Genesis 17:2). Rabbi Hanina ben Pazzi said: Abraham did not know from where he was to be circumcised. The Holy One, blessed be He, gave him a hint and told him from where he was to be circumcised, as it continues, "and I will multiply you" (Genesis 17:2) — from the place from which you are fruitful and multiply. Bar Kappara said: Abraham expounded a kal va-chomer (an argument from minor to major). Just as trees — from where are they obligated in regard to the foreskin (orlah)? From the place where they produce fruit. So too I, from the place where I produce fruit I am obligated to be circumcised.
How Abraham Knew Where to Circumcise From God's Covenant Hint
Midrash Tanchuma Buber, Lech Lecha 27:1
ואתנה בריתי ביני ובינך (שם יז ב), אמר ר' חנינא בן פזי לא היה יודע אברהם מהיכן לימול, רמז לו הקב"ה ואמר מהיכן לימול. וארבה אותך ממקום שאתה פרה ורבה. בר קפרא אומר קל וחומר דרש אברהם, ומה אילנות מהיכן חייבין בערלה, ממקום שהן עושין פרי, אף אני ממקום שאני עשה פרי אני צריך לימול.