Given a prime number $p$, and an irreducible polynomial $f$ of degree $2$ over $\mathbb{F}_p$. Let $n$ be a positive integer, and define: \begin{equation*} S:=\sum_{a\in \mathbb{F}_p[t], \deg{a}\leq 1} a^n. \end{equation*}

We can easily show that $S$ is nonzero only when:

1) $n$ is divisible by $p-1$;

2) if we write $n$ as $\sum_{i=0}^l c_i p^{n_i}$ with $1\le c_i \le p-1$ for all $i$, then the summation of all $c_i$'s should be at least $2(p-1)$.

I am interested in the distribution of $v_f(S)$ when $n$ varies.

By symmetry it is easy to get an upper bound of this valuation, namely, $\frac{n}{2p}$. I am wondering whether there is a formula for this valuation or any better bound.

Any some further questions:

1) What if $f$ is of higher degrees?

2) What if we substitute $p$ with some prime power?