qla_init.c 142 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
/*
2
 * QLogic Fibre Channel HBA Driver
3
 * Copyright (c)  2003-2008 QLogic Corporation
Linus Torvalds's avatar
Linus Torvalds committed
4
 *
5
 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds's avatar
Linus Torvalds committed
6
7
 */
#include "qla_def.h"
8
#include "qla_gbl.h"
Linus Torvalds's avatar
Linus Torvalds committed
9
10

#include <linux/delay.h>
11
#include <linux/slab.h>
12
#include <linux/vmalloc.h>
Linus Torvalds's avatar
Linus Torvalds committed
13
14
15

#include "qla_devtbl.h"

16
17
18
19
#ifdef CONFIG_SPARC
#include <asm/prom.h>
#endif

Linus Torvalds's avatar
Linus Torvalds committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
*  QLogic ISP2x00 Hardware Support Function Prototypes.
*/
static int qla2x00_isp_firmware(scsi_qla_host_t *);
static int qla2x00_setup_chip(scsi_qla_host_t *);
static int qla2x00_init_rings(scsi_qla_host_t *);
static int qla2x00_fw_ready(scsi_qla_host_t *);
static int qla2x00_configure_hba(scsi_qla_host_t *);
static int qla2x00_configure_loop(scsi_qla_host_t *);
static int qla2x00_configure_local_loop(scsi_qla_host_t *);
static int qla2x00_configure_fabric(scsi_qla_host_t *);
static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
static int qla2x00_device_resync(scsi_qla_host_t *);
static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
    uint16_t *);

static int qla2x00_restart_isp(scsi_qla_host_t *);

38
static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
39

40
41
static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
static int qla84xx_init_chip(scsi_qla_host_t *);
42
static int qla25xx_init_queues(struct qla_hw_data *);
43

44
45
46
47
48
49
50
/* SRB Extensions ---------------------------------------------------------- */

static void
qla2x00_ctx_sp_timeout(unsigned long __data)
{
	srb_t *sp = (srb_t *)__data;
	struct srb_ctx *ctx;
51
	struct srb_iocb *iocb;
52
53
54
55
56
57
58
59
60
	fc_port_t *fcport = sp->fcport;
	struct qla_hw_data *ha = fcport->vha->hw;
	struct req_que *req;
	unsigned long flags;

	spin_lock_irqsave(&ha->hardware_lock, flags);
	req = ha->req_q_map[0];
	req->outstanding_cmds[sp->handle] = NULL;
	ctx = sp->ctx;
61
62
63
	iocb = ctx->u.iocb_cmd;
	iocb->timeout(sp);
	iocb->free(sp);
64
	spin_unlock_irqrestore(&ha->hardware_lock, flags);
65
66
}

67
void
68
69
70
qla2x00_ctx_sp_free(srb_t *sp)
{
	struct srb_ctx *ctx = sp->ctx;
71
	struct srb_iocb *iocb = ctx->u.iocb_cmd;
72

73
74
	del_timer_sync(&iocb->timer);
	kfree(iocb);
75
76
77
78
79
80
81
82
83
84
85
	kfree(ctx);
	mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
}

inline srb_t *
qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
    unsigned long tmo)
{
	srb_t *sp;
	struct qla_hw_data *ha = vha->hw;
	struct srb_ctx *ctx;
86
	struct srb_iocb *iocb;
87
88
89
90
91
92
93

	sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
	if (!sp)
		goto done;
	ctx = kzalloc(size, GFP_KERNEL);
	if (!ctx) {
		mempool_free(sp, ha->srb_mempool);
94
95
96
97
98
99
100
101
		sp = NULL;
		goto done;
	}
	iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
	if (!iocb) {
		mempool_free(sp, ha->srb_mempool);
		sp = NULL;
		kfree(ctx);
102
103
104
105
106
107
		goto done;
	}

	memset(sp, 0, sizeof(*sp));
	sp->fcport = fcport;
	sp->ctx = ctx;
108
109
	ctx->u.iocb_cmd = iocb;
	iocb->free = qla2x00_ctx_sp_free;
110

111
	init_timer(&iocb->timer);
112
113
	if (!tmo)
		goto done;
114
115
116
117
	iocb->timer.expires = jiffies + tmo * HZ;
	iocb->timer.data = (unsigned long)sp;
	iocb->timer.function = qla2x00_ctx_sp_timeout;
	add_timer(&iocb->timer);
118
119
120
121
122
123
124
125
126
done:
	return sp;
}

/* Asynchronous Login/Logout Routines -------------------------------------- */

#define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)

