  We identify the class of f(R) dark energy models which have a viable
cosmology, i.e. a matter dominated epoch followed by a late-time acceleration.
The deviation from a LambdaCDM model (f=R-Lambda) is quantified by the function
m=Rf_{,RR}/f_{,R}. The matter epoch corresponds to m(r=-1) simeq +0 (where
r=-Rf_{,R}/f) while the accelerated attractor exists in the region 0<m<1. We
find that the equation of state w_DE of all such ``viable'' f(R) models
exhibits two features: w_DE diverges at some redshift z_{c} and crosses the
cosmological constant boundary (``phantom crossing'') at a redshift z_{b}
smaller than z_{c}. Using the observational data of Supernova Ia and Cosmic
Microwave Background, we obtain the constraint m<O(0.1) and we find that the
phantom crossing could occur at z_{b}>1, i.e. within reach of observations. If
we add local gravity constraints, the bound on m becomes very stringent, with m
several orders of magnitude smaller than unity in the region whose density is
much larger than the present cosmological density. The representative models
that satisfy both cosmological and local gravity constraints take the
asymptotic form m(r)=C(-r-1)^p with p>1 as r approaches -1.
