}
 }
 
+#define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
+
 void
 qla2x00_beacon_blink(struct scsi_qla_host *ha)
 {
        unsigned long flags;
        struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
 
-       if (ha->pio_address)
-               reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
-
        spin_lock_irqsave(&ha->hardware_lock, flags);
 
        /* Save the Original GPIOE. */
        if (ha->pio_address) {
-               gpio_enable = RD_REG_WORD_PIO(®->gpioe);
-               gpio_data = RD_REG_WORD_PIO(®->gpiod);
+               gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
+               gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
        } else {
                gpio_enable = RD_REG_WORD(®->gpioe);
                gpio_data = RD_REG_WORD(®->gpiod);
        gpio_enable |= GPIO_LED_MASK;
 
        if (ha->pio_address) {
-               WRT_REG_WORD_PIO(®->gpioe, gpio_enable);
+               WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
        } else {
                WRT_REG_WORD(®->gpioe, gpio_enable);
                RD_REG_WORD(®->gpioe);
 
        /* Set the modified gpio_data values */
        if (ha->pio_address) {
-               WRT_REG_WORD_PIO(®->gpiod, gpio_data);
+               WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
        } else {
                WRT_REG_WORD(®->gpiod, gpio_data);
                RD_REG_WORD(®->gpiod);
                return QLA_FUNCTION_FAILED;
        }
 
-       if (ha->pio_address)
-               reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
-
        /* Turn off LEDs. */
        spin_lock_irqsave(&ha->hardware_lock, flags);
        if (ha->pio_address) {
-               gpio_enable = RD_REG_WORD_PIO(®->gpioe);
-               gpio_data = RD_REG_WORD_PIO(®->gpiod);
+               gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
+               gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
        } else {
                gpio_enable = RD_REG_WORD(®->gpioe);
                gpio_data = RD_REG_WORD(®->gpiod);
 
        /* Set the modified gpio_enable values. */
        if (ha->pio_address) {
-               WRT_REG_WORD_PIO(®->gpioe, gpio_enable);
+               WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
        } else {
                WRT_REG_WORD(®->gpioe, gpio_enable);
                RD_REG_WORD(®->gpioe);
        /* Clear out previously set LED colour. */
        gpio_data &= ~GPIO_LED_MASK;
        if (ha->pio_address) {
-               WRT_REG_WORD_PIO(®->gpiod, gpio_data);
+               WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
        } else {
                WRT_REG_WORD(®->gpiod, gpio_data);
                RD_REG_WORD(®->gpiod);
        if (ha->pio_address) {
                uint16_t data2;
 
-               reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
-               WRT_REG_WORD_PIO(®->flash_address, (uint16_t)addr);
+               WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
                do {
-                       data = RD_REG_WORD_PIO(®->flash_data);
+                       data = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
                        barrier();
                        cpu_relax();
-                       data2 = RD_REG_WORD_PIO(®->flash_data);
+                       data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
                } while (data != data2);
        } else {
                WRT_REG_WORD(®->flash_address, (uint16_t)addr);
 
        /* Always perform IO mapped accesses to the FLASH registers. */
        if (ha->pio_address) {
-               reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
-               WRT_REG_WORD_PIO(®->flash_address, (uint16_t)addr);
-               WRT_REG_WORD_PIO(®->flash_data, (uint16_t)data);
+               WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
+               WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data);
        } else {
                WRT_REG_WORD(®->flash_address, (uint16_t)addr);
                RD_REG_WORD(®->ctrl_status);         /* PCI Posting. */