1 /******************************************************************************
2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 ******************************************************************************/
22 #include <linux/delay.h>
23 #include <asm/uaccess.h>
25 static uint16_t qla2x00_nvram_request(scsi_qla_host_t *, uint32_t);
26 static void qla2x00_nv_deselect(scsi_qla_host_t *);
27 static void qla2x00_nv_write(scsi_qla_host_t *, uint16_t);
30 * NVRAM support routines
34 * qla2x00_lock_nvram_access() -
38 qla2x00_lock_nvram_access(scsi_qla_host_t *ha)
41 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
43 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
44 data = RD_REG_WORD(®->nvram);
45 while (data & NVR_BUSY) {
47 data = RD_REG_WORD(®->nvram);
51 WRT_REG_WORD(®->u.isp2300.host_semaphore, 0x1);
52 RD_REG_WORD(®->u.isp2300.host_semaphore);
54 data = RD_REG_WORD(®->u.isp2300.host_semaphore);
55 while ((data & BIT_0) == 0) {
58 WRT_REG_WORD(®->u.isp2300.host_semaphore, 0x1);
59 RD_REG_WORD(®->u.isp2300.host_semaphore);
61 data = RD_REG_WORD(®->u.isp2300.host_semaphore);
67 * qla2x00_unlock_nvram_access() -
71 qla2x00_unlock_nvram_access(scsi_qla_host_t *ha)
73 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
75 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) {
76 WRT_REG_WORD(®->u.isp2300.host_semaphore, 0);
77 RD_REG_WORD(®->u.isp2300.host_semaphore);
82 * qla2x00_release_nvram_protection() -
86 qla2x00_release_nvram_protection(scsi_qla_host_t *ha)
88 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
91 /* Release NVRAM write protection. */
92 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
94 qla2x00_nv_write(ha, NVR_DATA_OUT);
95 qla2x00_nv_write(ha, 0);
96 qla2x00_nv_write(ha, 0);
97 for (word = 0; word < 8; word++)
98 qla2x00_nv_write(ha, NVR_DATA_OUT);
100 qla2x00_nv_deselect(ha);
102 /* Enable protection register. */
103 qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
104 qla2x00_nv_write(ha, NVR_PR_ENABLE);
105 qla2x00_nv_write(ha, NVR_PR_ENABLE);
106 for (word = 0; word < 8; word++)
107 qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
109 qla2x00_nv_deselect(ha);
111 /* Clear protection register (ffff is cleared). */
112 qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
113 qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
114 qla2x00_nv_write(ha, NVR_PR_ENABLE | NVR_DATA_OUT);
115 for (word = 0; word < 8; word++)
116 qla2x00_nv_write(ha, NVR_DATA_OUT | NVR_PR_ENABLE);
118 qla2x00_nv_deselect(ha);
120 /* Wait for NVRAM to become ready. */
121 WRT_REG_WORD(®->nvram, NVR_SELECT);
124 word = RD_REG_WORD(®->nvram);
125 } while ((word & NVR_DATA_IN) == 0);
130 * qla2x00_get_nvram_word() - Calculates word position in NVRAM and calls the
131 * request routine to get the word from NVRAM.
133 * @addr: Address in NVRAM to read
135 * Returns the word read from nvram @addr.
138 qla2x00_get_nvram_word(scsi_qla_host_t *ha, uint32_t addr)
144 nv_cmd |= NV_READ_OP;
145 data = qla2x00_nvram_request(ha, nv_cmd);
151 * qla2x00_write_nvram_word() - Write NVRAM data.
153 * @addr: Address in NVRAM to write
154 * @data: word to program
157 qla2x00_write_nvram_word(scsi_qla_host_t *ha, uint32_t addr, uint16_t data)
162 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
164 qla2x00_nv_write(ha, NVR_DATA_OUT);
165 qla2x00_nv_write(ha, 0);
166 qla2x00_nv_write(ha, 0);
168 for (word = 0; word < 8; word++)
169 qla2x00_nv_write(ha, NVR_DATA_OUT);
171 qla2x00_nv_deselect(ha);
174 nv_cmd = (addr << 16) | NV_WRITE_OP;
177 for (count = 0; count < 27; count++) {
179 qla2x00_nv_write(ha, NVR_DATA_OUT);
181 qla2x00_nv_write(ha, 0);
186 qla2x00_nv_deselect(ha);
188 /* Wait for NVRAM to become ready */
189 WRT_REG_WORD(®->nvram, NVR_SELECT);
192 word = RD_REG_WORD(®->nvram);
193 } while ((word & NVR_DATA_IN) == 0);
195 qla2x00_nv_deselect(ha);
198 qla2x00_nv_write(ha, NVR_DATA_OUT);
199 for (count = 0; count < 10; count++)
200 qla2x00_nv_write(ha, 0);
202 qla2x00_nv_deselect(ha);
206 * qla2x00_nvram_request() - Sends read command to NVRAM and gets data from
209 * @nv_cmd: NVRAM command
211 * Bit definitions for NVRAM command:
214 * Bit 25, 24 = opcode
215 * Bit 23-16 = address
216 * Bit 15-0 = write data
218 * Returns the word read from nvram @addr.
221 qla2x00_nvram_request(scsi_qla_host_t *ha, uint32_t nv_cmd)
224 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
228 /* Send command to NVRAM. */
230 for (cnt = 0; cnt < 11; cnt++) {
232 qla2x00_nv_write(ha, NVR_DATA_OUT);
234 qla2x00_nv_write(ha, 0);
238 /* Read data from NVRAM. */
239 for (cnt = 0; cnt < 16; cnt++) {
240 WRT_REG_WORD(®->nvram, NVR_SELECT | NVR_CLOCK);
243 reg_data = RD_REG_WORD(®->nvram);
244 if (reg_data & NVR_DATA_IN)
246 WRT_REG_WORD(®->nvram, NVR_SELECT);
247 RD_REG_WORD(®->nvram); /* PCI Posting. */
252 WRT_REG_WORD(®->nvram, NVR_DESELECT);
253 RD_REG_WORD(®->nvram); /* PCI Posting. */
260 * qla2x00_nv_write() - Clean NVRAM operations.
264 qla2x00_nv_deselect(scsi_qla_host_t *ha)
266 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
268 WRT_REG_WORD(®->nvram, NVR_DESELECT);
269 RD_REG_WORD(®->nvram); /* PCI Posting. */
274 * qla2x00_nv_write() - Prepare for NVRAM read/write operation.
276 * @data: Serial interface selector
279 qla2x00_nv_write(scsi_qla_host_t *ha, uint16_t data)
281 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
283 WRT_REG_WORD(®->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
284 RD_REG_WORD(®->nvram); /* PCI Posting. */
286 WRT_REG_WORD(®->nvram, data | NVR_SELECT| NVR_CLOCK |
288 RD_REG_WORD(®->nvram); /* PCI Posting. */
290 WRT_REG_WORD(®->nvram, data | NVR_SELECT | NVR_WRT_ENABLE);
291 RD_REG_WORD(®->nvram); /* PCI Posting. */