Maximal values of generalized algebraic immunity