Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * QLogic iSCSI HBA Driver
  4 * Copyright (c)  2003-2013 QLogic Corporation
 
 
  5 */
  6
  7#include "ql4_def.h"
  8#include "ql4_glbl.h"
  9#include "ql4_dbg.h"
 10#include "ql4_inline.h"
 11
 12static inline void eeprom_cmd(uint32_t cmd, struct scsi_qla_host *ha)
 13{
 14	writel(cmd, isp_nvram(ha));
 15	readl(isp_nvram(ha));
 16	udelay(1);
 17}
 18
 19static inline int eeprom_size(struct scsi_qla_host *ha)
 20{
 21	return is_qla4010(ha) ? FM93C66A_SIZE_16 : FM93C86A_SIZE_16;
 22}
 23
 24static inline int eeprom_no_addr_bits(struct scsi_qla_host *ha)
 25{
 26	return is_qla4010(ha) ? FM93C56A_NO_ADDR_BITS_16 :
 27		FM93C86A_NO_ADDR_BITS_16 ;
 28}
 29
 30static inline int eeprom_no_data_bits(struct scsi_qla_host *ha)
 31{
 32	return FM93C56A_DATA_BITS_16;
 33}
 34
 35static int fm93c56a_select(struct scsi_qla_host * ha)
 36{
 37	DEBUG5(printk(KERN_ERR "fm93c56a_select:\n"));
 38
 39	ha->eeprom_cmd_data = AUBURN_EEPROM_CS_1 | 0x000f0000;
 40	eeprom_cmd(ha->eeprom_cmd_data, ha);
 41	return 1;
 42}
 43
 44static int fm93c56a_cmd(struct scsi_qla_host * ha, int cmd, int addr)
 45{
 46	int i;
 47	int mask;
 48	int dataBit;
 49	int previousBit;
 50
 51	/* Clock in a zero, then do the start bit. */
 52	eeprom_cmd(ha->eeprom_cmd_data | AUBURN_EEPROM_DO_1, ha);
 53
 54	eeprom_cmd(ha->eeprom_cmd_data | AUBURN_EEPROM_DO_1 |
 55	       AUBURN_EEPROM_CLK_RISE, ha);
 56	eeprom_cmd(ha->eeprom_cmd_data | AUBURN_EEPROM_DO_1 |
 57	       AUBURN_EEPROM_CLK_FALL, ha);
 58
 59	mask = 1 << (FM93C56A_CMD_BITS - 1);
 60
 61	/* Force the previous data bit to be different. */
 62	previousBit = 0xffff;
 63	for (i = 0; i < FM93C56A_CMD_BITS; i++) {
 64		dataBit =
 65			(cmd & mask) ? AUBURN_EEPROM_DO_1 : AUBURN_EEPROM_DO_0;
 66		if (previousBit != dataBit) {
 67
 68			/*
 69			 * If the bit changed, then change the DO state to
 70			 * match.
 71			 */
 72			eeprom_cmd(ha->eeprom_cmd_data | dataBit, ha);
 73			previousBit = dataBit;
 74		}
 75		eeprom_cmd(ha->eeprom_cmd_data | dataBit |
 76		       AUBURN_EEPROM_CLK_RISE, ha);
 77		eeprom_cmd(ha->eeprom_cmd_data | dataBit |
 78		       AUBURN_EEPROM_CLK_FALL, ha);
 79
 80		cmd = cmd << 1;
 81	}
 82	mask = 1 << (eeprom_no_addr_bits(ha) - 1);
 83
 84	/* Force the previous data bit to be different. */
 85	previousBit = 0xffff;
 86	for (i = 0; i < eeprom_no_addr_bits(ha); i++) {
 87		dataBit = addr & mask ? AUBURN_EEPROM_DO_1 :
 88			AUBURN_EEPROM_DO_0;
 89		if (previousBit != dataBit) {
 90			/*
 91			 * If the bit changed, then change the DO state to
 92			 * match.
 93			 */
 94			eeprom_cmd(ha->eeprom_cmd_data | dataBit, ha);
 95
 96			previousBit = dataBit;
 97		}
 98		eeprom_cmd(ha->eeprom_cmd_data | dataBit |
 99		       AUBURN_EEPROM_CLK_RISE, ha);
100		eeprom_cmd(ha->eeprom_cmd_data | dataBit |
101		       AUBURN_EEPROM_CLK_FALL, ha);
102
103		addr = addr << 1;
104	}
105	return 1;
106}
107
108static int fm93c56a_deselect(struct scsi_qla_host * ha)
109{
110	ha->eeprom_cmd_data = AUBURN_EEPROM_CS_0 | 0x000f0000;
111	eeprom_cmd(ha->eeprom_cmd_data, ha);
112	return 1;
113}
114
115static int fm93c56a_datain(struct scsi_qla_host * ha, unsigned short *value)
116{
117	int i;
118	int data = 0;
119	int dataBit;
120
121	/* Read the data bits
122	 * The first bit is a dummy.  Clock right over it. */
123	for (i = 0; i < eeprom_no_data_bits(ha); i++) {
124		eeprom_cmd(ha->eeprom_cmd_data |
125		       AUBURN_EEPROM_CLK_RISE, ha);
126		eeprom_cmd(ha->eeprom_cmd_data |
127		       AUBURN_EEPROM_CLK_FALL, ha);
128
129		dataBit = (readw(isp_nvram(ha)) & AUBURN_EEPROM_DI_1) ? 1 : 0;
130
131		data = (data << 1) | dataBit;
132	}
133
134	*value = data;
135	return 1;
136}
137
138static int eeprom_readword(int eepromAddr, u16 * value,
139			   struct scsi_qla_host * ha)
140{
141	fm93c56a_select(ha);
142	fm93c56a_cmd(ha, FM93C56A_READ, eepromAddr);
143	fm93c56a_datain(ha, value);
144	fm93c56a_deselect(ha);
145	return 1;
146}
147
148/* Hardware_lock must be set before calling */
149u16 rd_nvram_word(struct scsi_qla_host * ha, int offset)
150{
151	u16 val = 0;
152
153	/* NOTE: NVRAM uses half-word addresses */
154	eeprom_readword(offset, &val, ha);
155	return val;
156}
157
158u8 rd_nvram_byte(struct scsi_qla_host *ha, int offset)
159{
160	u16 val = 0;
161	u8 rval = 0;
162	int index = 0;
163
164	if (offset & 0x1)
165		index = (offset - 1) / 2;
166	else
167		index = offset / 2;
168
169	val = le16_to_cpu(rd_nvram_word(ha, index));
170
171	if (offset & 0x1)
172		rval = (u8)((val & 0xff00) >> 8);
173	else
174		rval = (u8)((val & 0x00ff));
175
176	return rval;
177}
178
179int qla4xxx_is_nvram_configuration_valid(struct scsi_qla_host * ha)
180{
181	int status = QLA_ERROR;
182	uint16_t checksum = 0;
183	uint32_t index;
184	unsigned long flags;
185
186	spin_lock_irqsave(&ha->hardware_lock, flags);
187	for (index = 0; index < eeprom_size(ha); index++)
188		checksum += rd_nvram_word(ha, index);
189	spin_unlock_irqrestore(&ha->hardware_lock, flags);
190
191	if (checksum == 0)
192		status = QLA_SUCCESS;
193
194	return status;
195}
196
197/*************************************************************************
198 *
199 *			Hardware Semaphore routines
200 *
201 *************************************************************************/
202int ql4xxx_sem_spinlock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits)
203{
204	uint32_t value;
205	unsigned long flags;
206	unsigned int seconds = 30;
207
208	DEBUG2(printk("scsi%ld : Trying to get SEM lock - mask= 0x%x, code = "
209		      "0x%x\n", ha->host_no, sem_mask, sem_bits));
210	do {
211		spin_lock_irqsave(&ha->hardware_lock, flags);
212		writel((sem_mask | sem_bits), isp_semaphore(ha));
213		value = readw(isp_semaphore(ha));
214		spin_unlock_irqrestore(&ha->hardware_lock, flags);
215		if ((value & (sem_mask >> 16)) == sem_bits) {
216			DEBUG2(printk("scsi%ld : Got SEM LOCK - mask= 0x%x, "
217				      "code = 0x%x\n", ha->host_no,
218				      sem_mask, sem_bits));
219			return QLA_SUCCESS;
220		}
221		ssleep(1);
222	} while (--seconds);
223	return QLA_ERROR;
224}
225
226void ql4xxx_sem_unlock(struct scsi_qla_host * ha, u32 sem_mask)
227{
228	unsigned long flags;
229
230	spin_lock_irqsave(&ha->hardware_lock, flags);
231	writel(sem_mask, isp_semaphore(ha));
232	readl(isp_semaphore(ha));
233	spin_unlock_irqrestore(&ha->hardware_lock, flags);
234
235	DEBUG2(printk("scsi%ld : UNLOCK SEM - mask= 0x%x\n", ha->host_no,
236		      sem_mask));
237}
238
239int ql4xxx_sem_lock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits)
240{
241	uint32_t value;
242	unsigned long flags;
243
244	spin_lock_irqsave(&ha->hardware_lock, flags);
245	writel((sem_mask | sem_bits), isp_semaphore(ha));
246	value = readw(isp_semaphore(ha));
247	spin_unlock_irqrestore(&ha->hardware_lock, flags);
248	if ((value & (sem_mask >> 16)) == sem_bits) {
249		DEBUG2(printk("scsi%ld : Got SEM LOCK - mask= 0x%x, code = "
250			      "0x%x, sema code=0x%x\n", ha->host_no,
251			      sem_mask, sem_bits, value));
252		return 1;
253	}
254	return 0;
255}
v3.15
 
  1/*
  2 * QLogic iSCSI HBA Driver
  3 * Copyright (c)  2003-2013 QLogic Corporation
  4 *
  5 * See LICENSE.qla4xxx for copyright and licensing details.
  6 */
  7
  8#include "ql4_def.h"
  9#include "ql4_glbl.h"
 10#include "ql4_dbg.h"
 11#include "ql4_inline.h"
 12
 13static inline void eeprom_cmd(uint32_t cmd, struct scsi_qla_host *ha)
 14{
 15	writel(cmd, isp_nvram(ha));
 16	readl(isp_nvram(ha));
 17	udelay(1);
 18}
 19
 20static inline int eeprom_size(struct scsi_qla_host *ha)
 21{
 22	return is_qla4010(ha) ? FM93C66A_SIZE_16 : FM93C86A_SIZE_16;
 23}
 24
 25static inline int eeprom_no_addr_bits(struct scsi_qla_host *ha)
 26{
 27	return is_qla4010(ha) ? FM93C56A_NO_ADDR_BITS_16 :
 28		FM93C86A_NO_ADDR_BITS_16 ;
 29}
 30
 31static inline int eeprom_no_data_bits(struct scsi_qla_host *ha)
 32{
 33	return FM93C56A_DATA_BITS_16;
 34}
 35
 36static int fm93c56a_select(struct scsi_qla_host * ha)
 37{
 38	DEBUG5(printk(KERN_ERR "fm93c56a_select:\n"));
 39
 40	ha->eeprom_cmd_data = AUBURN_EEPROM_CS_1 | 0x000f0000;
 41	eeprom_cmd(ha->eeprom_cmd_data, ha);
 42	return 1;
 43}
 44
 45static int fm93c56a_cmd(struct scsi_qla_host * ha, int cmd, int addr)
 46{
 47	int i;
 48	int mask;
 49	int dataBit;
 50	int previousBit;
 51
 52	/* Clock in a zero, then do the start bit. */
 53	eeprom_cmd(ha->eeprom_cmd_data | AUBURN_EEPROM_DO_1, ha);
 54
 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);
 59
 60	mask = 1 << (FM93C56A_CMD_BITS - 1);
 61
 62	/* Force the previous data bit to be different. */
 63	previousBit = 0xffff;
 64	for (i = 0; i < FM93C56A_CMD_BITS; i++) {
 65		dataBit =
 66			(cmd & mask) ? AUBURN_EEPROM_DO_1 : AUBURN_EEPROM_DO_0;
 67		if (previousBit != dataBit) {
 68
 69			/*
 70			 * If the bit changed, then change the DO state to
 71			 * match.
 72			 */
 73			eeprom_cmd(ha->eeprom_cmd_data | dataBit, ha);
 74			previousBit = dataBit;
 75		}
 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);
 80
 81		cmd = cmd << 1;
 82	}
 83	mask = 1 << (eeprom_no_addr_bits(ha) - 1);
 84
 85	/* Force the previous data bit to be different. */
 86	previousBit = 0xffff;
 87	for (i = 0; i < eeprom_no_addr_bits(ha); i++) {
 88		dataBit = addr & mask ? AUBURN_EEPROM_DO_1 :
 89			AUBURN_EEPROM_DO_0;
 90		if (previousBit != dataBit) {
 91			/*
 92			 * If the bit changed, then change the DO state to
 93			 * match.
 94			 */
 95			eeprom_cmd(ha->eeprom_cmd_data | dataBit, ha);
 96
 97			previousBit = dataBit;
 98		}
 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);
