aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/gdth.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/gdth.c')
-rw-r--r--drivers/scsi/gdth.c312
1 files changed, 167 insertions, 145 deletions
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 05108ea1d833..9e4dd48899b6 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -444,12 +444,6 @@ static void gdth_copy_internal_data(int hanum,Scsi_Cmnd *scp,
444static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp); 444static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp);
445static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive); 445static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive);
446 446
447static int gdth_search_pci(gdth_pci_str *pcistr);
448static void gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
449 ushort vendor, ushort dev);
450static void gdth_sort_pci(gdth_pci_str *pcistr, int cnt);
451static int gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha);
452
453static void gdth_enable_int(int hanum); 447static void gdth_enable_int(int hanum);
454static int gdth_get_status(unchar *pIStatus,int irq); 448static int gdth_get_status(unchar *pIStatus,int irq);
455static int gdth_test_busy(int hanum); 449static int gdth_test_busy(int hanum);
@@ -478,6 +472,9 @@ static int gdth_isa_probe_one(struct scsi_host_template *, ulong32);
478#ifdef CONFIG_EISA 472#ifdef CONFIG_EISA
479static int gdth_eisa_probe_one(struct scsi_host_template *, ushort); 473static int gdth_eisa_probe_one(struct scsi_host_template *, ushort);
480#endif 474#endif
475#ifdef CONFIG_PCI
476static int gdth_pci_probe_one(struct scsi_host_template *, gdth_pci_str *, int);
477#endif
481 478
482#ifdef DEBUG_GDTH 479#ifdef DEBUG_GDTH
483static unchar DebugState = DEBUG_GDTH; 480static unchar DebugState = DEBUG_GDTH;
@@ -862,6 +859,10 @@ static int __init gdth_search_isa(ulong32 bios_adr)
862} 859}
863#endif /* CONFIG_ISA */ 860#endif /* CONFIG_ISA */
864 861
862#ifdef CONFIG_PCI
863static void gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
864 ushort vendor, ushort dev);
865
865static int __init gdth_search_pci(gdth_pci_str *pcistr) 866static int __init gdth_search_pci(gdth_pci_str *pcistr)
866{ 867{
867 ushort device, cnt; 868 ushort device, cnt;
@@ -940,7 +941,6 @@ static void __init gdth_search_dev(gdth_pci_str *pcistr, ushort *cnt,
940 } 941 }
941} 942}
942 943
943
944static void __init gdth_sort_pci(gdth_pci_str *pcistr, int cnt) 944static void __init gdth_sort_pci(gdth_pci_str *pcistr, int cnt)
945{ 945{
946 gdth_pci_str temp; 946 gdth_pci_str temp;
@@ -977,6 +977,7 @@ static void __init gdth_sort_pci(gdth_pci_str *pcistr, int cnt)
977 } 977 }
978 } while (changed); 978 } while (changed);
979} 979}
980#endif /* CONFIG_PCI */
980 981
981#ifdef CONFIG_EISA 982#ifdef CONFIG_EISA
982static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha) 983static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha)
@@ -1173,6 +1174,7 @@ static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
1173} 1174}
1174#endif /* CONFIG_ISA */ 1175#endif /* CONFIG_ISA */
1175 1176
1177#ifdef CONFIG_PCI
1176static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha) 1178static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
1177{ 1179{
1178 register gdt6_dpram_str __iomem *dp6_ptr; 1180 register gdt6_dpram_str __iomem *dp6_ptr;
@@ -1555,7 +1557,7 @@ static int __init gdth_init_pci(gdth_pci_str *pcistr,gdth_ha_str *ha)
1555 1557
1556 return 1; 1558 return 1;
1557} 1559}
1558 1560#endif /* CONFIG_PCI */
1559 1561
1560/* controller protocol functions */ 1562/* controller protocol functions */
1561 1563
@@ -4297,13 +4299,6 @@ static int __init gdth_detect(struct scsi_host_template *shtp)
4297static int __init gdth_detect(Scsi_Host_Template *shtp) 4299static int __init gdth_detect(Scsi_Host_Template *shtp)
4298#endif 4300#endif
4299{ 4301{
4300 struct Scsi_Host *shp;
4301 gdth_pci_str pcistr[MAXHA];
4302 gdth_ha_str *ha;
4303 int i,hanum,cnt,ctr,err;
4304 unchar b;
4305
4306
4307#ifdef DEBUG_GDTH 4302#ifdef DEBUG_GDTH
4308 printk("GDT: This driver contains debugging information !! Trace level = %d\n", 4303 printk("GDT: This driver contains debugging information !! Trace level = %d\n",
4309 DebugState); 4304 DebugState);
@@ -4329,7 +4324,7 @@ static int __init gdth_detect(Scsi_Host_Template *shtp)
4329 4324
4330 printk("GDT-HA: Storage RAID Controller Driver. Version: %s\n",GDTH_VERSION_STR); 4325 printk("GDT-HA: Storage RAID Controller Driver. Version: %s\n",GDTH_VERSION_STR);
4331 /* initializations */ 4326 /* initializations */
4332 gdth_polling = TRUE; b = 0; 4327 gdth_polling = TRUE;
4333 gdth_clear_events(); 4328 gdth_clear_events();
4334 4329
4335 /* As default we do not probe for EISA or ISA controllers */ 4330 /* As default we do not probe for EISA or ISA controllers */
@@ -4356,143 +4351,22 @@ static int __init gdth_detect(Scsi_Host_Template *shtp)
4356#endif 4351#endif
4357 } 4352 }
4358 4353
4354#ifdef CONFIG_PCI
4359 /* scanning for PCI controllers */ 4355 /* scanning for PCI controllers */
4356 {
4357 gdth_pci_str pcistr[MAXHA];
4358 int cnt,ctr;
4359
4360 cnt = gdth_search_pci(pcistr); 4360 cnt = gdth_search_pci(pcistr);
4361 printk("GDT-HA: Found %d PCI Storage RAID Controllers\n",cnt); 4361 printk("GDT-HA: Found %d PCI Storage RAID Controllers\n",cnt);
4362 gdth_sort_pci(pcistr,cnt); 4362 gdth_sort_pci(pcistr,cnt);
4363 for (ctr = 0; ctr < cnt; ++ctr) { 4363 for (ctr = 0; ctr < cnt; ++ctr) {
4364 dma_addr_t scratch_dma_handle;
4365 scratch_dma_handle = 0;
4366
4367 if (gdth_ctr_count >= MAXHA) 4364 if (gdth_ctr_count >= MAXHA)
4368 break; 4365 break;
4369 shp = scsi_register(shtp,sizeof(gdth_ext_str)); 4366 gdth_pci_probe_one(shtp, pcistr, ctr);
4370 if (shp == NULL)
4371 continue;
4372
4373 ha = HADATA(shp);
4374 if (!gdth_init_pci(&pcistr[ctr],ha)) {
4375 scsi_unregister(shp);
4376 continue;
4377 }
4378 /* controller found and initialized */
4379 printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
4380 pcistr[ctr].pdev->bus->number,
4381 PCI_SLOT(pcistr[ctr].pdev->devfn), ha->irq);
4382
4383 if (request_irq(ha->irq, gdth_interrupt,
4384 IRQF_DISABLED|IRQF_SHARED, "gdth", ha))
4385 {
4386 printk("GDT-PCI: Unable to allocate IRQ\n");
4387 scsi_unregister(shp);
4388 continue;
4389 }
4390 shp->unchecked_isa_dma = 0;
4391 shp->irq = ha->irq;
4392 shp->dma_channel = 0xff;
4393 hanum = gdth_ctr_count;
4394 gdth_ctr_tab[gdth_ctr_count++] = shp;
4395 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4396
4397 NUMDATA(shp)->hanum = (ushort)hanum;
4398 NUMDATA(shp)->busnum= 0;
4399
4400 ha->pccb = CMDDATA(shp);
4401 ha->ccb_phys = 0L;
4402
4403 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
4404 &scratch_dma_handle);
4405 ha->scratch_phys = scratch_dma_handle;
4406 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
4407 &scratch_dma_handle);
4408 ha->msg_phys = scratch_dma_handle;
4409#ifdef INT_COAL
4410 ha->coal_stat = (gdth_coal_status *)
4411 pci_alloc_consistent(ha->pdev, sizeof(gdth_coal_status) *
4412 MAXOFFSETS, &scratch_dma_handle);
4413 ha->coal_stat_phys = scratch_dma_handle;
4414#endif
4415 ha->scratch_busy = FALSE;
4416 ha->req_first = NULL;
4417 ha->tid_cnt = pcistr[ctr].pdev->device >= 0x200 ? MAXID : MAX_HDRIVES;
4418 if (max_ids > 0 && max_ids < ha->tid_cnt)
4419 ha->tid_cnt = max_ids;
4420 for (i=0; i<GDTH_MAXCMDS; ++i)
4421 ha->cmd_tab[i].cmnd = UNUSED_CMND;
4422 ha->scan_mode = rescan ? 0x10 : 0;
4423
4424 err = FALSE;
4425 if (ha->pscratch == NULL || ha->pmsg == NULL ||
4426 !gdth_search_drives(hanum)) {
4427 err = TRUE;
4428 } else {
4429 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
4430 hdr_channel = ha->bus_cnt;
4431 ha->virt_bus = hdr_channel;
4432
4433
4434#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
4435 scsi_set_pci_device(shp, pcistr[ctr].pdev);
4436#endif
4437 if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat &GDT_64BIT)||
4438 /* 64-bit DMA only supported from FW >= x.43 */
4439 (!ha->dma64_support)) {
4440 if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
4441 printk(KERN_WARNING "GDT-PCI %d: Unable to set 32-bit DMA\n", hanum);
4442 err = TRUE;
4443 }
4444 } else {
4445 shp->max_cmd_len = 16;
4446 if (!pci_set_dma_mask(pcistr[ctr].pdev, DMA_64BIT_MASK)) {
4447 printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum);
4448 } else if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
4449 printk(KERN_WARNING "GDT-PCI %d: Unable to set 64/32-bit DMA\n", hanum);
4450 err = TRUE;
4451 }
4452 }
4453 }
4454
4455 if (err) {
4456 printk("GDT-PCI %d: Error during device scan\n", hanum);
4457 --gdth_ctr_count;
4458 --gdth_ctr_vcount;
4459#ifdef INT_COAL
4460 if (ha->coal_stat)
4461 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
4462 MAXOFFSETS, ha->coal_stat,
4463 ha->coal_stat_phys);
4464#endif
4465 if (ha->pscratch)
4466 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
4467 ha->pscratch, ha->scratch_phys);
4468 if (ha->pmsg)
4469 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
4470 ha->pmsg, ha->msg_phys);
4471 free_irq(ha->irq,ha);
4472 scsi_unregister(shp);
4473 continue;
4474 }
4475
4476 shp->max_id = ha->tid_cnt;
4477 shp->max_lun = MAXLUN;
4478 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
4479 if (virt_ctr) {
4480 virt_ctr = 1;
4481 /* register addit. SCSI channels as virtual controllers */
4482 for (b = 1; b < ha->bus_cnt + 1; ++b) {
4483 shp = scsi_register(shtp,sizeof(gdth_num_str));
4484 shp->unchecked_isa_dma = 0;
4485 shp->irq = ha->irq;
4486 shp->dma_channel = 0xff;
4487 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
4488 NUMDATA(shp)->hanum = (ushort)hanum;
4489 NUMDATA(shp)->busnum = b;
4490 }
4491 }
4492
4493 spin_lock_init(&ha->smp_lock);
4494 gdth_enable_int(hanum);
4495 } 4367 }
4368 }
4369#endif /* CONFIG_PCI */
4496 4370
4497 TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count)); 4371 TRACE2(("gdth_detect() %d controller detected\n",gdth_ctr_count));
4498 if (gdth_ctr_count > 0) { 4372 if (gdth_ctr_count > 0) {
@@ -5735,6 +5609,154 @@ static int gdth_eisa_probe_one(struct scsi_host_template *shtp,
5735} 5609}
5736#endif /* CONFIG_EISA */ 5610#endif /* CONFIG_EISA */
5737 5611
5612#ifdef CONFIG_PCI
5613static int gdth_pci_probe_one(struct scsi_host_template *shtp,
5614 gdth_pci_str *pcistr, int ctr)
5615{
5616 struct Scsi_Host *shp;
5617 gdth_ha_str *ha;
5618 dma_addr_t scratch_dma_handle = 0;
5619 int error, hanum, i;
5620 u8 b;
5621
5622 shp = scsi_register(shtp,sizeof(gdth_ext_str));
5623 if (!shp)
5624 return -ENOMEM;
5625 ha = HADATA(shp);
5626
5627 error = -ENODEV;
5628 if (!gdth_init_pci(&pcistr[ctr],ha))
5629 goto out_host_put;
5630
5631 /* controller found and initialized */
5632 printk("Configuring GDT-PCI HA at %d/%d IRQ %u\n",
5633 pcistr[ctr].pdev->bus->number,
5634 PCI_SLOT(pcistr[ctr].pdev->devfn),
5635 ha->irq);
5636
5637 error = request_irq(ha->irq, gdth_interrupt,
5638 IRQF_DISABLED|IRQF_SHARED, "gdth", ha);
5639 if (error) {
5640 printk("GDT-PCI: Unable to allocate IRQ\n");
5641 goto out_host_put;
5642 }
5643
5644 shp->unchecked_isa_dma = 0;
5645 shp->irq = ha->irq;
5646 shp->dma_channel = 0xff;
5647 hanum = gdth_ctr_count;
5648 gdth_ctr_tab[gdth_ctr_count++] = shp;
5649 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
5650
5651 NUMDATA(shp)->hanum = (ushort)hanum;
5652 NUMDATA(shp)->busnum= 0;
5653
5654 ha->pccb = CMDDATA(shp);
5655 ha->ccb_phys = 0L;
5656
5657 error = -ENOMEM;
5658
5659 ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
5660 &scratch_dma_handle);
5661 if (!ha->pscratch)
5662 goto out_free_irq;
5663 ha->scratch_phys = scratch_dma_handle;
5664
5665 ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
5666 &scratch_dma_handle);
5667 if (!ha->pmsg)
5668 goto out_free_pscratch;
5669 ha->msg_phys = scratch_dma_handle;
5670
5671#ifdef INT_COAL
5672 ha->coal_stat = pci_alloc_consistent(ha->pdev,
5673 sizeof(gdth_coal_status) * MAXOFFSETS,
5674 &scratch_dma_handle);
5675 if (!ha->coal_stat)
5676 goto out_free_pmsg;
5677 ha->coal_stat_phys = scratch_dma_handle;
5678#endif
5679
5680 ha->scratch_busy = FALSE;
5681 ha->req_first = NULL;
5682 ha->tid_cnt = pcistr[ctr].pdev->device >= 0x200 ? MAXID : MAX_HDRIVES;
5683 if (max_ids > 0 && max_ids < ha->tid_cnt)
5684 ha->tid_cnt = max_ids;
5685 for (i = 0; i < GDTH_MAXCMDS; ++i)
5686 ha->cmd_tab[i].cmnd = UNUSED_CMND;
5687 ha->scan_mode = rescan ? 0x10 : 0;
5688
5689 error = -ENODEV;
5690 if (!gdth_search_drives(hanum)) {
5691 printk("GDT-PCI %d: Error during device scan\n", hanum);
5692 goto out_free_coal_stat;
5693 }
5694
5695 if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
5696 hdr_channel = ha->bus_cnt;
5697 ha->virt_bus = hdr_channel;
5698
5699 /* 64-bit DMA only supported from FW >= x.43 */
5700 if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) ||
5701 !ha->dma64_support) {
5702 if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
5703 printk(KERN_WARNING "GDT-PCI %d: "
5704 "Unable to set 32-bit DMA\n", hanum);
5705 goto out_free_coal_stat;
5706 }
5707 } else {
5708 shp->max_cmd_len = 16;
5709 if (!pci_set_dma_mask(pcistr[ctr].pdev, DMA_64BIT_MASK)) {
5710 printk("GDT-PCI %d: 64-bit DMA enabled\n", hanum);
5711 } else if (pci_set_dma_mask(pcistr[ctr].pdev, DMA_32BIT_MASK)) {
5712 printk(KERN_WARNING "GDT-PCI %d: "
5713 "Unable to set 64/32-bit DMA\n", hanum);
5714 goto out_free_coal_stat;
5715 }
5716 }
5717
5718 shp->max_id = ha->tid_cnt;
5719 shp->max_lun = MAXLUN;
5720 shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
5721 if (virt_ctr) {
5722 virt_ctr = 1;
5723 /* register addit. SCSI channels as virtual controllers */
5724 for (b = 1; b < ha->bus_cnt + 1; ++b) {
5725 shp = scsi_register(shtp,sizeof(gdth_num_str));
5726 shp->unchecked_isa_dma = 0;
5727 shp->irq = ha->irq;
5728 shp->dma_channel = 0xff;
5729 gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
5730 NUMDATA(shp)->hanum = (ushort)hanum;
5731 NUMDATA(shp)->busnum = b;
5732 }
5733 }
5734
5735 spin_lock_init(&ha->smp_lock);
5736 gdth_enable_int(hanum);
5737 return 0;
5738
5739 out_free_coal_stat:
5740#ifdef INT_COAL
5741 pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
5742 ha->coal_stat, ha->coal_stat_phys);
5743 out_free_pmsg:
5744#endif
5745 pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
5746 ha->pmsg, ha->msg_phys);
5747 out_free_pscratch:
5748 pci_free_consistent(ha->pdev, GDTH_SCRATCH,
5749 ha->pscratch, ha->scratch_phys);
5750 out_free_irq:
5751 free_irq(ha->irq, ha);
5752 gdth_ctr_count--;
5753 gdth_ctr_vcount--;
5754 out_host_put:
5755 scsi_unregister(shp);
5756 return error;
5757}
5758#endif /* CONFIG_PCI */
5759
5738#include "scsi_module.c" 5760#include "scsi_module.c"
5739#ifndef MODULE 5761#ifndef MODULE
5740__setup("gdth=", option_setup); 5762__setup("gdth=", option_setup);