The expression comes from the world of military aviation. In many planes, control sticks are topped with a ball-shaped grip. One such control is the throttle—to get maximum power you push it all the way forward, to the front of the cockpit, or firewall (so-called because it prevents an engine fire from reaching the rest of the plane). Another control is the joystick—pushing it forward sends a plane into a dive. So, literally pushing the balls to the (fire)wall would put a plane into a maximum-speed dive, and figuratively going balls to the wall is doing something all-out, with maximum effort. The phrase is essentially the aeronautical equivalent of the automotive "pedal to the metal."