Generalized Chern-Simons action and maximally supersymmetric gauge theories