Commit 1a68d41a334a406d4bd35999f0be4d47f193e477

Authored by Alan Cox
Committed by James Bottomley
1 parent 2538363eb5

[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>

Showing 2 changed files with 69 additions and 59 deletions Side-by-side Diff

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