static void
127
qla2x00_async_iocb_timeout(srb_t *sp)
128
129
{
	fc_port_t *fcport = sp->fcport;
130
	struct srb_ctx *ctx = sp->ctx;
131
132

	DEBUG2(printk(KERN_WARNING
133
134
135
136
		"scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
		fcport->vha->host_no, sp->handle,
		ctx->name, fcport->d_id.b.domain,
		fcport->d_id.b.area, fcport->d_id.b.al_pa));
137

138
	fcport->flags &= ~FCF_ASYNC_SENT;
139
140
	if (ctx->type == SRB_LOGIN_CMD) {
		struct srb_iocb *lio = ctx->u.iocb_cmd;
141
		qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
142
143
144
145
146
147
148
		/* Retry as needed. */
		lio->u.logio.data[0] = MBS_COMMAND_ERROR;
		lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
			QLA_LOGIO_LOGIN_RETRIED : 0;
		qla2x00_post_async_login_done_work(fcport->vha, fcport,
			lio->u.logio.data);
	}
149
150
}

151
152
153
static void
qla2x00_async_login_ctx_done(srb_t *sp)
{
154
155
	struct srb_ctx *ctx = sp->ctx;
	struct srb_iocb *lio = ctx->u.iocb_cmd;
156
157

	qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
158
159
		lio->u.logio.data);
	lio->free(sp);
160
161
}

162
163
164
165
166
167
int
qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
    uint16_t *data)
{
	struct qla_hw_data *ha = vha->hw;
	srb_t *sp;
168
169
	struct srb_ctx *ctx;
	struct srb_iocb *lio;
170
171
172
	int rval;

	rval = QLA_FUNCTION_FAILED;
173
	sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
174
175
176
177
	    ELS_TMO_2_RATOV(ha) + 2);
	if (!sp)
		goto done;

178
179
180
181
	ctx = sp->ctx;
	ctx->type = SRB_LOGIN_CMD;
	ctx->name = "login";
	lio = ctx->u.iocb_cmd;
182
	lio->timeout = qla2x00_async_iocb_timeout;
183
184
	lio->done = qla2x00_async_login_ctx_done;
	lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
185
	if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
186
		lio->u.logio.flags |= SRB_LOGIN_RETRIED;
187
188
189
190
191
192
193
194
195
196
197
198
	rval = qla2x00_start_sp(sp);
	if (rval != QLA_SUCCESS)
		goto done_free_sp;

	DEBUG2(printk(KERN_DEBUG
	    "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
	    "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
	    fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
	    fcport->login_retry));
	return rval;

done_free_sp:
199
	lio->free(sp);
200
201
202
203
done:
	return rval;
}

204
205
206
static void
qla2x00_async_logout_ctx_done(srb_t *sp)
{
207
208
	struct srb_ctx *ctx = sp->ctx;
	struct srb_iocb *lio = ctx->u.iocb_cmd;
209
210

	qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
211
212
	    lio->u.logio.data);
	lio->free(sp);
213
214
}

215
216
217
218
219
int
qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
{
	struct qla_hw_data *ha = vha->hw;
	srb_t *sp;
220
221
	struct srb_ctx *ctx;
	struct srb_iocb *lio;
222
223
224
	int rval;

	rval = QLA_FUNCTION_FAILED;
225
	sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
226
227
228
229
	    ELS_TMO_2_RATOV(ha) + 2);
	if (!sp)
		goto done;

230
231
232
233
	ctx = sp->ctx;
	ctx->type = SRB_LOGOUT_CMD;
	ctx->name = "logout";
	lio = ctx->u.iocb_cmd;
234
	lio->timeout = qla2x00_async_iocb_timeout;
235
	lio->done = qla2x00_async_logout_ctx_done;
236
237
238
239
240
241
242
243
244
245
246
	rval = qla2x00_start_sp(sp);
	if (rval != QLA_SUCCESS)
		goto done_free_sp;

	DEBUG2(printk(KERN_DEBUG
	    "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
	    fcport->vha->host_no, sp->handle, fcport->loop_id,
	    fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
	return rval;

done_free_sp:
247
	lio->free(sp);
248
249
250
251
done:
	return rval;
}

252
253
254
static void
qla2x00_async_adisc_ctx_done(srb_t *sp)
{
255
256
	struct srb_ctx *ctx = sp->ctx;
	struct srb_iocb *lio = ctx->u.iocb_cmd;
257
258

	qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
259
260
	    lio->u.logio.data);
	lio->free(sp);
261
262
263
264
265
266
267
268
}

int
qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
    uint16_t *data)
{
	struct qla_hw_data *ha = vha->hw;
	srb_t *sp;
269
270
	struct srb_ctx *ctx;
	struct srb_iocb *lio;
271
272
273
	int rval;

	rval = QLA_FUNCTION_FAILED;
274
	sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
275
276
277
278
	    ELS_TMO_2_RATOV(ha) + 2);
	if (!sp)
		goto done;

279
280
281
282
	ctx = sp->ctx;
	ctx->type = SRB_ADISC_CMD;
	ctx->name = "adisc";
	lio = ctx->u.iocb_cmd;
283
	lio->timeout = qla2x00_async_iocb_timeout;
284
	lio->done = qla2x00_async_adisc_ctx_done;
285
	if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
286
		lio->u.logio.flags |= SRB_LOGIN_RETRIED;
287
288
289
290
291
292
293
294
295
296
297
298
	rval = qla2x00_start_sp(sp);
	if (rval != QLA_SUCCESS)
		goto done_free_sp;

	DEBUG2(printk(KERN_DEBUG
	    "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
	    fcport->vha->host_no, sp->handle, fcport->loop_id,
	    fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));

	return rval;

