Former Ferrari driver Massa to quit at end of F1 season