aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/qla2xxx/qla_os.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/qla2xxx/qla_os.c')
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c1471
1 files changed, 866 insertions, 605 deletions
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 35567203ef61..8ea927788b3f 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -92,7 +92,12 @@ MODULE_PARM_DESC(ql2xiidmaenable,
92 "Enables iIDMA settings " 92 "Enables iIDMA settings "
93 "Default is 1 - perform iIDMA. 0 - no iIDMA."); 93 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
94 94
95 95int ql2xmaxqueues = 1;
96module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
97MODULE_PARM_DESC(ql2xmaxqueues,
98 "Enables MQ settings "
99 "Default is 1 for single queue. Set it to number \
100 of queues in MQ mode.");
96/* 101/*
97 * SCSI host template entry points 102 * SCSI host template entry points
98 */ 103 */
@@ -183,42 +188,108 @@ struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
183 */ 188 */
184 189
185__inline__ void 190__inline__ void
186qla2x00_start_timer(scsi_qla_host_t *ha, void *func, unsigned long interval) 191qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
187{ 192{
188 init_timer(&ha->timer); 193 init_timer(&vha->timer);
189 ha->timer.expires = jiffies + interval * HZ; 194 vha->timer.expires = jiffies + interval * HZ;
190 ha->timer.data = (unsigned long)ha; 195 vha->timer.data = (unsigned long)vha;
191 ha->timer.function = (void (*)(unsigned long))func; 196 vha->timer.function = (void (*)(unsigned long))func;
192 add_timer(&ha->timer); 197 add_timer(&vha->timer);
193 ha->timer_active = 1; 198 vha->timer_active = 1;
194} 199}
195 200
196static inline void 201static inline void
197qla2x00_restart_timer(scsi_qla_host_t *ha, unsigned long interval) 202qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
198{ 203{
199 mod_timer(&ha->timer, jiffies + interval * HZ); 204 mod_timer(&vha->timer, jiffies + interval * HZ);
200} 205}
201 206
202static __inline__ void 207static __inline__ void
203qla2x00_stop_timer(scsi_qla_host_t *ha) 208qla2x00_stop_timer(scsi_qla_host_t *vha)
204{ 209{
205 del_timer_sync(&ha->timer); 210 del_timer_sync(&vha->timer);
206 ha->timer_active = 0; 211 vha->timer_active = 0;
207} 212}
208 213
209static int qla2x00_do_dpc(void *data); 214static int qla2x00_do_dpc(void *data);
210 215
211static void qla2x00_rst_aen(scsi_qla_host_t *); 216static void qla2x00_rst_aen(scsi_qla_host_t *);
212 217
213static int qla2x00_mem_alloc(scsi_qla_host_t *); 218static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
214static void qla2x00_mem_free(scsi_qla_host_t *ha); 219 struct req_que **, struct rsp_que **);
215static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *); 220static void qla2x00_mem_free(struct qla_hw_data *);
221static void qla2x00_sp_free_dma(srb_t *);
216 222
217/* -------------------------------------------------------------------------- */ 223/* -------------------------------------------------------------------------- */
224static int qla2x00_alloc_queues(struct qla_hw_data *ha)
225{
226 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_queues,
227 GFP_KERNEL);
228 if (!ha->req_q_map) {
229 qla_printk(KERN_WARNING, ha,
230 "Unable to allocate memory for request queue ptrs\n");
231 goto fail_req_map;
232 }
233
234 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_queues,
235 GFP_KERNEL);
236 if (!ha->rsp_q_map) {
237 qla_printk(KERN_WARNING, ha,
238 "Unable to allocate memory for response queue ptrs\n");
239 goto fail_rsp_map;
240 }
241 set_bit(0, ha->rsp_qid_map);
242 set_bit(0, ha->req_qid_map);
243 return 1;
244
245fail_rsp_map:
246 kfree(ha->req_q_map);
247 ha->req_q_map = NULL;
248fail_req_map:
249 return -ENOMEM;
250}
251
252static void qla2x00_free_que(struct qla_hw_data *ha, struct req_que *req,
253 struct rsp_que *rsp)
254{
255 if (rsp && rsp->ring)
256 dma_free_coherent(&ha->pdev->dev,
257 (rsp->length + 1) * sizeof(response_t),
258 rsp->ring, rsp->dma);
259
260 kfree(rsp);
261 rsp = NULL;
262 if (req && req->ring)
263 dma_free_coherent(&ha->pdev->dev,
264 (req->length + 1) * sizeof(request_t),
265 req->ring, req->dma);
266
267 kfree(req);
268 req = NULL;
269}
270
271static void qla2x00_free_queues(struct qla_hw_data *ha)
272{
273 struct req_que *req;
274 struct rsp_que *rsp;
275 int cnt;
276
277 for (cnt = 0; cnt < ha->max_queues; cnt++) {
278 rsp = ha->rsp_q_map[cnt];
279 req = ha->req_q_map[cnt];
280 qla2x00_free_que(ha, req, rsp);
281 }
282 kfree(ha->rsp_q_map);
283 ha->rsp_q_map = NULL;
284
285 kfree(ha->req_q_map);
286 ha->req_q_map = NULL;
287}
218 288
219static char * 289static char *
220qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str) 290qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
221{ 291{
292 struct qla_hw_data *ha = vha->hw;
222 static char *pci_bus_modes[] = { 293 static char *pci_bus_modes[] = {
223 "33", "66", "100", "133", 294 "33", "66", "100", "133",
224 }; 295 };
@@ -240,9 +311,10 @@ qla2x00_pci_info_str(struct scsi_qla_host *ha, char *str)
240} 311}
241 312
242static char * 313static char *
243qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str) 314qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
244{ 315{
245 static char *pci_bus_modes[] = { "33", "66", "100", "133", }; 316 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
317 struct qla_hw_data *ha = vha->hw;
246 uint32_t pci_bus; 318 uint32_t pci_bus;
247 int pcie_reg; 319 int pcie_reg;
248 320
@@ -290,9 +362,10 @@ qla24xx_pci_info_str(struct scsi_qla_host *ha, char *str)
290} 362}
291 363
292static char * 364static char *
293qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str) 365qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
294{ 366{
295 char un_str[10]; 367 char un_str[10];
368 struct qla_hw_data *ha = vha->hw;
296 369
297 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version, 370 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
298 ha->fw_minor_version, 371 ha->fw_minor_version,
@@ -328,8 +401,9 @@ qla2x00_fw_version_str(struct scsi_qla_host *ha, char *str)
328} 401}
329 402
330static char * 403static char *
331qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str) 404qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
332{ 405{
406 struct qla_hw_data *ha = vha->hw;
333 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version, 407 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
334 ha->fw_minor_version, 408 ha->fw_minor_version,
335 ha->fw_subminor_version); 409 ha->fw_subminor_version);
@@ -354,18 +428,20 @@ qla24xx_fw_version_str(struct scsi_qla_host *ha, char *str)
354} 428}
355 429
356static inline srb_t * 430static inline srb_t *
357qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport, 431qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
358 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 432 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
359{ 433{
360 srb_t *sp; 434 srb_t *sp;
435 struct qla_hw_data *ha = vha->hw;
361 436
362 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); 437 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
363 if (!sp) 438 if (!sp)
364 return sp; 439 return sp;
365 440
366 sp->ha = ha; 441 sp->vha = vha;
367 sp->fcport = fcport; 442 sp->fcport = fcport;
368 sp->cmd = cmd; 443 sp->cmd = cmd;
444 sp->que = ha->req_q_map[0];
369 sp->flags = 0; 445 sp->flags = 0;
370 CMD_SP(cmd) = (void *)sp; 446 CMD_SP(cmd) = (void *)sp;
371 cmd->scsi_done = done; 447 cmd->scsi_done = done;
@@ -376,9 +452,10 @@ qla2x00_get_new_sp(scsi_qla_host_t *ha, fc_port_t *fcport,
376static int 452static int
377qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 453qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
378{ 454{
379 scsi_qla_host_t *ha = shost_priv(cmd->device->host); 455 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
380 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 456 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
381 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device)); 457 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
458 struct qla_hw_data *ha = vha->hw;
382 srb_t *sp; 459 srb_t *sp;
383 int rval; 460 int rval;
384 461
@@ -399,33 +476,33 @@ qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
399 476
400 if (atomic_read(&fcport->state) != FCS_ONLINE) { 477 if (atomic_read(&fcport->state) != FCS_ONLINE) {
401 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || 478 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
402 atomic_read(&ha->loop_state) == LOOP_DEAD) { 479 atomic_read(&vha->loop_state) == LOOP_DEAD) {
403 cmd->result = DID_NO_CONNECT << 16; 480 cmd->result = DID_NO_CONNECT << 16;
404 goto qc_fail_command; 481 goto qc_fail_command;
405 } 482 }
406 goto qc_target_busy; 483 goto qc_target_busy;
407 } 484 }
408 485
409 spin_unlock_irq(ha->host->host_lock); 486 spin_unlock_irq(vha->host->host_lock);
410 487
411 sp = qla2x00_get_new_sp(ha, fcport, cmd, done); 488 sp = qla2x00_get_new_sp(vha, fcport, cmd, done);
412 if (!sp) 489 if (!sp)
413 goto qc_host_busy_lock; 490 goto qc_host_busy_lock;
414 491
415 rval = qla2x00_start_scsi(sp); 492 rval = ha->isp_ops->start_scsi(sp);
416 if (rval != QLA_SUCCESS) 493 if (rval != QLA_SUCCESS)
417 goto qc_host_busy_free_sp; 494 goto qc_host_busy_free_sp;
418 495
419 spin_lock_irq(ha->host->host_lock); 496 spin_lock_irq(vha->host->host_lock);
420 497
421 return 0; 498 return 0;
422 499
423qc_host_busy_free_sp: 500qc_host_busy_free_sp:
424 qla2x00_sp_free_dma(ha, sp); 501 qla2x00_sp_free_dma(sp);
425 mempool_free(sp, ha->srb_mempool); 502 mempool_free(sp, ha->srb_mempool);
426 503
427qc_host_busy_lock: 504qc_host_busy_lock:
428 spin_lock_irq(ha->host->host_lock); 505 spin_lock_irq(vha->host->host_lock);
429 return SCSI_MLQUEUE_HOST_BUSY; 506 return SCSI_MLQUEUE_HOST_BUSY;
430 507
431qc_target_busy: 508qc_target_busy:
@@ -441,14 +518,15 @@ qc_fail_command:
441static int 518static int
442qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 519qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
443{ 520{
444 scsi_qla_host_t *ha = shost_priv(cmd->device->host); 521 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
445 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 522 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
446 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device)); 523 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
524 struct qla_hw_data *ha = vha->hw;
525 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
447 srb_t *sp; 526 srb_t *sp;
448 int rval; 527 int rval;
449 scsi_qla_host_t *pha = to_qla_parent(ha);
450 528
451 if (unlikely(pci_channel_offline(pha->pdev))) { 529 if (unlikely(pci_channel_offline(ha->pdev))) {
452 cmd->result = DID_REQUEUE << 16; 530 cmd->result = DID_REQUEUE << 16;
453 goto qc24_fail_command; 531 goto qc24_fail_command;
454 } 532 }
@@ -465,33 +543,33 @@ qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
465 543
466 if (atomic_read(&fcport->state) != FCS_ONLINE) { 544 if (atomic_read(&fcport->state) != FCS_ONLINE) {
467 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD || 545 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
468 atomic_read(&pha->loop_state) == LOOP_DEAD) { 546 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
469 cmd->result = DID_NO_CONNECT << 16; 547 cmd->result = DID_NO_CONNECT << 16;
470 goto qc24_fail_command; 548 goto qc24_fail_command;
471 } 549 }
472 goto qc24_target_busy; 550 goto qc24_target_busy;
473 } 551 }
474 552
475 spin_unlock_irq(ha->host->host_lock); 553 spin_unlock_irq(vha->host->host_lock);
476 554
477 sp = qla2x00_get_new_sp(pha, fcport, cmd, done); 555 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
478 if (!sp) 556 if (!sp)
479 goto qc24_host_busy_lock; 557 goto qc24_host_busy_lock;
480 558
481 rval = qla24xx_start_scsi(sp); 559 rval = ha->isp_ops->start_scsi(sp);
482 if (rval != QLA_SUCCESS) 560 if (rval != QLA_SUCCESS)
483 goto qc24_host_busy_free_sp; 561 goto qc24_host_busy_free_sp;
484 562
485 spin_lock_irq(ha->host->host_lock); 563 spin_lock_irq(vha->host->host_lock);
486 564
487 return 0; 565 return 0;
488 566
489qc24_host_busy_free_sp: 567qc24_host_busy_free_sp:
490 qla2x00_sp_free_dma(pha, sp); 568 qla2x00_sp_free_dma(sp);
491 mempool_free(sp, pha->srb_mempool); 569 mempool_free(sp, ha->srb_mempool);
492 570
493qc24_host_busy_lock: 571qc24_host_busy_lock:
494 spin_lock_irq(ha->host->host_lock); 572 spin_lock_irq(vha->host->host_lock);
495 return SCSI_MLQUEUE_HOST_BUSY; 573 return SCSI_MLQUEUE_HOST_BUSY;
496 574
497qc24_target_busy: 575qc24_target_busy:
@@ -510,17 +588,14 @@ qc24_fail_command:
510 * max time. 588 * max time.
511 * 589 *
512 * Input: 590 * Input:
513 * ha = actual ha whose done queue will contain the command
514 * returned by firmware.
515 * cmd = Scsi Command to wait on. 591 * cmd = Scsi Command to wait on.
516 * flag = Abort/Reset(Bus or Device Reset)
517 * 592 *
518 * Return: 593 * Return:
519 * Not Found : 0 594 * Not Found : 0
520 * Found : 1 595 * Found : 1
521 */ 596 */
522static int 597static int
523qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd) 598qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
524{ 599{
525#define ABORT_POLLING_PERIOD 1000 600#define ABORT_POLLING_PERIOD 1000
526#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD)) 601#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
@@ -557,21 +632,22 @@ qla2x00_eh_wait_on_command(scsi_qla_host_t *ha, struct scsi_cmnd *cmd)
557 * Failed (Adapter is offline/disabled) : 1 632 * Failed (Adapter is offline/disabled) : 1
558 */ 633 */
559int 634int
560qla2x00_wait_for_hba_online(scsi_qla_host_t *ha) 635qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
561{ 636{
562 int return_status; 637 int return_status;
563 unsigned long wait_online; 638 unsigned long wait_online;
564 scsi_qla_host_t *pha = to_qla_parent(ha); 639 struct qla_hw_data *ha = vha->hw;
640 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
565 641
566 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ); 642 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
567 while (((test_bit(ISP_ABORT_NEEDED, &pha->dpc_flags)) || 643 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
568 test_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags) || 644 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
569 test_bit(ISP_ABORT_RETRY, &pha->dpc_flags) || 645 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
570 pha->dpc_active) && time_before(jiffies, wait_online)) { 646 ha->dpc_active) && time_before(jiffies, wait_online)) {
571 647
572 msleep(1000); 648 msleep(1000);
573 } 649 }
574 if (pha->flags.online) 650 if (base_vha->flags.online)
575 return_status = QLA_SUCCESS; 651 return_status = QLA_SUCCESS;
576 else 652 else
577 return_status = QLA_FUNCTION_FAILED; 653 return_status = QLA_FUNCTION_FAILED;
@@ -596,19 +672,20 @@ qla2x00_wait_for_hba_online(scsi_qla_host_t *ha)
596 * Failed (LOOP_NOT_READY) : 1 672 * Failed (LOOP_NOT_READY) : 1
597 */ 673 */
598static inline int 674static inline int
599qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha) 675qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
600{ 676{
601 int return_status = QLA_SUCCESS; 677 int return_status = QLA_SUCCESS;
602 unsigned long loop_timeout ; 678 unsigned long loop_timeout ;
603 scsi_qla_host_t *pha = to_qla_parent(ha); 679 struct qla_hw_data *ha = vha->hw;
680 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
604 681
605 /* wait for 5 min at the max for loop to be ready */ 682 /* wait for 5 min at the max for loop to be ready */
606 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ); 683 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
607 684
608 while ((!atomic_read(&pha->loop_down_timer) && 685 while ((!atomic_read(&base_vha->loop_down_timer) &&
609 atomic_read(&pha->loop_state) == LOOP_DOWN) || 686 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
610 atomic_read(&pha->loop_state) != LOOP_READY) { 687 atomic_read(&base_vha->loop_state) != LOOP_READY) {
611 if (atomic_read(&pha->loop_state) == LOOP_DEAD) { 688 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
612 return_status = QLA_FUNCTION_FAILED; 689 return_status = QLA_FUNCTION_FAILED;
613 break; 690 break;
614 } 691 }
@@ -624,35 +701,42 @@ qla2x00_wait_for_loop_ready(scsi_qla_host_t *ha)
624void 701void
625qla2x00_abort_fcport_cmds(fc_port_t *fcport) 702qla2x00_abort_fcport_cmds(fc_port_t *fcport)
626{ 703{
627 int cnt; 704 int cnt, que, id;
628 unsigned long flags; 705 unsigned long flags;
629 srb_t *sp; 706 srb_t *sp;
630 scsi_qla_host_t *ha = fcport->ha; 707 scsi_qla_host_t *vha = fcport->vha;
631 scsi_qla_host_t *pha = to_qla_parent(ha); 708 struct qla_hw_data *ha = vha->hw;
709 struct req_que *req;
632 710
633 spin_lock_irqsave(&pha->hardware_lock, flags); 711 spin_lock_irqsave(&ha->hardware_lock, flags);
634 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { 712 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
635 sp = pha->outstanding_cmds[cnt]; 713 id = vha->req_ques[que];
636 if (!sp) 714 req = ha->req_q_map[id];
637 continue; 715 if (!req)
638 if (sp->fcport != fcport)
639 continue; 716 continue;
717 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
718 sp = req->outstanding_cmds[cnt];
719 if (!sp)
720 continue;
721 if (sp->fcport != fcport)
722 continue;
640 723
641 spin_unlock_irqrestore(&pha->hardware_lock, flags); 724 spin_unlock_irqrestore(&ha->hardware_lock, flags);
642 if (ha->isp_ops->abort_command(ha, sp)) { 725 if (ha->isp_ops->abort_command(vha, sp, req)) {
643 DEBUG2(qla_printk(KERN_WARNING, ha,
644 "Abort failed -- %lx\n", sp->cmd->serial_number));
645 } else {
646 if (qla2x00_eh_wait_on_command(ha, sp->cmd) !=
647 QLA_SUCCESS)
648 DEBUG2(qla_printk(KERN_WARNING, ha, 726 DEBUG2(qla_printk(KERN_WARNING, ha,
649 "Abort failed while waiting -- %lx\n", 727 "Abort failed -- %lx\n",
650 sp->cmd->serial_number)); 728 sp->cmd->serial_number));
651 729 } else {
730 if (qla2x00_eh_wait_on_command(sp->cmd) !=
731 QLA_SUCCESS)
732 DEBUG2(qla_printk(KERN_WARNING, ha,
733 "Abort failed while waiting -- %lx\n",
734 sp->cmd->serial_number));
735 }
736 spin_lock_irqsave(&ha->hardware_lock, flags);
652 } 737 }
653 spin_lock_irqsave(&pha->hardware_lock, flags);
654 } 738 }
655 spin_unlock_irqrestore(&pha->hardware_lock, flags); 739 spin_unlock_irqrestore(&ha->hardware_lock, flags);
656} 740}
657 741
658static void 742static void
@@ -690,14 +774,16 @@ qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
690static int 774static int
691qla2xxx_eh_abort(struct scsi_cmnd *cmd) 775qla2xxx_eh_abort(struct scsi_cmnd *cmd)
692{ 776{
693 scsi_qla_host_t *ha = shost_priv(cmd->device->host); 777 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
694 srb_t *sp; 778 srb_t *sp;
695 int ret, i; 779 int ret, i;
696 unsigned int id, lun; 780 unsigned int id, lun;
697 unsigned long serial; 781 unsigned long serial;
698 unsigned long flags; 782 unsigned long flags;
699 int wait = 0; 783 int wait = 0;
700 scsi_qla_host_t *pha = to_qla_parent(ha); 784 struct qla_hw_data *ha = vha->hw;
785 struct req_que *req;
786 srb_t *spt;
701 787
702 qla2x00_block_error_handler(cmd); 788 qla2x00_block_error_handler(cmd);
703 789
@@ -709,11 +795,15 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
709 id = cmd->device->id; 795 id = cmd->device->id;
710 lun = cmd->device->lun; 796 lun = cmd->device->lun;
711 serial = cmd->serial_number; 797 serial = cmd->serial_number;
798 spt = (srb_t *) CMD_SP(cmd);
799 if (!spt)
800 return SUCCESS;
801 req = spt->que;
712 802
713 /* Check active list for command command. */ 803 /* Check active list for command command. */
714 spin_lock_irqsave(&pha->hardware_lock, flags); 804 spin_lock_irqsave(&ha->hardware_lock, flags);
715 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) { 805 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
716 sp = pha->outstanding_cmds[i]; 806 sp = req->outstanding_cmds[i];
717 807
718 if (sp == NULL) 808 if (sp == NULL)
719 continue; 809 continue;
@@ -721,38 +811,36 @@ qla2xxx_eh_abort(struct scsi_cmnd *cmd)
721 if (sp->cmd != cmd) 811 if (sp->cmd != cmd)
722 continue; 812 continue;
723 813
724 DEBUG2(printk("%s(%ld): aborting sp %p from RISC. pid=%ld.\n", 814 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
725 __func__, ha->host_no, sp, serial)); 815 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
726 816
727 spin_unlock_irqrestore(&pha->hardware_lock, flags); 817 spin_unlock_irqrestore(&ha->hardware_lock, flags);
728 if (ha->isp_ops->abort_command(ha, sp)) { 818 if (ha->isp_ops->abort_command(vha, sp, req)) {
729 DEBUG2(printk("%s(%ld): abort_command " 819 DEBUG2(printk("%s(%ld): abort_command "
730 "mbx failed.\n", __func__, ha->host_no)); 820 "mbx failed.\n", __func__, vha->host_no));
731 ret = FAILED;
732 } else { 821 } else {
733 DEBUG3(printk("%s(%ld): abort_command " 822 DEBUG3(printk("%s(%ld): abort_command "
734 "mbx success.\n", __func__, ha->host_no)); 823 "mbx success.\n", __func__, vha->host_no));
735 wait = 1; 824 wait = 1;
736 } 825 }
737 spin_lock_irqsave(&pha->hardware_lock, flags); 826 spin_lock_irqsave(&ha->hardware_lock, flags);
738
739 break; 827 break;
740 } 828 }
741 spin_unlock_irqrestore(&pha->hardware_lock, flags); 829 spin_unlock_irqrestore(&ha->hardware_lock, flags);
742 830
743 /* Wait for the command to be returned. */ 831 /* Wait for the command to be returned. */
744 if (wait) { 832 if (wait) {
745 if (qla2x00_eh_wait_on_command(ha, cmd) != QLA_SUCCESS) { 833 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
746 qla_printk(KERN_ERR, ha, 834 qla_printk(KERN_ERR, ha,
747 "scsi(%ld:%d:%d): Abort handler timed out -- %lx " 835 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
748 "%x.\n", ha->host_no, id, lun, serial, ret); 836 "%x.\n", vha->host_no, id, lun, serial, ret);
749 ret = FAILED; 837 ret = FAILED;
750 } 838 }
751 } 839 }
752 840
753 qla_printk(KERN_INFO, ha, 841 qla_printk(KERN_INFO, ha,
754 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n", 842 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
755 ha->host_no, id, lun, wait, serial, ret); 843 vha->host_no, id, lun, wait, serial, ret);
756 844
757 return ret; 845 return ret;
758} 846}
@@ -764,23 +852,27 @@ enum nexus_wait_type {
764}; 852};
765 853
766static int 854static int
767qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha, unsigned int t, 855qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
768 unsigned int l, enum nexus_wait_type type) 856 unsigned int l, srb_t *sp, enum nexus_wait_type type)
769{ 857{
770 int cnt, match, status; 858 int cnt, match, status;
771 srb_t *sp;
772 unsigned long flags; 859 unsigned long flags;
773 scsi_qla_host_t *pha = to_qla_parent(ha); 860 struct qla_hw_data *ha = vha->hw;
861 struct req_que *req;
774 862
775 status = QLA_SUCCESS; 863 status = QLA_SUCCESS;
776 spin_lock_irqsave(&pha->hardware_lock, flags); 864 if (!sp)
777 for (cnt = 1; status == QLA_SUCCESS && cnt < MAX_OUTSTANDING_COMMANDS; 865 return status;
778 cnt++) { 866
779 sp = pha->outstanding_cmds[cnt]; 867 spin_lock_irqsave(&ha->hardware_lock, flags);
868 req = sp->que;
869 for (cnt = 1; status == QLA_SUCCESS &&
870 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
871 sp = req->outstanding_cmds[cnt];
780 if (!sp) 872 if (!sp)
781 continue; 873 continue;
782 874
783 if (ha->vp_idx != sp->fcport->ha->vp_idx) 875 if (vha->vp_idx != sp->fcport->vha->vp_idx)
784 continue; 876 continue;
785 match = 0; 877 match = 0;
786 switch (type) { 878 switch (type) {
@@ -792,17 +884,17 @@ qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *ha, unsigned int t,
792 break; 884 break;
793 case WAIT_LUN: 885 case WAIT_LUN:
794 match = (sp->cmd->device->id == t && 886 match = (sp->cmd->device->id == t &&
795 sp->cmd->device->lun == l); 887 sp->cmd->device->lun == l);
796 break; 888 break;
797 } 889 }
798 if (!match) 890 if (!match)
799 continue; 891 continue;
800 892
801 spin_unlock_irqrestore(&pha->hardware_lock, flags); 893 spin_unlock_irqrestore(&ha->hardware_lock, flags);
802 status = qla2x00_eh_wait_on_command(ha, sp->cmd); 894 status = qla2x00_eh_wait_on_command(sp->cmd);
803 spin_lock_irqsave(&pha->hardware_lock, flags); 895 spin_lock_irqsave(&ha->hardware_lock, flags);
804 } 896 }
805 spin_unlock_irqrestore(&pha->hardware_lock, flags); 897 spin_unlock_irqrestore(&ha->hardware_lock, flags);
806 898
807 return status; 899 return status;
808} 900}
@@ -818,7 +910,7 @@ static int
818__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type, 910__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
819 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int)) 911 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
820{ 912{
821 scsi_qla_host_t *ha = shost_priv(cmd->device->host); 913 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
822 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 914 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
823 int err; 915 int err;
824 916
@@ -827,31 +919,31 @@ __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
827 if (!fcport) 919 if (!fcport)
828 return FAILED; 920 return FAILED;
829 921
830 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET ISSUED.\n", 922 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
831 ha->host_no, cmd->device->id, cmd->device->lun, name); 923 vha->host_no, cmd->device->id, cmd->device->lun, name);
832 924
833 err = 0; 925 err = 0;
834 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) 926 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
835 goto eh_reset_failed; 927 goto eh_reset_failed;
836 err = 1; 928 err = 1;
837 if (qla2x00_wait_for_loop_ready(ha) != QLA_SUCCESS) 929 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
838 goto eh_reset_failed; 930 goto eh_reset_failed;
839 err = 2; 931 err = 2;
840 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS) 932 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
841 goto eh_reset_failed; 933 goto eh_reset_failed;
842 err = 3; 934 err = 3;
843 if (qla2x00_eh_wait_for_pending_commands(ha, cmd->device->id, 935 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
844 cmd->device->lun, type) != QLA_SUCCESS) 936 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
845 goto eh_reset_failed; 937 goto eh_reset_failed;
846 938
847 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n", 939 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
848 ha->host_no, cmd->device->id, cmd->device->lun, name); 940 vha->host_no, cmd->device->id, cmd->device->lun, name);
849 941
850 return SUCCESS; 942 return SUCCESS;
851 943
852 eh_reset_failed: 944 eh_reset_failed:
853 qla_printk(KERN_INFO, ha, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n", 945 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
854 ha->host_no, cmd->device->id, cmd->device->lun, name, 946 , vha->host_no, cmd->device->id, cmd->device->lun, name,
855 reset_errors[err]); 947 reset_errors[err]);
856 return FAILED; 948 return FAILED;
857} 949}
@@ -859,7 +951,8 @@ __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
859static int 951static int
860qla2xxx_eh_device_reset(struct scsi_cmnd *cmd) 952qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
861{ 953{
862 scsi_qla_host_t *ha = shost_priv(cmd->device->host); 954 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
955 struct qla_hw_data *ha = vha->hw;
863 956
864 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd, 957 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
865 ha->isp_ops->lun_reset); 958 ha->isp_ops->lun_reset);
@@ -868,7 +961,8 @@ qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
868static int 961static int
869qla2xxx_eh_target_reset(struct scsi_cmnd *cmd) 962qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
870{ 963{
871 scsi_qla_host_t *ha = shost_priv(cmd->device->host); 964 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
965 struct qla_hw_data *ha = vha->hw;
872 966
873 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd, 967 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
874 ha->isp_ops->target_reset); 968 ha->isp_ops->target_reset);
@@ -892,12 +986,12 @@ qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
892static int 986static int
893qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd) 987qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
894{ 988{
895 scsi_qla_host_t *ha = shost_priv(cmd->device->host); 989 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
896 scsi_qla_host_t *pha = to_qla_parent(ha);
897 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 990 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
898 int ret = FAILED; 991 int ret = FAILED;
899 unsigned int id, lun; 992 unsigned int id, lun;
900 unsigned long serial; 993 unsigned long serial;
994 srb_t *sp = (srb_t *) CMD_SP(cmd);
901 995
902 qla2x00_block_error_handler(cmd); 996 qla2x00_block_error_handler(cmd);
903 997
@@ -908,28 +1002,28 @@ qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
908 if (!fcport) 1002 if (!fcport)
909 return ret; 1003 return ret;
910 1004
911 qla_printk(KERN_INFO, ha, 1005 qla_printk(KERN_INFO, vha->hw,
912 "scsi(%ld:%d:%d): LOOP RESET ISSUED.\n", ha->host_no, id, lun); 1006 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
913 1007
914 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) { 1008 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
915 DEBUG2(printk("%s failed:board disabled\n",__func__)); 1009 DEBUG2(printk("%s failed:board disabled\n",__func__));
916 goto eh_bus_reset_done; 1010 goto eh_bus_reset_done;
917 } 1011 }
918 1012
919 if (qla2x00_wait_for_loop_ready(ha) == QLA_SUCCESS) { 1013 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
920 if (qla2x00_loop_reset(ha) == QLA_SUCCESS) 1014 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
921 ret = SUCCESS; 1015 ret = SUCCESS;
922 } 1016 }
923 if (ret == FAILED) 1017 if (ret == FAILED)
924 goto eh_bus_reset_done; 1018 goto eh_bus_reset_done;
925 1019
926 /* Flush outstanding commands. */ 1020 /* Flush outstanding commands. */
927 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) != 1021 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
928 QLA_SUCCESS) 1022 QLA_SUCCESS)
929 ret = FAILED; 1023 ret = FAILED;
930 1024
931eh_bus_reset_done: 1025eh_bus_reset_done:
932 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__, 1026 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
933 (ret == FAILED) ? "failed" : "succeded"); 1027 (ret == FAILED) ? "failed" : "succeded");
934 1028
935 return ret; 1029 return ret;
@@ -953,12 +1047,14 @@ eh_bus_reset_done:
953static int 1047static int
954qla2xxx_eh_host_reset(struct scsi_cmnd *cmd) 1048qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
955{ 1049{
956 scsi_qla_host_t *ha = shost_priv(cmd->device->host); 1050 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
957 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata; 1051 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1052 struct qla_hw_data *ha = vha->hw;
958 int ret = FAILED; 1053 int ret = FAILED;
959 unsigned int id, lun; 1054 unsigned int id, lun;
960 unsigned long serial; 1055 unsigned long serial;
961 scsi_qla_host_t *pha = to_qla_parent(ha); 1056 srb_t *sp = (srb_t *) CMD_SP(cmd);
1057 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
962 1058
963 qla2x00_block_error_handler(cmd); 1059 qla2x00_block_error_handler(cmd);
964 1060
@@ -970,9 +1066,9 @@ qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
970 return ret; 1066 return ret;
971 1067
972 qla_printk(KERN_INFO, ha, 1068 qla_printk(KERN_INFO, ha,
973 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no, id, lun); 1069 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
974 1070
975 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS) 1071 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
976 goto eh_host_reset_lock; 1072 goto eh_host_reset_lock;
977 1073
978 /* 1074 /*
@@ -983,26 +1079,28 @@ qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
983 * devices as lost kicking of the port_down_timer 1079 * devices as lost kicking of the port_down_timer
984 * while dpc is stuck for the mailbox to complete. 1080 * while dpc is stuck for the mailbox to complete.
985 */ 1081 */
986 qla2x00_wait_for_loop_ready(ha); 1082 qla2x00_wait_for_loop_ready(vha);
987 set_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags); 1083 if (vha != base_vha) {
988 if (qla2x00_abort_isp(pha)) { 1084 if (qla2x00_vp_abort_isp(vha))
989 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
990 /* failed. schedule dpc to try */
991 set_bit(ISP_ABORT_NEEDED, &pha->dpc_flags);
992
993 if (qla2x00_wait_for_hba_online(ha) != QLA_SUCCESS)
994 goto eh_host_reset_lock; 1085 goto eh_host_reset_lock;
1086 } else {
1087 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1088 if (qla2x00_abort_isp(base_vha)) {
1089 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1090 /* failed. schedule dpc to try */
1091 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1092
1093 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1094 goto eh_host_reset_lock;
1095 }
1096 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
995 } 1097 }
996 clear_bit(ABORT_ISP_ACTIVE, &pha->dpc_flags);
997 1098
998 /* Waiting for our command in done_queue to be returned to OS.*/ 1099 /* Waiting for command to be returned to OS.*/
999 if (qla2x00_eh_wait_for_pending_commands(pha, 0, 0, WAIT_HOST) == 1100 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
1000 QLA_SUCCESS) 1101 QLA_SUCCESS)
1001 ret = SUCCESS; 1102 ret = SUCCESS;
1002 1103
1003 if (ha->parent)
1004 qla2x00_vp_abort_isp(ha);
1005
1006eh_host_reset_lock: 1104eh_host_reset_lock:
1007 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__, 1105 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1008 (ret == FAILED) ? "failed" : "succeded"); 1106 (ret == FAILED) ? "failed" : "succeded");
@@ -1021,35 +1119,36 @@ eh_host_reset_lock:
1021* 0 = success 1119* 0 = success
1022*/ 1120*/
1023int 1121int
1024qla2x00_loop_reset(scsi_qla_host_t *ha) 1122qla2x00_loop_reset(scsi_qla_host_t *vha)
1025{ 1123{
1026 int ret; 1124 int ret;
1027 struct fc_port *fcport; 1125 struct fc_port *fcport;
1126 struct qla_hw_data *ha = vha->hw;
1028 1127
1029 if (ha->flags.enable_lip_full_login) { 1128 if (ha->flags.enable_lip_full_login && !vha->vp_idx) {
1030 ret = qla2x00_full_login_lip(ha); 1129 ret = qla2x00_full_login_lip(vha);
1031 if (ret != QLA_SUCCESS) { 1130 if (ret != QLA_SUCCESS) {
1032 DEBUG2_3(printk("%s(%ld): bus_reset failed: " 1131 DEBUG2_3(printk("%s(%ld): failed: "
1033 "full_login_lip=%d.\n", __func__, ha->host_no, 1132 "full_login_lip=%d.\n", __func__, vha->host_no,
1034 ret)); 1133 ret));
1035 } 1134 }
1036 atomic_set(&ha->loop_state, LOOP_DOWN); 1135 atomic_set(&vha->loop_state, LOOP_DOWN);
1037 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); 1136 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1038 qla2x00_mark_all_devices_lost(ha, 0); 1137 qla2x00_mark_all_devices_lost(vha, 0);
1039 qla2x00_wait_for_loop_ready(ha); 1138 qla2x00_wait_for_loop_ready(vha);
1040 } 1139 }
1041 1140
1042 if (ha->flags.enable_lip_reset) { 1141 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
1043 ret = qla2x00_lip_reset(ha); 1142 ret = qla2x00_lip_reset(vha);
1044 if (ret != QLA_SUCCESS) { 1143 if (ret != QLA_SUCCESS) {
1045 DEBUG2_3(printk("%s(%ld): bus_reset failed: " 1144 DEBUG2_3(printk("%s(%ld): failed: "
1046 "lip_reset=%d.\n", __func__, ha->host_no, ret)); 1145 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1047 } 1146 } else
1048 qla2x00_wait_for_loop_ready(ha); 1147 qla2x00_wait_for_loop_ready(vha);
1049 } 1148 }
1050 1149
1051 if (ha->flags.enable_target_reset) { 1150 if (ha->flags.enable_target_reset) {
1052 list_for_each_entry(fcport, &ha->fcports, list) { 1151 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1053 if (fcport->port_type != FCT_TARGET) 1152 if (fcport->port_type != FCT_TARGET)
1054 continue; 1153 continue;
1055 1154
@@ -1057,31 +1156,37 @@ qla2x00_loop_reset(scsi_qla_host_t *ha)
1057 if (ret != QLA_SUCCESS) { 1156 if (ret != QLA_SUCCESS) {
1058 DEBUG2_3(printk("%s(%ld): bus_reset failed: " 1157 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1059 "target_reset=%d d_id=%x.\n", __func__, 1158 "target_reset=%d d_id=%x.\n", __func__,
1060 ha->host_no, ret, fcport->d_id.b24)); 1159 vha->host_no, ret, fcport->d_id.b24));
1061 } 1160 }
1062 } 1161 }
1063 } 1162 }
1064
1065 /* Issue marker command only when we are going to start the I/O */ 1163 /* Issue marker command only when we are going to start the I/O */
1066 ha->marker_needed = 1; 1164 vha->marker_needed = 1;
1067 1165
1068 return QLA_SUCCESS; 1166 return QLA_SUCCESS;
1069} 1167}
1070 1168
1071void 1169void
1072qla2x00_abort_all_cmds(scsi_qla_host_t *ha, int res) 1170qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1073{ 1171{
1074 int cnt; 1172 int que, cnt;
1075 unsigned long flags; 1173 unsigned long flags;
1076 srb_t *sp; 1174 srb_t *sp;
1175 struct qla_hw_data *ha = vha->hw;
1176 struct req_que *req;
1077 1177
1078 spin_lock_irqsave(&ha->hardware_lock, flags); 1178 spin_lock_irqsave(&ha->hardware_lock, flags);
1079 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) { 1179 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
1080 sp = ha->outstanding_cmds[cnt]; 1180 req = ha->req_q_map[vha->req_ques[que]];
1081 if (sp) { 1181 if (!req)
1082 ha->outstanding_cmds[cnt] = NULL; 1182 continue;
1083 sp->cmd->result = res; 1183 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1084 qla2x00_sp_compl(ha, sp); 1184 sp = req->outstanding_cmds[cnt];
1185 if (sp && sp->vha == vha) {
1186 req->outstanding_cmds[cnt] = NULL;
1187 sp->cmd->result = res;
1188 qla2x00_sp_compl(ha, sp);
1189 }
1085 } 1190 }
1086 } 1191 }
1087 spin_unlock_irqrestore(&ha->hardware_lock, flags); 1192 spin_unlock_irqrestore(&ha->hardware_lock, flags);
@@ -1103,13 +1208,15 @@ qla2xxx_slave_alloc(struct scsi_device *sdev)
1103static int 1208static int
1104qla2xxx_slave_configure(struct scsi_device *sdev) 1209qla2xxx_slave_configure(struct scsi_device *sdev)
1105{ 1210{
1106 scsi_qla_host_t *ha = shost_priv(sdev->host); 1211 scsi_qla_host_t *vha = shost_priv(sdev->host);
1212 struct qla_hw_data *ha = vha->hw;
1107 struct fc_rport *rport = starget_to_rport(sdev->sdev_target); 1213 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
1214 struct req_que *req = ha->req_q_map[0];
1108 1215
1109 if (sdev->tagged_supported) 1216 if (sdev->tagged_supported)
1110 scsi_activate_tcq(sdev, ha->max_q_depth); 1217 scsi_activate_tcq(sdev, req->max_q_depth);
1111 else 1218 else
1112 scsi_deactivate_tcq(sdev, ha->max_q_depth); 1219 scsi_deactivate_tcq(sdev, req->max_q_depth);
1113 1220
1114 rport->dev_loss_tmo = ha->port_down_retry_count; 1221 rport->dev_loss_tmo = ha->port_down_retry_count;
1115 1222
@@ -1152,8 +1259,9 @@ qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1152 * supported addressing method. 1259 * supported addressing method.
1153 */ 1260 */
1154static void 1261static void
1155qla2x00_config_dma_addressing(scsi_qla_host_t *ha) 1262qla2x00_config_dma_addressing(scsi_qla_host_t *vha)
1156{ 1263{
1264 struct qla_hw_data *ha = vha->hw;
1157 /* Assume a 32bit DMA mask. */ 1265 /* Assume a 32bit DMA mask. */
1158 ha->flags.enable_64bit_addressing = 0; 1266 ha->flags.enable_64bit_addressing = 0;
1159 1267
@@ -1174,7 +1282,7 @@ qla2x00_config_dma_addressing(scsi_qla_host_t *ha)
1174} 1282}
1175 1283
1176static void 1284static void
1177qla2x00_enable_intrs(scsi_qla_host_t *ha) 1285qla2x00_enable_intrs(struct qla_hw_data *ha)
1178{ 1286{
1179 unsigned long flags = 0; 1287 unsigned long flags = 0;
1180 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 1288 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
@@ -1189,7 +1297,7 @@ qla2x00_enable_intrs(scsi_qla_host_t *ha)
1189} 1297}
1190 1298
1191static void 1299static void
1192qla2x00_disable_intrs(scsi_qla_host_t *ha) 1300qla2x00_disable_intrs(struct qla_hw_data *ha)
1193{ 1301{
1194 unsigned long flags = 0; 1302 unsigned long flags = 0;
1195 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 1303 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
@@ -1203,7 +1311,7 @@ qla2x00_disable_intrs(scsi_qla_host_t *ha)
1203} 1311}
1204 1312
1205static void 1313static void
1206qla24xx_enable_intrs(scsi_qla_host_t *ha) 1314qla24xx_enable_intrs(struct qla_hw_data *ha)
1207{ 1315{
1208 unsigned long flags = 0; 1316 unsigned long flags = 0;
1209 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; 1317 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
@@ -1216,7 +1324,7 @@ qla24xx_enable_intrs(scsi_qla_host_t *ha)
1216} 1324}
1217 1325
1218static void 1326static void
1219qla24xx_disable_intrs(scsi_qla_host_t *ha) 1327qla24xx_disable_intrs(struct qla_hw_data *ha)
1220{ 1328{
1221 unsigned long flags = 0; 1329 unsigned long flags = 0;
1222 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; 1330 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
@@ -1260,6 +1368,10 @@ static struct isp_operations qla2100_isp_ops = {
1260 .read_optrom = qla2x00_read_optrom_data, 1368 .read_optrom = qla2x00_read_optrom_data,
1261 .write_optrom = qla2x00_write_optrom_data, 1369 .write_optrom = qla2x00_write_optrom_data,
1262 .get_flash_version = qla2x00_get_flash_version, 1370 .get_flash_version = qla2x00_get_flash_version,
1371 .start_scsi = qla2x00_start_scsi,
1372 .wrt_req_reg = NULL,
1373 .wrt_rsp_reg = NULL,
1374 .rd_req_reg = NULL,
1263}; 1375};
1264 1376
1265static struct isp_operations qla2300_isp_ops = { 1377static struct isp_operations qla2300_isp_ops = {
@@ -1294,6 +1406,10 @@ static struct isp_operations qla2300_isp_ops = {
1294 .read_optrom = qla2x00_read_optrom_data, 1406 .read_optrom = qla2x00_read_optrom_data,
1295 .write_optrom = qla2x00_write_optrom_data, 1407 .write_optrom = qla2x00_write_optrom_data,
1296 .get_flash_version = qla2x00_get_flash_version, 1408 .get_flash_version = qla2x00_get_flash_version,
1409 .start_scsi = qla2x00_start_scsi,
1410 .wrt_req_reg = NULL,
1411 .wrt_rsp_reg = NULL,
1412 .rd_req_reg = NULL,
1297}; 1413};
1298 1414
1299static struct isp_operations qla24xx_isp_ops = { 1415static struct isp_operations qla24xx_isp_ops = {
@@ -1328,6 +1444,10 @@ static struct isp_operations qla24xx_isp_ops = {
1328 .read_optrom = qla24xx_read_optrom_data, 1444 .read_optrom = qla24xx_read_optrom_data,
1329 .write_optrom = qla24xx_write_optrom_data, 1445 .write_optrom = qla24xx_write_optrom_data,
1330 .get_flash_version = qla24xx_get_flash_version, 1446 .get_flash_version = qla24xx_get_flash_version,
1447 .start_scsi = qla24xx_start_scsi,
1448 .wrt_req_reg = qla24xx_wrt_req_reg,
1449 .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
1450 .rd_req_reg = qla24xx_rd_req_reg,
1331}; 1451};
1332 1452
1333static struct isp_operations qla25xx_isp_ops = { 1453static struct isp_operations qla25xx_isp_ops = {
@@ -1362,10 +1482,14 @@ static struct isp_operations qla25xx_isp_ops = {
1362 .read_optrom = qla25xx_read_optrom_data, 1482 .read_optrom = qla25xx_read_optrom_data,
1363 .write_optrom = qla24xx_write_optrom_data, 1483 .write_optrom = qla24xx_write_optrom_data,
1364 .get_flash_version = qla24xx_get_flash_version, 1484 .get_flash_version = qla24xx_get_flash_version,
1485 .start_scsi = qla24xx_start_scsi,
1486 .wrt_req_reg = qla24xx_wrt_req_reg,
1487 .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
1488 .rd_req_reg = qla24xx_rd_req_reg,
1365}; 1489};
1366 1490
1367static inline void 1491static inline void
1368qla2x00_set_isp_flags(scsi_qla_host_t *ha) 1492qla2x00_set_isp_flags(struct qla_hw_data *ha)
1369{ 1493{
1370 ha->device_type = DT_EXTENDED_IDS; 1494 ha->device_type = DT_EXTENDED_IDS;
1371 switch (ha->pdev->device) { 1495 switch (ha->pdev->device) {
@@ -1447,9 +1571,10 @@ qla2x00_set_isp_flags(scsi_qla_host_t *ha)
1447} 1571}
1448 1572
1449static int 1573static int
1450qla2x00_iospace_config(scsi_qla_host_t *ha) 1574qla2x00_iospace_config(struct qla_hw_data *ha)
1451{ 1575{
1452 resource_size_t pio; 1576 resource_size_t pio;
1577 uint16_t msix;
1453 1578
1454 if (pci_request_selected_regions(ha->pdev, ha->bars, 1579 if (pci_request_selected_regions(ha->pdev, ha->bars,
1455 QLA2XXX_DRIVER_NAME)) { 1580 QLA2XXX_DRIVER_NAME)) {
@@ -1502,6 +1627,30 @@ skip_pio:
1502 goto iospace_error_exit; 1627 goto iospace_error_exit;
1503 } 1628 }
1504 1629
1630 /* Determine queue resources */
1631 ha->max_queues = 1;
1632 if (ql2xmaxqueues <= 1 || !IS_QLA25XX(ha))
1633 goto mqiobase_exit;
1634 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1635 pci_resource_len(ha->pdev, 3));
1636 if (ha->mqiobase) {
1637 /* Read MSIX vector size of the board */
1638 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1639 ha->msix_count = msix;
1640 /* Max queues are bounded by available msix vectors */
1641 /* queue 0 uses two msix vectors */
1642 if (ha->msix_count - 1 < ql2xmaxqueues)
1643 ha->max_queues = ha->msix_count - 1;
1644 else if (ql2xmaxqueues > QLA_MQ_SIZE)
1645 ha->max_queues = QLA_MQ_SIZE;
1646 else
1647 ha->max_queues = ql2xmaxqueues;
1648 qla_printk(KERN_INFO, ha,
1649 "MSI-X vector count: %d\n", msix);
1650 }
1651
1652mqiobase_exit:
1653 ha->msix_count = ha->max_queues + 1;
1505 return (0); 1654 return (0);
1506 1655
1507iospace_error_exit: 1656iospace_error_exit:
@@ -1511,25 +1660,25 @@ iospace_error_exit:
1511static void 1660static void
1512qla2xxx_scan_start(struct Scsi_Host *shost) 1661qla2xxx_scan_start(struct Scsi_Host *shost)
1513{ 1662{
1514 scsi_qla_host_t *ha = shost_priv(shost); 1663 scsi_qla_host_t *vha = shost_priv(shost);
1515 1664
1516 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); 1665 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1517 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); 1666 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1518 set_bit(RSCN_UPDATE, &ha->dpc_flags); 1667 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1519 set_bit(NPIV_CONFIG_NEEDED, &ha->dpc_flags); 1668 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
1520} 1669}
1521 1670
1522static int 1671static int
1523qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time) 1672qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1524{ 1673{
1525 scsi_qla_host_t *ha = shost_priv(shost); 1674 scsi_qla_host_t *vha = shost_priv(shost);
1526 1675
1527 if (!ha->host) 1676 if (!vha->host)
1528 return 1; 1677 return 1;
1529 if (time > ha->loop_reset_delay * HZ) 1678 if (time > vha->hw->loop_reset_delay * HZ)
1530 return 1; 1679 return 1;
1531 1680
1532 return atomic_read(&ha->loop_state) == LOOP_READY; 1681 return atomic_read(&vha->loop_state) == LOOP_READY;
1533} 1682}
1534 1683
1535/* 1684/*
@@ -1540,11 +1689,15 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1540{ 1689{
1541 int ret = -ENODEV; 1690 int ret = -ENODEV;
1542 struct Scsi_Host *host; 1691 struct Scsi_Host *host;
1543 scsi_qla_host_t *ha; 1692 scsi_qla_host_t *base_vha = NULL;
1693 struct qla_hw_data *ha;
1544 char pci_info[30]; 1694 char pci_info[30];
1545 char fw_str[30]; 1695 char fw_str[30];
1546 struct scsi_host_template *sht; 1696 struct scsi_host_template *sht;
1547 int bars, mem_only = 0; 1697 int bars, max_id, mem_only = 0;
1698 uint16_t req_length = 0, rsp_length = 0;
1699 struct req_que *req = NULL;
1700 struct rsp_que *rsp = NULL;
1548 1701
1549 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO); 1702 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
1550 sht = &qla2x00_driver_template; 1703 sht = &qla2x00_driver_template;
@@ -1570,33 +1723,24 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1570 /* This may fail but that's ok */ 1723 /* This may fail but that's ok */
1571 pci_enable_pcie_error_reporting(pdev); 1724 pci_enable_pcie_error_reporting(pdev);
1572 1725
1573 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t)); 1726 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1574 if (host == NULL) { 1727 if (!ha) {
1575 printk(KERN_WARNING 1728 DEBUG(printk("Unable to allocate memory for ha\n"));
1576 "qla2xxx: Couldn't allocate host from scsi layer!\n"); 1729 goto probe_out;
1577 goto probe_disable_device;
1578 } 1730 }
1731 ha->pdev = pdev;
1579 1732
1580 /* Clear our data area */ 1733 /* Clear our data area */
1581 ha = shost_priv(host);
1582 memset(ha, 0, sizeof(scsi_qla_host_t));
1583
1584 ha->pdev = pdev;
1585 ha->host = host;
1586 ha->host_no = host->host_no;
1587 sprintf(ha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, ha->host_no);
1588 ha->parent = NULL;
1589 ha->bars = bars; 1734 ha->bars = bars;
1590 ha->mem_only = mem_only; 1735 ha->mem_only = mem_only;
1591 spin_lock_init(&ha->hardware_lock); 1736 spin_lock_init(&ha->hardware_lock);
1592 1737
1593 /* Set ISP-type information. */ 1738 /* Set ISP-type information. */
1594 qla2x00_set_isp_flags(ha); 1739 qla2x00_set_isp_flags(ha);
1595
1596 /* Configure PCI I/O space */ 1740 /* Configure PCI I/O space */
1597 ret = qla2x00_iospace_config(ha); 1741 ret = qla2x00_iospace_config(ha);
1598 if (ret) 1742 if (ret)
1599 goto probe_failed; 1743 goto probe_hw_failed;
1600 1744
1601 qla_printk(KERN_INFO, ha, 1745 qla_printk(KERN_INFO, ha,
1602 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq, 1746 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
@@ -1604,95 +1748,137 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1604 1748
1605 ha->prev_topology = 0; 1749 ha->prev_topology = 0;
1606 ha->init_cb_size = sizeof(init_cb_t); 1750 ha->init_cb_size = sizeof(init_cb_t);
1607 ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx;
1608 ha->link_data_rate = PORT_SPEED_UNKNOWN; 1751 ha->link_data_rate = PORT_SPEED_UNKNOWN;
1609 ha->optrom_size = OPTROM_SIZE_2300; 1752 ha->optrom_size = OPTROM_SIZE_2300;
1610 1753
1611 ha->max_q_depth = MAX_Q_DEPTH;
1612 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1613 ha->max_q_depth = ql2xmaxqdepth;
1614
1615 /* Assign ISP specific operations. */ 1754 /* Assign ISP specific operations. */
1755 max_id = MAX_TARGETS_2200;
1616 if (IS_QLA2100(ha)) { 1756 if (IS_QLA2100(ha)) {
1617 host->max_id = MAX_TARGETS_2100; 1757 max_id = MAX_TARGETS_2100;
1618 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100; 1758 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
1619 ha->request_q_length = REQUEST_ENTRY_CNT_2100; 1759 req_length = REQUEST_ENTRY_CNT_2100;
1620 ha->response_q_length = RESPONSE_ENTRY_CNT_2100; 1760 rsp_length = RESPONSE_ENTRY_CNT_2100;
1621 ha->last_loop_id = SNS_LAST_LOOP_ID_2100; 1761 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1622 host->sg_tablesize = 32;
1623 ha->gid_list_info_size = 4; 1762 ha->gid_list_info_size = 4;
1624 ha->isp_ops = &qla2100_isp_ops; 1763 ha->isp_ops = &qla2100_isp_ops;
1625 } else if (IS_QLA2200(ha)) { 1764 } else if (IS_QLA2200(ha)) {
1626 host->max_id = MAX_TARGETS_2200;
1627 ha->mbx_count = MAILBOX_REGISTER_COUNT; 1765 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1628 ha->request_q_length = REQUEST_ENTRY_CNT_2200; 1766 req_length = REQUEST_ENTRY_CNT_2200;
1629 ha->response_q_length = RESPONSE_ENTRY_CNT_2100; 1767 rsp_length = RESPONSE_ENTRY_CNT_2100;
1630 ha->last_loop_id = SNS_LAST_LOOP_ID_2100; 1768 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
1631 ha->gid_list_info_size = 4; 1769 ha->gid_list_info_size = 4;
1632 ha->isp_ops = &qla2100_isp_ops; 1770 ha->isp_ops = &qla2100_isp_ops;
1633 } else if (IS_QLA23XX(ha)) { 1771 } else if (IS_QLA23XX(ha)) {
1634 host->max_id = MAX_TARGETS_2200;
1635 ha->mbx_count = MAILBOX_REGISTER_COUNT; 1772 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1636 ha->request_q_length = REQUEST_ENTRY_CNT_2200; 1773 req_length = REQUEST_ENTRY_CNT_2200;
1637 ha->response_q_length = RESPONSE_ENTRY_CNT_2300; 1774 rsp_length = RESPONSE_ENTRY_CNT_2300;
1638 ha->last_loop_id = SNS_LAST_LOOP_ID_2300; 1775 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1639 ha->gid_list_info_size = 6; 1776 ha->gid_list_info_size = 6;
1640 if (IS_QLA2322(ha) || IS_QLA6322(ha)) 1777 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1641 ha->optrom_size = OPTROM_SIZE_2322; 1778 ha->optrom_size = OPTROM_SIZE_2322;
1642 ha->isp_ops = &qla2300_isp_ops; 1779 ha->isp_ops = &qla2300_isp_ops;
1643 } else if (IS_QLA24XX_TYPE(ha)) { 1780 } else if (IS_QLA24XX_TYPE(ha)) {
1644 host->max_id = MAX_TARGETS_2200;
1645 ha->mbx_count = MAILBOX_REGISTER_COUNT; 1781 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1646 ha->request_q_length = REQUEST_ENTRY_CNT_24XX; 1782 req_length = REQUEST_ENTRY_CNT_24XX;
1647 ha->response_q_length = RESPONSE_ENTRY_CNT_2300; 1783 rsp_length = RESPONSE_ENTRY_CNT_2300;
1648 ha->last_loop_id = SNS_LAST_LOOP_ID_2300; 1784 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1649 ha->init_cb_size = sizeof(struct mid_init_cb_24xx); 1785 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1650 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
1651 ha->gid_list_info_size = 8; 1786 ha->gid_list_info_size = 8;
1652 ha->optrom_size = OPTROM_SIZE_24XX; 1787 ha->optrom_size = OPTROM_SIZE_24XX;
1788 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
1653 ha->isp_ops = &qla24xx_isp_ops; 1789 ha->isp_ops = &qla24xx_isp_ops;
1654 } else if (IS_QLA25XX(ha)) { 1790 } else if (IS_QLA25XX(ha)) {
1655 host->max_id = MAX_TARGETS_2200;
1656 ha->mbx_count = MAILBOX_REGISTER_COUNT; 1791 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1657 ha->request_q_length = REQUEST_ENTRY_CNT_24XX; 1792 req_length = REQUEST_ENTRY_CNT_24XX;
1658 ha->response_q_length = RESPONSE_ENTRY_CNT_2300; 1793 rsp_length = RESPONSE_ENTRY_CNT_2300;
1659 ha->last_loop_id = SNS_LAST_LOOP_ID_2300; 1794 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1660 ha->init_cb_size = sizeof(struct mid_init_cb_24xx); 1795 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1661 ha->mgmt_svr_loop_id = 10 + ha->vp_idx;
1662 ha->gid_list_info_size = 8; 1796 ha->gid_list_info_size = 8;
1663 ha->optrom_size = OPTROM_SIZE_25XX; 1797 ha->optrom_size = OPTROM_SIZE_25XX;
1798 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
1664 ha->isp_ops = &qla25xx_isp_ops; 1799 ha->isp_ops = &qla25xx_isp_ops;
1665 } 1800 }
1666 host->can_queue = ha->request_q_length + 128;
1667 1801
1668 mutex_init(&ha->vport_lock); 1802 mutex_init(&ha->vport_lock);
1669 init_completion(&ha->mbx_cmd_comp); 1803 init_completion(&ha->mbx_cmd_comp);
1670 complete(&ha->mbx_cmd_comp); 1804 complete(&ha->mbx_cmd_comp);
1671 init_completion(&ha->mbx_intr_comp); 1805 init_completion(&ha->mbx_intr_comp);
1672 1806
1673 INIT_LIST_HEAD(&ha->list);
1674 INIT_LIST_HEAD(&ha->fcports);
1675 INIT_LIST_HEAD(&ha->vp_list);
1676 INIT_LIST_HEAD(&ha->work_list);
1677
1678 set_bit(0, (unsigned long *) ha->vp_idx_map); 1807 set_bit(0, (unsigned long *) ha->vp_idx_map);
1679 1808
1680 qla2x00_config_dma_addressing(ha); 1809 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
1681 if (qla2x00_mem_alloc(ha)) { 1810 if (!ret) {
1682 qla_printk(KERN_WARNING, ha, 1811 qla_printk(KERN_WARNING, ha,
1683 "[ERROR] Failed to allocate memory for adapter\n"); 1812 "[ERROR] Failed to allocate memory for adapter\n");
1684 1813
1814 goto probe_hw_failed;
1815 }
1816
1817 req->max_q_depth = MAX_Q_DEPTH;
1818 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
1819 req->max_q_depth = ql2xmaxqdepth;
1820
1821
1822 base_vha = qla2x00_create_host(sht, ha);
1823 if (!base_vha) {
1824 qla_printk(KERN_WARNING, ha,
1825 "[ERROR] Failed to allocate memory for scsi_host\n");
1826
1685 ret = -ENOMEM; 1827 ret = -ENOMEM;
1828 goto probe_hw_failed;
1829 }
1830
1831 pci_set_drvdata(pdev, base_vha);
1832
1833 qla2x00_config_dma_addressing(base_vha);
1834
1835 host = base_vha->host;
1836 base_vha->req_ques[0] = req->id;
1837 host->can_queue = req->length + 128;
1838 if (IS_QLA2XXX_MIDTYPE(ha))
1839 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
1840 else
1841 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1842 base_vha->vp_idx;
1843 if (IS_QLA2100(ha))
1844 host->sg_tablesize = 32;
1845 host->max_id = max_id;
1846 host->this_id = 255;
1847 host->cmd_per_lun = 3;
1848 host->unique_id = host->host_no;
1849 host->max_cmd_len = MAX_CMDSZ;
1850 host->max_channel = MAX_BUSES - 1;
1851 host->max_lun = MAX_LUNS;
1852 host->transportt = qla2xxx_transport_template;
1853
1854 /* Set up the irqs */
1855 ret = qla2x00_request_irqs(ha, rsp);
1856 if (ret)
1857 goto probe_failed;
1858
1859 /* Alloc arrays of request and response ring ptrs */
1860 if (!qla2x00_alloc_queues(ha)) {
1861 qla_printk(KERN_WARNING, ha,
1862 "[ERROR] Failed to allocate memory for queue"
1863 " pointers\n");
1686 goto probe_failed; 1864 goto probe_failed;
1687 } 1865 }
1866 ha->rsp_q_map[0] = rsp;
1867 ha->req_q_map[0] = req;
1688 1868
1689 if (qla2x00_initialize_adapter(ha)) { 1869 if (ha->mqenable) {
1870 ha->isp_ops->wrt_req_reg = qla25xx_wrt_req_reg;
1871 ha->isp_ops->wrt_rsp_reg = qla25xx_wrt_rsp_reg;
1872 ha->isp_ops->rd_req_reg = qla25xx_rd_req_reg;
1873 }
1874
1875 if (qla2x00_initialize_adapter(base_vha)) {
1690 qla_printk(KERN_WARNING, ha, 1876 qla_printk(KERN_WARNING, ha,
1691 "Failed to initialize adapter\n"); 1877 "Failed to initialize adapter\n");
1692 1878
1693 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - " 1879 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1694 "Adapter flags %x.\n", 1880 "Adapter flags %x.\n",
1695 ha->host_no, ha->device_flags)); 1881 base_vha->host_no, base_vha->device_flags));
1696 1882
1697 ret = -ENODEV; 1883 ret = -ENODEV;
1698 goto probe_failed; 1884 goto probe_failed;
@@ -1702,7 +1888,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1702 * Startup the kernel thread for this host adapter 1888 * Startup the kernel thread for this host adapter
1703 */ 1889 */
1704 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha, 1890 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1705 "%s_dpc", ha->host_str); 1891 "%s_dpc", base_vha->host_str);
1706 if (IS_ERR(ha->dpc_thread)) { 1892 if (IS_ERR(ha->dpc_thread)) {
1707 qla_printk(KERN_WARNING, ha, 1893 qla_printk(KERN_WARNING, ha,
1708 "Unable to start DPC thread!\n"); 1894 "Unable to start DPC thread!\n");
@@ -1710,28 +1896,17 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1710 goto probe_failed; 1896 goto probe_failed;
1711 } 1897 }
1712 1898
1713 host->this_id = 255; 1899 list_add_tail(&base_vha->list, &ha->vp_list);
1714 host->cmd_per_lun = 3; 1900 base_vha->host->irq = ha->pdev->irq;
1715 host->unique_id = host->host_no;
1716 host->max_cmd_len = MAX_CMDSZ;
1717 host->max_channel = MAX_BUSES - 1;
1718 host->max_lun = MAX_LUNS;
1719 host->transportt = qla2xxx_transport_template;
1720
1721 ret = qla2x00_request_irqs(ha);
1722 if (ret)
1723 goto probe_failed;
1724 1901
1725 /* Initialized the timer */ 1902 /* Initialized the timer */
1726 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL); 1903 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
1727 1904
1728 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n", 1905 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
1729 ha->host_no, ha)); 1906 base_vha->host_no, ha));
1730 1907
1731 pci_set_drvdata(pdev, ha); 1908 base_vha->flags.init_done = 1;
1732 1909 base_vha->flags.online = 1;
1733 ha->flags.init_done = 1;
1734 ha->flags.online = 1;
1735 1910
1736 ret = scsi_add_host(host, &pdev->dev); 1911 ret = scsi_add_host(host, &pdev->dev);
1737 if (ret) 1912 if (ret)
@@ -1741,76 +1916,98 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1741 1916
1742 scsi_scan_host(host); 1917 scsi_scan_host(host);
1743 1918
1744 qla2x00_alloc_sysfs_attr(ha); 1919 qla2x00_alloc_sysfs_attr(base_vha);
1745 1920
1746 qla2x00_init_host_attr(ha); 1921 qla2x00_init_host_attr(base_vha);
1747 1922
1748 qla2x00_dfs_setup(ha); 1923 qla2x00_dfs_setup(base_vha);
1749 1924
1750 qla_printk(KERN_INFO, ha, "\n" 1925 qla_printk(KERN_INFO, ha, "\n"
1751 " QLogic Fibre Channel HBA Driver: %s\n" 1926 " QLogic Fibre Channel HBA Driver: %s\n"
1752 " QLogic %s - %s\n" 1927 " QLogic %s - %s\n"
1753 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n", 1928 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1754 qla2x00_version_str, ha->model_number, 1929 qla2x00_version_str, ha->model_number,
1755 ha->model_desc ? ha->model_desc: "", pdev->device, 1930 ha->model_desc ? ha->model_desc : "", pdev->device,
1756 ha->isp_ops->pci_info_str(ha, pci_info), pci_name(pdev), 1931 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
1757 ha->flags.enable_64bit_addressing ? '+': '-', ha->host_no, 1932 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
1758 ha->isp_ops->fw_version_str(ha, fw_str)); 1933 ha->isp_ops->fw_version_str(base_vha, fw_str));
1759 1934
1760 return 0; 1935 return 0;
1761 1936
1762probe_failed: 1937probe_failed:
1763 qla2x00_free_device(ha); 1938 qla2x00_free_que(ha, req, rsp);
1939 qla2x00_free_device(base_vha);
1764 1940
1765 scsi_host_put(host); 1941 scsi_host_put(base_vha->host);
1766 1942
1767probe_disable_device: 1943probe_hw_failed:
1768 pci_disable_device(pdev); 1944 if (ha->iobase)
1945 iounmap(ha->iobase);
1946
1947 pci_release_selected_regions(ha->pdev, ha->bars);
1948 kfree(ha);
1949 ha = NULL;
1769 1950
1770probe_out: 1951probe_out:
1952 pci_disable_device(pdev);
1771 return ret; 1953 return ret;
1772} 1954}
1773 1955
1774static void 1956static void
1775qla2x00_remove_one(struct pci_dev *pdev) 1957qla2x00_remove_one(struct pci_dev *pdev)
1776{ 1958{
1777 scsi_qla_host_t *ha, *vha, *temp; 1959 scsi_qla_host_t *base_vha, *vha, *temp;
1960 struct qla_hw_data *ha;
1961
1962 base_vha = pci_get_drvdata(pdev);
1963 ha = base_vha->hw;
1964
1965 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
1966 if (vha && vha->fc_vport)
1967 fc_vport_terminate(vha->fc_vport);
1968 }
1778 1969
1779 ha = pci_get_drvdata(pdev); 1970 set_bit(UNLOADING, &base_vha->dpc_flags);
1780 1971
1781 list_for_each_entry_safe(vha, temp, &ha->vp_list, vp_list) 1972 qla2x00_dfs_remove(base_vha);
1782 fc_vport_terminate(vha->fc_vport);
1783 1973
1784 set_bit(UNLOADING, &ha->dpc_flags); 1974 qla84xx_put_chip(base_vha);
1785 1975
1786 qla2x00_dfs_remove(ha); 1976 qla2x00_free_sysfs_attr(base_vha);
1787 1977
1788 qla84xx_put_chip(ha); 1978 fc_remove_host(base_vha->host);
1789 1979
1790 qla2x00_free_sysfs_attr(ha); 1980 scsi_remove_host(base_vha->host);
1791 1981
1792 fc_remove_host(ha->host); 1982 qla2x00_free_device(base_vha);
1793 1983
1794 scsi_remove_host(ha->host); 1984 scsi_host_put(base_vha->host);
1795 1985
1796 qla2x00_free_device(ha); 1986 if (ha->iobase)
1987 iounmap(ha->iobase);
1797 1988
1798 scsi_host_put(ha->host); 1989 if (ha->mqiobase)
1990 iounmap(ha->mqiobase);
1991
1992 pci_release_selected_regions(ha->pdev, ha->bars);
1993 kfree(ha);
1994 ha = NULL;
1799 1995
1800 pci_disable_device(pdev); 1996 pci_disable_device(pdev);
1801 pci_set_drvdata(pdev, NULL); 1997 pci_set_drvdata(pdev, NULL);
1802} 1998}
1803 1999
1804static void 2000static void
1805qla2x00_free_device(scsi_qla_host_t *ha) 2001qla2x00_free_device(scsi_qla_host_t *vha)
1806{ 2002{
1807 qla2x00_abort_all_cmds(ha, DID_NO_CONNECT << 16); 2003 struct qla_hw_data *ha = vha->hw;
2004 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
1808 2005
1809 /* Disable timer */ 2006 /* Disable timer */
1810 if (ha->timer_active) 2007 if (vha->timer_active)
1811 qla2x00_stop_timer(ha); 2008 qla2x00_stop_timer(vha);
1812 2009
1813 ha->flags.online = 0; 2010 vha->flags.online = 0;
1814 2011
1815 /* Kill the kernel thread for this host */ 2012 /* Kill the kernel thread for this host */
1816 if (ha->dpc_thread) { 2013 if (ha->dpc_thread) {
@@ -1825,45 +2022,41 @@ qla2x00_free_device(scsi_qla_host_t *ha)
1825 } 2022 }
1826 2023
1827 if (ha->flags.fce_enabled) 2024 if (ha->flags.fce_enabled)
1828 qla2x00_disable_fce_trace(ha, NULL, NULL); 2025 qla2x00_disable_fce_trace(vha, NULL, NULL);
1829 2026
1830 if (ha->eft) 2027 if (ha->eft)
1831 qla2x00_disable_eft_trace(ha); 2028 qla2x00_disable_eft_trace(vha);
1832 2029
1833 /* Stop currently executing firmware. */ 2030 /* Stop currently executing firmware. */
1834 qla2x00_try_to_stop_firmware(ha); 2031 qla2x00_try_to_stop_firmware(vha);
1835 2032
1836 /* turn-off interrupts on the card */ 2033 /* turn-off interrupts on the card */
1837 if (ha->interrupts_on) 2034 if (ha->interrupts_on)
1838 ha->isp_ops->disable_intrs(ha); 2035 ha->isp_ops->disable_intrs(ha);
1839 2036
1840 qla2x00_mem_free(ha); 2037 qla2x00_free_irqs(vha);
1841 2038
1842 qla2x00_free_irqs(ha); 2039 qla2x00_mem_free(ha);
1843 2040
1844 /* release io space registers */ 2041 qla2x00_free_queues(ha);
1845 if (ha->iobase)
1846 iounmap(ha->iobase);
1847 pci_release_selected_regions(ha->pdev, ha->bars);
1848} 2042}
1849 2043
1850static inline void 2044static inline void
1851qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport, 2045qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
1852 int defer) 2046 int defer)
1853{ 2047{
1854 struct fc_rport *rport; 2048 struct fc_rport *rport;
1855 scsi_qla_host_t *pha = to_qla_parent(ha);
1856 2049
1857 if (!fcport->rport) 2050 if (!fcport->rport)
1858 return; 2051 return;
1859 2052
1860 rport = fcport->rport; 2053 rport = fcport->rport;
1861 if (defer) { 2054 if (defer) {
1862 spin_lock_irq(ha->host->host_lock); 2055 spin_lock_irq(vha->host->host_lock);
1863 fcport->drport = rport; 2056 fcport->drport = rport;
1864 spin_unlock_irq(ha->host->host_lock); 2057 spin_unlock_irq(vha->host->host_lock);
1865 set_bit(FCPORT_UPDATE_NEEDED, &pha->dpc_flags); 2058 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
1866 qla2xxx_wake_dpc(pha); 2059 qla2xxx_wake_dpc(vha);
1867 } else 2060 } else
1868 fc_remote_port_delete(rport); 2061 fc_remote_port_delete(rport);
1869} 2062}
@@ -1877,13 +2070,14 @@ qla2x00_schedule_rport_del(struct scsi_qla_host *ha, fc_port_t *fcport,
1877 * 2070 *
1878 * Context: 2071 * Context:
1879 */ 2072 */
1880void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport, 2073void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
1881 int do_login, int defer) 2074 int do_login, int defer)
1882{ 2075{
1883 if (atomic_read(&fcport->state) == FCS_ONLINE && 2076 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1884 ha->vp_idx == fcport->vp_idx) 2077 vha->vp_idx == fcport->vp_idx) {
1885 qla2x00_schedule_rport_del(ha, fcport, defer); 2078 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1886 2079 qla2x00_schedule_rport_del(vha, fcport, defer);
2080 }
1887 /* 2081 /*
1888 * We may need to retry the login, so don't change the state of the 2082 * We may need to retry the login, so don't change the state of the
1889 * port but do the retries. 2083 * port but do the retries.
@@ -1895,13 +2089,13 @@ void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1895 return; 2089 return;
1896 2090
1897 if (fcport->login_retry == 0) { 2091 if (fcport->login_retry == 0) {
1898 fcport->login_retry = ha->login_retry_count; 2092 fcport->login_retry = vha->hw->login_retry_count;
1899 set_bit(RELOGIN_NEEDED, &ha->dpc_flags); 2093 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1900 2094
1901 DEBUG(printk("scsi(%ld): Port login retry: " 2095 DEBUG(printk("scsi(%ld): Port login retry: "
1902 "%02x%02x%02x%02x%02x%02x%02x%02x, " 2096 "%02x%02x%02x%02x%02x%02x%02x%02x, "
1903 "id = 0x%04x retry cnt=%d\n", 2097 "id = 0x%04x retry cnt=%d\n",
1904 ha->host_no, 2098 vha->host_no,
1905 fcport->port_name[0], 2099 fcport->port_name[0],
1906 fcport->port_name[1], 2100 fcport->port_name[1],
1907 fcport->port_name[2], 2101 fcport->port_name[2],
@@ -1929,13 +2123,12 @@ void qla2x00_mark_device_lost(scsi_qla_host_t *ha, fc_port_t *fcport,
1929 * Context: 2123 * Context:
1930 */ 2124 */
1931void 2125void
1932qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer) 2126qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
1933{ 2127{
1934 fc_port_t *fcport; 2128 fc_port_t *fcport;
1935 scsi_qla_host_t *pha = to_qla_parent(ha);
1936 2129
1937 list_for_each_entry(fcport, &pha->fcports, list) { 2130 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1938 if (ha->vp_idx != fcport->vp_idx) 2131 if (vha->vp_idx != fcport->vp_idx)
1939 continue; 2132 continue;
1940 /* 2133 /*
1941 * No point in marking the device as lost, if the device is 2134 * No point in marking the device as lost, if the device is
@@ -1943,9 +2136,11 @@ qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
1943 */ 2136 */
1944 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD) 2137 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
1945 continue; 2138 continue;
1946 if (atomic_read(&fcport->state) == FCS_ONLINE) 2139 if (atomic_read(&fcport->state) == FCS_ONLINE) {
1947 qla2x00_schedule_rport_del(ha, fcport, defer); 2140 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1948 atomic_set(&fcport->state, FCS_DEVICE_LOST); 2141 qla2x00_schedule_rport_del(vha, fcport, defer);
2142 } else
2143 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1949 } 2144 }
1950} 2145}
1951 2146
@@ -1958,105 +2153,153 @@ qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
1958* !0 = failure. 2153* !0 = failure.
1959*/ 2154*/
1960static int 2155static int
1961qla2x00_mem_alloc(scsi_qla_host_t *ha) 2156qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2157 struct req_que **req, struct rsp_que **rsp)
1962{ 2158{
1963 char name[16]; 2159 char name[16];
1964 2160
1965 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev, 2161 ha->init_cb_size = sizeof(init_cb_t);
1966 (ha->request_q_length + 1) * sizeof(request_t), &ha->request_dma, 2162 if (IS_QLA2XXX_MIDTYPE(ha))
1967 GFP_KERNEL); 2163 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
1968 if (!ha->request_ring)
1969 goto fail;
1970
1971 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
1972 (ha->response_q_length + 1) * sizeof(response_t),
1973 &ha->response_dma, GFP_KERNEL);
1974 if (!ha->response_ring)
1975 goto fail_free_request_ring;
1976
1977 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1978 &ha->gid_list_dma, GFP_KERNEL);
1979 if (!ha->gid_list)
1980 goto fail_free_response_ring;
1981 2164
1982 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size, 2165 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
1983 &ha->init_cb_dma, GFP_KERNEL); 2166 &ha->init_cb_dma, GFP_KERNEL);
1984 if (!ha->init_cb) 2167 if (!ha->init_cb)
1985 goto fail_free_gid_list; 2168 goto fail;
1986 2169
1987 snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME, 2170 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
1988 ha->host_no); 2171 &ha->gid_list_dma, GFP_KERNEL);
1989 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev, 2172 if (!ha->gid_list)
1990 DMA_POOL_SIZE, 8, 0);
1991 if (!ha->s_dma_pool)
1992 goto fail_free_init_cb; 2173 goto fail_free_init_cb;
1993 2174
1994 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); 2175 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
1995 if (!ha->srb_mempool) 2176 if (!ha->srb_mempool)
1996 goto fail_free_s_dma_pool; 2177 goto fail_free_gid_list;
1997 2178
1998 /* Get memory for cached NVRAM */ 2179 /* Get memory for cached NVRAM */
1999 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL); 2180 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2000 if (!ha->nvram) 2181 if (!ha->nvram)
2001 goto fail_free_srb_mempool; 2182 goto fail_free_srb_mempool;
2002 2183
2184 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2185 ha->pdev->device);
2186 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2187 DMA_POOL_SIZE, 8, 0);
2188 if (!ha->s_dma_pool)
2189 goto fail_free_nvram;
2190
2003 /* Allocate memory for SNS commands */ 2191 /* Allocate memory for SNS commands */
2004 if (IS_QLA2100(ha) || IS_QLA2200(ha)) { 2192 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2005 /* Get consistent memory allocated for SNS commands */ 2193 /* Get consistent memory allocated for SNS commands */
2006 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev, 2194 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
2007 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL); 2195 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
2008 if (!ha->sns_cmd) 2196 if (!ha->sns_cmd)
2009 goto fail_free_nvram; 2197 goto fail_dma_pool;
2010 } else { 2198 } else {
2011 /* Get consistent memory allocated for MS IOCB */ 2199 /* Get consistent memory allocated for MS IOCB */
2012 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, 2200 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2013 &ha->ms_iocb_dma); 2201 &ha->ms_iocb_dma);
2014 if (!ha->ms_iocb) 2202 if (!ha->ms_iocb)
2015 goto fail_free_nvram; 2203 goto fail_dma_pool;
2016 2204 /* Get consistent memory allocated for CT SNS commands */
2017 /* Get consistent memory allocated for CT SNS commands */
2018 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev, 2205 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
2019 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL); 2206 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
2020 if (!ha->ct_sns) 2207 if (!ha->ct_sns)
2021 goto fail_free_ms_iocb; 2208 goto fail_free_ms_iocb;
2022 } 2209 }
2023 2210
2024 return 0; 2211 /* Allocate memory for request ring */
2212 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2213 if (!*req) {
2214 DEBUG(printk("Unable to allocate memory for req\n"));
2215 goto fail_req;
2216 }
2217 (*req)->length = req_len;
2218 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2219 ((*req)->length + 1) * sizeof(request_t),
2220 &(*req)->dma, GFP_KERNEL);
2221 if (!(*req)->ring) {
2222 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2223 goto fail_req_ring;
2224 }
2225 /* Allocate memory for response ring */
2226 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2227 if (!*rsp) {
2228 qla_printk(KERN_WARNING, ha,
2229 "Unable to allocate memory for rsp\n");
2230 goto fail_rsp;
2231 }
2232 (*rsp)->hw = ha;
2233 (*rsp)->length = rsp_len;
2234 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2235 ((*rsp)->length + 1) * sizeof(response_t),
2236 &(*rsp)->dma, GFP_KERNEL);
2237 if (!(*rsp)->ring) {
2238 qla_printk(KERN_WARNING, ha,
2239 "Unable to allocate memory for rsp_ring\n");
2240 goto fail_rsp_ring;
2241 }
2242 (*req)->rsp = *rsp;
2243 (*rsp)->req = *req;
2244 /* Allocate memory for NVRAM data for vports */
2245 if (ha->nvram_npiv_size) {
2246 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2247 ha->nvram_npiv_size, GFP_KERNEL);
2248 if (!ha->npiv_info) {
2249 qla_printk(KERN_WARNING, ha,
2250 "Unable to allocate memory for npiv info\n");
2251 goto fail_npiv_info;
2252 }
2253 } else
2254 ha->npiv_info = NULL;
2025 2255
2256 INIT_LIST_HEAD(&ha->vp_list);
2257 return 1;
2258
2259fail_npiv_info:
2260 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2261 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2262 (*rsp)->ring = NULL;
2263 (*rsp)->dma = 0;
2264fail_rsp_ring:
2265 kfree(*rsp);
2266fail_rsp:
2267 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2268 sizeof(request_t), (*req)->ring, (*req)->dma);
2269 (*req)->ring = NULL;
2270 (*req)->dma = 0;
2271fail_req_ring:
2272 kfree(*req);
2273fail_req:
2274 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2275 ha->ct_sns, ha->ct_sns_dma);
2276 ha->ct_sns = NULL;
2277 ha->ct_sns_dma = 0;
2026fail_free_ms_iocb: 2278fail_free_ms_iocb:
2027 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma); 2279 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2028 ha->ms_iocb = NULL; 2280 ha->ms_iocb = NULL;
2029 ha->ms_iocb_dma = 0; 2281 ha->ms_iocb_dma = 0;
2282fail_dma_pool:
2283 dma_pool_destroy(ha->s_dma_pool);
2284 ha->s_dma_pool = NULL;
2030fail_free_nvram: 2285fail_free_nvram:
2031 kfree(ha->nvram); 2286 kfree(ha->nvram);
2032 ha->nvram = NULL; 2287 ha->nvram = NULL;
2033fail_free_srb_mempool: 2288fail_free_srb_mempool:
2034 mempool_destroy(ha->srb_mempool); 2289 mempool_destroy(ha->srb_mempool);
2035 ha->srb_mempool = NULL; 2290 ha->srb_mempool = NULL;
2036fail_free_s_dma_pool:
2037 dma_pool_destroy(ha->s_dma_pool);
2038 ha->s_dma_pool = NULL;
2039fail_free_init_cb:
2040 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2041 ha->init_cb_dma);
2042 ha->init_cb = NULL;
2043 ha->init_cb_dma = 0;
2044fail_free_gid_list: 2291fail_free_gid_list:
2045 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, 2292 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2046 ha->gid_list_dma); 2293 ha->gid_list_dma);
2047 ha->gid_list = NULL; 2294 ha->gid_list = NULL;
2048 ha->gid_list_dma = 0; 2295 ha->gid_list_dma = 0;
2049fail_free_response_ring: 2296fail_free_init_cb:
2050 dma_free_coherent(&ha->pdev->dev, (ha->response_q_length + 1) * 2297 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2051 sizeof(response_t), ha->response_ring, ha->response_dma); 2298 ha->init_cb_dma);
2052 ha->response_ring = NULL; 2299 ha->init_cb = NULL;
2053 ha->response_dma = 0; 2300 ha->init_cb_dma = 0;
2054fail_free_request_ring:
2055 dma_free_coherent(&ha->pdev->dev, (ha->request_q_length + 1) *
2056 sizeof(request_t), ha->request_ring, ha->request_dma);
2057 ha->request_ring = NULL;
2058 ha->request_dma = 0;
2059fail: 2301fail:
2302 DEBUG(printk("%s: Memory allocation failure\n", __func__));
2060 return -ENOMEM; 2303 return -ENOMEM;
2061} 2304}
2062 2305
@@ -2068,32 +2311,29 @@ fail:
2068* ha = adapter block pointer. 2311* ha = adapter block pointer.
2069*/ 2312*/
2070static void 2313static void
2071qla2x00_mem_free(scsi_qla_host_t *ha) 2314qla2x00_mem_free(struct qla_hw_data *ha)
2072{ 2315{
2073 struct list_head *fcpl, *fcptemp;
2074 fc_port_t *fcport;
2075
2076 if (ha->srb_mempool) 2316 if (ha->srb_mempool)
2077 mempool_destroy(ha->srb_mempool); 2317 mempool_destroy(ha->srb_mempool);
2078 2318
2079 if (ha->fce) 2319 if (ha->fce)
2080 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, 2320 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2081 ha->fce_dma); 2321 ha->fce_dma);
2082 2322
2083 if (ha->fw_dump) { 2323 if (ha->fw_dump) {
2084 if (ha->eft) 2324 if (ha->eft)
2085 dma_free_coherent(&ha->pdev->dev, 2325 dma_free_coherent(&ha->pdev->dev,
2086 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma); 2326 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
2087 vfree(ha->fw_dump); 2327 vfree(ha->fw_dump);
2088 } 2328 }
2089 2329
2090 if (ha->sns_cmd) 2330 if (ha->sns_cmd)
2091 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt), 2331 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
2092 ha->sns_cmd, ha->sns_cmd_dma); 2332 ha->sns_cmd, ha->sns_cmd_dma);
2093 2333
2094 if (ha->ct_sns) 2334 if (ha->ct_sns)
2095 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt), 2335 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2096 ha->ct_sns, ha->ct_sns_dma); 2336 ha->ct_sns, ha->ct_sns_dma);
2097 2337
2098 if (ha->sfp_data) 2338 if (ha->sfp_data)
2099 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma); 2339 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
@@ -2104,23 +2344,18 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
2104 if (ha->s_dma_pool) 2344 if (ha->s_dma_pool)
2105 dma_pool_destroy(ha->s_dma_pool); 2345 dma_pool_destroy(ha->s_dma_pool);
2106 2346
2107 if (ha->init_cb)
2108 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2109 ha->init_cb, ha->init_cb_dma);
2110 2347
2111 if (ha->gid_list) 2348 if (ha->gid_list)
2112 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list, 2349 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
2113 ha->gid_list_dma); 2350 ha->gid_list_dma);
2114 2351
2115 if (ha->response_ring)
2116 dma_free_coherent(&ha->pdev->dev,
2117 (ha->response_q_length + 1) * sizeof(response_t),
2118 ha->response_ring, ha->response_dma);
2119 2352
2120 if (ha->request_ring) 2353 if (ha->init_cb)
2121 dma_free_coherent(&ha->pdev->dev, 2354 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2122 (ha->request_q_length + 1) * sizeof(request_t), 2355 ha->init_cb, ha->init_cb_dma);
2123 ha->request_ring, ha->request_dma); 2356 vfree(ha->optrom_buffer);
2357 kfree(ha->nvram);
2358 kfree(ha->npiv_info);
2124 2359
2125 ha->srb_mempool = NULL; 2360 ha->srb_mempool = NULL;
2126 ha->eft = NULL; 2361 ha->eft = NULL;
@@ -2139,30 +2374,45 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
2139 ha->gid_list = NULL; 2374 ha->gid_list = NULL;
2140 ha->gid_list_dma = 0; 2375 ha->gid_list_dma = 0;
2141 2376
2142 ha->response_ring = NULL; 2377 ha->fw_dump = NULL;
2143 ha->response_dma = 0; 2378 ha->fw_dumped = 0;
2144 ha->request_ring = NULL; 2379 ha->fw_dump_reading = 0;
2145 ha->request_dma = 0; 2380}
2146 2381
2147 list_for_each_safe(fcpl, fcptemp, &ha->fcports) { 2382struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2148 fcport = list_entry(fcpl, fc_port_t, list); 2383 struct qla_hw_data *ha)
2384{
2385 struct Scsi_Host *host;
2386 struct scsi_qla_host *vha = NULL;
2149 2387
2150 /* fc ports */ 2388 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2151 list_del_init(&fcport->list); 2389 if (host == NULL) {
2152 kfree(fcport); 2390 printk(KERN_WARNING
2391 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2392 goto fail;
2153 } 2393 }
2154 INIT_LIST_HEAD(&ha->fcports);
2155 2394
2156 ha->fw_dump = NULL; 2395 /* Clear our data area */
2157 ha->fw_dumped = 0; 2396 vha = shost_priv(host);
2158 ha->fw_dump_reading = 0; 2397 memset(vha, 0, sizeof(scsi_qla_host_t));
2159 2398
2160 vfree(ha->optrom_buffer); 2399 vha->host = host;
2161 kfree(ha->nvram); 2400 vha->host_no = host->host_no;
2401 vha->hw = ha;
2402
2403 INIT_LIST_HEAD(&vha->vp_fcports);
2404 INIT_LIST_HEAD(&vha->work_list);
2405 INIT_LIST_HEAD(&vha->list);
2406
2407 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2408 return vha;
2409
2410fail:
2411 return vha;
2162} 2412}
2163 2413
2164static struct qla_work_evt * 2414static struct qla_work_evt *
2165qla2x00_alloc_work(struct scsi_qla_host *ha, enum qla_work_type type, 2415qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
2166 int locked) 2416 int locked)
2167{ 2417{
2168 struct qla_work_evt *e; 2418 struct qla_work_evt *e;
@@ -2179,42 +2429,42 @@ qla2x00_alloc_work(struct scsi_qla_host *ha, enum qla_work_type type,
2179} 2429}
2180 2430
2181static int 2431static int
2182qla2x00_post_work(struct scsi_qla_host *ha, struct qla_work_evt *e, int locked) 2432qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
2183{ 2433{
2184 unsigned long uninitialized_var(flags); 2434 unsigned long uninitialized_var(flags);
2185 scsi_qla_host_t *pha = to_qla_parent(ha); 2435 struct qla_hw_data *ha = vha->hw;
2186 2436
2187 if (!locked) 2437 if (!locked)
2188 spin_lock_irqsave(&pha->hardware_lock, flags); 2438 spin_lock_irqsave(&ha->hardware_lock, flags);
2189 list_add_tail(&e->list, &ha->work_list); 2439 list_add_tail(&e->list, &vha->work_list);
2190 qla2xxx_wake_dpc(ha); 2440 qla2xxx_wake_dpc(vha);
2191 if (!locked) 2441 if (!locked)
2192 spin_unlock_irqrestore(&pha->hardware_lock, flags); 2442 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2193 return QLA_SUCCESS; 2443 return QLA_SUCCESS;
2194} 2444}
2195 2445
2196int 2446int
2197qla2x00_post_aen_work(struct scsi_qla_host *ha, enum fc_host_event_code code, 2447qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
2198 u32 data) 2448 u32 data)
2199{ 2449{
2200 struct qla_work_evt *e; 2450 struct qla_work_evt *e;
2201 2451
2202 e = qla2x00_alloc_work(ha, QLA_EVT_AEN, 1); 2452 e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
2203 if (!e) 2453 if (!e)
2204 return QLA_FUNCTION_FAILED; 2454 return QLA_FUNCTION_FAILED;
2205 2455
2206 e->u.aen.code = code; 2456 e->u.aen.code = code;
2207 e->u.aen.data = data; 2457 e->u.aen.data = data;
2208 return qla2x00_post_work(ha, e, 1); 2458 return qla2x00_post_work(vha, e, 1);
2209} 2459}
2210 2460
2211int 2461int
2212qla2x00_post_hwe_work(struct scsi_qla_host *ha, uint16_t code, uint16_t d1, 2462qla2x00_post_hwe_work(struct scsi_qla_host *vha, uint16_t code, uint16_t d1,
2213 uint16_t d2, uint16_t d3) 2463 uint16_t d2, uint16_t d3)
2214{ 2464{
2215 struct qla_work_evt *e; 2465 struct qla_work_evt *e;
2216 2466
2217 e = qla2x00_alloc_work(ha, QLA_EVT_HWE_LOG, 1); 2467 e = qla2x00_alloc_work(vha, QLA_EVT_HWE_LOG, 1);
2218 if (!e) 2468 if (!e)
2219 return QLA_FUNCTION_FAILED; 2469 return QLA_FUNCTION_FAILED;
2220 2470
@@ -2222,36 +2472,95 @@ qla2x00_post_hwe_work(struct scsi_qla_host *ha, uint16_t code, uint16_t d1,
2222 e->u.hwe.d1 = d1; 2472 e->u.hwe.d1 = d1;
2223 e->u.hwe.d2 = d2; 2473 e->u.hwe.d2 = d2;
2224 e->u.hwe.d3 = d3; 2474 e->u.hwe.d3 = d3;
2225 return qla2x00_post_work(ha, e, 1); 2475 return qla2x00_post_work(vha, e, 1);
2226} 2476}
2227 2477
2228static void 2478static void
2229qla2x00_do_work(struct scsi_qla_host *ha) 2479qla2x00_do_work(struct scsi_qla_host *vha)
2230{ 2480{
2231 struct qla_work_evt *e; 2481 struct qla_work_evt *e;
2232 scsi_qla_host_t *pha = to_qla_parent(ha); 2482 struct qla_hw_data *ha = vha->hw;
2233 2483
2234 spin_lock_irq(&pha->hardware_lock); 2484 spin_lock_irq(&ha->hardware_lock);
2235 while (!list_empty(&ha->work_list)) { 2485 while (!list_empty(&vha->work_list)) {
2236 e = list_entry(ha->work_list.next, struct qla_work_evt, list); 2486 e = list_entry(vha->work_list.next, struct qla_work_evt, list);
2237 list_del_init(&e->list); 2487 list_del_init(&e->list);
2238 spin_unlock_irq(&pha->hardware_lock); 2488 spin_unlock_irq(&ha->hardware_lock);
2239 2489
2240 switch (e->type) { 2490 switch (e->type) {
2241 case QLA_EVT_AEN: 2491 case QLA_EVT_AEN:
2242 fc_host_post_event(ha->host, fc_get_event_number(), 2492 fc_host_post_event(vha->host, fc_get_event_number(),
2243 e->u.aen.code, e->u.aen.data); 2493 e->u.aen.code, e->u.aen.data);
2244 break; 2494 break;
2245 case QLA_EVT_HWE_LOG: 2495 case QLA_EVT_HWE_LOG:
2246 qla2xxx_hw_event_log(ha, e->u.hwe.code, e->u.hwe.d1, 2496 qla2xxx_hw_event_log(vha, e->u.hwe.code, e->u.hwe.d1,
2247 e->u.hwe.d2, e->u.hwe.d3); 2497 e->u.hwe.d2, e->u.hwe.d3);
2248 break; 2498 break;
2249 } 2499 }
2250 if (e->flags & QLA_EVT_FLAG_FREE) 2500 if (e->flags & QLA_EVT_FLAG_FREE)
2251 kfree(e); 2501 kfree(e);
2252 spin_lock_irq(&pha->hardware_lock); 2502 spin_lock_irq(&ha->hardware_lock);
2503 }
2504 spin_unlock_irq(&ha->hardware_lock);
2505}
2506/* Relogins all the fcports of a vport
2507 * Context: dpc thread
2508 */
2509void qla2x00_relogin(struct scsi_qla_host *vha)
2510{
2511 fc_port_t *fcport;
2512 uint8_t status;
2513 uint16_t next_loopid = 0;
2514 struct qla_hw_data *ha = vha->hw;
2515
2516 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2517 /*
2518 * If the port is not ONLINE then try to login
2519 * to it if we haven't run out of retries.
2520 */
2521 if (atomic_read(&fcport->state) !=
2522 FCS_ONLINE && fcport->login_retry) {
2523
2524 if (fcport->flags & FCF_FABRIC_DEVICE) {
2525 if (fcport->flags & FCF_TAPE_PRESENT)
2526 ha->isp_ops->fabric_logout(vha,
2527 fcport->loop_id,
2528 fcport->d_id.b.domain,
2529 fcport->d_id.b.area,
2530 fcport->d_id.b.al_pa);
2531
2532 status = qla2x00_fabric_login(vha, fcport,
2533 &next_loopid);
2534 } else
2535 status = qla2x00_local_device_login(vha,
2536 fcport);
2537
2538 fcport->login_retry--;
2539 if (status == QLA_SUCCESS) {
2540 fcport->old_loop_id = fcport->loop_id;
2541
2542 DEBUG(printk("scsi(%ld): port login OK: logged "
2543 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2544
2545 qla2x00_update_fcport(vha, fcport);
2546
2547 } else if (status == 1) {
2548 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2549 /* retry the login again */
2550 DEBUG(printk("scsi(%ld): Retrying"
2551 " %d login again loop_id 0x%x\n",
2552 vha->host_no, fcport->login_retry,
2553 fcport->loop_id));
2554 } else {
2555 fcport->login_retry = 0;
2556 }
2557
2558 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2559 fcport->loop_id = FC_NO_LOOP_ID;
2560 }
2561 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2562 break;
2253 } 2563 }
2254 spin_unlock_irq(&pha->hardware_lock);
2255} 2564}
2256 2565
2257/************************************************************************** 2566/**************************************************************************
@@ -2271,15 +2580,11 @@ static int
2271qla2x00_do_dpc(void *data) 2580qla2x00_do_dpc(void *data)
2272{ 2581{
2273 int rval; 2582 int rval;
2274 scsi_qla_host_t *ha; 2583 scsi_qla_host_t *base_vha;
2275 fc_port_t *fcport; 2584 struct qla_hw_data *ha;
2276 uint8_t status;
2277 uint16_t next_loopid;
2278 struct scsi_qla_host *vha;
2279 int i;
2280 2585
2281 2586 ha = (struct qla_hw_data *)data;
2282 ha = (scsi_qla_host_t *)data; 2587 base_vha = pci_get_drvdata(ha->pdev);
2283 2588
2284 set_user_nice(current, -20); 2589 set_user_nice(current, -20);
2285 2590
@@ -2293,10 +2598,10 @@ qla2x00_do_dpc(void *data)
2293 DEBUG3(printk("qla2x00: DPC handler waking up\n")); 2598 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2294 2599
2295 /* Initialization not yet finished. Don't do anything yet. */ 2600 /* Initialization not yet finished. Don't do anything yet. */
2296 if (!ha->flags.init_done) 2601 if (!base_vha->flags.init_done)
2297 continue; 2602 continue;
2298 2603
2299 DEBUG3(printk("scsi(%ld): DPC handler\n", ha->host_no)); 2604 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
2300 2605
2301 ha->dpc_active = 1; 2606 ha->dpc_active = 1;
2302 2607
@@ -2305,149 +2610,98 @@ qla2x00_do_dpc(void *data)
2305 continue; 2610 continue;
2306 } 2611 }
2307 2612
2308 qla2x00_do_work(ha); 2613 qla2x00_do_work(base_vha);
2309 2614
2310 if (test_and_clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) { 2615 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2616 &base_vha->dpc_flags)) {
2311 2617
2312 DEBUG(printk("scsi(%ld): dpc: sched " 2618 DEBUG(printk("scsi(%ld): dpc: sched "
2313 "qla2x00_abort_isp ha = %p\n", 2619 "qla2x00_abort_isp ha = %p\n",
2314 ha->host_no, ha)); 2620 base_vha->host_no, ha));
2315 if (!(test_and_set_bit(ABORT_ISP_ACTIVE, 2621 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
2316 &ha->dpc_flags))) { 2622 &base_vha->dpc_flags))) {
2317 2623
2318 if (qla2x00_abort_isp(ha)) { 2624 if (qla2x00_abort_isp(base_vha)) {
2319 /* failed. retry later */ 2625 /* failed. retry later */
2320 set_bit(ISP_ABORT_NEEDED, 2626 set_bit(ISP_ABORT_NEEDED,
2321 &ha->dpc_flags); 2627 &base_vha->dpc_flags);
2322 }
2323 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
2324 }
2325
2326 for_each_mapped_vp_idx(ha, i) {
2327 list_for_each_entry(vha, &ha->vp_list,
2328 vp_list) {
2329 if (i == vha->vp_idx) {
2330 set_bit(ISP_ABORT_NEEDED,
2331 &vha->dpc_flags);
2332 break;
2333 }
2334 } 2628 }
2629 clear_bit(ABORT_ISP_ACTIVE,
2630 &base_vha->dpc_flags);
2335 } 2631 }
2336 2632
2337 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n", 2633 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
2338 ha->host_no)); 2634 base_vha->host_no));
2339 } 2635 }
2340 2636
2341 if (test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags)) { 2637 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2342 qla2x00_update_fcports(ha); 2638 qla2x00_update_fcports(base_vha);
2343 clear_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags); 2639 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2344 } 2640 }
2345 2641
2346 if (test_and_clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) && 2642 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2347 (!(test_and_set_bit(RESET_ACTIVE, &ha->dpc_flags)))) { 2643 &base_vha->dpc_flags) &&
2644 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
2348 2645
2349 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n", 2646 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
2350 ha->host_no)); 2647 base_vha->host_no));
2351 2648
2352 qla2x00_rst_aen(ha); 2649 qla2x00_rst_aen(base_vha);
2353 clear_bit(RESET_ACTIVE, &ha->dpc_flags); 2650 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
2354 } 2651 }
2355 2652
2356 /* Retry each device up to login retry count */ 2653 /* Retry each device up to login retry count */
2357 if ((test_and_clear_bit(RELOGIN_NEEDED, &ha->dpc_flags)) && 2654 if ((test_and_clear_bit(RELOGIN_NEEDED,
2358 !test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) && 2655 &base_vha->dpc_flags)) &&
2359 atomic_read(&ha->loop_state) != LOOP_DOWN) { 2656 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2657 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
2360 2658
2361 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n", 2659 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
2362 ha->host_no)); 2660 base_vha->host_no));
2363 2661 qla2x00_relogin(base_vha);
2364 next_loopid = 0; 2662
2365 list_for_each_entry(fcport, &ha->fcports, list) {
2366 /*
2367 * If the port is not ONLINE then try to login
2368 * to it if we haven't run out of retries.
2369 */
2370 if (atomic_read(&fcport->state) != FCS_ONLINE &&
2371 fcport->login_retry) {
2372
2373 if (fcport->flags & FCF_FABRIC_DEVICE) {
2374 if (fcport->flags &
2375 FCF_TAPE_PRESENT)
2376 ha->isp_ops->fabric_logout(
2377 ha, fcport->loop_id,
2378 fcport->d_id.b.domain,
2379 fcport->d_id.b.area,
2380 fcport->d_id.b.al_pa);
2381 status = qla2x00_fabric_login(
2382 ha, fcport, &next_loopid);
2383 } else
2384 status =
2385 qla2x00_local_device_login(
2386 ha, fcport);
2387
2388 fcport->login_retry--;
2389 if (status == QLA_SUCCESS) {
2390 fcport->old_loop_id = fcport->loop_id;
2391
2392 DEBUG(printk("scsi(%ld): port login OK: logged in ID 0x%x\n",
2393 ha->host_no, fcport->loop_id));
2394
2395 qla2x00_update_fcport(ha,
2396 fcport);
2397 } else if (status == 1) {
2398 set_bit(RELOGIN_NEEDED, &ha->dpc_flags);
2399 /* retry the login again */
2400 DEBUG(printk("scsi(%ld): Retrying %d login again loop_id 0x%x\n",
2401 ha->host_no,
2402 fcport->login_retry, fcport->loop_id));
2403 } else {
2404 fcport->login_retry = 0;
2405 }
2406 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2407 fcport->loop_id = FC_NO_LOOP_ID;
2408 }
2409 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2410 break;
2411 }
2412 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n", 2663 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
2413 ha->host_no)); 2664 base_vha->host_no));
2414 } 2665 }
2415 2666
2416 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) { 2667 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2668 &base_vha->dpc_flags)) {
2417 2669
2418 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n", 2670 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
2419 ha->host_no)); 2671 base_vha->host_no));
2420 2672
2421 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, 2673 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
2422 &ha->dpc_flags))) { 2674 &base_vha->dpc_flags))) {
2423 2675
2424 rval = qla2x00_loop_resync(ha); 2676 rval = qla2x00_loop_resync(base_vha);
2425 2677
2426 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); 2678 clear_bit(LOOP_RESYNC_ACTIVE,
2679 &base_vha->dpc_flags);
2427 } 2680 }
2428 2681
2429 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n", 2682 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
2430 ha->host_no)); 2683 base_vha->host_no));
2431 } 2684 }
2432 2685
2433 if (test_bit(NPIV_CONFIG_NEEDED, &ha->dpc_flags) && 2686 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2434 atomic_read(&ha->loop_state) == LOOP_READY) { 2687 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2435 clear_bit(NPIV_CONFIG_NEEDED, &ha->dpc_flags); 2688 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2436 qla2xxx_flash_npiv_conf(ha); 2689 qla2xxx_flash_npiv_conf(base_vha);
2437 } 2690 }
2438 2691
2439 if (!ha->interrupts_on) 2692 if (!ha->interrupts_on)
2440 ha->isp_ops->enable_intrs(ha); 2693 ha->isp_ops->enable_intrs(ha);
2441 2694
2442 if (test_and_clear_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags)) 2695 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2443 ha->isp_ops->beacon_blink(ha); 2696 &base_vha->dpc_flags))
2697 ha->isp_ops->beacon_blink(base_vha);
2444 2698
2445 qla2x00_do_dpc_all_vps(ha); 2699 qla2x00_do_dpc_all_vps(base_vha);
2446 2700
2447 ha->dpc_active = 0; 2701 ha->dpc_active = 0;
2448 } /* End of while(1) */ 2702 } /* End of while(1) */
2449 2703
2450 DEBUG(printk("scsi(%ld): DPC handler exiting\n", ha->host_no)); 2704 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
2451 2705
2452 /* 2706 /*
2453 * Make sure that nobody tries to wake us up again. 2707 * Make sure that nobody tries to wake us up again.
@@ -2458,11 +2712,12 @@ qla2x00_do_dpc(void *data)
2458} 2712}
2459 2713
2460void 2714void
2461qla2xxx_wake_dpc(scsi_qla_host_t *ha) 2715qla2xxx_wake_dpc(struct scsi_qla_host *vha)
2462{ 2716{
2717 struct qla_hw_data *ha = vha->hw;
2463 struct task_struct *t = ha->dpc_thread; 2718 struct task_struct *t = ha->dpc_thread;
2464 2719
2465 if (!test_bit(UNLOADING, &ha->dpc_flags) && t) 2720 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
2466 wake_up_process(t); 2721 wake_up_process(t);
2467} 2722}
2468 2723
@@ -2474,26 +2729,26 @@ qla2xxx_wake_dpc(scsi_qla_host_t *ha)
2474* ha = adapter block pointer. 2729* ha = adapter block pointer.
2475*/ 2730*/
2476static void 2731static void
2477qla2x00_rst_aen(scsi_qla_host_t *ha) 2732qla2x00_rst_aen(scsi_qla_host_t *vha)
2478{ 2733{
2479 if (ha->flags.online && !ha->flags.reset_active && 2734 if (vha->flags.online && !vha->flags.reset_active &&
2480 !atomic_read(&ha->loop_down_timer) && 2735 !atomic_read(&vha->loop_down_timer) &&
2481 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags))) { 2736 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
2482 do { 2737 do {
2483 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); 2738 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
2484 2739
2485 /* 2740 /*
2486 * Issue marker command only when we are going to start 2741 * Issue marker command only when we are going to start
2487 * the I/O. 2742 * the I/O.
2488 */ 2743 */
2489 ha->marker_needed = 1; 2744 vha->marker_needed = 1;
2490 } while (!atomic_read(&ha->loop_down_timer) && 2745 } while (!atomic_read(&vha->loop_down_timer) &&
2491 (test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags))); 2746 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
2492 } 2747 }
2493} 2748}
2494 2749
2495static void 2750static void
2496qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp) 2751qla2x00_sp_free_dma(srb_t *sp)
2497{ 2752{
2498 struct scsi_cmnd *cmd = sp->cmd; 2753 struct scsi_cmnd *cmd = sp->cmd;
2499 2754
@@ -2505,11 +2760,11 @@ qla2x00_sp_free_dma(scsi_qla_host_t *ha, srb_t *sp)
2505} 2760}
2506 2761
2507void 2762void
2508qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp) 2763qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
2509{ 2764{
2510 struct scsi_cmnd *cmd = sp->cmd; 2765 struct scsi_cmnd *cmd = sp->cmd;
2511 2766
2512 qla2x00_sp_free_dma(ha, sp); 2767 qla2x00_sp_free_dma(sp);
2513 2768
2514 mempool_free(sp, ha->srb_mempool); 2769 mempool_free(sp, ha->srb_mempool);
2515 2770
@@ -2525,7 +2780,7 @@ qla2x00_sp_compl(scsi_qla_host_t *ha, srb_t *sp)
2525* Context: Interrupt 2780* Context: Interrupt
2526***************************************************************************/ 2781***************************************************************************/
2527void 2782void
2528qla2x00_timer(scsi_qla_host_t *ha) 2783qla2x00_timer(scsi_qla_host_t *vha)
2529{ 2784{
2530 unsigned long cpu_flags = 0; 2785 unsigned long cpu_flags = 0;
2531 fc_port_t *fcport; 2786 fc_port_t *fcport;
@@ -2533,8 +2788,8 @@ qla2x00_timer(scsi_qla_host_t *ha)
2533 int index; 2788 int index;
2534 srb_t *sp; 2789 srb_t *sp;
2535 int t; 2790 int t;
2536 scsi_qla_host_t *pha = to_qla_parent(ha); 2791 struct qla_hw_data *ha = vha->hw;
2537 2792 struct req_que *req;
2538 /* 2793 /*
2539 * Ports - Port down timer. 2794 * Ports - Port down timer.
2540 * 2795 *
@@ -2543,7 +2798,7 @@ qla2x00_timer(scsi_qla_host_t *ha)
2543 * the port it marked DEAD. 2798 * the port it marked DEAD.
2544 */ 2799 */
2545 t = 0; 2800 t = 0;
2546 list_for_each_entry(fcport, &ha->fcports, list) { 2801 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2547 if (fcport->port_type != FCT_TARGET) 2802 if (fcport->port_type != FCT_TARGET)
2548 continue; 2803 continue;
2549 2804
@@ -2557,7 +2812,7 @@ qla2x00_timer(scsi_qla_host_t *ha)
2557 2812
2558 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: " 2813 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
2559 "%d remaining\n", 2814 "%d remaining\n",
2560 ha->host_no, 2815 vha->host_no,
2561 t, atomic_read(&fcport->port_down_timer))); 2816 t, atomic_read(&fcport->port_down_timer)));
2562 } 2817 }
2563 t++; 2818 t++;
@@ -2565,30 +2820,32 @@ qla2x00_timer(scsi_qla_host_t *ha)
2565 2820
2566 2821
2567 /* Loop down handler. */ 2822 /* Loop down handler. */
2568 if (atomic_read(&ha->loop_down_timer) > 0 && 2823 if (atomic_read(&vha->loop_down_timer) > 0 &&
2569 !(test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) && ha->flags.online) { 2824 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
2825 && vha->flags.online) {
2570 2826
2571 if (atomic_read(&ha->loop_down_timer) == 2827 if (atomic_read(&vha->loop_down_timer) ==
2572 ha->loop_down_abort_time) { 2828 vha->loop_down_abort_time) {
2573 2829
2574 DEBUG(printk("scsi(%ld): Loop Down - aborting the " 2830 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2575 "queues before time expire\n", 2831 "queues before time expire\n",
2576 ha->host_no)); 2832 vha->host_no));
2577 2833
2578 if (!IS_QLA2100(ha) && ha->link_down_timeout) 2834 if (!IS_QLA2100(ha) && vha->link_down_timeout)
2579 atomic_set(&ha->loop_state, LOOP_DEAD); 2835 atomic_set(&vha->loop_state, LOOP_DEAD);
2580 2836
2581 /* Schedule an ISP abort to return any tape commands. */ 2837 /* Schedule an ISP abort to return any tape commands. */
2582 /* NPIV - scan physical port only */ 2838 /* NPIV - scan physical port only */
2583 if (!ha->parent) { 2839 if (!vha->vp_idx) {
2584 spin_lock_irqsave(&ha->hardware_lock, 2840 spin_lock_irqsave(&ha->hardware_lock,
2585 cpu_flags); 2841 cpu_flags);
2842 req = ha->req_q_map[0];
2586 for (index = 1; 2843 for (index = 1;
2587 index < MAX_OUTSTANDING_COMMANDS; 2844 index < MAX_OUTSTANDING_COMMANDS;
2588 index++) { 2845 index++) {
2589 fc_port_t *sfcp; 2846 fc_port_t *sfcp;
2590 2847
2591 sp = ha->outstanding_cmds[index]; 2848 sp = req->outstanding_cmds[index];
2592 if (!sp) 2849 if (!sp)
2593 continue; 2850 continue;
2594 sfcp = sp->fcport; 2851 sfcp = sp->fcport;
@@ -2596,63 +2853,63 @@ qla2x00_timer(scsi_qla_host_t *ha)
2596 continue; 2853 continue;
2597 2854
2598 set_bit(ISP_ABORT_NEEDED, 2855 set_bit(ISP_ABORT_NEEDED,
2599 &ha->dpc_flags); 2856 &vha->dpc_flags);
2600 break; 2857 break;
2601 } 2858 }
2602 spin_unlock_irqrestore(&ha->hardware_lock, 2859 spin_unlock_irqrestore(&ha->hardware_lock,
2603 cpu_flags); 2860 cpu_flags);
2604 } 2861 }
2605 set_bit(ABORT_QUEUES_NEEDED, &ha->dpc_flags); 2862 set_bit(ABORT_QUEUES_NEEDED, &vha->dpc_flags);
2606 start_dpc++; 2863 start_dpc++;
2607 } 2864 }
2608 2865
2609 /* if the loop has been down for 4 minutes, reinit adapter */ 2866 /* if the loop has been down for 4 minutes, reinit adapter */
2610 if (atomic_dec_and_test(&ha->loop_down_timer) != 0) { 2867 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
2611 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - " 2868 DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
2612 "restarting queues.\n", 2869 "restarting queues.\n",
2613 ha->host_no)); 2870 vha->host_no));
2614 2871
2615 set_bit(RESTART_QUEUES_NEEDED, &ha->dpc_flags); 2872 set_bit(RESTART_QUEUES_NEEDED, &vha->dpc_flags);
2616 start_dpc++; 2873 start_dpc++;
2617 2874
2618 if (!(ha->device_flags & DFLG_NO_CABLE) && 2875 if (!(vha->device_flags & DFLG_NO_CABLE) &&
2619 !ha->parent) { 2876 !vha->vp_idx) {
2620 DEBUG(printk("scsi(%ld): Loop down - " 2877 DEBUG(printk("scsi(%ld): Loop down - "
2621 "aborting ISP.\n", 2878 "aborting ISP.\n",
2622 ha->host_no)); 2879 vha->host_no));
2623 qla_printk(KERN_WARNING, ha, 2880 qla_printk(KERN_WARNING, ha,
2624 "Loop down - aborting ISP.\n"); 2881 "Loop down - aborting ISP.\n");
2625 2882
2626 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); 2883 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2627 } 2884 }
2628 } 2885 }
2629 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n", 2886 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
2630 ha->host_no, 2887 vha->host_no,
2631 atomic_read(&ha->loop_down_timer))); 2888 atomic_read(&vha->loop_down_timer)));
2632 } 2889 }
2633 2890
2634 /* Check if beacon LED needs to be blinked */ 2891 /* Check if beacon LED needs to be blinked */
2635 if (ha->beacon_blink_led == 1) { 2892 if (ha->beacon_blink_led == 1) {
2636 set_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags); 2893 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
2637 start_dpc++; 2894 start_dpc++;
2638 } 2895 }
2639 2896
2640 /* Process any deferred work. */ 2897 /* Process any deferred work. */
2641 if (!list_empty(&ha->work_list)) 2898 if (!list_empty(&vha->work_list))
2642 start_dpc++; 2899 start_dpc++;
2643 2900
2644 /* Schedule the DPC routine if needed */ 2901 /* Schedule the DPC routine if needed */
2645 if ((test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) || 2902 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
2646 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags) || 2903 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
2647 test_bit(FCPORT_UPDATE_NEEDED, &ha->dpc_flags) || 2904 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
2648 start_dpc || 2905 start_dpc ||
2649 test_bit(RESET_MARKER_NEEDED, &ha->dpc_flags) || 2906 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
2650 test_bit(BEACON_BLINK_NEEDED, &ha->dpc_flags) || 2907 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
2651 test_bit(VP_DPC_NEEDED, &ha->dpc_flags) || 2908 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
2652 test_bit(RELOGIN_NEEDED, &ha->dpc_flags))) 2909 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
2653 qla2xxx_wake_dpc(pha); 2910 qla2xxx_wake_dpc(vha);
2654 2911
2655 qla2x00_restart_timer(ha, WATCH_INTERVAL); 2912 qla2x00_restart_timer(vha, WATCH_INTERVAL);
2656} 2913}
2657 2914
2658/* Firmware interface routines. */ 2915/* Firmware interface routines. */
@@ -2684,8 +2941,9 @@ static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
2684}; 2941};
2685 2942
2686struct fw_blob * 2943struct fw_blob *
2687qla2x00_request_firmware(scsi_qla_host_t *ha) 2944qla2x00_request_firmware(scsi_qla_host_t *vha)
2688{ 2945{
2946 struct qla_hw_data *ha = vha->hw;
2689 struct fw_blob *blob; 2947 struct fw_blob *blob;
2690 2948
2691 blob = NULL; 2949 blob = NULL;
@@ -2709,7 +2967,7 @@ qla2x00_request_firmware(scsi_qla_host_t *ha)
2709 2967
2710 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) { 2968 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2711 DEBUG2(printk("scsi(%ld): Failed to load firmware image " 2969 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
2712 "(%s).\n", ha->host_no, blob->name)); 2970 "(%s).\n", vha->host_no, blob->name));
2713 blob->fw = NULL; 2971 blob->fw = NULL;
2714 blob = NULL; 2972 blob = NULL;
2715 goto out; 2973 goto out;
@@ -2754,7 +3012,8 @@ qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2754 int risc_paused = 0; 3012 int risc_paused = 0;
2755 uint32_t stat; 3013 uint32_t stat;
2756 unsigned long flags; 3014 unsigned long flags;
2757 scsi_qla_host_t *ha = pci_get_drvdata(pdev); 3015 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3016 struct qla_hw_data *ha = base_vha->hw;
2758 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 3017 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2759 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24; 3018 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
2760 3019
@@ -2777,7 +3036,7 @@ qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
2777 if (risc_paused) { 3036 if (risc_paused) {
2778 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, " 3037 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
2779 "Dumping firmware!\n"); 3038 "Dumping firmware!\n");
2780 ha->isp_ops->fw_dump(ha, 0); 3039 ha->isp_ops->fw_dump(base_vha, 0);
2781 3040
2782 return PCI_ERS_RESULT_NEED_RESET; 3041 return PCI_ERS_RESULT_NEED_RESET;
2783 } else 3042 } else
@@ -2788,7 +3047,8 @@ static pci_ers_result_t
2788qla2xxx_pci_slot_reset(struct pci_dev *pdev) 3047qla2xxx_pci_slot_reset(struct pci_dev *pdev)
2789{ 3048{
2790 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; 3049 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
2791 scsi_qla_host_t *ha = pci_get_drvdata(pdev); 3050 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3051 struct qla_hw_data *ha = base_vha->hw;
2792 int rc; 3052 int rc;
2793 3053
2794 if (ha->mem_only) 3054 if (ha->mem_only)
@@ -2804,13 +3064,13 @@ qla2xxx_pci_slot_reset(struct pci_dev *pdev)
2804 } 3064 }
2805 pci_set_master(pdev); 3065 pci_set_master(pdev);
2806 3066
2807 if (ha->isp_ops->pci_config(ha)) 3067 if (ha->isp_ops->pci_config(base_vha))
2808 return ret; 3068 return ret;
2809 3069
2810 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); 3070 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
2811 if (qla2x00_abort_isp(ha)== QLA_SUCCESS) 3071 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
2812 ret = PCI_ERS_RESULT_RECOVERED; 3072 ret = PCI_ERS_RESULT_RECOVERED;
2813 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); 3073 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
2814 3074
2815 return ret; 3075 return ret;
2816} 3076}
@@ -2818,10 +3078,11 @@ qla2xxx_pci_slot_reset(struct pci_dev *pdev)
2818static void 3078static void
2819qla2xxx_pci_resume(struct pci_dev *pdev) 3079qla2xxx_pci_resume(struct pci_dev *pdev)
2820{ 3080{
2821 scsi_qla_host_t *ha = pci_get_drvdata(pdev); 3081 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3082 struct qla_hw_data *ha = base_vha->hw;
2822 int ret; 3083 int ret;
2823 3084
2824 ret = qla2x00_wait_for_hba_online(ha); 3085 ret = qla2x00_wait_for_hba_online(base_vha);
2825 if (ret != QLA_SUCCESS) { 3086 if (ret != QLA_SUCCESS) {
2826 qla_printk(KERN_ERR, ha, 3087 qla_printk(KERN_ERR, ha,
2827 "the device failed to resume I/O " 3088 "the device failed to resume I/O "