done_free_sp:
299
	lio->free(sp);
300
301
302
303
done:
	return rval;
}

304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
static void
qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
{
	struct srb_ctx *ctx = sp->ctx;
	struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;

	qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
	iocb->free(sp);
}

int
qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
	uint32_t tag)
{
	struct scsi_qla_host *vha = fcport->vha;
	struct qla_hw_data *ha = vha->hw;
	srb_t *sp;
	struct srb_ctx *ctx;
	struct srb_iocb *tcf;
	int rval;

	rval = QLA_FUNCTION_FAILED;
	sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
	    ELS_TMO_2_RATOV(ha) + 2);
	if (!sp)
		goto done;

	ctx = sp->ctx;
	ctx->type = SRB_TM_CMD;
	ctx->name = "tmf";
	tcf = ctx->u.iocb_cmd;
	tcf->u.tmf.flags = flags;
	tcf->u.tmf.lun = lun;
	tcf->u.tmf.data = tag;
	tcf->timeout = qla2x00_async_iocb_timeout;
	tcf->done = qla2x00_async_tm_cmd_ctx_done;

	rval = qla2x00_start_sp(sp);
	if (rval != QLA_SUCCESS)
		goto done_free_sp;

	DEBUG2(printk(KERN_DEBUG
	    "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
	    fcport->vha->host_no, sp->handle, fcport->loop_id,
	    fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));

	return rval;

done_free_sp:
	tcf->free(sp);
done:
	return rval;
}

static void
qla2x00_async_marker_ctx_done(srb_t *sp)
{
	struct srb_ctx *ctx = sp->ctx;
	struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;

	qla2x00_async_marker_done(sp->fcport->vha, sp->fcport, iocb);
	iocb->free(sp);
}

int
qla2x00_async_marker(fc_port_t *fcport, uint16_t lun, uint8_t modif)
{
	struct scsi_qla_host *vha = fcport->vha;
	srb_t *sp;
	struct srb_ctx *ctx;
	struct srb_iocb *mrk;
	int rval;

	rval = QLA_FUNCTION_FAILED;
	sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), 0);
	if (!sp)
		goto done;

	ctx = sp->ctx;
	ctx->type = SRB_MARKER_CMD;
	ctx->name = "marker";
	mrk = ctx->u.iocb_cmd;
	mrk->u.marker.lun = lun;
	mrk->u.marker.modif = modif;
	mrk->timeout = qla2x00_async_iocb_timeout;
	mrk->done = qla2x00_async_marker_ctx_done;

	rval = qla2x00_start_sp(sp);
	if (rval != QLA_SUCCESS)
		goto done_free_sp;

	DEBUG2(printk(KERN_DEBUG
	    "scsi(%ld:%x): Async-marker - loop-id=%x "
	    "portid=%02x%02x%02x.\n",
	    fcport->vha->host_no, sp->handle, fcport->loop_id,
	    fcport->d_id.b.domain, fcport->d_id.b.area,
	    fcport->d_id.b.al_pa));

	return rval;

done_free_sp:
	mrk->free(sp);
done:
	return rval;
}

410
void
411
412
413
414
415
416
417
qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
    uint16_t *data)
{
	int rval;

	switch (data[0]) {
	case MBS_COMMAND_COMPLETE:
418
		if (fcport->flags & FCF_FCP2_DEVICE) {
419
420
421
			fcport->flags |= FCF_ASYNC_SENT;
			qla2x00_post_async_adisc_work(vha, fcport, data);
			break;
422
423
		}
		qla2x00_update_fcport(vha, fcport);
424
425
		break;
	case MBS_COMMAND_ERROR:
426
		fcport->flags &= ~FCF_ASYNC_SENT;
427
428
429
		if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
			set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
		else
430
			qla2x00_mark_device_lost(vha, fcport, 1, 1);
431
432
433
		break;
	case MBS_PORT_ID_USED:
		fcport->loop_id = data[1];
434
		qla2x00_post_async_logout_work(vha, fcport, NULL);
435
436
437
438
439
440
		qla2x00_post_async_login_work(vha, fcport, NULL);
		break;
	case MBS_LOOP_ID_USED:
		fcport->loop_id++;
		rval = qla2x00_find_new_loop_id(vha, fcport);
		if (rval != QLA_SUCCESS) {
441
			fcport->flags &= ~FCF_ASYNC_SENT;
442
			qla2x00_mark_device_lost(vha, fcport, 1, 1);
443
444
445
446
447
			break;
		}
		qla2x00_post_async_login_work(vha, fcport, NULL);
		break;
	}
448
	return;
449
450
}

451
void
452
453
454
455
qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
    uint16_t *data)
{
	qla2x00_mark_device_lost(vha, fcport, 1, 0);
456
	return;
457
458
}

