The 3G/3GS can be software unlocked using UltraSn0w under the proper requirements. On the 4S and above, you can purchase an interposer such as the R-SIM to unlock your device, but upgrading your iOS is dependent on whether or not the iOS and device combination post-upgrade is supported by the software component of the interposer.