103
104		addr = addr << 1;
105	}
106	return 1;
107}
108
109static int fm93c56a_deselect(struct scsi_qla_host * ha)
110{
111	ha->eeprom_cmd_data = AUBURN_EEPROM_CS_0 | 0x000f0000;
112	eeprom_cmd(ha->eeprom_cmd_data, ha);
113	return 1;
114}
115
116static int fm93c56a_datain(struct scsi_qla_host * ha, unsigned short *value)
117{
118	int i;
119	int data = 0;
120	int dataBit;
121
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);
129
130		dataBit = (readw(isp_nvram(ha)) & AUBURN_EEPROM_DI_1) ? 1 : 0;
131
132		data = (data << 1) | dataBit;
133	}
134
135	*value = data;
136	return 1;
137}
138
139static int eeprom_readword(int eepromAddr, u16 * value,
140			   struct scsi_qla_host * ha)
141{
142	fm93c56a_select(ha);
143	fm93c56a_cmd(ha, FM93C56A_READ, eepromAddr);
144	fm93c56a_datain(ha, value);
145	fm93c56a_deselect(ha);
146	return 1;
147}
148
149/* Hardware_lock must be set before calling */
150u16 rd_nvram_word(struct scsi_qla_host * ha, int offset)
151{
152	u16 val = 0;
153
154	/* NOTE: NVRAM uses half-word addresses */
155	eeprom_readword(offset, &val, ha);
156	return val;
157}
158
159u8 rd_nvram_byte(struct scsi_qla_host *ha, int offset)
160{
161	u16 val = 0;
162	u8 rval = 0;
163	int index = 0;
164
165	if (offset & 0x1)
166		index = (offset - 1) / 2;
167	else
168		index = offset / 2;
169
170	val = le16_to_cpu(rd_nvram_word(ha, index));
171
172	if (offset & 0x1)
173		rval = (u8)((val & 0xff00) >> 8);
174	else
175		rval = (u8)((val & 0x00ff));
176
177	return rval;
178}
179
180int qla4xxx_is_nvram_configuration_valid(struct scsi_qla_host * ha)
181{
182	int status = QLA_ERROR;
183	uint16_t checksum = 0;
184	uint32_t index;
185	unsigned long flags;
186
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);
191
192	if (checksum == 0)
193		status = QLA_SUCCESS;
194
195	return status;
196}
197
198/*************************************************************************
199 *
200 *			Hardware Semaphore routines
201 *
202 *************************************************************************/
203int ql4xxx_sem_spinlock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits)
204{
205	uint32_t value;
206	unsigned long flags;
207	unsigned int seconds = 30;
208
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));
211	do {
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));
220			return QLA_SUCCESS;
221		}
222		ssleep(1);
223	} while (--seconds);
224	return QLA_ERROR;
225}
226
227void ql4xxx_sem_unlock(struct scsi_qla_host * ha, u32 sem_mask)
228{
229	unsigned long flags;
230
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);
235
236	DEBUG2(printk("scsi%ld : UNLOCK SEM - mask= 0x%x\n", ha->host_no,
237		      sem_mask));
238}
239
240int ql4xxx_sem_lock(struct scsi_qla_host * ha, u32 sem_mask, u32 sem_bits)
241{
242	uint32_t value;
243	unsigned long flags;
244
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));
253		return 1;
254	}
255	return 0;
256}