Ideally the person performing the scrum master role would only perform that work, to avoid conflict of interest. Combining Product Owner and Scrum Master in the same role is usually disasterous. Combining Scrum Master and QA can be effective, if the person has the excellent persuasive abilities and meeting facilitation skills.
If that's not possible, the person needs to have the personality strength and persuasive ability to protect the team from interruptions from the Product Owner, and others with more power in the organization.
On the best teams, the scrum master's focus is on helping the team be productive. The scrum master sets up the sprint planning, estimation and review meetings and works with the Product Owner to get the PBL narrowed down to work items that the team can quickly make estimates on.
In many companies, the Product Owner and Scrum Master roles are combined into one person, this usually leads to PBL items being given to the team in incomplete form, causing the team to waste time defining unclear requirements, and often working on the wrong things, since the requirements weren't clear at the start of the sprint.
Developers or QA can sometimes perform well as a team's scrum master, but both are importantant for getting work done, so the time they spend on the scrum master role decreases the amount of code they can write or test.
A scrum master is seen as the protector of the team, as well as the motivator, the scrum master prevents changes to the work being done by the team during the sprint, coordinates with other teams impacted by the team's work, drives team members to get their work done and recording tools updated.
Here's a good article on the scrum master role:
The ScrumMaster is also often viewed as a protector of the team. The most common example is that the ScrumMaster protects the team by making sure they do not over-commit themselves to what they can achieve during a sprint due to pressure from an overly aggressive product owner. However, a good ScrumMaster also protects the team from complacency.