It is ambiguous and could have either meaning, or it could mean both at once. Teachers have some discretion on who to give a passing or failing grade to. If you feel that the cause of the "F" is the teacher's (unfair) grading you can say "The teacher failed me" to mean "... gave me a failing grade". This is rather casual.
You can also use "the teacher failed me" to mean "... didn't teach me well" This meaning is rather more formal. You need to consider the context to understand which is meant:
I got an "F" in Science!? I can't believe Mr Henderson failed me, even after I offered to tidy the lab every week before the test.
We think Mr Henderson failed us because he didn't arrive to lessons on time, never graded our papers, and his explainations were confused and unclear. I could have obtained a grade A instead of a C if we had had a better teacher.