2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
10 static inline int eeprom_size(struct scsi_qla_host *ha)
12 return is_qla4022(ha) ? FM93C86A_SIZE_16 : FM93C66A_SIZE_16;
15 static inline int eeprom_no_addr_bits(struct scsi_qla_host *ha)
17 return is_qla4022(ha) ? FM93C86A_NO_ADDR_BITS_16 :
18 FM93C56A_NO_ADDR_BITS_16;
21 static inline int eeprom_no_data_bits(struct scsi_qla_host *ha)
23 return FM93C56A_DATA_BITS_16;
26 static int fm93c56a_select(struct scsi_qla_host * ha)
28 DEBUG5(printk(KERN_ERR "fm93c56a_select:\n"));
30 ha->eeprom_cmd_data = AUBURN_EEPROM_CS_1 | 0x000f0000;
31 writel(ha->eeprom_cmd_data, isp_nvram(ha));
36 static int fm93c56a_cmd(struct scsi_qla_host * ha, int cmd, int addr)
43 /* Clock in a zero, then do the start bit. */
44 writel(ha->eeprom_cmd_data | AUBURN_EEPROM_DO_1, isp_nvram(ha));
45 writel(ha->eeprom_cmd_data | AUBURN_EEPROM_DO_1 |
46 AUBURN_EEPROM_CLK_RISE, isp_nvram(ha));
47 writel(ha->eeprom_cmd_data | AUBURN_EEPROM_DO_1 |
48 AUBURN_EEPROM_CLK_FALL, isp_nvram(ha));
50 mask = 1 << (FM93C56A_CMD_BITS - 1);
52 /* Force the previous data bit to be different. */
54 for (i = 0; i < FM93C56A_CMD_BITS; i++) {
56 (cmd & mask) ? AUBURN_EEPROM_DO_1 : AUBURN_EEPROM_DO_0;
57 if (previousBit != dataBit) {
60 * If the bit changed, then change the DO state to
63 writel(ha->eeprom_cmd_data | dataBit, isp_nvram(ha));
64 previousBit = dataBit;
66 writel(ha->eeprom_cmd_data | dataBit |
67 AUBURN_EEPROM_CLK_RISE, isp_nvram(ha));
68 writel(ha->eeprom_cmd_data | dataBit |
69 AUBURN_EEPROM_CLK_FALL, isp_nvram(ha));
73 mask = 1 << (eeprom_no_addr_bits(ha) - 1);
75 /* Force the previous data bit to be different. */
77 for (i = 0; i < eeprom_no_addr_bits(ha); i++) {
78 dataBit = addr & mask ? AUBURN_EEPROM_DO_1 :
80 if (previousBit != dataBit) {
82 * If the bit changed, then change the DO state to
85 writel(ha->eeprom_cmd_data | dataBit, isp_nvram(ha));
86 previousBit = dataBit;
88 writel(ha->eeprom_cmd_data | dataBit |
89 AUBURN_EEPROM_CLK_RISE, isp_nvram(ha));
90 writel(ha->eeprom_cmd_data | dataBit |
91 AUBURN_EEPROM_CLK_FALL, isp_nvram(ha));
98 static int fm93c56a_deselect(struct scsi_qla_host * ha)
100 ha->eeprom_cmd_data = AUBURN_EEPROM_CS_0 | 0x000f0000;
101 writel(ha->eeprom_cmd_data, isp_nvram(ha));
102 readl(isp_nvram(ha));
106 static int fm93c56a_datain(struct scsi_qla_host * ha, unsigned short *value)
112 /* Read the data bits
113 * The first bit is a dummy. Clock right over it. */
114 for (i = 0; i < eeprom_no_data_bits(ha); i++) {
115 writel(ha->eeprom_cmd_data |
116 AUBURN_EEPROM_CLK_RISE, isp_nvram(ha));
117 writel(ha->eeprom_cmd_data |
118 AUBURN_EEPROM_CLK_FALL, isp_nvram(ha));
120 (readw(isp_nvram(ha)) & AUBURN_EEPROM_DI_1) ? 1 : 0;
121 data = (data << 1) | dataBit;
128 static int eeprom_readword(int eepromAddr, u16 * value,
129 struct scsi_qla_host * ha)
132 fm93c56a_cmd(ha, FM93C56A_READ, eepromAddr);
133 fm93c56a_datain(ha, value);
134 fm93c56a_deselect(ha);
138 /* Hardware_lock must be set before calling */
139 u16 rd_nvram_word(struct scsi_qla_host * ha, int offset)
143 /* NOTE: NVRAM uses half-word addresses */
144 eeprom_readword(offset, &val, ha);
148 int qla4xxx_is_nvram_configuration_valid(struct scsi_qla_host * ha)
150 int status = QLA_ERROR;
151 uint16_t checksum = 0;
155 spin_lock_irqsave(&ha->hardware_lock, flags);
156 for (index = 0; index < eeprom_size(ha); index++)
157 checksum += rd_nvram_word(ha, index);
158 spin_unlock_irqrestore(&ha->hardware_lock, flags);
161 status = QLA_SUCCESS;
166 /*************************************************************************
168 * Hardware Semaphore routines
170 *************************************************************************/
171 int ql4xxx_sem_spinlock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits)
175 unsigned int seconds = 30;
177 DEBUG2(printk("scsi%ld : Trying to get SEM lock - mask= 0x%x, code = "
178 "0x%x\n", ha->host_no, sem_mask, sem_bits));
180 spin_lock_irqsave(&ha->hardware_lock, flags);
181 writel((sem_mask | sem_bits), isp_semaphore(ha));
182 value = readw(isp_semaphore(ha));
183 spin_unlock_irqrestore(&ha->hardware_lock, flags);
184 if ((value & (sem_mask >> 16)) == sem_bits) {
185 DEBUG2(printk("scsi%ld : Got SEM LOCK - mask= 0x%x, "
186 "code = 0x%x\n", ha->host_no,
187 sem_mask, sem_bits));
195 void ql4xxx_sem_unlock(struct scsi_qla_host * ha, u32 sem_mask)
199 spin_lock_irqsave(&ha->hardware_lock, flags);
200 writel(sem_mask, isp_semaphore(ha));
201 readl(isp_semaphore(ha));
202 spin_unlock_irqrestore(&ha->hardware_lock, flags);
204 DEBUG2(printk("scsi%ld : UNLOCK SEM - mask= 0x%x\n", ha->host_no,
208 int ql4xxx_sem_lock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits)
213 spin_lock_irqsave(&ha->hardware_lock, flags);
214 writel((sem_mask | sem_bits), isp_semaphore(ha));
215 value = readw(isp_semaphore(ha));
216 spin_unlock_irqrestore(&ha->hardware_lock, flags);
217 if ((value & (sem_mask >> 16)) == sem_bits) {
218 DEBUG2(printk("scsi%ld : Got SEM LOCK - mask= 0x%x, code = "
219 "0x%x, sema code=0x%x\n", ha->host_no,
220 sem_mask, sem_bits, value));