This tutorial is for windows only. A complete guide on how to install iOS 5.1 and jailbreak iPhone 4 on Mac has been discussed here. This tutorial guide you through the process of installing iOS 5.1 on iPhone 4 and jailbreaking it using redsn0w.
Upgrading your iPhone to iOS 5.1 through iTunes will update your baseband, removing your chances for an unlock. Please follow this tutorial on how to update to iOS 5.1 using a custom ipsw which prevents your iphone baseband from getting upgraded, if you rely on ultrasn0w unlock. This jailbreak for iOS 5.1 is tethered which means you will have to connect your device to the computer everytime you reboot