459
void
460
461
462
463
464
465
qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
    uint16_t *data)
{
	if (data[0] == MBS_COMMAND_COMPLETE) {
		qla2x00_update_fcport(vha, fcport);

466
		return;
467
468
469
470
471
472
473
	}

	/* Retry login. */
	fcport->flags &= ~FCF_ASYNC_SENT;
	if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
		set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
	else
474
		qla2x00_mark_device_lost(vha, fcport, 1, 1);
475

476
	return;
477
478
}

479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
void
qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
    struct srb_iocb *iocb)
{
	int rval;
	uint32_t flags;
	uint16_t lun;

	flags = iocb->u.tmf.flags;
	lun = (uint16_t)iocb->u.tmf.lun;

	/* Issue Marker IOCB */
	rval = qla2x00_async_marker(fcport, lun,
		flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);

	if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
		DEBUG2_3_11(printk(KERN_WARNING
			"%s(%ld): TM IOCB failed (%x).\n",
			__func__, vha->host_no, rval));
	}

	return;
}

void
qla2x00_async_marker_done(struct scsi_qla_host *vha, fc_port_t *fcport,
    struct srb_iocb *iocb)
{
	/*
	 * Currently we dont have any specific post response processing
	 * for this IOCB. We'll just return success or failed
	 * depending on whether the IOCB command succeeded or failed.
	 */
	if (iocb->u.tmf.data) {
		DEBUG2_3_11(printk(KERN_WARNING
		    "%s(%ld): Marker IOCB failed (%x).\n",
		    __func__, vha->host_no, iocb->u.tmf.data));
	}

	return;
}

Linus Torvalds's avatar
Linus Torvalds committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
/****************************************************************************/
/*                QLogic ISP2x00 Hardware Support Functions.                */
/****************************************************************************/

/*
* qla2x00_initialize_adapter
*      Initialize board.
*
* Input:
*      ha = adapter block pointer.
*
* Returns:
*      0 = success
*/
int
536
qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds's avatar
Linus Torvalds committed
537
538
{
	int	rval;
539
	struct qla_hw_data *ha = vha->hw;
540
	struct req_que *req = ha->req_q_map[0];
541

Linus Torvalds's avatar
Linus Torvalds committed
542
	/* Clear adapter flags. */
543
	vha->flags.online = 0;
544
	ha->flags.chip_reset_done = 0;
545
	vha->flags.reset_active = 0;
546
547
	ha->flags.pci_channel_io_perm_failure = 0;
	ha->flags.eeh_busy = 0;
548
549
550
551
552
553
	atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
	atomic_set(&vha->loop_state, LOOP_DOWN);
	vha->device_flags = DFLG_NO_CABLE;
	vha->dpc_flags = 0;
	vha->flags.management_server_logged_in = 0;
	vha->marker_needed = 0;
Linus Torvalds's avatar
Linus Torvalds committed
554
555
556
	ha->isp_abort_cnt = 0;
	ha->beacon_blink_led = 0;

557
558
559
	set_bit(0, ha->req_qid_map);
	set_bit(0, ha->rsp_qid_map);

560
	qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
561
	rval = ha->isp_ops->pci_config(vha);
Linus Torvalds's avatar
Linus Torvalds committed
562
	if (rval) {
563
		DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
564
		    vha->host_no));
Linus Torvalds's avatar
Linus Torvalds committed
565
566
567
		return (rval);
	}

568
	ha->isp_ops->reset_chip(vha);
Linus Torvalds's avatar
Linus Torvalds committed
569

570
	rval = qla2xxx_get_flash_info(vha);
571
572
	if (rval) {
		DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
573
		    vha->host_no));
574
575
576
		return (rval);
	}

577
	ha->isp_ops->get_flash_version(vha, req->ring);
578

Linus Torvalds's avatar
Linus Torvalds committed
579
	qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
580

581
	ha->isp_ops->nvram_config(vha);
Linus Torvalds's avatar
Linus Torvalds committed
582

583
584
585
586
	if (ha->flags.disable_serdes) {
		/* Mask HBA via NVRAM settings? */
		qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
		    "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
587
588
589
590
		    vha->port_name[0], vha->port_name[1],
		    vha->port_name[2], vha->port_name[3],
		    vha->port_name[4], vha->port_name[5],
		    vha->port_name[6], vha->port_name[7]);
591
592
593
		return QLA_FUNCTION_FAILED;
	}

Linus Torvalds's avatar
Linus Torvalds committed
594
595
	qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");

596
597
	if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
		rval = ha->isp_ops->chip_diag(vha);
598
599
		if (rval)
			return (rval);
600
		rval = qla2x00_setup_chip(vha);
601
602
		if (rval)
			return (rval);
Linus Torvalds's avatar
Linus Torvalds committed
603
	}
604

605
	if (IS_QLA84XX(ha)) {
606
		ha->cs84xx = qla84xx_get_chip(vha);
607
608
609
610
611
612
		if (!ha->cs84xx) {
			qla_printk(KERN_ERR, ha,
			    "Unable to configure ISP84XX.\n");
			return QLA_FUNCTION_FAILED;
		}
	}
613
	rval = qla2x00_init_rings(vha);
