Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[SCSI] eata_pio cleanup and PCI fix

This started as a PCI reference fixup but to do that I need to build it,
to build it I need to fix it and its full of 32bitisms and uglies.

It has been resurrected, I'm not sure if this is a thank you for the
work on the license stuff or punishment for some unknown misdeed however
8). I've also fixed a memory scribble in the init code.

One oddity - the changes from HZ * to constants are deliberate. Whoever
originally wrote the code (or cleaned it up) used HZ for a cycle timing
loop even though is not HZ related. I've put it back to the counts used
in the old days when the driver was most used.

Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>

authored by

Alan Cox and committed by
James Bottomley
1a68d41a 2538363e

+69 -59
+1
drivers/scsi/eata_generic.h
··· 364 364 __u8 moresupport; /* HBA supports MORE flag */ 365 365 struct Scsi_Host *next; 366 366 struct Scsi_Host *prev; 367 + struct pci_dev *pdev; /* PCI device or NULL for non PCI */ 367 368 struct eata_sp sp; /* status packet */ 368 369 struct eata_ccb ccb[0]; /* ccb array begins here */ 369 370 }hostdata;
+68 -59
drivers/scsi/eata_pio.c
··· 71 71 #include "eata_pio.h" 72 72 73 73 74 - static uint ISAbases[MAXISA] = { 74 + static unsigned int ISAbases[MAXISA] = { 75 75 0x1F0, 0x170, 0x330, 0x230 76 76 }; 77 77 78 - static uint ISAirqs[MAXISA] = { 78 + static unsigned int ISAirqs[MAXISA] = { 79 79 14, 12, 15, 11 80 80 }; 81 81 ··· 84 84 1, 1, 1, 1, 1, 1, 1, 1 85 85 }; 86 86 87 - static uint registered_HBAs; 87 + static unsigned int registered_HBAs; 88 88 static struct Scsi_Host *last_HBA; 89 89 static struct Scsi_Host *first_HBA; 90 90 static unsigned char reg_IRQ[16]; ··· 165 165 166 166 static int eata_pio_release(struct Scsi_Host *sh) 167 167 { 168 + hostdata *hd = SD(sh); 168 169 if (sh->irq && reg_IRQ[sh->irq] == 1) 169 170 free_irq(sh->irq, NULL); 170 171 else ··· 174 173 if (sh->io_port && sh->n_io_port) 175 174 release_region(sh->io_port, sh->n_io_port); 176 175 } 176 + /* At this point the PCI reference can go */ 177 + if (hd->pdev) 178 + pci_dev_put(hd->pdev); 177 179 return 1; 178 180 } 179 181 180 - static void IncStat(struct scsi_pointer *SCp, uint Increment) 182 + static void IncStat(struct scsi_pointer *SCp, unsigned int Increment) 181 183 { 182 184 SCp->ptr += Increment; 183 185 if ((SCp->this_residual -= Increment) == 0) { ··· 194 190 } 195 191 } 196 192 197 - static void eata_pio_int_handler(int irq, void *dev_id, struct pt_regs *regs); 193 + static irqreturn_t eata_pio_int_handler(int irq, void *dev_id, struct pt_regs *regs); 198 194 199 195 static irqreturn_t do_eata_pio_int_handler(int irq, void *dev_id, 200 196 struct pt_regs *regs) 201 197 { 202 198 unsigned long flags; 203 199 struct Scsi_Host *dev = dev_id; 200 + irqreturn_t ret; 204 201 205 202 spin_lock_irqsave(dev->host_lock, flags); 206 - eata_pio_int_handler(irq, dev_id, regs); 203 + ret = eata_pio_int_handler(irq, dev_id, regs); 207 204 spin_unlock_irqrestore(dev->host_lock, flags); 208 - return IRQ_HANDLED; 205 + return ret; 209 206 } 210 207 211 - static void eata_pio_int_handler(int irq, void *dev_id, struct pt_regs *regs) 208 + static irqreturn_t eata_pio_int_handler(int irq, void *dev_id, struct pt_regs *regs) 212 209 { 213 - uint eata_stat = 0xfffff; 210 + unsigned int eata_stat = 0xfffff; 214 211 struct scsi_cmnd *cmd; 215 212 hostdata *hd; 216 213 struct eata_ccb *cp; 217 - uint base; 218 - uint x, z; 214 + unsigned long base; 215 + unsigned int x, z; 219 216 struct Scsi_Host *sh; 220 217 unsigned short zwickel = 0; 221 218 unsigned char stat, odd; 219 + irqreturn_t ret = IRQ_NONE; 222 220 223 221 for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) 224 222 { 225 223 if (sh->irq != irq) 226 224 continue; 227 - if (inb((uint) sh->base + HA_RSTATUS) & HA_SBUSY) 225 + if (inb(sh->base + HA_RSTATUS) & HA_SBUSY) 228 226 continue; 229 227 230 228 int_counter++; 229 + ret = IRQ_HANDLED; 231 230 232 231 hd = SD(sh); 233 232 234 233 cp = &hd->ccb[0]; 235 234 cmd = cp->cmd; 236 - base = (uint) cmd->device->host->base; 235 + base = cmd->device->host->base; 237 236 238 237 do { 239 238 stat = inb(base + HA_RSTATUS); ··· 311 304 if (!(inb(base + HA_RSTATUS) & HA_SERROR)) { 312 305 cmd->result = (DID_OK << 16); 313 306 hd->devflags |= (1 << cp->cp_id); 314 - } else if (hd->devflags & 1 << cp->cp_id) 307 + } else if (hd->devflags & (1 << cp->cp_id)) 315 308 cmd->result = (DID_OK << 16) + 0x02; 316 309 else 317 310 cmd->result = (DID_NO_CONNECT << 16); ··· 320 313 cp->status = FREE; 321 314 eata_stat = inb(base + HA_RSTATUS); 322 315 printk(KERN_CRIT "eata_pio: int_handler, freeing locked " "queueslot\n"); 323 - return; 316 + return ret; 324 317 } 325 318 #if DBG_INTR2 326 319 if (stat != 0x50) ··· 332 325 cmd->scsi_done(cmd); 333 326 } 334 327 335 - return; 328 + return ret; 336 329 } 337 330 338 - static inline uint eata_pio_send_command(uint base, unsigned char command) 331 + static inline unsigned int eata_pio_send_command(unsigned long base, unsigned char command) 339 332 { 340 - uint loop = HZ / 2; 333 + unsigned int loop = 50; 341 334 342 335 while (inb(base + HA_RSTATUS) & HA_SBUSY) 343 336 if (--loop == 0) ··· 356 349 static int eata_pio_queue(struct scsi_cmnd *cmd, 357 350 void (*done)(struct scsi_cmnd *)) 358 351 { 359 - uint x, y; 360 - uint base; 352 + unsigned int x, y; 353 + unsigned long base; 361 354 362 355 hostdata *hd; 363 356 struct Scsi_Host *sh; ··· 367 360 368 361 hd = HD(cmd); 369 362 sh = cmd->device->host; 370 - base = (uint) sh->base; 363 + base = sh->base; 371 364 372 365 /* use only slot 0, as 2001 can handle only one cmd at a time */ 373 366 ··· 402 395 cp->DataIn = 0; /* Input mode */ 403 396 404 397 cp->Interpret = (cmd->device->id == hd->hostid); 405 - cp->cp_datalen = htonl((unsigned long) cmd->request_bufflen); 398 + cp->cp_datalen = cpu_to_be32(cmd->request_bufflen); 406 399 cp->Auto_Req_Sen = 0; 407 - cp->cp_reqDMA = htonl(0); 400 + cp->cp_reqDMA = 0; 408 401 cp->reqlen = 0; 409 402 410 403 cp->cp_id = cmd->device->id; ··· 413 406 cp->cp_identify = 1; 414 407 memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd)); 415 408 416 - cp->cp_statDMA = htonl(0); 409 + cp->cp_statDMA = 0; 417 410 418 411 cp->cp_viraddr = cp; 419 412 cp->cmd = cmd; ··· 452 445 453 446 DBG(DBG_QUEUE, scmd_printk(KERN_DEBUG, cmd, 454 447 "Queued base %#.4lx pid: %ld " 455 - "slot %d irq %d\n", (long) sh->base, cmd->pid, y, sh->irq)); 448 + "slot %d irq %d\n", sh->base, cmd->pid, y, sh->irq)); 456 449 457 450 return (0); 458 451 } 459 452 460 453 static int eata_pio_abort(struct scsi_cmnd *cmd) 461 454 { 462 - uint loop = HZ; 455 + unsigned int loop = 100; 463 456 464 457 DBG(DBG_ABNORM, scmd_printk(KERN_WARNING, cmd, 465 458 "eata_pio_abort called pid: %ld\n", ··· 492 485 493 486 static int eata_pio_host_reset(struct scsi_cmnd *cmd) 494 487 { 495 - uint x, limit = 0; 488 + unsigned int x, limit = 0; 496 489 unsigned char success = 0; 497 490 struct scsi_cmnd *sp; 498 491 struct Scsi_Host *host = cmd->device->host; ··· 525 518 } 526 519 527 520 /* hard reset the HBA */ 528 - outb(EATA_CMD_RESET, (uint) cmd->device->host->base + HA_WCOMMAND); 521 + outb(EATA_CMD_RESET, cmd->device->host->base + HA_WCOMMAND); 529 522 530 523 DBG(DBG_ABNORM, printk(KERN_WARNING "eata_pio_reset: board reset done.\n")); 531 524 HD(cmd)->state = RESET; ··· 565 558 } 566 559 } 567 560 568 - static char *get_pio_board_data(unsigned long base, uint irq, uint id, unsigned long cplen, unsigned short cppadlen) 561 + static char *get_pio_board_data(unsigned long base, unsigned int irq, unsigned int id, unsigned long cplen, unsigned short cppadlen) 569 562 { 570 563 struct eata_ccb cp; 571 564 static char buff[256]; ··· 577 570 cp.DataIn = 1; 578 571 cp.Interpret = 1; /* Interpret command */ 579 572 580 - cp.cp_datalen = htonl(254); 581 - cp.cp_dataDMA = htonl(0); 573 + cp.cp_datalen = cpu_to_be32(254); 574 + cp.cp_dataDMA = cpu_to_be32(0); 582 575 583 576 cp.cp_id = id; 584 577 cp.cp_lun = 0; ··· 590 583 cp.cp_cdb[4] = 254; 591 584 cp.cp_cdb[5] = 0; 592 585 593 - if (eata_pio_send_command((uint) base, EATA_CMD_PIO_SEND_CP)) 586 + if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP)) 594 587 return (NULL); 595 588 while (!(inb(base + HA_RSTATUS) & HA_SDRQ)); 596 589 outsw(base + HA_RDATA, &cp, cplen); ··· 611 604 } 612 605 } 613 606 614 - static int get_pio_conf_PIO(u32 base, struct get_conf *buf) 607 + static int get_pio_conf_PIO(unsigned long base, struct get_conf *buf) 615 608 { 616 609 unsigned long loop = HZ / 2; 617 610 int z; ··· 626 619 if (--loop == 0) 627 620 goto fail; 628 621 629 - DBG(DBG_PIO && DBG_PROBE, printk(KERN_DEBUG "Issuing PIO READ CONFIG to HBA at %#x\n", base)); 622 + DBG(DBG_PIO && DBG_PROBE, printk(KERN_DEBUG "Issuing PIO READ CONFIG to HBA at %#lx\n", base)); 630 623 eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG); 631 624 632 - loop = HZ / 2; 625 + loop = 50; 633 626 for (p = (unsigned short *) buf; (long) p <= ((long) buf + (sizeof(struct get_conf) / 2)); p++) { 634 627 while (!(inb(base + HA_RSTATUS) & HA_SDRQ)) 635 628 if (--loop == 0) 636 629 goto fail; 637 630 638 - loop = HZ / 2; 631 + loop = 50; 639 632 *p = inw(base + HA_RDATA); 640 633 } 641 634 if (inb(base + HA_RSTATUS) & HA_SERROR) { 642 635 DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during " 643 - "transfer for HBA at %x\n", base)); 636 + "transfer for HBA at %lx\n", base)); 644 637 goto fail; 645 638 } 646 639 647 - if (htonl(EATA_SIGNATURE) != buf->signature) 640 + if (cpu_to_be32(EATA_SIGNATURE) != buf->signature) 648 641 goto fail; 649 642 650 643 DBG(DBG_PIO && DBG_PROBE, printk(KERN_NOTICE "EATA Controller found " 651 - "at %#4x EATA Level: %x\n", 652 - base, (uint) (buf->version))); 644 + "at %#4lx EATA Level: %x\n", 645 + base, (unsigned int) (buf->version))); 653 646 654 647 while (inb(base + HA_RSTATUS) & HA_SDRQ) 655 648 inw(base + HA_RDATA); ··· 672 665 static void print_pio_config(struct get_conf *gc) 673 666 { 674 667 printk("Please check values: (read config data)\n"); 675 - printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n", (uint) ntohl(gc->len), gc->version, gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support); 676 - printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n", gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2], gc->scsi_id[1], ntohs(gc->queuesiz), ntohs(gc->SGsiz), gc->SECOND); 668 + printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n", be32_to_cpu(gc->len), gc->version, gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support); 669 + printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n", gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2], gc->scsi_id[1], be16_to_cpu(gc->queuesiz), be16_to_cpu(gc->SGsiz), gc->SECOND); 677 670 printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n", gc->IRQ, gc->IRQ_TR, gc->FORCADR, gc->MAX_CHAN, gc->ID_qest); 678 671 } 679 672 680 - static uint print_selftest(uint base) 673 + static unsigned int print_selftest(unsigned int base) 681 674 { 682 675 unsigned char buffer[512]; 683 676 #ifdef VERBOSE_SETUP ··· 704 697 return (!(inb(base + HA_RSTATUS) & HA_SERROR)); 705 698 } 706 699 707 - static int register_pio_HBA(long base, struct get_conf *gc) 700 + static int register_pio_HBA(long base, struct get_conf *gc, struct pci_dev *pdev) 708 701 { 709 702 unsigned long size = 0; 710 703 char *buff; ··· 721 714 return 0; 722 715 } 723 716 724 - if ((buff = get_pio_board_data((uint) base, gc->IRQ, gc->scsi_id[3], cplen = (htonl(gc->cplen) + 1) / 2, cppadlen = (htons(gc->cppadlen) + 1) / 2)) == NULL) { 725 - printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", (unsigned long) base); 717 + if ((buff = get_pio_board_data(base, gc->IRQ, gc->scsi_id[3], cplen = (cpu_to_be32(gc->cplen) + 1) / 2, cppadlen = (cpu_to_be16(gc->cppadlen) + 1) / 2)) == NULL) { 718 + printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", base); 726 719 return 0; 727 720 } 728 721 729 722 if (!print_selftest(base) && !ALLOW_DMA_BOARDS) { 730 - printk("HBA at %#lx failed while performing self test & setup.\n", (unsigned long) base); 723 + printk("HBA at %#lx failed while performing self test & setup.\n", base); 731 724 return 0; 732 725 } 733 726 734 - size = sizeof(hostdata) + (sizeof(struct eata_ccb) * ntohs(gc->queuesiz)); 727 + size = sizeof(hostdata) + (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz)); 735 728 736 729 sh = scsi_register(&driver_template, size); 737 730 if (sh == NULL) ··· 756 749 757 750 hd = SD(sh); 758 751 759 - memset(hd->ccb, 0, (sizeof(struct eata_ccb) * ntohs(gc->queuesiz))); 760 - memset(hd->reads, 0, sizeof(unsigned long) * 26); 752 + memset(hd->ccb, 0, (sizeof(struct eata_ccb) * be16_to_cpu(gc->queuesiz))); 753 + memset(hd->reads, 0, sizeof(hd->reads)); 761 754 762 755 strlcpy(SD(sh)->vendor, &buff[8], sizeof(SD(sh)->vendor)); 763 756 strlcpy(SD(sh)->name, &buff[16], sizeof(SD(sh)->name)); ··· 768 761 SD(sh)->revision[4] = buff[35]; 769 762 SD(sh)->revision[5] = 0; 770 763 771 - switch (ntohl(gc->len)) { 764 + switch (be32_to_cpu(gc->len)) { 772 765 case 0x1c: 773 766 SD(sh)->EATA_revision = 'a'; 774 767 break; ··· 784 777 SD(sh)->EATA_revision = '?'; 785 778 } 786 779 787 - if (ntohl(gc->len) >= 0x22) { 780 + if (be32_to_cpu(gc->len) >= 0x22) { 788 781 if (gc->is_PCI) 789 782 hd->bustype = IS_PCI; 790 783 else if (gc->is_EISA) ··· 818 811 819 812 hd->channel = 0; 820 813 814 + hd->pdev = pci_dev_get(pdev); /* Keep a PCI reference */ 815 + 821 816 sh->max_id = 8; 822 817 sh->max_lun = 8; 823 818 ··· 850 841 continue; 851 842 if (!get_pio_conf_PIO(ISAbases[i], buf)) 852 843 continue; 853 - if (!register_pio_HBA(ISAbases[i], buf)) 844 + if (!register_pio_HBA(ISAbases[i], buf, NULL)) 854 845 release_region(ISAbases[i], 9); 855 846 else 856 847 ISAbases[i] = 0; ··· 882 873 if (get_pio_conf_PIO(base, buf)) { 883 874 DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf)); 884 875 if (buf->IRQ) { 885 - if (!register_pio_HBA(base, buf)) 876 + if (!register_pio_HBA(base, buf, NULL)) 886 877 release_region(base, 9); 887 878 } else { 888 879 printk(KERN_NOTICE "eata_dma: No valid IRQ. HBA " "removed from list\n"); ··· 905 896 printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n"); 906 897 #else 907 898 struct pci_dev *dev = NULL; 908 - u32 base, x; 899 + unsigned long base, x; 909 900 910 - while ((dev = pci_find_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, dev)) != NULL) { 901 + while ((dev = pci_get_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, dev)) != NULL) { 911 902 DBG(DBG_PROBE && DBG_PCI, printk("eata_pio: find_PCI, HBA at %s\n", pci_name(dev))); 912 903 if (pci_enable_device(dev)) 913 904 continue; ··· 935 926 * eventually remove it from the EISA and ISA list 936 927 */ 937 928 938 - if (!register_pio_HBA(base, buf)) { 929 + if (!register_pio_HBA(base, buf, dev)) { 939 930 release_region(base, 9); 940 931 continue; 941 932 } ··· 985 976 printk("Registered HBAs:\n"); 986 977 printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:" " QS: SG: CPL:\n"); 987 978 for (i = 1; i <= registered_HBAs; i++) { 988 - printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4x %2d %d %d %c" 979 + printk("scsi%-2d: %.10s v%s 2.0%c %s %#.4lx %2d %d %d %c" 989 980 " %2d %2d %2d\n", 990 981 HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision, 991 982 SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P') ? 992 983 "PCI " : (SD(HBA_ptr)->bustype == 'E') ? "EISA" : "ISA ", 993 - (uint) HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, HBA_ptr->this_id, 984 + HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, HBA_ptr->this_id, 994 985 SD(HBA_ptr)->primary ? 'Y' : 'N', HBA_ptr->can_queue, 995 986 HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun); 996 987 HBA_ptr = SD(HBA_ptr)->next;