blob: 13d8e4895f58b32d0f7d30f1199c85f332d1663e [file] [log] [blame]
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301/*
2 * QLogic iSCSI HBA Driver
Vikas Chaudhary7d01d062010-12-02 22:12:51 -08003 * Copyright (c) 2003-2010 QLogic Corporation
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05304 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7#include <linux/delay.h>
Jiri Slabya6751cc2010-09-14 14:12:54 +02008#include <linux/io.h>
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05309#include <linux/pci.h>
Tej Parkash068237c82012-05-18 04:41:44 -040010#include <linux/ratelimit.h>
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053011#include "ql4_def.h"
12#include "ql4_glbl.h"
13
Hitoshi Mitake797a7962012-02-07 11:45:33 +090014#include <asm-generic/io-64-nonatomic-lo-hi.h>
15
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053016#define MASK(n) DMA_BIT_MASK(n)
17#define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | ((addr >> 25) & 0x3ff))
18#define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | ((addr >> 25) & 0x3ff))
19#define MS_WIN(addr) (addr & 0x0ffc0000)
20#define QLA82XX_PCI_MN_2M (0)
21#define QLA82XX_PCI_MS_2M (0x80000)
22#define QLA82XX_PCI_OCM0_2M (0xc0000)
23#define VALID_OCM_ADDR(addr) (((addr) & 0x3f800) != 0x3f800)
24#define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
25
26/* CRB window related */
27#define CRB_BLK(off) ((off >> 20) & 0x3f)
28#define CRB_SUBBLK(off) ((off >> 16) & 0xf)
29#define CRB_WINDOW_2M (0x130060)
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -040030#define CRB_HI(off) ((qla4_82xx_crb_hub_agt[CRB_BLK(off)] << 20) | \
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053031 ((off) & 0xf0000))
32#define QLA82XX_PCI_CAMQM_2M_END (0x04800800UL)
33#define QLA82XX_PCI_CAMQM_2M_BASE (0x000ff800UL)
34#define CRB_INDIRECT_2M (0x1e0000UL)
35
36static inline void __iomem *
37qla4_8xxx_pci_base_offsetfset(struct scsi_qla_host *ha, unsigned long off)
38{
39 if ((off < ha->first_page_group_end) &&
40 (off >= ha->first_page_group_start))
41 return (void __iomem *)(ha->nx_pcibase + off);
42
43 return NULL;
44}
45
46#define MAX_CRB_XFORM 60
47static unsigned long crb_addr_xform[MAX_CRB_XFORM];
48static int qla4_8xxx_crb_table_initialized;
49
50#define qla4_8xxx_crb_addr_transform(name) \
51 (crb_addr_xform[QLA82XX_HW_PX_MAP_CRB_##name] = \
52 QLA82XX_HW_CRB_HUB_AGT_ADR_##name << 20)
53static void
Vikas Chaudharyf8086f42012-08-22 07:54:59 -040054qla4_82xx_crb_addr_transform_setup(void)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053055{
56 qla4_8xxx_crb_addr_transform(XDMA);
57 qla4_8xxx_crb_addr_transform(TIMR);
58 qla4_8xxx_crb_addr_transform(SRE);
59 qla4_8xxx_crb_addr_transform(SQN3);
60 qla4_8xxx_crb_addr_transform(SQN2);
61 qla4_8xxx_crb_addr_transform(SQN1);
62 qla4_8xxx_crb_addr_transform(SQN0);
63 qla4_8xxx_crb_addr_transform(SQS3);
64 qla4_8xxx_crb_addr_transform(SQS2);
65 qla4_8xxx_crb_addr_transform(SQS1);
66 qla4_8xxx_crb_addr_transform(SQS0);
67 qla4_8xxx_crb_addr_transform(RPMX7);
68 qla4_8xxx_crb_addr_transform(RPMX6);
69 qla4_8xxx_crb_addr_transform(RPMX5);
70 qla4_8xxx_crb_addr_transform(RPMX4);
71 qla4_8xxx_crb_addr_transform(RPMX3);
72 qla4_8xxx_crb_addr_transform(RPMX2);
73 qla4_8xxx_crb_addr_transform(RPMX1);
74 qla4_8xxx_crb_addr_transform(RPMX0);
75 qla4_8xxx_crb_addr_transform(ROMUSB);
76 qla4_8xxx_crb_addr_transform(SN);
77 qla4_8xxx_crb_addr_transform(QMN);
78 qla4_8xxx_crb_addr_transform(QMS);
79 qla4_8xxx_crb_addr_transform(PGNI);
80 qla4_8xxx_crb_addr_transform(PGND);
81 qla4_8xxx_crb_addr_transform(PGN3);
82 qla4_8xxx_crb_addr_transform(PGN2);
83 qla4_8xxx_crb_addr_transform(PGN1);
84 qla4_8xxx_crb_addr_transform(PGN0);
85 qla4_8xxx_crb_addr_transform(PGSI);
86 qla4_8xxx_crb_addr_transform(PGSD);
87 qla4_8xxx_crb_addr_transform(PGS3);
88 qla4_8xxx_crb_addr_transform(PGS2);
89 qla4_8xxx_crb_addr_transform(PGS1);
90 qla4_8xxx_crb_addr_transform(PGS0);
91 qla4_8xxx_crb_addr_transform(PS);
92 qla4_8xxx_crb_addr_transform(PH);
93 qla4_8xxx_crb_addr_transform(NIU);
94 qla4_8xxx_crb_addr_transform(I2Q);
95 qla4_8xxx_crb_addr_transform(EG);
96 qla4_8xxx_crb_addr_transform(MN);
97 qla4_8xxx_crb_addr_transform(MS);
98 qla4_8xxx_crb_addr_transform(CAS2);
99 qla4_8xxx_crb_addr_transform(CAS1);
100 qla4_8xxx_crb_addr_transform(CAS0);
101 qla4_8xxx_crb_addr_transform(CAM);
102 qla4_8xxx_crb_addr_transform(C2C1);
103 qla4_8xxx_crb_addr_transform(C2C0);
104 qla4_8xxx_crb_addr_transform(SMB);
105 qla4_8xxx_crb_addr_transform(OCM0);
106 qla4_8xxx_crb_addr_transform(I2C0);
107
108 qla4_8xxx_crb_table_initialized = 1;
109}
110
111static struct crb_128M_2M_block_map crb_128M_2M_map[64] = {
112 {{{0, 0, 0, 0} } }, /* 0: PCI */
113 {{{1, 0x0100000, 0x0102000, 0x120000}, /* 1: PCIE */
114 {1, 0x0110000, 0x0120000, 0x130000},
115 {1, 0x0120000, 0x0122000, 0x124000},
116 {1, 0x0130000, 0x0132000, 0x126000},
117 {1, 0x0140000, 0x0142000, 0x128000},
118 {1, 0x0150000, 0x0152000, 0x12a000},
119 {1, 0x0160000, 0x0170000, 0x110000},
120 {1, 0x0170000, 0x0172000, 0x12e000},
121 {0, 0x0000000, 0x0000000, 0x000000},
122 {0, 0x0000000, 0x0000000, 0x000000},
123 {0, 0x0000000, 0x0000000, 0x000000},
124 {0, 0x0000000, 0x0000000, 0x000000},
125 {0, 0x0000000, 0x0000000, 0x000000},
126 {0, 0x0000000, 0x0000000, 0x000000},
127 {1, 0x01e0000, 0x01e0800, 0x122000},
128 {0, 0x0000000, 0x0000000, 0x000000} } },
129 {{{1, 0x0200000, 0x0210000, 0x180000} } },/* 2: MN */
130 {{{0, 0, 0, 0} } }, /* 3: */
131 {{{1, 0x0400000, 0x0401000, 0x169000} } },/* 4: P2NR1 */
132 {{{1, 0x0500000, 0x0510000, 0x140000} } },/* 5: SRE */
133 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },/* 6: NIU */
134 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },/* 7: QM */
135 {{{1, 0x0800000, 0x0802000, 0x170000}, /* 8: SQM0 */
136 {0, 0x0000000, 0x0000000, 0x000000},
137 {0, 0x0000000, 0x0000000, 0x000000},
138 {0, 0x0000000, 0x0000000, 0x000000},
139 {0, 0x0000000, 0x0000000, 0x000000},
140 {0, 0x0000000, 0x0000000, 0x000000},
141 {0, 0x0000000, 0x0000000, 0x000000},
142 {0, 0x0000000, 0x0000000, 0x000000},
143 {0, 0x0000000, 0x0000000, 0x000000},
144 {0, 0x0000000, 0x0000000, 0x000000},
145 {0, 0x0000000, 0x0000000, 0x000000},
146 {0, 0x0000000, 0x0000000, 0x000000},
147 {0, 0x0000000, 0x0000000, 0x000000},
148 {0, 0x0000000, 0x0000000, 0x000000},
149 {0, 0x0000000, 0x0000000, 0x000000},
150 {1, 0x08f0000, 0x08f2000, 0x172000} } },
151 {{{1, 0x0900000, 0x0902000, 0x174000}, /* 9: SQM1*/
152 {0, 0x0000000, 0x0000000, 0x000000},
153 {0, 0x0000000, 0x0000000, 0x000000},
154 {0, 0x0000000, 0x0000000, 0x000000},
155 {0, 0x0000000, 0x0000000, 0x000000},
156 {0, 0x0000000, 0x0000000, 0x000000},
157 {0, 0x0000000, 0x0000000, 0x000000},
158 {0, 0x0000000, 0x0000000, 0x000000},
159 {0, 0x0000000, 0x0000000, 0x000000},
160 {0, 0x0000000, 0x0000000, 0x000000},
161 {0, 0x0000000, 0x0000000, 0x000000},
162 {0, 0x0000000, 0x0000000, 0x000000},
163 {0, 0x0000000, 0x0000000, 0x000000},
164 {0, 0x0000000, 0x0000000, 0x000000},
165 {0, 0x0000000, 0x0000000, 0x000000},
166 {1, 0x09f0000, 0x09f2000, 0x176000} } },
167 {{{0, 0x0a00000, 0x0a02000, 0x178000}, /* 10: SQM2*/
168 {0, 0x0000000, 0x0000000, 0x000000},
169 {0, 0x0000000, 0x0000000, 0x000000},
170 {0, 0x0000000, 0x0000000, 0x000000},
171 {0, 0x0000000, 0x0000000, 0x000000},
172 {0, 0x0000000, 0x0000000, 0x000000},
173 {0, 0x0000000, 0x0000000, 0x000000},
174 {0, 0x0000000, 0x0000000, 0x000000},
175 {0, 0x0000000, 0x0000000, 0x000000},
176 {0, 0x0000000, 0x0000000, 0x000000},
177 {0, 0x0000000, 0x0000000, 0x000000},
178 {0, 0x0000000, 0x0000000, 0x000000},
179 {0, 0x0000000, 0x0000000, 0x000000},
180 {0, 0x0000000, 0x0000000, 0x000000},
181 {0, 0x0000000, 0x0000000, 0x000000},
182 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
183 {{{0, 0x0b00000, 0x0b02000, 0x17c000}, /* 11: SQM3*/
184 {0, 0x0000000, 0x0000000, 0x000000},
185 {0, 0x0000000, 0x0000000, 0x000000},
186 {0, 0x0000000, 0x0000000, 0x000000},
187 {0, 0x0000000, 0x0000000, 0x000000},
188 {0, 0x0000000, 0x0000000, 0x000000},
189 {0, 0x0000000, 0x0000000, 0x000000},
190 {0, 0x0000000, 0x0000000, 0x000000},
191 {0, 0x0000000, 0x0000000, 0x000000},
192 {0, 0x0000000, 0x0000000, 0x000000},
193 {0, 0x0000000, 0x0000000, 0x000000},
194 {0, 0x0000000, 0x0000000, 0x000000},
195 {0, 0x0000000, 0x0000000, 0x000000},
196 {0, 0x0000000, 0x0000000, 0x000000},
197 {0, 0x0000000, 0x0000000, 0x000000},
198 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
199 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },/* 12: I2Q */
200 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },/* 13: TMR */
201 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },/* 14: ROMUSB */
202 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },/* 15: PEG4 */
203 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },/* 16: XDMA */
204 {{{1, 0x1100000, 0x1101000, 0x160000} } },/* 17: PEG0 */
205 {{{1, 0x1200000, 0x1201000, 0x161000} } },/* 18: PEG1 */
206 {{{1, 0x1300000, 0x1301000, 0x162000} } },/* 19: PEG2 */
207 {{{1, 0x1400000, 0x1401000, 0x163000} } },/* 20: PEG3 */
208 {{{1, 0x1500000, 0x1501000, 0x165000} } },/* 21: P2ND */
209 {{{1, 0x1600000, 0x1601000, 0x166000} } },/* 22: P2NI */
210 {{{0, 0, 0, 0} } }, /* 23: */
211 {{{0, 0, 0, 0} } }, /* 24: */
212 {{{0, 0, 0, 0} } }, /* 25: */
213 {{{0, 0, 0, 0} } }, /* 26: */
214 {{{0, 0, 0, 0} } }, /* 27: */
215 {{{0, 0, 0, 0} } }, /* 28: */
216 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },/* 29: MS */
217 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },/* 30: P2NR2 */
218 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },/* 31: EPG */
219 {{{0} } }, /* 32: PCI */
220 {{{1, 0x2100000, 0x2102000, 0x120000}, /* 33: PCIE */
221 {1, 0x2110000, 0x2120000, 0x130000},
222 {1, 0x2120000, 0x2122000, 0x124000},
223 {1, 0x2130000, 0x2132000, 0x126000},
224 {1, 0x2140000, 0x2142000, 0x128000},
225 {1, 0x2150000, 0x2152000, 0x12a000},
226 {1, 0x2160000, 0x2170000, 0x110000},
227 {1, 0x2170000, 0x2172000, 0x12e000},
228 {0, 0x0000000, 0x0000000, 0x000000},
229 {0, 0x0000000, 0x0000000, 0x000000},
230 {0, 0x0000000, 0x0000000, 0x000000},
231 {0, 0x0000000, 0x0000000, 0x000000},
232 {0, 0x0000000, 0x0000000, 0x000000},
233 {0, 0x0000000, 0x0000000, 0x000000},
234 {0, 0x0000000, 0x0000000, 0x000000},
235 {0, 0x0000000, 0x0000000, 0x000000} } },
236 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },/* 34: CAM */
237 {{{0} } }, /* 35: */
238 {{{0} } }, /* 36: */
239 {{{0} } }, /* 37: */
240 {{{0} } }, /* 38: */
241 {{{0} } }, /* 39: */
242 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },/* 40: TMR */
243 {{{1, 0x2900000, 0x2901000, 0x16b000} } },/* 41: P2NR3 */
244 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },/* 42: RPMX1 */
245 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },/* 43: RPMX2 */
246 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },/* 44: RPMX3 */
247 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },/* 45: RPMX4 */
248 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },/* 46: RPMX5 */
249 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },/* 47: RPMX6 */
250 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },/* 48: RPMX7 */
251 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },/* 49: XDMA */
252 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },/* 50: I2Q */
253 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },/* 51: ROMUSB */
254 {{{0} } }, /* 52: */
255 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },/* 53: RPMX0 */
256 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },/* 54: RPMX8 */
257 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },/* 55: RPMX9 */
258 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },/* 56: OCM0 */
259 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },/* 57: CRYPTO */
260 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },/* 58: SMB */
261 {{{0} } }, /* 59: I2C0 */
262 {{{0} } }, /* 60: I2C1 */
263 {{{1, 0x3d00000, 0x3d04000, 0x1dc000} } },/* 61: LPC */
264 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },/* 62: P2NC */
265 {{{1, 0x3f00000, 0x3f01000, 0x168000} } } /* 63: P2NR0 */
266};
267
268/*
269 * top 12 bits of crb internal address (hub, agent)
270 */
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -0400271static unsigned qla4_82xx_crb_hub_agt[64] = {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530272 0,
273 QLA82XX_HW_CRB_HUB_AGT_ADR_PS,
274 QLA82XX_HW_CRB_HUB_AGT_ADR_MN,
275 QLA82XX_HW_CRB_HUB_AGT_ADR_MS,
276 0,
277 QLA82XX_HW_CRB_HUB_AGT_ADR_SRE,
278 QLA82XX_HW_CRB_HUB_AGT_ADR_NIU,
279 QLA82XX_HW_CRB_HUB_AGT_ADR_QMN,
280 QLA82XX_HW_CRB_HUB_AGT_ADR_SQN0,
281 QLA82XX_HW_CRB_HUB_AGT_ADR_SQN1,
282 QLA82XX_HW_CRB_HUB_AGT_ADR_SQN2,
283 QLA82XX_HW_CRB_HUB_AGT_ADR_SQN3,
284 QLA82XX_HW_CRB_HUB_AGT_ADR_I2Q,
285 QLA82XX_HW_CRB_HUB_AGT_ADR_TIMR,
286 QLA82XX_HW_CRB_HUB_AGT_ADR_ROMUSB,
287 QLA82XX_HW_CRB_HUB_AGT_ADR_PGN4,
288 QLA82XX_HW_CRB_HUB_AGT_ADR_XDMA,
289 QLA82XX_HW_CRB_HUB_AGT_ADR_PGN0,
290 QLA82XX_HW_CRB_HUB_AGT_ADR_PGN1,
291 QLA82XX_HW_CRB_HUB_AGT_ADR_PGN2,
292 QLA82XX_HW_CRB_HUB_AGT_ADR_PGN3,
293 QLA82XX_HW_CRB_HUB_AGT_ADR_PGND,
294 QLA82XX_HW_CRB_HUB_AGT_ADR_PGNI,
295 QLA82XX_HW_CRB_HUB_AGT_ADR_PGS0,
296 QLA82XX_HW_CRB_HUB_AGT_ADR_PGS1,
297 QLA82XX_HW_CRB_HUB_AGT_ADR_PGS2,
298 QLA82XX_HW_CRB_HUB_AGT_ADR_PGS3,
299 0,
300 QLA82XX_HW_CRB_HUB_AGT_ADR_PGSI,
301 QLA82XX_HW_CRB_HUB_AGT_ADR_SN,
302 0,
303 QLA82XX_HW_CRB_HUB_AGT_ADR_EG,
304 0,
305 QLA82XX_HW_CRB_HUB_AGT_ADR_PS,
306 QLA82XX_HW_CRB_HUB_AGT_ADR_CAM,
307 0,
308 0,
309 0,
310 0,
311 0,
312 QLA82XX_HW_CRB_HUB_AGT_ADR_TIMR,
313 0,
314 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX1,
315 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX2,
316 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX3,
317 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX4,
318 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX5,
319 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX6,
320 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX7,
321 QLA82XX_HW_CRB_HUB_AGT_ADR_XDMA,
322 QLA82XX_HW_CRB_HUB_AGT_ADR_I2Q,
323 QLA82XX_HW_CRB_HUB_AGT_ADR_ROMUSB,
324 0,
325 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX0,
326 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX8,
327 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX9,
328 QLA82XX_HW_CRB_HUB_AGT_ADR_OCM0,
329 0,
330 QLA82XX_HW_CRB_HUB_AGT_ADR_SMB,
331 QLA82XX_HW_CRB_HUB_AGT_ADR_I2C0,
332 QLA82XX_HW_CRB_HUB_AGT_ADR_I2C1,
333 0,
334 QLA82XX_HW_CRB_HUB_AGT_ADR_PGNC,
335 0,
336};
337
338/* Device states */
339static char *qdev_state[] = {
340 "Unknown",
341 "Cold",
342 "Initializing",
343 "Ready",
344 "Need Reset",
345 "Need Quiescent",
346 "Failed",
347 "Quiescent",
348};
349
350/*
351 * In: 'off' is offset from CRB space in 128M pci map
352 * Out: 'off' is 2M pci map addr
353 * side effect: lock crb window
354 */
355static void
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400356qla4_82xx_pci_set_crbwindow_2M(struct scsi_qla_host *ha, ulong *off)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530357{
358 u32 win_read;
359
360 ha->crb_win = CRB_HI(*off);
361 writel(ha->crb_win,
362 (void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
363
364 /* Read back value to make sure write has gone through before trying
365 * to use it. */
366 win_read = readl((void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
367 if (win_read != ha->crb_win) {
368 DEBUG2(ql4_printk(KERN_INFO, ha,
369 "%s: Written crbwin (0x%x) != Read crbwin (0x%x),"
370 " off=0x%lx\n", __func__, ha->crb_win, win_read, *off));
371 }
372 *off = (*off & MASK(16)) + CRB_INDIRECT_2M + ha->nx_pcibase;
373}
374
375void
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400376qla4_82xx_wr_32(struct scsi_qla_host *ha, ulong off, u32 data)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530377{
378 unsigned long flags = 0;
379 int rv;
380
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400381 rv = qla4_82xx_pci_get_crb_addr_2M(ha, &off);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530382
383 BUG_ON(rv == -1);
384
385 if (rv == 1) {
386 write_lock_irqsave(&ha->hw_lock, flags);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400387 qla4_82xx_crb_win_lock(ha);
388 qla4_82xx_pci_set_crbwindow_2M(ha, &off);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530389 }
390
391 writel(data, (void __iomem *)off);
392
393 if (rv == 1) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400394 qla4_82xx_crb_win_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530395 write_unlock_irqrestore(&ha->hw_lock, flags);
396 }
397}
398
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400399uint32_t qla4_82xx_rd_32(struct scsi_qla_host *ha, ulong off)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530400{
401 unsigned long flags = 0;
402 int rv;
403 u32 data;
404
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400405 rv = qla4_82xx_pci_get_crb_addr_2M(ha, &off);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530406
407 BUG_ON(rv == -1);
408
409 if (rv == 1) {
410 write_lock_irqsave(&ha->hw_lock, flags);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400411 qla4_82xx_crb_win_lock(ha);
412 qla4_82xx_pci_set_crbwindow_2M(ha, &off);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530413 }
414 data = readl((void __iomem *)off);
415
416 if (rv == 1) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400417 qla4_82xx_crb_win_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530418 write_unlock_irqrestore(&ha->hw_lock, flags);
419 }
420 return data;
421}
422
Tej Parkash068237c82012-05-18 04:41:44 -0400423/* Minidump related functions */
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400424int qla4_82xx_md_rd_32(struct scsi_qla_host *ha, uint32_t off, uint32_t *data)
Tej Parkash068237c82012-05-18 04:41:44 -0400425{
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400426 uint32_t win_read, off_value;
427 int rval = QLA_SUCCESS;
428
429 off_value = off & 0xFFFF0000;
430 writel(off_value, (void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
431
432 /*
433 * Read back value to make sure write has gone through before trying
434 * to use it.
435 */
436 win_read = readl((void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
437 if (win_read != off_value) {
438 DEBUG2(ql4_printk(KERN_INFO, ha,
439 "%s: Written (0x%x) != Read (0x%x), off=0x%x\n",
440 __func__, off_value, win_read, off));
441 rval = QLA_ERROR;
442 } else {
443 off_value = off & 0x0000FFFF;
444 *data = readl((void __iomem *)(off_value + CRB_INDIRECT_2M +
445 ha->nx_pcibase));
446 }
447 return rval;
448}
449
450int qla4_82xx_md_wr_32(struct scsi_qla_host *ha, uint32_t off, uint32_t data)
451{
452 uint32_t win_read, off_value;
453 int rval = QLA_SUCCESS;
Tej Parkash068237c82012-05-18 04:41:44 -0400454
455 off_value = off & 0xFFFF0000;
456 writel(off_value, (void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
457
458 /* Read back value to make sure write has gone through before trying
459 * to use it.
460 */
461 win_read = readl((void __iomem *)(CRB_WINDOW_2M + ha->nx_pcibase));
462 if (win_read != off_value) {
463 DEBUG2(ql4_printk(KERN_INFO, ha,
464 "%s: Written (0x%x) != Read (0x%x), off=0x%x\n",
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400465 __func__, off_value, win_read, off));
466 rval = QLA_ERROR;
467 } else {
468 off_value = off & 0x0000FFFF;
Tej Parkash068237c82012-05-18 04:41:44 -0400469 writel(data, (void __iomem *)(off_value + CRB_INDIRECT_2M +
470 ha->nx_pcibase));
Vikas Chaudhary33693c72012-08-22 07:55:04 -0400471 }
Tej Parkash068237c82012-05-18 04:41:44 -0400472 return rval;
473}
474
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530475#define CRB_WIN_LOCK_TIMEOUT 100000000
476
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400477int qla4_82xx_crb_win_lock(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530478{
479 int i;
480 int done = 0, timeout = 0;
481
482 while (!done) {
483 /* acquire semaphore3 from PCI HW block */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400484 done = qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_LOCK));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530485 if (done == 1)
486 break;
487 if (timeout >= CRB_WIN_LOCK_TIMEOUT)
488 return -1;
489
490 timeout++;
491
492 /* Yield CPU */
493 if (!in_interrupt())
494 schedule();
495 else {
496 for (i = 0; i < 20; i++)
497 cpu_relax(); /*This a nop instr on i386*/
498 }
499 }
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400500 qla4_82xx_wr_32(ha, QLA82XX_CRB_WIN_LOCK_ID, ha->func_num);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530501 return 0;
502}
503
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400504void qla4_82xx_crb_win_unlock(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530505{
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400506 qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_UNLOCK));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530507}
508
509#define IDC_LOCK_TIMEOUT 100000000
510
511/**
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400512 * qla4_82xx_idc_lock - hw_lock
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530513 * @ha: pointer to adapter structure
514 *
515 * General purpose lock used to synchronize access to
516 * CRB_DEV_STATE, CRB_DEV_REF_COUNT, etc.
517 **/
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400518int qla4_82xx_idc_lock(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530519{
520 int i;
521 int done = 0, timeout = 0;
522
523 while (!done) {
524 /* acquire semaphore5 from PCI HW block */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400525 done = qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM5_LOCK));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530526 if (done == 1)
527 break;
528 if (timeout >= IDC_LOCK_TIMEOUT)
529 return -1;
530
531 timeout++;
532
533 /* Yield CPU */
534 if (!in_interrupt())
535 schedule();
536 else {
537 for (i = 0; i < 20; i++)
538 cpu_relax(); /*This a nop instr on i386*/
539 }
540 }
541 return 0;
542}
543
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400544void qla4_82xx_idc_unlock(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530545{
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400546 qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM5_UNLOCK));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530547}
548
549int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400550qla4_82xx_pci_get_crb_addr_2M(struct scsi_qla_host *ha, ulong *off)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530551{
552 struct crb_128M_2M_sub_block_map *m;
553
554 if (*off >= QLA82XX_CRB_MAX)
555 return -1;
556
557 if (*off >= QLA82XX_PCI_CAMQM && (*off < QLA82XX_PCI_CAMQM_2M_END)) {
558 *off = (*off - QLA82XX_PCI_CAMQM) +
559 QLA82XX_PCI_CAMQM_2M_BASE + ha->nx_pcibase;
560 return 0;
561 }
562
563 if (*off < QLA82XX_PCI_CRBSPACE)
564 return -1;
565
566 *off -= QLA82XX_PCI_CRBSPACE;
567 /*
568 * Try direct map
569 */
570
571 m = &crb_128M_2M_map[CRB_BLK(*off)].sub_block[CRB_SUBBLK(*off)];
572
573 if (m->valid && (m->start_128M <= *off) && (m->end_128M > *off)) {
574 *off = *off + m->start_2M - m->start_128M + ha->nx_pcibase;
575 return 0;
576 }
577
578 /*
579 * Not in direct map, use crb window
580 */
581 return 1;
582}
583
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530584/*
585* check memory access boundary.
586* used by test agent. support ddr access only for now
587*/
588static unsigned long
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400589qla4_82xx_pci_mem_bound_check(struct scsi_qla_host *ha,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530590 unsigned long long addr, int size)
591{
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400592 if (!QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_DDR_NET,
593 QLA8XXX_ADDR_DDR_NET_MAX) ||
594 !QLA8XXX_ADDR_IN_RANGE(addr + size - 1,
595 QLA8XXX_ADDR_DDR_NET, QLA8XXX_ADDR_DDR_NET_MAX) ||
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530596 ((size != 1) && (size != 2) && (size != 4) && (size != 8))) {
597 return 0;
598 }
599 return 1;
600}
601
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -0400602static int qla4_82xx_pci_set_window_warning_count;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530603
604static unsigned long
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400605qla4_82xx_pci_set_window(struct scsi_qla_host *ha, unsigned long long addr)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530606{
607 int window;
608 u32 win_read;
609
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400610 if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_DDR_NET,
611 QLA8XXX_ADDR_DDR_NET_MAX)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530612 /* DDR network side */
613 window = MN_WIN(addr);
614 ha->ddr_mn_window = window;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400615 qla4_82xx_wr_32(ha, ha->mn_win_crb |
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530616 QLA82XX_PCI_CRBSPACE, window);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400617 win_read = qla4_82xx_rd_32(ha, ha->mn_win_crb |
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530618 QLA82XX_PCI_CRBSPACE);
619 if ((win_read << 17) != window) {
620 ql4_printk(KERN_WARNING, ha,
621 "%s: Written MNwin (0x%x) != Read MNwin (0x%x)\n",
622 __func__, window, win_read);
623 }
624 addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_DDR_NET;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400625 } else if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_OCM0,
626 QLA8XXX_ADDR_OCM0_MAX)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530627 unsigned int temp1;
628 /* if bits 19:18&17:11 are on */
629 if ((addr & 0x00ff800) == 0xff800) {
630 printk("%s: QM access not handled.\n", __func__);
631 addr = -1UL;
632 }
633
634 window = OCM_WIN(addr);
635 ha->ddr_mn_window = window;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400636 qla4_82xx_wr_32(ha, ha->mn_win_crb |
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530637 QLA82XX_PCI_CRBSPACE, window);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400638 win_read = qla4_82xx_rd_32(ha, ha->mn_win_crb |
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530639 QLA82XX_PCI_CRBSPACE);
640 temp1 = ((window & 0x1FF) << 7) |
641 ((window & 0x0FFFE0000) >> 17);
642 if (win_read != temp1) {
643 printk("%s: Written OCMwin (0x%x) != Read"
644 " OCMwin (0x%x)\n", __func__, temp1, win_read);
645 }
646 addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_OCM0_2M;
647
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400648 } else if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_QDR_NET,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530649 QLA82XX_P3_ADDR_QDR_NET_MAX)) {
650 /* QDR network side */
651 window = MS_WIN(addr);
652 ha->qdr_sn_window = window;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400653 qla4_82xx_wr_32(ha, ha->ms_win_crb |
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530654 QLA82XX_PCI_CRBSPACE, window);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400655 win_read = qla4_82xx_rd_32(ha,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530656 ha->ms_win_crb | QLA82XX_PCI_CRBSPACE);
657 if (win_read != window) {
658 printk("%s: Written MSwin (0x%x) != Read "
659 "MSwin (0x%x)\n", __func__, window, win_read);
660 }
661 addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_QDR_NET;
662
663 } else {
664 /*
665 * peg gdb frequently accesses memory that doesn't exist,
666 * this limits the chit chat so debugging isn't slowed down.
667 */
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -0400668 if ((qla4_82xx_pci_set_window_warning_count++ < 8) ||
669 (qla4_82xx_pci_set_window_warning_count%64 == 0)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530670 printk("%s: Warning:%s Unknown address range!\n",
671 __func__, DRIVER_NAME);
672 }
673 addr = -1UL;
674 }
675 return addr;
676}
677
678/* check if address is in the same windows as the previous access */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400679static int qla4_82xx_pci_is_same_window(struct scsi_qla_host *ha,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530680 unsigned long long addr)
681{
682 int window;
683 unsigned long long qdr_max;
684
685 qdr_max = QLA82XX_P3_ADDR_QDR_NET_MAX;
686
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400687 if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_DDR_NET,
688 QLA8XXX_ADDR_DDR_NET_MAX)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530689 /* DDR network side */
690 BUG(); /* MN access can not come here */
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400691 } else if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_OCM0,
692 QLA8XXX_ADDR_OCM0_MAX)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530693 return 1;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400694 } else if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_OCM1,
695 QLA8XXX_ADDR_OCM1_MAX)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530696 return 1;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400697 } else if (QLA8XXX_ADDR_IN_RANGE(addr, QLA8XXX_ADDR_QDR_NET,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530698 qdr_max)) {
699 /* QDR network side */
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -0400700 window = ((addr - QLA8XXX_ADDR_QDR_NET) >> 22) & 0x3f;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530701 if (ha->qdr_sn_window == window)
702 return 1;
703 }
704
705 return 0;
706}
707
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400708static int qla4_82xx_pci_mem_read_direct(struct scsi_qla_host *ha,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530709 u64 off, void *data, int size)
710{
711 unsigned long flags;
712 void __iomem *addr;
713 int ret = 0;
714 u64 start;
715 void __iomem *mem_ptr = NULL;
716 unsigned long mem_base;
717 unsigned long mem_page;
718
719 write_lock_irqsave(&ha->hw_lock, flags);
720
721 /*
722 * If attempting to access unknown address or straddle hw windows,
723 * do not access.
724 */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400725 start = qla4_82xx_pci_set_window(ha, off);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530726 if ((start == -1UL) ||
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400727 (qla4_82xx_pci_is_same_window(ha, off + size - 1) == 0)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530728 write_unlock_irqrestore(&ha->hw_lock, flags);
729 printk(KERN_ERR"%s out of bound pci memory access. "
730 "offset is 0x%llx\n", DRIVER_NAME, off);
731 return -1;
732 }
733
734 addr = qla4_8xxx_pci_base_offsetfset(ha, start);
735 if (!addr) {
736 write_unlock_irqrestore(&ha->hw_lock, flags);
737 mem_base = pci_resource_start(ha->pdev, 0);
738 mem_page = start & PAGE_MASK;
739 /* Map two pages whenever user tries to access addresses in two
740 consecutive pages.
741 */
742 if (mem_page != ((start + size - 1) & PAGE_MASK))
743 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
744 else
745 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
746
747 if (mem_ptr == NULL) {
748 *(u8 *)data = 0;
749 return -1;
750 }
751 addr = mem_ptr;
752 addr += start & (PAGE_SIZE - 1);
753 write_lock_irqsave(&ha->hw_lock, flags);
754 }
755
756 switch (size) {
757 case 1:
758 *(u8 *)data = readb(addr);
759 break;
760 case 2:
761 *(u16 *)data = readw(addr);
762 break;
763 case 4:
764 *(u32 *)data = readl(addr);
765 break;
766 case 8:
767 *(u64 *)data = readq(addr);
768 break;
769 default:
770 ret = -1;
771 break;
772 }
773 write_unlock_irqrestore(&ha->hw_lock, flags);
774
775 if (mem_ptr)
776 iounmap(mem_ptr);
777 return ret;
778}
779
780static int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400781qla4_82xx_pci_mem_write_direct(struct scsi_qla_host *ha, u64 off,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530782 void *data, int size)
783{
784 unsigned long flags;
785 void __iomem *addr;
786 int ret = 0;
787 u64 start;
788 void __iomem *mem_ptr = NULL;
789 unsigned long mem_base;
790 unsigned long mem_page;
791
792 write_lock_irqsave(&ha->hw_lock, flags);
793
794 /*
795 * If attempting to access unknown address or straddle hw windows,
796 * do not access.
797 */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400798 start = qla4_82xx_pci_set_window(ha, off);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530799 if ((start == -1UL) ||
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400800 (qla4_82xx_pci_is_same_window(ha, off + size - 1) == 0)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530801 write_unlock_irqrestore(&ha->hw_lock, flags);
802 printk(KERN_ERR"%s out of bound pci memory access. "
803 "offset is 0x%llx\n", DRIVER_NAME, off);
804 return -1;
805 }
806
807 addr = qla4_8xxx_pci_base_offsetfset(ha, start);
808 if (!addr) {
809 write_unlock_irqrestore(&ha->hw_lock, flags);
810 mem_base = pci_resource_start(ha->pdev, 0);
811 mem_page = start & PAGE_MASK;
812 /* Map two pages whenever user tries to access addresses in two
813 consecutive pages.
814 */
815 if (mem_page != ((start + size - 1) & PAGE_MASK))
816 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2);
817 else
818 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
819 if (mem_ptr == NULL)
820 return -1;
821
822 addr = mem_ptr;
823 addr += start & (PAGE_SIZE - 1);
824 write_lock_irqsave(&ha->hw_lock, flags);
825 }
826
827 switch (size) {
828 case 1:
829 writeb(*(u8 *)data, addr);
830 break;
831 case 2:
832 writew(*(u16 *)data, addr);
833 break;
834 case 4:
835 writel(*(u32 *)data, addr);
836 break;
837 case 8:
838 writeq(*(u64 *)data, addr);
839 break;
840 default:
841 ret = -1;
842 break;
843 }
844 write_unlock_irqrestore(&ha->hw_lock, flags);
845 if (mem_ptr)
846 iounmap(mem_ptr);
847 return ret;
848}
849
850#define MTU_FUDGE_FACTOR 100
851
852static unsigned long
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400853qla4_82xx_decode_crb_addr(unsigned long addr)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530854{
855 int i;
856 unsigned long base_addr, offset, pci_base;
857
858 if (!qla4_8xxx_crb_table_initialized)
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400859 qla4_82xx_crb_addr_transform_setup();
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530860
861 pci_base = ADDR_ERROR;
862 base_addr = addr & 0xfff00000;
863 offset = addr & 0x000fffff;
864
865 for (i = 0; i < MAX_CRB_XFORM; i++) {
866 if (crb_addr_xform[i] == base_addr) {
867 pci_base = i << 20;
868 break;
869 }
870 }
871 if (pci_base == ADDR_ERROR)
872 return pci_base;
873 else
874 return pci_base + offset;
875}
876
877static long rom_max_timeout = 100;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -0400878static long qla4_82xx_rom_lock_timeout = 100;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530879
880static int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400881qla4_82xx_rom_lock(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530882{
883 int i;
884 int done = 0, timeout = 0;
885
886 while (!done) {
887 /* acquire semaphore2 from PCI HW block */
888
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400889 done = qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_LOCK));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530890 if (done == 1)
891 break;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -0400892 if (timeout >= qla4_82xx_rom_lock_timeout)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530893 return -1;
894
895 timeout++;
896
897 /* Yield CPU */
898 if (!in_interrupt())
899 schedule();
900 else {
901 for (i = 0; i < 20; i++)
902 cpu_relax(); /*This a nop instr on i386*/
903 }
904 }
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400905 qla4_82xx_wr_32(ha, QLA82XX_ROM_LOCK_ID, ROM_LOCK_DRIVER);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530906 return 0;
907}
908
909static void
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400910qla4_82xx_rom_unlock(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530911{
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400912 qla4_82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_UNLOCK));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530913}
914
915static int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400916qla4_82xx_wait_rom_done(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530917{
918 long timeout = 0;
919 long done = 0 ;
920
921 while (done == 0) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400922 done = qla4_82xx_rd_32(ha, QLA82XX_ROMUSB_GLB_STATUS);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530923 done &= 2;
924 timeout++;
925 if (timeout >= rom_max_timeout) {
926 printk("%s: Timeout reached waiting for rom done",
927 DRIVER_NAME);
928 return -1;
929 }
930 }
931 return 0;
932}
933
934static int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400935qla4_82xx_do_rom_fast_read(struct scsi_qla_host *ha, int addr, int *valp)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530936{
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400937 qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ADDRESS, addr);
938 qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
939 qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ABYTE_CNT, 3);
940 qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_INSTR_OPCODE, 0xb);
941 if (qla4_82xx_wait_rom_done(ha)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530942 printk("%s: Error waiting for rom done\n", DRIVER_NAME);
943 return -1;
944 }
945 /* reset abyte_cnt and dummy_byte_cnt */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400946 qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_DUMMY_BYTE_CNT, 0);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530947 udelay(10);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400948 qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ABYTE_CNT, 0);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530949
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400950 *valp = qla4_82xx_rd_32(ha, QLA82XX_ROMUSB_ROM_RDATA);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530951 return 0;
952}
953
954static int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400955qla4_82xx_rom_fast_read(struct scsi_qla_host *ha, int addr, int *valp)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530956{
957 int ret, loops = 0;
958
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400959 while ((qla4_82xx_rom_lock(ha) != 0) && (loops < 50000)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530960 udelay(100);
961 loops++;
962 }
963 if (loops >= 50000) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400964 ql4_printk(KERN_WARNING, ha, "%s: qla4_82xx_rom_lock failed\n",
965 DRIVER_NAME);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530966 return -1;
967 }
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400968 ret = qla4_82xx_do_rom_fast_read(ha, addr, valp);
969 qla4_82xx_rom_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530970 return ret;
971}
972
973/**
974 * This routine does CRB initialize sequence
975 * to put the ISP into operational state
976 **/
977static int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400978qla4_82xx_pinit_from_rom(struct scsi_qla_host *ha, int verbose)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530979{
980 int addr, val;
981 int i ;
982 struct crb_addr_pair *buf;
983 unsigned long off;
984 unsigned offset, n;
985
986 struct crb_addr_pair {
987 long addr;
988 long data;
989 };
990
991 /* Halt all the indiviual PEGs and other blocks of the ISP */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400992 qla4_82xx_rom_lock(ha);
Swapnil Naglea1fc26b2010-12-02 22:12:15 -0800993
Vikas Chaudharycb744282011-05-17 23:17:04 -0700994 /* disable all I2Q */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -0400995 qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x10, 0x0);
996 qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x14, 0x0);
997 qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x18, 0x0);
998 qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x1c, 0x0);
999 qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x20, 0x0);
1000 qla4_82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x24, 0x0);
Vikas Chaudharycb744282011-05-17 23:17:04 -07001001
1002 /* disable all niu interrupts */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001003 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x40, 0xff);
Swapnil Naglea1fc26b2010-12-02 22:12:15 -08001004 /* disable xge rx/tx */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001005 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x70000, 0x00);
Swapnil Naglea1fc26b2010-12-02 22:12:15 -08001006 /* disable xg1 rx/tx */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001007 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x80000, 0x00);
Vikas Chaudharycb744282011-05-17 23:17:04 -07001008 /* disable sideband mac */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001009 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x90000, 0x00);
Vikas Chaudharycb744282011-05-17 23:17:04 -07001010 /* disable ap0 mac */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001011 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0xa0000, 0x00);
Vikas Chaudharycb744282011-05-17 23:17:04 -07001012 /* disable ap1 mac */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001013 qla4_82xx_wr_32(ha, QLA82XX_CRB_NIU + 0xb0000, 0x00);
Swapnil Naglea1fc26b2010-12-02 22:12:15 -08001014
1015 /* halt sre */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001016 val = qla4_82xx_rd_32(ha, QLA82XX_CRB_SRE + 0x1000);
1017 qla4_82xx_wr_32(ha, QLA82XX_CRB_SRE + 0x1000, val & (~(0x1)));
Swapnil Naglea1fc26b2010-12-02 22:12:15 -08001018
1019 /* halt epg */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001020 qla4_82xx_wr_32(ha, QLA82XX_CRB_EPG + 0x1300, 0x1);
Swapnil Naglea1fc26b2010-12-02 22:12:15 -08001021
1022 /* halt timers */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001023 qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x0, 0x0);
1024 qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x8, 0x0);
1025 qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x10, 0x0);
1026 qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x18, 0x0);
1027 qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x100, 0x0);
1028 qla4_82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x200, 0x0);
Swapnil Naglea1fc26b2010-12-02 22:12:15 -08001029
1030 /* halt pegs */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001031 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0 + 0x3c, 1);
1032 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_1 + 0x3c, 1);
1033 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_2 + 0x3c, 1);
1034 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_3 + 0x3c, 1);
1035 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_4 + 0x3c, 1);
Vikas Chaudharycb744282011-05-17 23:17:04 -07001036 msleep(5);
Swapnil Naglea1fc26b2010-12-02 22:12:15 -08001037
1038 /* big hammer */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301039 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
1040 /* don't reset CAM block on reset */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001041 qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0xfeffffff);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301042 else
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001043 qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0xffffffff);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301044
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001045 qla4_82xx_rom_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301046
1047 /* Read the signature value from the flash.
1048 * Offset 0: Contain signature (0xcafecafe)
1049 * Offset 4: Offset and number of addr/value pairs
1050 * that present in CRB initialize sequence
1051 */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001052 if (qla4_82xx_rom_fast_read(ha, 0, &n) != 0 || n != 0xcafecafeUL ||
1053 qla4_82xx_rom_fast_read(ha, 4, &n) != 0) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301054 ql4_printk(KERN_WARNING, ha,
1055 "[ERROR] Reading crb_init area: n: %08x\n", n);
1056 return -1;
1057 }
1058
1059 /* Offset in flash = lower 16 bits
1060 * Number of enteries = upper 16 bits
1061 */
1062 offset = n & 0xffffU;
1063 n = (n >> 16) & 0xffffU;
1064
1065 /* number of addr/value pair should not exceed 1024 enteries */
1066 if (n >= 1024) {
1067 ql4_printk(KERN_WARNING, ha,
1068 "%s: %s:n=0x%x [ERROR] Card flash not initialized.\n",
1069 DRIVER_NAME, __func__, n);
1070 return -1;
1071 }
1072
1073 ql4_printk(KERN_INFO, ha,
1074 "%s: %d CRB init values found in ROM.\n", DRIVER_NAME, n);
1075
1076 buf = kmalloc(n * sizeof(struct crb_addr_pair), GFP_KERNEL);
1077 if (buf == NULL) {
1078 ql4_printk(KERN_WARNING, ha,
1079 "%s: [ERROR] Unable to malloc memory.\n", DRIVER_NAME);
1080 return -1;
1081 }
1082
1083 for (i = 0; i < n; i++) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001084 if (qla4_82xx_rom_fast_read(ha, 8*i + 4*offset, &val) != 0 ||
1085 qla4_82xx_rom_fast_read(ha, 8*i + 4*offset + 4, &addr) !=
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301086 0) {
1087 kfree(buf);
1088 return -1;
1089 }
1090
1091 buf[i].addr = addr;
1092 buf[i].data = val;
1093 }
1094
1095 for (i = 0; i < n; i++) {
1096 /* Translate internal CRB initialization
1097 * address to PCI bus address
1098 */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001099 off = qla4_82xx_decode_crb_addr((unsigned long)buf[i].addr) +
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301100 QLA82XX_PCI_CRBSPACE;
1101 /* Not all CRB addr/value pair to be written,
1102 * some of them are skipped
1103 */
1104
1105 /* skip if LS bit is set*/
1106 if (off & 0x1) {
1107 DEBUG2(ql4_printk(KERN_WARNING, ha,
1108 "Skip CRB init replay for offset = 0x%lx\n", off));
1109 continue;
1110 }
1111
1112 /* skipping cold reboot MAGIC */
1113 if (off == QLA82XX_CAM_RAM(0x1fc))
1114 continue;
1115
1116 /* do not reset PCI */
1117 if (off == (ROMUSB_GLB + 0xbc))
1118 continue;
1119
1120 /* skip core clock, so that firmware can increase the clock */
1121 if (off == (ROMUSB_GLB + 0xc8))
1122 continue;
1123
1124 /* skip the function enable register */
1125 if (off == QLA82XX_PCIE_REG(PCIE_SETUP_FUNCTION))
1126 continue;
1127
1128 if (off == QLA82XX_PCIE_REG(PCIE_SETUP_FUNCTION2))
1129 continue;
1130
1131 if ((off & 0x0ff00000) == QLA82XX_CRB_SMB)
1132 continue;
1133
1134 if ((off & 0x0ff00000) == QLA82XX_CRB_DDR_NET)
1135 continue;
1136
1137 if (off == ADDR_ERROR) {
1138 ql4_printk(KERN_WARNING, ha,
1139 "%s: [ERROR] Unknown addr: 0x%08lx\n",
1140 DRIVER_NAME, buf[i].addr);
1141 continue;
1142 }
1143
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001144 qla4_82xx_wr_32(ha, off, buf[i].data);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301145
1146 /* ISP requires much bigger delay to settle down,
1147 * else crb_window returns 0xffffffff
1148 */
1149 if (off == QLA82XX_ROMUSB_GLB_SW_RESET)
1150 msleep(1000);
1151
1152 /* ISP requires millisec delay between
1153 * successive CRB register updation
1154 */
1155 msleep(1);
1156 }
1157
1158 kfree(buf);
1159
1160 /* Resetting the data and instruction cache */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001161 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_D+0xec, 0x1e);
1162 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_D+0x4c, 8);
1163 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_I+0x4c, 8);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301164
1165 /* Clear all protocol processing engines */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001166 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0+0x8, 0);
1167 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0+0xc, 0);
1168 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_1+0x8, 0);
1169 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_1+0xc, 0);
1170 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_2+0x8, 0);
1171 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_2+0xc, 0);
1172 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_3+0x8, 0);
1173 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_3+0xc, 0);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301174
1175 return 0;
1176}
1177
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301178static int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001179qla4_82xx_load_from_flash(struct scsi_qla_host *ha, uint32_t image_start)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301180{
Lalit Chandivade4cd83cb2010-12-02 22:12:40 -08001181 int i, rval = 0;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301182 long size = 0;
1183 long flashaddr, memaddr;
1184 u64 data;
1185 u32 high, low;
1186
1187 flashaddr = memaddr = ha->hw.flt_region_bootload;
Lalit Chandivade4cd83cb2010-12-02 22:12:40 -08001188 size = (image_start - flashaddr) / 8;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301189
1190 DEBUG2(printk("scsi%ld: %s: bootldr=0x%lx, fw_image=0x%x\n",
1191 ha->host_no, __func__, flashaddr, image_start));
1192
1193 for (i = 0; i < size; i++) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001194 if ((qla4_82xx_rom_fast_read(ha, flashaddr, (int *)&low)) ||
1195 (qla4_82xx_rom_fast_read(ha, flashaddr + 4,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301196 (int *)&high))) {
Lalit Chandivade4cd83cb2010-12-02 22:12:40 -08001197 rval = -1;
1198 goto exit_load_from_flash;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301199 }
1200 data = ((u64)high << 32) | low ;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001201 rval = qla4_82xx_pci_mem_write_2M(ha, memaddr, &data, 8);
Lalit Chandivade4cd83cb2010-12-02 22:12:40 -08001202 if (rval)
1203 goto exit_load_from_flash;
1204
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301205 flashaddr += 8;
1206 memaddr += 8;
1207
Lalit Chandivade4cd83cb2010-12-02 22:12:40 -08001208 if (i % 0x1000 == 0)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301209 msleep(1);
1210
1211 }
1212
1213 udelay(100);
1214
1215 read_lock(&ha->hw_lock);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001216 qla4_82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0 + 0x18, 0x1020);
1217 qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0x80001e);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301218 read_unlock(&ha->hw_lock);
1219
Lalit Chandivade4cd83cb2010-12-02 22:12:40 -08001220exit_load_from_flash:
1221 return rval;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301222}
1223
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001224static int qla4_82xx_load_fw(struct scsi_qla_host *ha, uint32_t image_start)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301225{
1226 u32 rst;
1227
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001228 qla4_82xx_wr_32(ha, CRB_CMDPEG_STATE, 0);
1229 if (qla4_82xx_pinit_from_rom(ha, 0) != QLA_SUCCESS) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301230 printk(KERN_WARNING "%s: Error during CRB Initialization\n",
1231 __func__);
1232 return QLA_ERROR;
1233 }
1234
1235 udelay(500);
1236
1237 /* at this point, QM is in reset. This could be a problem if there are
1238 * incoming d* transition queue messages. QM/PCIE could wedge.
1239 * To get around this, QM is brought out of reset.
1240 */
1241
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001242 rst = qla4_82xx_rd_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301243 /* unreset qm */
1244 rst &= ~(1 << 28);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001245 qla4_82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, rst);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301246
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001247 if (qla4_82xx_load_from_flash(ha, image_start)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301248 printk("%s: Error trying to load fw from flash!\n", __func__);
1249 return QLA_ERROR;
1250 }
1251
1252 return QLA_SUCCESS;
1253}
1254
1255int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001256qla4_82xx_pci_mem_read_2M(struct scsi_qla_host *ha,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301257 u64 off, void *data, int size)
1258{
1259 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1260 int shift_amount;
1261 uint32_t temp;
1262 uint64_t off8, val, mem_crb, word[2] = {0, 0};
1263
1264 /*
1265 * If not MN, go check for MS or invalid.
1266 */
1267
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001268 if (off >= QLA8XXX_ADDR_QDR_NET && off <= QLA82XX_P3_ADDR_QDR_NET_MAX)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301269 mem_crb = QLA82XX_CRB_QDR_NET;
1270 else {
1271 mem_crb = QLA82XX_CRB_DDR_NET;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001272 if (qla4_82xx_pci_mem_bound_check(ha, off, size) == 0)
1273 return qla4_82xx_pci_mem_read_direct(ha,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301274 off, data, size);
1275 }
1276
1277
1278 off8 = off & 0xfffffff0;
1279 off0[0] = off & 0xf;
1280 sz[0] = (size < (16 - off0[0])) ? size : (16 - off0[0]);
1281 shift_amount = 4;
1282
1283 loop = ((off0[0] + size - 1) >> shift_amount) + 1;
1284 off0[1] = 0;
1285 sz[1] = size - sz[0];
1286
1287 for (i = 0; i < loop; i++) {
1288 temp = off8 + (i << shift_amount);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001289 qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_ADDR_LO, temp);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301290 temp = 0;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001291 qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_ADDR_HI, temp);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301292 temp = MIU_TA_CTL_ENABLE;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001293 qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_CTRL, temp);
Vikas Chaudharyc38fa3a2012-08-22 07:55:03 -04001294 temp = MIU_TA_CTL_START_ENABLE;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001295 qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_CTRL, temp);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301296
1297 for (j = 0; j < MAX_CTL_CHECK; j++) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001298 temp = qla4_82xx_rd_32(ha, mem_crb + MIU_TEST_AGT_CTRL);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301299 if ((temp & MIU_TA_CTL_BUSY) == 0)
1300 break;
1301 }
1302
1303 if (j >= MAX_CTL_CHECK) {
Tej Parkash068237c82012-05-18 04:41:44 -04001304 printk_ratelimited(KERN_ERR
1305 "%s: failed to read through agent\n",
1306 __func__);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301307 break;
1308 }
1309
1310 start = off0[i] >> 2;
1311 end = (off0[i] + sz[i] - 1) >> 2;
1312 for (k = start; k <= end; k++) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001313 temp = qla4_82xx_rd_32(ha,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301314 mem_crb + MIU_TEST_AGT_RDDATA(k));
1315 word[i] |= ((uint64_t)temp << (32 * (k & 1)));
1316 }
1317 }
1318
1319 if (j >= MAX_CTL_CHECK)
1320 return -1;
1321
1322 if ((off0[0] & 7) == 0) {
1323 val = word[0];
1324 } else {
1325 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1326 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1327 }
1328
1329 switch (size) {
1330 case 1:
1331 *(uint8_t *)data = val;
1332 break;
1333 case 2:
1334 *(uint16_t *)data = val;
1335 break;
1336 case 4:
1337 *(uint32_t *)data = val;
1338 break;
1339 case 8:
1340 *(uint64_t *)data = val;
1341 break;
1342 }
1343 return 0;
1344}
1345
1346int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001347qla4_82xx_pci_mem_write_2M(struct scsi_qla_host *ha,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301348 u64 off, void *data, int size)
1349{
1350 int i, j, ret = 0, loop, sz[2], off0;
1351 int scale, shift_amount, startword;
1352 uint32_t temp;
1353 uint64_t off8, mem_crb, tmpw, word[2] = {0, 0};
1354
1355 /*
1356 * If not MN, go check for MS or invalid.
1357 */
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001358 if (off >= QLA8XXX_ADDR_QDR_NET && off <= QLA82XX_P3_ADDR_QDR_NET_MAX)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301359 mem_crb = QLA82XX_CRB_QDR_NET;
1360 else {
1361 mem_crb = QLA82XX_CRB_DDR_NET;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001362 if (qla4_82xx_pci_mem_bound_check(ha, off, size) == 0)
1363 return qla4_82xx_pci_mem_write_direct(ha,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301364 off, data, size);
1365 }
1366
1367 off0 = off & 0x7;
1368 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1369 sz[1] = size - sz[0];
1370
1371 off8 = off & 0xfffffff0;
1372 loop = (((off & 0xf) + size - 1) >> 4) + 1;
1373 shift_amount = 4;
1374 scale = 2;
1375 startword = (off & 0xf)/8;
1376
1377 for (i = 0; i < loop; i++) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001378 if (qla4_82xx_pci_mem_read_2M(ha, off8 +
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301379 (i << shift_amount), &word[i * scale], 8))
1380 return -1;
1381 }
1382
1383 switch (size) {
1384 case 1:
1385 tmpw = *((uint8_t *)data);
1386 break;
1387 case 2:
1388 tmpw = *((uint16_t *)data);
1389 break;
1390 case 4:
1391 tmpw = *((uint32_t *)data);
1392 break;
1393 case 8:
1394 default:
1395 tmpw = *((uint64_t *)data);
1396 break;
1397 }
1398
1399 if (sz[0] == 8)
1400 word[startword] = tmpw;
1401 else {
1402 word[startword] &=
1403 ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1404 word[startword] |= tmpw << (off0 * 8);
1405 }
1406
1407 if (sz[1] != 0) {
1408 word[startword+1] &= ~(~0ULL << (sz[1] * 8));
1409 word[startword+1] |= tmpw >> (sz[0] * 8);
1410 }
1411
1412 for (i = 0; i < loop; i++) {
1413 temp = off8 + (i << shift_amount);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001414 qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_ADDR_LO, temp);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301415 temp = 0;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001416 qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_ADDR_HI, temp);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301417 temp = word[i * scale] & 0xffffffff;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001418 qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_WRDATA_LO, temp);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301419 temp = (word[i * scale] >> 32) & 0xffffffff;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001420 qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_WRDATA_HI, temp);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301421 temp = word[i*scale + 1] & 0xffffffff;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001422 qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_WRDATA_UPPER_LO,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301423 temp);
1424 temp = (word[i*scale + 1] >> 32) & 0xffffffff;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001425 qla4_82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_WRDATA_UPPER_HI,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301426 temp);
1427
Vikas Chaudharyc38fa3a2012-08-22 07:55:03 -04001428 temp = MIU_TA_CTL_WRITE_ENABLE;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001429 qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_CTRL, temp);
Vikas Chaudharyc38fa3a2012-08-22 07:55:03 -04001430 temp = MIU_TA_CTL_WRITE_START;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001431 qla4_82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_CTRL, temp);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301432
1433 for (j = 0; j < MAX_CTL_CHECK; j++) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001434 temp = qla4_82xx_rd_32(ha, mem_crb + MIU_TEST_AGT_CTRL);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301435 if ((temp & MIU_TA_CTL_BUSY) == 0)
1436 break;
1437 }
1438
1439 if (j >= MAX_CTL_CHECK) {
1440 if (printk_ratelimit())
1441 ql4_printk(KERN_ERR, ha,
Tej Parkash068237c82012-05-18 04:41:44 -04001442 "%s: failed to read through agent\n",
1443 __func__);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301444 ret = -1;
1445 break;
1446 }
1447 }
1448
1449 return ret;
1450}
1451
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001452static int qla4_82xx_cmdpeg_ready(struct scsi_qla_host *ha, int pegtune_val)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301453{
1454 u32 val = 0;
1455 int retries = 60;
1456
1457 if (!pegtune_val) {
1458 do {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001459 val = qla4_82xx_rd_32(ha, CRB_CMDPEG_STATE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301460 if ((val == PHAN_INITIALIZE_COMPLETE) ||
1461 (val == PHAN_INITIALIZE_ACK))
1462 return 0;
1463 set_current_state(TASK_UNINTERRUPTIBLE);
1464 schedule_timeout(500);
1465
1466 } while (--retries);
1467
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301468 if (!retries) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001469 pegtune_val = qla4_82xx_rd_32(ha,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301470 QLA82XX_ROMUSB_GLB_PEGTUNE_DONE);
1471 printk(KERN_WARNING "%s: init failed, "
1472 "pegtune_val = %x\n", __func__, pegtune_val);
1473 return -1;
1474 }
1475 }
1476 return 0;
1477}
1478
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001479static int qla4_82xx_rcvpeg_ready(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301480{
1481 uint32_t state = 0;
1482 int loops = 0;
1483
1484 /* Window 1 call */
1485 read_lock(&ha->hw_lock);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001486 state = qla4_82xx_rd_32(ha, CRB_RCVPEG_STATE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301487 read_unlock(&ha->hw_lock);
1488
1489 while ((state != PHAN_PEG_RCV_INITIALIZED) && (loops < 30000)) {
1490 udelay(100);
1491 /* Window 1 call */
1492 read_lock(&ha->hw_lock);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001493 state = qla4_82xx_rd_32(ha, CRB_RCVPEG_STATE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301494 read_unlock(&ha->hw_lock);
1495
1496 loops++;
1497 }
1498
1499 if (loops >= 30000) {
1500 DEBUG2(ql4_printk(KERN_INFO, ha,
1501 "Receive Peg initialization not complete: 0x%x.\n", state));
1502 return QLA_ERROR;
1503 }
1504
1505 return QLA_SUCCESS;
1506}
1507
Andrew Morton626115c2010-08-19 14:13:42 -07001508void
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301509qla4_8xxx_set_drv_active(struct scsi_qla_host *ha)
1510{
1511 uint32_t drv_active;
1512
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001513 drv_active = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_ACTIVE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301514 drv_active |= (1 << (ha->func_num * 4));
Tej Parkash068237c82012-05-18 04:41:44 -04001515 ql4_printk(KERN_INFO, ha, "%s(%ld): drv_active: 0x%08x\n",
1516 __func__, ha->host_no, drv_active);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001517 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_ACTIVE, drv_active);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301518}
1519
1520void
1521qla4_8xxx_clear_drv_active(struct scsi_qla_host *ha)
1522{
1523 uint32_t drv_active;
1524
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001525 drv_active = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_ACTIVE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301526 drv_active &= ~(1 << (ha->func_num * 4));
Tej Parkash068237c82012-05-18 04:41:44 -04001527 ql4_printk(KERN_INFO, ha, "%s(%ld): drv_active: 0x%08x\n",
1528 __func__, ha->host_no, drv_active);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001529 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_ACTIVE, drv_active);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301530}
1531
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001532inline int qla4_8xxx_need_reset(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301533{
Lalit Chandivade2232be02010-07-30 14:38:47 +05301534 uint32_t drv_state, drv_active;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301535 int rval;
1536
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001537 drv_active = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_ACTIVE);
1538 drv_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_STATE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301539 rval = drv_state & (1 << (ha->func_num * 4));
Lalit Chandivade2232be02010-07-30 14:38:47 +05301540 if ((test_bit(AF_EEH_BUSY, &ha->flags)) && drv_active)
1541 rval = 1;
1542
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301543 return rval;
1544}
1545
1546static inline void
1547qla4_8xxx_set_rst_ready(struct scsi_qla_host *ha)
1548{
1549 uint32_t drv_state;
1550
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001551 drv_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_STATE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301552 drv_state |= (1 << (ha->func_num * 4));
Tej Parkash068237c82012-05-18 04:41:44 -04001553 ql4_printk(KERN_INFO, ha, "%s(%ld): drv_state: 0x%08x\n",
1554 __func__, ha->host_no, drv_state);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001555 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, drv_state);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301556}
1557
1558static inline void
1559qla4_8xxx_clear_rst_ready(struct scsi_qla_host *ha)
1560{
1561 uint32_t drv_state;
1562
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001563 drv_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_STATE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301564 drv_state &= ~(1 << (ha->func_num * 4));
Tej Parkash068237c82012-05-18 04:41:44 -04001565 ql4_printk(KERN_INFO, ha, "%s(%ld): drv_state: 0x%08x\n",
1566 __func__, ha->host_no, drv_state);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001567 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, drv_state);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301568}
1569
1570static inline void
1571qla4_8xxx_set_qsnt_ready(struct scsi_qla_host *ha)
1572{
1573 uint32_t qsnt_state;
1574
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001575 qsnt_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DRV_STATE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301576 qsnt_state |= (2 << (ha->func_num * 4));
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001577 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_STATE, qsnt_state);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301578}
1579
1580
1581static int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001582qla4_82xx_start_firmware(struct scsi_qla_host *ha, uint32_t image_start)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301583{
1584 int pcie_cap;
1585 uint16_t lnk;
1586
1587 /* scrub dma mask expansion register */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001588 qla4_82xx_wr_32(ha, CRB_DMA_SHIFT, 0x55555555);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301589
1590 /* Overwrite stale initialization register values */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001591 qla4_82xx_wr_32(ha, CRB_CMDPEG_STATE, 0);
1592 qla4_82xx_wr_32(ha, CRB_RCVPEG_STATE, 0);
1593 qla4_82xx_wr_32(ha, QLA82XX_PEG_HALT_STATUS1, 0);
1594 qla4_82xx_wr_32(ha, QLA82XX_PEG_HALT_STATUS2, 0);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301595
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001596 if (qla4_82xx_load_fw(ha, image_start) != QLA_SUCCESS) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301597 printk("%s: Error trying to start fw!\n", __func__);
1598 return QLA_ERROR;
1599 }
1600
1601 /* Handshake with the card before we register the devices. */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001602 if (qla4_82xx_cmdpeg_ready(ha, 0) != QLA_SUCCESS) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301603 printk("%s: Error during card handshake!\n", __func__);
1604 return QLA_ERROR;
1605 }
1606
1607 /* Negotiated Link width */
Jon Mason983bfb52012-07-10 14:57:55 -07001608 pcie_cap = pci_pcie_cap(ha->pdev);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301609 pci_read_config_word(ha->pdev, pcie_cap + PCI_EXP_LNKSTA, &lnk);
1610 ha->link_width = (lnk >> 4) & 0x3f;
1611
1612 /* Synchronize with Receive peg */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001613 return qla4_82xx_rcvpeg_ready(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301614}
1615
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001616int qla4_82xx_try_start_fw(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301617{
1618 int rval = QLA_ERROR;
1619
1620 /*
1621 * FW Load priority:
1622 * 1) Operational firmware residing in flash.
1623 * 2) Fail
1624 */
1625
1626 ql4_printk(KERN_INFO, ha,
1627 "FW: Retrieving flash offsets from FLT/FDT ...\n");
1628 rval = qla4_8xxx_get_flash_info(ha);
1629 if (rval != QLA_SUCCESS)
1630 return rval;
1631
1632 ql4_printk(KERN_INFO, ha,
1633 "FW: Attempting to load firmware from flash...\n");
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001634 rval = qla4_82xx_start_firmware(ha, ha->hw.flt_region_fw);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301635
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07001636 if (rval != QLA_SUCCESS) {
1637 ql4_printk(KERN_ERR, ha, "FW: Load firmware from flash"
1638 " FAILED...\n");
1639 return rval;
1640 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301641
1642 return rval;
1643}
1644
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001645void qla4_82xx_rom_lock_recovery(struct scsi_qla_host *ha)
Shyam Sundarb25ee662010-10-06 22:50:51 -07001646{
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001647 if (qla4_82xx_rom_lock(ha)) {
Shyam Sundarb25ee662010-10-06 22:50:51 -07001648 /* Someone else is holding the lock. */
1649 dev_info(&ha->pdev->dev, "Resetting rom_lock\n");
1650 }
1651
1652 /*
1653 * Either we got the lock, or someone
1654 * else died while holding it.
1655 * In either case, unlock.
1656 */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001657 qla4_82xx_rom_unlock(ha);
Shyam Sundarb25ee662010-10-06 22:50:51 -07001658}
1659
Tej Parkash068237c82012-05-18 04:41:44 -04001660static void qla4_8xxx_minidump_process_rdcrb(struct scsi_qla_host *ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001661 struct qla8xxx_minidump_entry_hdr *entry_hdr,
Tej Parkash068237c82012-05-18 04:41:44 -04001662 uint32_t **d_ptr)
1663{
1664 uint32_t r_addr, r_stride, loop_cnt, i, r_value;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001665 struct qla8xxx_minidump_entry_crb *crb_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001666 uint32_t *data_ptr = *d_ptr;
1667
1668 DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001669 crb_hdr = (struct qla8xxx_minidump_entry_crb *)entry_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001670 r_addr = crb_hdr->addr;
1671 r_stride = crb_hdr->crb_strd.addr_stride;
1672 loop_cnt = crb_hdr->op_count;
1673
1674 for (i = 0; i < loop_cnt; i++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001675 ha->isp_ops->rd_reg_indirect(ha, r_addr, &r_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001676 *data_ptr++ = cpu_to_le32(r_addr);
1677 *data_ptr++ = cpu_to_le32(r_value);
1678 r_addr += r_stride;
1679 }
1680 *d_ptr = data_ptr;
1681}
1682
1683static int qla4_8xxx_minidump_process_l2tag(struct scsi_qla_host *ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001684 struct qla8xxx_minidump_entry_hdr *entry_hdr,
Tej Parkash068237c82012-05-18 04:41:44 -04001685 uint32_t **d_ptr)
1686{
1687 uint32_t addr, r_addr, c_addr, t_r_addr;
1688 uint32_t i, k, loop_count, t_value, r_cnt, r_value;
1689 unsigned long p_wait, w_time, p_mask;
1690 uint32_t c_value_w, c_value_r;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001691 struct qla8xxx_minidump_entry_cache *cache_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001692 int rval = QLA_ERROR;
1693 uint32_t *data_ptr = *d_ptr;
1694
1695 DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001696 cache_hdr = (struct qla8xxx_minidump_entry_cache *)entry_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001697
1698 loop_count = cache_hdr->op_count;
1699 r_addr = cache_hdr->read_addr;
1700 c_addr = cache_hdr->control_addr;
1701 c_value_w = cache_hdr->cache_ctrl.write_value;
1702
1703 t_r_addr = cache_hdr->tag_reg_addr;
1704 t_value = cache_hdr->addr_ctrl.init_tag_value;
1705 r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
1706 p_wait = cache_hdr->cache_ctrl.poll_wait;
1707 p_mask = cache_hdr->cache_ctrl.poll_mask;
1708
1709 for (i = 0; i < loop_count; i++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001710 ha->isp_ops->wr_reg_indirect(ha, t_r_addr, t_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001711
1712 if (c_value_w)
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001713 ha->isp_ops->wr_reg_indirect(ha, c_addr, c_value_w);
Tej Parkash068237c82012-05-18 04:41:44 -04001714
1715 if (p_mask) {
1716 w_time = jiffies + p_wait;
1717 do {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001718 ha->isp_ops->rd_reg_indirect(ha, c_addr,
1719 &c_value_r);
Tej Parkash068237c82012-05-18 04:41:44 -04001720 if ((c_value_r & p_mask) == 0) {
1721 break;
1722 } else if (time_after_eq(jiffies, w_time)) {
1723 /* capturing dump failed */
1724 return rval;
1725 }
1726 } while (1);
1727 }
1728
1729 addr = r_addr;
1730 for (k = 0; k < r_cnt; k++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001731 ha->isp_ops->rd_reg_indirect(ha, addr, &r_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001732 *data_ptr++ = cpu_to_le32(r_value);
1733 addr += cache_hdr->read_ctrl.read_addr_stride;
1734 }
1735
1736 t_value += cache_hdr->addr_ctrl.tag_value_stride;
1737 }
1738 *d_ptr = data_ptr;
1739 return QLA_SUCCESS;
1740}
1741
1742static int qla4_8xxx_minidump_process_control(struct scsi_qla_host *ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001743 struct qla8xxx_minidump_entry_hdr *entry_hdr)
Tej Parkash068237c82012-05-18 04:41:44 -04001744{
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001745 struct qla8xxx_minidump_entry_crb *crb_entry;
Tej Parkash068237c82012-05-18 04:41:44 -04001746 uint32_t read_value, opcode, poll_time, addr, index, rval = QLA_SUCCESS;
1747 uint32_t crb_addr;
1748 unsigned long wtime;
1749 struct qla4_8xxx_minidump_template_hdr *tmplt_hdr;
1750 int i;
1751
1752 DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
1753 tmplt_hdr = (struct qla4_8xxx_minidump_template_hdr *)
1754 ha->fw_dump_tmplt_hdr;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001755 crb_entry = (struct qla8xxx_minidump_entry_crb *)entry_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001756
1757 crb_addr = crb_entry->addr;
1758 for (i = 0; i < crb_entry->op_count; i++) {
1759 opcode = crb_entry->crb_ctrl.opcode;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001760 if (opcode & QLA8XXX_DBG_OPCODE_WR) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001761 ha->isp_ops->wr_reg_indirect(ha, crb_addr,
1762 crb_entry->value_1);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001763 opcode &= ~QLA8XXX_DBG_OPCODE_WR;
Tej Parkash068237c82012-05-18 04:41:44 -04001764 }
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001765 if (opcode & QLA8XXX_DBG_OPCODE_RW) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001766 ha->isp_ops->rd_reg_indirect(ha, crb_addr, &read_value);
1767 ha->isp_ops->wr_reg_indirect(ha, crb_addr, read_value);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001768 opcode &= ~QLA8XXX_DBG_OPCODE_RW;
Tej Parkash068237c82012-05-18 04:41:44 -04001769 }
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001770 if (opcode & QLA8XXX_DBG_OPCODE_AND) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001771 ha->isp_ops->rd_reg_indirect(ha, crb_addr, &read_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001772 read_value &= crb_entry->value_2;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001773 opcode &= ~QLA8XXX_DBG_OPCODE_AND;
1774 if (opcode & QLA8XXX_DBG_OPCODE_OR) {
Tej Parkash068237c82012-05-18 04:41:44 -04001775 read_value |= crb_entry->value_3;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001776 opcode &= ~QLA8XXX_DBG_OPCODE_OR;
Tej Parkash068237c82012-05-18 04:41:44 -04001777 }
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001778 ha->isp_ops->wr_reg_indirect(ha, crb_addr, read_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001779 }
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001780 if (opcode & QLA8XXX_DBG_OPCODE_OR) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001781 ha->isp_ops->rd_reg_indirect(ha, crb_addr, &read_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001782 read_value |= crb_entry->value_3;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001783 ha->isp_ops->wr_reg_indirect(ha, crb_addr, read_value);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001784 opcode &= ~QLA8XXX_DBG_OPCODE_OR;
Tej Parkash068237c82012-05-18 04:41:44 -04001785 }
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001786 if (opcode & QLA8XXX_DBG_OPCODE_POLL) {
Tej Parkash068237c82012-05-18 04:41:44 -04001787 poll_time = crb_entry->crb_strd.poll_timeout;
1788 wtime = jiffies + poll_time;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001789 ha->isp_ops->rd_reg_indirect(ha, crb_addr, &read_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001790
1791 do {
1792 if ((read_value & crb_entry->value_2) ==
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001793 crb_entry->value_1) {
Tej Parkash068237c82012-05-18 04:41:44 -04001794 break;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001795 } else if (time_after_eq(jiffies, wtime)) {
Tej Parkash068237c82012-05-18 04:41:44 -04001796 /* capturing dump failed */
1797 rval = QLA_ERROR;
1798 break;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001799 } else {
1800 ha->isp_ops->rd_reg_indirect(ha,
1801 crb_addr, &read_value);
1802 }
Tej Parkash068237c82012-05-18 04:41:44 -04001803 } while (1);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001804 opcode &= ~QLA8XXX_DBG_OPCODE_POLL;
Tej Parkash068237c82012-05-18 04:41:44 -04001805 }
1806
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001807 if (opcode & QLA8XXX_DBG_OPCODE_RDSTATE) {
Tej Parkash068237c82012-05-18 04:41:44 -04001808 if (crb_entry->crb_strd.state_index_a) {
1809 index = crb_entry->crb_strd.state_index_a;
1810 addr = tmplt_hdr->saved_state_array[index];
1811 } else {
1812 addr = crb_addr;
1813 }
1814
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001815 ha->isp_ops->rd_reg_indirect(ha, addr, &read_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001816 index = crb_entry->crb_ctrl.state_index_v;
1817 tmplt_hdr->saved_state_array[index] = read_value;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001818 opcode &= ~QLA8XXX_DBG_OPCODE_RDSTATE;
Tej Parkash068237c82012-05-18 04:41:44 -04001819 }
1820
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001821 if (opcode & QLA8XXX_DBG_OPCODE_WRSTATE) {
Tej Parkash068237c82012-05-18 04:41:44 -04001822 if (crb_entry->crb_strd.state_index_a) {
1823 index = crb_entry->crb_strd.state_index_a;
1824 addr = tmplt_hdr->saved_state_array[index];
1825 } else {
1826 addr = crb_addr;
1827 }
1828
1829 if (crb_entry->crb_ctrl.state_index_v) {
1830 index = crb_entry->crb_ctrl.state_index_v;
1831 read_value =
1832 tmplt_hdr->saved_state_array[index];
1833 } else {
1834 read_value = crb_entry->value_1;
1835 }
1836
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001837 ha->isp_ops->wr_reg_indirect(ha, addr, read_value);
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001838 opcode &= ~QLA8XXX_DBG_OPCODE_WRSTATE;
Tej Parkash068237c82012-05-18 04:41:44 -04001839 }
1840
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001841 if (opcode & QLA8XXX_DBG_OPCODE_MDSTATE) {
Tej Parkash068237c82012-05-18 04:41:44 -04001842 index = crb_entry->crb_ctrl.state_index_v;
1843 read_value = tmplt_hdr->saved_state_array[index];
1844 read_value <<= crb_entry->crb_ctrl.shl;
1845 read_value >>= crb_entry->crb_ctrl.shr;
1846 if (crb_entry->value_2)
1847 read_value &= crb_entry->value_2;
1848 read_value |= crb_entry->value_3;
1849 read_value += crb_entry->value_1;
1850 tmplt_hdr->saved_state_array[index] = read_value;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04001851 opcode &= ~QLA8XXX_DBG_OPCODE_MDSTATE;
Tej Parkash068237c82012-05-18 04:41:44 -04001852 }
1853 crb_addr += crb_entry->crb_strd.addr_stride;
1854 }
1855 DEBUG2(ql4_printk(KERN_INFO, ha, "Leaving fn: %s\n", __func__));
1856 return rval;
1857}
1858
1859static void qla4_8xxx_minidump_process_rdocm(struct scsi_qla_host *ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001860 struct qla8xxx_minidump_entry_hdr *entry_hdr,
Tej Parkash068237c82012-05-18 04:41:44 -04001861 uint32_t **d_ptr)
1862{
1863 uint32_t r_addr, r_stride, loop_cnt, i, r_value;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001864 struct qla8xxx_minidump_entry_rdocm *ocm_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001865 uint32_t *data_ptr = *d_ptr;
1866
1867 DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001868 ocm_hdr = (struct qla8xxx_minidump_entry_rdocm *)entry_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001869 r_addr = ocm_hdr->read_addr;
1870 r_stride = ocm_hdr->read_addr_stride;
1871 loop_cnt = ocm_hdr->op_count;
1872
1873 DEBUG2(ql4_printk(KERN_INFO, ha,
1874 "[%s]: r_addr: 0x%x, r_stride: 0x%x, loop_cnt: 0x%x\n",
1875 __func__, r_addr, r_stride, loop_cnt));
1876
1877 for (i = 0; i < loop_cnt; i++) {
1878 r_value = readl((void __iomem *)(r_addr + ha->nx_pcibase));
1879 *data_ptr++ = cpu_to_le32(r_value);
1880 r_addr += r_stride;
1881 }
1882 DEBUG2(ql4_printk(KERN_INFO, ha, "Leaving fn: %s datacount: 0x%lx\n",
Vikas Chaudhary26fdf922012-08-07 07:57:14 -04001883 __func__, (long unsigned int) (loop_cnt * sizeof(uint32_t))));
Tej Parkash068237c82012-05-18 04:41:44 -04001884 *d_ptr = data_ptr;
1885}
1886
1887static void qla4_8xxx_minidump_process_rdmux(struct scsi_qla_host *ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001888 struct qla8xxx_minidump_entry_hdr *entry_hdr,
Tej Parkash068237c82012-05-18 04:41:44 -04001889 uint32_t **d_ptr)
1890{
1891 uint32_t r_addr, s_stride, s_addr, s_value, loop_cnt, i, r_value;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001892 struct qla8xxx_minidump_entry_mux *mux_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001893 uint32_t *data_ptr = *d_ptr;
1894
1895 DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001896 mux_hdr = (struct qla8xxx_minidump_entry_mux *)entry_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001897 r_addr = mux_hdr->read_addr;
1898 s_addr = mux_hdr->select_addr;
1899 s_stride = mux_hdr->select_value_stride;
1900 s_value = mux_hdr->select_value;
1901 loop_cnt = mux_hdr->op_count;
1902
1903 for (i = 0; i < loop_cnt; i++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001904 ha->isp_ops->wr_reg_indirect(ha, s_addr, s_value);
1905 ha->isp_ops->rd_reg_indirect(ha, r_addr, &r_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001906 *data_ptr++ = cpu_to_le32(s_value);
1907 *data_ptr++ = cpu_to_le32(r_value);
1908 s_value += s_stride;
1909 }
1910 *d_ptr = data_ptr;
1911}
1912
1913static void qla4_8xxx_minidump_process_l1cache(struct scsi_qla_host *ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001914 struct qla8xxx_minidump_entry_hdr *entry_hdr,
Tej Parkash068237c82012-05-18 04:41:44 -04001915 uint32_t **d_ptr)
1916{
1917 uint32_t addr, r_addr, c_addr, t_r_addr;
1918 uint32_t i, k, loop_count, t_value, r_cnt, r_value;
1919 uint32_t c_value_w;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001920 struct qla8xxx_minidump_entry_cache *cache_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001921 uint32_t *data_ptr = *d_ptr;
1922
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001923 cache_hdr = (struct qla8xxx_minidump_entry_cache *)entry_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001924 loop_count = cache_hdr->op_count;
1925 r_addr = cache_hdr->read_addr;
1926 c_addr = cache_hdr->control_addr;
1927 c_value_w = cache_hdr->cache_ctrl.write_value;
1928
1929 t_r_addr = cache_hdr->tag_reg_addr;
1930 t_value = cache_hdr->addr_ctrl.init_tag_value;
1931 r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
1932
1933 for (i = 0; i < loop_count; i++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001934 ha->isp_ops->wr_reg_indirect(ha, t_r_addr, t_value);
1935 ha->isp_ops->wr_reg_indirect(ha, c_addr, c_value_w);
Tej Parkash068237c82012-05-18 04:41:44 -04001936 addr = r_addr;
1937 for (k = 0; k < r_cnt; k++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001938 ha->isp_ops->rd_reg_indirect(ha, addr, &r_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001939 *data_ptr++ = cpu_to_le32(r_value);
1940 addr += cache_hdr->read_ctrl.read_addr_stride;
1941 }
1942 t_value += cache_hdr->addr_ctrl.tag_value_stride;
1943 }
1944 *d_ptr = data_ptr;
1945}
1946
1947static void qla4_8xxx_minidump_process_queue(struct scsi_qla_host *ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001948 struct qla8xxx_minidump_entry_hdr *entry_hdr,
Tej Parkash068237c82012-05-18 04:41:44 -04001949 uint32_t **d_ptr)
1950{
1951 uint32_t s_addr, r_addr;
1952 uint32_t r_stride, r_value, r_cnt, qid = 0;
1953 uint32_t i, k, loop_cnt;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001954 struct qla8xxx_minidump_entry_queue *q_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001955 uint32_t *data_ptr = *d_ptr;
1956
1957 DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001958 q_hdr = (struct qla8xxx_minidump_entry_queue *)entry_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001959 s_addr = q_hdr->select_addr;
1960 r_cnt = q_hdr->rd_strd.read_addr_cnt;
1961 r_stride = q_hdr->rd_strd.read_addr_stride;
1962 loop_cnt = q_hdr->op_count;
1963
1964 for (i = 0; i < loop_cnt; i++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001965 ha->isp_ops->wr_reg_indirect(ha, s_addr, qid);
Tej Parkash068237c82012-05-18 04:41:44 -04001966 r_addr = q_hdr->read_addr;
1967 for (k = 0; k < r_cnt; k++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001968 ha->isp_ops->rd_reg_indirect(ha, r_addr, &r_value);
Tej Parkash068237c82012-05-18 04:41:44 -04001969 *data_ptr++ = cpu_to_le32(r_value);
1970 r_addr += r_stride;
1971 }
1972 qid += q_hdr->q_strd.queue_id_stride;
1973 }
1974 *d_ptr = data_ptr;
1975}
1976
1977#define MD_DIRECT_ROM_WINDOW 0x42110030
1978#define MD_DIRECT_ROM_READ_BASE 0x42150000
1979
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04001980static void qla4_82xx_minidump_process_rdrom(struct scsi_qla_host *ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001981 struct qla8xxx_minidump_entry_hdr *entry_hdr,
Tej Parkash068237c82012-05-18 04:41:44 -04001982 uint32_t **d_ptr)
1983{
1984 uint32_t r_addr, r_value;
1985 uint32_t i, loop_cnt;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001986 struct qla8xxx_minidump_entry_rdrom *rom_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001987 uint32_t *data_ptr = *d_ptr;
1988
1989 DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04001990 rom_hdr = (struct qla8xxx_minidump_entry_rdrom *)entry_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04001991 r_addr = rom_hdr->read_addr;
1992 loop_cnt = rom_hdr->read_data_size/sizeof(uint32_t);
1993
1994 DEBUG2(ql4_printk(KERN_INFO, ha,
1995 "[%s]: flash_addr: 0x%x, read_data_size: 0x%x\n",
1996 __func__, r_addr, loop_cnt));
1997
1998 for (i = 0; i < loop_cnt; i++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04001999 ha->isp_ops->wr_reg_indirect(ha, MD_DIRECT_ROM_WINDOW,
2000 (r_addr & 0xFFFF0000));
2001 ha->isp_ops->rd_reg_indirect(ha,
2002 MD_DIRECT_ROM_READ_BASE + (r_addr & 0x0000FFFF),
2003 &r_value);
Tej Parkash068237c82012-05-18 04:41:44 -04002004 *data_ptr++ = cpu_to_le32(r_value);
2005 r_addr += sizeof(uint32_t);
2006 }
2007 *d_ptr = data_ptr;
2008}
2009
2010#define MD_MIU_TEST_AGT_CTRL 0x41000090
2011#define MD_MIU_TEST_AGT_ADDR_LO 0x41000094
2012#define MD_MIU_TEST_AGT_ADDR_HI 0x41000098
2013
2014static int qla4_8xxx_minidump_process_rdmem(struct scsi_qla_host *ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04002015 struct qla8xxx_minidump_entry_hdr *entry_hdr,
Tej Parkash068237c82012-05-18 04:41:44 -04002016 uint32_t **d_ptr)
2017{
2018 uint32_t r_addr, r_value, r_data;
2019 uint32_t i, j, loop_cnt;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04002020 struct qla8xxx_minidump_entry_rdmem *m_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04002021 unsigned long flags;
2022 uint32_t *data_ptr = *d_ptr;
2023
2024 DEBUG2(ql4_printk(KERN_INFO, ha, "Entering fn: %s\n", __func__));
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04002025 m_hdr = (struct qla8xxx_minidump_entry_rdmem *)entry_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04002026 r_addr = m_hdr->read_addr;
2027 loop_cnt = m_hdr->read_data_size/16;
2028
2029 DEBUG2(ql4_printk(KERN_INFO, ha,
2030 "[%s]: Read addr: 0x%x, read_data_size: 0x%x\n",
2031 __func__, r_addr, m_hdr->read_data_size));
2032
2033 if (r_addr & 0xf) {
2034 DEBUG2(ql4_printk(KERN_INFO, ha,
2035 "[%s]: Read addr 0x%x not 16 bytes alligned\n",
2036 __func__, r_addr));
2037 return QLA_ERROR;
2038 }
2039
2040 if (m_hdr->read_data_size % 16) {
2041 DEBUG2(ql4_printk(KERN_INFO, ha,
2042 "[%s]: Read data[0x%x] not multiple of 16 bytes\n",
2043 __func__, m_hdr->read_data_size));
2044 return QLA_ERROR;
2045 }
2046
2047 DEBUG2(ql4_printk(KERN_INFO, ha,
2048 "[%s]: rdmem_addr: 0x%x, read_data_size: 0x%x, loop_cnt: 0x%x\n",
2049 __func__, r_addr, m_hdr->read_data_size, loop_cnt));
2050
2051 write_lock_irqsave(&ha->hw_lock, flags);
2052 for (i = 0; i < loop_cnt; i++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002053 ha->isp_ops->wr_reg_indirect(ha, MD_MIU_TEST_AGT_ADDR_LO,
2054 r_addr);
Tej Parkash068237c82012-05-18 04:41:44 -04002055 r_value = 0;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002056 ha->isp_ops->wr_reg_indirect(ha, MD_MIU_TEST_AGT_ADDR_HI,
2057 r_value);
Tej Parkash068237c82012-05-18 04:41:44 -04002058 r_value = MIU_TA_CTL_ENABLE;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002059 ha->isp_ops->wr_reg_indirect(ha, MD_MIU_TEST_AGT_CTRL, r_value);
Vikas Chaudharyc38fa3a2012-08-22 07:55:03 -04002060 r_value = MIU_TA_CTL_START_ENABLE;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002061 ha->isp_ops->wr_reg_indirect(ha, MD_MIU_TEST_AGT_CTRL, r_value);
Tej Parkash068237c82012-05-18 04:41:44 -04002062
2063 for (j = 0; j < MAX_CTL_CHECK; j++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002064 ha->isp_ops->rd_reg_indirect(ha, MD_MIU_TEST_AGT_CTRL,
2065 &r_value);
Tej Parkash068237c82012-05-18 04:41:44 -04002066 if ((r_value & MIU_TA_CTL_BUSY) == 0)
2067 break;
2068 }
2069
2070 if (j >= MAX_CTL_CHECK) {
2071 printk_ratelimited(KERN_ERR
2072 "%s: failed to read through agent\n",
2073 __func__);
2074 write_unlock_irqrestore(&ha->hw_lock, flags);
2075 return QLA_SUCCESS;
2076 }
2077
2078 for (j = 0; j < 4; j++) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002079 ha->isp_ops->rd_reg_indirect(ha,
2080 MD_MIU_TEST_AGT_RDDATA[j],
2081 &r_data);
Tej Parkash068237c82012-05-18 04:41:44 -04002082 *data_ptr++ = cpu_to_le32(r_data);
2083 }
2084
2085 r_addr += 16;
2086 }
2087 write_unlock_irqrestore(&ha->hw_lock, flags);
2088
2089 DEBUG2(ql4_printk(KERN_INFO, ha, "Leaving fn: %s datacount: 0x%x\n",
2090 __func__, (loop_cnt * 16)));
2091
2092 *d_ptr = data_ptr;
2093 return QLA_SUCCESS;
2094}
2095
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -04002096static void qla4_8xxx_mark_entry_skipped(struct scsi_qla_host *ha,
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04002097 struct qla8xxx_minidump_entry_hdr *entry_hdr,
Tej Parkash068237c82012-05-18 04:41:44 -04002098 int index)
2099{
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002100 entry_hdr->d_ctrl.driver_flags |= QLA8XXX_DBG_SKIPPED_FLAG;
Tej Parkash068237c82012-05-18 04:41:44 -04002101 DEBUG2(ql4_printk(KERN_INFO, ha,
2102 "scsi(%ld): Skipping entry[%d]: ETYPE[0x%x]-ELEVEL[0x%x]\n",
2103 ha->host_no, index, entry_hdr->entry_type,
2104 entry_hdr->d_ctrl.entry_capture_mask));
2105}
2106
2107/**
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002108 * qla4_8xxx_collect_md_data - Retrieve firmware minidump data.
Tej Parkash068237c82012-05-18 04:41:44 -04002109 * @ha: pointer to adapter structure
2110 **/
2111static int qla4_8xxx_collect_md_data(struct scsi_qla_host *ha)
2112{
2113 int num_entry_hdr = 0;
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04002114 struct qla8xxx_minidump_entry_hdr *entry_hdr;
Tej Parkash068237c82012-05-18 04:41:44 -04002115 struct qla4_8xxx_minidump_template_hdr *tmplt_hdr;
2116 uint32_t *data_ptr;
2117 uint32_t data_collected = 0;
2118 int i, rval = QLA_ERROR;
2119 uint64_t now;
2120 uint32_t timestamp;
2121
2122 if (!ha->fw_dump) {
2123 ql4_printk(KERN_INFO, ha, "%s(%ld) No buffer to dump\n",
2124 __func__, ha->host_no);
2125 return rval;
2126 }
2127
2128 tmplt_hdr = (struct qla4_8xxx_minidump_template_hdr *)
2129 ha->fw_dump_tmplt_hdr;
2130 data_ptr = (uint32_t *)((uint8_t *)ha->fw_dump +
2131 ha->fw_dump_tmplt_size);
2132 data_collected += ha->fw_dump_tmplt_size;
2133
2134 num_entry_hdr = tmplt_hdr->num_of_entries;
2135 ql4_printk(KERN_INFO, ha, "[%s]: starting data ptr: %p\n",
2136 __func__, data_ptr);
2137 ql4_printk(KERN_INFO, ha,
2138 "[%s]: no of entry headers in Template: 0x%x\n",
2139 __func__, num_entry_hdr);
2140 ql4_printk(KERN_INFO, ha, "[%s]: Capture Mask obtained: 0x%x\n",
2141 __func__, ha->fw_dump_capture_mask);
2142 ql4_printk(KERN_INFO, ha, "[%s]: Total_data_size 0x%x, %d obtained\n",
2143 __func__, ha->fw_dump_size, ha->fw_dump_size);
2144
2145 /* Update current timestamp before taking dump */
2146 now = get_jiffies_64();
2147 timestamp = (u32)(jiffies_to_msecs(now) / 1000);
2148 tmplt_hdr->driver_timestamp = timestamp;
2149
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04002150 entry_hdr = (struct qla8xxx_minidump_entry_hdr *)
Tej Parkash068237c82012-05-18 04:41:44 -04002151 (((uint8_t *)ha->fw_dump_tmplt_hdr) +
2152 tmplt_hdr->first_entry_offset);
2153
2154 /* Walk through the entry headers - validate/perform required action */
2155 for (i = 0; i < num_entry_hdr; i++) {
2156 if (data_collected >= ha->fw_dump_size) {
2157 ql4_printk(KERN_INFO, ha,
2158 "Data collected: [0x%x], Total Dump size: [0x%x]\n",
2159 data_collected, ha->fw_dump_size);
2160 return rval;
2161 }
2162
2163 if (!(entry_hdr->d_ctrl.entry_capture_mask &
2164 ha->fw_dump_capture_mask)) {
2165 entry_hdr->d_ctrl.driver_flags |=
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002166 QLA8XXX_DBG_SKIPPED_FLAG;
Tej Parkash068237c82012-05-18 04:41:44 -04002167 goto skip_nxt_entry;
2168 }
2169
2170 DEBUG2(ql4_printk(KERN_INFO, ha,
2171 "Data collected: [0x%x], Dump size left:[0x%x]\n",
2172 data_collected,
2173 (ha->fw_dump_size - data_collected)));
2174
2175 /* Decode the entry type and take required action to capture
2176 * debug data
2177 */
2178 switch (entry_hdr->entry_type) {
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002179 case QLA8XXX_RDEND:
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -04002180 qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
Tej Parkash068237c82012-05-18 04:41:44 -04002181 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002182 case QLA8XXX_CNTRL:
Tej Parkash068237c82012-05-18 04:41:44 -04002183 rval = qla4_8xxx_minidump_process_control(ha,
2184 entry_hdr);
2185 if (rval != QLA_SUCCESS) {
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -04002186 qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
Tej Parkash068237c82012-05-18 04:41:44 -04002187 goto md_failed;
2188 }
2189 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002190 case QLA8XXX_RDCRB:
Tej Parkash068237c82012-05-18 04:41:44 -04002191 qla4_8xxx_minidump_process_rdcrb(ha, entry_hdr,
2192 &data_ptr);
2193 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002194 case QLA8XXX_RDMEM:
Tej Parkash068237c82012-05-18 04:41:44 -04002195 rval = qla4_8xxx_minidump_process_rdmem(ha, entry_hdr,
2196 &data_ptr);
2197 if (rval != QLA_SUCCESS) {
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -04002198 qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
Tej Parkash068237c82012-05-18 04:41:44 -04002199 goto md_failed;
2200 }
2201 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002202 case QLA8XXX_BOARD:
2203 case QLA8XXX_RDROM:
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002204 qla4_82xx_minidump_process_rdrom(ha, entry_hdr,
Tej Parkash068237c82012-05-18 04:41:44 -04002205 &data_ptr);
2206 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002207 case QLA8XXX_L2DTG:
2208 case QLA8XXX_L2ITG:
2209 case QLA8XXX_L2DAT:
2210 case QLA8XXX_L2INS:
Tej Parkash068237c82012-05-18 04:41:44 -04002211 rval = qla4_8xxx_minidump_process_l2tag(ha, entry_hdr,
2212 &data_ptr);
2213 if (rval != QLA_SUCCESS) {
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -04002214 qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
Tej Parkash068237c82012-05-18 04:41:44 -04002215 goto md_failed;
2216 }
2217 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002218 case QLA8XXX_L1DAT:
2219 case QLA8XXX_L1INS:
Tej Parkash068237c82012-05-18 04:41:44 -04002220 qla4_8xxx_minidump_process_l1cache(ha, entry_hdr,
2221 &data_ptr);
2222 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002223 case QLA8XXX_RDOCM:
Tej Parkash068237c82012-05-18 04:41:44 -04002224 qla4_8xxx_minidump_process_rdocm(ha, entry_hdr,
2225 &data_ptr);
2226 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002227 case QLA8XXX_RDMUX:
Tej Parkash068237c82012-05-18 04:41:44 -04002228 qla4_8xxx_minidump_process_rdmux(ha, entry_hdr,
2229 &data_ptr);
2230 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002231 case QLA8XXX_QUEUE:
Tej Parkash068237c82012-05-18 04:41:44 -04002232 qla4_8xxx_minidump_process_queue(ha, entry_hdr,
2233 &data_ptr);
2234 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002235 case QLA8XXX_RDNOP:
Tej Parkash068237c82012-05-18 04:41:44 -04002236 default:
Vikas Chaudhary5e9bcec2012-08-22 07:55:01 -04002237 qla4_8xxx_mark_entry_skipped(ha, entry_hdr, i);
Tej Parkash068237c82012-05-18 04:41:44 -04002238 break;
2239 }
2240
2241 data_collected = (uint8_t *)data_ptr -
2242 ((uint8_t *)((uint8_t *)ha->fw_dump +
2243 ha->fw_dump_tmplt_size));
2244skip_nxt_entry:
2245 /* next entry in the template */
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04002246 entry_hdr = (struct qla8xxx_minidump_entry_hdr *)
Tej Parkash068237c82012-05-18 04:41:44 -04002247 (((uint8_t *)entry_hdr) +
2248 entry_hdr->entry_size);
2249 }
2250
2251 if ((data_collected + ha->fw_dump_tmplt_size) != ha->fw_dump_size) {
2252 ql4_printk(KERN_INFO, ha,
2253 "Dump data mismatch: Data collected: [0x%x], total_data_size:[0x%x]\n",
2254 data_collected, ha->fw_dump_size);
2255 goto md_failed;
2256 }
2257
2258 DEBUG2(ql4_printk(KERN_INFO, ha, "Leaving fn: %s Last entry: 0x%x\n",
2259 __func__, i));
2260md_failed:
2261 return rval;
2262}
2263
2264/**
2265 * qla4_8xxx_uevent_emit - Send uevent when the firmware dump is ready.
2266 * @ha: pointer to adapter structure
2267 **/
2268static void qla4_8xxx_uevent_emit(struct scsi_qla_host *ha, u32 code)
2269{
2270 char event_string[40];
2271 char *envp[] = { event_string, NULL };
2272
2273 switch (code) {
2274 case QL4_UEVENT_CODE_FW_DUMP:
2275 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
2276 ha->host_no);
2277 break;
2278 default:
2279 /*do nothing*/
2280 break;
2281 }
2282
2283 kobject_uevent_env(&(&ha->pdev->dev)->kobj, KOBJ_CHANGE, envp);
2284}
2285
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302286/**
2287 * qla4_8xxx_device_bootstrap - Initialize device, set DEV_READY, start fw
2288 * @ha: pointer to adapter structure
2289 *
2290 * Note: IDC lock must be held upon entry
2291 **/
2292static int
2293qla4_8xxx_device_bootstrap(struct scsi_qla_host *ha)
2294{
Shyam Sundarb25ee662010-10-06 22:50:51 -07002295 int rval = QLA_ERROR;
2296 int i, timeout;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302297 uint32_t old_count, count;
Shyam Sundarb25ee662010-10-06 22:50:51 -07002298 int need_reset = 0, peg_stuck = 1;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302299
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002300 need_reset = ha->isp_ops->need_reset(ha);
2301 old_count = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302302
2303 for (i = 0; i < 10; i++) {
2304 timeout = msleep_interruptible(200);
2305 if (timeout) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002306 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
2307 QLA8XXX_DEV_FAILED);
Shyam Sundarb25ee662010-10-06 22:50:51 -07002308 return rval;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302309 }
2310
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002311 count = qla4_8xxx_rd_direct(ha, QLA8XXX_PEG_ALIVE_COUNTER);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302312 if (count != old_count)
Shyam Sundarb25ee662010-10-06 22:50:51 -07002313 peg_stuck = 0;
2314 }
2315
2316 if (need_reset) {
2317 /* We are trying to perform a recovery here. */
2318 if (peg_stuck)
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002319 ha->isp_ops->rom_lock_recovery(ha);
Shyam Sundarb25ee662010-10-06 22:50:51 -07002320 goto dev_initialize;
2321 } else {
2322 /* Start of day for this ha context. */
2323 if (peg_stuck) {
2324 /* Either we are the first or recovery in progress. */
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002325 ha->isp_ops->rom_lock_recovery(ha);
Shyam Sundarb25ee662010-10-06 22:50:51 -07002326 goto dev_initialize;
2327 } else {
2328 /* Firmware already running. */
2329 rval = QLA_SUCCESS;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302330 goto dev_ready;
Shyam Sundarb25ee662010-10-06 22:50:51 -07002331 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302332 }
2333
2334dev_initialize:
2335 /* set to DEV_INITIALIZING */
2336 ql4_printk(KERN_INFO, ha, "HW State: INITIALIZING\n");
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002337 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
2338 QLA8XXX_DEV_INITIALIZING);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302339
2340 /* Driver that sets device state to initializating sets IDC version */
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002341 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DRV_IDC_VERSION,
2342 QLA82XX_IDC_VERSION);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302343
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002344 ha->isp_ops->idc_unlock(ha);
Tej Parkash068237c82012-05-18 04:41:44 -04002345 if (ql4xenablemd && test_bit(AF_FW_RECOVERY, &ha->flags) &&
2346 !test_and_set_bit(AF_82XX_FW_DUMPED, &ha->flags)) {
2347 if (!qla4_8xxx_collect_md_data(ha)) {
2348 qla4_8xxx_uevent_emit(ha, QL4_UEVENT_CODE_FW_DUMP);
2349 } else {
2350 ql4_printk(KERN_INFO, ha, "Unable to collect minidump\n");
2351 clear_bit(AF_82XX_FW_DUMPED, &ha->flags);
2352 }
2353 }
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002354 rval = ha->isp_ops->restart_firmware(ha);
2355 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302356
2357 if (rval != QLA_SUCCESS) {
2358 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
2359 qla4_8xxx_clear_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002360 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
2361 QLA8XXX_DEV_FAILED);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302362 return rval;
2363 }
2364
2365dev_ready:
2366 ql4_printk(KERN_INFO, ha, "HW State: READY\n");
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002367 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE, QLA8XXX_DEV_READY);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302368
Shyam Sundarb25ee662010-10-06 22:50:51 -07002369 return rval;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302370}
2371
2372/**
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002373 * qla4_82xx_need_reset_handler - Code to start reset sequence
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302374 * @ha: pointer to adapter structure
2375 *
2376 * Note: IDC lock must be held upon entry
2377 **/
2378static void
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002379qla4_82xx_need_reset_handler(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302380{
2381 uint32_t dev_state, drv_state, drv_active;
Tej Parkash068237c82012-05-18 04:41:44 -04002382 uint32_t active_mask = 0xFFFFFFFF;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302383 unsigned long reset_timeout;
2384
2385 ql4_printk(KERN_INFO, ha,
2386 "Performing ISP error recovery\n");
2387
2388 if (test_and_clear_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002389 qla4_82xx_idc_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302390 ha->isp_ops->disable_intrs(ha);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002391 qla4_82xx_idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302392 }
2393
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002394 if (!test_bit(AF_8XXX_RST_OWNER, &ha->flags)) {
Tej Parkash068237c82012-05-18 04:41:44 -04002395 DEBUG2(ql4_printk(KERN_INFO, ha,
2396 "%s(%ld): reset acknowledged\n",
2397 __func__, ha->host_no));
2398 qla4_8xxx_set_rst_ready(ha);
2399 } else {
2400 active_mask = (~(1 << (ha->func_num * 4)));
2401 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302402
2403 /* wait for 10 seconds for reset ack from all functions */
2404 reset_timeout = jiffies + (ha->nx_reset_timeout * HZ);
2405
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002406 drv_state = qla4_82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
2407 drv_active = qla4_82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302408
2409 ql4_printk(KERN_INFO, ha,
2410 "%s(%ld): drv_state = 0x%x, drv_active = 0x%x\n",
2411 __func__, ha->host_no, drv_state, drv_active);
2412
Tej Parkash068237c82012-05-18 04:41:44 -04002413 while (drv_state != (drv_active & active_mask)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302414 if (time_after_eq(jiffies, reset_timeout)) {
Tej Parkash068237c82012-05-18 04:41:44 -04002415 ql4_printk(KERN_INFO, ha,
2416 "%s: RESET TIMEOUT! drv_state: 0x%08x, drv_active: 0x%08x\n",
2417 DRIVER_NAME, drv_state, drv_active);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302418 break;
2419 }
2420
Tej Parkash068237c82012-05-18 04:41:44 -04002421 /*
2422 * When reset_owner times out, check which functions
2423 * acked/did not ack
2424 */
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002425 if (test_bit(AF_8XXX_RST_OWNER, &ha->flags)) {
Tej Parkash068237c82012-05-18 04:41:44 -04002426 ql4_printk(KERN_INFO, ha,
2427 "%s(%ld): drv_state = 0x%x, drv_active = 0x%x\n",
2428 __func__, ha->host_no, drv_state,
2429 drv_active);
2430 }
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002431 qla4_82xx_idc_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302432 msleep(1000);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002433 qla4_82xx_idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302434
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002435 drv_state = qla4_82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
2436 drv_active = qla4_82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302437 }
2438
Tej Parkash068237c82012-05-18 04:41:44 -04002439 /* Clear RESET OWNER as we are not going to use it any further */
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002440 clear_bit(AF_8XXX_RST_OWNER, &ha->flags);
Tej Parkash068237c82012-05-18 04:41:44 -04002441
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002442 dev_state = qla4_82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
Tej Parkash068237c82012-05-18 04:41:44 -04002443 ql4_printk(KERN_INFO, ha, "Device state is 0x%x = %s\n", dev_state,
2444 dev_state < MAX_STATES ? qdev_state[dev_state] : "Unknown");
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302445
2446 /* Force to DEV_COLD unless someone else is starting a reset */
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002447 if (dev_state != QLA8XXX_DEV_INITIALIZING) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302448 ql4_printk(KERN_INFO, ha, "HW State: COLD/RE-INIT\n");
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002449 qla4_82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA8XXX_DEV_COLD);
Tej Parkash068237c82012-05-18 04:41:44 -04002450 qla4_8xxx_set_rst_ready(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302451 }
2452}
2453
2454/**
2455 * qla4_8xxx_need_qsnt_handler - Code to start qsnt
2456 * @ha: pointer to adapter structure
2457 **/
2458void
2459qla4_8xxx_need_qsnt_handler(struct scsi_qla_host *ha)
2460{
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002461 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302462 qla4_8xxx_set_qsnt_ready(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002463 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302464}
2465
2466/**
2467 * qla4_8xxx_device_state_handler - Adapter state machine
2468 * @ha: pointer to host adapter structure.
2469 *
2470 * Note: IDC lock must be UNLOCKED upon entry
2471 **/
2472int qla4_8xxx_device_state_handler(struct scsi_qla_host *ha)
2473{
2474 uint32_t dev_state;
2475 int rval = QLA_SUCCESS;
2476 unsigned long dev_init_timeout;
2477
Nilesh Javalie3f37d12011-12-01 22:42:11 -08002478 if (!test_bit(AF_INIT_DONE, &ha->flags)) {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002479 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302480 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002481 ha->isp_ops->idc_unlock(ha);
Nilesh Javalie3f37d12011-12-01 22:42:11 -08002482 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302483
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002484 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
Tej Parkash068237c82012-05-18 04:41:44 -04002485 DEBUG2(ql4_printk(KERN_INFO, ha, "Device state is 0x%x = %s\n",
2486 dev_state, dev_state < MAX_STATES ?
2487 qdev_state[dev_state] : "Unknown"));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302488
2489 /* wait for 30 seconds for device to go ready */
2490 dev_init_timeout = jiffies + (ha->nx_dev_init_timeout * HZ);
2491
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002492 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302493 while (1) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302494
2495 if (time_after_eq(jiffies, dev_init_timeout)) {
Tej Parkash068237c82012-05-18 04:41:44 -04002496 ql4_printk(KERN_WARNING, ha,
2497 "%s: Device Init Failed 0x%x = %s\n",
2498 DRIVER_NAME,
2499 dev_state, dev_state < MAX_STATES ?
2500 qdev_state[dev_state] : "Unknown");
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002501 qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
2502 QLA8XXX_DEV_FAILED);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302503 }
2504
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002505 dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
Tej Parkash068237c82012-05-18 04:41:44 -04002506 ql4_printk(KERN_INFO, ha, "Device state is 0x%x = %s\n",
2507 dev_state, dev_state < MAX_STATES ?
2508 qdev_state[dev_state] : "Unknown");
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302509
2510 /* NOTE: Make sure idc unlocked upon exit of switch statement */
2511 switch (dev_state) {
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002512 case QLA8XXX_DEV_READY:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302513 goto exit;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002514 case QLA8XXX_DEV_COLD:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302515 rval = qla4_8xxx_device_bootstrap(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302516 goto exit;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002517 case QLA8XXX_DEV_INITIALIZING:
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002518 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302519 msleep(1000);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002520 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302521 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002522 case QLA8XXX_DEV_NEED_RESET:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302523 if (!ql4xdontresethba) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002524 qla4_82xx_need_reset_handler(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302525 /* Update timeout value after need
2526 * reset handler */
2527 dev_init_timeout = jiffies +
2528 (ha->nx_dev_init_timeout * HZ);
Mike Hernandez9acf7532011-12-01 22:42:07 -08002529 } else {
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002530 ha->isp_ops->idc_unlock(ha);
Mike Hernandez9acf7532011-12-01 22:42:07 -08002531 msleep(1000);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002532 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302533 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302534 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002535 case QLA8XXX_DEV_NEED_QUIESCENT:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302536 /* idc locked/unlocked in handler */
2537 qla4_8xxx_need_qsnt_handler(ha);
Nilesh Javalie3f37d12011-12-01 22:42:11 -08002538 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002539 case QLA8XXX_DEV_QUIESCENT:
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002540 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302541 msleep(1000);
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002542 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302543 break;
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002544 case QLA8XXX_DEV_FAILED:
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002545 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302546 qla4xxx_dead_adapter_cleanup(ha);
2547 rval = QLA_ERROR;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002548 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302549 goto exit;
2550 default:
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002551 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302552 qla4xxx_dead_adapter_cleanup(ha);
2553 rval = QLA_ERROR;
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002554 ha->isp_ops->idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302555 goto exit;
2556 }
2557 }
2558exit:
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002559 ha->isp_ops->idc_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302560 return rval;
2561}
2562
2563int qla4_8xxx_load_risc(struct scsi_qla_host *ha)
2564{
2565 int retval;
Sarang Radke78764992012-01-11 02:44:18 -08002566
2567 /* clear the interrupt */
Vikas Chaudhary7664a1f2012-08-22 07:55:00 -04002568 writel(0, &ha->qla4_82xx_reg->host_int);
2569 readl(&ha->qla4_82xx_reg->host_int);
Sarang Radke78764992012-01-11 02:44:18 -08002570
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302571 retval = qla4_8xxx_device_state_handler(ha);
2572
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07002573 if (retval == QLA_SUCCESS && !test_bit(AF_INIT_DONE, &ha->flags))
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302574 retval = qla4xxx_request_irqs(ha);
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07002575
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302576 return retval;
2577}
2578
2579/*****************************************************************************/
2580/* Flash Manipulation Routines */
2581/*****************************************************************************/
2582
2583#define OPTROM_BURST_SIZE 0x1000
2584#define OPTROM_BURST_DWORDS (OPTROM_BURST_SIZE / 4)
2585
2586#define FARX_DATA_FLAG BIT_31
2587#define FARX_ACCESS_FLASH_CONF 0x7FFD0000
2588#define FARX_ACCESS_FLASH_DATA 0x7FF00000
2589
2590static inline uint32_t
2591flash_conf_addr(struct ql82xx_hw_data *hw, uint32_t faddr)
2592{
2593 return hw->flash_conf_off | faddr;
2594}
2595
2596static inline uint32_t
2597flash_data_addr(struct ql82xx_hw_data *hw, uint32_t faddr)
2598{
2599 return hw->flash_data_off | faddr;
2600}
2601
2602static uint32_t *
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002603qla4_82xx_read_flash_data(struct scsi_qla_host *ha, uint32_t *dwptr,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302604 uint32_t faddr, uint32_t length)
2605{
2606 uint32_t i;
2607 uint32_t val;
2608 int loops = 0;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002609 while ((qla4_82xx_rom_lock(ha) != 0) && (loops < 50000)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302610 udelay(100);
2611 cond_resched();
2612 loops++;
2613 }
2614 if (loops >= 50000) {
2615 ql4_printk(KERN_WARNING, ha, "ROM lock failed\n");
2616 return dwptr;
2617 }
2618
2619 /* Dword reads to flash. */
2620 for (i = 0; i < length/4; i++, faddr += 4) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002621 if (qla4_82xx_do_rom_fast_read(ha, faddr, &val)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302622 ql4_printk(KERN_WARNING, ha,
2623 "Do ROM fast read failed\n");
2624 goto done_read;
2625 }
2626 dwptr[i] = __constant_cpu_to_le32(val);
2627 }
2628
2629done_read:
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002630 qla4_82xx_rom_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302631 return dwptr;
2632}
2633
2634/**
2635 * Address and length are byte address
2636 **/
2637static uint8_t *
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002638qla4_82xx_read_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302639 uint32_t offset, uint32_t length)
2640{
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002641 qla4_82xx_read_flash_data(ha, (uint32_t *)buf, offset, length);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302642 return buf;
2643}
2644
2645static int
2646qla4_8xxx_find_flt_start(struct scsi_qla_host *ha, uint32_t *start)
2647{
2648 const char *loc, *locations[] = { "DEF", "PCI" };
2649
2650 /*
2651 * FLT-location structure resides after the last PCI region.
2652 */
2653
2654 /* Begin with sane defaults. */
2655 loc = locations[0];
2656 *start = FA_FLASH_LAYOUT_ADDR_82;
2657
2658 DEBUG2(ql4_printk(KERN_INFO, ha, "FLTL[%s] = 0x%x.\n", loc, *start));
2659 return QLA_SUCCESS;
2660}
2661
2662static void
2663qla4_8xxx_get_flt_info(struct scsi_qla_host *ha, uint32_t flt_addr)
2664{
2665 const char *loc, *locations[] = { "DEF", "FLT" };
2666 uint16_t *wptr;
2667 uint16_t cnt, chksum;
2668 uint32_t start;
2669 struct qla_flt_header *flt;
2670 struct qla_flt_region *region;
2671 struct ql82xx_hw_data *hw = &ha->hw;
2672
2673 hw->flt_region_flt = flt_addr;
2674 wptr = (uint16_t *)ha->request_ring;
2675 flt = (struct qla_flt_header *)ha->request_ring;
2676 region = (struct qla_flt_region *)&flt[1];
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002677 qla4_82xx_read_optrom_data(ha, (uint8_t *)ha->request_ring,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302678 flt_addr << 2, OPTROM_BURST_SIZE);
2679 if (*wptr == __constant_cpu_to_le16(0xffff))
2680 goto no_flash_data;
2681 if (flt->version != __constant_cpu_to_le16(1)) {
2682 DEBUG2(ql4_printk(KERN_INFO, ha, "Unsupported FLT detected: "
2683 "version=0x%x length=0x%x checksum=0x%x.\n",
2684 le16_to_cpu(flt->version), le16_to_cpu(flt->length),
2685 le16_to_cpu(flt->checksum)));
2686 goto no_flash_data;
2687 }
2688
2689 cnt = (sizeof(struct qla_flt_header) + le16_to_cpu(flt->length)) >> 1;
2690 for (chksum = 0; cnt; cnt--)
2691 chksum += le16_to_cpu(*wptr++);
2692 if (chksum) {
2693 DEBUG2(ql4_printk(KERN_INFO, ha, "Inconsistent FLT detected: "
2694 "version=0x%x length=0x%x checksum=0x%x.\n",
2695 le16_to_cpu(flt->version), le16_to_cpu(flt->length),
2696 chksum));
2697 goto no_flash_data;
2698 }
2699
2700 loc = locations[1];
2701 cnt = le16_to_cpu(flt->length) / sizeof(struct qla_flt_region);
2702 for ( ; cnt; cnt--, region++) {
2703 /* Store addresses as DWORD offsets. */
2704 start = le32_to_cpu(region->start) >> 2;
2705
2706 DEBUG3(ql4_printk(KERN_DEBUG, ha, "FLT[%02x]: start=0x%x "
2707 "end=0x%x size=0x%x.\n", le32_to_cpu(region->code), start,
2708 le32_to_cpu(region->end) >> 2, le32_to_cpu(region->size)));
2709
2710 switch (le32_to_cpu(region->code) & 0xff) {
2711 case FLT_REG_FDT:
2712 hw->flt_region_fdt = start;
2713 break;
2714 case FLT_REG_BOOT_CODE_82:
2715 hw->flt_region_boot = start;
2716 break;
2717 case FLT_REG_FW_82:
Nilesh Javali93823952011-10-07 16:55:39 -07002718 case FLT_REG_FW_82_1:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302719 hw->flt_region_fw = start;
2720 break;
2721 case FLT_REG_BOOTLOAD_82:
2722 hw->flt_region_bootload = start;
2723 break;
Manish Rangankar2a991c22011-07-25 13:48:55 -05002724 case FLT_REG_ISCSI_PARAM:
2725 hw->flt_iscsi_param = start;
2726 break;
Lalit Chandivade45494152011-10-07 16:55:42 -07002727 case FLT_REG_ISCSI_CHAP:
2728 hw->flt_region_chap = start;
2729 hw->flt_chap_size = le32_to_cpu(region->size);
2730 break;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302731 }
2732 }
2733 goto done;
2734
2735no_flash_data:
2736 /* Use hardcoded defaults. */
2737 loc = locations[0];
2738
2739 hw->flt_region_fdt = FA_FLASH_DESCR_ADDR_82;
2740 hw->flt_region_boot = FA_BOOT_CODE_ADDR_82;
2741 hw->flt_region_bootload = FA_BOOT_LOAD_ADDR_82;
2742 hw->flt_region_fw = FA_RISC_CODE_ADDR_82;
Lalit Chandivade45494152011-10-07 16:55:42 -07002743 hw->flt_region_chap = FA_FLASH_ISCSI_CHAP;
2744 hw->flt_chap_size = FA_FLASH_CHAP_SIZE;
2745
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302746done:
2747 DEBUG2(ql4_printk(KERN_INFO, ha, "FLT[%s]: flt=0x%x fdt=0x%x "
2748 "boot=0x%x bootload=0x%x fw=0x%x\n", loc, hw->flt_region_flt,
2749 hw->flt_region_fdt, hw->flt_region_boot, hw->flt_region_bootload,
2750 hw->flt_region_fw));
2751}
2752
2753static void
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002754qla4_82xx_get_fdt_info(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302755{
2756#define FLASH_BLK_SIZE_4K 0x1000
2757#define FLASH_BLK_SIZE_32K 0x8000
2758#define FLASH_BLK_SIZE_64K 0x10000
2759 const char *loc, *locations[] = { "MID", "FDT" };
2760 uint16_t cnt, chksum;
2761 uint16_t *wptr;
2762 struct qla_fdt_layout *fdt;
Vikas Chaudhary3c3e2102010-08-09 05:14:07 -07002763 uint16_t mid = 0;
2764 uint16_t fid = 0;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302765 struct ql82xx_hw_data *hw = &ha->hw;
2766
2767 hw->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2768 hw->flash_data_off = FARX_ACCESS_FLASH_DATA;
2769
2770 wptr = (uint16_t *)ha->request_ring;
2771 fdt = (struct qla_fdt_layout *)ha->request_ring;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002772 qla4_82xx_read_optrom_data(ha, (uint8_t *)ha->request_ring,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302773 hw->flt_region_fdt << 2, OPTROM_BURST_SIZE);
2774
2775 if (*wptr == __constant_cpu_to_le16(0xffff))
2776 goto no_flash_data;
2777
2778 if (fdt->sig[0] != 'Q' || fdt->sig[1] != 'L' || fdt->sig[2] != 'I' ||
2779 fdt->sig[3] != 'D')
2780 goto no_flash_data;
2781
2782 for (cnt = 0, chksum = 0; cnt < sizeof(struct qla_fdt_layout) >> 1;
2783 cnt++)
2784 chksum += le16_to_cpu(*wptr++);
2785
2786 if (chksum) {
2787 DEBUG2(ql4_printk(KERN_INFO, ha, "Inconsistent FDT detected: "
2788 "checksum=0x%x id=%c version=0x%x.\n", chksum, fdt->sig[0],
2789 le16_to_cpu(fdt->version)));
2790 goto no_flash_data;
2791 }
2792
2793 loc = locations[1];
2794 mid = le16_to_cpu(fdt->man_id);
2795 fid = le16_to_cpu(fdt->id);
2796 hw->fdt_wrt_disable = fdt->wrt_disable_bits;
2797 hw->fdt_erase_cmd = flash_conf_addr(hw, 0x0300 | fdt->erase_cmd);
2798 hw->fdt_block_size = le32_to_cpu(fdt->block_size);
2799
2800 if (fdt->unprotect_sec_cmd) {
2801 hw->fdt_unprotect_sec_cmd = flash_conf_addr(hw, 0x0300 |
2802 fdt->unprotect_sec_cmd);
2803 hw->fdt_protect_sec_cmd = fdt->protect_sec_cmd ?
2804 flash_conf_addr(hw, 0x0300 | fdt->protect_sec_cmd) :
2805 flash_conf_addr(hw, 0x0336);
2806 }
2807 goto done;
2808
2809no_flash_data:
2810 loc = locations[0];
2811 hw->fdt_block_size = FLASH_BLK_SIZE_64K;
2812done:
2813 DEBUG2(ql4_printk(KERN_INFO, ha, "FDT[%s]: (0x%x/0x%x) erase=0x%x "
2814 "pro=%x upro=%x wrtd=0x%x blk=0x%x.\n", loc, mid, fid,
2815 hw->fdt_erase_cmd, hw->fdt_protect_sec_cmd,
2816 hw->fdt_unprotect_sec_cmd, hw->fdt_wrt_disable,
2817 hw->fdt_block_size));
2818}
2819
2820static void
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002821qla4_82xx_get_idc_param(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302822{
2823#define QLA82XX_IDC_PARAM_ADDR 0x003e885c
2824 uint32_t *wptr;
2825
2826 if (!is_qla8022(ha))
2827 return;
2828 wptr = (uint32_t *)ha->request_ring;
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002829 qla4_82xx_read_optrom_data(ha, (uint8_t *)ha->request_ring,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302830 QLA82XX_IDC_PARAM_ADDR , 8);
2831
2832 if (*wptr == __constant_cpu_to_le32(0xffffffff)) {
2833 ha->nx_dev_init_timeout = ROM_DEV_INIT_TIMEOUT;
2834 ha->nx_reset_timeout = ROM_DRV_RESET_ACK_TIMEOUT;
2835 } else {
2836 ha->nx_dev_init_timeout = le32_to_cpu(*wptr++);
2837 ha->nx_reset_timeout = le32_to_cpu(*wptr);
2838 }
2839
2840 DEBUG2(ql4_printk(KERN_DEBUG, ha,
2841 "ha->nx_dev_init_timeout = %d\n", ha->nx_dev_init_timeout));
2842 DEBUG2(ql4_printk(KERN_DEBUG, ha,
2843 "ha->nx_reset_timeout = %d\n", ha->nx_reset_timeout));
2844 return;
2845}
2846
Vikas Chaudhary33693c72012-08-22 07:55:04 -04002847void qla4_82xx_queue_mbox_cmd(struct scsi_qla_host *ha, uint32_t *mbx_cmd,
2848 int in_count)
2849{
2850 int i;
2851
2852 /* Load all mailbox registers, except mailbox 0. */
2853 for (i = 1; i < in_count; i++)
2854 writel(mbx_cmd[i], &ha->qla4_82xx_reg->mailbox_in[i]);
2855
2856 /* Wakeup firmware */
2857 writel(mbx_cmd[0], &ha->qla4_82xx_reg->mailbox_in[0]);
2858 readl(&ha->qla4_82xx_reg->mailbox_in[0]);
2859 writel(HINT_MBX_INT_PENDING, &ha->qla4_82xx_reg->hint);
2860 readl(&ha->qla4_82xx_reg->hint);
2861}
2862
2863void qla4_82xx_process_mbox_intr(struct scsi_qla_host *ha, int out_count)
2864{
2865 int intr_status;
2866
2867 intr_status = readl(&ha->qla4_82xx_reg->host_int);
2868 if (intr_status & ISRX_82XX_RISC_INT) {
2869 ha->mbox_status_count = out_count;
2870 intr_status = readl(&ha->qla4_82xx_reg->host_status);
2871 ha->isp_ops->interrupt_service_routine(ha, intr_status);
2872
2873 if (test_bit(AF_INTERRUPTS_ON, &ha->flags) &&
2874 test_bit(AF_INTx_ENABLED, &ha->flags))
2875 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg,
2876 0xfbff);
2877 }
2878}
2879
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302880int
2881qla4_8xxx_get_flash_info(struct scsi_qla_host *ha)
2882{
2883 int ret;
2884 uint32_t flt_addr;
2885
2886 ret = qla4_8xxx_find_flt_start(ha, &flt_addr);
2887 if (ret != QLA_SUCCESS)
2888 return ret;
2889
2890 qla4_8xxx_get_flt_info(ha, flt_addr);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002891 qla4_82xx_get_fdt_info(ha);
2892 qla4_82xx_get_idc_param(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302893
2894 return QLA_SUCCESS;
2895}
2896
2897/**
2898 * qla4_8xxx_stop_firmware - stops firmware on specified adapter instance
2899 * @ha: pointer to host adapter structure.
2900 *
2901 * Remarks:
2902 * For iSCSI, throws away all I/O and AENs into bit bucket, so they will
2903 * not be available after successful return. Driver must cleanup potential
2904 * outstanding I/O's after calling this funcion.
2905 **/
2906int
2907qla4_8xxx_stop_firmware(struct scsi_qla_host *ha)
2908{
2909 int status;
2910 uint32_t mbox_cmd[MBOX_REG_COUNT];
2911 uint32_t mbox_sts[MBOX_REG_COUNT];
2912
2913 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2914 memset(&mbox_sts, 0, sizeof(mbox_sts));
2915
2916 mbox_cmd[0] = MBOX_CMD_STOP_FW;
2917 status = qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1,
2918 &mbox_cmd[0], &mbox_sts[0]);
2919
2920 DEBUG2(printk("scsi%ld: %s: status = %d\n", ha->host_no,
2921 __func__, status));
2922 return status;
2923}
2924
2925/**
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002926 * qla4_82xx_isp_reset - Resets ISP and aborts all outstanding commands.
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302927 * @ha: pointer to host adapter structure.
2928 **/
2929int
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002930qla4_82xx_isp_reset(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302931{
2932 int rval;
2933 uint32_t dev_state;
2934
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002935 qla4_82xx_idc_lock(ha);
2936 dev_state = qla4_82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302937
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002938 if (dev_state == QLA8XXX_DEV_READY) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302939 ql4_printk(KERN_INFO, ha, "HW State: NEED RESET\n");
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002940 qla4_82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
Vikas Chaudharyde8c72d2012-08-22 09:14:24 -04002941 QLA8XXX_DEV_NEED_RESET);
2942 set_bit(AF_8XXX_RST_OWNER, &ha->flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302943 } else
2944 ql4_printk(KERN_INFO, ha, "HW State: DEVICE INITIALIZING\n");
2945
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002946 qla4_82xx_idc_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302947
2948 rval = qla4_8xxx_device_state_handler(ha);
2949
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002950 qla4_82xx_idc_lock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302951 qla4_8xxx_clear_rst_ready(ha);
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002952 qla4_82xx_idc_unlock(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302953
Tej Parkash068237c82012-05-18 04:41:44 -04002954 if (rval == QLA_SUCCESS) {
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04002955 ql4_printk(KERN_INFO, ha, "Clearing AF_RECOVERY in qla4_82xx_isp_reset\n");
Nilesh Javali21033632010-07-30 14:28:07 +05302956 clear_bit(AF_FW_RECOVERY, &ha->flags);
Tej Parkash068237c82012-05-18 04:41:44 -04002957 }
Nilesh Javali21033632010-07-30 14:28:07 +05302958
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302959 return rval;
2960}
2961
2962/**
2963 * qla4_8xxx_get_sys_info - get adapter MAC address(es) and serial number
2964 * @ha: pointer to host adapter structure.
2965 *
2966 **/
2967int qla4_8xxx_get_sys_info(struct scsi_qla_host *ha)
2968{
2969 uint32_t mbox_cmd[MBOX_REG_COUNT];
2970 uint32_t mbox_sts[MBOX_REG_COUNT];
2971 struct mbx_sys_info *sys_info;
2972 dma_addr_t sys_info_dma;
2973 int status = QLA_ERROR;
2974
2975 sys_info = dma_alloc_coherent(&ha->pdev->dev, sizeof(*sys_info),
2976 &sys_info_dma, GFP_KERNEL);
2977 if (sys_info == NULL) {
2978 DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
2979 ha->host_no, __func__));
2980 return status;
2981 }
2982
2983 memset(sys_info, 0, sizeof(*sys_info));
2984 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
2985 memset(&mbox_sts, 0, sizeof(mbox_sts));
2986
2987 mbox_cmd[0] = MBOX_CMD_GET_SYS_INFO;
2988 mbox_cmd[1] = LSDW(sys_info_dma);
2989 mbox_cmd[2] = MSDW(sys_info_dma);
2990 mbox_cmd[4] = sizeof(*sys_info);
2991
2992 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 6, &mbox_cmd[0],
2993 &mbox_sts[0]) != QLA_SUCCESS) {
2994 DEBUG2(printk("scsi%ld: %s: GET_SYS_INFO failed\n",
2995 ha->host_no, __func__));
2996 goto exit_validate_mac82;
2997 }
2998
Vikas Chaudhary2ccdf0d2010-07-30 14:27:45 +05302999 /* Make sure we receive the minimum required data to cache internally */
3000 if (mbox_sts[4] < offsetof(struct mbx_sys_info, reserved)) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303001 DEBUG2(printk("scsi%ld: %s: GET_SYS_INFO data receive"
3002 " error (%x)\n", ha->host_no, __func__, mbox_sts[4]));
3003 goto exit_validate_mac82;
3004
3005 }
3006
3007 /* Save M.A.C. address & serial_number */
Manish Rangankar2a991c22011-07-25 13:48:55 -05003008 ha->port_num = sys_info->port_num;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303009 memcpy(ha->my_mac, &sys_info->mac_addr[0],
3010 min(sizeof(ha->my_mac), sizeof(sys_info->mac_addr)));
3011 memcpy(ha->serial_number, &sys_info->serial_number,
3012 min(sizeof(ha->serial_number), sizeof(sys_info->serial_number)));
Vikas Chaudhary91ec7ce2011-08-01 03:26:17 -07003013 memcpy(ha->model_name, &sys_info->board_id_str,
3014 min(sizeof(ha->model_name), sizeof(sys_info->board_id_str)));
3015 ha->phy_port_cnt = sys_info->phys_port_cnt;
3016 ha->phy_port_num = sys_info->port_num;
3017 ha->iscsi_pci_func_cnt = sys_info->iscsi_pci_func_cnt;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303018
3019 DEBUG2(printk("scsi%ld: %s: "
3020 "mac %02x:%02x:%02x:%02x:%02x:%02x "
3021 "serial %s\n", ha->host_no, __func__,
3022 ha->my_mac[0], ha->my_mac[1], ha->my_mac[2],
3023 ha->my_mac[3], ha->my_mac[4], ha->my_mac[5],
3024 ha->serial_number));
3025
3026 status = QLA_SUCCESS;
3027
3028exit_validate_mac82:
3029 dma_free_coherent(&ha->pdev->dev, sizeof(*sys_info), sys_info,
3030 sys_info_dma);
3031 return status;
3032}
3033
3034/* Interrupt handling helpers. */
3035
3036static int
3037qla4_8xxx_mbx_intr_enable(struct scsi_qla_host *ha)
3038{
3039 uint32_t mbox_cmd[MBOX_REG_COUNT];
3040 uint32_t mbox_sts[MBOX_REG_COUNT];
3041
3042 DEBUG2(ql4_printk(KERN_INFO, ha, "%s\n", __func__));
3043
3044 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
3045 memset(&mbox_sts, 0, sizeof(mbox_sts));
3046 mbox_cmd[0] = MBOX_CMD_ENABLE_INTRS;
3047 mbox_cmd[1] = INTR_ENABLE;
3048 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
3049 &mbox_sts[0]) != QLA_SUCCESS) {
3050 DEBUG2(ql4_printk(KERN_INFO, ha,
3051 "%s: MBOX_CMD_ENABLE_INTRS failed (0x%04x)\n",
3052 __func__, mbox_sts[0]));
3053 return QLA_ERROR;
3054 }
3055 return QLA_SUCCESS;
3056}
3057
3058static int
3059qla4_8xxx_mbx_intr_disable(struct scsi_qla_host *ha)
3060{
3061 uint32_t mbox_cmd[MBOX_REG_COUNT];
3062 uint32_t mbox_sts[MBOX_REG_COUNT];
3063
3064 DEBUG2(ql4_printk(KERN_INFO, ha, "%s\n", __func__));
3065
3066 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
3067 memset(&mbox_sts, 0, sizeof(mbox_sts));
3068 mbox_cmd[0] = MBOX_CMD_ENABLE_INTRS;
3069 mbox_cmd[1] = INTR_DISABLE;
3070 if (qla4xxx_mailbox_command(ha, MBOX_REG_COUNT, 1, &mbox_cmd[0],
3071 &mbox_sts[0]) != QLA_SUCCESS) {
3072 DEBUG2(ql4_printk(KERN_INFO, ha,
3073 "%s: MBOX_CMD_ENABLE_INTRS failed (0x%04x)\n",
3074 __func__, mbox_sts[0]));
3075 return QLA_ERROR;
3076 }
3077
3078 return QLA_SUCCESS;
3079}
3080
3081void
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04003082qla4_82xx_enable_intrs(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303083{
3084 qla4_8xxx_mbx_intr_enable(ha);
3085
3086 spin_lock_irq(&ha->hardware_lock);
3087 /* BIT 10 - reset */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04003088 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303089 spin_unlock_irq(&ha->hardware_lock);
3090 set_bit(AF_INTERRUPTS_ON, &ha->flags);
3091}
3092
3093void
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04003094qla4_82xx_disable_intrs(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303095{
Sarang Radke5fa8b572011-03-23 08:07:33 -07003096 if (test_and_clear_bit(AF_INTERRUPTS_ON, &ha->flags))
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303097 qla4_8xxx_mbx_intr_disable(ha);
3098
3099 spin_lock_irq(&ha->hardware_lock);
3100 /* BIT 10 - set */
Vikas Chaudharyf8086f42012-08-22 07:54:59 -04003101 qla4_82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0x0400);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303102 spin_unlock_irq(&ha->hardware_lock);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303103}
3104
3105struct ql4_init_msix_entry {
3106 uint16_t entry;
3107 uint16_t index;
3108 const char *name;
3109 irq_handler_t handler;
3110};
3111
3112static struct ql4_init_msix_entry qla4_8xxx_msix_entries[QLA_MSIX_ENTRIES] = {
3113 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
3114 "qla4xxx (default)",
3115 (irq_handler_t)qla4_8xxx_default_intr_handler },
3116 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
3117 "qla4xxx (rsp_q)", (irq_handler_t)qla4_8xxx_msix_rsp_q },
3118};
3119
3120void
3121qla4_8xxx_disable_msix(struct scsi_qla_host *ha)
3122{
3123 int i;
3124 struct ql4_msix_entry *qentry;
3125
3126 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
3127 qentry = &ha->msix_entries[qla4_8xxx_msix_entries[i].index];
3128 if (qentry->have_irq) {
3129 free_irq(qentry->msix_vector, ha);
3130 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %s\n",
3131 __func__, qla4_8xxx_msix_entries[i].name));
3132 }
3133 }
3134 pci_disable_msix(ha->pdev);
3135 clear_bit(AF_MSIX_ENABLED, &ha->flags);
3136}
3137
3138int
3139qla4_8xxx_enable_msix(struct scsi_qla_host *ha)
3140{
3141 int i, ret;
3142 struct msix_entry entries[QLA_MSIX_ENTRIES];
3143 struct ql4_msix_entry *qentry;
3144
3145 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
3146 entries[i].entry = qla4_8xxx_msix_entries[i].entry;
3147
3148 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
3149 if (ret) {
3150 ql4_printk(KERN_WARNING, ha,
3151 "MSI-X: Failed to enable support -- %d/%d\n",
3152 QLA_MSIX_ENTRIES, ret);
3153 goto msix_out;
3154 }
3155 set_bit(AF_MSIX_ENABLED, &ha->flags);
3156
3157 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
3158 qentry = &ha->msix_entries[qla4_8xxx_msix_entries[i].index];
3159 qentry->msix_vector = entries[i].vector;
3160 qentry->msix_entry = entries[i].entry;
3161 qentry->have_irq = 0;
3162 ret = request_irq(qentry->msix_vector,
3163 qla4_8xxx_msix_entries[i].handler, 0,
3164 qla4_8xxx_msix_entries[i].name, ha);
3165 if (ret) {
3166 ql4_printk(KERN_WARNING, ha,
3167 "MSI-X: Unable to register handler -- %x/%d.\n",
3168 qla4_8xxx_msix_entries[i].index, ret);
3169 qla4_8xxx_disable_msix(ha);
3170 goto msix_out;
3171 }
3172 qentry->have_irq = 1;
3173 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %s\n",
3174 __func__, qla4_8xxx_msix_entries[i].name));
3175 }
3176msix_out:
3177 return ret;
3178}