614
	ha->flags.chip_reset_done = 1;
Linus Torvalds's avatar
Linus Torvalds committed
615

616
	if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
617
		/* Issue verify 84xx FW IOCB to complete 84xx initialization */
618
619
620
621
622
623
624
625
		rval = qla84xx_init_chip(vha);
		if (rval != QLA_SUCCESS) {
			qla_printk(KERN_ERR, ha,
				"Unable to initialize ISP84XX.\n");
		qla84xx_put_chip(vha);
		}
	}

626
627
628
629
630
631
	if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) {
		if (qla24xx_read_fcp_prio_cfg(vha))
			qla_printk(KERN_ERR, ha,
			"Unable to read FCP priority data.\n");
	}

Linus Torvalds's avatar
Linus Torvalds committed
632
633
634
635
	return (rval);
}

/**
636
 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds's avatar
Linus Torvalds committed
637
638
639
640
 * @ha: HA context
 *
 * Returns 0 on success.
 */
641
int
642
qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds's avatar
Linus Torvalds committed
643
{
644
	uint16_t w;
645
	unsigned long flags;
646
	struct qla_hw_data *ha = vha->hw;
647
	struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds's avatar
Linus Torvalds committed
648
649

	pci_set_master(ha->pdev);
650
	pci_try_set_mwi(ha->pdev);
Linus Torvalds's avatar
Linus Torvalds committed
651
652

	pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
653
	w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
654
655
	pci_write_config_word(ha->pdev, PCI_COMMAND, w);

656
	pci_disable_rom(ha->pdev);
Linus Torvalds's avatar
Linus Torvalds committed
657
658
659

	/* Get PCI bus information. */
	spin_lock_irqsave(&ha->hardware_lock, flags);
660
	ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Linus Torvalds's avatar
Linus Torvalds committed
661
662
	spin_unlock_irqrestore(&ha->hardware_lock, flags);

663
664
	return QLA_SUCCESS;
}
Linus Torvalds's avatar
Linus Torvalds committed
665

666
667
668
669
670
671
672
/**
 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
 * @ha: HA context
 *
 * Returns 0 on success.
 */
int
673
qla2300_pci_config(scsi_qla_host_t *vha)
674
{
675
	uint16_t	w;
676
677
	unsigned long   flags = 0;
	uint32_t	cnt;
678
	struct qla_hw_data *ha = vha->hw;
679
	struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds's avatar
Linus Torvalds committed
680

681
	pci_set_master(ha->pdev);
682
	pci_try_set_mwi(ha->pdev);
Linus Torvalds's avatar
Linus Torvalds committed
683

684
	pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
685
	w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds's avatar
Linus Torvalds committed
686

687
688
	if (IS_QLA2322(ha) || IS_QLA6322(ha))
		w &= ~PCI_COMMAND_INTX_DISABLE;
689
	pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Linus Torvalds's avatar
Linus Torvalds committed
690

691
692
693
694
695
696
697
698
699
	/*
	 * If this is a 2300 card and not 2312, reset the
	 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
	 * the 2310 also reports itself as a 2300 so we need to get the
	 * fb revision level -- a 6 indicates it really is a 2300 and
	 * not a 2310.
	 */
	if (IS_QLA2300(ha)) {
		spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds's avatar
Linus Torvalds committed
700

701
		/* Pause RISC. */
702
		WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
703
		for (cnt = 0; cnt < 30000; cnt++) {
704
			if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
705
				break;
Linus Torvalds's avatar
Linus Torvalds committed
706

707
708
			udelay(10);
		}
Linus Torvalds's avatar
Linus Torvalds committed
709

710
		/* Select FPM registers. */
711
712
		WRT_REG_WORD(&reg->ctrl_status, 0x20);
		RD_REG_WORD(&reg->ctrl_status);
713
714

		/* Get the fb rev level */
715
		ha->fb_rev = RD_FB_CMD_REG(ha, reg);
716
717

		if (ha->fb_rev == FPM_2300)
718
			pci_clear_mwi(ha->pdev);
719
720

		/* Deselect FPM registers. */
721
722
		WRT_REG_WORD(&reg->ctrl_status, 0x0);
		RD_REG_WORD(&reg->ctrl_status);
723
724

		/* Release RISC module. */
725
		WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
726
		for (cnt = 0; cnt < 30000; cnt++) {
727
			if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
728
729
730
				break;

			udelay(10);
Linus Torvalds's avatar
Linus Torvalds committed
731
732
		}

733
734
		spin_unlock_irqrestore(&ha->hardware_lock, flags);
	}
Linus Torvalds's avatar
Linus Torvalds committed
735

736
737
	pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);

738
	pci_disable_rom(ha->pdev);
Linus Torvalds's avatar
Linus Torvalds committed
739

740
741
	/* Get PCI bus information. */
	spin_lock_irqsave(&ha->hardware_lock, flags);
742
	ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
743
744
745
	spin_unlock_irqrestore(&ha->hardware_lock, flags);

	return QLA_SUCCESS;
