Assuming you had your SHSH blobs saved in Cydia:
1. Download TinyUmbrella and w/e FW version ipsw (get it from
here)you have the shsh blobs saved for (ie if you were on 4.0 and had saved your 4.0 blobs, then download the 4.0 ipsw).
2. Enter DFU mode and connect iPhone to your computer.
3. Open TinyUmbrella. Confirm that you have your SHSH for the correct FW version saved (choose your phone in the left menu, tick Advanced Options, then open the menu that will appear and select iPhone3GS/x.x.x (x.x.x being your download IPSW's firmware version) and click Save my SHSH). It should say SHSH blobs cached if the blobs had been saved on Cydia's server.
4. Click Start TSS Server. iTunes should close and re-open (if it was open). Otherwise open iTunes.
[DO NOT CLOSE TINYUMBRELLA UNTIL THE END]
5. iTunes will say that it has detected an iPhone in recovery mode and that you must restore to use your iPhone. Click OK.
6. Shift-click Restore (on a PC) or Alt-click (on a Mac). In the Explorer/Finder window that pops up, navigate to your downloaded IPSW and click OK.
7. iPhone should restore to your IPSW's firmware. Again, TinyUmbrella must be open throughout this entire process.
8. Done- jailbreak and unlock your phone.
If you get Error 1600, click 'Kick device out of recovery' in TinyUmbrella.
If step 4 fails, add '74.208.10.249 gs.apple.com' to your hosts file.
In Windows, the host file is located in 'c:\windows\system32\drivers\etc\'
On the Mac, the host file is located in '/private/etc/hosts'.
You may need to get root access to write to these files. Google on how to do it.
Hope this helps.