2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
8 #include <linux/delay.h>
10 #include <linux/ratelimit.h>
11 #include <linux/vmalloc.h>
12 #include <scsi/scsi_tcq.h>
13 #include <asm/unaligned.h>
15 #define MASK(n) ((1ULL<<(n))-1)
16 #define MN_WIN(addr) (((addr & 0x1fc0000) >> 1) | \
17 ((addr >> 25) & 0x3ff))
18 #define OCM_WIN(addr) (((addr & 0x1ff0000) >> 1) | \
19 ((addr >> 25) & 0x3ff))
20 #define MS_WIN(addr) (addr & 0x0ffc0000)
21 #define QLA82XX_PCI_MN_2M (0)
22 #define QLA82XX_PCI_MS_2M (0x80000)
23 #define QLA82XX_PCI_OCM0_2M (0xc0000)
24 #define VALID_OCM_ADDR(addr) (((addr) & 0x3f800) != 0x3f800)
25 #define GET_MEM_OFFS_2M(addr) (addr & MASK(18))
26 #define BLOCK_PROTECT_BITS 0x0F
28 /* CRB window related */
29 #define CRB_BLK(off) ((off >> 20) & 0x3f)
30 #define CRB_SUBBLK(off) ((off >> 16) & 0xf)
31 #define CRB_WINDOW_2M (0x130060)
32 #define QLA82XX_PCI_CAMQM_2M_END (0x04800800UL)
33 #define CRB_HI(off) ((qla82xx_crb_hub_agt[CRB_BLK(off)] << 20) | \
35 #define QLA82XX_PCI_CAMQM_2M_BASE (0x000ff800UL)
36 #define CRB_INDIRECT_2M (0x1e0000UL)
38 #define MAX_CRB_XFORM 60
39 static unsigned long crb_addr_xform[MAX_CRB_XFORM];
40 static int qla82xx_crb_table_initialized;
42 #define qla82xx_crb_addr_transform(name) \
43 (crb_addr_xform[QLA82XX_HW_PX_MAP_CRB_##name] = \
44 QLA82XX_HW_CRB_HUB_AGT_ADR_##name << 20)
46 static void qla82xx_crb_addr_transform_setup(void)
48 qla82xx_crb_addr_transform(XDMA);
49 qla82xx_crb_addr_transform(TIMR);
50 qla82xx_crb_addr_transform(SRE);
51 qla82xx_crb_addr_transform(SQN3);
52 qla82xx_crb_addr_transform(SQN2);
53 qla82xx_crb_addr_transform(SQN1);
54 qla82xx_crb_addr_transform(SQN0);
55 qla82xx_crb_addr_transform(SQS3);
56 qla82xx_crb_addr_transform(SQS2);
57 qla82xx_crb_addr_transform(SQS1);
58 qla82xx_crb_addr_transform(SQS0);
59 qla82xx_crb_addr_transform(RPMX7);
60 qla82xx_crb_addr_transform(RPMX6);
61 qla82xx_crb_addr_transform(RPMX5);
62 qla82xx_crb_addr_transform(RPMX4);
63 qla82xx_crb_addr_transform(RPMX3);
64 qla82xx_crb_addr_transform(RPMX2);
65 qla82xx_crb_addr_transform(RPMX1);
66 qla82xx_crb_addr_transform(RPMX0);
67 qla82xx_crb_addr_transform(ROMUSB);
68 qla82xx_crb_addr_transform(SN);
69 qla82xx_crb_addr_transform(QMN);
70 qla82xx_crb_addr_transform(QMS);
71 qla82xx_crb_addr_transform(PGNI);
72 qla82xx_crb_addr_transform(PGND);
73 qla82xx_crb_addr_transform(PGN3);
74 qla82xx_crb_addr_transform(PGN2);
75 qla82xx_crb_addr_transform(PGN1);
76 qla82xx_crb_addr_transform(PGN0);
77 qla82xx_crb_addr_transform(PGSI);
78 qla82xx_crb_addr_transform(PGSD);
79 qla82xx_crb_addr_transform(PGS3);
80 qla82xx_crb_addr_transform(PGS2);
81 qla82xx_crb_addr_transform(PGS1);
82 qla82xx_crb_addr_transform(PGS0);
83 qla82xx_crb_addr_transform(PS);
84 qla82xx_crb_addr_transform(PH);
85 qla82xx_crb_addr_transform(NIU);
86 qla82xx_crb_addr_transform(I2Q);
87 qla82xx_crb_addr_transform(EG);
88 qla82xx_crb_addr_transform(MN);
89 qla82xx_crb_addr_transform(MS);
90 qla82xx_crb_addr_transform(CAS2);
91 qla82xx_crb_addr_transform(CAS1);
92 qla82xx_crb_addr_transform(CAS0);
93 qla82xx_crb_addr_transform(CAM);
94 qla82xx_crb_addr_transform(C2C1);
95 qla82xx_crb_addr_transform(C2C0);
96 qla82xx_crb_addr_transform(SMB);
97 qla82xx_crb_addr_transform(OCM0);
99 * Used only in P3 just define it for P2 also.
101 qla82xx_crb_addr_transform(I2C0);
103 qla82xx_crb_table_initialized = 1;
106 static struct crb_128M_2M_block_map crb_128M_2M_map[64] = {
108 {{{1, 0x0100000, 0x0102000, 0x120000},
109 {1, 0x0110000, 0x0120000, 0x130000},
110 {1, 0x0120000, 0x0122000, 0x124000},
111 {1, 0x0130000, 0x0132000, 0x126000},
112 {1, 0x0140000, 0x0142000, 0x128000},
113 {1, 0x0150000, 0x0152000, 0x12a000},
114 {1, 0x0160000, 0x0170000, 0x110000},
115 {1, 0x0170000, 0x0172000, 0x12e000},
116 {0, 0x0000000, 0x0000000, 0x000000},
117 {0, 0x0000000, 0x0000000, 0x000000},
118 {0, 0x0000000, 0x0000000, 0x000000},
119 {0, 0x0000000, 0x0000000, 0x000000},
120 {0, 0x0000000, 0x0000000, 0x000000},
121 {0, 0x0000000, 0x0000000, 0x000000},
122 {1, 0x01e0000, 0x01e0800, 0x122000},
123 {0, 0x0000000, 0x0000000, 0x000000} } } ,
124 {{{1, 0x0200000, 0x0210000, 0x180000} } },
126 {{{1, 0x0400000, 0x0401000, 0x169000} } },
127 {{{1, 0x0500000, 0x0510000, 0x140000} } },
128 {{{1, 0x0600000, 0x0610000, 0x1c0000} } },
129 {{{1, 0x0700000, 0x0704000, 0x1b8000} } },
130 {{{1, 0x0800000, 0x0802000, 0x170000},
131 {0, 0x0000000, 0x0000000, 0x000000},
132 {0, 0x0000000, 0x0000000, 0x000000},
133 {0, 0x0000000, 0x0000000, 0x000000},
134 {0, 0x0000000, 0x0000000, 0x000000},
135 {0, 0x0000000, 0x0000000, 0x000000},
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 {1, 0x08f0000, 0x08f2000, 0x172000} } },
146 {{{1, 0x0900000, 0x0902000, 0x174000},
147 {0, 0x0000000, 0x0000000, 0x000000},
148 {0, 0x0000000, 0x0000000, 0x000000},
149 {0, 0x0000000, 0x0000000, 0x000000},
150 {0, 0x0000000, 0x0000000, 0x000000},
151 {0, 0x0000000, 0x0000000, 0x000000},
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 {1, 0x09f0000, 0x09f2000, 0x176000} } },
162 {{{0, 0x0a00000, 0x0a02000, 0x178000},
163 {0, 0x0000000, 0x0000000, 0x000000},
164 {0, 0x0000000, 0x0000000, 0x000000},
165 {0, 0x0000000, 0x0000000, 0x000000},
166 {0, 0x0000000, 0x0000000, 0x000000},
167 {0, 0x0000000, 0x0000000, 0x000000},
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 {1, 0x0af0000, 0x0af2000, 0x17a000} } },
178 {{{0, 0x0b00000, 0x0b02000, 0x17c000},
179 {0, 0x0000000, 0x0000000, 0x000000},
180 {0, 0x0000000, 0x0000000, 0x000000},
181 {0, 0x0000000, 0x0000000, 0x000000},
182 {0, 0x0000000, 0x0000000, 0x000000},
183 {0, 0x0000000, 0x0000000, 0x000000},
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 {1, 0x0bf0000, 0x0bf2000, 0x17e000} } },
194 {{{1, 0x0c00000, 0x0c04000, 0x1d4000} } },
195 {{{1, 0x0d00000, 0x0d04000, 0x1a4000} } },
196 {{{1, 0x0e00000, 0x0e04000, 0x1a0000} } },
197 {{{1, 0x0f00000, 0x0f01000, 0x164000} } },
198 {{{0, 0x1000000, 0x1004000, 0x1a8000} } },
199 {{{1, 0x1100000, 0x1101000, 0x160000} } },
200 {{{1, 0x1200000, 0x1201000, 0x161000} } },
201 {{{1, 0x1300000, 0x1301000, 0x162000} } },
202 {{{1, 0x1400000, 0x1401000, 0x163000} } },
203 {{{1, 0x1500000, 0x1501000, 0x165000} } },
204 {{{1, 0x1600000, 0x1601000, 0x166000} } },
211 {{{1, 0x1d00000, 0x1d10000, 0x190000} } },
212 {{{1, 0x1e00000, 0x1e01000, 0x16a000} } },
213 {{{1, 0x1f00000, 0x1f10000, 0x150000} } },
215 {{{1, 0x2100000, 0x2102000, 0x120000},
216 {1, 0x2110000, 0x2120000, 0x130000},
217 {1, 0x2120000, 0x2122000, 0x124000},
218 {1, 0x2130000, 0x2132000, 0x126000},
219 {1, 0x2140000, 0x2142000, 0x128000},
220 {1, 0x2150000, 0x2152000, 0x12a000},
221 {1, 0x2160000, 0x2170000, 0x110000},
222 {1, 0x2170000, 0x2172000, 0x12e000},
223 {0, 0x0000000, 0x0000000, 0x000000},
224 {0, 0x0000000, 0x0000000, 0x000000},
225 {0, 0x0000000, 0x0000000, 0x000000},
226 {0, 0x0000000, 0x0000000, 0x000000},
227 {0, 0x0000000, 0x0000000, 0x000000},
228 {0, 0x0000000, 0x0000000, 0x000000},
229 {0, 0x0000000, 0x0000000, 0x000000},
230 {0, 0x0000000, 0x0000000, 0x000000} } },
231 {{{1, 0x2200000, 0x2204000, 0x1b0000} } },
237 {{{1, 0x2800000, 0x2804000, 0x1a4000} } },
238 {{{1, 0x2900000, 0x2901000, 0x16b000} } },
239 {{{1, 0x2a00000, 0x2a00400, 0x1ac400} } },
240 {{{1, 0x2b00000, 0x2b00400, 0x1ac800} } },
241 {{{1, 0x2c00000, 0x2c00400, 0x1acc00} } },
242 {{{1, 0x2d00000, 0x2d00400, 0x1ad000} } },
243 {{{1, 0x2e00000, 0x2e00400, 0x1ad400} } },
244 {{{1, 0x2f00000, 0x2f00400, 0x1ad800} } },
245 {{{1, 0x3000000, 0x3000400, 0x1adc00} } },
246 {{{0, 0x3100000, 0x3104000, 0x1a8000} } },
247 {{{1, 0x3200000, 0x3204000, 0x1d4000} } },
248 {{{1, 0x3300000, 0x3304000, 0x1a0000} } },
250 {{{1, 0x3500000, 0x3500400, 0x1ac000} } },
251 {{{1, 0x3600000, 0x3600400, 0x1ae000} } },
252 {{{1, 0x3700000, 0x3700400, 0x1ae400} } },
253 {{{1, 0x3800000, 0x3804000, 0x1d0000} } },
254 {{{1, 0x3900000, 0x3904000, 0x1b4000} } },
255 {{{1, 0x3a00000, 0x3a04000, 0x1d8000} } },
258 {{{1, 0x3d00000, 0x3d04000, 0x1dc000} } },
259 {{{1, 0x3e00000, 0x3e01000, 0x167000} } },
260 {{{1, 0x3f00000, 0x3f01000, 0x168000} } }
264 * top 12 bits of crb internal address (hub, agent)
266 static unsigned qla82xx_crb_hub_agt[64] = {
268 QLA82XX_HW_CRB_HUB_AGT_ADR_PS,
269 QLA82XX_HW_CRB_HUB_AGT_ADR_MN,
270 QLA82XX_HW_CRB_HUB_AGT_ADR_MS,
272 QLA82XX_HW_CRB_HUB_AGT_ADR_SRE,
273 QLA82XX_HW_CRB_HUB_AGT_ADR_NIU,
274 QLA82XX_HW_CRB_HUB_AGT_ADR_QMN,
275 QLA82XX_HW_CRB_HUB_AGT_ADR_SQN0,
276 QLA82XX_HW_CRB_HUB_AGT_ADR_SQN1,
277 QLA82XX_HW_CRB_HUB_AGT_ADR_SQN2,
278 QLA82XX_HW_CRB_HUB_AGT_ADR_SQN3,
279 QLA82XX_HW_CRB_HUB_AGT_ADR_I2Q,
280 QLA82XX_HW_CRB_HUB_AGT_ADR_TIMR,
281 QLA82XX_HW_CRB_HUB_AGT_ADR_ROMUSB,
282 QLA82XX_HW_CRB_HUB_AGT_ADR_PGN4,
283 QLA82XX_HW_CRB_HUB_AGT_ADR_XDMA,
284 QLA82XX_HW_CRB_HUB_AGT_ADR_PGN0,
285 QLA82XX_HW_CRB_HUB_AGT_ADR_PGN1,
286 QLA82XX_HW_CRB_HUB_AGT_ADR_PGN2,
287 QLA82XX_HW_CRB_HUB_AGT_ADR_PGN3,
288 QLA82XX_HW_CRB_HUB_AGT_ADR_PGND,
289 QLA82XX_HW_CRB_HUB_AGT_ADR_PGNI,
290 QLA82XX_HW_CRB_HUB_AGT_ADR_PGS0,
291 QLA82XX_HW_CRB_HUB_AGT_ADR_PGS1,
292 QLA82XX_HW_CRB_HUB_AGT_ADR_PGS2,
293 QLA82XX_HW_CRB_HUB_AGT_ADR_PGS3,
295 QLA82XX_HW_CRB_HUB_AGT_ADR_PGSI,
296 QLA82XX_HW_CRB_HUB_AGT_ADR_SN,
298 QLA82XX_HW_CRB_HUB_AGT_ADR_EG,
300 QLA82XX_HW_CRB_HUB_AGT_ADR_PS,
301 QLA82XX_HW_CRB_HUB_AGT_ADR_CAM,
307 QLA82XX_HW_CRB_HUB_AGT_ADR_TIMR,
309 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX1,
310 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX2,
311 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX3,
312 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX4,
313 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX5,
314 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX6,
315 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX7,
316 QLA82XX_HW_CRB_HUB_AGT_ADR_XDMA,
317 QLA82XX_HW_CRB_HUB_AGT_ADR_I2Q,
318 QLA82XX_HW_CRB_HUB_AGT_ADR_ROMUSB,
320 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX0,
321 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX8,
322 QLA82XX_HW_CRB_HUB_AGT_ADR_RPMX9,
323 QLA82XX_HW_CRB_HUB_AGT_ADR_OCM0,
325 QLA82XX_HW_CRB_HUB_AGT_ADR_SMB,
326 QLA82XX_HW_CRB_HUB_AGT_ADR_I2C0,
327 QLA82XX_HW_CRB_HUB_AGT_ADR_I2C1,
329 QLA82XX_HW_CRB_HUB_AGT_ADR_PGNC,
334 static char *q_dev_state[] = {
345 char *qdev_state(uint32_t dev_state)
347 return q_dev_state[dev_state];
351 * In: 'off_in' is offset from CRB space in 128M pci map
352 * Out: 'off_out' is 2M pci map addr
353 * side effect: lock crb window
356 qla82xx_pci_set_crbwindow_2M(struct qla_hw_data *ha, ulong off_in,
357 void __iomem **off_out)
360 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
362 ha->crb_win = CRB_HI(off_in);
363 writel(ha->crb_win, CRB_WINDOW_2M + ha->nx_pcibase);
365 /* Read back value to make sure write has gone through before trying
368 win_read = RD_REG_DWORD(CRB_WINDOW_2M + ha->nx_pcibase);
369 if (win_read != ha->crb_win) {
370 ql_dbg(ql_dbg_p3p, vha, 0xb000,
371 "%s: Written crbwin (0x%x) "
372 "!= Read crbwin (0x%x), off=0x%lx.\n",
373 __func__, ha->crb_win, win_read, off_in);
375 *off_out = (off_in & MASK(16)) + CRB_INDIRECT_2M + ha->nx_pcibase;
378 static inline unsigned long
379 qla82xx_pci_set_crbwindow(struct qla_hw_data *ha, u64 off)
381 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
382 /* See if we are currently pointing to the region we want to use next */
383 if ((off >= QLA82XX_CRB_PCIX_HOST) && (off < QLA82XX_CRB_DDR_NET)) {
384 /* No need to change window. PCIX and PCIEregs are in both
385 * regs are in both windows.
390 if ((off >= QLA82XX_CRB_PCIX_HOST) && (off < QLA82XX_CRB_PCIX_HOST2)) {
391 /* We are in first CRB window */
392 if (ha->curr_window != 0)
397 if ((off > QLA82XX_CRB_PCIX_HOST2) && (off < QLA82XX_CRB_MAX)) {
398 /* We are in second CRB window */
399 off = off - QLA82XX_CRB_PCIX_HOST2 + QLA82XX_CRB_PCIX_HOST;
401 if (ha->curr_window != 1)
404 /* We are in the QM or direct access
405 * register region - do nothing
407 if ((off >= QLA82XX_PCI_DIRECT_CRB) &&
408 (off < QLA82XX_PCI_CAMQM_MAX))
411 /* strange address given */
412 ql_dbg(ql_dbg_p3p, vha, 0xb001,
413 "%s: Warning: unm_nic_pci_set_crbwindow "
414 "called with an unknown address(%llx).\n",
415 QLA2XXX_DRIVER_NAME, off);
420 qla82xx_pci_get_crb_addr_2M(struct qla_hw_data *ha, ulong off_in,
421 void __iomem **off_out)
423 struct crb_128M_2M_sub_block_map *m;
425 if (off_in >= QLA82XX_CRB_MAX)
428 if (off_in >= QLA82XX_PCI_CAMQM && off_in < QLA82XX_PCI_CAMQM_2M_END) {
429 *off_out = (off_in - QLA82XX_PCI_CAMQM) +
430 QLA82XX_PCI_CAMQM_2M_BASE + ha->nx_pcibase;
434 if (off_in < QLA82XX_PCI_CRBSPACE)
437 off_in -= QLA82XX_PCI_CRBSPACE;
440 m = &crb_128M_2M_map[CRB_BLK(off_in)].sub_block[CRB_SUBBLK(off_in)];
442 if (m->valid && (m->start_128M <= off_in) && (m->end_128M > off_in)) {
443 *off_out = off_in + m->start_2M - m->start_128M + ha->nx_pcibase;
446 /* Not in direct map, use crb window */
447 *off_out = (void __iomem *)off_in;
451 #define CRB_WIN_LOCK_TIMEOUT 100000000
452 static int qla82xx_crb_win_lock(struct qla_hw_data *ha)
454 int done = 0, timeout = 0;
457 /* acquire semaphore3 from PCI HW block */
458 done = qla82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_LOCK));
461 if (timeout >= CRB_WIN_LOCK_TIMEOUT)
465 qla82xx_wr_32(ha, QLA82XX_CRB_WIN_LOCK_ID, ha->portnum);
470 qla82xx_wr_32(struct qla_hw_data *ha, ulong off_in, u32 data)
473 unsigned long flags = 0;
476 rv = qla82xx_pci_get_crb_addr_2M(ha, off_in, &off);
482 write_lock_irqsave(&ha->hw_lock, flags);
484 qla82xx_crb_win_lock(ha);
485 qla82xx_pci_set_crbwindow_2M(ha, off_in, &off);
488 writel(data, (void __iomem *)off);
491 qla82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_UNLOCK));
493 write_unlock_irqrestore(&ha->hw_lock, flags);
500 qla82xx_rd_32(struct qla_hw_data *ha, ulong off_in)
503 unsigned long flags = 0;
507 rv = qla82xx_pci_get_crb_addr_2M(ha, off_in, &off);
513 write_lock_irqsave(&ha->hw_lock, flags);
515 qla82xx_crb_win_lock(ha);
516 qla82xx_pci_set_crbwindow_2M(ha, off_in, &off);
518 data = RD_REG_DWORD(off);
521 qla82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM7_UNLOCK));
523 write_unlock_irqrestore(&ha->hw_lock, flags);
529 #define IDC_LOCK_TIMEOUT 100000000
530 int qla82xx_idc_lock(struct qla_hw_data *ha)
533 int done = 0, timeout = 0;
536 /* acquire semaphore5 from PCI HW block */
537 done = qla82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM5_LOCK));
540 if (timeout >= IDC_LOCK_TIMEOUT)
549 for (i = 0; i < 20; i++)
557 void qla82xx_idc_unlock(struct qla_hw_data *ha)
559 qla82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM5_UNLOCK));
563 * check memory access boundary.
564 * used by test agent. support ddr access only for now
567 qla82xx_pci_mem_bound_check(struct qla_hw_data *ha,
568 unsigned long long addr, int size)
570 if (!addr_in_range(addr, QLA82XX_ADDR_DDR_NET,
571 QLA82XX_ADDR_DDR_NET_MAX) ||
572 !addr_in_range(addr + size - 1, QLA82XX_ADDR_DDR_NET,
573 QLA82XX_ADDR_DDR_NET_MAX) ||
574 ((size != 1) && (size != 2) && (size != 4) && (size != 8)))
580 static int qla82xx_pci_set_window_warning_count;
583 qla82xx_pci_set_window(struct qla_hw_data *ha, unsigned long long addr)
587 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
589 if (addr_in_range(addr, QLA82XX_ADDR_DDR_NET,
590 QLA82XX_ADDR_DDR_NET_MAX)) {
591 /* DDR network side */
592 window = MN_WIN(addr);
593 ha->ddr_mn_window = window;
595 ha->mn_win_crb | QLA82XX_PCI_CRBSPACE, window);
596 win_read = qla82xx_rd_32(ha,
597 ha->mn_win_crb | QLA82XX_PCI_CRBSPACE);
598 if ((win_read << 17) != window) {
599 ql_dbg(ql_dbg_p3p, vha, 0xb003,
600 "%s: Written MNwin (0x%x) != Read MNwin (0x%x).\n",
601 __func__, window, win_read);
603 addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_DDR_NET;
604 } else if (addr_in_range(addr, QLA82XX_ADDR_OCM0,
605 QLA82XX_ADDR_OCM0_MAX)) {
607 if ((addr & 0x00ff800) == 0xff800) {
608 ql_log(ql_log_warn, vha, 0xb004,
609 "%s: QM access not handled.\n", __func__);
612 window = OCM_WIN(addr);
613 ha->ddr_mn_window = window;
615 ha->mn_win_crb | QLA82XX_PCI_CRBSPACE, window);
616 win_read = qla82xx_rd_32(ha,
617 ha->mn_win_crb | QLA82XX_PCI_CRBSPACE);
618 temp1 = ((window & 0x1FF) << 7) |
619 ((window & 0x0FFFE0000) >> 17);
620 if (win_read != temp1) {
621 ql_log(ql_log_warn, vha, 0xb005,
622 "%s: Written OCMwin (0x%x) != Read OCMwin (0x%x).\n",
623 __func__, temp1, win_read);
625 addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_OCM0_2M;
627 } else if (addr_in_range(addr, QLA82XX_ADDR_QDR_NET,
628 QLA82XX_P3_ADDR_QDR_NET_MAX)) {
629 /* QDR network side */
630 window = MS_WIN(addr);
631 ha->qdr_sn_window = window;
633 ha->ms_win_crb | QLA82XX_PCI_CRBSPACE, window);
634 win_read = qla82xx_rd_32(ha,
635 ha->ms_win_crb | QLA82XX_PCI_CRBSPACE);
636 if (win_read != window) {
637 ql_log(ql_log_warn, vha, 0xb006,
638 "%s: Written MSwin (0x%x) != Read MSwin (0x%x).\n",
639 __func__, window, win_read);
641 addr = GET_MEM_OFFS_2M(addr) + QLA82XX_PCI_QDR_NET;
644 * peg gdb frequently accesses memory that doesn't exist,
645 * this limits the chit chat so debugging isn't slowed down.
647 if ((qla82xx_pci_set_window_warning_count++ < 8) ||
648 (qla82xx_pci_set_window_warning_count%64 == 0)) {
649 ql_log(ql_log_warn, vha, 0xb007,
650 "%s: Warning:%s Unknown address range!.\n",
651 __func__, QLA2XXX_DRIVER_NAME);
658 /* check if address is in the same windows as the previous access */
659 static int qla82xx_pci_is_same_window(struct qla_hw_data *ha,
660 unsigned long long addr)
663 unsigned long long qdr_max;
665 qdr_max = QLA82XX_P3_ADDR_QDR_NET_MAX;
667 /* DDR network side */
668 if (addr_in_range(addr, QLA82XX_ADDR_DDR_NET,
669 QLA82XX_ADDR_DDR_NET_MAX))
671 else if (addr_in_range(addr, QLA82XX_ADDR_OCM0,
672 QLA82XX_ADDR_OCM0_MAX))
674 else if (addr_in_range(addr, QLA82XX_ADDR_OCM1,
675 QLA82XX_ADDR_OCM1_MAX))
677 else if (addr_in_range(addr, QLA82XX_ADDR_QDR_NET, qdr_max)) {
678 /* QDR network side */
679 window = ((addr - QLA82XX_ADDR_QDR_NET) >> 22) & 0x3f;
680 if (ha->qdr_sn_window == window)
686 static int qla82xx_pci_mem_read_direct(struct qla_hw_data *ha,
687 u64 off, void *data, int size)
690 void __iomem *addr = NULL;
693 uint8_t __iomem *mem_ptr = NULL;
694 unsigned long mem_base;
695 unsigned long mem_page;
696 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
698 write_lock_irqsave(&ha->hw_lock, flags);
701 * If attempting to access unknown address or straddle hw windows,
704 start = qla82xx_pci_set_window(ha, off);
705 if ((start == -1UL) ||
706 (qla82xx_pci_is_same_window(ha, off + size - 1) == 0)) {
707 write_unlock_irqrestore(&ha->hw_lock, flags);
708 ql_log(ql_log_fatal, vha, 0xb008,
709 "%s out of bound pci memory "
710 "access, offset is 0x%llx.\n",
711 QLA2XXX_DRIVER_NAME, off);
715 write_unlock_irqrestore(&ha->hw_lock, flags);
716 mem_base = pci_resource_start(ha->pdev, 0);
717 mem_page = start & PAGE_MASK;
718 /* Map two pages whenever user tries to access addresses in two
721 if (mem_page != ((start + size - 1) & PAGE_MASK))
722 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
724 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
725 if (mem_ptr == NULL) {
730 addr += start & (PAGE_SIZE - 1);
731 write_lock_irqsave(&ha->hw_lock, flags);
735 *(u8 *)data = readb(addr);
738 *(u16 *)data = readw(addr);
741 *(u32 *)data = readl(addr);
744 *(u64 *)data = readq(addr);
750 write_unlock_irqrestore(&ha->hw_lock, flags);
758 qla82xx_pci_mem_write_direct(struct qla_hw_data *ha,
759 u64 off, void *data, int size)
762 void __iomem *addr = NULL;
765 uint8_t __iomem *mem_ptr = NULL;
766 unsigned long mem_base;
767 unsigned long mem_page;
768 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
770 write_lock_irqsave(&ha->hw_lock, flags);
773 * If attempting to access unknown address or straddle hw windows,
776 start = qla82xx_pci_set_window(ha, off);
777 if ((start == -1UL) ||
778 (qla82xx_pci_is_same_window(ha, off + size - 1) == 0)) {
779 write_unlock_irqrestore(&ha->hw_lock, flags);
780 ql_log(ql_log_fatal, vha, 0xb009,
781 "%s out of bount memory "
782 "access, offset is 0x%llx.\n",
783 QLA2XXX_DRIVER_NAME, off);
787 write_unlock_irqrestore(&ha->hw_lock, flags);
788 mem_base = pci_resource_start(ha->pdev, 0);
789 mem_page = start & PAGE_MASK;
790 /* Map two pages whenever user tries to access addresses in two
793 if (mem_page != ((start + size - 1) & PAGE_MASK))
794 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE*2);
796 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
801 addr += start & (PAGE_SIZE - 1);
802 write_lock_irqsave(&ha->hw_lock, flags);
806 writeb(*(u8 *)data, addr);
809 writew(*(u16 *)data, addr);
812 writel(*(u32 *)data, addr);
815 writeq(*(u64 *)data, addr);
821 write_unlock_irqrestore(&ha->hw_lock, flags);
827 #define MTU_FUDGE_FACTOR 100
829 qla82xx_decode_crb_addr(unsigned long addr)
832 unsigned long base_addr, offset, pci_base;
834 if (!qla82xx_crb_table_initialized)
835 qla82xx_crb_addr_transform_setup();
837 pci_base = ADDR_ERROR;
838 base_addr = addr & 0xfff00000;
839 offset = addr & 0x000fffff;
841 for (i = 0; i < MAX_CRB_XFORM; i++) {
842 if (crb_addr_xform[i] == base_addr) {
847 if (pci_base == ADDR_ERROR)
849 return pci_base + offset;
852 static long rom_max_timeout = 100;
853 static long qla82xx_rom_lock_timeout = 100;
856 qla82xx_rom_lock(struct qla_hw_data *ha)
858 int done = 0, timeout = 0;
859 uint32_t lock_owner = 0;
860 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
863 /* acquire semaphore2 from PCI HW block */
864 done = qla82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_LOCK));
867 if (timeout >= qla82xx_rom_lock_timeout) {
868 lock_owner = qla82xx_rd_32(ha, QLA82XX_ROM_LOCK_ID);
869 ql_dbg(ql_dbg_p3p, vha, 0xb157,
870 "%s: Simultaneous flash access by following ports, active port = %d: accessing port = %d",
871 __func__, ha->portnum, lock_owner);
876 qla82xx_wr_32(ha, QLA82XX_ROM_LOCK_ID, ha->portnum);
881 qla82xx_rom_unlock(struct qla_hw_data *ha)
883 qla82xx_wr_32(ha, QLA82XX_ROM_LOCK_ID, 0xffffffff);
884 qla82xx_rd_32(ha, QLA82XX_PCIE_REG(PCIE_SEM2_UNLOCK));
888 qla82xx_wait_rom_busy(struct qla_hw_data *ha)
892 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
895 done = qla82xx_rd_32(ha, QLA82XX_ROMUSB_GLB_STATUS);
898 if (timeout >= rom_max_timeout) {
899 ql_dbg(ql_dbg_p3p, vha, 0xb00a,
900 "%s: Timeout reached waiting for rom busy.\n",
901 QLA2XXX_DRIVER_NAME);
909 qla82xx_wait_rom_done(struct qla_hw_data *ha)
913 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
916 done = qla82xx_rd_32(ha, QLA82XX_ROMUSB_GLB_STATUS);
919 if (timeout >= rom_max_timeout) {
920 ql_dbg(ql_dbg_p3p, vha, 0xb00b,
921 "%s: Timeout reached waiting for rom done.\n",
922 QLA2XXX_DRIVER_NAME);
930 qla82xx_md_rw_32(struct qla_hw_data *ha, uint32_t off, u32 data, uint8_t flag)
932 uint32_t off_value, rval = 0;
934 WRT_REG_DWORD(CRB_WINDOW_2M + ha->nx_pcibase, off & 0xFFFF0000);
936 /* Read back value to make sure write has gone through */
937 RD_REG_DWORD(CRB_WINDOW_2M + ha->nx_pcibase);
938 off_value = (off & 0x0000FFFF);
941 WRT_REG_DWORD(off_value + CRB_INDIRECT_2M + ha->nx_pcibase,
944 rval = RD_REG_DWORD(off_value + CRB_INDIRECT_2M +
951 qla82xx_do_rom_fast_read(struct qla_hw_data *ha, int addr, int *valp)
953 /* Dword reads to flash. */
954 qla82xx_md_rw_32(ha, MD_DIRECT_ROM_WINDOW, (addr & 0xFFFF0000), 1);
955 *valp = qla82xx_md_rw_32(ha, MD_DIRECT_ROM_READ_BASE +
956 (addr & 0x0000FFFF), 0, 0);
962 qla82xx_rom_fast_read(struct qla_hw_data *ha, int addr, int *valp)
965 uint32_t lock_owner = 0;
966 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
968 while ((qla82xx_rom_lock(ha) != 0) && (loops < 50000)) {
973 if (loops >= 50000) {
974 lock_owner = qla82xx_rd_32(ha, QLA82XX_ROM_LOCK_ID);
975 ql_log(ql_log_fatal, vha, 0x00b9,
976 "Failed to acquire SEM2 lock, Lock Owner %u.\n",
980 ret = qla82xx_do_rom_fast_read(ha, addr, valp);
981 qla82xx_rom_unlock(ha);
986 qla82xx_read_status_reg(struct qla_hw_data *ha, uint32_t *val)
988 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
989 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_INSTR_OPCODE, M25P_INSTR_RDSR);
990 qla82xx_wait_rom_busy(ha);
991 if (qla82xx_wait_rom_done(ha)) {
992 ql_log(ql_log_warn, vha, 0xb00c,
993 "Error waiting for rom done.\n");
996 *val = qla82xx_rd_32(ha, QLA82XX_ROMUSB_ROM_RDATA);
1001 qla82xx_flash_wait_write_finish(struct qla_hw_data *ha)
1007 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1009 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ABYTE_CNT, 0);
1010 while ((done != 0) && (ret == 0)) {
1011 ret = qla82xx_read_status_reg(ha, &val);
1016 if (timeout >= 50000) {
1017 ql_log(ql_log_warn, vha, 0xb00d,
1018 "Timeout reached waiting for write finish.\n");
1026 qla82xx_flash_set_write_enable(struct qla_hw_data *ha)
1029 qla82xx_wait_rom_busy(ha);
1030 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ABYTE_CNT, 0);
1031 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_INSTR_OPCODE, M25P_INSTR_WREN);
1032 qla82xx_wait_rom_busy(ha);
1033 if (qla82xx_wait_rom_done(ha))
1035 if (qla82xx_read_status_reg(ha, &val) != 0)
1043 qla82xx_write_status_reg(struct qla_hw_data *ha, uint32_t val)
1045 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1046 if (qla82xx_flash_set_write_enable(ha))
1048 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_WDATA, val);
1049 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_INSTR_OPCODE, 0x1);
1050 if (qla82xx_wait_rom_done(ha)) {
1051 ql_log(ql_log_warn, vha, 0xb00e,
1052 "Error waiting for rom done.\n");
1055 return qla82xx_flash_wait_write_finish(ha);
1059 qla82xx_write_disable_flash(struct qla_hw_data *ha)
1061 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1062 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_INSTR_OPCODE, M25P_INSTR_WRDI);
1063 if (qla82xx_wait_rom_done(ha)) {
1064 ql_log(ql_log_warn, vha, 0xb00f,
1065 "Error waiting for rom done.\n");
1072 ql82xx_rom_lock_d(struct qla_hw_data *ha)
1075 uint32_t lock_owner = 0;
1076 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1078 while ((qla82xx_rom_lock(ha) != 0) && (loops < 50000)) {
1083 if (loops >= 50000) {
1084 lock_owner = qla82xx_rd_32(ha, QLA82XX_ROM_LOCK_ID);
1085 ql_log(ql_log_warn, vha, 0xb010,
1086 "ROM lock failed, Lock Owner %u.\n", lock_owner);
1093 qla82xx_write_flash_dword(struct qla_hw_data *ha, uint32_t flashaddr,
1097 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1099 ret = ql82xx_rom_lock_d(ha);
1101 ql_log(ql_log_warn, vha, 0xb011,
1102 "ROM lock failed.\n");
1106 ret = qla82xx_flash_set_write_enable(ha);
1110 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_WDATA, data);
1111 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ADDRESS, flashaddr);
1112 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ABYTE_CNT, 3);
1113 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_INSTR_OPCODE, M25P_INSTR_PP);
1114 qla82xx_wait_rom_busy(ha);
1115 if (qla82xx_wait_rom_done(ha)) {
1116 ql_log(ql_log_warn, vha, 0xb012,
1117 "Error waiting for rom done.\n");
1122 ret = qla82xx_flash_wait_write_finish(ha);
1125 qla82xx_rom_unlock(ha);
1129 /* This routine does CRB initialize sequence
1130 * to put the ISP into operational state
1133 qla82xx_pinit_from_rom(scsi_qla_host_t *vha)
1137 struct crb_addr_pair *buf;
1140 struct qla_hw_data *ha = vha->hw;
1142 struct crb_addr_pair {
1147 /* Halt all the individual PEGs and other blocks of the ISP */
1148 qla82xx_rom_lock(ha);
1150 /* disable all I2Q */
1151 qla82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x10, 0x0);
1152 qla82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x14, 0x0);
1153 qla82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x18, 0x0);
1154 qla82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x1c, 0x0);
1155 qla82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x20, 0x0);
1156 qla82xx_wr_32(ha, QLA82XX_CRB_I2Q + 0x24, 0x0);
1158 /* disable all niu interrupts */
1159 qla82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x40, 0xff);
1160 /* disable xge rx/tx */
1161 qla82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x70000, 0x00);
1162 /* disable xg1 rx/tx */
1163 qla82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x80000, 0x00);
1164 /* disable sideband mac */
1165 qla82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x90000, 0x00);
1166 /* disable ap0 mac */
1167 qla82xx_wr_32(ha, QLA82XX_CRB_NIU + 0xa0000, 0x00);
1168 /* disable ap1 mac */
1169 qla82xx_wr_32(ha, QLA82XX_CRB_NIU + 0xb0000, 0x00);
1172 val = qla82xx_rd_32(ha, QLA82XX_CRB_SRE + 0x1000);
1173 qla82xx_wr_32(ha, QLA82XX_CRB_SRE + 0x1000, val & (~(0x1)));
1176 qla82xx_wr_32(ha, QLA82XX_CRB_EPG + 0x1300, 0x1);
1179 qla82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x0, 0x0);
1180 qla82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x8, 0x0);
1181 qla82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x10, 0x0);
1182 qla82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x18, 0x0);
1183 qla82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x100, 0x0);
1184 qla82xx_wr_32(ha, QLA82XX_CRB_TIMER + 0x200, 0x0);
1187 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0 + 0x3c, 1);
1188 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_1 + 0x3c, 1);
1189 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_2 + 0x3c, 1);
1190 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_3 + 0x3c, 1);
1191 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_4 + 0x3c, 1);
1195 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
1196 /* don't reset CAM block on reset */
1197 qla82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0xfeffffff);
1199 qla82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0xffffffff);
1200 qla82xx_rom_unlock(ha);
1202 /* Read the signature value from the flash.
1203 * Offset 0: Contain signature (0xcafecafe)
1204 * Offset 4: Offset and number of addr/value pairs
1205 * that present in CRB initialize sequence
1207 if (qla82xx_rom_fast_read(ha, 0, &n) != 0 || n != 0xcafecafeUL ||
1208 qla82xx_rom_fast_read(ha, 4, &n) != 0) {
1209 ql_log(ql_log_fatal, vha, 0x006e,
1210 "Error Reading crb_init area: n: %08x.\n", n);
1214 /* Offset in flash = lower 16 bits
1215 * Number of entries = upper 16 bits
1217 offset = n & 0xffffU;
1218 n = (n >> 16) & 0xffffU;
1220 /* number of addr/value pair should not exceed 1024 entries */
1222 ql_log(ql_log_fatal, vha, 0x0071,
1223 "Card flash not initialized:n=0x%x.\n", n);
1227 ql_log(ql_log_info, vha, 0x0072,
1228 "%d CRB init values found in ROM.\n", n);
1230 buf = kmalloc(n * sizeof(struct crb_addr_pair), GFP_KERNEL);
1232 ql_log(ql_log_fatal, vha, 0x010c,
1233 "Unable to allocate memory.\n");
1237 for (i = 0; i < n; i++) {
1238 if (qla82xx_rom_fast_read(ha, 8*i + 4*offset, &val) != 0 ||
1239 qla82xx_rom_fast_read(ha, 8*i + 4*offset + 4, &addr) != 0) {
1248 for (i = 0; i < n; i++) {
1249 /* Translate internal CRB initialization
1250 * address to PCI bus address
1252 off = qla82xx_decode_crb_addr((unsigned long)buf[i].addr) +
1253 QLA82XX_PCI_CRBSPACE;
1254 /* Not all CRB addr/value pair to be written,
1255 * some of them are skipped
1258 /* skipping cold reboot MAGIC */
1259 if (off == QLA82XX_CAM_RAM(0x1fc))
1262 /* do not reset PCI */
1263 if (off == (ROMUSB_GLB + 0xbc))
1266 /* skip core clock, so that firmware can increase the clock */
1267 if (off == (ROMUSB_GLB + 0xc8))
1270 /* skip the function enable register */
1271 if (off == QLA82XX_PCIE_REG(PCIE_SETUP_FUNCTION))
1274 if (off == QLA82XX_PCIE_REG(PCIE_SETUP_FUNCTION2))
1277 if ((off & 0x0ff00000) == QLA82XX_CRB_SMB)
1280 if ((off & 0x0ff00000) == QLA82XX_CRB_DDR_NET)
1283 if (off == ADDR_ERROR) {
1284 ql_log(ql_log_fatal, vha, 0x0116,
1285 "Unknown addr: 0x%08lx.\n", buf[i].addr);
1289 qla82xx_wr_32(ha, off, buf[i].data);
1291 /* ISP requires much bigger delay to settle down,
1292 * else crb_window returns 0xffffffff
1294 if (off == QLA82XX_ROMUSB_GLB_SW_RESET)
1297 /* ISP requires millisec delay between
1298 * successive CRB register updation
1305 /* Resetting the data and instruction cache */
1306 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_D+0xec, 0x1e);
1307 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_D+0x4c, 8);
1308 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_I+0x4c, 8);
1310 /* Clear all protocol processing engines */
1311 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0+0x8, 0);
1312 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0+0xc, 0);
1313 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_1+0x8, 0);
1314 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_1+0xc, 0);
1315 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_2+0x8, 0);
1316 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_2+0xc, 0);
1317 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_3+0x8, 0);
1318 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_3+0xc, 0);
1323 qla82xx_pci_mem_write_2M(struct qla_hw_data *ha,
1324 u64 off, void *data, int size)
1326 int i, j, ret = 0, loop, sz[2], off0;
1327 int scale, shift_amount, startword;
1329 uint64_t off8, mem_crb, tmpw, word[2] = {0, 0};
1332 * If not MN, go check for MS or invalid.
1334 if (off >= QLA82XX_ADDR_QDR_NET && off <= QLA82XX_P3_ADDR_QDR_NET_MAX)
1335 mem_crb = QLA82XX_CRB_QDR_NET;
1337 mem_crb = QLA82XX_CRB_DDR_NET;
1338 if (qla82xx_pci_mem_bound_check(ha, off, size) == 0)
1339 return qla82xx_pci_mem_write_direct(ha,
1344 sz[0] = (size < (8 - off0)) ? size : (8 - off0);
1345 sz[1] = size - sz[0];
1347 off8 = off & 0xfffffff0;
1348 loop = (((off & 0xf) + size - 1) >> 4) + 1;
1351 startword = (off & 0xf)/8;
1353 for (i = 0; i < loop; i++) {
1354 if (qla82xx_pci_mem_read_2M(ha, off8 +
1355 (i << shift_amount), &word[i * scale], 8))
1361 tmpw = *((uint8_t *)data);
1364 tmpw = *((uint16_t *)data);
1367 tmpw = *((uint32_t *)data);
1371 tmpw = *((uint64_t *)data);
1376 word[startword] = tmpw;
1379 ~((~(~0ULL << (sz[0] * 8))) << (off0 * 8));
1380 word[startword] |= tmpw << (off0 * 8);
1383 word[startword+1] &= ~(~0ULL << (sz[1] * 8));
1384 word[startword+1] |= tmpw >> (sz[0] * 8);
1387 for (i = 0; i < loop; i++) {
1388 temp = off8 + (i << shift_amount);
1389 qla82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_ADDR_LO, temp);
1391 qla82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_ADDR_HI, temp);
1392 temp = word[i * scale] & 0xffffffff;
1393 qla82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_WRDATA_LO, temp);
1394 temp = (word[i * scale] >> 32) & 0xffffffff;
1395 qla82xx_wr_32(ha, mem_crb+MIU_TEST_AGT_WRDATA_HI, temp);
1396 temp = word[i*scale + 1] & 0xffffffff;
1397 qla82xx_wr_32(ha, mem_crb +
1398 MIU_TEST_AGT_WRDATA_UPPER_LO, temp);
1399 temp = (word[i*scale + 1] >> 32) & 0xffffffff;
1400 qla82xx_wr_32(ha, mem_crb +
1401 MIU_TEST_AGT_WRDATA_UPPER_HI, temp);
1403 temp = MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
1404 qla82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_CTRL, temp);
1405 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE | MIU_TA_CTL_WRITE;
1406 qla82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_CTRL, temp);
1408 for (j = 0; j < MAX_CTL_CHECK; j++) {
1409 temp = qla82xx_rd_32(ha, mem_crb + MIU_TEST_AGT_CTRL);
1410 if ((temp & MIU_TA_CTL_BUSY) == 0)
1414 if (j >= MAX_CTL_CHECK) {
1415 if (printk_ratelimit())
1416 dev_err(&ha->pdev->dev,
1417 "failed to write through agent.\n");
1427 qla82xx_fw_load_from_flash(struct qla_hw_data *ha)
1431 long flashaddr = ha->flt_region_bootload << 2;
1432 long memaddr = BOOTLD_START;
1435 size = (IMAGE_START - BOOTLD_START) / 8;
1437 for (i = 0; i < size; i++) {
1438 if ((qla82xx_rom_fast_read(ha, flashaddr, (int *)&low)) ||
1439 (qla82xx_rom_fast_read(ha, flashaddr + 4, (int *)&high))) {
1442 data = ((u64)high << 32) | low ;
1443 qla82xx_pci_mem_write_2M(ha, memaddr, &data, 8);
1447 if (i % 0x1000 == 0)
1451 read_lock(&ha->hw_lock);
1452 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0 + 0x18, 0x1020);
1453 qla82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0x80001e);
1454 read_unlock(&ha->hw_lock);
1459 qla82xx_pci_mem_read_2M(struct qla_hw_data *ha,
1460 u64 off, void *data, int size)
1462 int i, j = 0, k, start, end, loop, sz[2], off0[2];
1465 uint64_t off8, val, mem_crb, word[2] = {0, 0};
1468 * If not MN, go check for MS or invalid.
1471 if (off >= QLA82XX_ADDR_QDR_NET && off <= QLA82XX_P3_ADDR_QDR_NET_MAX)
1472 mem_crb = QLA82XX_CRB_QDR_NET;
1474 mem_crb = QLA82XX_CRB_DDR_NET;
1475 if (qla82xx_pci_mem_bound_check(ha, off, size) == 0)
1476 return qla82xx_pci_mem_read_direct(ha,
1480 off8 = off & 0xfffffff0;
1481 off0[0] = off & 0xf;
1482 sz[0] = (size < (16 - off0[0])) ? size : (16 - off0[0]);
1484 loop = ((off0[0] + size - 1) >> shift_amount) + 1;
1486 sz[1] = size - sz[0];
1488 for (i = 0; i < loop; i++) {
1489 temp = off8 + (i << shift_amount);
1490 qla82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_ADDR_LO, temp);
1492 qla82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_ADDR_HI, temp);
1493 temp = MIU_TA_CTL_ENABLE;
1494 qla82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_CTRL, temp);
1495 temp = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE;
1496 qla82xx_wr_32(ha, mem_crb + MIU_TEST_AGT_CTRL, temp);
1498 for (j = 0; j < MAX_CTL_CHECK; j++) {
1499 temp = qla82xx_rd_32(ha, mem_crb + MIU_TEST_AGT_CTRL);
1500 if ((temp & MIU_TA_CTL_BUSY) == 0)
1504 if (j >= MAX_CTL_CHECK) {
1505 if (printk_ratelimit())
1506 dev_err(&ha->pdev->dev,
1507 "failed to read through agent.\n");
1511 start = off0[i] >> 2;
1512 end = (off0[i] + sz[i] - 1) >> 2;
1513 for (k = start; k <= end; k++) {
1514 temp = qla82xx_rd_32(ha,
1515 mem_crb + MIU_TEST_AGT_RDDATA(k));
1516 word[i] |= ((uint64_t)temp << (32 * (k & 1)));
1520 if (j >= MAX_CTL_CHECK)
1523 if ((off0[0] & 7) == 0) {
1526 val = ((word[0] >> (off0[0] * 8)) & (~(~0ULL << (sz[0] * 8)))) |
1527 ((word[1] & (~(~0ULL << (sz[1] * 8)))) << (sz[0] * 8));
1532 *(uint8_t *)data = val;
1535 *(uint16_t *)data = val;
1538 *(uint32_t *)data = val;
1541 *(uint64_t *)data = val;
1548 static struct qla82xx_uri_table_desc *
1549 qla82xx_get_table_desc(const u8 *unirom, int section)
1552 struct qla82xx_uri_table_desc *directory =
1553 (struct qla82xx_uri_table_desc *)&unirom[0];
1556 __le32 entries = cpu_to_le32(directory->num_entries);
1558 for (i = 0; i < entries; i++) {
1559 offset = cpu_to_le32(directory->findex) +
1560 (i * cpu_to_le32(directory->entry_size));
1561 tab_type = cpu_to_le32(*((u32 *)&unirom[offset] + 8));
1563 if (tab_type == section)
1564 return (struct qla82xx_uri_table_desc *)&unirom[offset];
1570 static struct qla82xx_uri_data_desc *
1571 qla82xx_get_data_desc(struct qla_hw_data *ha,
1572 u32 section, u32 idx_offset)
1574 const u8 *unirom = ha->hablob->fw->data;
1575 int idx = cpu_to_le32(*((int *)&unirom[ha->file_prd_off] + idx_offset));
1576 struct qla82xx_uri_table_desc *tab_desc = NULL;
1579 tab_desc = qla82xx_get_table_desc(unirom, section);
1583 offset = cpu_to_le32(tab_desc->findex) +
1584 (cpu_to_le32(tab_desc->entry_size) * idx);
1586 return (struct qla82xx_uri_data_desc *)&unirom[offset];
1590 qla82xx_get_bootld_offset(struct qla_hw_data *ha)
1592 u32 offset = BOOTLD_START;
1593 struct qla82xx_uri_data_desc *uri_desc = NULL;
1595 if (ha->fw_type == QLA82XX_UNIFIED_ROMIMAGE) {
1596 uri_desc = qla82xx_get_data_desc(ha,
1597 QLA82XX_URI_DIR_SECT_BOOTLD, QLA82XX_URI_BOOTLD_IDX_OFF);
1599 offset = cpu_to_le32(uri_desc->findex);
1602 return (u8 *)&ha->hablob->fw->data[offset];
1605 static u32 qla82xx_get_fw_size(struct qla_hw_data *ha)
1607 struct qla82xx_uri_data_desc *uri_desc = NULL;
1609 if (ha->fw_type == QLA82XX_UNIFIED_ROMIMAGE) {
1610 uri_desc = qla82xx_get_data_desc(ha, QLA82XX_URI_DIR_SECT_FW,
1611 QLA82XX_URI_FIRMWARE_IDX_OFF);
1613 return cpu_to_le32(uri_desc->size);
1616 return get_unaligned_le32(&ha->hablob->fw->data[FW_SIZE_OFFSET]);
1620 qla82xx_get_fw_offs(struct qla_hw_data *ha)
1622 u32 offset = IMAGE_START;
1623 struct qla82xx_uri_data_desc *uri_desc = NULL;
1625 if (ha->fw_type == QLA82XX_UNIFIED_ROMIMAGE) {
1626 uri_desc = qla82xx_get_data_desc(ha, QLA82XX_URI_DIR_SECT_FW,
1627 QLA82XX_URI_FIRMWARE_IDX_OFF);
1629 offset = cpu_to_le32(uri_desc->findex);
1632 return (u8 *)&ha->hablob->fw->data[offset];
1635 /* PCI related functions */
1636 int qla82xx_pci_region_offset(struct pci_dev *pdev, int region)
1638 unsigned long val = 0;
1646 pci_read_config_dword(pdev, QLA82XX_PCI_REG_MSIX_TBL, &control);
1647 val = control + QLA82XX_MSIX_TBL_SPACE;
1655 qla82xx_iospace_config(struct qla_hw_data *ha)
1659 if (pci_request_regions(ha->pdev, QLA2XXX_DRIVER_NAME)) {
1660 ql_log_pci(ql_log_fatal, ha->pdev, 0x000c,
1661 "Failed to reserver selected regions.\n");
1662 goto iospace_error_exit;
1665 /* Use MMIO operations for all accesses. */
1666 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1667 ql_log_pci(ql_log_fatal, ha->pdev, 0x000d,
1668 "Region #0 not an MMIO resource, aborting.\n");
1669 goto iospace_error_exit;
1672 len = pci_resource_len(ha->pdev, 0);
1673 ha->nx_pcibase = ioremap(pci_resource_start(ha->pdev, 0), len);
1674 if (!ha->nx_pcibase) {
1675 ql_log_pci(ql_log_fatal, ha->pdev, 0x000e,
1676 "Cannot remap pcibase MMIO, aborting.\n");
1677 goto iospace_error_exit;
1680 /* Mapping of IO base pointer */
1681 if (IS_QLA8044(ha)) {
1682 ha->iobase = ha->nx_pcibase;
1683 } else if (IS_QLA82XX(ha)) {
1684 ha->iobase = ha->nx_pcibase + 0xbc000 + (ha->pdev->devfn << 11);
1688 ha->nxdb_wr_ptr = ioremap((pci_resource_start(ha->pdev, 4) +
1689 (ha->pdev->devfn << 12)), 4);
1690 if (!ha->nxdb_wr_ptr) {
1691 ql_log_pci(ql_log_fatal, ha->pdev, 0x000f,
1692 "Cannot remap MMIO, aborting.\n");
1693 goto iospace_error_exit;
1696 /* Mapping of IO base pointer,
1697 * door bell read and write pointer
1699 ha->nxdb_rd_ptr = ha->nx_pcibase + (512 * 1024) +
1700 (ha->pdev->devfn * 8);
1702 ha->nxdb_wr_ptr = (void __iomem *)(ha->pdev->devfn == 6 ?
1703 QLA82XX_CAMRAM_DB1 :
1704 QLA82XX_CAMRAM_DB2);
1707 ha->max_req_queues = ha->max_rsp_queues = 1;
1708 ha->msix_count = ha->max_rsp_queues + 1;
1709 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc006,
1710 "nx_pci_base=%p iobase=%p "
1711 "max_req_queues=%d msix_count=%d.\n",
1712 ha->nx_pcibase, ha->iobase,
1713 ha->max_req_queues, ha->msix_count);
1714 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0010,
1715 "nx_pci_base=%p iobase=%p "
1716 "max_req_queues=%d msix_count=%d.\n",
1717 ha->nx_pcibase, ha->iobase,
1718 ha->max_req_queues, ha->msix_count);
1725 /* GS related functions */
1727 /* Initialization related functions */
1730 * qla82xx_pci_config() - Setup ISP82xx PCI configuration registers.
1733 * Returns 0 on success.
1736 qla82xx_pci_config(scsi_qla_host_t *vha)
1738 struct qla_hw_data *ha = vha->hw;
1741 pci_set_master(ha->pdev);
1742 ret = pci_set_mwi(ha->pdev);
1743 ha->chip_revision = ha->pdev->revision;
1744 ql_dbg(ql_dbg_init, vha, 0x0043,
1745 "Chip revision:%d; pci_set_mwi() returned %d.\n",
1746 ha->chip_revision, ret);
1751 * qla82xx_reset_chip() - Setup ISP82xx PCI configuration registers.
1754 * Returns 0 on success.
1757 qla82xx_reset_chip(scsi_qla_host_t *vha)
1759 struct qla_hw_data *ha = vha->hw;
1760 ha->isp_ops->disable_intrs(ha);
1763 void qla82xx_config_rings(struct scsi_qla_host *vha)
1765 struct qla_hw_data *ha = vha->hw;
1766 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
1767 struct init_cb_81xx *icb;
1768 struct req_que *req = ha->req_q_map[0];
1769 struct rsp_que *rsp = ha->rsp_q_map[0];
1771 /* Setup ring parameters in initialization control block. */
1772 icb = (struct init_cb_81xx *)ha->init_cb;
1773 icb->request_q_outpointer = cpu_to_le16(0);
1774 icb->response_q_inpointer = cpu_to_le16(0);
1775 icb->request_q_length = cpu_to_le16(req->length);
1776 icb->response_q_length = cpu_to_le16(rsp->length);
1777 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1778 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1779 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1780 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
1782 WRT_REG_DWORD(®->req_q_out[0], 0);
1783 WRT_REG_DWORD(®->rsp_q_in[0], 0);
1784 WRT_REG_DWORD(®->rsp_q_out[0], 0);
1788 qla82xx_fw_load_from_blob(struct qla_hw_data *ha)
1791 u32 i, flashaddr, size;
1794 size = (IMAGE_START - BOOTLD_START) / 8;
1796 ptr64 = (u64 *)qla82xx_get_bootld_offset(ha);
1797 flashaddr = BOOTLD_START;
1799 for (i = 0; i < size; i++) {
1800 data = cpu_to_le64(ptr64[i]);
1801 if (qla82xx_pci_mem_write_2M(ha, flashaddr, &data, 8))
1806 flashaddr = FLASH_ADDR_START;
1807 size = qla82xx_get_fw_size(ha) / 8;
1808 ptr64 = (u64 *)qla82xx_get_fw_offs(ha);
1810 for (i = 0; i < size; i++) {
1811 data = cpu_to_le64(ptr64[i]);
1813 if (qla82xx_pci_mem_write_2M(ha, flashaddr, &data, 8))
1819 /* Write a magic value to CAMRAM register
1820 * at a specified offset to indicate
1821 * that all data is written and
1822 * ready for firmware to initialize.
1824 qla82xx_wr_32(ha, QLA82XX_CAM_RAM(0x1fc), QLA82XX_BDINFO_MAGIC);
1826 read_lock(&ha->hw_lock);
1827 qla82xx_wr_32(ha, QLA82XX_CRB_PEG_NET_0 + 0x18, 0x1020);
1828 qla82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, 0x80001e);
1829 read_unlock(&ha->hw_lock);
1834 qla82xx_set_product_offset(struct qla_hw_data *ha)
1836 struct qla82xx_uri_table_desc *ptab_desc = NULL;
1837 const uint8_t *unirom = ha->hablob->fw->data;
1840 __le32 flags, file_chiprev, offset;
1841 uint8_t chiprev = ha->chip_revision;
1842 /* Hardcoding mn_present flag for P3P */
1846 ptab_desc = qla82xx_get_table_desc(unirom,
1847 QLA82XX_URI_DIR_SECT_PRODUCT_TBL);
1851 entries = cpu_to_le32(ptab_desc->num_entries);
1853 for (i = 0; i < entries; i++) {
1854 offset = cpu_to_le32(ptab_desc->findex) +
1855 (i * cpu_to_le32(ptab_desc->entry_size));
1856 flags = cpu_to_le32(*((int *)&unirom[offset] +
1857 QLA82XX_URI_FLAGS_OFF));
1858 file_chiprev = cpu_to_le32(*((int *)&unirom[offset] +
1859 QLA82XX_URI_CHIP_REV_OFF));
1861 flagbit = mn_present ? 1 : 2;
1863 if ((chiprev == file_chiprev) && ((1ULL << flagbit) & flags)) {
1864 ha->file_prd_off = offset;
1872 qla82xx_validate_firmware_blob(scsi_qla_host_t *vha, uint8_t fw_type)
1876 struct qla_hw_data *ha = vha->hw;
1877 const struct firmware *fw = ha->hablob->fw;
1879 ha->fw_type = fw_type;
1881 if (fw_type == QLA82XX_UNIFIED_ROMIMAGE) {
1882 if (qla82xx_set_product_offset(ha))
1885 min_size = QLA82XX_URI_FW_MIN_SIZE;
1887 val = cpu_to_le32(*(u32 *)&fw->data[QLA82XX_FW_MAGIC_OFFSET]);
1888 if ((__force u32)val != QLA82XX_BDINFO_MAGIC)
1891 min_size = QLA82XX_FW_MIN_SIZE;
1894 if (fw->size < min_size)
1900 qla82xx_check_cmdpeg_state(struct qla_hw_data *ha)
1904 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1907 read_lock(&ha->hw_lock);
1908 val = qla82xx_rd_32(ha, CRB_CMDPEG_STATE);
1909 read_unlock(&ha->hw_lock);
1912 case PHAN_INITIALIZE_COMPLETE:
1913 case PHAN_INITIALIZE_ACK:
1915 case PHAN_INITIALIZE_FAILED:
1920 ql_log(ql_log_info, vha, 0x00a8,
1921 "CRB_CMDPEG_STATE: 0x%x and retries:0x%x.\n",
1926 } while (--retries);
1928 ql_log(ql_log_fatal, vha, 0x00a9,
1929 "Cmd Peg initialization failed: 0x%x.\n", val);
1931 val = qla82xx_rd_32(ha, QLA82XX_ROMUSB_GLB_PEGTUNE_DONE);
1932 read_lock(&ha->hw_lock);
1933 qla82xx_wr_32(ha, CRB_CMDPEG_STATE, PHAN_INITIALIZE_FAILED);
1934 read_unlock(&ha->hw_lock);
1935 return QLA_FUNCTION_FAILED;
1939 qla82xx_check_rcvpeg_state(struct qla_hw_data *ha)
1943 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
1946 read_lock(&ha->hw_lock);
1947 val = qla82xx_rd_32(ha, CRB_RCVPEG_STATE);
1948 read_unlock(&ha->hw_lock);
1951 case PHAN_INITIALIZE_COMPLETE:
1952 case PHAN_INITIALIZE_ACK:
1954 case PHAN_INITIALIZE_FAILED:
1959 ql_log(ql_log_info, vha, 0x00ab,
1960 "CRB_RCVPEG_STATE: 0x%x and retries: 0x%x.\n",
1965 } while (--retries);
1967 ql_log(ql_log_fatal, vha, 0x00ac,
1968 "Rcv Peg initializatin failed: 0x%x.\n", val);
1969 read_lock(&ha->hw_lock);
1970 qla82xx_wr_32(ha, CRB_RCVPEG_STATE, PHAN_INITIALIZE_FAILED);
1971 read_unlock(&ha->hw_lock);
1972 return QLA_FUNCTION_FAILED;
1975 /* ISR related functions */
1976 static struct qla82xx_legacy_intr_set legacy_intr[] = \
1977 QLA82XX_LEGACY_INTR_CONFIG;
1980 * qla82xx_mbx_completion() - Process mailbox command completions.
1981 * @ha: SCSI driver HA context
1982 * @mb0: Mailbox0 register
1985 qla82xx_mbx_completion(scsi_qla_host_t *vha, uint16_t mb0)
1988 uint16_t __iomem *wptr;
1989 struct qla_hw_data *ha = vha->hw;
1990 struct device_reg_82xx __iomem *reg = &ha->iobase->isp82;
1991 wptr = (uint16_t __iomem *)®->mailbox_out[1];
1993 /* Load return mailbox registers. */
1994 ha->flags.mbox_int = 1;
1995 ha->mailbox_out[0] = mb0;
1997 for (cnt = 1; cnt < ha->mbx_count; cnt++) {
1998 ha->mailbox_out[cnt] = RD_REG_WORD(wptr);
2003 ql_dbg(ql_dbg_async, vha, 0x5053,
2004 "MBX pointer ERROR.\n");
2008 * qla82xx_intr_handler() - Process interrupts for the ISP23xx and ISP63xx.
2010 * @dev_id: SCSI driver HA context
2013 * Called by system whenever the host adapter generates an interrupt.
2015 * Returns handled flag.
2018 qla82xx_intr_handler(int irq, void *dev_id)
2020 scsi_qla_host_t *vha;
2021 struct qla_hw_data *ha;
2022 struct rsp_que *rsp;
2023 struct device_reg_82xx __iomem *reg;
2024 int status = 0, status1 = 0;
2025 unsigned long flags;
2030 rsp = (struct rsp_que *) dev_id;
2032 ql_log(ql_log_info, NULL, 0xb053,
2033 "%s: NULL response queue pointer.\n", __func__);
2038 if (!ha->flags.msi_enabled) {
2039 status = qla82xx_rd_32(ha, ISR_INT_VECTOR);
2040 if (!(status & ha->nx_legacy_intr.int_vec_bit))
2043 status1 = qla82xx_rd_32(ha, ISR_INT_STATE_REG);
2044 if (!ISR_IS_LEGACY_INTR_TRIGGERED(status1))
2048 /* clear the interrupt */
2049 qla82xx_wr_32(ha, ha->nx_legacy_intr.tgt_status_reg, 0xffffffff);
2051 /* read twice to ensure write is flushed */
2052 qla82xx_rd_32(ha, ISR_INT_VECTOR);
2053 qla82xx_rd_32(ha, ISR_INT_VECTOR);
2055 reg = &ha->iobase->isp82;
2057 spin_lock_irqsave(&ha->hardware_lock, flags);
2058 vha = pci_get_drvdata(ha->pdev);
2059 for (iter = 1; iter--; ) {
2061 if (RD_REG_DWORD(®->host_int)) {
2062 stat = RD_REG_DWORD(®->host_status);
2064 switch (stat & 0xff) {
2069 qla82xx_mbx_completion(vha, MSW(stat));
2070 status |= MBX_INTERRUPT;
2074 mb[1] = RD_REG_WORD(®->mailbox_out[1]);
2075 mb[2] = RD_REG_WORD(®->mailbox_out[2]);
2076 mb[3] = RD_REG_WORD(®->mailbox_out[3]);
2077 qla2x00_async_event(vha, rsp, mb);
2080 qla24xx_process_response_queue(vha, rsp);
2083 ql_dbg(ql_dbg_async, vha, 0x5054,
2084 "Unrecognized interrupt type (%d).\n",
2089 WRT_REG_DWORD(®->host_int, 0);
2092 qla2x00_handle_mbx_completion(ha, status);
2093 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2095 if (!ha->flags.msi_enabled)
2096 qla82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
2102 qla82xx_msix_default(int irq, void *dev_id)
2104 scsi_qla_host_t *vha;
2105 struct qla_hw_data *ha;
2106 struct rsp_que *rsp;
2107 struct device_reg_82xx __iomem *reg;
2109 unsigned long flags;
2111 uint32_t host_int = 0;
2114 rsp = (struct rsp_que *) dev_id;
2117 "%s(): NULL response queue pointer.\n", __func__);
2122 reg = &ha->iobase->isp82;
2124 spin_lock_irqsave(&ha->hardware_lock, flags);
2125 vha = pci_get_drvdata(ha->pdev);
2127 host_int = RD_REG_DWORD(®->host_int);
2128 if (qla2x00_check_reg32_for_disconnect(vha, host_int))
2131 stat = RD_REG_DWORD(®->host_status);
2133 switch (stat & 0xff) {
2138 qla82xx_mbx_completion(vha, MSW(stat));
2139 status |= MBX_INTERRUPT;
2143 mb[1] = RD_REG_WORD(®->mailbox_out[1]);
2144 mb[2] = RD_REG_WORD(®->mailbox_out[2]);
2145 mb[3] = RD_REG_WORD(®->mailbox_out[3]);
2146 qla2x00_async_event(vha, rsp, mb);
2149 qla24xx_process_response_queue(vha, rsp);
2152 ql_dbg(ql_dbg_async, vha, 0x5041,
2153 "Unrecognized interrupt type (%d).\n",
2158 WRT_REG_DWORD(®->host_int, 0);
2161 qla2x00_handle_mbx_completion(ha, status);
2162 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2168 qla82xx_msix_rsp_q(int irq, void *dev_id)
2170 scsi_qla_host_t *vha;
2171 struct qla_hw_data *ha;
2172 struct rsp_que *rsp;
2173 struct device_reg_82xx __iomem *reg;
2174 unsigned long flags;
2175 uint32_t host_int = 0;
2177 rsp = (struct rsp_que *) dev_id;
2180 "%s(): NULL response queue pointer.\n", __func__);
2185 reg = &ha->iobase->isp82;
2186 spin_lock_irqsave(&ha->hardware_lock, flags);
2187 vha = pci_get_drvdata(ha->pdev);
2188 host_int = RD_REG_DWORD(®->host_int);
2189 if (qla2x00_check_reg32_for_disconnect(vha, host_int))
2191 qla24xx_process_response_queue(vha, rsp);
2192 WRT_REG_DWORD(®->host_int, 0);
2194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2199 qla82xx_poll(int irq, void *dev_id)
2201 scsi_qla_host_t *vha;
2202 struct qla_hw_data *ha;
2203 struct rsp_que *rsp;
2204 struct device_reg_82xx __iomem *reg;
2207 uint32_t host_int = 0;
2209 unsigned long flags;
2211 rsp = (struct rsp_que *) dev_id;
2214 "%s(): NULL response queue pointer.\n", __func__);
2219 reg = &ha->iobase->isp82;
2220 spin_lock_irqsave(&ha->hardware_lock, flags);
2221 vha = pci_get_drvdata(ha->pdev);
2223 host_int = RD_REG_DWORD(®->host_int);
2224 if (qla2x00_check_reg32_for_disconnect(vha, host_int))
2227 stat = RD_REG_DWORD(®->host_status);
2228 switch (stat & 0xff) {
2233 qla82xx_mbx_completion(vha, MSW(stat));
2234 status |= MBX_INTERRUPT;
2238 mb[1] = RD_REG_WORD(®->mailbox_out[1]);
2239 mb[2] = RD_REG_WORD(®->mailbox_out[2]);
2240 mb[3] = RD_REG_WORD(®->mailbox_out[3]);
2241 qla2x00_async_event(vha, rsp, mb);
2244 qla24xx_process_response_queue(vha, rsp);
2247 ql_dbg(ql_dbg_p3p, vha, 0xb013,
2248 "Unrecognized interrupt type (%d).\n",
2252 WRT_REG_DWORD(®->host_int, 0);
2255 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2259 qla82xx_enable_intrs(struct qla_hw_data *ha)
2261 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
2262 qla82xx_mbx_intr_enable(vha);
2263 spin_lock_irq(&ha->hardware_lock);
2265 qla8044_wr_reg(ha, LEG_INTR_MASK_OFFSET, 0);
2267 qla82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0xfbff);
2268 spin_unlock_irq(&ha->hardware_lock);
2269 ha->interrupts_on = 1;
2273 qla82xx_disable_intrs(struct qla_hw_data *ha)
2275 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
2276 qla82xx_mbx_intr_disable(vha);
2277 spin_lock_irq(&ha->hardware_lock);
2279 qla8044_wr_reg(ha, LEG_INTR_MASK_OFFSET, 1);
2281 qla82xx_wr_32(ha, ha->nx_legacy_intr.tgt_mask_reg, 0x0400);
2282 spin_unlock_irq(&ha->hardware_lock);
2283 ha->interrupts_on = 0;
2286 void qla82xx_init_flags(struct qla_hw_data *ha)
2288 struct qla82xx_legacy_intr_set *nx_legacy_intr;
2290 /* ISP 8021 initializations */
2291 rwlock_init(&ha->hw_lock);
2292 ha->qdr_sn_window = -1;
2293 ha->ddr_mn_window = -1;
2294 ha->curr_window = 255;
2295 ha->portnum = PCI_FUNC(ha->pdev->devfn);
2296 nx_legacy_intr = &legacy_intr[ha->portnum];
2297 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
2298 ha->nx_legacy_intr.tgt_status_reg = nx_legacy_intr->tgt_status_reg;
2299 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
2300 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
2304 qla82xx_set_idc_version(scsi_qla_host_t *vha)
2307 uint32_t drv_active;
2308 struct qla_hw_data *ha = vha->hw;
2310 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
2311 if (drv_active == (QLA82XX_DRV_ACTIVE << (ha->portnum * 4))) {
2312 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
2313 QLA82XX_IDC_VERSION);
2314 ql_log(ql_log_info, vha, 0xb082,
2315 "IDC version updated to %d\n", QLA82XX_IDC_VERSION);
2317 idc_ver = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_IDC_VERSION);
2318 if (idc_ver != QLA82XX_IDC_VERSION)
2319 ql_log(ql_log_info, vha, 0xb083,
2320 "qla2xxx driver IDC version %d is not compatible "
2321 "with IDC version %d of the other drivers\n",
2322 QLA82XX_IDC_VERSION, idc_ver);
2327 qla82xx_set_drv_active(scsi_qla_host_t *vha)
2329 uint32_t drv_active;
2330 struct qla_hw_data *ha = vha->hw;
2332 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
2334 /* If reset value is all FF's, initialize DRV_ACTIVE */
2335 if (drv_active == 0xffffffff) {
2336 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_ACTIVE,
2337 QLA82XX_DRV_NOT_ACTIVE);
2338 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
2340 drv_active |= (QLA82XX_DRV_ACTIVE << (ha->portnum * 4));
2341 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_ACTIVE, drv_active);
2345 qla82xx_clear_drv_active(struct qla_hw_data *ha)
2347 uint32_t drv_active;
2349 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
2350 drv_active &= ~(QLA82XX_DRV_ACTIVE << (ha->portnum * 4));
2351 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_ACTIVE, drv_active);
2355 qla82xx_need_reset(struct qla_hw_data *ha)
2360 if (ha->flags.nic_core_reset_owner)
2363 drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
2364 rval = drv_state & (QLA82XX_DRVST_RST_RDY << (ha->portnum * 4));
2370 qla82xx_set_rst_ready(struct qla_hw_data *ha)
2373 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
2375 drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
2377 /* If reset value is all FF's, initialize DRV_STATE */
2378 if (drv_state == 0xffffffff) {
2379 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, QLA82XX_DRVST_NOT_RDY);
2380 drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
2382 drv_state |= (QLA82XX_DRVST_RST_RDY << (ha->portnum * 4));
2383 ql_dbg(ql_dbg_init, vha, 0x00bb,
2384 "drv_state = 0x%08x.\n", drv_state);
2385 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, drv_state);
2389 qla82xx_clear_rst_ready(struct qla_hw_data *ha)
2393 drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
2394 drv_state &= ~(QLA82XX_DRVST_RST_RDY << (ha->portnum * 4));
2395 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, drv_state);
2399 qla82xx_set_qsnt_ready(struct qla_hw_data *ha)
2401 uint32_t qsnt_state;
2403 qsnt_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
2404 qsnt_state |= (QLA82XX_DRVST_QSNT_RDY << (ha->portnum * 4));
2405 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, qsnt_state);
2409 qla82xx_clear_qsnt_ready(scsi_qla_host_t *vha)
2411 struct qla_hw_data *ha = vha->hw;
2412 uint32_t qsnt_state;
2414 qsnt_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
2415 qsnt_state &= ~(QLA82XX_DRVST_QSNT_RDY << (ha->portnum * 4));
2416 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, qsnt_state);
2420 qla82xx_load_fw(scsi_qla_host_t *vha)
2423 struct fw_blob *blob;
2424 struct qla_hw_data *ha = vha->hw;
2426 if (qla82xx_pinit_from_rom(vha) != QLA_SUCCESS) {
2427 ql_log(ql_log_fatal, vha, 0x009f,
2428 "Error during CRB initialization.\n");
2429 return QLA_FUNCTION_FAILED;
2433 /* Bring QM and CAMRAM out of reset */
2434 rst = qla82xx_rd_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET);
2435 rst &= ~((1 << 28) | (1 << 24));
2436 qla82xx_wr_32(ha, QLA82XX_ROMUSB_GLB_SW_RESET, rst);
2440 * 1) Operational firmware residing in flash.
2441 * 2) Firmware via request-firmware interface (.bin file).
2443 if (ql2xfwloadbin == 2)
2446 ql_log(ql_log_info, vha, 0x00a0,
2447 "Attempting to load firmware from flash.\n");
2449 if (qla82xx_fw_load_from_flash(ha) == QLA_SUCCESS) {
2450 ql_log(ql_log_info, vha, 0x00a1,
2451 "Firmware loaded successfully from flash.\n");
2454 ql_log(ql_log_warn, vha, 0x0108,
2455 "Firmware load from flash failed.\n");
2459 ql_log(ql_log_info, vha, 0x00a2,
2460 "Attempting to load firmware from blob.\n");
2462 /* Load firmware blob. */
2463 blob = ha->hablob = qla2x00_request_firmware(vha);
2465 ql_log(ql_log_fatal, vha, 0x00a3,
2466 "Firmware image not present.\n");
2467 goto fw_load_failed;
2470 /* Validating firmware blob */
2471 if (qla82xx_validate_firmware_blob(vha,
2472 QLA82XX_FLASH_ROMIMAGE)) {
2473 /* Fallback to URI format */
2474 if (qla82xx_validate_firmware_blob(vha,
2475 QLA82XX_UNIFIED_ROMIMAGE)) {
2476 ql_log(ql_log_fatal, vha, 0x00a4,
2477 "No valid firmware image found.\n");
2478 return QLA_FUNCTION_FAILED;
2482 if (qla82xx_fw_load_from_blob(ha) == QLA_SUCCESS) {
2483 ql_log(ql_log_info, vha, 0x00a5,
2484 "Firmware loaded successfully from binary blob.\n");
2488 ql_log(ql_log_fatal, vha, 0x00a6,
2489 "Firmware load failed for binary blob.\n");
2494 return QLA_FUNCTION_FAILED;
2498 qla82xx_start_firmware(scsi_qla_host_t *vha)
2501 struct qla_hw_data *ha = vha->hw;
2503 /* scrub dma mask expansion register */
2504 qla82xx_wr_32(ha, CRB_DMA_SHIFT, QLA82XX_DMA_SHIFT_VALUE);
2506 /* Put both the PEG CMD and RCV PEG to default state
2507 * of 0 before resetting the hardware
2509 qla82xx_wr_32(ha, CRB_CMDPEG_STATE, 0);
2510 qla82xx_wr_32(ha, CRB_RCVPEG_STATE, 0);
2512 /* Overwrite stale initialization register values */
2513 qla82xx_wr_32(ha, QLA82XX_PEG_HALT_STATUS1, 0);
2514 qla82xx_wr_32(ha, QLA82XX_PEG_HALT_STATUS2, 0);
2516 if (qla82xx_load_fw(vha) != QLA_SUCCESS) {
2517 ql_log(ql_log_fatal, vha, 0x00a7,
2518 "Error trying to start fw.\n");
2519 return QLA_FUNCTION_FAILED;
2522 /* Handshake with the card before we register the devices. */
2523 if (qla82xx_check_cmdpeg_state(ha) != QLA_SUCCESS) {
2524 ql_log(ql_log_fatal, vha, 0x00aa,
2525 "Error during card handshake.\n");
2526 return QLA_FUNCTION_FAILED;
2529 /* Negotiated Link width */
2530 pcie_capability_read_word(ha->pdev, PCI_EXP_LNKSTA, &lnk);
2531 ha->link_width = (lnk >> 4) & 0x3f;
2533 /* Synchronize with Receive peg */
2534 return qla82xx_check_rcvpeg_state(ha);
2538 qla82xx_read_flash_data(scsi_qla_host_t *vha, uint32_t *dwptr, uint32_t faddr,
2543 struct qla_hw_data *ha = vha->hw;
2545 /* Dword reads to flash. */
2546 for (i = 0; i < length/4; i++, faddr += 4) {
2547 if (qla82xx_rom_fast_read(ha, faddr, &val)) {
2548 ql_log(ql_log_warn, vha, 0x0106,
2549 "Do ROM fast read failed.\n");
2552 dwptr[i] = cpu_to_le32(val);
2559 qla82xx_unprotect_flash(struct qla_hw_data *ha)
2563 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
2565 ret = ql82xx_rom_lock_d(ha);
2567 ql_log(ql_log_warn, vha, 0xb014,
2568 "ROM Lock failed.\n");
2572 ret = qla82xx_read_status_reg(ha, &val);
2574 goto done_unprotect;
2576 val &= ~(BLOCK_PROTECT_BITS << 2);
2577 ret = qla82xx_write_status_reg(ha, val);
2579 val |= (BLOCK_PROTECT_BITS << 2);
2580 qla82xx_write_status_reg(ha, val);
2583 if (qla82xx_write_disable_flash(ha) != 0)
2584 ql_log(ql_log_warn, vha, 0xb015,
2585 "Write disable failed.\n");
2588 qla82xx_rom_unlock(ha);
2593 qla82xx_protect_flash(struct qla_hw_data *ha)
2597 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
2599 ret = ql82xx_rom_lock_d(ha);
2601 ql_log(ql_log_warn, vha, 0xb016,
2602 "ROM Lock failed.\n");
2606 ret = qla82xx_read_status_reg(ha, &val);
2610 val |= (BLOCK_PROTECT_BITS << 2);
2611 /* LOCK all sectors */
2612 ret = qla82xx_write_status_reg(ha, val);
2614 ql_log(ql_log_warn, vha, 0xb017,
2615 "Write status register failed.\n");
2617 if (qla82xx_write_disable_flash(ha) != 0)
2618 ql_log(ql_log_warn, vha, 0xb018,
2619 "Write disable failed.\n");
2621 qla82xx_rom_unlock(ha);
2626 qla82xx_erase_sector(struct qla_hw_data *ha, int addr)
2629 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
2631 ret = ql82xx_rom_lock_d(ha);
2633 ql_log(ql_log_warn, vha, 0xb019,
2634 "ROM Lock failed.\n");
2638 qla82xx_flash_set_write_enable(ha);
2639 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ADDRESS, addr);
2640 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_ABYTE_CNT, 3);
2641 qla82xx_wr_32(ha, QLA82XX_ROMUSB_ROM_INSTR_OPCODE, M25P_INSTR_SE);
2643 if (qla82xx_wait_rom_done(ha)) {
2644 ql_log(ql_log_warn, vha, 0xb01a,
2645 "Error waiting for rom done.\n");
2649 ret = qla82xx_flash_wait_write_finish(ha);
2651 qla82xx_rom_unlock(ha);
2656 * Address and length are byte address
2659 qla82xx_read_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
2660 uint32_t offset, uint32_t length)
2662 scsi_block_requests(vha->host);
2663 qla82xx_read_flash_data(vha, (uint32_t *)buf, offset, length);
2664 scsi_unblock_requests(vha->host);
2669 qla82xx_write_flash_data(struct scsi_qla_host *vha, uint32_t *dwptr,
2670 uint32_t faddr, uint32_t dwords)
2675 dma_addr_t optrom_dma;
2676 void *optrom = NULL;
2678 struct qla_hw_data *ha = vha->hw;
2682 /* Prepare burst-capable write on supported ISPs. */
2683 if (page_mode && !(faddr & 0xfff) &&
2684 dwords > OPTROM_BURST_DWORDS) {
2685 optrom = dma_alloc_coherent(&ha->pdev->dev, OPTROM_BURST_SIZE,
2686 &optrom_dma, GFP_KERNEL);
2688 ql_log(ql_log_warn, vha, 0xb01b,
2689 "Unable to allocate memory "
2690 "for optrom burst write (%x KB).\n",
2691 OPTROM_BURST_SIZE / 1024);
2695 rest_addr = ha->fdt_block_size - 1;
2697 ret = qla82xx_unprotect_flash(ha);
2699 ql_log(ql_log_warn, vha, 0xb01c,
2700 "Unable to unprotect flash for update.\n");
2704 for (liter = 0; liter < dwords; liter++, faddr += 4, dwptr++) {
2705 /* Are we at the beginning of a sector? */
2706 if ((faddr & rest_addr) == 0) {
2708 ret = qla82xx_erase_sector(ha, faddr);
2710 ql_log(ql_log_warn, vha, 0xb01d,
2711 "Unable to erase sector: address=%x.\n",
2717 /* Go with burst-write. */
2718 if (optrom && (liter + OPTROM_BURST_DWORDS) <= dwords) {
2719 /* Copy data to DMA'ble buffer. */
2720 memcpy(optrom, dwptr, OPTROM_BURST_SIZE);
2722 ret = qla2x00_load_ram(vha, optrom_dma,
2723 (ha->flash_data_off | faddr),
2724 OPTROM_BURST_DWORDS);
2725 if (ret != QLA_SUCCESS) {
2726 ql_log(ql_log_warn, vha, 0xb01e,
2727 "Unable to burst-write optrom segment "
2728 "(%x/%x/%llx).\n", ret,
2729 (ha->flash_data_off | faddr),
2730 (unsigned long long)optrom_dma);
2731 ql_log(ql_log_warn, vha, 0xb01f,
2732 "Reverting to slow-write.\n");
2734 dma_free_coherent(&ha->pdev->dev,
2735 OPTROM_BURST_SIZE, optrom, optrom_dma);
2738 liter += OPTROM_BURST_DWORDS - 1;
2739 faddr += OPTROM_BURST_DWORDS - 1;
2740 dwptr += OPTROM_BURST_DWORDS - 1;
2745 ret = qla82xx_write_flash_dword(ha, faddr,
2746 cpu_to_le32(*dwptr));
2748 ql_dbg(ql_dbg_p3p, vha, 0xb020,
2749 "Unable to program flash address=%x data=%x.\n",
2755 ret = qla82xx_protect_flash(ha);
2757 ql_log(ql_log_warn, vha, 0xb021,
2758 "Unable to protect flash after update.\n");
2761 dma_free_coherent(&ha->pdev->dev,
2762 OPTROM_BURST_SIZE, optrom, optrom_dma);
2767 qla82xx_write_optrom_data(struct scsi_qla_host *vha, uint8_t *buf,
2768 uint32_t offset, uint32_t length)
2773 scsi_block_requests(vha->host);
2774 rval = qla82xx_write_flash_data(vha, (uint32_t *)buf, offset,
2776 scsi_unblock_requests(vha->host);
2778 /* Convert return ISP82xx to generic */
2780 rval = QLA_FUNCTION_FAILED;
2787 qla82xx_start_iocbs(scsi_qla_host_t *vha)
2789 struct qla_hw_data *ha = vha->hw;
2790 struct req_que *req = ha->req_q_map[0];
2793 /* Adjust ring index. */
2795 if (req->ring_index == req->length) {
2796 req->ring_index = 0;
2797 req->ring_ptr = req->ring;
2801 dbval = 0x04 | (ha->portnum << 5);
2803 dbval = dbval | (req->id << 8) | (req->ring_index << 16);
2805 qla82xx_wr_32(ha, (unsigned long)ha->nxdb_wr_ptr, dbval);
2807 WRT_REG_DWORD(ha->nxdb_wr_ptr, dbval);
2809 while (RD_REG_DWORD(ha->nxdb_rd_ptr) != dbval) {
2810 WRT_REG_DWORD(ha->nxdb_wr_ptr, dbval);
2817 qla82xx_rom_lock_recovery(struct qla_hw_data *ha)
2819 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
2820 uint32_t lock_owner = 0;
2822 if (qla82xx_rom_lock(ha)) {
2823 lock_owner = qla82xx_rd_32(ha, QLA82XX_ROM_LOCK_ID);
2824 /* Someone else is holding the lock. */
2825 ql_log(ql_log_info, vha, 0xb022,
2826 "Resetting rom_lock, Lock Owner %u.\n", lock_owner);
2829 * Either we got the lock, or someone
2830 * else died while holding it.
2831 * In either case, unlock.
2833 qla82xx_rom_unlock(ha);
2837 * qla82xx_device_bootstrap
2838 * Initialize device, set DEV_READY, start fw
2841 * IDC lock must be held upon entry
2848 qla82xx_device_bootstrap(scsi_qla_host_t *vha)
2850 int rval = QLA_SUCCESS;
2852 uint32_t old_count, count;
2853 struct qla_hw_data *ha = vha->hw;
2856 need_reset = qla82xx_need_reset(ha);
2859 /* We are trying to perform a recovery here. */
2860 if (ha->flags.isp82xx_fw_hung)
2861 qla82xx_rom_lock_recovery(ha);
2863 old_count = qla82xx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
2864 for (i = 0; i < 10; i++) {
2866 count = qla82xx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
2867 if (count != old_count) {
2872 qla82xx_rom_lock_recovery(ha);
2875 /* set to DEV_INITIALIZING */
2876 ql_log(ql_log_info, vha, 0x009e,
2877 "HW State: INITIALIZING.\n");
2878 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
2880 qla82xx_idc_unlock(ha);
2881 rval = qla82xx_start_firmware(vha);
2882 qla82xx_idc_lock(ha);
2884 if (rval != QLA_SUCCESS) {
2885 ql_log(ql_log_fatal, vha, 0x00ad,
2886 "HW State: FAILED.\n");
2887 qla82xx_clear_drv_active(ha);
2888 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA8XXX_DEV_FAILED);
2893 ql_log(ql_log_info, vha, 0x00ae,
2894 "HW State: READY.\n");
2895 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA8XXX_DEV_READY);
2901 * qla82xx_need_qsnt_handler
2902 * Code to start quiescence sequence
2905 * IDC lock must be held upon entry
2911 qla82xx_need_qsnt_handler(scsi_qla_host_t *vha)
2913 struct qla_hw_data *ha = vha->hw;
2914 uint32_t dev_state, drv_state, drv_active;
2915 unsigned long reset_timeout;
2917 if (vha->flags.online) {
2918 /*Block any further I/O and wait for pending cmnds to complete*/
2919 qla2x00_quiesce_io(vha);
2922 /* Set the quiescence ready bit */
2923 qla82xx_set_qsnt_ready(ha);
2925 /*wait for 30 secs for other functions to ack */
2926 reset_timeout = jiffies + (30 * HZ);
2928 drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
2929 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
2930 /* Its 2 that is written when qsnt is acked, moving one bit */
2931 drv_active = drv_active << 0x01;
2933 while (drv_state != drv_active) {
2935 if (time_after_eq(jiffies, reset_timeout)) {
2936 /* quiescence timeout, other functions didn't ack
2937 * changing the state to DEV_READY
2939 ql_log(ql_log_info, vha, 0xb023,
2940 "%s : QUIESCENT TIMEOUT DRV_ACTIVE:%d "
2941 "DRV_STATE:%d.\n", QLA2XXX_DRIVER_NAME,
2942 drv_active, drv_state);
2943 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2945 ql_log(ql_log_info, vha, 0xb025,
2946 "HW State: DEV_READY.\n");
2947 qla82xx_idc_unlock(ha);
2948 qla2x00_perform_loop_resync(vha);
2949 qla82xx_idc_lock(ha);
2951 qla82xx_clear_qsnt_ready(vha);
2955 qla82xx_idc_unlock(ha);
2957 qla82xx_idc_lock(ha);
2959 drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
2960 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
2961 drv_active = drv_active << 0x01;
2963 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2964 /* everyone acked so set the state to DEV_QUIESCENCE */
2965 if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
2966 ql_log(ql_log_info, vha, 0xb026,
2967 "HW State: DEV_QUIESCENT.\n");
2968 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA8XXX_DEV_QUIESCENT);
2973 * qla82xx_wait_for_state_change
2974 * Wait for device state to change from given current state
2977 * IDC lock must not be held upon entry
2980 * Changed device state.
2983 qla82xx_wait_for_state_change(scsi_qla_host_t *vha, uint32_t curr_state)
2985 struct qla_hw_data *ha = vha->hw;
2990 qla82xx_idc_lock(ha);
2991 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2992 qla82xx_idc_unlock(ha);
2993 } while (dev_state == curr_state);
2999 qla8xxx_dev_failed_handler(scsi_qla_host_t *vha)
3001 struct qla_hw_data *ha = vha->hw;
3003 /* Disable the board */
3004 ql_log(ql_log_fatal, vha, 0x00b8,
3005 "Disabling the board.\n");
3007 if (IS_QLA82XX(ha)) {
3008 qla82xx_clear_drv_active(ha);
3009 qla82xx_idc_unlock(ha);
3010 } else if (IS_QLA8044(ha)) {
3011 qla8044_clear_drv_active(ha);
3012 qla8044_idc_unlock(ha);
3015 /* Set DEV_FAILED flag to disable timer */
3016 vha->device_flags |= DFLG_DEV_FAILED;
3017 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
3018 qla2x00_mark_all_devices_lost(vha, 0);
3019 vha->flags.online = 0;
3020 vha->flags.init_done = 0;
3024 * qla82xx_need_reset_handler
3025 * Code to start reset sequence
3028 * IDC lock must be held upon entry
3035 qla82xx_need_reset_handler(scsi_qla_host_t *vha)
3037 uint32_t dev_state, drv_state, drv_active;
3038 uint32_t active_mask = 0;
3039 unsigned long reset_timeout;
3040 struct qla_hw_data *ha = vha->hw;
3041 struct req_que *req = ha->req_q_map[0];
3043 if (vha->flags.online) {
3044 qla82xx_idc_unlock(ha);
3045 qla2x00_abort_isp_cleanup(vha);
3046 ha->isp_ops->get_flash_version(vha, req->ring);
3047 ha->isp_ops->nvram_config(vha);
3048 qla82xx_idc_lock(ha);
3051 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
3052 if (!ha->flags.nic_core_reset_owner) {
3053 ql_dbg(ql_dbg_p3p, vha, 0xb028,
3054 "reset_acknowledged by 0x%x\n", ha->portnum);
3055 qla82xx_set_rst_ready(ha);
3057 active_mask = ~(QLA82XX_DRV_ACTIVE << (ha->portnum * 4));
3058 drv_active &= active_mask;
3059 ql_dbg(ql_dbg_p3p, vha, 0xb029,
3060 "active_mask: 0x%08x\n", active_mask);
3063 /* wait for 10 seconds for reset ack from all functions */
3064 reset_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
3066 drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
3067 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
3068 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
3070 ql_dbg(ql_dbg_p3p, vha, 0xb02a,
3071 "drv_state: 0x%08x, drv_active: 0x%08x, "
3072 "dev_state: 0x%08x, active_mask: 0x%08x\n",
3073 drv_state, drv_active, dev_state, active_mask);
3075 while (drv_state != drv_active &&
3076 dev_state != QLA8XXX_DEV_INITIALIZING) {
3077 if (time_after_eq(jiffies, reset_timeout)) {
3078 ql_log(ql_log_warn, vha, 0x00b5,
3079 "Reset timeout.\n");
3082 qla82xx_idc_unlock(ha);
3084 qla82xx_idc_lock(ha);
3085 drv_state = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_STATE);
3086 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
3087 if (ha->flags.nic_core_reset_owner)
3088 drv_active &= active_mask;
3089 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
3092 ql_dbg(ql_dbg_p3p, vha, 0xb02b,
3093 "drv_state: 0x%08x, drv_active: 0x%08x, "
3094 "dev_state: 0x%08x, active_mask: 0x%08x\n",
3095 drv_state, drv_active, dev_state, active_mask);
3097 ql_log(ql_log_info, vha, 0x00b6,
3098 "Device state is 0x%x = %s.\n",
3100 dev_state < MAX_STATES ? qdev_state(dev_state) : "Unknown");
3102 /* Force to DEV_COLD unless someone else is starting a reset */
3103 if (dev_state != QLA8XXX_DEV_INITIALIZING &&
3104 dev_state != QLA8XXX_DEV_COLD) {
3105 ql_log(ql_log_info, vha, 0x00b7,
3106 "HW State: COLD/RE-INIT.\n");
3107 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE, QLA8XXX_DEV_COLD);
3108 qla82xx_set_rst_ready(ha);
3110 if (qla82xx_md_collect(vha))
3111 ql_log(ql_log_warn, vha, 0xb02c,
3112 "Minidump not collected.\n");
3114 ql_log(ql_log_warn, vha, 0xb04f,
3115 "Minidump disabled.\n");
3120 qla82xx_check_md_needed(scsi_qla_host_t *vha)
3122 struct qla_hw_data *ha = vha->hw;
3123 uint16_t fw_major_version, fw_minor_version, fw_subminor_version;
3124 int rval = QLA_SUCCESS;
3126 fw_major_version = ha->fw_major_version;
3127 fw_minor_version = ha->fw_minor_version;
3128 fw_subminor_version = ha->fw_subminor_version;
3130 rval = qla2x00_get_fw_version(vha);
3131 if (rval != QLA_SUCCESS)
3135 if (!ha->fw_dumped) {
3136 if ((fw_major_version != ha->fw_major_version ||
3137 fw_minor_version != ha->fw_minor_version ||
3138 fw_subminor_version != ha->fw_subminor_version) ||
3139 (ha->prev_minidump_failed)) {
3140 ql_dbg(ql_dbg_p3p, vha, 0xb02d,
3141 "Firmware version differs Previous version: %d:%d:%d - New version: %d:%d:%d, prev_minidump_failed: %d.\n",
3142 fw_major_version, fw_minor_version,
3143 fw_subminor_version,
3144 ha->fw_major_version,
3145 ha->fw_minor_version,
3146 ha->fw_subminor_version,
3147 ha->prev_minidump_failed);
3148 /* Release MiniDump resources */
3149 qla82xx_md_free(vha);
3150 /* ALlocate MiniDump resources */
3151 qla82xx_md_prep(vha);
3154 ql_log(ql_log_info, vha, 0xb02e,
3155 "Firmware dump available to retrieve\n");
3162 qla82xx_check_fw_alive(scsi_qla_host_t *vha)
3164 uint32_t fw_heartbeat_counter;
3167 fw_heartbeat_counter = qla82xx_rd_32(vha->hw,
3168 QLA82XX_PEG_ALIVE_COUNTER);
3169 /* all 0xff, assume AER/EEH in progress, ignore */
3170 if (fw_heartbeat_counter == 0xffffffff) {
3171 ql_dbg(ql_dbg_timer, vha, 0x6003,
3172 "FW heartbeat counter is 0xffffffff, "
3173 "returning status=%d.\n", status);
3176 if (vha->fw_heartbeat_counter == fw_heartbeat_counter) {
3177 vha->seconds_since_last_heartbeat++;
3178 /* FW not alive after 2 seconds */
3179 if (vha->seconds_since_last_heartbeat == 2) {
3180 vha->seconds_since_last_heartbeat = 0;
3184 vha->seconds_since_last_heartbeat = 0;
3185 vha->fw_heartbeat_counter = fw_heartbeat_counter;
3187 ql_dbg(ql_dbg_timer, vha, 0x6004,
3188 "Returning status=%d.\n", status);
3193 * qla82xx_device_state_handler
3194 * Main state handler
3197 * IDC lock must be held upon entry
3204 qla82xx_device_state_handler(scsi_qla_host_t *vha)
3207 uint32_t old_dev_state;
3208 int rval = QLA_SUCCESS;
3209 unsigned long dev_init_timeout;
3210 struct qla_hw_data *ha = vha->hw;
3213 qla82xx_idc_lock(ha);
3214 if (!vha->flags.init_done) {
3215 qla82xx_set_drv_active(vha);
3216 qla82xx_set_idc_version(vha);
3219 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
3220 old_dev_state = dev_state;
3221 ql_log(ql_log_info, vha, 0x009b,
3222 "Device state is 0x%x = %s.\n",
3224 dev_state < MAX_STATES ? qdev_state(dev_state) : "Unknown");
3226 /* wait for 30 seconds for device to go ready */
3227 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
3231 if (time_after_eq(jiffies, dev_init_timeout)) {
3232 ql_log(ql_log_fatal, vha, 0x009c,
3233 "Device init failed.\n");
3234 rval = QLA_FUNCTION_FAILED;
3237 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
3238 if (old_dev_state != dev_state) {
3240 old_dev_state = dev_state;
3242 if (loopcount < 5) {
3243 ql_log(ql_log_info, vha, 0x009d,
3244 "Device state is 0x%x = %s.\n",
3246 dev_state < MAX_STATES ? qdev_state(dev_state) :
3250 switch (dev_state) {
3251 case QLA8XXX_DEV_READY:
3252 ha->flags.nic_core_reset_owner = 0;
3254 case QLA8XXX_DEV_COLD:
3255 rval = qla82xx_device_bootstrap(vha);
3257 case QLA8XXX_DEV_INITIALIZING:
3258 qla82xx_idc_unlock(ha);
3260 qla82xx_idc_lock(ha);
3262 case QLA8XXX_DEV_NEED_RESET:
3263 if (!ql2xdontresethba)
3264 qla82xx_need_reset_handler(vha);
3266 qla82xx_idc_unlock(ha);
3268 qla82xx_idc_lock(ha);
3270 dev_init_timeout = jiffies +
3271 (ha->fcoe_dev_init_timeout * HZ);
3273 case QLA8XXX_DEV_NEED_QUIESCENT:
3274 qla82xx_need_qsnt_handler(vha);
3275 /* Reset timeout value after quiescence handler */
3276 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout\
3279 case QLA8XXX_DEV_QUIESCENT:
3280 /* Owner will exit and other will wait for the state
3283 if (ha->flags.quiesce_owner)
3286 qla82xx_idc_unlock(ha);
3288 qla82xx_idc_lock(ha);
3290 /* Reset timeout value after quiescence handler */
3291 dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout\
3294 case QLA8XXX_DEV_FAILED:
3295 qla8xxx_dev_failed_handler(vha);
3296 rval = QLA_FUNCTION_FAILED;
3299 qla82xx_idc_unlock(ha);
3301 qla82xx_idc_lock(ha);
3306 qla82xx_idc_unlock(ha);
3311 static int qla82xx_check_temp(scsi_qla_host_t *vha)
3313 uint32_t temp, temp_state, temp_val;
3314 struct qla_hw_data *ha = vha->hw;
3316 temp = qla82xx_rd_32(ha, CRB_TEMP_STATE);
3317 temp_state = qla82xx_get_temp_state(temp);
3318 temp_val = qla82xx_get_temp_val(temp);
3320 if (temp_state == QLA82XX_TEMP_PANIC) {
3321 ql_log(ql_log_warn, vha, 0x600e,
3322 "Device temperature %d degrees C exceeds "
3323 " maximum allowed. Hardware has been shut down.\n",
3326 } else if (temp_state == QLA82XX_TEMP_WARN) {
3327 ql_log(ql_log_warn, vha, 0x600f,
3328 "Device temperature %d degrees C exceeds "
3329 "operating range. Immediate action needed.\n",
3335 int qla82xx_read_temperature(scsi_qla_host_t *vha)
3339 temp = qla82xx_rd_32(vha->hw, CRB_TEMP_STATE);
3340 return qla82xx_get_temp_val(temp);
3343 void qla82xx_clear_pending_mbx(scsi_qla_host_t *vha)
3345 struct qla_hw_data *ha = vha->hw;
3347 if (ha->flags.mbox_busy) {
3348 ha->flags.mbox_int = 1;
3349 ha->flags.mbox_busy = 0;
3350 ql_log(ql_log_warn, vha, 0x6010,
3351 "Doing premature completion of mbx command.\n");
3352 if (test_and_clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags))
3353 complete(&ha->mbx_intr_comp);
3357 void qla82xx_watchdog(scsi_qla_host_t *vha)
3359 uint32_t dev_state, halt_status;
3360 struct qla_hw_data *ha = vha->hw;
3362 /* don't poll if reset is going on */
3363 if (!ha->flags.nic_core_reset_hdlr_active) {
3364 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
3365 if (qla82xx_check_temp(vha)) {
3366 set_bit(ISP_UNRECOVERABLE, &vha->dpc_flags);
3367 ha->flags.isp82xx_fw_hung = 1;
3368 qla82xx_clear_pending_mbx(vha);
3369 } else if (dev_state == QLA8XXX_DEV_NEED_RESET &&
3370 !test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) {
3371 ql_log(ql_log_warn, vha, 0x6001,
3372 "Adapter reset needed.\n");
3373 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3374 } else if (dev_state == QLA8XXX_DEV_NEED_QUIESCENT &&
3375 !test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags)) {
3376 ql_log(ql_log_warn, vha, 0x6002,
3377 "Quiescent needed.\n");
3378 set_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags);
3379 } else if (dev_state == QLA8XXX_DEV_FAILED &&
3380 !test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) &&
3381 vha->flags.online == 1) {
3382 ql_log(ql_log_warn, vha, 0xb055,
3383 "Adapter state is failed. Offlining.\n");
3384 set_bit(ISP_UNRECOVERABLE, &vha->dpc_flags);
3385 ha->flags.isp82xx_fw_hung = 1;
3386 qla82xx_clear_pending_mbx(vha);
3388 if (qla82xx_check_fw_alive(vha)) {
3389 ql_dbg(ql_dbg_timer, vha, 0x6011,
3390 "disabling pause transmit on port 0 & 1.\n");
3391 qla82xx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
3392 CRB_NIU_XG_PAUSE_CTL_P0|CRB_NIU_XG_PAUSE_CTL_P1);
3393 halt_status = qla82xx_rd_32(ha,
3394 QLA82XX_PEG_HALT_STATUS1);
3395 ql_log(ql_log_info, vha, 0x6005,
3396 "dumping hw/fw registers:.\n "
3397 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2: 0x%x,.\n "
3398 " PEG_NET_0_PC: 0x%x, PEG_NET_1_PC: 0x%x,.\n "
3399 " PEG_NET_2_PC: 0x%x, PEG_NET_3_PC: 0x%x,.\n "
3400 " PEG_NET_4_PC: 0x%x.\n", halt_status,
3401 qla82xx_rd_32(ha, QLA82XX_PEG_HALT_STATUS2),
3403 QLA82XX_CRB_PEG_NET_0 + 0x3c),
3405 QLA82XX_CRB_PEG_NET_1 + 0x3c),
3407 QLA82XX_CRB_PEG_NET_2 + 0x3c),
3409 QLA82XX_CRB_PEG_NET_3 + 0x3c),
3411 QLA82XX_CRB_PEG_NET_4 + 0x3c));
3412 if (((halt_status & 0x1fffff00) >> 8) == 0x67)
3413 ql_log(ql_log_warn, vha, 0xb052,
3414 "Firmware aborted with "
3415 "error code 0x00006700. Device is "
3417 if (halt_status & HALT_STATUS_UNRECOVERABLE) {
3418 set_bit(ISP_UNRECOVERABLE,
3421 ql_log(ql_log_info, vha, 0x6006,
3422 "Detect abort needed.\n");
3423 set_bit(ISP_ABORT_NEEDED,
3426 ha->flags.isp82xx_fw_hung = 1;
3427 ql_log(ql_log_warn, vha, 0x6007, "Firmware hung.\n");
3428 qla82xx_clear_pending_mbx(vha);
3434 int qla82xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
3437 struct qla_hw_data *ha = vha->hw;
3440 rval = qla82xx_device_state_handler(vha);
3441 else if (IS_QLA8044(ha)) {
3442 qla8044_idc_lock(ha);
3443 /* Decide the reset ownership */
3444 qla83xx_reset_ownership(vha);
3445 qla8044_idc_unlock(ha);
3446 rval = qla8044_device_state_handler(vha);
3452 qla82xx_set_reset_owner(scsi_qla_host_t *vha)
3454 struct qla_hw_data *ha = vha->hw;
3455 uint32_t dev_state = 0;
3458 dev_state = qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
3459 else if (IS_QLA8044(ha))
3460 dev_state = qla8044_rd_direct(vha, QLA8044_CRB_DEV_STATE_INDEX);
3462 if (dev_state == QLA8XXX_DEV_READY) {
3463 ql_log(ql_log_info, vha, 0xb02f,
3464 "HW State: NEED RESET\n");
3465 if (IS_QLA82XX(ha)) {
3466 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3467 QLA8XXX_DEV_NEED_RESET);
3468 ha->flags.nic_core_reset_owner = 1;
3469 ql_dbg(ql_dbg_p3p, vha, 0xb030,
3470 "reset_owner is 0x%x\n", ha->portnum);
3471 } else if (IS_QLA8044(ha))
3472 qla8044_wr_direct(vha, QLA8044_CRB_DEV_STATE_INDEX,
3473 QLA8XXX_DEV_NEED_RESET);
3475 ql_log(ql_log_info, vha, 0xb031,
3476 "Device state is 0x%x = %s.\n",
3478 dev_state < MAX_STATES ? qdev_state(dev_state) : "Unknown");
3483 * Resets ISP and aborts all outstanding commands.
3486 * ha = adapter block pointer.
3492 qla82xx_abort_isp(scsi_qla_host_t *vha)
3495 struct qla_hw_data *ha = vha->hw;
3497 if (vha->device_flags & DFLG_DEV_FAILED) {
3498 ql_log(ql_log_warn, vha, 0x8024,
3499 "Device in failed state, exiting.\n");
3502 ha->flags.nic_core_reset_hdlr_active = 1;
3504 qla82xx_idc_lock(ha);
3505 qla82xx_set_reset_owner(vha);
3506 qla82xx_idc_unlock(ha);
3509 rval = qla82xx_device_state_handler(vha);
3510 else if (IS_QLA8044(ha)) {
3511 qla8044_idc_lock(ha);
3512 /* Decide the reset ownership */
3513 qla83xx_reset_ownership(vha);
3514 qla8044_idc_unlock(ha);
3515 rval = qla8044_device_state_handler(vha);
3518 qla82xx_idc_lock(ha);
3519 qla82xx_clear_rst_ready(ha);
3520 qla82xx_idc_unlock(ha);
3522 if (rval == QLA_SUCCESS) {
3523 ha->flags.isp82xx_fw_hung = 0;
3524 ha->flags.nic_core_reset_hdlr_active = 0;
3525 qla82xx_restart_isp(vha);
3529 vha->flags.online = 1;
3530 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
3531 if (ha->isp_abort_cnt == 0) {
3532 ql_log(ql_log_warn, vha, 0x8027,
3533 "ISP error recover failed - board "
3536 * The next call disables the board
3539 ha->isp_ops->reset_adapter(vha);
3540 vha->flags.online = 0;
3541 clear_bit(ISP_ABORT_RETRY,
3544 } else { /* schedule another ISP abort */
3545 ha->isp_abort_cnt--;
3546 ql_log(ql_log_warn, vha, 0x8036,
3547 "ISP abort - retry remaining %d.\n",
3549 rval = QLA_FUNCTION_FAILED;
3552 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3553 ql_dbg(ql_dbg_taskm, vha, 0x8029,
3554 "ISP error recovery - retrying (%d) more times.\n",
3556 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3557 rval = QLA_FUNCTION_FAILED;
3564 * qla82xx_fcoe_ctx_reset
3565 * Perform a quick reset and aborts all outstanding commands.
3566 * This will only perform an FCoE context reset and avoids a full blown
3570 * ha = adapter block pointer.
3571 * is_reset_path = flag for identifying the reset path.
3576 int qla82xx_fcoe_ctx_reset(scsi_qla_host_t *vha)
3578 int rval = QLA_FUNCTION_FAILED;
3580 if (vha->flags.online) {
3581 /* Abort all outstanding commands, so as to be requeued later */
3582 qla2x00_abort_isp_cleanup(vha);
3585 /* Stop currently executing firmware.
3586 * This will destroy existing FCoE context at the F/W end.
3588 qla2x00_try_to_stop_firmware(vha);
3590 /* Restart. Creates a new FCoE context on INIT_FIRMWARE. */
3591 rval = qla82xx_restart_isp(vha);
3597 * qla2x00_wait_for_fcoe_ctx_reset
3598 * Wait till the FCoE context is reset.
3601 * Does context switching here.
3602 * Release SPIN_LOCK (if any) before calling this routine.
3605 * Success (fcoe_ctx reset is done) : 0
3606 * Failed (fcoe_ctx reset not completed within max loop timout ) : 1
3608 int qla2x00_wait_for_fcoe_ctx_reset(scsi_qla_host_t *vha)
3610 int status = QLA_FUNCTION_FAILED;
3611 unsigned long wait_reset;
3613 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
3614 while ((test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
3615 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
3616 && time_before(jiffies, wait_reset)) {
3618 set_current_state(TASK_UNINTERRUPTIBLE);
3619 schedule_timeout(HZ);
3621 if (!test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) &&
3622 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
3623 status = QLA_SUCCESS;
3627 ql_dbg(ql_dbg_p3p, vha, 0xb027,
3628 "%s: status=%d.\n", __func__, status);
3634 qla82xx_chip_reset_cleanup(scsi_qla_host_t *vha)
3636 int i, fw_state = 0;
3637 unsigned long flags;
3638 struct qla_hw_data *ha = vha->hw;
3640 /* Check if 82XX firmware is alive or not
3641 * We may have arrived here from NEED_RESET
3644 if (!ha->flags.isp82xx_fw_hung) {
3645 for (i = 0; i < 2; i++) {
3648 fw_state = qla82xx_check_fw_alive(vha);
3649 else if (IS_QLA8044(ha))
3650 fw_state = qla8044_check_fw_alive(vha);
3652 ha->flags.isp82xx_fw_hung = 1;
3653 qla82xx_clear_pending_mbx(vha);
3658 ql_dbg(ql_dbg_init, vha, 0x00b0,
3659 "Entered %s fw_hung=%d.\n",
3660 __func__, ha->flags.isp82xx_fw_hung);
3662 /* Abort all commands gracefully if fw NOT hung */
3663 if (!ha->flags.isp82xx_fw_hung) {
3666 struct req_que *req;
3668 spin_lock_irqsave(&ha->hardware_lock, flags);
3669 for (que = 0; que < ha->max_req_queues; que++) {
3670 req = ha->req_q_map[que];
3673 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
3674 sp = req->outstanding_cmds[cnt];
3676 if ((!sp->u.scmd.ctx ||
3678 SRB_FCP_CMND_DMA_VALID)) &&
3679 !ha->flags.isp82xx_fw_hung) {
3680 spin_unlock_irqrestore(
3681 &ha->hardware_lock, flags);
3682 if (ha->isp_ops->abort_command(sp)) {
3683 ql_log(ql_log_info, vha,
3685 "mbx abort failed.\n");
3687 ql_log(ql_log_info, vha,
3689 "mbx abort success.\n");
3691 spin_lock_irqsave(&ha->hardware_lock, flags);
3696 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3698 /* Wait for pending cmds (physical and virtual) to complete */
3699 if (!qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
3700 WAIT_HOST) == QLA_SUCCESS) {
3701 ql_dbg(ql_dbg_init, vha, 0x00b3,
3703 "pending commands.\n");
3708 /* Minidump related functions */
3710 qla82xx_minidump_process_control(scsi_qla_host_t *vha,
3711 qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
3713 struct qla_hw_data *ha = vha->hw;
3714 struct qla82xx_md_entry_crb *crb_entry;
3715 uint32_t read_value, opcode, poll_time;
3716 uint32_t addr, index, crb_addr;
3717 unsigned long wtime;
3718 struct qla82xx_md_template_hdr *tmplt_hdr;
3719 uint32_t rval = QLA_SUCCESS;
3722 tmplt_hdr = (struct qla82xx_md_template_hdr *)ha->md_tmplt_hdr;
3723 crb_entry = (struct qla82xx_md_entry_crb *)entry_hdr;
3724 crb_addr = crb_entry->addr;
3726 for (i = 0; i < crb_entry->op_count; i++) {
3727 opcode = crb_entry->crb_ctrl.opcode;
3728 if (opcode & QLA82XX_DBG_OPCODE_WR) {
3729 qla82xx_md_rw_32(ha, crb_addr,
3730 crb_entry->value_1, 1);
3731 opcode &= ~QLA82XX_DBG_OPCODE_WR;
3734 if (opcode & QLA82XX_DBG_OPCODE_RW) {
3735 read_value = qla82xx_md_rw_32(ha, crb_addr, 0, 0);
3736 qla82xx_md_rw_32(ha, crb_addr, read_value, 1);
3737 opcode &= ~QLA82XX_DBG_OPCODE_RW;
3740 if (opcode & QLA82XX_DBG_OPCODE_AND) {
3741 read_value = qla82xx_md_rw_32(ha, crb_addr, 0, 0);
3742 read_value &= crb_entry->value_2;
3743 opcode &= ~QLA82XX_DBG_OPCODE_AND;
3744 if (opcode & QLA82XX_DBG_OPCODE_OR) {
3745 read_value |= crb_entry->value_3;
3746 opcode &= ~QLA82XX_DBG_OPCODE_OR;
3748 qla82xx_md_rw_32(ha, crb_addr, read_value, 1);
3751 if (opcode & QLA82XX_DBG_OPCODE_OR) {
3752 read_value = qla82xx_md_rw_32(ha, crb_addr, 0, 0);
3753 read_value |= crb_entry->value_3;
3754 qla82xx_md_rw_32(ha, crb_addr, read_value, 1);
3755 opcode &= ~QLA82XX_DBG_OPCODE_OR;
3758 if (opcode & QLA82XX_DBG_OPCODE_POLL) {
3759 poll_time = crb_entry->crb_strd.poll_timeout;
3760 wtime = jiffies + poll_time;
3761 read_value = qla82xx_md_rw_32(ha, crb_addr, 0, 0);
3764 if ((read_value & crb_entry->value_2)
3765 == crb_entry->value_1)
3767 else if (time_after_eq(jiffies, wtime)) {
3768 /* capturing dump failed */
3769 rval = QLA_FUNCTION_FAILED;
3772 read_value = qla82xx_md_rw_32(ha,
3775 opcode &= ~QLA82XX_DBG_OPCODE_POLL;
3778 if (opcode & QLA82XX_DBG_OPCODE_RDSTATE) {
3779 if (crb_entry->crb_strd.state_index_a) {
3780 index = crb_entry->crb_strd.state_index_a;
3781 addr = tmplt_hdr->saved_state_array[index];
3785 read_value = qla82xx_md_rw_32(ha, addr, 0, 0);
3786 index = crb_entry->crb_ctrl.state_index_v;
3787 tmplt_hdr->saved_state_array[index] = read_value;
3788 opcode &= ~QLA82XX_DBG_OPCODE_RDSTATE;
3791 if (opcode & QLA82XX_DBG_OPCODE_WRSTATE) {
3792 if (crb_entry->crb_strd.state_index_a) {
3793 index = crb_entry->crb_strd.state_index_a;
3794 addr = tmplt_hdr->saved_state_array[index];
3798 if (crb_entry->crb_ctrl.state_index_v) {
3799 index = crb_entry->crb_ctrl.state_index_v;
3801 tmplt_hdr->saved_state_array[index];
3803 read_value = crb_entry->value_1;
3805 qla82xx_md_rw_32(ha, addr, read_value, 1);
3806 opcode &= ~QLA82XX_DBG_OPCODE_WRSTATE;
3809 if (opcode & QLA82XX_DBG_OPCODE_MDSTATE) {
3810 index = crb_entry->crb_ctrl.state_index_v;
3811 read_value = tmplt_hdr->saved_state_array[index];
3812 read_value <<= crb_entry->crb_ctrl.shl;
3813 read_value >>= crb_entry->crb_ctrl.shr;
3814 if (crb_entry->value_2)
3815 read_value &= crb_entry->value_2;
3816 read_value |= crb_entry->value_3;
3817 read_value += crb_entry->value_1;
3818 tmplt_hdr->saved_state_array[index] = read_value;
3819 opcode &= ~QLA82XX_DBG_OPCODE_MDSTATE;
3821 crb_addr += crb_entry->crb_strd.addr_stride;
3827 qla82xx_minidump_process_rdocm(scsi_qla_host_t *vha,
3828 qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
3830 struct qla_hw_data *ha = vha->hw;
3831 uint32_t r_addr, r_stride, loop_cnt, i, r_value;
3832 struct qla82xx_md_entry_rdocm *ocm_hdr;
3833 uint32_t *data_ptr = *d_ptr;
3835 ocm_hdr = (struct qla82xx_md_entry_rdocm *)entry_hdr;
3836 r_addr = ocm_hdr->read_addr;
3837 r_stride = ocm_hdr->read_addr_stride;
3838 loop_cnt = ocm_hdr->op_count;
3840 for (i = 0; i < loop_cnt; i++) {
3841 r_value = RD_REG_DWORD(r_addr + ha->nx_pcibase);
3842 *data_ptr++ = cpu_to_le32(r_value);
3849 qla82xx_minidump_process_rdmux(scsi_qla_host_t *vha,
3850 qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
3852 struct qla_hw_data *ha = vha->hw;
3853 uint32_t r_addr, s_stride, s_addr, s_value, loop_cnt, i, r_value;
3854 struct qla82xx_md_entry_mux *mux_hdr;
3855 uint32_t *data_ptr = *d_ptr;
3857 mux_hdr = (struct qla82xx_md_entry_mux *)entry_hdr;
3858 r_addr = mux_hdr->read_addr;
3859 s_addr = mux_hdr->select_addr;
3860 s_stride = mux_hdr->select_value_stride;
3861 s_value = mux_hdr->select_value;
3862 loop_cnt = mux_hdr->op_count;
3864 for (i = 0; i < loop_cnt; i++) {
3865 qla82xx_md_rw_32(ha, s_addr, s_value, 1);
3866 r_value = qla82xx_md_rw_32(ha, r_addr, 0, 0);
3867 *data_ptr++ = cpu_to_le32(s_value);
3868 *data_ptr++ = cpu_to_le32(r_value);
3869 s_value += s_stride;
3875 qla82xx_minidump_process_rdcrb(scsi_qla_host_t *vha,
3876 qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
3878 struct qla_hw_data *ha = vha->hw;
3879 uint32_t r_addr, r_stride, loop_cnt, i, r_value;
3880 struct qla82xx_md_entry_crb *crb_hdr;
3881 uint32_t *data_ptr = *d_ptr;
3883 crb_hdr = (struct qla82xx_md_entry_crb *)entry_hdr;
3884 r_addr = crb_hdr->addr;
3885 r_stride = crb_hdr->crb_strd.addr_stride;
3886 loop_cnt = crb_hdr->op_count;
3888 for (i = 0; i < loop_cnt; i++) {
3889 r_value = qla82xx_md_rw_32(ha, r_addr, 0, 0);
3890 *data_ptr++ = cpu_to_le32(r_addr);
3891 *data_ptr++ = cpu_to_le32(r_value);
3898 qla82xx_minidump_process_l2tag(scsi_qla_host_t *vha,
3899 qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
3901 struct qla_hw_data *ha = vha->hw;
3902 uint32_t addr, r_addr, c_addr, t_r_addr;
3903 uint32_t i, k, loop_count, t_value, r_cnt, r_value;
3904 unsigned long p_wait, w_time, p_mask;
3905 uint32_t c_value_w, c_value_r;
3906 struct qla82xx_md_entry_cache *cache_hdr;
3907 int rval = QLA_FUNCTION_FAILED;
3908 uint32_t *data_ptr = *d_ptr;
3910 cache_hdr = (struct qla82xx_md_entry_cache *)entry_hdr;
3911 loop_count = cache_hdr->op_count;
3912 r_addr = cache_hdr->read_addr;
3913 c_addr = cache_hdr->control_addr;
3914 c_value_w = cache_hdr->cache_ctrl.write_value;
3916 t_r_addr = cache_hdr->tag_reg_addr;
3917 t_value = cache_hdr->addr_ctrl.init_tag_value;
3918 r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
3919 p_wait = cache_hdr->cache_ctrl.poll_wait;
3920 p_mask = cache_hdr->cache_ctrl.poll_mask;
3922 for (i = 0; i < loop_count; i++) {
3923 qla82xx_md_rw_32(ha, t_r_addr, t_value, 1);
3925 qla82xx_md_rw_32(ha, c_addr, c_value_w, 1);
3928 w_time = jiffies + p_wait;
3930 c_value_r = qla82xx_md_rw_32(ha, c_addr, 0, 0);
3931 if ((c_value_r & p_mask) == 0)
3933 else if (time_after_eq(jiffies, w_time)) {
3934 /* capturing dump failed */
3935 ql_dbg(ql_dbg_p3p, vha, 0xb032,
3936 "c_value_r: 0x%x, poll_mask: 0x%lx, "
3938 c_value_r, p_mask, w_time);
3945 for (k = 0; k < r_cnt; k++) {
3946 r_value = qla82xx_md_rw_32(ha, addr, 0, 0);
3947 *data_ptr++ = cpu_to_le32(r_value);
3948 addr += cache_hdr->read_ctrl.read_addr_stride;
3950 t_value += cache_hdr->addr_ctrl.tag_value_stride;
3957 qla82xx_minidump_process_l1cache(scsi_qla_host_t *vha,
3958 qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
3960 struct qla_hw_data *ha = vha->hw;
3961 uint32_t addr, r_addr, c_addr, t_r_addr;
3962 uint32_t i, k, loop_count, t_value, r_cnt, r_value;
3964 struct qla82xx_md_entry_cache *cache_hdr;
3965 uint32_t *data_ptr = *d_ptr;
3967 cache_hdr = (struct qla82xx_md_entry_cache *)entry_hdr;
3968 loop_count = cache_hdr->op_count;
3969 r_addr = cache_hdr->read_addr;
3970 c_addr = cache_hdr->control_addr;
3971 c_value_w = cache_hdr->cache_ctrl.write_value;
3973 t_r_addr = cache_hdr->tag_reg_addr;
3974 t_value = cache_hdr->addr_ctrl.init_tag_value;
3975 r_cnt = cache_hdr->read_ctrl.read_addr_cnt;
3977 for (i = 0; i < loop_count; i++) {
3978 qla82xx_md_rw_32(ha, t_r_addr, t_value, 1);
3979 qla82xx_md_rw_32(ha, c_addr, c_value_w, 1);
3981 for (k = 0; k < r_cnt; k++) {
3982 r_value = qla82xx_md_rw_32(ha, addr, 0, 0);
3983 *data_ptr++ = cpu_to_le32(r_value);
3984 addr += cache_hdr->read_ctrl.read_addr_stride;
3986 t_value += cache_hdr->addr_ctrl.tag_value_stride;
3992 qla82xx_minidump_process_queue(scsi_qla_host_t *vha,
3993 qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
3995 struct qla_hw_data *ha = vha->hw;
3996 uint32_t s_addr, r_addr;
3997 uint32_t r_stride, r_value, r_cnt, qid = 0;
3998 uint32_t i, k, loop_cnt;
3999 struct qla82xx_md_entry_queue *q_hdr;
4000 uint32_t *data_ptr = *d_ptr;
4002 q_hdr = (struct qla82xx_md_entry_queue *)entry_hdr;
4003 s_addr = q_hdr->select_addr;
4004 r_cnt = q_hdr->rd_strd.read_addr_cnt;
4005 r_stride = q_hdr->rd_strd.read_addr_stride;
4006 loop_cnt = q_hdr->op_count;
4008 for (i = 0; i < loop_cnt; i++) {
4009 qla82xx_md_rw_32(ha, s_addr, qid, 1);
4010 r_addr = q_hdr->read_addr;
4011 for (k = 0; k < r_cnt; k++) {
4012 r_value = qla82xx_md_rw_32(ha, r_addr, 0, 0);
4013 *data_ptr++ = cpu_to_le32(r_value);
4016 qid += q_hdr->q_strd.queue_id_stride;
4022 qla82xx_minidump_process_rdrom(scsi_qla_host_t *vha,
4023 qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
4025 struct qla_hw_data *ha = vha->hw;
4026 uint32_t r_addr, r_value;
4027 uint32_t i, loop_cnt;
4028 struct qla82xx_md_entry_rdrom *rom_hdr;
4029 uint32_t *data_ptr = *d_ptr;
4031 rom_hdr = (struct qla82xx_md_entry_rdrom *)entry_hdr;
4032 r_addr = rom_hdr->read_addr;
4033 loop_cnt = rom_hdr->read_data_size/sizeof(uint32_t);
4035 for (i = 0; i < loop_cnt; i++) {
4036 qla82xx_md_rw_32(ha, MD_DIRECT_ROM_WINDOW,
4037 (r_addr & 0xFFFF0000), 1);
4038 r_value = qla82xx_md_rw_32(ha,
4039 MD_DIRECT_ROM_READ_BASE +
4040 (r_addr & 0x0000FFFF), 0, 0);
4041 *data_ptr++ = cpu_to_le32(r_value);
4042 r_addr += sizeof(uint32_t);
4048 qla82xx_minidump_process_rdmem(scsi_qla_host_t *vha,
4049 qla82xx_md_entry_hdr_t *entry_hdr, uint32_t **d_ptr)
4051 struct qla_hw_data *ha = vha->hw;
4052 uint32_t r_addr, r_value, r_data;
4053 uint32_t i, j, loop_cnt;
4054 struct qla82xx_md_entry_rdmem *m_hdr;
4055 unsigned long flags;
4056 int rval = QLA_FUNCTION_FAILED;
4057 uint32_t *data_ptr = *d_ptr;
4059 m_hdr = (struct qla82xx_md_entry_rdmem *)entry_hdr;
4060 r_addr = m_hdr->read_addr;
4061 loop_cnt = m_hdr->read_data_size/16;
4064 ql_log(ql_log_warn, vha, 0xb033,
4065 "Read addr 0x%x not 16 bytes aligned\n", r_addr);
4069 if (m_hdr->read_data_size % 16) {
4070 ql_log(ql_log_warn, vha, 0xb034,
4071 "Read data[0x%x] not multiple of 16 bytes\n",
4072 m_hdr->read_data_size);
4076 ql_dbg(ql_dbg_p3p, vha, 0xb035,
4077 "[%s]: rdmem_addr: 0x%x, read_data_size: 0x%x, loop_cnt: 0x%x\n",
4078 __func__, r_addr, m_hdr->read_data_size, loop_cnt);
4080 write_lock_irqsave(&ha->hw_lock, flags);
4081 for (i = 0; i < loop_cnt; i++) {
4082 qla82xx_md_rw_32(ha, MD_MIU_TEST_AGT_ADDR_LO, r_addr, 1);
4084 qla82xx_md_rw_32(ha, MD_MIU_TEST_AGT_ADDR_HI, r_value, 1);
4085 r_value = MIU_TA_CTL_ENABLE;
4086 qla82xx_md_rw_32(ha, MD_MIU_TEST_AGT_CTRL, r_value, 1);
4087 r_value = MIU_TA_CTL_START | MIU_TA_CTL_ENABLE;
4088 qla82xx_md_rw_32(ha, MD_MIU_TEST_AGT_CTRL, r_value, 1);
4090 for (j = 0; j < MAX_CTL_CHECK; j++) {
4091 r_value = qla82xx_md_rw_32(ha,
4092 MD_MIU_TEST_AGT_CTRL, 0, 0);
4093 if ((r_value & MIU_TA_CTL_BUSY) == 0)
4097 if (j >= MAX_CTL_CHECK) {
4098 printk_ratelimited(KERN_ERR
4099 "failed to read through agent\n");
4100 write_unlock_irqrestore(&ha->hw_lock, flags);
4104 for (j = 0; j < 4; j++) {
4105 r_data = qla82xx_md_rw_32(ha,
4106 MD_MIU_TEST_AGT_RDDATA[j], 0, 0);
4107 *data_ptr++ = cpu_to_le32(r_data);
4111 write_unlock_irqrestore(&ha->hw_lock, flags);
4117 qla82xx_validate_template_chksum(scsi_qla_host_t *vha)
4119 struct qla_hw_data *ha = vha->hw;
4120 uint64_t chksum = 0;
4121 uint32_t *d_ptr = (uint32_t *)ha->md_tmplt_hdr;
4122 int count = ha->md_template_size/sizeof(uint32_t);
4126 while (chksum >> 32)
4127 chksum = (chksum & 0xFFFFFFFF) + (chksum >> 32);
4132 qla82xx_mark_entry_skipped(scsi_qla_host_t *vha,
4133 qla82xx_md_entry_hdr_t *entry_hdr, int index)
4135 entry_hdr->d_ctrl.driver_flags |= QLA82XX_DBG_SKIPPED_FLAG;
4136 ql_dbg(ql_dbg_p3p, vha, 0xb036,
4137 "Skipping entry[%d]: "
4138 "ETYPE[0x%x]-ELEVEL[0x%x]\n",
4139 index, entry_hdr->entry_type,
4140 entry_hdr->d_ctrl.entry_capture_mask);
4144 qla82xx_md_collect(scsi_qla_host_t *vha)
4146 struct qla_hw_data *ha = vha->hw;
4147 int no_entry_hdr = 0;
4148 qla82xx_md_entry_hdr_t *entry_hdr;
4149 struct qla82xx_md_template_hdr *tmplt_hdr;
4151 uint32_t total_data_size = 0, f_capture_mask, data_collected = 0;
4152 int i = 0, rval = QLA_FUNCTION_FAILED;
4154 tmplt_hdr = (struct qla82xx_md_template_hdr *)ha->md_tmplt_hdr;
4155 data_ptr = (uint32_t *)ha->md_dump;
4157 if (ha->fw_dumped) {
4158 ql_log(ql_log_warn, vha, 0xb037,
4159 "Firmware has been previously dumped (%p) "
4160 "-- ignoring request.\n", ha->fw_dump);
4166 if (!ha->md_tmplt_hdr || !ha->md_dump) {
4167 ql_log(ql_log_warn, vha, 0xb038,
4168 "Memory not allocated for minidump capture\n");
4172 if (ha->flags.isp82xx_no_md_cap) {
4173 ql_log(ql_log_warn, vha, 0xb054,
4174 "Forced reset from application, "
4175 "ignore minidump capture\n");
4176 ha->flags.isp82xx_no_md_cap = 0;
4180 if (qla82xx_validate_template_chksum(vha)) {
4181 ql_log(ql_log_info, vha, 0xb039,
4182 "Template checksum validation error\n");
4186 no_entry_hdr = tmplt_hdr->num_of_entries;
4187 ql_dbg(ql_dbg_p3p, vha, 0xb03a,
4188 "No of entry headers in Template: 0x%x\n", no_entry_hdr);
4190 ql_dbg(ql_dbg_p3p, vha, 0xb03b,
4191 "Capture Mask obtained: 0x%x\n", tmplt_hdr->capture_debug_level);
4193 f_capture_mask = tmplt_hdr->capture_debug_level & 0xFF;
4195 /* Validate whether required debug level is set */
4196 if ((f_capture_mask & 0x3) != 0x3) {
4197 ql_log(ql_log_warn, vha, 0xb03c,
4198 "Minimum required capture mask[0x%x] level not set\n",
4202 tmplt_hdr->driver_capture_mask = ql2xmdcapmask;
4204 tmplt_hdr->driver_info[0] = vha->host_no;
4205 tmplt_hdr->driver_info[1] = (QLA_DRIVER_MAJOR_VER << 24) |
4206 (QLA_DRIVER_MINOR_VER << 16) | (QLA_DRIVER_PATCH_VER << 8) |
4207 QLA_DRIVER_BETA_VER;
4209 total_data_size = ha->md_dump_size;
4211 ql_dbg(ql_dbg_p3p, vha, 0xb03d,
4212 "Total minidump data_size 0x%x to be captured\n", total_data_size);
4214 /* Check whether template obtained is valid */
4215 if (tmplt_hdr->entry_type != QLA82XX_TLHDR) {
4216 ql_log(ql_log_warn, vha, 0xb04e,
4217 "Bad template header entry type: 0x%x obtained\n",
4218 tmplt_hdr->entry_type);
4222 entry_hdr = (qla82xx_md_entry_hdr_t *) \
4223 (((uint8_t *)ha->md_tmplt_hdr) + tmplt_hdr->first_entry_offset);
4225 /* Walk through the entry headers */
4226 for (i = 0; i < no_entry_hdr; i++) {
4228 if (data_collected > total_data_size) {
4229 ql_log(ql_log_warn, vha, 0xb03e,
4230 "More MiniDump data collected: [0x%x]\n",
4235 if (!(entry_hdr->d_ctrl.entry_capture_mask &
4237 entry_hdr->d_ctrl.driver_flags |=
4238 QLA82XX_DBG_SKIPPED_FLAG;
4239 ql_dbg(ql_dbg_p3p, vha, 0xb03f,
4240 "Skipping entry[%d]: "
4241 "ETYPE[0x%x]-ELEVEL[0x%x]\n",
4242 i, entry_hdr->entry_type,
4243 entry_hdr->d_ctrl.entry_capture_mask);
4244 goto skip_nxt_entry;
4247 ql_dbg(ql_dbg_p3p, vha, 0xb040,
4248 "[%s]: data ptr[%d]: %p, entry_hdr: %p\n"
4249 "entry_type: 0x%x, captrue_mask: 0x%x\n",
4250 __func__, i, data_ptr, entry_hdr,
4251 entry_hdr->entry_type,
4252 entry_hdr->d_ctrl.entry_capture_mask);
4254 ql_dbg(ql_dbg_p3p, vha, 0xb041,
4255 "Data collected: [0x%x], Dump size left:[0x%x]\n",
4256 data_collected, (ha->md_dump_size - data_collected));
4258 /* Decode the entry type and take
4259 * required action to capture debug data */
4260 switch (entry_hdr->entry_type) {
4262 qla82xx_mark_entry_skipped(vha, entry_hdr, i);
4265 rval = qla82xx_minidump_process_control(vha,
4266 entry_hdr, &data_ptr);
4267 if (rval != QLA_SUCCESS) {
4268 qla82xx_mark_entry_skipped(vha, entry_hdr, i);
4273 qla82xx_minidump_process_rdcrb(vha,
4274 entry_hdr, &data_ptr);
4277 rval = qla82xx_minidump_process_rdmem(vha,
4278 entry_hdr, &data_ptr);
4279 if (rval != QLA_SUCCESS) {
4280 qla82xx_mark_entry_skipped(vha, entry_hdr, i);
4286 qla82xx_minidump_process_rdrom(vha,
4287 entry_hdr, &data_ptr);
4293 rval = qla82xx_minidump_process_l2tag(vha,
4294 entry_hdr, &data_ptr);
4295 if (rval != QLA_SUCCESS) {
4296 qla82xx_mark_entry_skipped(vha, entry_hdr, i);
4302 qla82xx_minidump_process_l1cache(vha,
4303 entry_hdr, &data_ptr);
4306 qla82xx_minidump_process_rdocm(vha,
4307 entry_hdr, &data_ptr);
4310 qla82xx_minidump_process_rdmux(vha,
4311 entry_hdr, &data_ptr);
4314 qla82xx_minidump_process_queue(vha,
4315 entry_hdr, &data_ptr);
4319 qla82xx_mark_entry_skipped(vha, entry_hdr, i);
4323 ql_dbg(ql_dbg_p3p, vha, 0xb042,
4324 "[%s]: data ptr[%d]: %p\n", __func__, i, data_ptr);
4326 data_collected = (uint8_t *)data_ptr -
4327 (uint8_t *)ha->md_dump;
4329 entry_hdr = (qla82xx_md_entry_hdr_t *) \
4330 (((uint8_t *)entry_hdr) + entry_hdr->entry_size);
4333 if (data_collected != total_data_size) {
4334 ql_dbg(ql_dbg_p3p, vha, 0xb043,
4335 "MiniDump data mismatch: Data collected: [0x%x],"
4336 "total_data_size:[0x%x]\n",
4337 data_collected, total_data_size);
4341 ql_log(ql_log_info, vha, 0xb044,
4342 "Firmware dump saved to temp buffer (%ld/%p %ld/%p).\n",
4343 vha->host_no, ha->md_tmplt_hdr, vha->host_no, ha->md_dump);
4345 qla2x00_post_uevent_work(vha, QLA_UEVENT_CODE_FW_DUMP);
4352 qla82xx_md_alloc(scsi_qla_host_t *vha)
4354 struct qla_hw_data *ha = vha->hw;
4356 struct qla82xx_md_template_hdr *tmplt_hdr;
4358 tmplt_hdr = (struct qla82xx_md_template_hdr *)ha->md_tmplt_hdr;
4360 if (ql2xmdcapmask < 0x3 || ql2xmdcapmask > 0x7F) {
4361 ql2xmdcapmask = tmplt_hdr->capture_debug_level & 0xFF;
4362 ql_log(ql_log_info, vha, 0xb045,
4363 "Forcing driver capture mask to firmware default capture mask: 0x%x.\n",
4367 for (i = 0x2, k = 1; (i & QLA82XX_DEFAULT_CAP_MASK); i <<= 1, k++) {
4368 if (i & ql2xmdcapmask)
4369 ha->md_dump_size += tmplt_hdr->capture_size_array[k];
4373 ql_log(ql_log_warn, vha, 0xb046,
4374 "Firmware dump previously allocated.\n");
4378 ha->md_dump = vmalloc(ha->md_dump_size);
4379 if (ha->md_dump == NULL) {
4380 ql_log(ql_log_warn, vha, 0xb047,
4381 "Unable to allocate memory for Minidump size "
4382 "(0x%x).\n", ha->md_dump_size);
4389 qla82xx_md_free(scsi_qla_host_t *vha)
4391 struct qla_hw_data *ha = vha->hw;
4393 /* Release the template header allocated */
4394 if (ha->md_tmplt_hdr) {
4395 ql_log(ql_log_info, vha, 0xb048,
4396 "Free MiniDump template: %p, size (%d KB)\n",
4397 ha->md_tmplt_hdr, ha->md_template_size / 1024);
4398 dma_free_coherent(&ha->pdev->dev, ha->md_template_size,
4399 ha->md_tmplt_hdr, ha->md_tmplt_hdr_dma);
4400 ha->md_tmplt_hdr = NULL;
4403 /* Release the template data buffer allocated */
4405 ql_log(ql_log_info, vha, 0xb049,
4406 "Free MiniDump memory: %p, size (%d KB)\n",
4407 ha->md_dump, ha->md_dump_size / 1024);
4409 ha->md_dump_size = 0;
4415 qla82xx_md_prep(scsi_qla_host_t *vha)
4417 struct qla_hw_data *ha = vha->hw;
4420 /* Get Minidump template size */
4421 rval = qla82xx_md_get_template_size(vha);
4422 if (rval == QLA_SUCCESS) {
4423 ql_log(ql_log_info, vha, 0xb04a,
4424 "MiniDump Template size obtained (%d KB)\n",
4425 ha->md_template_size / 1024);
4427 /* Get Minidump template */
4429 rval = qla8044_md_get_template(vha);
4431 rval = qla82xx_md_get_template(vha);
4433 if (rval == QLA_SUCCESS) {
4434 ql_dbg(ql_dbg_p3p, vha, 0xb04b,
4435 "MiniDump Template obtained\n");
4437 /* Allocate memory for minidump */
4438 rval = qla82xx_md_alloc(vha);
4439 if (rval == QLA_SUCCESS)
4440 ql_log(ql_log_info, vha, 0xb04c,
4441 "MiniDump memory allocated (%d KB)\n",
4442 ha->md_dump_size / 1024);
4444 ql_log(ql_log_info, vha, 0xb04d,
4445 "Free MiniDump template: %p, size: (%d KB)\n",
4447 ha->md_template_size / 1024);
4448 dma_free_coherent(&ha->pdev->dev,
4449 ha->md_template_size,
4450 ha->md_tmplt_hdr, ha->md_tmplt_hdr_dma);
4451 ha->md_tmplt_hdr = NULL;
4459 qla82xx_beacon_on(struct scsi_qla_host *vha)
4463 struct qla_hw_data *ha = vha->hw;
4464 qla82xx_idc_lock(ha);
4465 rval = qla82xx_mbx_beacon_ctl(vha, 1);
4468 ql_log(ql_log_warn, vha, 0xb050,
4469 "mbx set led config failed in %s\n", __func__);
4472 ha->beacon_blink_led = 1;
4474 qla82xx_idc_unlock(ha);
4479 qla82xx_beacon_off(struct scsi_qla_host *vha)
4483 struct qla_hw_data *ha = vha->hw;
4484 qla82xx_idc_lock(ha);
4485 rval = qla82xx_mbx_beacon_ctl(vha, 0);
4488 ql_log(ql_log_warn, vha, 0xb051,
4489 "mbx set led config failed in %s\n", __func__);
4492 ha->beacon_blink_led = 0;
4494 qla82xx_idc_unlock(ha);
4499 qla82xx_fw_dump(scsi_qla_host_t *vha, int hardware_locked)
4501 struct qla_hw_data *ha = vha->hw;
4503 if (!ha->allow_cna_fw_dump)
4506 scsi_block_requests(vha->host);
4507 ha->flags.isp82xx_no_md_cap = 1;
4508 qla82xx_idc_lock(ha);
4509 qla82xx_set_reset_owner(vha);
4510 qla82xx_idc_unlock(ha);
4511 qla2x00_wait_for_chip_reset(vha);
4512 scsi_unblock_requests(vha->host);