Linus Torvalds's avatar
Linus Torvalds committed
746
747
}

748
749
750
751
752
753
754
/**
 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
 * @ha: HA context
 *
 * Returns 0 on success.
 */
int
755
qla24xx_pci_config(scsi_qla_host_t *vha)
756
{
757
	uint16_t w;
758
	unsigned long flags = 0;
759
	struct qla_hw_data *ha = vha->hw;
760
761
762
	struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;

	pci_set_master(ha->pdev);
763
	pci_try_set_mwi(ha->pdev);
764
765

	pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
766
	w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
767
768
769
770
771
772
	w &= ~PCI_COMMAND_INTX_DISABLE;
	pci_write_config_word(ha->pdev, PCI_COMMAND, w);

	pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);

	/* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
773
774
	if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
		pcix_set_mmrbc(ha->pdev, 2048);
775
776

	/* PCIe -- adjust Maximum Read Request Size (2048). */
777
778
	if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
		pcie_set_readrq(ha->pdev, 2048);
779

780
	pci_disable_rom(ha->pdev);
781

782
	ha->chip_revision = ha->pdev->revision;
783

784
785
786
787
788
789
790
791
	/* Get PCI bus information. */
	spin_lock_irqsave(&ha->hardware_lock, flags);
	ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
	spin_unlock_irqrestore(&ha->hardware_lock, flags);

	return QLA_SUCCESS;
}

792
793
794
795
796
797
798
/**
 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
 * @ha: HA context
 *
 * Returns 0 on success.
 */
int
799
qla25xx_pci_config(scsi_qla_host_t *vha)
800
801
{
	uint16_t w;
802
	struct qla_hw_data *ha = vha->hw;
803
804
805
806
807
808
809
810
811
812
813
814
815

	pci_set_master(ha->pdev);
	pci_try_set_mwi(ha->pdev);

	pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
	w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
	w &= ~PCI_COMMAND_INTX_DISABLE;
	pci_write_config_word(ha->pdev, PCI_COMMAND, w);

	/* PCIe -- adjust Maximum Read Request Size (2048). */
	if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
		pcie_set_readrq(ha->pdev, 2048);

816
	pci_disable_rom(ha->pdev);
817
818
819
820
821
822

	ha->chip_revision = ha->pdev->revision;

	return QLA_SUCCESS;
}

Linus Torvalds's avatar
Linus Torvalds committed
823
824
825
826
827
828
829
/**
 * qla2x00_isp_firmware() - Choose firmware image.
 * @ha: HA context
 *
 * Returns 0 on success.
 */
static int
830
qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds's avatar
Linus Torvalds committed
831
832
{
	int  rval;
833
834
	uint16_t loop_id, topo, sw_cap;
	uint8_t domain, area, al_pa;
835
	struct qla_hw_data *ha = vha->hw;
Linus Torvalds's avatar
Linus Torvalds committed
836
837

	/* Assume loading risc code */
838
	rval = QLA_FUNCTION_FAILED;
Linus Torvalds's avatar
Linus Torvalds committed
839
840
841

	if (ha->flags.disable_risc_code_load) {
		DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
842
		    vha->host_no));
Linus Torvalds's avatar
Linus Torvalds committed
843
844
845
		qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");

		/* Verify checksum of loaded RISC code. */
846
		rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
847
848
		if (rval == QLA_SUCCESS) {
			/* And, verify we are not in ROM code. */
849
			rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
850
851
			    &area, &domain, &topo, &sw_cap);
		}
Linus Torvalds's avatar
Linus Torvalds committed
852
853
854
855
	}

	if (rval) {
		DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
856
		    vha->host_no));
Linus Torvalds's avatar
Linus Torvalds committed
857
858
859
860
861
862
863
864
865
866
867
	}

	return (rval);
}

/**
 * qla2x00_reset_chip() - Reset ISP chip.
 * @ha: HA context
 *
 * Returns 0 on success.
 */
