1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * sym53c500_cs.c Bob Tracy (rct@frus.com) 4 * 5 * A rewrite of the pcmcia-cs add-on driver for newer (circa 1997) 6 * New Media Bus Toaster PCMCIA SCSI cards using the Symbios Logic 7 * 53c500 controller: intended for use with 2.6 and later kernels. 8 * The pcmcia-cs add-on version of this driver is not supported 9 * beyond 2.4. It consisted of three files with history/copyright 10 * information as follows: 11 * 12 * SYM53C500.h 13 * Bob Tracy (rct@frus.com) 14 * Original by Tom Corner (tcorner@via.at). 15 * Adapted from NCR53c406a.h which is Copyrighted (C) 1994 16 * Normunds Saumanis (normunds@rx.tech.swh.lv) 17 * 18 * SYM53C500.c 19 * Bob Tracy (rct@frus.com) 20 * Original driver by Tom Corner (tcorner@via.at) was adapted 21 * from NCR53c406a.c which is Copyrighted (C) 1994, 1995, 1996 22 * Normunds Saumanis (normunds@fi.ibm.com) 23 * 24 * sym53c500.c 25 * Bob Tracy (rct@frus.com) 26 * Original by Tom Corner (tcorner@via.at) was adapted from a 27 * driver for the Qlogic SCSI card written by 28 * David Hinds (dhinds@allegro.stanford.edu). 29 */ 30 31 #define SYM53C500_DEBUG 0 32 #define VERBOSE_SYM53C500_DEBUG 0 33 34 /* 35 * Set this to 0 if you encounter kernel lockups while transferring 36 * data in PIO mode. Note this can be changed via "sysfs". 37 */ 38 #define USE_FAST_PIO 1 39 40 /* =============== End of user configurable parameters ============== */ 41 42 #include <linux/module.h> 43 #include <linux/moduleparam.h> 44 #include <linux/errno.h> 45 #include <linux/init.h> 46 #include <linux/interrupt.h> 47 #include <linux/kernel.h> 48 #include <linux/slab.h> 49 #include <linux/string.h> 50 #include <linux/ioport.h> 51 #include <linux/blkdev.h> 52 #include <linux/spinlock.h> 53 #include <linux/bitops.h> 54 55 #include <asm/io.h> 56 #include <asm/dma.h> 57 #include <asm/irq.h> 58 59 #include <scsi/scsi_ioctl.h> 60 #include <scsi/scsi_cmnd.h> 61 #include <scsi/scsi_device.h> 62 #include <scsi/scsi.h> 63 #include <scsi/scsi_host.h> 64 65 #include <pcmcia/cistpl.h> 66 #include <pcmcia/ds.h> 67 #include <pcmcia/ciscode.h> 68 69 70 /* ================================================================== */ 71 72 #define SYNC_MODE 0 /* Synchronous transfer mode */ 73 74 /* Default configuration */ 75 #define C1_IMG 0x07 /* ID=7 */ 76 #define C2_IMG 0x48 /* FE SCSI2 */ 77 #define C3_IMG 0x20 /* CDB */ 78 #define C4_IMG 0x04 /* ANE */ 79 #define C5_IMG 0xa4 /* ? changed from b6= AA PI SIE POL */ 80 #define C7_IMG 0x80 /* added for SYM53C500 t. corner */ 81 82 /* Hardware Registers: offsets from io_port (base) */ 83 84 /* Control Register Set 0 */ 85 #define TC_LSB 0x00 /* transfer counter lsb */ 86 #define TC_MSB 0x01 /* transfer counter msb */ 87 #define SCSI_FIFO 0x02 /* scsi fifo register */ 88 #define CMD_REG 0x03 /* command register */ 89 #define STAT_REG 0x04 /* status register */ 90 #define DEST_ID 0x04 /* selection/reselection bus id */ 91 #define INT_REG 0x05 /* interrupt status register */ 92 #define SRTIMOUT 0x05 /* select/reselect timeout reg */ 93 #define SEQ_REG 0x06 /* sequence step register */ 94 #define SYNCPRD 0x06 /* synchronous transfer period */ 95 #define FIFO_FLAGS 0x07 /* indicates # of bytes in fifo */ 96 #define SYNCOFF 0x07 /* synchronous offset register */ 97 #define CONFIG1 0x08 /* configuration register */ 98 #define CLKCONV 0x09 /* clock conversion register */ 99 /* #define TESTREG 0x0A */ /* test mode register */ 100 #define CONFIG2 0x0B /* configuration 2 register */ 101 #define CONFIG3 0x0C /* configuration 3 register */ 102 #define CONFIG4 0x0D /* configuration 4 register */ 103 #define TC_HIGH 0x0E /* transfer counter high */ 104 /* #define FIFO_BOTTOM 0x0F */ /* reserve FIFO byte register */ 105 106 /* Control Register Set 1 */ 107 /* #define JUMPER_SENSE 0x00 */ /* jumper sense port reg (r/w) */ 108 /* #define SRAM_PTR 0x01 */ /* SRAM address pointer reg (r/w) */ 109 /* #define SRAM_DATA 0x02 */ /* SRAM data register (r/w) */ 110 #define PIO_FIFO 0x04 /* PIO FIFO registers (r/w) */ 111 /* #define PIO_FIFO1 0x05 */ /* */ 112 /* #define PIO_FIFO2 0x06 */ /* */ 113 /* #define PIO_FIFO3 0x07 */ /* */ 114 #define PIO_STATUS 0x08 /* PIO status (r/w) */ 115 /* #define ATA_CMD 0x09 */ /* ATA command/status reg (r/w) */ 116 /* #define ATA_ERR 0x0A */ /* ATA features/error reg (r/w) */ 117 #define PIO_FLAG 0x0B /* PIO flag interrupt enable (r/w) */ 118 #define CONFIG5 0x09 /* configuration 5 register */ 119 /* #define SIGNATURE 0x0E */ /* signature register (r) */ 120 /* #define CONFIG6 0x0F */ /* configuration 6 register (r) */ 121 #define CONFIG7 0x0d 122 123 /* select register set 0 */ 124 #define REG0(x) (outb(C4_IMG, (x) + CONFIG4)) 125 /* select register set 1 */ 126 #define REG1(x) outb(C7_IMG, (x) + CONFIG7); outb(C5_IMG, (x) + CONFIG5) 127 128 #if SYM53C500_DEBUG 129 #define DEB(x) x 130 #else 131 #define DEB(x) 132 #endif 133 134 #if VERBOSE_SYM53C500_DEBUG 135 #define VDEB(x) x 136 #else 137 #define VDEB(x) 138 #endif 139 140 #define LOAD_DMA_COUNT(x, count) \ 141 outb(count & 0xff, (x) + TC_LSB); \ 142 outb((count >> 8) & 0xff, (x) + TC_MSB); \ 143 outb((count >> 16) & 0xff, (x) + TC_HIGH); 144 145 /* Chip commands */ 146 #define DMA_OP 0x80 147 148 #define SCSI_NOP 0x00 149 #define FLUSH_FIFO 0x01 150 #define CHIP_RESET 0x02 151 #define SCSI_RESET 0x03 152 #define RESELECT 0x40 153 #define SELECT_NO_ATN 0x41 154 #define SELECT_ATN 0x42 155 #define SELECT_ATN_STOP 0x43 156 #define ENABLE_SEL 0x44 157 #define DISABLE_SEL 0x45 158 #define SELECT_ATN3 0x46 159 #define RESELECT3 0x47 160 #define TRANSFER_INFO 0x10 161 #define INIT_CMD_COMPLETE 0x11 162 #define MSG_ACCEPT 0x12 163 #define TRANSFER_PAD 0x18 164 #define SET_ATN 0x1a 165 #define RESET_ATN 0x1b 166 #define SEND_MSG 0x20 167 #define SEND_STATUS 0x21 168 #define SEND_DATA 0x22 169 #define DISCONN_SEQ 0x23 170 #define TERMINATE_SEQ 0x24 171 #define TARG_CMD_COMPLETE 0x25 172 #define DISCONN 0x27 173 #define RECV_MSG 0x28 174 #define RECV_CMD 0x29 175 #define RECV_DATA 0x2a 176 #define RECV_CMD_SEQ 0x2b 177 #define TARGET_ABORT_DMA 0x04 178 179 /* ================================================================== */ 180 181 struct scsi_info_t { 182 struct pcmcia_device *p_dev; 183 struct Scsi_Host *host; 184 unsigned short manf_id; 185 }; 186 187 /* 188 * Repository for per-instance host data. 189 */ 190 struct sym53c500_data { 191 struct scsi_cmnd *current_SC; 192 int fast_pio; 193 }; 194 195 static struct scsi_pointer *sym53c500_scsi_pointer(struct scsi_cmnd *cmd) 196 { 197 return scsi_cmd_priv(cmd); 198 } 199 200 enum Phase { 201 idle, 202 data_out, 203 data_in, 204 command_ph, 205 status_ph, 206 message_out, 207 message_in 208 }; 209 210 /* ================================================================== */ 211 212 static void 213 chip_init(int io_port) 214 { 215 REG1(io_port); 216 outb(0x01, io_port + PIO_STATUS); 217 outb(0x00, io_port + PIO_FLAG); 218 219 outb(C4_IMG, io_port + CONFIG4); /* REG0(io_port); */ 220 outb(C3_IMG, io_port + CONFIG3); 221 outb(C2_IMG, io_port + CONFIG2); 222 outb(C1_IMG, io_port + CONFIG1); 223 224 outb(0x05, io_port + CLKCONV); /* clock conversion factor */ 225 outb(0x9C, io_port + SRTIMOUT); /* Selection timeout */ 226 outb(0x05, io_port + SYNCPRD); /* Synchronous transfer period */ 227 outb(SYNC_MODE, io_port + SYNCOFF); /* synchronous mode */ 228 } 229 230 static void 231 SYM53C500_int_host_reset(int io_port) 232 { 233 outb(C4_IMG, io_port + CONFIG4); /* REG0(io_port); */ 234 outb(CHIP_RESET, io_port + CMD_REG); 235 outb(SCSI_NOP, io_port + CMD_REG); /* required after reset */ 236 outb(SCSI_RESET, io_port + CMD_REG); 237 chip_init(io_port); 238 } 239 240 static __inline__ int 241 SYM53C500_pio_read(int fast_pio, int base, unsigned char *request, unsigned int reqlen) 242 { 243 int i; 244 int len; /* current scsi fifo size */ 245 246 REG1(base); 247 while (reqlen) { 248 i = inb(base + PIO_STATUS); 249 /* VDEB(printk("pio_status=%x\n", i)); */ 250 if (i & 0x80) 251 return 0; 252 253 switch (i & 0x1e) { 254 default: 255 case 0x10: /* fifo empty */ 256 len = 0; 257 break; 258 case 0x0: 259 len = 1; 260 break; 261 case 0x8: /* fifo 1/3 full */ 262 len = 42; 263 break; 264 case 0xc: /* fifo 2/3 full */ 265 len = 84; 266 break; 267 case 0xe: /* fifo full */ 268 len = 128; 269 break; 270 } 271 272 if ((i & 0x40) && len == 0) { /* fifo empty and interrupt occurred */ 273 return 0; 274 } 275 276 if (len) { 277 if (len > reqlen) 278 len = reqlen; 279 280 if (fast_pio && len > 3) { 281 insl(base + PIO_FIFO, request, len >> 2); 282 request += len & 0xfc; 283 reqlen -= len & 0xfc; 284 } else { 285 while (len--) { 286 *request++ = inb(base + PIO_FIFO); 287 reqlen--; 288 } 289 } 290 } 291 } 292 return 0; 293 } 294 295 static __inline__ int 296 SYM53C500_pio_write(int fast_pio, int base, unsigned char *request, unsigned int reqlen) 297 { 298 int i = 0; 299 int len; /* current scsi fifo size */ 300 301 REG1(base); 302 while (reqlen && !(i & 0x40)) { 303 i = inb(base + PIO_STATUS); 304 /* VDEB(printk("pio_status=%x\n", i)); */ 305 if (i & 0x80) /* error */ 306 return 0; 307 308 switch (i & 0x1e) { 309 case 0x10: 310 len = 128; 311 break; 312 case 0x0: 313 len = 84; 314 break; 315 case 0x8: 316 len = 42; 317 break; 318 case 0xc: 319 len = 1; 320 break; 321 default: 322 case 0xe: 323 len = 0; 324 break; 325 } 326 327 if (len) { 328 if (len > reqlen) 329 len = reqlen; 330 331 if (fast_pio && len > 3) { 332 outsl(base + PIO_FIFO, request, len >> 2); 333 request += len & 0xfc; 334 reqlen -= len & 0xfc; 335 } else { 336 while (len--) { 337 outb(*request++, base + PIO_FIFO); 338 reqlen--; 339 } 340 } 341 } 342 } 343 return 0; 344 } 345 346 static irqreturn_t 347 SYM53C500_intr(int irq, void *dev_id) 348 { 349 unsigned long flags; 350 struct Scsi_Host *dev = dev_id; 351 DEB(unsigned char fifo_size;) 352 DEB(unsigned char seq_reg;) 353 unsigned char status, int_reg; 354 unsigned char pio_status; 355 int port_base = dev->io_port; 356 struct sym53c500_data *data = 357 (struct sym53c500_data *)dev->hostdata; 358 struct scsi_cmnd *curSC = data->current_SC; 359 struct scsi_pointer *scsi_pointer = sym53c500_scsi_pointer(curSC); 360 int fast_pio = data->fast_pio; 361 362 spin_lock_irqsave(dev->host_lock, flags); 363 364 VDEB(printk("SYM53C500_intr called\n")); 365 366 REG1(port_base); 367 pio_status = inb(port_base + PIO_STATUS); 368 REG0(port_base); 369 status = inb(port_base + STAT_REG); 370 DEB(seq_reg = inb(port_base + SEQ_REG)); 371 int_reg = inb(port_base + INT_REG); 372 DEB(fifo_size = inb(port_base + FIFO_FLAGS) & 0x1f); 373 374 #if SYM53C500_DEBUG 375 printk("status=%02x, seq_reg=%02x, int_reg=%02x, fifo_size=%02x", 376 status, seq_reg, int_reg, fifo_size); 377 printk(", pio=%02x\n", pio_status); 378 #endif /* SYM53C500_DEBUG */ 379 380 if (int_reg & 0x80) { /* SCSI reset intr */ 381 DEB(printk("SYM53C500: reset intr received\n")); 382 curSC->result = DID_RESET << 16; 383 goto idle_out; 384 } 385 386 if (pio_status & 0x80) { 387 printk("SYM53C500: Warning: PIO error!\n"); 388 curSC->result = DID_ERROR << 16; 389 goto idle_out; 390 } 391 392 if (status & 0x20) { /* Parity error */ 393 printk("SYM53C500: Warning: parity error!\n"); 394 curSC->result = DID_PARITY << 16; 395 goto idle_out; 396 } 397 398 if (status & 0x40) { /* Gross error */ 399 printk("SYM53C500: Warning: gross error!\n"); 400 curSC->result = DID_ERROR << 16; 401 goto idle_out; 402 } 403 404 if (int_reg & 0x20) { /* Disconnect */ 405 DEB(printk("SYM53C500: disconnect intr received\n")); 406 if (scsi_pointer->phase != message_in) { /* Unexpected disconnect */ 407 curSC->result = DID_NO_CONNECT << 16; 408 } else { /* Command complete, return status and message */ 409 curSC->result = (scsi_pointer->Status & 0xff) | 410 ((scsi_pointer->Message & 0xff) << 8) | 411 (DID_OK << 16); 412 } 413 goto idle_out; 414 } 415 416 switch (status & 0x07) { /* scsi phase */ 417 case 0x00: /* DATA-OUT */ 418 if (int_reg & 0x10) { /* Target requesting info transfer */ 419 struct scatterlist *sg; 420 int i; 421 422 scsi_pointer->phase = data_out; 423 VDEB(printk("SYM53C500: Data-Out phase\n")); 424 outb(FLUSH_FIFO, port_base + CMD_REG); 425 LOAD_DMA_COUNT(port_base, scsi_bufflen(curSC)); /* Max transfer size */ 426 outb(TRANSFER_INFO | DMA_OP, port_base + CMD_REG); 427 428 scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) { 429 SYM53C500_pio_write(fast_pio, port_base, 430 sg_virt(sg), sg->length); 431 } 432 REG0(port_base); 433 } 434 break; 435 436 case 0x01: /* DATA-IN */ 437 if (int_reg & 0x10) { /* Target requesting info transfer */ 438 struct scatterlist *sg; 439 int i; 440 441 scsi_pointer->phase = data_in; 442 VDEB(printk("SYM53C500: Data-In phase\n")); 443 outb(FLUSH_FIFO, port_base + CMD_REG); 444 LOAD_DMA_COUNT(port_base, scsi_bufflen(curSC)); /* Max transfer size */ 445 outb(TRANSFER_INFO | DMA_OP, port_base + CMD_REG); 446 447 scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) { 448 SYM53C500_pio_read(fast_pio, port_base, 449 sg_virt(sg), sg->length); 450 } 451 REG0(port_base); 452 } 453 break; 454 455 case 0x02: /* COMMAND */ 456 scsi_pointer->phase = command_ph; 457 printk("SYM53C500: Warning: Unknown interrupt occurred in command phase!\n"); 458 break; 459 460 case 0x03: /* STATUS */ 461 scsi_pointer->phase = status_ph; 462 VDEB(printk("SYM53C500: Status phase\n")); 463 outb(FLUSH_FIFO, port_base + CMD_REG); 464 outb(INIT_CMD_COMPLETE, port_base + CMD_REG); 465 break; 466 467 case 0x04: /* Reserved */ 468 case 0x05: /* Reserved */ 469 printk("SYM53C500: WARNING: Reserved phase!!!\n"); 470 break; 471 472 case 0x06: /* MESSAGE-OUT */ 473 DEB(printk("SYM53C500: Message-Out phase\n")); 474 scsi_pointer->phase = message_out; 475 outb(SET_ATN, port_base + CMD_REG); /* Reject the message */ 476 outb(MSG_ACCEPT, port_base + CMD_REG); 477 break; 478 479 case 0x07: /* MESSAGE-IN */ 480 VDEB(printk("SYM53C500: Message-In phase\n")); 481 scsi_pointer->phase = message_in; 482 483 scsi_pointer->Status = inb(port_base + SCSI_FIFO); 484 scsi_pointer->Message = inb(port_base + SCSI_FIFO); 485 486 VDEB(printk("SCSI FIFO size=%d\n", inb(port_base + FIFO_FLAGS) & 0x1f)); 487 DEB(printk("Status = %02x Message = %02x\n", 488 scsi_pointer->Status, scsi_pointer->Message)); 489 490 if (scsi_pointer->Message == SAVE_POINTERS || 491 scsi_pointer->Message == DISCONNECT) { 492 outb(SET_ATN, port_base + CMD_REG); /* Reject message */ 493 DEB(printk("Discarding SAVE_POINTERS message\n")); 494 } 495 outb(MSG_ACCEPT, port_base + CMD_REG); 496 break; 497 } 498 out: 499 spin_unlock_irqrestore(dev->host_lock, flags); 500 return IRQ_HANDLED; 501 502 idle_out: 503 scsi_pointer->phase = idle; 504 scsi_done(curSC); 505 goto out; 506 } 507 508 static void 509 SYM53C500_release(struct pcmcia_device *link) 510 { 511 struct scsi_info_t *info = link->priv; 512 struct Scsi_Host *shost = info->host; 513 514 dev_dbg(&link->dev, "SYM53C500_release\n"); 515 516 /* 517 * Do this before releasing/freeing resources. 518 */ 519 scsi_remove_host(shost); 520 521 /* 522 * Interrupts getting hosed on card removal. Try 523 * the following code, mostly from qlogicfas.c. 524 */ 525 if (shost->irq) 526 free_irq(shost->irq, shost); 527 if (shost->io_port && shost->n_io_port) 528 release_region(shost->io_port, shost->n_io_port); 529 530 pcmcia_disable_device(link); 531 532 scsi_host_put(shost); 533 } /* SYM53C500_release */ 534 535 static const char* 536 SYM53C500_info(struct Scsi_Host *SChost) 537 { 538 static char info_msg[256]; 539 struct sym53c500_data *data = 540 (struct sym53c500_data *)SChost->hostdata; 541 542 DEB(printk("SYM53C500_info called\n")); 543 (void)snprintf(info_msg, sizeof(info_msg), 544 "SYM53C500 at 0x%lx, IRQ %d, %s PIO mode.", 545 SChost->io_port, SChost->irq, data->fast_pio ? "fast" : "slow"); 546 return (info_msg); 547 } 548 549 static int SYM53C500_queue_lck(struct scsi_cmnd *SCpnt) 550 { 551 struct scsi_pointer *scsi_pointer = sym53c500_scsi_pointer(SCpnt); 552 int i; 553 int port_base = SCpnt->device->host->io_port; 554 struct sym53c500_data *data = 555 (struct sym53c500_data *)SCpnt->device->host->hostdata; 556 557 VDEB(printk("SYM53C500_queue called\n")); 558 559 DEB(printk("cmd=%02x, cmd_len=%02x, target=%02x, lun=%02x, bufflen=%d\n", 560 SCpnt->cmnd[0], SCpnt->cmd_len, SCpnt->device->id, 561 (u8)SCpnt->device->lun, scsi_bufflen(SCpnt))); 562 563 VDEB(for (i = 0; i < SCpnt->cmd_len; i++) 564 printk("cmd[%d]=%02x ", i, SCpnt->cmnd[i])); 565 VDEB(printk("\n")); 566 567 data->current_SC = SCpnt; 568 scsi_pointer->phase = command_ph; 569 scsi_pointer->Status = 0; 570 scsi_pointer->Message = 0; 571 572 /* We are locked here already by the mid layer */ 573 REG0(port_base); 574 outb(scmd_id(SCpnt), port_base + DEST_ID); /* set destination */ 575 outb(FLUSH_FIFO, port_base + CMD_REG); /* reset the fifos */ 576 577 for (i = 0; i < SCpnt->cmd_len; i++) { 578 outb(SCpnt->cmnd[i], port_base + SCSI_FIFO); 579 } 580 outb(SELECT_NO_ATN, port_base + CMD_REG); 581 582 return 0; 583 } 584 585 static DEF_SCSI_QCMD(SYM53C500_queue) 586 587 static int 588 SYM53C500_host_reset(struct scsi_cmnd *SCpnt) 589 { 590 int port_base = SCpnt->device->host->io_port; 591 592 DEB(printk("SYM53C500_host_reset called\n")); 593 spin_lock_irq(SCpnt->device->host->host_lock); 594 SYM53C500_int_host_reset(port_base); 595 spin_unlock_irq(SCpnt->device->host->host_lock); 596 597 return SUCCESS; 598 } 599 600 static int 601 SYM53C500_biosparm(struct scsi_device *disk, 602 struct block_device *dev, 603 sector_t capacity, int *info_array) 604 { 605 int size; 606 607 DEB(printk("SYM53C500_biosparm called\n")); 608 609 size = capacity; 610 info_array[0] = 64; /* heads */ 611 info_array[1] = 32; /* sectors */ 612 info_array[2] = size >> 11; /* cylinders */ 613 if (info_array[2] > 1024) { /* big disk */ 614 info_array[0] = 255; 615 info_array[1] = 63; 616 info_array[2] = size / (255 * 63); 617 } 618 return 0; 619 } 620 621 static ssize_t 622 SYM53C500_show_pio(struct device *dev, struct device_attribute *attr, 623 char *buf) 624 { 625 struct Scsi_Host *SHp = class_to_shost(dev); 626 struct sym53c500_data *data = 627 (struct sym53c500_data *)SHp->hostdata; 628 629 return snprintf(buf, 4, "%d\n", data->fast_pio); 630 } 631 632 static ssize_t 633 SYM53C500_store_pio(struct device *dev, struct device_attribute *attr, 634 const char *buf, size_t count) 635 { 636 int pio; 637 struct Scsi_Host *SHp = class_to_shost(dev); 638 struct sym53c500_data *data = 639 (struct sym53c500_data *)SHp->hostdata; 640 641 pio = simple_strtoul(buf, NULL, 0); 642 if (pio == 0 || pio == 1) { 643 data->fast_pio = pio; 644 return count; 645 } 646 else 647 return -EINVAL; 648 } 649 650 /* 651 * SCSI HBA device attributes we want to 652 * make available via sysfs. 653 */ 654 static struct device_attribute SYM53C500_pio_attr = { 655 .attr = { 656 .name = "fast_pio", 657 .mode = (S_IRUGO | S_IWUSR), 658 }, 659 .show = SYM53C500_show_pio, 660 .store = SYM53C500_store_pio, 661 }; 662 663 static struct attribute *SYM53C500_shost_attrs[] = { 664 &SYM53C500_pio_attr.attr, 665 NULL, 666 }; 667 668 ATTRIBUTE_GROUPS(SYM53C500_shost); 669 670 /* 671 * scsi_host_template initializer 672 */ 673 static struct scsi_host_template sym53c500_driver_template = { 674 .module = THIS_MODULE, 675 .name = "SYM53C500", 676 .info = SYM53C500_info, 677 .queuecommand = SYM53C500_queue, 678 .eh_host_reset_handler = SYM53C500_host_reset, 679 .bios_param = SYM53C500_biosparm, 680 .proc_name = "SYM53C500", 681 .can_queue = 1, 682 .this_id = 7, 683 .sg_tablesize = 32, 684 .shost_groups = SYM53C500_shost_groups, 685 .cmd_size = sizeof(struct scsi_pointer), 686 }; 687 688 static int SYM53C500_config_check(struct pcmcia_device *p_dev, void *priv_data) 689 { 690 p_dev->io_lines = 10; 691 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH; 692 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 693 694 if (p_dev->resource[0]->start == 0) 695 return -ENODEV; 696 697 return pcmcia_request_io(p_dev); 698 } 699 700 static int 701 SYM53C500_config(struct pcmcia_device *link) 702 { 703 struct scsi_info_t *info = link->priv; 704 int ret; 705 int irq_level, port_base; 706 struct Scsi_Host *host; 707 struct scsi_host_template *tpnt = &sym53c500_driver_template; 708 struct sym53c500_data *data; 709 710 dev_dbg(&link->dev, "SYM53C500_config\n"); 711 712 info->manf_id = link->manf_id; 713 714 ret = pcmcia_loop_config(link, SYM53C500_config_check, NULL); 715 if (ret) 716 goto failed; 717 718 if (!link->irq) 719 goto failed; 720 721 ret = pcmcia_enable_device(link); 722 if (ret) 723 goto failed; 724 725 /* 726 * That's the trouble with copying liberally from another driver. 727 * Some things probably aren't relevant, and I suspect this entire 728 * section dealing with manufacturer IDs can be scrapped. --rct 729 */ 730 if ((info->manf_id == MANFID_MACNICA) || 731 (info->manf_id == MANFID_PIONEER) || 732 (info->manf_id == 0x0098)) { 733 /* set ATAcmd */ 734 outb(0xb4, link->resource[0]->start + 0xd); 735 outb(0x24, link->resource[0]->start + 0x9); 736 outb(0x04, link->resource[0]->start + 0xd); 737 } 738 739 /* 740 * irq_level == 0 implies tpnt->can_queue == 0, which 741 * is not supported in 2.6. Thus, only irq_level > 0 742 * will be allowed. 743 * 744 * Possible port_base values are as follows: 745 * 746 * 0x130, 0x230, 0x280, 0x290, 747 * 0x320, 0x330, 0x340, 0x350 748 */ 749 port_base = link->resource[0]->start; 750 irq_level = link->irq; 751 752 DEB(printk("SYM53C500: port_base=0x%x, irq=%d, fast_pio=%d\n", 753 port_base, irq_level, USE_FAST_PIO);) 754 755 chip_init(port_base); 756 757 host = scsi_host_alloc(tpnt, sizeof(struct sym53c500_data)); 758 if (!host) { 759 printk("SYM53C500: Unable to register host, giving up.\n"); 760 goto err_release; 761 } 762 763 data = (struct sym53c500_data *)host->hostdata; 764 765 if (irq_level > 0) { 766 if (request_irq(irq_level, SYM53C500_intr, IRQF_SHARED, "SYM53C500", host)) { 767 printk("SYM53C500: unable to allocate IRQ %d\n", irq_level); 768 goto err_free_scsi; 769 } 770 DEB(printk("SYM53C500: allocated IRQ %d\n", irq_level)); 771 } else if (irq_level == 0) { 772 DEB(printk("SYM53C500: No interrupts detected\n")); 773 goto err_free_scsi; 774 } else { 775 DEB(printk("SYM53C500: Shouldn't get here!\n")); 776 goto err_free_scsi; 777 } 778 779 host->unique_id = port_base; 780 host->irq = irq_level; 781 host->io_port = port_base; 782 host->n_io_port = 0x10; 783 host->dma_channel = -1; 784 785 /* 786 * Note fast_pio is set to USE_FAST_PIO by 787 * default, but can be changed via "sysfs". 788 */ 789 data->fast_pio = USE_FAST_PIO; 790 791 info->host = host; 792 793 if (scsi_add_host(host, NULL)) 794 goto err_free_irq; 795 796 scsi_scan_host(host); 797 798 return 0; 799 800 err_free_irq: 801 free_irq(irq_level, host); 802 err_free_scsi: 803 scsi_host_put(host); 804 err_release: 805 release_region(port_base, 0x10); 806 printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n"); 807 return -ENODEV; 808 809 failed: 810 SYM53C500_release(link); 811 return -ENODEV; 812 } /* SYM53C500_config */ 813 814 static int sym53c500_resume(struct pcmcia_device *link) 815 { 816 struct scsi_info_t *info = link->priv; 817 818 /* See earlier comment about manufacturer IDs. */ 819 if ((info->manf_id == MANFID_MACNICA) || 820 (info->manf_id == MANFID_PIONEER) || 821 (info->manf_id == 0x0098)) { 822 outb(0x80, link->resource[0]->start + 0xd); 823 outb(0x24, link->resource[0]->start + 0x9); 824 outb(0x04, link->resource[0]->start + 0xd); 825 } 826 /* 827 * If things don't work after a "resume", 828 * this is a good place to start looking. 829 */ 830 SYM53C500_int_host_reset(link->resource[0]->start); 831 832 return 0; 833 } 834 835 static void 836 SYM53C500_detach(struct pcmcia_device *link) 837 { 838 dev_dbg(&link->dev, "SYM53C500_detach\n"); 839 840 SYM53C500_release(link); 841 842 kfree(link->priv); 843 link->priv = NULL; 844 } /* SYM53C500_detach */ 845 846 static int 847 SYM53C500_probe(struct pcmcia_device *link) 848 { 849 struct scsi_info_t *info; 850 851 dev_dbg(&link->dev, "SYM53C500_attach()\n"); 852 853 /* Create new SCSI device */ 854 info = kzalloc(sizeof(*info), GFP_KERNEL); 855 if (!info) 856 return -ENOMEM; 857 info->p_dev = link; 858 link->priv = info; 859 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; 860 861 return SYM53C500_config(link); 862 } /* SYM53C500_attach */ 863 864 MODULE_AUTHOR("Bob Tracy <rct@frus.com>"); 865 MODULE_DESCRIPTION("SYM53C500 PCMCIA SCSI driver"); 866 MODULE_LICENSE("GPL"); 867 868 static const struct pcmcia_device_id sym53c500_ids[] = { 869 PCMCIA_DEVICE_PROD_ID12("BASICS by New Media Corporation", "SCSI Sym53C500", 0x23c78a9d, 0x0099e7f7), 870 PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "SCSI Bus Toaster Sym53C500", 0x085a850b, 0x45432eb8), 871 PCMCIA_DEVICE_PROD_ID2("SCSI9000", 0x21648f44), 872 PCMCIA_DEVICE_NULL, 873 }; 874 MODULE_DEVICE_TABLE(pcmcia, sym53c500_ids); 875 876 static struct pcmcia_driver sym53c500_cs_driver = { 877 .owner = THIS_MODULE, 878 .name = "sym53c500_cs", 879 .probe = SYM53C500_probe, 880 .remove = SYM53C500_detach, 881 .id_table = sym53c500_ids, 882 .resume = sym53c500_resume, 883 }; 884 module_pcmcia_driver(sym53c500_cs_driver); 885