0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #define QLA1280_VERSION "3.27.1"
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330 #include <linux/module.h>
0331
0332 #include <linux/types.h>
0333 #include <linux/string.h>
0334 #include <linux/errno.h>
0335 #include <linux/kernel.h>
0336 #include <linux/ioport.h>
0337 #include <linux/delay.h>
0338 #include <linux/timer.h>
0339 #include <linux/pci.h>
0340 #include <linux/proc_fs.h>
0341 #include <linux/stat.h>
0342 #include <linux/pci_ids.h>
0343 #include <linux/interrupt.h>
0344 #include <linux/init.h>
0345 #include <linux/dma-mapping.h>
0346 #include <linux/firmware.h>
0347
0348 #include <asm/io.h>
0349 #include <asm/irq.h>
0350 #include <asm/byteorder.h>
0351 #include <asm/processor.h>
0352 #include <asm/types.h>
0353
0354 #include <scsi/scsi.h>
0355 #include <scsi/scsi_cmnd.h>
0356 #include <scsi/scsi_device.h>
0357 #include <scsi/scsi_host.h>
0358 #include <scsi/scsi_tcq.h>
0359
0360
0361
0362
0363
0364
0365 #define DEBUG_QLA1280_INTR 0
0366 #define DEBUG_PRINT_NVRAM 0
0367 #define DEBUG_QLA1280 0
0368
0369 #define MEMORY_MAPPED_IO 1
0370
0371 #include "qla1280.h"
0372
0373 #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
0374 #define QLA_64BIT_PTR 1
0375 #endif
0376
0377 #define NVRAM_DELAY() udelay(500)
0378
0379 #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
0380 #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
0381 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
0382 #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
0383 ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
0384
0385
0386 static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
0387 static void qla1280_remove_one(struct pci_dev *);
0388
0389
0390
0391
0392 static void qla1280_done(struct scsi_qla_host *);
0393 static int qla1280_get_token(char *);
0394 static int qla1280_setup(char *s) __init;
0395
0396
0397
0398
0399 static int qla1280_load_firmware(struct scsi_qla_host *);
0400 static int qla1280_init_rings(struct scsi_qla_host *);
0401 static int qla1280_nvram_config(struct scsi_qla_host *);
0402 static int qla1280_mailbox_command(struct scsi_qla_host *,
0403 uint8_t, uint16_t *);
0404 static int qla1280_bus_reset(struct scsi_qla_host *, int);
0405 static int qla1280_device_reset(struct scsi_qla_host *, int, int);
0406 static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
0407 static int qla1280_abort_isp(struct scsi_qla_host *);
0408 #ifdef QLA_64BIT_PTR
0409 static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
0410 #else
0411 static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
0412 #endif
0413 static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
0414 static void qla1280_poll(struct scsi_qla_host *);
0415 static void qla1280_reset_adapter(struct scsi_qla_host *);
0416 static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
0417 static void qla1280_isp_cmd(struct scsi_qla_host *);
0418 static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
0419 static void qla1280_rst_aen(struct scsi_qla_host *);
0420 static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
0421 struct list_head *);
0422 static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
0423 struct list_head *);
0424 static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
0425 static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
0426 static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *);
0427 static request_t *qla1280_req_pkt(struct scsi_qla_host *);
0428 static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
0429 unsigned int);
0430 static void qla1280_get_target_parameters(struct scsi_qla_host *,
0431 struct scsi_device *);
0432 static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
0433
0434
0435 static struct qla_driver_setup driver_setup;
0436
0437
0438
0439
0440 static inline uint16_t
0441 qla1280_data_direction(struct scsi_cmnd *cmnd)
0442 {
0443 switch(cmnd->sc_data_direction) {
0444 case DMA_FROM_DEVICE:
0445 return BIT_5;
0446 case DMA_TO_DEVICE:
0447 return BIT_6;
0448 case DMA_BIDIRECTIONAL:
0449 return BIT_5 | BIT_6;
0450
0451
0452
0453
0454
0455 case DMA_NONE:
0456 default:
0457 return 0;
0458 }
0459 }
0460
0461 #if DEBUG_QLA1280
0462 static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
0463 static void __qla1280_dump_buffer(char *, int);
0464 #endif
0465
0466
0467
0468
0469
0470 #ifdef MODULE
0471 static char *qla1280;
0472
0473
0474 module_param(qla1280, charp, 0);
0475 #else
0476 __setup("qla1280=", qla1280_setup);
0477 #endif
0478
0479
0480 #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
0481 #define CMD_CDBP(Cmnd) Cmnd->cmnd
0482 #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
0483 #define CMD_SNSLEN(Cmnd) SCSI_SENSE_BUFFERSIZE
0484 #define CMD_RESULT(Cmnd) Cmnd->result
0485 #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
0486
0487 #define CMD_HOST(Cmnd) Cmnd->device->host
0488 #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
0489 #define SCSI_TCN_32(Cmnd) Cmnd->device->id
0490 #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
0491
0492
0493
0494
0495
0496
0497 struct qla_boards {
0498 char *name;
0499 int numPorts;
0500 int fw_index;
0501 };
0502
0503
0504 static struct pci_device_id qla1280_pci_tbl[] = {
0505 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
0506 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
0507 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020,
0508 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
0509 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
0510 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
0511 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
0512 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
0513 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
0514 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
0515 {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
0516 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
0517 {0,}
0518 };
0519 MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
0520
0521 static DEFINE_MUTEX(qla1280_firmware_mutex);
0522
0523 struct qla_fw {
0524 char *fwname;
0525 const struct firmware *fw;
0526 };
0527
0528 #define QL_NUM_FW_IMAGES 3
0529
0530 static struct qla_fw qla1280_fw_tbl[QL_NUM_FW_IMAGES] = {
0531 {"qlogic/1040.bin", NULL},
0532 {"qlogic/1280.bin", NULL},
0533 {"qlogic/12160.bin", NULL},
0534 };
0535
0536
0537 static struct qla_boards ql1280_board_tbl[] = {
0538 {.name = "QLA12160", .numPorts = 2, .fw_index = 2},
0539 {.name = "QLA1040" , .numPorts = 1, .fw_index = 0},
0540 {.name = "QLA1080" , .numPorts = 1, .fw_index = 1},
0541 {.name = "QLA1240" , .numPorts = 2, .fw_index = 1},
0542 {.name = "QLA1280" , .numPorts = 2, .fw_index = 1},
0543 {.name = "QLA10160", .numPorts = 1, .fw_index = 2},
0544 {.name = " ", .numPorts = 0, .fw_index = -1},
0545 };
0546
0547 static int qla1280_verbose = 1;
0548
0549 #if DEBUG_QLA1280
0550 static int ql_debug_level = 1;
0551 #define dprintk(level, format, a...) \
0552 do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
0553 #define qla1280_dump_buffer(level, buf, size) \
0554 if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
0555 #define qla1280_print_scsi_cmd(level, cmd) \
0556 if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
0557 #else
0558 #define ql_debug_level 0
0559 #define dprintk(level, format, a...) do{}while(0)
0560 #define qla1280_dump_buffer(a, b, c) do{}while(0)
0561 #define qla1280_print_scsi_cmd(a, b) do{}while(0)
0562 #endif
0563
0564 #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
0565 #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
0566 #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
0567 #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
0568
0569
0570 static int qla1280_read_nvram(struct scsi_qla_host *ha)
0571 {
0572 uint16_t *wptr;
0573 uint8_t chksum;
0574 int cnt, i;
0575 struct nvram *nv;
0576
0577 ENTER("qla1280_read_nvram");
0578
0579 if (driver_setup.no_nvram)
0580 return 1;
0581
0582 printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
0583
0584 wptr = (uint16_t *)&ha->nvram;
0585 nv = &ha->nvram;
0586 chksum = 0;
0587 for (cnt = 0; cnt < 3; cnt++) {
0588 *wptr = qla1280_get_nvram_word(ha, cnt);
0589 chksum += *wptr & 0xff;
0590 chksum += (*wptr >> 8) & 0xff;
0591 wptr++;
0592 }
0593
0594 if (nv->id0 != 'I' || nv->id1 != 'S' ||
0595 nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
0596 dprintk(2, "Invalid nvram ID or version!\n");
0597 chksum = 1;
0598 } else {
0599 for (; cnt < sizeof(struct nvram); cnt++) {
0600 *wptr = qla1280_get_nvram_word(ha, cnt);
0601 chksum += *wptr & 0xff;
0602 chksum += (*wptr >> 8) & 0xff;
0603 wptr++;
0604 }
0605 }
0606
0607 dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
0608 " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
0609 nv->version);
0610
0611
0612 if (chksum) {
0613 if (!driver_setup.no_nvram)
0614 printk(KERN_WARNING "scsi(%ld): Unable to identify or "
0615 "validate NVRAM checksum, using default "
0616 "settings\n", ha->host_no);
0617 ha->nvram_valid = 0;
0618 } else
0619 ha->nvram_valid = 1;
0620
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637 nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
0638 nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
0639 for(i = 0; i < MAX_BUSES; i++) {
0640 nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
0641 nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
0642 }
0643 dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
0644 LEAVE("qla1280_read_nvram");
0645
0646 return chksum;
0647 }
0648
0649
0650
0651
0652
0653 static const char *
0654 qla1280_info(struct Scsi_Host *host)
0655 {
0656 static char qla1280_scsi_name_buffer[125];
0657 char *bp;
0658 struct scsi_qla_host *ha;
0659 struct qla_boards *bdp;
0660
0661 bp = &qla1280_scsi_name_buffer[0];
0662 ha = (struct scsi_qla_host *)host->hostdata;
0663 bdp = &ql1280_board_tbl[ha->devnum];
0664 memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
0665
0666 sprintf (bp,
0667 "QLogic %s PCI to SCSI Host Adapter\n"
0668 " Firmware version: %2d.%02d.%02d, Driver version %s",
0669 &bdp->name[0], ha->fwver1, ha->fwver2, ha->fwver3,
0670 QLA1280_VERSION);
0671 return bp;
0672 }
0673
0674
0675
0676
0677
0678
0679
0680
0681
0682
0683
0684
0685 static int qla1280_queuecommand_lck(struct scsi_cmnd *cmd)
0686 {
0687 struct Scsi_Host *host = cmd->device->host;
0688 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
0689 struct srb *sp = scsi_cmd_priv(cmd);
0690 int status;
0691
0692 sp->cmd = cmd;
0693 sp->flags = 0;
0694 sp->wait = NULL;
0695 CMD_HANDLE(cmd) = (unsigned char *)NULL;
0696
0697 qla1280_print_scsi_cmd(5, cmd);
0698
0699 #ifdef QLA_64BIT_PTR
0700
0701
0702
0703
0704
0705
0706 status = qla1280_64bit_start_scsi(ha, sp);
0707 #else
0708 status = qla1280_32bit_start_scsi(ha, sp);
0709 #endif
0710 return status;
0711 }
0712
0713 static DEF_SCSI_QCMD(qla1280_queuecommand)
0714
0715 enum action {
0716 ABORT_COMMAND,
0717 DEVICE_RESET,
0718 BUS_RESET,
0719 ADAPTER_RESET,
0720 };
0721
0722
0723 static void qla1280_mailbox_timeout(struct timer_list *t)
0724 {
0725 struct scsi_qla_host *ha = from_timer(ha, t, mailbox_timer);
0726 struct device_reg __iomem *reg;
0727 reg = ha->iobase;
0728
0729 ha->mailbox_out[0] = RD_REG_WORD(®->mailbox0);
0730 printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
0731 "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
0732 RD_REG_WORD(®->ictrl), RD_REG_WORD(®->istatus));
0733 complete(ha->mailbox_wait);
0734 }
0735
0736 static int
0737 _qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp,
0738 struct completion *wait)
0739 {
0740 int status = FAILED;
0741 struct scsi_cmnd *cmd = sp->cmd;
0742
0743 spin_unlock_irq(ha->host->host_lock);
0744 wait_for_completion_timeout(wait, 4*HZ);
0745 spin_lock_irq(ha->host->host_lock);
0746 sp->wait = NULL;
0747 if(CMD_HANDLE(cmd) == COMPLETED_HANDLE) {
0748 status = SUCCESS;
0749 scsi_done(cmd);
0750 }
0751 return status;
0752 }
0753
0754 static int
0755 qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp)
0756 {
0757 DECLARE_COMPLETION_ONSTACK(wait);
0758
0759 sp->wait = &wait;
0760 return _qla1280_wait_for_single_command(ha, sp, &wait);
0761 }
0762
0763 static int
0764 qla1280_wait_for_pending_commands(struct scsi_qla_host *ha, int bus, int target)
0765 {
0766 int cnt;
0767 int status;
0768 struct srb *sp;
0769 struct scsi_cmnd *cmd;
0770
0771 status = SUCCESS;
0772
0773
0774
0775
0776
0777 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
0778 sp = ha->outstanding_cmds[cnt];
0779 if (sp) {
0780 cmd = sp->cmd;
0781
0782 if (bus >= 0 && SCSI_BUS_32(cmd) != bus)
0783 continue;
0784 if (target >= 0 && SCSI_TCN_32(cmd) != target)
0785 continue;
0786
0787 status = qla1280_wait_for_single_command(ha, sp);
0788 if (status == FAILED)
0789 break;
0790 }
0791 }
0792 return status;
0793 }
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804
0805
0806
0807
0808
0809 static int
0810 qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
0811 {
0812 struct scsi_qla_host *ha;
0813 int bus, target, lun;
0814 struct srb *sp;
0815 int i, found;
0816 int result=FAILED;
0817 int wait_for_bus=-1;
0818 int wait_for_target = -1;
0819 DECLARE_COMPLETION_ONSTACK(wait);
0820
0821 ENTER("qla1280_error_action");
0822
0823 ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
0824 sp = scsi_cmd_priv(cmd);
0825 bus = SCSI_BUS_32(cmd);
0826 target = SCSI_TCN_32(cmd);
0827 lun = SCSI_LUN_32(cmd);
0828
0829 dprintk(4, "error_action %i, istatus 0x%04x\n", action,
0830 RD_REG_WORD(&ha->iobase->istatus));
0831
0832 dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
0833 RD_REG_WORD(&ha->iobase->host_cmd),
0834 RD_REG_WORD(&ha->iobase->ictrl), jiffies);
0835
0836 if (qla1280_verbose)
0837 printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
0838 "Handle=0x%p, action=0x%x\n",
0839 ha->host_no, cmd, CMD_HANDLE(cmd), action);
0840
0841
0842
0843
0844
0845
0846
0847 found = -1;
0848 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
0849 if (sp == ha->outstanding_cmds[i]) {
0850 found = i;
0851 sp->wait = &wait;
0852 break;
0853 }
0854 }
0855
0856 if (found < 0) {
0857 result = SUCCESS;
0858 if (qla1280_verbose) {
0859 printk(KERN_INFO
0860 "scsi(%ld:%d:%d:%d): specified command has "
0861 "already completed.\n", ha->host_no, bus,
0862 target, lun);
0863 }
0864 }
0865
0866 switch (action) {
0867
0868 case ABORT_COMMAND:
0869 dprintk(1, "qla1280: RISC aborting command\n");
0870
0871
0872
0873
0874
0875 if (found >= 0)
0876 qla1280_abort_command(ha, sp, found);
0877 break;
0878
0879 case DEVICE_RESET:
0880 if (qla1280_verbose)
0881 printk(KERN_INFO
0882 "scsi(%ld:%d:%d:%d): Queueing device reset "
0883 "command.\n", ha->host_no, bus, target, lun);
0884 if (qla1280_device_reset(ha, bus, target) == 0) {
0885
0886 wait_for_bus = bus;
0887 wait_for_target = target;
0888 }
0889 break;
0890
0891 case BUS_RESET:
0892 if (qla1280_verbose)
0893 printk(KERN_INFO "qla1280(%ld:%d): Issued bus "
0894 "reset.\n", ha->host_no, bus);
0895 if (qla1280_bus_reset(ha, bus) == 0) {
0896
0897 wait_for_bus = bus;
0898 }
0899 break;
0900
0901 case ADAPTER_RESET:
0902 default:
0903 if (qla1280_verbose) {
0904 printk(KERN_INFO
0905 "scsi(%ld): Issued ADAPTER RESET\n",
0906 ha->host_no);
0907 printk(KERN_INFO "scsi(%ld): I/O processing will "
0908 "continue automatically\n", ha->host_no);
0909 }
0910 ha->flags.reset_active = 1;
0911
0912 if (qla1280_abort_isp(ha) != 0) {
0913 result = FAILED;
0914 }
0915
0916 ha->flags.reset_active = 0;
0917 }
0918
0919
0920
0921
0922
0923
0924
0925
0926
0927
0928 if (found >= 0)
0929 result = _qla1280_wait_for_single_command(ha, sp, &wait);
0930
0931 if (action == ABORT_COMMAND && result != SUCCESS) {
0932 printk(KERN_WARNING
0933 "scsi(%li:%i:%i:%i): "
0934 "Unable to abort command!\n",
0935 ha->host_no, bus, target, lun);
0936 }
0937
0938
0939
0940
0941
0942
0943
0944
0945
0946
0947
0948 if (result == SUCCESS && wait_for_bus >= 0) {
0949 result = qla1280_wait_for_pending_commands(ha,
0950 wait_for_bus, wait_for_target);
0951 }
0952
0953 dprintk(1, "RESET returning %d\n", result);
0954
0955 LEAVE("qla1280_error_action");
0956 return result;
0957 }
0958
0959
0960
0961
0962
0963 static int
0964 qla1280_eh_abort(struct scsi_cmnd * cmd)
0965 {
0966 int rc;
0967
0968 spin_lock_irq(cmd->device->host->host_lock);
0969 rc = qla1280_error_action(cmd, ABORT_COMMAND);
0970 spin_unlock_irq(cmd->device->host->host_lock);
0971
0972 return rc;
0973 }
0974
0975
0976
0977
0978
0979 static int
0980 qla1280_eh_device_reset(struct scsi_cmnd *cmd)
0981 {
0982 int rc;
0983
0984 spin_lock_irq(cmd->device->host->host_lock);
0985 rc = qla1280_error_action(cmd, DEVICE_RESET);
0986 spin_unlock_irq(cmd->device->host->host_lock);
0987
0988 return rc;
0989 }
0990
0991
0992
0993
0994
0995 static int
0996 qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
0997 {
0998 int rc;
0999
1000 spin_lock_irq(cmd->device->host->host_lock);
1001 rc = qla1280_error_action(cmd, BUS_RESET);
1002 spin_unlock_irq(cmd->device->host->host_lock);
1003
1004 return rc;
1005 }
1006
1007
1008
1009
1010
1011 static int
1012 qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
1013 {
1014 int rc;
1015
1016 spin_lock_irq(cmd->device->host->host_lock);
1017 rc = qla1280_error_action(cmd, ADAPTER_RESET);
1018 spin_unlock_irq(cmd->device->host->host_lock);
1019
1020 return rc;
1021 }
1022
1023 static int
1024 qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1025 sector_t capacity, int geom[])
1026 {
1027 int heads, sectors, cylinders;
1028
1029 heads = 64;
1030 sectors = 32;
1031 cylinders = (unsigned long)capacity / (heads * sectors);
1032 if (cylinders > 1024) {
1033 heads = 255;
1034 sectors = 63;
1035 cylinders = (unsigned long)capacity / (heads * sectors);
1036
1037
1038 }
1039
1040 geom[0] = heads;
1041 geom[1] = sectors;
1042 geom[2] = cylinders;
1043
1044 return 0;
1045 }
1046
1047
1048
1049 static inline void
1050 qla1280_disable_intrs(struct scsi_qla_host *ha)
1051 {
1052 WRT_REG_WORD(&ha->iobase->ictrl, 0);
1053 RD_REG_WORD(&ha->iobase->ictrl);
1054 }
1055
1056
1057 static inline void
1058 qla1280_enable_intrs(struct scsi_qla_host *ha)
1059 {
1060 WRT_REG_WORD(&ha->iobase->ictrl, (ISP_EN_INT | ISP_EN_RISC));
1061 RD_REG_WORD(&ha->iobase->ictrl);
1062 }
1063
1064
1065
1066
1067
1068 static irqreturn_t
1069 qla1280_intr_handler(int irq, void *dev_id)
1070 {
1071 struct scsi_qla_host *ha;
1072 struct device_reg __iomem *reg;
1073 u16 data;
1074 int handled = 0;
1075
1076 ENTER_INTR ("qla1280_intr_handler");
1077 ha = (struct scsi_qla_host *)dev_id;
1078
1079 spin_lock(ha->host->host_lock);
1080
1081 ha->isr_count++;
1082 reg = ha->iobase;
1083
1084 qla1280_disable_intrs(ha);
1085
1086 data = qla1280_debounce_register(®->istatus);
1087
1088 if (data & RISC_INT) {
1089 qla1280_isr(ha, &ha->done_q);
1090 handled = 1;
1091 }
1092 if (!list_empty(&ha->done_q))
1093 qla1280_done(ha);
1094
1095 spin_unlock(ha->host->host_lock);
1096
1097 qla1280_enable_intrs(ha);
1098
1099 LEAVE_INTR("qla1280_intr_handler");
1100 return IRQ_RETVAL(handled);
1101 }
1102
1103
1104 static int
1105 qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
1106 {
1107 uint8_t mr;
1108 uint16_t mb[MAILBOX_REGISTER_COUNT];
1109 struct nvram *nv;
1110 int status, lun;
1111
1112 nv = &ha->nvram;
1113
1114 mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
1115
1116
1117 mb[0] = MBC_SET_TARGET_PARAMETERS;
1118 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
1119 mb[2] = nv->bus[bus].target[target].parameter.renegotiate_on_error << 8;
1120 mb[2] |= nv->bus[bus].target[target].parameter.stop_queue_on_check << 9;
1121 mb[2] |= nv->bus[bus].target[target].parameter.auto_request_sense << 10;
1122 mb[2] |= nv->bus[bus].target[target].parameter.tag_queuing << 11;
1123 mb[2] |= nv->bus[bus].target[target].parameter.enable_sync << 12;
1124 mb[2] |= nv->bus[bus].target[target].parameter.enable_wide << 13;
1125 mb[2] |= nv->bus[bus].target[target].parameter.parity_checking << 14;
1126 mb[2] |= nv->bus[bus].target[target].parameter.disconnect_allowed << 15;
1127
1128 if (IS_ISP1x160(ha)) {
1129 mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
1130 mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8);
1131 mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
1132 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
1133 mr |= BIT_6;
1134 } else {
1135 mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8);
1136 }
1137 mb[3] |= nv->bus[bus].target[target].sync_period;
1138
1139 status = qla1280_mailbox_command(ha, mr, mb);
1140
1141
1142 for (lun = 0; lun < MAX_LUNS; lun++) {
1143 mb[0] = MBC_SET_DEVICE_QUEUE;
1144 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
1145 mb[1] |= lun;
1146 mb[2] = nv->bus[bus].max_queue_depth;
1147 mb[3] = nv->bus[bus].target[target].execution_throttle;
1148 status |= qla1280_mailbox_command(ha, 0x0f, mb);
1149 }
1150
1151 if (status)
1152 printk(KERN_WARNING "scsi(%ld:%i:%i): "
1153 "qla1280_set_target_parameters() failed\n",
1154 ha->host_no, bus, target);
1155 return status;
1156 }
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170 static int
1171 qla1280_slave_configure(struct scsi_device *device)
1172 {
1173 struct scsi_qla_host *ha;
1174 int default_depth = 3;
1175 int bus = device->channel;
1176 int target = device->id;
1177 int status = 0;
1178 struct nvram *nv;
1179 unsigned long flags;
1180
1181 ha = (struct scsi_qla_host *)device->host->hostdata;
1182 nv = &ha->nvram;
1183
1184 if (qla1280_check_for_dead_scsi_bus(ha, bus))
1185 return 1;
1186
1187 if (device->tagged_supported &&
1188 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1189 scsi_change_queue_depth(device, ha->bus_settings[bus].hiwat);
1190 } else {
1191 scsi_change_queue_depth(device, default_depth);
1192 }
1193
1194 nv->bus[bus].target[target].parameter.enable_sync = device->sdtr;
1195 nv->bus[bus].target[target].parameter.enable_wide = device->wdtr;
1196 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
1197
1198 if (driver_setup.no_sync ||
1199 (driver_setup.sync_mask &&
1200 (~driver_setup.sync_mask & (1 << target))))
1201 nv->bus[bus].target[target].parameter.enable_sync = 0;
1202 if (driver_setup.no_wide ||
1203 (driver_setup.wide_mask &&
1204 (~driver_setup.wide_mask & (1 << target))))
1205 nv->bus[bus].target[target].parameter.enable_wide = 0;
1206 if (IS_ISP1x160(ha)) {
1207 if (driver_setup.no_ppr ||
1208 (driver_setup.ppr_mask &&
1209 (~driver_setup.ppr_mask & (1 << target))))
1210 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
1211 }
1212
1213 spin_lock_irqsave(ha->host->host_lock, flags);
1214 if (nv->bus[bus].target[target].parameter.enable_sync)
1215 status = qla1280_set_target_parameters(ha, bus, target);
1216 qla1280_get_target_parameters(ha, device);
1217 spin_unlock_irqrestore(ha->host->host_lock, flags);
1218 return status;
1219 }
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229 static void
1230 qla1280_done(struct scsi_qla_host *ha)
1231 {
1232 struct srb *sp;
1233 struct list_head *done_q;
1234 int bus, target;
1235 struct scsi_cmnd *cmd;
1236
1237 ENTER("qla1280_done");
1238
1239 done_q = &ha->done_q;
1240
1241 while (!list_empty(done_q)) {
1242 sp = list_entry(done_q->next, struct srb, list);
1243
1244 list_del(&sp->list);
1245
1246 cmd = sp->cmd;
1247 bus = SCSI_BUS_32(cmd);
1248 target = SCSI_TCN_32(cmd);
1249
1250 switch ((CMD_RESULT(cmd) >> 16)) {
1251 case DID_RESET:
1252
1253 if (!ha->flags.abort_isp_active)
1254 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
1255 break;
1256 case DID_ABORT:
1257 sp->flags &= ~SRB_ABORT_PENDING;
1258 sp->flags |= SRB_ABORTED;
1259 break;
1260 default:
1261 break;
1262 }
1263
1264
1265 scsi_dma_unmap(cmd);
1266
1267
1268 ha->actthreads--;
1269
1270 if (sp->wait == NULL)
1271 scsi_done(cmd);
1272 else
1273 complete(sp->wait);
1274 }
1275 LEAVE("qla1280_done");
1276 }
1277
1278
1279
1280
1281 static int
1282 qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
1283 {
1284 int host_status = DID_ERROR;
1285 uint16_t comp_status = le16_to_cpu(sts->comp_status);
1286 uint16_t state_flags = le16_to_cpu(sts->state_flags);
1287 uint32_t residual_length = le32_to_cpu(sts->residual_length);
1288 uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
1289 #if DEBUG_QLA1280_INTR
1290 static char *reason[] = {
1291 "DID_OK",
1292 "DID_NO_CONNECT",
1293 "DID_BUS_BUSY",
1294 "DID_TIME_OUT",
1295 "DID_BAD_TARGET",
1296 "DID_ABORT",
1297 "DID_PARITY",
1298 "DID_ERROR",
1299 "DID_RESET",
1300 "DID_BAD_INTR"
1301 };
1302 #endif
1303
1304 ENTER("qla1280_return_status");
1305
1306 #if DEBUG_QLA1280_INTR
1307
1308
1309
1310
1311 #endif
1312
1313 switch (comp_status) {
1314 case CS_COMPLETE:
1315 host_status = DID_OK;
1316 break;
1317
1318 case CS_INCOMPLETE:
1319 if (!(state_flags & SF_GOT_BUS))
1320 host_status = DID_NO_CONNECT;
1321 else if (!(state_flags & SF_GOT_TARGET))
1322 host_status = DID_BAD_TARGET;
1323 else if (!(state_flags & SF_SENT_CDB))
1324 host_status = DID_ERROR;
1325 else if (!(state_flags & SF_TRANSFERRED_DATA))
1326 host_status = DID_ERROR;
1327 else if (!(state_flags & SF_GOT_STATUS))
1328 host_status = DID_ERROR;
1329 else if (!(state_flags & SF_GOT_SENSE))
1330 host_status = DID_ERROR;
1331 break;
1332
1333 case CS_RESET:
1334 host_status = DID_RESET;
1335 break;
1336
1337 case CS_ABORTED:
1338 host_status = DID_ABORT;
1339 break;
1340
1341 case CS_TIMEOUT:
1342 host_status = DID_TIME_OUT;
1343 break;
1344
1345 case CS_DATA_OVERRUN:
1346 dprintk(2, "Data overrun 0x%x\n", residual_length);
1347 dprintk(2, "qla1280_return_status: response packet data\n");
1348 qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
1349 host_status = DID_ERROR;
1350 break;
1351
1352 case CS_DATA_UNDERRUN:
1353 if ((scsi_bufflen(cp) - residual_length) <
1354 cp->underflow) {
1355 printk(KERN_WARNING
1356 "scsi: Underflow detected - retrying "
1357 "command.\n");
1358 host_status = DID_ERROR;
1359 } else {
1360 scsi_set_resid(cp, residual_length);
1361 host_status = DID_OK;
1362 }
1363 break;
1364
1365 default:
1366 host_status = DID_ERROR;
1367 break;
1368 }
1369
1370 #if DEBUG_QLA1280_INTR
1371 dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
1372 reason[host_status], scsi_status);
1373 #endif
1374
1375 LEAVE("qla1280_return_status");
1376
1377 return (scsi_status & 0xff) | (host_status << 16);
1378 }
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394 static int
1395 qla1280_initialize_adapter(struct scsi_qla_host *ha)
1396 {
1397 struct device_reg __iomem *reg;
1398 int status;
1399 int bus;
1400 unsigned long flags;
1401
1402 ENTER("qla1280_initialize_adapter");
1403
1404
1405 ha->flags.online = 0;
1406 ha->flags.disable_host_adapter = 0;
1407 ha->flags.reset_active = 0;
1408 ha->flags.abort_isp_active = 0;
1409
1410
1411 if (IS_ISP1040(ha))
1412 driver_setup.no_nvram = 1;
1413
1414 dprintk(1, "Configure PCI space for adapter...\n");
1415
1416 reg = ha->iobase;
1417
1418
1419 WRT_REG_WORD(®->semaphore, 0);
1420 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
1421 WRT_REG_WORD(®->host_cmd, HC_CLR_HOST_INT);
1422 RD_REG_WORD(®->host_cmd);
1423
1424 if (qla1280_read_nvram(ha)) {
1425 dprintk(2, "qla1280_initialize_adapter: failed to read "
1426 "NVRAM\n");
1427 }
1428
1429
1430
1431
1432
1433
1434 spin_lock_irqsave(ha->host->host_lock, flags);
1435
1436 status = qla1280_load_firmware(ha);
1437 if (status) {
1438 printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
1439 ha->host_no);
1440 goto out;
1441 }
1442
1443
1444 dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
1445 qla1280_nvram_config(ha);
1446
1447 if (ha->flags.disable_host_adapter) {
1448 status = 1;
1449 goto out;
1450 }
1451
1452 status = qla1280_init_rings(ha);
1453 if (status)
1454 goto out;
1455
1456
1457 for (bus = 0; bus < ha->ports; bus++) {
1458 if (!ha->bus_settings[bus].disable_scsi_reset &&
1459 qla1280_bus_reset(ha, bus) &&
1460 qla1280_bus_reset(ha, bus))
1461 ha->bus_settings[bus].scsi_bus_dead = 1;
1462 }
1463
1464 ha->flags.online = 1;
1465 out:
1466 spin_unlock_irqrestore(ha->host->host_lock, flags);
1467
1468 if (status)
1469 dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
1470
1471 LEAVE("qla1280_initialize_adapter");
1472 return status;
1473 }
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487 static const struct firmware *
1488 qla1280_request_firmware(struct scsi_qla_host *ha)
1489 {
1490 const struct firmware *fw;
1491 int err;
1492 int index;
1493 char *fwname;
1494
1495 spin_unlock_irq(ha->host->host_lock);
1496 mutex_lock(&qla1280_firmware_mutex);
1497
1498 index = ql1280_board_tbl[ha->devnum].fw_index;
1499 fw = qla1280_fw_tbl[index].fw;
1500 if (fw)
1501 goto out;
1502
1503 fwname = qla1280_fw_tbl[index].fwname;
1504 err = request_firmware(&fw, fwname, &ha->pdev->dev);
1505
1506 if (err) {
1507 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
1508 fwname, err);
1509 fw = ERR_PTR(err);
1510 goto unlock;
1511 }
1512 if ((fw->size % 2) || (fw->size < 6)) {
1513 printk(KERN_ERR "Invalid firmware length %zu in image \"%s\"\n",
1514 fw->size, fwname);
1515 release_firmware(fw);
1516 fw = ERR_PTR(-EINVAL);
1517 goto unlock;
1518 }
1519
1520 qla1280_fw_tbl[index].fw = fw;
1521
1522 out:
1523 ha->fwver1 = fw->data[0];
1524 ha->fwver2 = fw->data[1];
1525 ha->fwver3 = fw->data[2];
1526 unlock:
1527 mutex_unlock(&qla1280_firmware_mutex);
1528 spin_lock_irq(ha->host->host_lock);
1529 return fw;
1530 }
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542 static int
1543 qla1280_chip_diag(struct scsi_qla_host *ha)
1544 {
1545 uint16_t mb[MAILBOX_REGISTER_COUNT];
1546 struct device_reg __iomem *reg = ha->iobase;
1547 int status = 0;
1548 int cnt;
1549 uint16_t data;
1550 dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", ®->id_l);
1551
1552 dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
1553
1554
1555 WRT_REG_WORD(®->ictrl, ISP_RESET);
1556
1557
1558
1559
1560
1561
1562
1563
1564 udelay(20);
1565 data = qla1280_debounce_register(®->ictrl);
1566
1567
1568
1569 for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
1570 udelay(5);
1571 data = RD_REG_WORD(®->ictrl);
1572 }
1573
1574 if (!cnt)
1575 goto fail;
1576
1577
1578 dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
1579
1580 WRT_REG_WORD(®->cfg_1, 0);
1581
1582
1583
1584 WRT_REG_WORD(®->host_cmd, HC_RESET_RISC |
1585 HC_RELEASE_RISC | HC_DISABLE_BIOS);
1586
1587 RD_REG_WORD(®->id_l);
1588 data = qla1280_debounce_register(®->mailbox0);
1589
1590
1591
1592
1593 for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
1594 udelay(5);
1595 data = RD_REG_WORD(®->mailbox0);
1596 }
1597
1598 if (!cnt)
1599 goto fail;
1600
1601
1602 dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
1603
1604 if (RD_REG_WORD(®->mailbox1) != PROD_ID_1 ||
1605 (RD_REG_WORD(®->mailbox2) != PROD_ID_2 &&
1606 RD_REG_WORD(®->mailbox2) != PROD_ID_2a) ||
1607 RD_REG_WORD(®->mailbox3) != PROD_ID_3 ||
1608 RD_REG_WORD(®->mailbox4) != PROD_ID_4) {
1609 printk(KERN_INFO "qla1280: Wrong product ID = "
1610 "0x%x,0x%x,0x%x,0x%x\n",
1611 RD_REG_WORD(®->mailbox1),
1612 RD_REG_WORD(®->mailbox2),
1613 RD_REG_WORD(®->mailbox3),
1614 RD_REG_WORD(®->mailbox4));
1615 goto fail;
1616 }
1617
1618
1619
1620
1621 qla1280_enable_intrs(ha);
1622
1623 dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
1624
1625 mb[0] = MBC_MAILBOX_REGISTER_TEST;
1626 mb[1] = 0xAAAA;
1627 mb[2] = 0x5555;
1628 mb[3] = 0xAA55;
1629 mb[4] = 0x55AA;
1630 mb[5] = 0xA5A5;
1631 mb[6] = 0x5A5A;
1632 mb[7] = 0x2525;
1633
1634 status = qla1280_mailbox_command(ha, 0xff, mb);
1635 if (status)
1636 goto fail;
1637
1638 if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
1639 mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
1640 mb[7] != 0x2525) {
1641 printk(KERN_INFO "qla1280: Failed mbox check\n");
1642 goto fail;
1643 }
1644
1645 dprintk(3, "qla1280_chip_diag: exiting normally\n");
1646 return 0;
1647 fail:
1648 dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
1649 return status;
1650 }
1651
1652 static int
1653 qla1280_load_firmware_pio(struct scsi_qla_host *ha)
1654 {
1655
1656
1657 const struct firmware *fw;
1658 const __le16 *fw_data;
1659 uint16_t risc_address, risc_code_size;
1660 uint16_t mb[MAILBOX_REGISTER_COUNT], i;
1661 int err = 0;
1662
1663 fw = qla1280_request_firmware(ha);
1664 if (IS_ERR(fw))
1665 return PTR_ERR(fw);
1666
1667 fw_data = (const __le16 *)&fw->data[0];
1668 ha->fwstart = __le16_to_cpu(fw_data[2]);
1669
1670
1671 risc_address = ha->fwstart;
1672 fw_data = (const __le16 *)&fw->data[6];
1673 risc_code_size = (fw->size - 6) / 2;
1674
1675 for (i = 0; i < risc_code_size; i++) {
1676 mb[0] = MBC_WRITE_RAM_WORD;
1677 mb[1] = risc_address + i;
1678 mb[2] = __le16_to_cpu(fw_data[i]);
1679
1680 err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
1681 if (err) {
1682 printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
1683 ha->host_no);
1684 break;
1685 }
1686 }
1687
1688 return err;
1689 }
1690
1691 #ifdef QLA_64BIT_PTR
1692 #define LOAD_CMD MBC_LOAD_RAM_A64_ROM
1693 #define DUMP_CMD MBC_DUMP_RAM_A64_ROM
1694 #define CMD_ARGS (BIT_7 | BIT_6 | BIT_4 | BIT_3 | BIT_2 | BIT_1 | BIT_0)
1695 #else
1696 #define LOAD_CMD MBC_LOAD_RAM
1697 #define DUMP_CMD MBC_DUMP_RAM
1698 #define CMD_ARGS (BIT_4 | BIT_3 | BIT_2 | BIT_1 | BIT_0)
1699 #endif
1700
1701 #define DUMP_IT_BACK 0
1702 static int
1703 qla1280_load_firmware_dma(struct scsi_qla_host *ha)
1704 {
1705
1706 const struct firmware *fw;
1707 const __le16 *fw_data;
1708 uint16_t risc_address, risc_code_size;
1709 uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
1710 int err = 0, num, i;
1711 #if DUMP_IT_BACK
1712 uint8_t *sp, *tbuf;
1713 dma_addr_t p_tbuf;
1714
1715 tbuf = dma_alloc_coherent(&ha->pdev->dev, 8000, &p_tbuf, GFP_KERNEL);
1716 if (!tbuf)
1717 return -ENOMEM;
1718 #endif
1719
1720 fw = qla1280_request_firmware(ha);
1721 if (IS_ERR(fw))
1722 return PTR_ERR(fw);
1723
1724 fw_data = (const __le16 *)&fw->data[0];
1725 ha->fwstart = __le16_to_cpu(fw_data[2]);
1726
1727
1728 risc_address = ha->fwstart;
1729 fw_data = (const __le16 *)&fw->data[6];
1730 risc_code_size = (fw->size - 6) / 2;
1731
1732 dprintk(1, "%s: DMA RISC code (%i) words\n",
1733 __func__, risc_code_size);
1734
1735 num = 0;
1736 while (risc_code_size > 0) {
1737 int warn __attribute__((unused)) = 0;
1738
1739 cnt = 2000 >> 1;
1740
1741 if (cnt > risc_code_size)
1742 cnt = risc_code_size;
1743
1744 dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
1745 "%d,%d(0x%x)\n",
1746 fw_data, cnt, num, risc_address);
1747 for(i = 0; i < cnt; i++)
1748 ((__le16 *)ha->request_ring)[i] = fw_data[i];
1749
1750 mb[0] = LOAD_CMD;
1751 mb[1] = risc_address;
1752 mb[4] = cnt;
1753 mb[3] = ha->request_dma & 0xffff;
1754 mb[2] = (ha->request_dma >> 16) & 0xffff;
1755 mb[7] = upper_32_bits(ha->request_dma) & 0xffff;
1756 mb[6] = upper_32_bits(ha->request_dma) >> 16;
1757 dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
1758 __func__, mb[0],
1759 (void *)(long)ha->request_dma,
1760 mb[6], mb[7], mb[2], mb[3]);
1761 err = qla1280_mailbox_command(ha, CMD_ARGS, mb);
1762 if (err) {
1763 printk(KERN_ERR "scsi(%li): Failed to load partial "
1764 "segment of f\n", ha->host_no);
1765 goto out;
1766 }
1767
1768 #if DUMP_IT_BACK
1769 mb[0] = DUMP_CMD;
1770 mb[1] = risc_address;
1771 mb[4] = cnt;
1772 mb[3] = p_tbuf & 0xffff;
1773 mb[2] = (p_tbuf >> 16) & 0xffff;
1774 mb[7] = upper_32_bits(p_tbuf) & 0xffff;
1775 mb[6] = upper_32_bits(p_tbuf) >> 16;
1776
1777 err = qla1280_mailbox_command(ha, CMD_ARGS, mb);
1778 if (err) {
1779 printk(KERN_ERR
1780 "Failed to dump partial segment of f/w\n");
1781 goto out;
1782 }
1783 sp = (uint8_t *)ha->request_ring;
1784 for (i = 0; i < (cnt << 1); i++) {
1785 if (tbuf[i] != sp[i] && warn++ < 10) {
1786 printk(KERN_ERR "%s: FW compare error @ "
1787 "byte(0x%x) loop#=%x\n",
1788 __func__, i, num);
1789 printk(KERN_ERR "%s: FWbyte=%x "
1790 "FWfromChip=%x\n",
1791 __func__, sp[i], tbuf[i]);
1792
1793 }
1794 }
1795 #endif
1796 risc_address += cnt;
1797 risc_code_size = risc_code_size - cnt;
1798 fw_data = fw_data + cnt;
1799 num++;
1800 }
1801
1802 out:
1803 #if DUMP_IT_BACK
1804 dma_free_coherent(&ha->pdev->dev, 8000, tbuf, p_tbuf);
1805 #endif
1806 return err;
1807 }
1808
1809 static int
1810 qla1280_start_firmware(struct scsi_qla_host *ha)
1811 {
1812 uint16_t mb[MAILBOX_REGISTER_COUNT];
1813 int err;
1814
1815 dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
1816 __func__);
1817
1818
1819 mb[0] = MBC_VERIFY_CHECKSUM;
1820
1821 mb[1] = ha->fwstart;
1822 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
1823 if (err) {
1824 printk(KERN_ERR "scsi(%li): RISC checksum failed.\n", ha->host_no);
1825 return err;
1826 }
1827
1828
1829 dprintk(1, "%s: start firmware running.\n", __func__);
1830 mb[0] = MBC_EXECUTE_FIRMWARE;
1831 mb[1] = ha->fwstart;
1832 err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
1833 if (err) {
1834 printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
1835 ha->host_no);
1836 }
1837
1838 return err;
1839 }
1840
1841 static int
1842 qla1280_load_firmware(struct scsi_qla_host *ha)
1843 {
1844
1845 int err;
1846
1847 err = qla1280_chip_diag(ha);
1848 if (err)
1849 goto out;
1850 if (IS_ISP1040(ha))
1851 err = qla1280_load_firmware_pio(ha);
1852 else
1853 err = qla1280_load_firmware_dma(ha);
1854 if (err)
1855 goto out;
1856 err = qla1280_start_firmware(ha);
1857 out:
1858 return err;
1859 }
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874 static int
1875 qla1280_init_rings(struct scsi_qla_host *ha)
1876 {
1877 uint16_t mb[MAILBOX_REGISTER_COUNT];
1878 int status = 0;
1879
1880 ENTER("qla1280_init_rings");
1881
1882
1883 memset(ha->outstanding_cmds, 0,
1884 sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
1885
1886
1887 ha->request_ring_ptr = ha->request_ring;
1888 ha->req_ring_index = 0;
1889 ha->req_q_cnt = REQUEST_ENTRY_CNT;
1890
1891 mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
1892 mb[1] = REQUEST_ENTRY_CNT;
1893 mb[3] = ha->request_dma & 0xffff;
1894 mb[2] = (ha->request_dma >> 16) & 0xffff;
1895 mb[4] = 0;
1896 mb[7] = upper_32_bits(ha->request_dma) & 0xffff;
1897 mb[6] = upper_32_bits(ha->request_dma) >> 16;
1898 if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
1899 BIT_3 | BIT_2 | BIT_1 | BIT_0,
1900 &mb[0]))) {
1901
1902 ha->response_ring_ptr = ha->response_ring;
1903 ha->rsp_ring_index = 0;
1904
1905 mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
1906 mb[1] = RESPONSE_ENTRY_CNT;
1907 mb[3] = ha->response_dma & 0xffff;
1908 mb[2] = (ha->response_dma >> 16) & 0xffff;
1909 mb[5] = 0;
1910 mb[7] = upper_32_bits(ha->response_dma) & 0xffff;
1911 mb[6] = upper_32_bits(ha->response_dma) >> 16;
1912 status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
1913 BIT_3 | BIT_2 | BIT_1 | BIT_0,
1914 &mb[0]);
1915 }
1916
1917 if (status)
1918 dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
1919
1920 LEAVE("qla1280_init_rings");
1921 return status;
1922 }
1923
1924 static void
1925 qla1280_print_settings(struct nvram *nv)
1926 {
1927 dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
1928 nv->bus[0].config_1.initiator_id);
1929 dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
1930 nv->bus[1].config_1.initiator_id);
1931
1932 dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
1933 nv->bus[0].bus_reset_delay);
1934 dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
1935 nv->bus[1].bus_reset_delay);
1936
1937 dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
1938 dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
1939 dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
1940 dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
1941
1942 dprintk(1, "qla1280 : async data setup time[0]=%d\n",
1943 nv->bus[0].config_2.async_data_setup_time);
1944 dprintk(1, "qla1280 : async data setup time[1]=%d\n",
1945 nv->bus[1].config_2.async_data_setup_time);
1946
1947 dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
1948 nv->bus[0].config_2.req_ack_active_negation);
1949 dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
1950 nv->bus[1].config_2.req_ack_active_negation);
1951
1952 dprintk(1, "qla1280 : data line active negation[0]=%d\n",
1953 nv->bus[0].config_2.data_line_active_negation);
1954 dprintk(1, "qla1280 : data line active negation[1]=%d\n",
1955 nv->bus[1].config_2.data_line_active_negation);
1956
1957 dprintk(1, "qla1280 : disable loading risc code=%d\n",
1958 nv->cntr_flags_1.disable_loading_risc_code);
1959
1960 dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
1961 nv->cntr_flags_1.enable_64bit_addressing);
1962
1963 dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
1964 nv->bus[0].selection_timeout);
1965 dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
1966 nv->bus[1].selection_timeout);
1967
1968 dprintk(1, "qla1280 : max queue depth[0]=%d\n",
1969 nv->bus[0].max_queue_depth);
1970 dprintk(1, "qla1280 : max queue depth[1]=%d\n",
1971 nv->bus[1].max_queue_depth);
1972 }
1973
1974 static void
1975 qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
1976 {
1977 struct nvram *nv = &ha->nvram;
1978
1979 nv->bus[bus].target[target].parameter.renegotiate_on_error = 1;
1980 nv->bus[bus].target[target].parameter.auto_request_sense = 1;
1981 nv->bus[bus].target[target].parameter.tag_queuing = 1;
1982 nv->bus[bus].target[target].parameter.enable_sync = 1;
1983 #if 1
1984 nv->bus[bus].target[target].parameter.enable_wide = 1;
1985 #endif
1986 nv->bus[bus].target[target].execution_throttle =
1987 nv->bus[bus].max_queue_depth - 1;
1988 nv->bus[bus].target[target].parameter.parity_checking = 1;
1989 nv->bus[bus].target[target].parameter.disconnect_allowed = 1;
1990
1991 if (IS_ISP1x160(ha)) {
1992 nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
1993 nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
1994 nv->bus[bus].target[target].sync_period = 9;
1995 nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
1996 nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
1997 nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
1998 } else {
1999 nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
2000 nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
2001 nv->bus[bus].target[target].sync_period = 10;
2002 }
2003 }
2004
2005 static void
2006 qla1280_set_defaults(struct scsi_qla_host *ha)
2007 {
2008 struct nvram *nv = &ha->nvram;
2009 int bus, target;
2010
2011 dprintk(1, "Using defaults for NVRAM: \n");
2012 memset(nv, 0, sizeof(struct nvram));
2013
2014
2015 nv->firmware_feature.f.enable_fast_posting = 1;
2016 nv->firmware_feature.f.disable_synchronous_backoff = 1;
2017 nv->termination.scsi_bus_0_control = 3;
2018 nv->termination.scsi_bus_1_control = 3;
2019 nv->termination.auto_term_support = 1;
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029 nv->isp_config.burst_enable = 1;
2030 if (IS_ISP1040(ha))
2031 nv->isp_config.fifo_threshold |= 3;
2032 else
2033 nv->isp_config.fifo_threshold |= 4;
2034
2035 if (IS_ISP1x160(ha))
2036 nv->isp_parameter = 0x01;
2037
2038 for (bus = 0; bus < MAX_BUSES; bus++) {
2039 nv->bus[bus].config_1.initiator_id = 7;
2040 nv->bus[bus].config_2.req_ack_active_negation = 1;
2041 nv->bus[bus].config_2.data_line_active_negation = 1;
2042 nv->bus[bus].selection_timeout = 250;
2043 nv->bus[bus].max_queue_depth = 32;
2044
2045 if (IS_ISP1040(ha)) {
2046 nv->bus[bus].bus_reset_delay = 3;
2047 nv->bus[bus].config_2.async_data_setup_time = 6;
2048 nv->bus[bus].retry_delay = 1;
2049 } else {
2050 nv->bus[bus].bus_reset_delay = 5;
2051 nv->bus[bus].config_2.async_data_setup_time = 8;
2052 }
2053
2054 for (target = 0; target < MAX_TARGETS; target++)
2055 qla1280_set_target_defaults(ha, bus, target);
2056 }
2057 }
2058
2059 static int
2060 qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
2061 {
2062 struct nvram *nv = &ha->nvram;
2063 uint16_t mb[MAILBOX_REGISTER_COUNT];
2064 int status, lun;
2065 uint16_t flag;
2066
2067
2068 mb[0] = MBC_SET_TARGET_PARAMETERS;
2069 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
2070
2071
2072
2073
2074
2075
2076 mb[2] = (TP_RENEGOTIATE | TP_AUTO_REQUEST_SENSE | TP_TAGGED_QUEUE
2077 | TP_WIDE | TP_PARITY | TP_DISCONNECT);
2078
2079 if (IS_ISP1x160(ha))
2080 mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
2081 else
2082 mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
2083 mb[3] |= nv->bus[bus].target[target].sync_period;
2084 status = qla1280_mailbox_command(ha, 0x0f, mb);
2085
2086
2087 flag = (BIT_0 << target);
2088 if (nv->bus[bus].target[target].parameter.tag_queuing)
2089 ha->bus_settings[bus].qtag_enables |= flag;
2090
2091
2092 if (IS_ISP1x160(ha)) {
2093 if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
2094 ha->bus_settings[bus].device_enables |= flag;
2095 ha->bus_settings[bus].lun_disables |= 0;
2096 } else {
2097 if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
2098 ha->bus_settings[bus].device_enables |= flag;
2099
2100 if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
2101 ha->bus_settings[bus].lun_disables |= flag;
2102 }
2103
2104
2105 for (lun = 0; lun < MAX_LUNS; lun++) {
2106 mb[0] = MBC_SET_DEVICE_QUEUE;
2107 mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
2108 mb[1] |= lun;
2109 mb[2] = nv->bus[bus].max_queue_depth;
2110 mb[3] = nv->bus[bus].target[target].execution_throttle;
2111 status |= qla1280_mailbox_command(ha, 0x0f, mb);
2112 }
2113
2114 return status;
2115 }
2116
2117 static int
2118 qla1280_config_bus(struct scsi_qla_host *ha, int bus)
2119 {
2120 struct nvram *nv = &ha->nvram;
2121 uint16_t mb[MAILBOX_REGISTER_COUNT];
2122 int target, status;
2123
2124
2125 ha->bus_settings[bus].disable_scsi_reset =
2126 nv->bus[bus].config_1.scsi_reset_disable;
2127
2128
2129 ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
2130 mb[0] = MBC_SET_INITIATOR_ID;
2131 mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
2132 ha->bus_settings[bus].id;
2133 status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2134
2135
2136 ha->bus_settings[bus].bus_reset_delay =
2137 nv->bus[bus].bus_reset_delay;
2138
2139
2140 ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
2141
2142
2143 for (target = 0; target < MAX_TARGETS; target++)
2144 status |= qla1280_config_target(ha, bus, target);
2145
2146 return status;
2147 }
2148
2149 static int
2150 qla1280_nvram_config(struct scsi_qla_host *ha)
2151 {
2152 struct device_reg __iomem *reg = ha->iobase;
2153 struct nvram *nv = &ha->nvram;
2154 int bus, target, status = 0;
2155 uint16_t mb[MAILBOX_REGISTER_COUNT];
2156
2157 ENTER("qla1280_nvram_config");
2158
2159 if (ha->nvram_valid) {
2160
2161 for (bus = 0; bus < MAX_BUSES; bus++)
2162 for (target = 0; target < MAX_TARGETS; target++) {
2163 nv->bus[bus].target[target].parameter.
2164 auto_request_sense = 1;
2165 }
2166 } else {
2167 qla1280_set_defaults(ha);
2168 }
2169
2170 qla1280_print_settings(nv);
2171
2172
2173 ha->flags.disable_risc_code_load =
2174 nv->cntr_flags_1.disable_loading_risc_code;
2175
2176 if (IS_ISP1040(ha)) {
2177 uint16_t hwrev, cfg1, cdma_conf;
2178
2179 hwrev = RD_REG_WORD(®->cfg_0) & ISP_CFG0_HWMSK;
2180
2181 cfg1 = RD_REG_WORD(®->cfg_1) & ~(BIT_4 | BIT_5 | BIT_6);
2182 cdma_conf = RD_REG_WORD(®->cdma_cfg);
2183
2184
2185 if (hwrev != ISP_CFG0_1040A)
2186 cfg1 |= nv->isp_config.fifo_threshold << 4;
2187
2188 cfg1 |= nv->isp_config.burst_enable << 2;
2189 WRT_REG_WORD(®->cfg_1, cfg1);
2190
2191 WRT_REG_WORD(®->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
2192 WRT_REG_WORD(®->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
2193 } else {
2194 uint16_t cfg1, term;
2195
2196
2197 cfg1 = nv->isp_config.fifo_threshold << 4;
2198 cfg1 |= nv->isp_config.burst_enable << 2;
2199
2200 if (ha->ports > 1)
2201 cfg1 |= BIT_13;
2202 WRT_REG_WORD(®->cfg_1, cfg1);
2203
2204
2205 WRT_REG_WORD(®->gpio_enable,
2206 BIT_7 | BIT_3 | BIT_2 | BIT_1 | BIT_0);
2207 term = nv->termination.scsi_bus_1_control;
2208 term |= nv->termination.scsi_bus_0_control << 2;
2209 term |= nv->termination.auto_term_support << 7;
2210 RD_REG_WORD(®->id_l);
2211 WRT_REG_WORD(®->gpio_data, term);
2212 }
2213 RD_REG_WORD(®->id_l);
2214
2215
2216 mb[0] = MBC_SET_SYSTEM_PARAMETER;
2217 mb[1] = nv->isp_parameter;
2218 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
2219
2220 if (IS_ISP1x40(ha)) {
2221
2222 mb[0] = MBC_SET_CLOCK_RATE;
2223 mb[1] = 40;
2224 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2225 }
2226
2227
2228 mb[0] = MBC_SET_FIRMWARE_FEATURES;
2229 mb[1] = nv->firmware_feature.f.enable_fast_posting;
2230 mb[1] |= nv->firmware_feature.f.report_lvd_bus_transition << 1;
2231 mb[1] |= nv->firmware_feature.f.disable_synchronous_backoff << 5;
2232 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2233
2234
2235 mb[0] = MBC_SET_RETRY_COUNT;
2236 mb[1] = nv->bus[0].retry_count;
2237 mb[2] = nv->bus[0].retry_delay;
2238 mb[6] = nv->bus[1].retry_count;
2239 mb[7] = nv->bus[1].retry_delay;
2240 status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
2241 BIT_1 | BIT_0, &mb[0]);
2242
2243
2244 mb[0] = MBC_SET_ASYNC_DATA_SETUP;
2245 mb[1] = nv->bus[0].config_2.async_data_setup_time;
2246 mb[2] = nv->bus[1].config_2.async_data_setup_time;
2247 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2248
2249
2250 mb[0] = MBC_SET_ACTIVE_NEGATION;
2251 mb[1] = 0;
2252 if (nv->bus[0].config_2.req_ack_active_negation)
2253 mb[1] |= BIT_5;
2254 if (nv->bus[0].config_2.data_line_active_negation)
2255 mb[1] |= BIT_4;
2256 mb[2] = 0;
2257 if (nv->bus[1].config_2.req_ack_active_negation)
2258 mb[2] |= BIT_5;
2259 if (nv->bus[1].config_2.data_line_active_negation)
2260 mb[2] |= BIT_4;
2261 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2262
2263 mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
2264 mb[1] = 2;
2265 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2266
2267
2268 mb[0] = MBC_SET_PCI_CONTROL;
2269 mb[1] = BIT_1;
2270 mb[2] = BIT_1;
2271 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2272
2273 mb[0] = MBC_SET_TAG_AGE_LIMIT;
2274 mb[1] = 8;
2275 status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
2276
2277
2278 mb[0] = MBC_SET_SELECTION_TIMEOUT;
2279 mb[1] = nv->bus[0].selection_timeout;
2280 mb[2] = nv->bus[1].selection_timeout;
2281 status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
2282
2283 for (bus = 0; bus < ha->ports; bus++)
2284 status |= qla1280_config_bus(ha, bus);
2285
2286 if (status)
2287 dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
2288
2289 LEAVE("qla1280_nvram_config");
2290 return status;
2291 }
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305 static uint16_t
2306 qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
2307 {
2308 uint32_t nv_cmd;
2309 uint16_t data;
2310
2311 nv_cmd = address << 16;
2312 nv_cmd |= NV_READ_OP;
2313
2314 data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
2315
2316 dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
2317 "0x%x", data);
2318
2319 return data;
2320 }
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336 static uint16_t
2337 qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
2338 {
2339 struct device_reg __iomem *reg = ha->iobase;
2340 int cnt;
2341 uint16_t data = 0;
2342 uint16_t reg_data;
2343
2344
2345
2346 nv_cmd <<= 5;
2347 for (cnt = 0; cnt < 11; cnt++) {
2348 if (nv_cmd & BIT_31)
2349 qla1280_nv_write(ha, NV_DATA_OUT);
2350 else
2351 qla1280_nv_write(ha, 0);
2352 nv_cmd <<= 1;
2353 }
2354
2355
2356
2357 for (cnt = 0; cnt < 16; cnt++) {
2358 WRT_REG_WORD(®->nvram, (NV_SELECT | NV_CLOCK));
2359 RD_REG_WORD(®->id_l);
2360 NVRAM_DELAY();
2361 data <<= 1;
2362 reg_data = RD_REG_WORD(®->nvram);
2363 if (reg_data & NV_DATA_IN)
2364 data |= BIT_0;
2365 WRT_REG_WORD(®->nvram, NV_SELECT);
2366 RD_REG_WORD(®->id_l);
2367 NVRAM_DELAY();
2368 }
2369
2370
2371
2372 WRT_REG_WORD(®->nvram, NV_DESELECT);
2373 RD_REG_WORD(®->id_l);
2374 NVRAM_DELAY();
2375
2376 return data;
2377 }
2378
2379 static void
2380 qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
2381 {
2382 struct device_reg __iomem *reg = ha->iobase;
2383
2384 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2385 RD_REG_WORD(®->id_l);
2386 NVRAM_DELAY();
2387 WRT_REG_WORD(®->nvram, data | NV_SELECT | NV_CLOCK);
2388 RD_REG_WORD(®->id_l);
2389 NVRAM_DELAY();
2390 WRT_REG_WORD(®->nvram, data | NV_SELECT);
2391 RD_REG_WORD(®->id_l);
2392 NVRAM_DELAY();
2393 }
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410 static int
2411 qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
2412 {
2413 struct device_reg __iomem *reg = ha->iobase;
2414 int status = 0;
2415 int cnt;
2416 uint16_t *optr, *iptr;
2417 uint16_t __iomem *mptr;
2418 DECLARE_COMPLETION_ONSTACK(wait);
2419
2420 ENTER("qla1280_mailbox_command");
2421
2422 if (ha->mailbox_wait) {
2423 printk(KERN_ERR "Warning mailbox wait already in use!\n");
2424 }
2425 ha->mailbox_wait = &wait;
2426
2427
2428
2429
2430
2431
2432 mptr = (uint16_t __iomem *) ®->mailbox0;
2433 iptr = mb;
2434 for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
2435 if (mr & BIT_0) {
2436 WRT_REG_WORD(mptr, (*iptr));
2437 }
2438
2439 mr >>= 1;
2440 mptr++;
2441 iptr++;
2442 }
2443
2444
2445
2446
2447 timer_setup(&ha->mailbox_timer, qla1280_mailbox_timeout, 0);
2448 mod_timer(&ha->mailbox_timer, jiffies + 20 * HZ);
2449
2450 spin_unlock_irq(ha->host->host_lock);
2451 WRT_REG_WORD(®->host_cmd, HC_SET_HOST_INT);
2452 qla1280_debounce_register(®->istatus);
2453
2454 wait_for_completion(&wait);
2455 del_timer_sync(&ha->mailbox_timer);
2456
2457 spin_lock_irq(ha->host->host_lock);
2458
2459 ha->mailbox_wait = NULL;
2460
2461
2462 if (ha->mailbox_out[0] != MBS_CMD_CMP) {
2463 printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
2464 "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
2465 "0x%04x\n",
2466 mb[0], ha->mailbox_out[0], RD_REG_WORD(®->istatus));
2467 printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
2468 RD_REG_WORD(®->mailbox0), RD_REG_WORD(®->mailbox1),
2469 RD_REG_WORD(®->mailbox2), RD_REG_WORD(®->mailbox3));
2470 printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
2471 RD_REG_WORD(®->mailbox4), RD_REG_WORD(®->mailbox5),
2472 RD_REG_WORD(®->mailbox6), RD_REG_WORD(®->mailbox7));
2473 status = 1;
2474 }
2475
2476
2477 optr = mb;
2478 iptr = (uint16_t *) &ha->mailbox_out[0];
2479 mr = MAILBOX_REGISTER_COUNT;
2480 memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
2481
2482 if (ha->flags.reset_marker)
2483 qla1280_rst_aen(ha);
2484
2485 if (status)
2486 dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
2487 "0x%x ****\n", mb[0]);
2488
2489 LEAVE("qla1280_mailbox_command");
2490 return status;
2491 }
2492
2493
2494
2495
2496
2497
2498
2499
2500 static void
2501 qla1280_poll(struct scsi_qla_host *ha)
2502 {
2503 struct device_reg __iomem *reg = ha->iobase;
2504 uint16_t data;
2505 LIST_HEAD(done_q);
2506
2507
2508
2509
2510 data = RD_REG_WORD(®->istatus);
2511 if (data & RISC_INT)
2512 qla1280_isr(ha, &done_q);
2513
2514 if (!ha->mailbox_wait) {
2515 if (ha->flags.reset_marker)
2516 qla1280_rst_aen(ha);
2517 }
2518
2519 if (!list_empty(&done_q))
2520 qla1280_done(ha);
2521
2522
2523 }
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536 static int
2537 qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
2538 {
2539 uint16_t mb[MAILBOX_REGISTER_COUNT];
2540 uint16_t reset_delay;
2541 int status;
2542
2543 dprintk(3, "qla1280_bus_reset: entered\n");
2544
2545 if (qla1280_verbose)
2546 printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
2547 ha->host_no, bus);
2548
2549 reset_delay = ha->bus_settings[bus].bus_reset_delay;
2550 mb[0] = MBC_BUS_RESET;
2551 mb[1] = reset_delay;
2552 mb[2] = (uint16_t) bus;
2553 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2554
2555 if (status) {
2556 if (ha->bus_settings[bus].failed_reset_count > 2)
2557 ha->bus_settings[bus].scsi_bus_dead = 1;
2558 ha->bus_settings[bus].failed_reset_count++;
2559 } else {
2560 spin_unlock_irq(ha->host->host_lock);
2561 ssleep(reset_delay);
2562 spin_lock_irq(ha->host->host_lock);
2563
2564 ha->bus_settings[bus].scsi_bus_dead = 0;
2565 ha->bus_settings[bus].failed_reset_count = 0;
2566 ha->bus_settings[bus].reset_marker = 0;
2567
2568 qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
2569 }
2570
2571
2572
2573
2574
2575
2576 if (status)
2577 dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
2578 else
2579 dprintk(3, "qla1280_bus_reset: exiting normally\n");
2580
2581 return status;
2582 }
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596 static int
2597 qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
2598 {
2599 uint16_t mb[MAILBOX_REGISTER_COUNT];
2600 int status;
2601
2602 ENTER("qla1280_device_reset");
2603
2604 mb[0] = MBC_ABORT_TARGET;
2605 mb[1] = (bus ? (target | BIT_7) : target) << 8;
2606 mb[2] = 1;
2607 status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
2608
2609
2610 qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
2611
2612 if (status)
2613 dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
2614
2615 LEAVE("qla1280_device_reset");
2616 return status;
2617 }
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630 static int
2631 qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
2632 {
2633 uint16_t mb[MAILBOX_REGISTER_COUNT];
2634 unsigned int bus, target, lun;
2635 int status;
2636
2637 ENTER("qla1280_abort_command");
2638
2639 bus = SCSI_BUS_32(sp->cmd);
2640 target = SCSI_TCN_32(sp->cmd);
2641 lun = SCSI_LUN_32(sp->cmd);
2642
2643 sp->flags |= SRB_ABORT_PENDING;
2644
2645 mb[0] = MBC_ABORT_COMMAND;
2646 mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
2647 mb[2] = handle >> 16;
2648 mb[3] = handle & 0xffff;
2649 status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
2650
2651 if (status) {
2652 dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
2653 sp->flags &= ~SRB_ABORT_PENDING;
2654 }
2655
2656
2657 LEAVE("qla1280_abort_command");
2658 return status;
2659 }
2660
2661
2662
2663
2664
2665
2666
2667
2668 static void
2669 qla1280_reset_adapter(struct scsi_qla_host *ha)
2670 {
2671 struct device_reg __iomem *reg = ha->iobase;
2672
2673 ENTER("qla1280_reset_adapter");
2674
2675
2676 ha->flags.online = 0;
2677 WRT_REG_WORD(®->ictrl, ISP_RESET);
2678 WRT_REG_WORD(®->host_cmd,
2679 HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
2680 RD_REG_WORD(®->id_l);
2681
2682 LEAVE("qla1280_reset_adapter");
2683 }
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696 static void
2697 qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
2698 {
2699 struct mrk_entry *pkt;
2700
2701 ENTER("qla1280_marker");
2702
2703
2704 if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
2705 pkt->entry_type = MARKER_TYPE;
2706 pkt->lun = (uint8_t) lun;
2707 pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
2708 pkt->modifier = type;
2709 pkt->entry_status = 0;
2710
2711
2712 qla1280_isp_cmd(ha);
2713 }
2714
2715 LEAVE("qla1280_marker");
2716 }
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731 #ifdef QLA_64BIT_PTR
2732 static int
2733 qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
2734 {
2735 struct device_reg __iomem *reg = ha->iobase;
2736 struct scsi_cmnd *cmd = sp->cmd;
2737 cmd_a64_entry_t *pkt;
2738 __le32 *dword_ptr;
2739 dma_addr_t dma_handle;
2740 int status = 0;
2741 int cnt;
2742 int req_cnt;
2743 int seg_cnt;
2744 u8 dir;
2745
2746 ENTER("qla1280_64bit_start_scsi:");
2747
2748
2749 req_cnt = 1;
2750 seg_cnt = scsi_dma_map(cmd);
2751 if (seg_cnt > 0) {
2752 if (seg_cnt > 2) {
2753 req_cnt += (seg_cnt - 2) / 5;
2754 if ((seg_cnt - 2) % 5)
2755 req_cnt++;
2756 }
2757 } else if (seg_cnt < 0) {
2758 status = 1;
2759 goto out;
2760 }
2761
2762 if ((req_cnt + 2) >= ha->req_q_cnt) {
2763
2764 cnt = RD_REG_WORD(®->mailbox4);
2765 if (ha->req_ring_index < cnt)
2766 ha->req_q_cnt = cnt - ha->req_ring_index;
2767 else
2768 ha->req_q_cnt =
2769 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
2770 }
2771
2772 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
2773 ha->req_q_cnt, seg_cnt);
2774
2775
2776 if ((req_cnt + 2) >= ha->req_q_cnt) {
2777 status = SCSI_MLQUEUE_HOST_BUSY;
2778 dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
2779 "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
2780 req_cnt);
2781 goto out;
2782 }
2783
2784
2785 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
2786 ha->outstanding_cmds[cnt] != NULL; cnt++);
2787
2788 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
2789 status = SCSI_MLQUEUE_HOST_BUSY;
2790 dprintk(2, "qla1280_start_scsi: NO ROOM IN "
2791 "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
2792 goto out;
2793 }
2794
2795 ha->outstanding_cmds[cnt] = sp;
2796 ha->req_q_cnt -= req_cnt;
2797 CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
2798
2799 dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
2800 cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
2801 dprintk(2, " bus %i, target %i, lun %i\n",
2802 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2803 qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
2804
2805
2806
2807
2808 pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
2809
2810 pkt->entry_type = COMMAND_A64_TYPE;
2811 pkt->entry_count = (uint8_t) req_cnt;
2812 pkt->sys_define = (uint8_t) ha->req_ring_index;
2813 pkt->entry_status = 0;
2814 pkt->handle = cpu_to_le32(cnt);
2815
2816
2817 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
2818
2819
2820 pkt->timeout = cpu_to_le16(scsi_cmd_to_rq(cmd)->timeout / HZ);
2821
2822
2823 pkt->lun = SCSI_LUN_32(cmd);
2824 pkt->target = SCSI_BUS_32(cmd) ?
2825 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
2826
2827
2828 if (cmd->device->simple_tags)
2829 pkt->control_flags |= cpu_to_le16(BIT_3);
2830
2831
2832 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
2833 memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
2834
2835
2836
2837 dir = qla1280_data_direction(cmd);
2838 pkt->control_flags |= cpu_to_le16(dir);
2839
2840
2841 pkt->dseg_count = cpu_to_le16(seg_cnt);
2842
2843
2844
2845
2846 if (seg_cnt) {
2847 struct scatterlist *sg, *s;
2848 int remseg = seg_cnt;
2849
2850 sg = scsi_sglist(cmd);
2851
2852
2853 dword_ptr = (u32 *)&pkt->dseg_0_address;
2854
2855
2856 for_each_sg(sg, s, seg_cnt, cnt) {
2857 if (cnt == 2)
2858 break;
2859
2860 dma_handle = sg_dma_address(s);
2861 *dword_ptr++ =
2862 cpu_to_le32(lower_32_bits(dma_handle));
2863 *dword_ptr++ =
2864 cpu_to_le32(upper_32_bits(dma_handle));
2865 *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
2866 dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
2867 cpu_to_le32(upper_32_bits(dma_handle)),
2868 cpu_to_le32(lower_32_bits(dma_handle)),
2869 cpu_to_le32(sg_dma_len(sg_next(s))));
2870 remseg--;
2871 }
2872 dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
2873 "command packet data - b %i, t %i, l %i \n",
2874 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
2875 SCSI_LUN_32(cmd));
2876 qla1280_dump_buffer(5, (char *)pkt,
2877 REQUEST_ENTRY_SIZE);
2878
2879
2880
2881
2882 dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
2883 "remains\n", seg_cnt);
2884
2885 while (remseg > 0) {
2886
2887 sg = s;
2888
2889 ha->req_ring_index++;
2890 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
2891 ha->req_ring_index = 0;
2892 ha->request_ring_ptr =
2893 ha->request_ring;
2894 } else
2895 ha->request_ring_ptr++;
2896
2897 pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
2898
2899
2900 memset(pkt, 0, REQUEST_ENTRY_SIZE);
2901
2902
2903 ((struct cont_a64_entry *) pkt)->entry_type =
2904 CONTINUE_A64_TYPE;
2905 ((struct cont_a64_entry *) pkt)->entry_count = 1;
2906 ((struct cont_a64_entry *) pkt)->sys_define =
2907 (uint8_t)ha->req_ring_index;
2908
2909 dword_ptr =
2910 (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
2911
2912
2913 for_each_sg(sg, s, remseg, cnt) {
2914 if (cnt == 5)
2915 break;
2916 dma_handle = sg_dma_address(s);
2917 *dword_ptr++ =
2918 cpu_to_le32(lower_32_bits(dma_handle));
2919 *dword_ptr++ =
2920 cpu_to_le32(upper_32_bits(dma_handle));
2921 *dword_ptr++ =
2922 cpu_to_le32(sg_dma_len(s));
2923 dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
2924 cpu_to_le32(upper_32_bits(dma_handle)),
2925 cpu_to_le32(lower_32_bits(dma_handle)),
2926 cpu_to_le32(sg_dma_len(s)));
2927 }
2928 remseg -= cnt;
2929 dprintk(5, "qla1280_64bit_start_scsi: "
2930 "continuation packet data - b %i, t "
2931 "%i, l %i \n", SCSI_BUS_32(cmd),
2932 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2933 qla1280_dump_buffer(5, (char *)pkt,
2934 REQUEST_ENTRY_SIZE);
2935 }
2936 } else {
2937 dprintk(5, "qla1280_64bit_start_scsi: No data, command "
2938 "packet data - b %i, t %i, l %i \n",
2939 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
2940 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
2941 }
2942
2943 ha->req_ring_index++;
2944 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
2945 ha->req_ring_index = 0;
2946 ha->request_ring_ptr = ha->request_ring;
2947 } else
2948 ha->request_ring_ptr++;
2949
2950
2951 dprintk(2,
2952 "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
2953 sp->flags |= SRB_SENT;
2954 ha->actthreads++;
2955 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
2956
2957 out:
2958 if (status)
2959 dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
2960 else
2961 dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
2962
2963 return status;
2964 }
2965 #else
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986 static int
2987 qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
2988 {
2989 struct device_reg __iomem *reg = ha->iobase;
2990 struct scsi_cmnd *cmd = sp->cmd;
2991 struct cmd_entry *pkt;
2992 __le32 *dword_ptr;
2993 int status = 0;
2994 int cnt;
2995 int req_cnt;
2996 int seg_cnt;
2997 u8 dir;
2998
2999 ENTER("qla1280_32bit_start_scsi");
3000
3001 dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
3002 cmd->cmnd[0]);
3003
3004
3005 req_cnt = 1;
3006 seg_cnt = scsi_dma_map(cmd);
3007 if (seg_cnt) {
3008
3009
3010
3011
3012 if (seg_cnt > 4) {
3013 req_cnt += (seg_cnt - 4) / 7;
3014 if ((seg_cnt - 4) % 7)
3015 req_cnt++;
3016 }
3017 dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
3018 cmd, seg_cnt, req_cnt);
3019 } else if (seg_cnt < 0) {
3020 status = 1;
3021 goto out;
3022 }
3023
3024 if ((req_cnt + 2) >= ha->req_q_cnt) {
3025
3026 cnt = RD_REG_WORD(®->mailbox4);
3027 if (ha->req_ring_index < cnt)
3028 ha->req_q_cnt = cnt - ha->req_ring_index;
3029 else
3030 ha->req_q_cnt =
3031 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3032 }
3033
3034 dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
3035 ha->req_q_cnt, seg_cnt);
3036
3037 if ((req_cnt + 2) >= ha->req_q_cnt) {
3038 status = SCSI_MLQUEUE_HOST_BUSY;
3039 dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
3040 "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
3041 ha->req_q_cnt, req_cnt);
3042 goto out;
3043 }
3044
3045
3046 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
3047 ha->outstanding_cmds[cnt]; cnt++);
3048
3049 if (cnt >= MAX_OUTSTANDING_COMMANDS) {
3050 status = SCSI_MLQUEUE_HOST_BUSY;
3051 dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
3052 "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
3053 goto out;
3054 }
3055
3056 CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
3057 ha->outstanding_cmds[cnt] = sp;
3058 ha->req_q_cnt -= req_cnt;
3059
3060
3061
3062
3063 pkt = (struct cmd_entry *) ha->request_ring_ptr;
3064
3065 pkt->entry_type = COMMAND_TYPE;
3066 pkt->entry_count = (uint8_t) req_cnt;
3067 pkt->sys_define = (uint8_t) ha->req_ring_index;
3068 pkt->entry_status = 0;
3069 pkt->handle = cpu_to_le32(cnt);
3070
3071
3072 memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
3073
3074
3075 pkt->timeout = cpu_to_le16(scsi_cmd_to_rq(cmd)->timeout / HZ);
3076
3077
3078 pkt->lun = SCSI_LUN_32(cmd);
3079 pkt->target = SCSI_BUS_32(cmd) ?
3080 (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
3081
3082
3083 if (cmd->device->simple_tags)
3084 pkt->control_flags |= cpu_to_le16(BIT_3);
3085
3086
3087 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3088 memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
3089
3090
3091
3092 dir = qla1280_data_direction(cmd);
3093 pkt->control_flags |= cpu_to_le16(dir);
3094
3095
3096 pkt->dseg_count = cpu_to_le16(seg_cnt);
3097
3098
3099
3100
3101 if (seg_cnt) {
3102 struct scatterlist *sg, *s;
3103 int remseg = seg_cnt;
3104
3105 sg = scsi_sglist(cmd);
3106
3107
3108 dword_ptr = &pkt->dseg_0_address;
3109
3110 dprintk(3, "Building S/G data segments..\n");
3111 qla1280_dump_buffer(1, (char *)sg, 4 * 16);
3112
3113
3114 for_each_sg(sg, s, seg_cnt, cnt) {
3115 if (cnt == 4)
3116 break;
3117 *dword_ptr++ =
3118 cpu_to_le32(lower_32_bits(sg_dma_address(s)));
3119 *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
3120 dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
3121 (lower_32_bits(sg_dma_address(s))),
3122 (sg_dma_len(s)));
3123 remseg--;
3124 }
3125
3126
3127
3128 dprintk(3, "S/G Building Continuation"
3129 "...seg_cnt=0x%x remains\n", seg_cnt);
3130 while (remseg > 0) {
3131
3132 sg = s;
3133
3134 ha->req_ring_index++;
3135 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3136 ha->req_ring_index = 0;
3137 ha->request_ring_ptr =
3138 ha->request_ring;
3139 } else
3140 ha->request_ring_ptr++;
3141
3142 pkt = (struct cmd_entry *)ha->request_ring_ptr;
3143
3144
3145 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3146
3147
3148 ((struct cont_entry *) pkt)->
3149 entry_type = CONTINUE_TYPE;
3150 ((struct cont_entry *) pkt)->entry_count = 1;
3151
3152 ((struct cont_entry *) pkt)->sys_define =
3153 (uint8_t) ha->req_ring_index;
3154
3155
3156 dword_ptr =
3157 &((struct cont_entry *) pkt)->dseg_0_address;
3158
3159
3160 for_each_sg(sg, s, remseg, cnt) {
3161 if (cnt == 7)
3162 break;
3163 *dword_ptr++ =
3164 cpu_to_le32(lower_32_bits(sg_dma_address(s)));
3165 *dword_ptr++ =
3166 cpu_to_le32(sg_dma_len(s));
3167 dprintk(1,
3168 "S/G Segment Cont. phys_addr=0x%x, "
3169 "len=0x%x\n",
3170 cpu_to_le32(lower_32_bits(sg_dma_address(s))),
3171 cpu_to_le32(sg_dma_len(s)));
3172 }
3173 remseg -= cnt;
3174 dprintk(5, "qla1280_32bit_start_scsi: "
3175 "continuation packet data - "
3176 "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
3177 SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
3178 qla1280_dump_buffer(5, (char *)pkt,
3179 REQUEST_ENTRY_SIZE);
3180 }
3181 } else {
3182 dprintk(5, "qla1280_32bit_start_scsi: No data, command "
3183 "packet data - \n");
3184 qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
3185 }
3186 dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
3187 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3188 REQUEST_ENTRY_SIZE);
3189
3190
3191 ha->req_ring_index++;
3192 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3193 ha->req_ring_index = 0;
3194 ha->request_ring_ptr = ha->request_ring;
3195 } else
3196 ha->request_ring_ptr++;
3197
3198
3199 dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
3200 "for pending command\n");
3201 sp->flags |= SRB_SENT;
3202 ha->actthreads++;
3203 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3204
3205 out:
3206 if (status)
3207 dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
3208
3209 LEAVE("qla1280_32bit_start_scsi");
3210
3211 return status;
3212 }
3213 #endif
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226 static request_t *
3227 qla1280_req_pkt(struct scsi_qla_host *ha)
3228 {
3229 struct device_reg __iomem *reg = ha->iobase;
3230 request_t *pkt = NULL;
3231 int cnt;
3232 uint32_t timer;
3233
3234 ENTER("qla1280_req_pkt");
3235
3236
3237
3238
3239
3240 for (timer = 15000000; timer; timer--) {
3241 if (ha->req_q_cnt > 0) {
3242
3243 cnt = RD_REG_WORD(®->mailbox4);
3244 if (ha->req_ring_index < cnt)
3245 ha->req_q_cnt = cnt - ha->req_ring_index;
3246 else
3247 ha->req_q_cnt =
3248 REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
3249 }
3250
3251
3252 if (ha->req_q_cnt > 0) {
3253 ha->req_q_cnt--;
3254 pkt = ha->request_ring_ptr;
3255
3256
3257 memset(pkt, 0, REQUEST_ENTRY_SIZE);
3258
3259
3260
3261
3262
3263
3264 pkt->sys_define = (uint8_t) ha->req_ring_index;
3265
3266
3267 pkt->entry_count = 1;
3268
3269 break;
3270 }
3271
3272 udelay(2);
3273
3274
3275 qla1280_poll(ha);
3276 }
3277
3278 if (!pkt)
3279 dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
3280 else
3281 dprintk(3, "qla1280_req_pkt: exiting normally\n");
3282
3283 return pkt;
3284 }
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294 static void
3295 qla1280_isp_cmd(struct scsi_qla_host *ha)
3296 {
3297 struct device_reg __iomem *reg = ha->iobase;
3298
3299 ENTER("qla1280_isp_cmd");
3300
3301 dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
3302 qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
3303 REQUEST_ENTRY_SIZE);
3304
3305
3306 ha->req_ring_index++;
3307 if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
3308 ha->req_ring_index = 0;
3309 ha->request_ring_ptr = ha->request_ring;
3310 } else
3311 ha->request_ring_ptr++;
3312
3313
3314
3315
3316 WRT_REG_WORD(®->mailbox4, ha->req_ring_index);
3317
3318 LEAVE("qla1280_isp_cmd");
3319 }
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333 static void
3334 qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
3335 {
3336 struct device_reg __iomem *reg = ha->iobase;
3337 struct response *pkt;
3338 struct srb *sp = NULL;
3339 uint16_t mailbox[MAILBOX_REGISTER_COUNT];
3340 uint16_t *wptr;
3341 uint32_t index;
3342 u16 istatus;
3343
3344 ENTER("qla1280_isr");
3345
3346 istatus = RD_REG_WORD(®->istatus);
3347 if (!(istatus & (RISC_INT | PCI_INT)))
3348 return;
3349
3350
3351 mailbox[5] = RD_REG_WORD(®->mailbox5);
3352
3353
3354
3355 mailbox[0] = RD_REG_WORD_dmasync(®->semaphore);
3356
3357 if (mailbox[0] & BIT_0) {
3358
3359
3360
3361 wptr = &mailbox[0];
3362 *wptr++ = RD_REG_WORD(®->mailbox0);
3363 *wptr++ = RD_REG_WORD(®->mailbox1);
3364 *wptr = RD_REG_WORD(®->mailbox2);
3365 if (mailbox[0] != MBA_SCSI_COMPLETION) {
3366 wptr++;
3367 *wptr++ = RD_REG_WORD(®->mailbox3);
3368 *wptr++ = RD_REG_WORD(®->mailbox4);
3369 wptr++;
3370 *wptr++ = RD_REG_WORD(®->mailbox6);
3371 *wptr = RD_REG_WORD(®->mailbox7);
3372 }
3373
3374
3375
3376 WRT_REG_WORD(®->semaphore, 0);
3377 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3378
3379 dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
3380 mailbox[0]);
3381
3382
3383 switch (mailbox[0]) {
3384 case MBA_SCSI_COMPLETION:
3385 dprintk(5, "qla1280_isr: mailbox SCSI response "
3386 "completion\n");
3387
3388 if (ha->flags.online) {
3389
3390 index = mailbox[2] << 16 | mailbox[1];
3391
3392
3393 if (index < MAX_OUTSTANDING_COMMANDS)
3394 sp = ha->outstanding_cmds[index];
3395 else
3396 sp = NULL;
3397
3398 if (sp) {
3399
3400 ha->outstanding_cmds[index] = NULL;
3401
3402
3403 CMD_RESULT(sp->cmd) = 0;
3404 CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
3405
3406
3407 list_add_tail(&sp->list, done_q);
3408 } else {
3409
3410
3411
3412 printk(KERN_WARNING
3413 "qla1280: ISP invalid handle\n");
3414 }
3415 }
3416 break;
3417
3418 case MBA_BUS_RESET:
3419 ha->flags.reset_marker = 1;
3420 index = mailbox[6] & BIT_0;
3421 ha->bus_settings[index].reset_marker = 1;
3422
3423 printk(KERN_DEBUG "qla1280_isr(): index %i "
3424 "asynchronous BUS_RESET\n", index);
3425 break;
3426
3427 case MBA_SYSTEM_ERR:
3428 printk(KERN_WARNING
3429 "qla1280: ISP System Error - mbx1=%xh, mbx2="
3430 "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
3431 mailbox[3]);
3432 break;
3433
3434 case MBA_REQ_TRANSFER_ERR:
3435 printk(KERN_WARNING
3436 "qla1280: ISP Request Transfer Error\n");
3437 break;
3438
3439 case MBA_RSP_TRANSFER_ERR:
3440 printk(KERN_WARNING
3441 "qla1280: ISP Response Transfer Error\n");
3442 break;
3443
3444 case MBA_WAKEUP_THRES:
3445 dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
3446 break;
3447
3448 case MBA_TIMEOUT_RESET:
3449 dprintk(2,
3450 "qla1280_isr: asynchronous TIMEOUT_RESET\n");
3451 break;
3452
3453 case MBA_DEVICE_RESET:
3454 printk(KERN_INFO "qla1280_isr(): asynchronous "
3455 "BUS_DEVICE_RESET\n");
3456
3457 ha->flags.reset_marker = 1;
3458 index = mailbox[6] & BIT_0;
3459 ha->bus_settings[index].reset_marker = 1;
3460 break;
3461
3462 case MBA_BUS_MODE_CHANGE:
3463 dprintk(2,
3464 "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
3465 break;
3466
3467 default:
3468
3469 if (mailbox[0] < MBA_ASYNC_EVENT) {
3470 wptr = &mailbox[0];
3471 memcpy((uint16_t *) ha->mailbox_out, wptr,
3472 MAILBOX_REGISTER_COUNT *
3473 sizeof(uint16_t));
3474
3475 if(ha->mailbox_wait != NULL)
3476 complete(ha->mailbox_wait);
3477 }
3478 break;
3479 }
3480 } else {
3481 WRT_REG_WORD(®->host_cmd, HC_CLR_RISC_INT);
3482 }
3483
3484
3485
3486
3487
3488 if (!(ha->flags.online && !ha->mailbox_wait)) {
3489 dprintk(2, "qla1280_isr: Response pointer Error\n");
3490 goto out;
3491 }
3492
3493 if (mailbox[5] >= RESPONSE_ENTRY_CNT)
3494 goto out;
3495
3496 while (ha->rsp_ring_index != mailbox[5]) {
3497 pkt = ha->response_ring_ptr;
3498
3499 dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
3500 " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
3501 dprintk(5,"qla1280_isr: response packet data\n");
3502 qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
3503
3504 if (pkt->entry_type == STATUS_TYPE) {
3505 if ((le16_to_cpu(pkt->scsi_status) & 0xff)
3506 || pkt->comp_status || pkt->entry_status) {
3507 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3508 "0x%x mailbox[5] = 0x%x, comp_status "
3509 "= 0x%x, scsi_status = 0x%x\n",
3510 ha->rsp_ring_index, mailbox[5],
3511 le16_to_cpu(pkt->comp_status),
3512 le16_to_cpu(pkt->scsi_status));
3513 }
3514 } else {
3515 dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
3516 "0x%x, mailbox[5] = 0x%x\n",
3517 ha->rsp_ring_index, mailbox[5]);
3518 dprintk(2, "qla1280_isr: response packet data\n");
3519 qla1280_dump_buffer(2, (char *)pkt,
3520 RESPONSE_ENTRY_SIZE);
3521 }
3522
3523 if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
3524 dprintk(2, "status: Cmd %p, handle %i\n",
3525 ha->outstanding_cmds[pkt->handle]->cmd,
3526 pkt->handle);
3527 if (pkt->entry_type == STATUS_TYPE)
3528 qla1280_status_entry(ha, pkt, done_q);
3529 else
3530 qla1280_error_entry(ha, pkt, done_q);
3531
3532 ha->rsp_ring_index++;
3533 if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
3534 ha->rsp_ring_index = 0;
3535 ha->response_ring_ptr = ha->response_ring;
3536 } else
3537 ha->response_ring_ptr++;
3538 WRT_REG_WORD(®->mailbox5, ha->rsp_ring_index);
3539 }
3540 }
3541
3542 out:
3543 LEAVE("qla1280_isr");
3544 }
3545
3546
3547
3548
3549
3550
3551
3552
3553 static void
3554 qla1280_rst_aen(struct scsi_qla_host *ha)
3555 {
3556 uint8_t bus;
3557
3558 ENTER("qla1280_rst_aen");
3559
3560 if (ha->flags.online && !ha->flags.reset_active &&
3561 !ha->flags.abort_isp_active) {
3562 ha->flags.reset_active = 1;
3563 while (ha->flags.reset_marker) {
3564
3565 ha->flags.reset_marker = 0;
3566 for (bus = 0; bus < ha->ports &&
3567 !ha->flags.reset_marker; bus++) {
3568 if (ha->bus_settings[bus].reset_marker) {
3569 ha->bus_settings[bus].reset_marker = 0;
3570 qla1280_marker(ha, bus, 0, 0,
3571 MK_SYNC_ALL);
3572 }
3573 }
3574 }
3575 }
3576
3577 LEAVE("qla1280_rst_aen");
3578 }
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590 static void
3591 qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
3592 struct list_head *done_q)
3593 {
3594 int sense_sz;
3595 struct srb *sp;
3596 struct scsi_cmnd *cmd;
3597 uint32_t handle = le32_to_cpu(pkt->handle);
3598 uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
3599 uint16_t comp_status = le16_to_cpu(pkt->comp_status);
3600
3601 ENTER("qla1280_status_entry");
3602
3603
3604 if (handle < MAX_OUTSTANDING_COMMANDS)
3605 sp = ha->outstanding_cmds[handle];
3606 else
3607 sp = NULL;
3608
3609 if (!sp) {
3610 printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
3611 goto out;
3612 }
3613
3614
3615 ha->outstanding_cmds[handle] = NULL;
3616
3617 cmd = sp->cmd;
3618
3619 if (comp_status || scsi_status) {
3620 dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
3621 "0x%x, handle = 0x%x\n", comp_status,
3622 scsi_status, handle);
3623 }
3624
3625
3626 if ((scsi_status & 0xFF) == SAM_STAT_TASK_SET_FULL ||
3627 (scsi_status & 0xFF) == SAM_STAT_BUSY) {
3628 CMD_RESULT(cmd) = scsi_status & 0xff;
3629 } else {
3630
3631
3632 CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
3633
3634 if (scsi_status & SAM_STAT_CHECK_CONDITION) {
3635 if (comp_status != CS_ARS_FAILED) {
3636 uint16_t req_sense_length =
3637 le16_to_cpu(pkt->req_sense_length);
3638 if (req_sense_length < CMD_SNSLEN(cmd))
3639 sense_sz = req_sense_length;
3640 else
3641
3642
3643
3644
3645
3646 sense_sz = CMD_SNSLEN(cmd) - 1;
3647
3648 memcpy(cmd->sense_buffer,
3649 &pkt->req_sense_data, sense_sz);
3650 } else
3651 sense_sz = 0;
3652 memset(cmd->sense_buffer + sense_sz, 0,
3653 SCSI_SENSE_BUFFERSIZE - sense_sz);
3654
3655 dprintk(2, "qla1280_status_entry: Check "
3656 "condition Sense data, b %i, t %i, "
3657 "l %i\n", SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
3658 SCSI_LUN_32(cmd));
3659 if (sense_sz)
3660 qla1280_dump_buffer(2,
3661 (char *)cmd->sense_buffer,
3662 sense_sz);
3663 }
3664 }
3665
3666 CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
3667
3668
3669 list_add_tail(&sp->list, done_q);
3670 out:
3671 LEAVE("qla1280_status_entry");
3672 }
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683 static void
3684 qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
3685 struct list_head *done_q)
3686 {
3687 struct srb *sp;
3688 uint32_t handle = le32_to_cpu(pkt->handle);
3689
3690 ENTER("qla1280_error_entry");
3691
3692 if (pkt->entry_status & BIT_3)
3693 dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
3694 else if (pkt->entry_status & BIT_2)
3695 dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
3696 else if (pkt->entry_status & BIT_1)
3697 dprintk(2, "qla1280_error_entry: FULL flag error\n");
3698 else
3699 dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
3700
3701
3702 if (handle < MAX_OUTSTANDING_COMMANDS)
3703 sp = ha->outstanding_cmds[handle];
3704 else
3705 sp = NULL;
3706
3707 if (sp) {
3708
3709 ha->outstanding_cmds[handle] = NULL;
3710
3711
3712 if (pkt->entry_status & (BIT_3 + BIT_2)) {
3713
3714
3715 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
3716 } else if (pkt->entry_status & BIT_1) {
3717 CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
3718 } else {
3719
3720 CMD_RESULT(sp->cmd) = DID_ERROR << 16;
3721 }
3722
3723 CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
3724
3725
3726 list_add_tail(&sp->list, done_q);
3727 }
3728 #ifdef QLA_64BIT_PTR
3729 else if (pkt->entry_type == COMMAND_A64_TYPE) {
3730 printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
3731 }
3732 #endif
3733
3734 LEAVE("qla1280_error_entry");
3735 }
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747 static int
3748 qla1280_abort_isp(struct scsi_qla_host *ha)
3749 {
3750 struct device_reg __iomem *reg = ha->iobase;
3751 struct srb *sp;
3752 int status = 0;
3753 int cnt;
3754 int bus;
3755
3756 ENTER("qla1280_abort_isp");
3757
3758 if (ha->flags.abort_isp_active || !ha->flags.online)
3759 goto out;
3760
3761 ha->flags.abort_isp_active = 1;
3762
3763
3764 qla1280_disable_intrs(ha);
3765 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
3766 RD_REG_WORD(®->id_l);
3767
3768 printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
3769 ha->host_no);
3770
3771 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3772 struct scsi_cmnd *cmd;
3773 sp = ha->outstanding_cmds[cnt];
3774 if (sp) {
3775 cmd = sp->cmd;
3776 CMD_RESULT(cmd) = DID_RESET << 16;
3777 CMD_HANDLE(cmd) = COMPLETED_HANDLE;
3778 ha->outstanding_cmds[cnt] = NULL;
3779 list_add_tail(&sp->list, &ha->done_q);
3780 }
3781 }
3782
3783 qla1280_done(ha);
3784
3785 status = qla1280_load_firmware(ha);
3786 if (status)
3787 goto out;
3788
3789
3790 qla1280_nvram_config (ha);
3791
3792 status = qla1280_init_rings(ha);
3793 if (status)
3794 goto out;
3795
3796
3797 for (bus = 0; bus < ha->ports; bus++)
3798 qla1280_bus_reset(ha, bus);
3799
3800 ha->flags.abort_isp_active = 0;
3801 out:
3802 if (status) {
3803 printk(KERN_WARNING
3804 "qla1280: ISP error recovery failed, board disabled");
3805 qla1280_reset_adapter(ha);
3806 dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
3807 }
3808
3809 LEAVE("qla1280_abort_isp");
3810 return status;
3811 }
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824 static u16
3825 qla1280_debounce_register(volatile u16 __iomem * addr)
3826 {
3827 volatile u16 ret;
3828 volatile u16 ret2;
3829
3830 ret = RD_REG_WORD(addr);
3831 ret2 = RD_REG_WORD(addr);
3832
3833 if (ret == ret2)
3834 return ret;
3835
3836 do {
3837 cpu_relax();
3838 ret = RD_REG_WORD(addr);
3839 ret2 = RD_REG_WORD(addr);
3840 } while (ret != ret2);
3841
3842 return ret;
3843 }
3844
3845
3846
3847
3848
3849
3850
3851 #define SET_SXP_BANK 0x0100
3852 #define SCSI_PHASE_INVALID 0x87FF
3853 static int
3854 qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
3855 {
3856 uint16_t config_reg, scsi_control;
3857 struct device_reg __iomem *reg = ha->iobase;
3858
3859 if (ha->bus_settings[bus].scsi_bus_dead) {
3860 WRT_REG_WORD(®->host_cmd, HC_PAUSE_RISC);
3861 config_reg = RD_REG_WORD(®->cfg_1);
3862 WRT_REG_WORD(®->cfg_1, SET_SXP_BANK);
3863 scsi_control = RD_REG_WORD(®->scsiControlPins);
3864 WRT_REG_WORD(®->cfg_1, config_reg);
3865 WRT_REG_WORD(®->host_cmd, HC_RELEASE_RISC);
3866
3867 if (scsi_control == SCSI_PHASE_INVALID) {
3868 ha->bus_settings[bus].scsi_bus_dead = 1;
3869 return 1;
3870 } else {
3871 ha->bus_settings[bus].scsi_bus_dead = 0;
3872 ha->bus_settings[bus].failed_reset_count = 0;
3873 }
3874 }
3875 return 0;
3876 }
3877
3878 static void
3879 qla1280_get_target_parameters(struct scsi_qla_host *ha,
3880 struct scsi_device *device)
3881 {
3882 uint16_t mb[MAILBOX_REGISTER_COUNT];
3883 int bus, target, lun;
3884
3885 bus = device->channel;
3886 target = device->id;
3887 lun = device->lun;
3888
3889
3890 mb[0] = MBC_GET_TARGET_PARAMETERS;
3891 mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
3892 mb[1] <<= 8;
3893 qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
3894 &mb[0]);
3895
3896 printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
3897
3898 if (mb[3] != 0) {
3899 printk(KERN_CONT " Sync: period %d, offset %d",
3900 (mb[3] & 0xff), (mb[3] >> 8));
3901 if (mb[2] & BIT_13)
3902 printk(KERN_CONT ", Wide");
3903 if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
3904 printk(KERN_CONT ", DT");
3905 } else
3906 printk(KERN_CONT " Async");
3907
3908 if (device->simple_tags)
3909 printk(KERN_CONT ", Tagged queuing: depth %d", device->queue_depth);
3910 printk(KERN_CONT "\n");
3911 }
3912
3913
3914 #if DEBUG_QLA1280
3915 static void
3916 __qla1280_dump_buffer(char *b, int size)
3917 {
3918 int cnt;
3919 u8 c;
3920
3921 printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
3922 "Bh Ch Dh Eh Fh\n");
3923 printk(KERN_DEBUG "---------------------------------------------"
3924 "------------------\n");
3925
3926 for (cnt = 0; cnt < size;) {
3927 c = *b++;
3928
3929 printk("0x%02x", c);
3930 cnt++;
3931 if (!(cnt % 16))
3932 printk("\n");
3933 else
3934 printk(" ");
3935 }
3936 if (cnt % 16)
3937 printk("\n");
3938 }
3939
3940
3941
3942
3943
3944 static void
3945 __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
3946 {
3947 struct scsi_qla_host *ha;
3948 struct Scsi_Host *host = CMD_HOST(cmd);
3949 struct srb *sp;
3950
3951
3952 int i;
3953 ha = (struct scsi_qla_host *)host->hostdata;
3954
3955 sp = scsi_cmd_priv(cmd);
3956 printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
3957 printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
3958 SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
3959 CMD_CDBLEN(cmd));
3960 printk(" CDB = ");
3961 for (i = 0; i < cmd->cmd_len; i++) {
3962 printk("0x%02x ", cmd->cmnd[i]);
3963 }
3964 printk(" seg_cnt =%d\n", scsi_sg_count(cmd));
3965 printk(" request buffer=0x%p, request buffer len=0x%x\n",
3966 scsi_sglist(cmd), scsi_bufflen(cmd));
3967
3968
3969
3970
3971
3972
3973 printk(" tag=%d, transfersize=0x%x \n",
3974 scsi_cmd_to_rq(cmd)->tag, cmd->transfersize);
3975 printk(" underflow size = 0x%x, direction=0x%x\n",
3976 cmd->underflow, cmd->sc_data_direction);
3977 }
3978
3979
3980
3981
3982
3983 static void
3984 ql1280_dump_device(struct scsi_qla_host *ha)
3985 {
3986
3987 struct scsi_cmnd *cp;
3988 struct srb *sp;
3989 int i;
3990
3991 printk(KERN_DEBUG "Outstanding Commands on controller:\n");
3992
3993 for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
3994 if ((sp = ha->outstanding_cmds[i]) == NULL)
3995 continue;
3996 if ((cp = sp->cmd) == NULL)
3997 continue;
3998 qla1280_print_scsi_cmd(1, cp);
3999 }
4000 }
4001 #endif
4002
4003
4004 enum tokens {
4005 TOKEN_NVRAM,
4006 TOKEN_SYNC,
4007 TOKEN_WIDE,
4008 TOKEN_PPR,
4009 TOKEN_VERBOSE,
4010 TOKEN_DEBUG,
4011 };
4012
4013 struct setup_tokens {
4014 char *token;
4015 int val;
4016 };
4017
4018 static struct setup_tokens setup_token[] __initdata =
4019 {
4020 { "nvram", TOKEN_NVRAM },
4021 { "sync", TOKEN_SYNC },
4022 { "wide", TOKEN_WIDE },
4023 { "ppr", TOKEN_PPR },
4024 { "verbose", TOKEN_VERBOSE },
4025 { "debug", TOKEN_DEBUG },
4026 };
4027
4028
4029
4030
4031
4032
4033
4034
4035 static int __init
4036 qla1280_setup(char *s)
4037 {
4038 char *cp, *ptr;
4039 unsigned long val;
4040
4041 cp = s;
4042
4043 while (cp && (ptr = strchr(cp, ':'))) {
4044 ptr++;
4045 if (!strcmp(ptr, "yes")) {
4046 val = 0x10000;
4047 ptr += 3;
4048 } else if (!strcmp(ptr, "no")) {
4049 val = 0;
4050 ptr += 2;
4051 } else
4052 val = simple_strtoul(ptr, &ptr, 0);
4053
4054 switch (qla1280_get_token(cp)) {
4055 case TOKEN_NVRAM:
4056 if (!val)
4057 driver_setup.no_nvram = 1;
4058 break;
4059 case TOKEN_SYNC:
4060 if (!val)
4061 driver_setup.no_sync = 1;
4062 else if (val != 0x10000)
4063 driver_setup.sync_mask = val;
4064 break;
4065 case TOKEN_WIDE:
4066 if (!val)
4067 driver_setup.no_wide = 1;
4068 else if (val != 0x10000)
4069 driver_setup.wide_mask = val;
4070 break;
4071 case TOKEN_PPR:
4072 if (!val)
4073 driver_setup.no_ppr = 1;
4074 else if (val != 0x10000)
4075 driver_setup.ppr_mask = val;
4076 break;
4077 case TOKEN_VERBOSE:
4078 qla1280_verbose = val;
4079 break;
4080 default:
4081 printk(KERN_INFO "qla1280: unknown boot option %s\n",
4082 cp);
4083 }
4084
4085 cp = strchr(ptr, ';');
4086 if (cp)
4087 cp++;
4088 else {
4089 break;
4090 }
4091 }
4092 return 1;
4093 }
4094
4095
4096 static int __init
4097 qla1280_get_token(char *str)
4098 {
4099 char *sep;
4100 long ret = -1;
4101 int i;
4102
4103 sep = strchr(str, ':');
4104
4105 if (sep) {
4106 for (i = 0; i < ARRAY_SIZE(setup_token); i++) {
4107 if (!strncmp(setup_token[i].token, str, (sep - str))) {
4108 ret = setup_token[i].val;
4109 break;
4110 }
4111 }
4112 }
4113
4114 return ret;
4115 }
4116
4117
4118 static struct scsi_host_template qla1280_driver_template = {
4119 .module = THIS_MODULE,
4120 .proc_name = "qla1280",
4121 .name = "Qlogic ISP 1280/12160",
4122 .info = qla1280_info,
4123 .slave_configure = qla1280_slave_configure,
4124 .queuecommand = qla1280_queuecommand,
4125 .eh_abort_handler = qla1280_eh_abort,
4126 .eh_device_reset_handler= qla1280_eh_device_reset,
4127 .eh_bus_reset_handler = qla1280_eh_bus_reset,
4128 .eh_host_reset_handler = qla1280_eh_adapter_reset,
4129 .bios_param = qla1280_biosparam,
4130 .can_queue = MAX_OUTSTANDING_COMMANDS,
4131 .this_id = -1,
4132 .sg_tablesize = SG_ALL,
4133 .cmd_size = sizeof(struct srb),
4134 };
4135
4136
4137 static int
4138 qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4139 {
4140 int devnum = id->driver_data;
4141 struct qla_boards *bdp = &ql1280_board_tbl[devnum];
4142 struct Scsi_Host *host;
4143 struct scsi_qla_host *ha;
4144 int error = -ENODEV;
4145
4146
4147 if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
4148 printk(KERN_INFO
4149 "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
4150 goto error;
4151 }
4152
4153 printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
4154 bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
4155
4156 if (pci_enable_device(pdev)) {
4157 printk(KERN_WARNING
4158 "qla1280: Failed to enabled pci device, aborting.\n");
4159 goto error;
4160 }
4161
4162 pci_set_master(pdev);
4163
4164 error = -ENOMEM;
4165 host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
4166 if (!host) {
4167 printk(KERN_WARNING
4168 "qla1280: Failed to register host, aborting.\n");
4169 goto error_disable_device;
4170 }
4171
4172 ha = (struct scsi_qla_host *)host->hostdata;
4173 memset(ha, 0, sizeof(struct scsi_qla_host));
4174
4175 ha->pdev = pdev;
4176 ha->devnum = devnum;
4177
4178 #ifdef QLA_64BIT_PTR
4179 if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
4180 if (dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32))) {
4181 printk(KERN_WARNING "scsi(%li): Unable to set a "
4182 "suitable DMA mask - aborting\n", ha->host_no);
4183 error = -ENODEV;
4184 goto error_put_host;
4185 }
4186 } else
4187 dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
4188 ha->host_no);
4189 #else
4190 if (dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32))) {
4191 printk(KERN_WARNING "scsi(%li): Unable to set a "
4192 "suitable DMA mask - aborting\n", ha->host_no);
4193 error = -ENODEV;
4194 goto error_put_host;
4195 }
4196 #endif
4197
4198 ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
4199 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4200 &ha->request_dma, GFP_KERNEL);
4201 if (!ha->request_ring) {
4202 printk(KERN_INFO "qla1280: Failed to get request memory\n");
4203 goto error_put_host;
4204 }
4205
4206 ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
4207 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4208 &ha->response_dma, GFP_KERNEL);
4209 if (!ha->response_ring) {
4210 printk(KERN_INFO "qla1280: Failed to get response memory\n");
4211 goto error_free_request_ring;
4212 }
4213
4214 ha->ports = bdp->numPorts;
4215
4216 ha->host = host;
4217 ha->host_no = host->host_no;
4218
4219 host->irq = pdev->irq;
4220 host->max_channel = bdp->numPorts - 1;
4221 host->max_lun = MAX_LUNS - 1;
4222 host->max_id = MAX_TARGETS;
4223 host->max_sectors = 1024;
4224 host->unique_id = host->host_no;
4225
4226 error = -ENODEV;
4227
4228 #if MEMORY_MAPPED_IO
4229 ha->mmpbase = pci_ioremap_bar(ha->pdev, 1);
4230 if (!ha->mmpbase) {
4231 printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
4232 goto error_free_response_ring;
4233 }
4234
4235 host->base = (unsigned long)ha->mmpbase;
4236 ha->iobase = (struct device_reg __iomem *)ha->mmpbase;
4237 #else
4238 host->io_port = pci_resource_start(ha->pdev, 0);
4239 if (!request_region(host->io_port, 0xff, "qla1280")) {
4240 printk(KERN_INFO "qla1280: Failed to reserve i/o region "
4241 "0x%04lx-0x%04lx - already in use\n",
4242 host->io_port, host->io_port + 0xff);
4243 goto error_free_response_ring;
4244 }
4245
4246 ha->iobase = (struct device_reg *)host->io_port;
4247 #endif
4248
4249 INIT_LIST_HEAD(&ha->done_q);
4250
4251
4252 qla1280_disable_intrs(ha);
4253
4254 if (request_irq(pdev->irq, qla1280_intr_handler, IRQF_SHARED,
4255 "qla1280", ha)) {
4256 printk("qla1280 : Failed to reserve interrupt %d already "
4257 "in use\n", pdev->irq);
4258 goto error_release_region;
4259 }
4260
4261
4262 if (qla1280_initialize_adapter(ha)) {
4263 printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
4264 goto error_free_irq;
4265 }
4266
4267
4268 host->this_id = ha->bus_settings[0].id;
4269
4270 pci_set_drvdata(pdev, host);
4271
4272 error = scsi_add_host(host, &pdev->dev);
4273 if (error)
4274 goto error_disable_adapter;
4275 scsi_scan_host(host);
4276
4277 return 0;
4278
4279 error_disable_adapter:
4280 qla1280_disable_intrs(ha);
4281 error_free_irq:
4282 free_irq(pdev->irq, ha);
4283 error_release_region:
4284 #if MEMORY_MAPPED_IO
4285 iounmap(ha->mmpbase);
4286 #else
4287 release_region(host->io_port, 0xff);
4288 #endif
4289 error_free_response_ring:
4290 dma_free_coherent(&ha->pdev->dev,
4291 ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
4292 ha->response_ring, ha->response_dma);
4293 error_free_request_ring:
4294 dma_free_coherent(&ha->pdev->dev,
4295 ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
4296 ha->request_ring, ha->request_dma);
4297 error_put_host:
4298 scsi_host_put(host);
4299 error_disable_device:
4300 pci_disable_device(pdev);
4301 error:
4302 return error;
4303 }
4304
4305
4306 static void
4307 qla1280_remove_one(struct pci_dev *pdev)
4308 {
4309 struct Scsi_Host *host = pci_get_drvdata(pdev);
4310 struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
4311
4312 scsi_remove_host(host);
4313
4314 qla1280_disable_intrs(ha);
4315
4316 free_irq(pdev->irq, ha);
4317
4318 #if MEMORY_MAPPED_IO
4319 iounmap(ha->mmpbase);
4320 #else
4321 release_region(host->io_port, 0xff);
4322 #endif
4323
4324 dma_free_coherent(&ha->pdev->dev,
4325 ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
4326 ha->request_ring, ha->request_dma);
4327 dma_free_coherent(&ha->pdev->dev,
4328 ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
4329 ha->response_ring, ha->response_dma);
4330
4331 pci_disable_device(pdev);
4332
4333 scsi_host_put(host);
4334 }
4335
4336 static struct pci_driver qla1280_pci_driver = {
4337 .name = "qla1280",
4338 .id_table = qla1280_pci_tbl,
4339 .probe = qla1280_probe_one,
4340 .remove = qla1280_remove_one,
4341 };
4342
4343 static int __init
4344 qla1280_init(void)
4345 {
4346 #ifdef MODULE
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359 if (qla1280)
4360 qla1280_setup(qla1280);
4361 #endif
4362
4363 return pci_register_driver(&qla1280_pci_driver);
4364 }
4365
4366 static void __exit
4367 qla1280_exit(void)
4368 {
4369 int i;
4370
4371 pci_unregister_driver(&qla1280_pci_driver);
4372
4373 for (i = 0; i < QL_NUM_FW_IMAGES; i++) {
4374 release_firmware(qla1280_fw_tbl[i].fw);
4375 qla1280_fw_tbl[i].fw = NULL;
4376 }
4377 }
4378
4379 module_init(qla1280_init);
4380 module_exit(qla1280_exit);
4381
4382 MODULE_AUTHOR("Qlogic & Jes Sorensen");
4383 MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
4384 MODULE_LICENSE("GPL");
4385 MODULE_FIRMWARE("qlogic/1040.bin");
4386 MODULE_FIRMWARE("qlogic/1280.bin");
4387 MODULE_FIRMWARE("qlogic/12160.bin");
4388 MODULE_VERSION(QLA1280_VERSION);