868
void
869
qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds's avatar
Linus Torvalds committed
870
871
{
	unsigned long   flags = 0;
872
	struct qla_hw_data *ha = vha->hw;
873
	struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds's avatar
Linus Torvalds committed
874
875
876
	uint32_t	cnt;
	uint16_t	cmd;

877
878
879
	if (unlikely(pci_channel_offline(ha->pdev)))
		return;

880
	ha->isp_ops->disable_intrs(ha);
Linus Torvalds's avatar
Linus Torvalds committed
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984

	spin_lock_irqsave(&ha->hardware_lock, flags);

	/* Turn off master enable */
	cmd = 0;
	pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
	cmd &= ~PCI_COMMAND_MASTER;
	pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);

	if (!IS_QLA2100(ha)) {
		/* Pause RISC. */
		WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
		if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
			for (cnt = 0; cnt < 30000; cnt++) {
				if ((RD_REG_WORD(&reg->hccr) &
				    HCCR_RISC_PAUSE) != 0)
					break;
				udelay(100);
			}
		} else {
			RD_REG_WORD(&reg->hccr);	/* PCI Posting. */
			udelay(10);
		}

		/* Select FPM registers. */
		WRT_REG_WORD(&reg->ctrl_status, 0x20);
		RD_REG_WORD(&reg->ctrl_status);		/* PCI Posting. */

		/* FPM Soft Reset. */
		WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
		RD_REG_WORD(&reg->fpm_diag_config);	/* PCI Posting. */

		/* Toggle Fpm Reset. */
		if (!IS_QLA2200(ha)) {
			WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
			RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
		}

		/* Select frame buffer registers. */
		WRT_REG_WORD(&reg->ctrl_status, 0x10);
		RD_REG_WORD(&reg->ctrl_status);		/* PCI Posting. */

		/* Reset frame buffer FIFOs. */
		if (IS_QLA2200(ha)) {
			WRT_FB_CMD_REG(ha, reg, 0xa000);
			RD_FB_CMD_REG(ha, reg);		/* PCI Posting. */
		} else {
			WRT_FB_CMD_REG(ha, reg, 0x00fc);

			/* Read back fb_cmd until zero or 3 seconds max */
			for (cnt = 0; cnt < 3000; cnt++) {
				if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
					break;
				udelay(100);
			}
		}

		/* Select RISC module registers. */
		WRT_REG_WORD(&reg->ctrl_status, 0);
		RD_REG_WORD(&reg->ctrl_status);		/* PCI Posting. */

		/* Reset RISC processor. */
		WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
		RD_REG_WORD(&reg->hccr);		/* PCI Posting. */

		/* Release RISC processor. */
		WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
		RD_REG_WORD(&reg->hccr);		/* PCI Posting. */
	}

	WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
	WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);

	/* Reset ISP chip. */
	WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);

	/* Wait for RISC to recover from reset. */
	if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
		/*
		 * It is necessary to for a delay here since the card doesn't
		 * respond to PCI reads during a reset. On some architectures
		 * this will result in an MCA.
		 */
		udelay(20);
		for (cnt = 30000; cnt; cnt--) {
			if ((RD_REG_WORD(&reg->ctrl_status) &
			    CSR_ISP_SOFT_RESET) == 0)
				break;
			udelay(100);
		}
	} else
		udelay(10);

	/* Reset RISC processor. */
	WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);

	WRT_REG_WORD(&reg->semaphore, 0);

	/* Release RISC processor. */
	WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
	RD_REG_WORD(&reg->hccr);			/* PCI Posting. */

	if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
		for (cnt = 0; cnt < 30000; cnt++) {
985
			if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds's avatar
Linus Torvalds committed
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
				break;

			udelay(100);
		}
	} else
		udelay(100);

	/* Turn on master enable */
	cmd |= PCI_COMMAND_MASTER;
	pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);

	/* Disable RISC pause on FPM parity error. */
	if (!IS_QLA2100(ha)) {
		WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
		RD_REG_WORD(&reg->hccr);		/* PCI Posting. */
	}

	spin_unlock_irqrestore(&ha->hardware_lock, flags);
}

1006
/**
1007
 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
1008
1009
1010
1011
 * @ha: HA context
 *
 * Returns 0 on success.
 */
1012
static inline void
1013
qla24xx_reset_risc(scsi_qla_host_t *vha)
1014
1015
{
	unsigned long flags = 0;
1016
	struct qla_hw_data *ha = vha->hw;
1017
1018
	struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
	uint32_t cnt, d2;
1019
	uint16_t wd;
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033

	spin_lock_irqsave(&ha->hardware_lock, flags);

	/* Reset RISC. */
	WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
	for (cnt = 0; cnt < 30000; cnt++) {
		if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
			break;

		udelay(10);
	}

	WRT_REG_DWORD(&reg->ctrl_status,
	    CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1034
	pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
1035

1036
	udelay(100);
1037
1038
1039
1040
1041
1042
1043
1044
	/* Wait for firmware to complete NVRAM accesses. */
	d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
	for (cnt = 10000 ; cnt && d2; cnt--) {
		udelay(5);
		d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
		barrier();
	}

1045
	/* Wait for soft-reset to complete. */
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
	d2 = RD_REG_DWORD(&reg->ctrl_status);
	for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
		udelay(5);
		d2 = RD_REG_DWORD(&reg->ctrl_status);
		barrier();
	}

	WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
	RD_REG_DWORD(&reg->hccr);

	WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
	RD_REG_DWORD(&reg->hccr);

	WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
	RD_REG_DWORD(&reg->hccr);

	d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
	for (cnt = 6000000 ; cnt && d2; cnt--) {
		udelay(5);
		d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
		barrier();
	}

	spin_unlock_irqrestore(&ha->hardware_lock, flags);
1070
1071
1072

	if (IS_NOPOLLING_TYPE(ha))
		ha->isp_ops->enable_intrs(ha);
1073
1074
}

1075
1076
1077
1078
1079
1080
1081
/**
 * qla24xx_reset_chip() - Reset ISP24xx chip.
 * @ha: HA context
 *
 * Returns 0 on success.
 */
