2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2010 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
11 #include "ql4_inline.h"
13 static inline void eeprom_cmd(uint32_t cmd
, struct scsi_qla_host
*ha
)
15 writel(cmd
, isp_nvram(ha
));
20 static inline int eeprom_size(struct scsi_qla_host
*ha
)
22 return is_qla4010(ha
) ? FM93C66A_SIZE_16
: FM93C86A_SIZE_16
;
25 static inline int eeprom_no_addr_bits(struct scsi_qla_host
*ha
)
27 return is_qla4010(ha
) ? FM93C56A_NO_ADDR_BITS_16
:
28 FM93C86A_NO_ADDR_BITS_16
;
31 static inline int eeprom_no_data_bits(struct scsi_qla_host
*ha
)
33 return FM93C56A_DATA_BITS_16
;
36 static int fm93c56a_select(struct scsi_qla_host
* ha
)
38 DEBUG5(printk(KERN_ERR
"fm93c56a_select:\n"));
40 ha
->eeprom_cmd_data
= AUBURN_EEPROM_CS_1
| 0x000f0000;
41 eeprom_cmd(ha
->eeprom_cmd_data
, ha
);
45 static int fm93c56a_cmd(struct scsi_qla_host
* ha
, int cmd
, int addr
)
52 /* Clock in a zero, then do the start bit. */
53 eeprom_cmd(ha
->eeprom_cmd_data
| AUBURN_EEPROM_DO_1
, ha
);
55 eeprom_cmd(ha
->eeprom_cmd_data
| AUBURN_EEPROM_DO_1
|
56 AUBURN_EEPROM_CLK_RISE
, ha
);
57 eeprom_cmd(ha
->eeprom_cmd_data
| AUBURN_EEPROM_DO_1
|
58 AUBURN_EEPROM_CLK_FALL
, ha
);
60 mask
= 1 << (FM93C56A_CMD_BITS
- 1);
62 /* Force the previous data bit to be different. */
64 for (i
= 0; i
< FM93C56A_CMD_BITS
; i
++) {
66 (cmd
& mask
) ? AUBURN_EEPROM_DO_1
: AUBURN_EEPROM_DO_0
;
67 if (previousBit
!= dataBit
) {
70 * If the bit changed, then change the DO state to
73 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
, ha
);
74 previousBit
= dataBit
;
76 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
|
77 AUBURN_EEPROM_CLK_RISE
, ha
);
78 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
|
79 AUBURN_EEPROM_CLK_FALL
, ha
);
83 mask
= 1 << (eeprom_no_addr_bits(ha
) - 1);
85 /* Force the previous data bit to be different. */
87 for (i
= 0; i
< eeprom_no_addr_bits(ha
); i
++) {
88 dataBit
= addr
& mask
? AUBURN_EEPROM_DO_1
:
90 if (previousBit
!= dataBit
) {
92 * If the bit changed, then change the DO state to
95 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
, ha
);
97 previousBit
= dataBit
;
99 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
|
100 AUBURN_EEPROM_CLK_RISE
, ha
);
101 eeprom_cmd(ha
->eeprom_cmd_data
| dataBit
|
102 AUBURN_EEPROM_CLK_FALL
, ha
);
109 static int fm93c56a_deselect(struct scsi_qla_host
* ha
)
111 ha
->eeprom_cmd_data
= AUBURN_EEPROM_CS_0
| 0x000f0000;
112 eeprom_cmd(ha
->eeprom_cmd_data
, ha
);
116 static int fm93c56a_datain(struct scsi_qla_host
* ha
, unsigned short *value
)
122 /* Read the data bits
123 * The first bit is a dummy. Clock right over it. */
124 for (i
= 0; i
< eeprom_no_data_bits(ha
); i
++) {
125 eeprom_cmd(ha
->eeprom_cmd_data
|
126 AUBURN_EEPROM_CLK_RISE
, ha
);
127 eeprom_cmd(ha
->eeprom_cmd_data
|
128 AUBURN_EEPROM_CLK_FALL
, ha
);
130 dataBit
= (readw(isp_nvram(ha
)) & AUBURN_EEPROM_DI_1
) ? 1 : 0;
132 data
= (data
<< 1) | dataBit
;
139 static int eeprom_readword(int eepromAddr
, u16
* value
,
140 struct scsi_qla_host
* ha
)
143 fm93c56a_cmd(ha
, FM93C56A_READ
, eepromAddr
);
144 fm93c56a_datain(ha
, value
);
145 fm93c56a_deselect(ha
);
149 /* Hardware_lock must be set before calling */
150 u16
rd_nvram_word(struct scsi_qla_host
* ha
, int offset
)
154 /* NOTE: NVRAM uses half-word addresses */
155 eeprom_readword(offset
, &val
, ha
);
159 u8
rd_nvram_byte(struct scsi_qla_host
*ha
, int offset
)
166 index
= (offset
- 1) / 2;
170 val
= le16_to_cpu(rd_nvram_word(ha
, index
));
173 rval
= (u8
)((val
& 0xff00) >> 8);
175 rval
= (u8
)((val
& 0x00ff));
180 int qla4xxx_is_nvram_configuration_valid(struct scsi_qla_host
* ha
)
182 int status
= QLA_ERROR
;
183 uint16_t checksum
= 0;
187 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
188 for (index
= 0; index
< eeprom_size(ha
); index
++)
189 checksum
+= rd_nvram_word(ha
, index
);
190 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
193 status
= QLA_SUCCESS
;
198 /*************************************************************************
200 * Hardware Semaphore routines
202 *************************************************************************/
203 int ql4xxx_sem_spinlock(struct scsi_qla_host
* ha
, u32 sem_mask
, u32 sem_bits
)
207 unsigned int seconds
= 30;
209 DEBUG2(printk("scsi%ld : Trying to get SEM lock - mask= 0x%x, code = "
210 "0x%x\n", ha
->host_no
, sem_mask
, sem_bits
));
212 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
213 writel((sem_mask
| sem_bits
), isp_semaphore(ha
));
214 value
= readw(isp_semaphore(ha
));
215 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
216 if ((value
& (sem_mask
>> 16)) == sem_bits
) {
217 DEBUG2(printk("scsi%ld : Got SEM LOCK - mask= 0x%x, "
218 "code = 0x%x\n", ha
->host_no
,
219 sem_mask
, sem_bits
));
227 void ql4xxx_sem_unlock(struct scsi_qla_host
* ha
, u32 sem_mask
)
231 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
232 writel(sem_mask
, isp_semaphore(ha
));
233 readl(isp_semaphore(ha
));
234 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
236 DEBUG2(printk("scsi%ld : UNLOCK SEM - mask= 0x%x\n", ha
->host_no
,
240 int ql4xxx_sem_lock(struct scsi_qla_host
* ha
, u32 sem_mask
, u32 sem_bits
)
245 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
246 writel((sem_mask
| sem_bits
), isp_semaphore(ha
));
247 value
= readw(isp_semaphore(ha
));
248 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
249 if ((value
& (sem_mask
>> 16)) == sem_bits
) {
250 DEBUG2(printk("scsi%ld : Got SEM LOCK - mask= 0x%x, code = "
251 "0x%x, sema code=0x%x\n", ha
->host_no
,
252 sem_mask
, sem_bits
, value
));