Functional It\^o formula for fractional Brownian motion