void
1082
qla24xx_reset_chip(scsi_qla_host_t *vha)
1083
{
1084
	struct qla_hw_data *ha = vha->hw;
1085
1086
1087
1088
1089
1090

	if (pci_channel_offline(ha->pdev) &&
	    ha->flags.pci_channel_io_perm_failure) {
		return;
	}

1091
	ha->isp_ops->disable_intrs(ha);
1092
1093

	/* Perform RISC reset. */
1094
	qla24xx_reset_risc(vha);
1095
1096
}

Linus Torvalds's avatar
Linus Torvalds committed
1097
1098
1099
1100
1101
1102
/**
 * qla2x00_chip_diag() - Test chip for proper operation.
 * @ha: HA context
 *
 * Returns 0 on success.
 */
1103
int
1104
qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds's avatar
Linus Torvalds committed
1105
1106
{
	int		rval;
1107
	struct qla_hw_data *ha = vha->hw;
1108
	struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds's avatar
Linus Torvalds committed
1109
1110
1111
1112
	unsigned long	flags = 0;
	uint16_t	data;
	uint32_t	cnt;
	uint16_t	mb[5];
1113
	struct req_que *req = ha->req_q_map[0];
Linus Torvalds's avatar
Linus Torvalds committed
1114
1115
1116
1117
1118

	/* Assume a failed state */
	rval = QLA_FUNCTION_FAILED;

	DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
1119
	    vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds's avatar
Linus Torvalds committed
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141

	spin_lock_irqsave(&ha->hardware_lock, flags);

	/* Reset ISP chip. */
	WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);

	/*
	 * We need to have a delay here since the card will not respond while
	 * in reset causing an MCA on some architectures.
	 */
	udelay(20);
	data = qla2x00_debounce_register(&reg->ctrl_status);
	for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
		udelay(5);
		data = RD_REG_WORD(&reg->ctrl_status);
		barrier();
	}

	if (!cnt)
		goto chip_diag_failed;

	DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
1142
	    vha->host_no));
Linus Torvalds's avatar
Linus Torvalds committed
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153

	/* Reset RISC processor. */
	WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
	WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);

	/* Workaround for QLA2312 PCI parity error */
	if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
		data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
		for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
			udelay(5);
			data = RD_MAILBOX_REG(ha, reg, 0);
1154
			barrier();
Linus Torvalds's avatar
Linus Torvalds committed
1155
1156
1157
1158
1159
1160
1161
1162
		}
	} else
		udelay(10);

	if (!cnt)
		goto chip_diag_failed;

	/* Check product ID of chip */
1163
	DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds's avatar
Linus Torvalds committed
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181

	mb[1] = RD_MAILBOX_REG(ha, reg, 1);
	mb[2] = RD_MAILBOX_REG(ha, reg, 2);
	mb[3] = RD_MAILBOX_REG(ha, reg, 3);
	mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
	if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
	    mb[3] != PROD_ID_3) {
		qla_printk(KERN_WARNING, ha,
		    "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);

		goto chip_diag_failed;
	}
	ha->product_id[0] = mb[1];
	ha->product_id[1] = mb[2];
	ha->product_id[2] = mb[3];
	ha->product_id[3] = mb[4];

	/* Adjust fw RISC transfer size */
1182
	if (req->length > 1024)
Linus Torvalds's avatar
Linus Torvalds committed
1183
1184
1185
		ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
	else
		ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
1186
		    req->length;
Linus Torvalds's avatar
Linus Torvalds committed
1187
1188
1189
1190
1191

	if (IS_QLA2200(ha) &&
	    RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
		/* Limit firmware transfer size with a 2200A */
		DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
1192
		    vha->host_no));
Linus Torvalds's avatar
Linus Torvalds committed
1193

1194
		ha->device_type |= DT_ISP2200A;
Linus Torvalds's avatar
Linus Torvalds committed
1195
1196
1197
1198
1199
1200
		ha->fw_transfer_size = 128;
	}

	/* Wrap Incoming Mailboxes Test. */
	spin_unlock_irqrestore(&ha->hardware_lock, flags);

1201
1202
	DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
	rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds's avatar
Linus Torvalds committed
1203
1204
	if (rval) {
		DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
1205
		    vha->host_no));
Linus Torvalds's avatar
Linus Torvalds committed
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
		qla_printk(KERN_WARNING, ha,
		    "Failed mailbox send register test\n");
	}
	else {
		/* Flag a successful rval */
		rval = QLA_SUCCESS;
	}
	spin_lock_irqsave(&ha->hardware_lock, flags);

chip_diag_failed:
	if (rval)
		DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
1218
		    "****\n", vha->host_no));
Linus Torvalds's avatar
Linus Torvalds committed
1219
1220
1221
1222
1223
1224

	spin_unlock_irqrestore(&ha->hardware_lock, flags);

	return (rval);
}

1225
1226
1227
1228
1229
1230
1231
/**
 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
 * @ha: HA context
 *
 * Returns 0 on success.
 */
int
1232
qla24xx_chip_diag(scsi_qla_host_t *vha)
1233
1234
{
	int rval;