2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
10 static inline void eeprom_cmd(uint32_t cmd
, struct scsi_qla_host
*ha
)
12 writel(cmd
, isp_nvram(ha
));
17 static inline int eeprom_size(struct scsi_qla_host
*ha
)
19 return is_qla4010(ha
) ? FM93C66A_SIZE_16
: FM93C86A_SIZE_16
;
22 static inline int eeprom_no_addr_bits(struct scsi_qla_host
*ha
)
24 return is_qla4010(ha
) ? FM93C56A_NO_ADDR_BITS_16
:
25 FM93C86A_NO_ADDR_BITS_16
;
28 static inline int eeprom_no_data_bits(struct scsi_qla_host
*ha
)
30 return FM93C56A_DATA_BITS_16
;
33 static int fm93c56a_select(struct scsi_qla_host
* ha
)
35 DEBUG5(printk(KERN_ERR
"fm93c56a_select:\n"));
37 ha
->eeprom_cmd_data
= AUBURN_EEPROM_CS_1
| 0x000f0000;
38 eeprom_cmd(ha
->eeprom_cmd_data
, ha
);
42 static int fm93c56a_cmd(struct scsi_qla_host
* ha
, int cmd
, int addr
)
49 /* Clock in a zero, then do the start bit. */
50 eeprom_cmd(ha
->eeprom_cmd_data
| AUBURN_EEPROM_DO_1
, ha
);
52 eeprom_cmd(ha
->eeprom_cmd_data
| AUBURN_EEPROM_DO_1
|
53 AUBURN_EEPROM_CLK_RISE
, ha
);
54 eeprom_cmd(ha
->eeprom_cmd_data
| AUBURN_EEPROM_DO_1
|
55 AUBURN_EEPROM_CLK_FALL
, ha
);
57 mask
= 1 << (FM93C56A_CMD_BITS
- 1);
59 /* Force the previous data bit to be different. */
61 for (i
= 0; i
< FM93C56A_CMD_BITS
; i
++) {
63 (cmd
& mask
) ? AUBURN_EEPROM_DO_1
: AUBURN_EEPROM_DO_0
;
64 if (previousBit
!= dataBit
) {
67 * If the bit changed, then change the DO state to
70 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
, ha
);
71 previousBit
= dataBit
;
73 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
|
74 AUBURN_EEPROM_CLK_RISE
, ha
);
75 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
|
76 AUBURN_EEPROM_CLK_FALL
, ha
);
80 mask
= 1 << (eeprom_no_addr_bits(ha
) - 1);
82 /* Force the previous data bit to be different. */
84 for (i
= 0; i
< eeprom_no_addr_bits(ha
); i
++) {
85 dataBit
= addr
& mask
? AUBURN_EEPROM_DO_1
:
87 if (previousBit
!= dataBit
) {
89 * If the bit changed, then change the DO state to
92 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
, ha
);
94 previousBit
= dataBit
;
96 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
|
97 AUBURN_EEPROM_CLK_RISE
, ha
);
98 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
|
99 AUBURN_EEPROM_CLK_FALL
, ha
);
106 static int fm93c56a_deselect(struct scsi_qla_host
* ha
)
108 ha
->eeprom_cmd_data
= AUBURN_EEPROM_CS_0
| 0x000f0000;
109 eeprom_cmd(ha
->eeprom_cmd_data
, ha
);
113 static int fm93c56a_datain(struct scsi_qla_host
* ha
, unsigned short *value
)
119 /* Read the data bits
120 * The first bit is a dummy. Clock right over it. */
121 for (i
= 0; i
< eeprom_no_data_bits(ha
); i
++) {
122 eeprom_cmd(ha
->eeprom_cmd_data
|
123 AUBURN_EEPROM_CLK_RISE
, ha
);
124 eeprom_cmd(ha
->eeprom_cmd_data
|
125 AUBURN_EEPROM_CLK_FALL
, ha
);
127 dataBit
= (readw(isp_nvram(ha
)) & AUBURN_EEPROM_DI_1
) ? 1 : 0;
129 data
= (data
<< 1) | dataBit
;
136 static int eeprom_readword(int eepromAddr
, u16
* value
,
137 struct scsi_qla_host
* ha
)
140 fm93c56a_cmd(ha
, FM93C56A_READ
, eepromAddr
);
141 fm93c56a_datain(ha
, value
);
142 fm93c56a_deselect(ha
);
146 /* Hardware_lock must be set before calling */
147 u16
rd_nvram_word(struct scsi_qla_host
* ha
, int offset
)
151 /* NOTE: NVRAM uses half-word addresses */
152 eeprom_readword(offset
, &val
, ha
);
156 int qla4xxx_is_nvram_configuration_valid(struct scsi_qla_host
* ha
)
158 int status
= QLA_ERROR
;
159 uint16_t checksum
= 0;
163 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
164 for (index
= 0; index
< eeprom_size(ha
); index
++)
165 checksum
+= rd_nvram_word(ha
, index
);
166 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
169 status
= QLA_SUCCESS
;
174 /*************************************************************************
176 * Hardware Semaphore routines
178 *************************************************************************/
179 int ql4xxx_sem_spinlock(struct scsi_qla_host
* ha
, u32 sem_mask
, u32 sem_bits
)
183 unsigned int seconds
= 30;
185 DEBUG2(printk("scsi%ld : Trying to get SEM lock - mask= 0x%x, code = "
186 "0x%x\n", ha
->host_no
, sem_mask
, sem_bits
));
188 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
189 writel((sem_mask
| sem_bits
), isp_semaphore(ha
));
190 value
= readw(isp_semaphore(ha
));
191 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
192 if ((value
& (sem_mask
>> 16)) == sem_bits
) {
193 DEBUG2(printk("scsi%ld : Got SEM LOCK - mask= 0x%x, "
194 "code = 0x%x\n", ha
->host_no
,
195 sem_mask
, sem_bits
));
203 void ql4xxx_sem_unlock(struct scsi_qla_host
* ha
, u32 sem_mask
)
207 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
208 writel(sem_mask
, isp_semaphore(ha
));
209 readl(isp_semaphore(ha
));
210 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
212 DEBUG2(printk("scsi%ld : UNLOCK SEM - mask= 0x%x\n", ha
->host_no
,
216 int ql4xxx_sem_lock(struct scsi_qla_host
* ha
, u32 sem_mask
, u32 sem_bits
)
221 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
222 writel((sem_mask
| sem_bits
), isp_semaphore(ha
));
223 value
= readw(isp_semaphore(ha
));
224 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
225 if ((value
& (sem_mask
>> 16)) == sem_bits
) {
226 DEBUG2(printk("scsi%ld : Got SEM LOCK - mask= 0x%x, code = "
227 "0x%x, sema code=0x%x\n", ha
->host_no
,
228 sem_mask
, sem_bits
, value
));