Social Security/Medicare and Self-Employment

Upon retirement age, is Social Security available for those who have solely self-employed?

What about Medicare?

If not, how many years of contributions through a W-2 job are required to qualify for these benefits?

Or, what else can I do to provide for these future costs?