11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * sym53c500_cs.c Bob Tracy (rct@frus.com) 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * A rewrite of the pcmcia-cs add-on driver for newer (circa 1997) 51da177e4SLinus Torvalds * New Media Bus Toaster PCMCIA SCSI cards using the Symbios Logic 61da177e4SLinus Torvalds * 53c500 controller: intended for use with 2.6 and later kernels. 71da177e4SLinus Torvalds * The pcmcia-cs add-on version of this driver is not supported 81da177e4SLinus Torvalds * beyond 2.4. It consisted of three files with history/copyright 91da177e4SLinus Torvalds * information as follows: 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * SYM53C500.h 121da177e4SLinus Torvalds * Bob Tracy (rct@frus.com) 131da177e4SLinus Torvalds * Original by Tom Corner (tcorner@via.at). 141da177e4SLinus Torvalds * Adapted from NCR53c406a.h which is Copyrighted (C) 1994 151da177e4SLinus Torvalds * Normunds Saumanis (normunds@rx.tech.swh.lv) 161da177e4SLinus Torvalds * 171da177e4SLinus Torvalds * SYM53C500.c 181da177e4SLinus Torvalds * Bob Tracy (rct@frus.com) 191da177e4SLinus Torvalds * Original driver by Tom Corner (tcorner@via.at) was adapted 201da177e4SLinus Torvalds * from NCR53c406a.c which is Copyrighted (C) 1994, 1995, 1996 211da177e4SLinus Torvalds * Normunds Saumanis (normunds@fi.ibm.com) 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * sym53c500.c 241da177e4SLinus Torvalds * Bob Tracy (rct@frus.com) 251da177e4SLinus Torvalds * Original by Tom Corner (tcorner@via.at) was adapted from a 261da177e4SLinus Torvalds * driver for the Qlogic SCSI card written by 271da177e4SLinus Torvalds * David Hinds (dhinds@allegro.stanford.edu). 281da177e4SLinus Torvalds * 291da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 301da177e4SLinus Torvalds * under the terms of the GNU General Public License as published by the 311da177e4SLinus Torvalds * Free Software Foundation; either version 2, or (at your option) any 321da177e4SLinus Torvalds * later version. 331da177e4SLinus Torvalds * 341da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, but 351da177e4SLinus Torvalds * WITHOUT ANY WARRANTY; without even the implied warranty of 361da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 371da177e4SLinus Torvalds * General Public License for more details. 381da177e4SLinus Torvalds */ 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds #define SYM53C500_DEBUG 0 411da177e4SLinus Torvalds #define VERBOSE_SYM53C500_DEBUG 0 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds /* 441da177e4SLinus Torvalds * Set this to 0 if you encounter kernel lockups while transferring 451da177e4SLinus Torvalds * data in PIO mode. Note this can be changed via "sysfs". 461da177e4SLinus Torvalds */ 471da177e4SLinus Torvalds #define USE_FAST_PIO 1 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds /* =============== End of user configurable parameters ============== */ 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds #include <linux/module.h> 521da177e4SLinus Torvalds #include <linux/moduleparam.h> 531da177e4SLinus Torvalds #include <linux/errno.h> 541da177e4SLinus Torvalds #include <linux/init.h> 551da177e4SLinus Torvalds #include <linux/interrupt.h> 561da177e4SLinus Torvalds #include <linux/kernel.h> 571da177e4SLinus Torvalds #include <linux/sched.h> 581da177e4SLinus Torvalds #include <linux/slab.h> 591da177e4SLinus Torvalds #include <linux/string.h> 601da177e4SLinus Torvalds #include <linux/ioport.h> 611da177e4SLinus Torvalds #include <linux/blkdev.h> 621da177e4SLinus Torvalds #include <linux/spinlock.h> 631da177e4SLinus Torvalds #include <linux/bitops.h> 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds #include <asm/io.h> 661da177e4SLinus Torvalds #include <asm/dma.h> 671da177e4SLinus Torvalds #include <asm/irq.h> 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds #include <scsi/scsi_ioctl.h> 701da177e4SLinus Torvalds #include <scsi/scsi_cmnd.h> 711da177e4SLinus Torvalds #include <scsi/scsi_device.h> 721da177e4SLinus Torvalds #include <scsi/scsi.h> 731da177e4SLinus Torvalds #include <scsi/scsi_host.h> 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds #include <pcmcia/cs_types.h> 761da177e4SLinus Torvalds #include <pcmcia/cs.h> 771da177e4SLinus Torvalds #include <pcmcia/cistpl.h> 781da177e4SLinus Torvalds #include <pcmcia/ds.h> 791da177e4SLinus Torvalds #include <pcmcia/ciscode.h> 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds /* ================================================================== */ 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds #ifdef PCMCIA_DEBUG 841da177e4SLinus Torvalds static int pc_debug = PCMCIA_DEBUG; 851da177e4SLinus Torvalds module_param(pc_debug, int, 0); 861da177e4SLinus Torvalds #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) 871da177e4SLinus Torvalds static char *version = 881da177e4SLinus Torvalds "sym53c500_cs.c 0.9c 2004/10/27 (Bob Tracy)"; 891da177e4SLinus Torvalds #else 901da177e4SLinus Torvalds #define DEBUG(n, args...) 911da177e4SLinus Torvalds #endif 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds /* ================================================================== */ 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds #define SYNC_MODE 0 /* Synchronous transfer mode */ 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds /* Default configuration */ 981da177e4SLinus Torvalds #define C1_IMG 0x07 /* ID=7 */ 991da177e4SLinus Torvalds #define C2_IMG 0x48 /* FE SCSI2 */ 1001da177e4SLinus Torvalds #define C3_IMG 0x20 /* CDB */ 1011da177e4SLinus Torvalds #define C4_IMG 0x04 /* ANE */ 1021da177e4SLinus Torvalds #define C5_IMG 0xa4 /* ? changed from b6= AA PI SIE POL */ 1031da177e4SLinus Torvalds #define C7_IMG 0x80 /* added for SYM53C500 t. corner */ 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds /* Hardware Registers: offsets from io_port (base) */ 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds /* Control Register Set 0 */ 1081da177e4SLinus Torvalds #define TC_LSB 0x00 /* transfer counter lsb */ 1091da177e4SLinus Torvalds #define TC_MSB 0x01 /* transfer counter msb */ 1101da177e4SLinus Torvalds #define SCSI_FIFO 0x02 /* scsi fifo register */ 1111da177e4SLinus Torvalds #define CMD_REG 0x03 /* command register */ 1121da177e4SLinus Torvalds #define STAT_REG 0x04 /* status register */ 1131da177e4SLinus Torvalds #define DEST_ID 0x04 /* selection/reselection bus id */ 1141da177e4SLinus Torvalds #define INT_REG 0x05 /* interrupt status register */ 1151da177e4SLinus Torvalds #define SRTIMOUT 0x05 /* select/reselect timeout reg */ 1161da177e4SLinus Torvalds #define SEQ_REG 0x06 /* sequence step register */ 1171da177e4SLinus Torvalds #define SYNCPRD 0x06 /* synchronous transfer period */ 1181da177e4SLinus Torvalds #define FIFO_FLAGS 0x07 /* indicates # of bytes in fifo */ 1191da177e4SLinus Torvalds #define SYNCOFF 0x07 /* synchronous offset register */ 1201da177e4SLinus Torvalds #define CONFIG1 0x08 /* configuration register */ 1211da177e4SLinus Torvalds #define CLKCONV 0x09 /* clock conversion register */ 1221da177e4SLinus Torvalds /* #define TESTREG 0x0A */ /* test mode register */ 1231da177e4SLinus Torvalds #define CONFIG2 0x0B /* configuration 2 register */ 1241da177e4SLinus Torvalds #define CONFIG3 0x0C /* configuration 3 register */ 1251da177e4SLinus Torvalds #define CONFIG4 0x0D /* configuration 4 register */ 1261da177e4SLinus Torvalds #define TC_HIGH 0x0E /* transfer counter high */ 1271da177e4SLinus Torvalds /* #define FIFO_BOTTOM 0x0F */ /* reserve FIFO byte register */ 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds /* Control Register Set 1 */ 1301da177e4SLinus Torvalds /* #define JUMPER_SENSE 0x00 */ /* jumper sense port reg (r/w) */ 1311da177e4SLinus Torvalds /* #define SRAM_PTR 0x01 */ /* SRAM address pointer reg (r/w) */ 1321da177e4SLinus Torvalds /* #define SRAM_DATA 0x02 */ /* SRAM data register (r/w) */ 1331da177e4SLinus Torvalds #define PIO_FIFO 0x04 /* PIO FIFO registers (r/w) */ 1341da177e4SLinus Torvalds /* #define PIO_FIFO1 0x05 */ /* */ 1351da177e4SLinus Torvalds /* #define PIO_FIFO2 0x06 */ /* */ 1361da177e4SLinus Torvalds /* #define PIO_FIFO3 0x07 */ /* */ 1371da177e4SLinus Torvalds #define PIO_STATUS 0x08 /* PIO status (r/w) */ 1381da177e4SLinus Torvalds /* #define ATA_CMD 0x09 */ /* ATA command/status reg (r/w) */ 1391da177e4SLinus Torvalds /* #define ATA_ERR 0x0A */ /* ATA features/error reg (r/w) */ 1401da177e4SLinus Torvalds #define PIO_FLAG 0x0B /* PIO flag interrupt enable (r/w) */ 1411da177e4SLinus Torvalds #define CONFIG5 0x09 /* configuration 5 register */ 1421da177e4SLinus Torvalds /* #define SIGNATURE 0x0E */ /* signature register (r) */ 1431da177e4SLinus Torvalds /* #define CONFIG6 0x0F */ /* configuration 6 register (r) */ 1441da177e4SLinus Torvalds #define CONFIG7 0x0d 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds /* select register set 0 */ 1471da177e4SLinus Torvalds #define REG0(x) (outb(C4_IMG, (x) + CONFIG4)) 1481da177e4SLinus Torvalds /* select register set 1 */ 1491da177e4SLinus Torvalds #define REG1(x) outb(C7_IMG, (x) + CONFIG7); outb(C5_IMG, (x) + CONFIG5) 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds #if SYM53C500_DEBUG 1521da177e4SLinus Torvalds #define DEB(x) x 1531da177e4SLinus Torvalds #else 1541da177e4SLinus Torvalds #define DEB(x) 1551da177e4SLinus Torvalds #endif 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds #if VERBOSE_SYM53C500_DEBUG 1581da177e4SLinus Torvalds #define VDEB(x) x 1591da177e4SLinus Torvalds #else 1601da177e4SLinus Torvalds #define VDEB(x) 1611da177e4SLinus Torvalds #endif 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds #define LOAD_DMA_COUNT(x, count) \ 1641da177e4SLinus Torvalds outb(count & 0xff, (x) + TC_LSB); \ 1651da177e4SLinus Torvalds outb((count >> 8) & 0xff, (x) + TC_MSB); \ 1661da177e4SLinus Torvalds outb((count >> 16) & 0xff, (x) + TC_HIGH); 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds /* Chip commands */ 1691da177e4SLinus Torvalds #define DMA_OP 0x80 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds #define SCSI_NOP 0x00 1721da177e4SLinus Torvalds #define FLUSH_FIFO 0x01 1731da177e4SLinus Torvalds #define CHIP_RESET 0x02 1741da177e4SLinus Torvalds #define SCSI_RESET 0x03 1751da177e4SLinus Torvalds #define RESELECT 0x40 1761da177e4SLinus Torvalds #define SELECT_NO_ATN 0x41 1771da177e4SLinus Torvalds #define SELECT_ATN 0x42 1781da177e4SLinus Torvalds #define SELECT_ATN_STOP 0x43 1791da177e4SLinus Torvalds #define ENABLE_SEL 0x44 1801da177e4SLinus Torvalds #define DISABLE_SEL 0x45 1811da177e4SLinus Torvalds #define SELECT_ATN3 0x46 1821da177e4SLinus Torvalds #define RESELECT3 0x47 1831da177e4SLinus Torvalds #define TRANSFER_INFO 0x10 1841da177e4SLinus Torvalds #define INIT_CMD_COMPLETE 0x11 1851da177e4SLinus Torvalds #define MSG_ACCEPT 0x12 1861da177e4SLinus Torvalds #define TRANSFER_PAD 0x18 1871da177e4SLinus Torvalds #define SET_ATN 0x1a 1881da177e4SLinus Torvalds #define RESET_ATN 0x1b 1891da177e4SLinus Torvalds #define SEND_MSG 0x20 1901da177e4SLinus Torvalds #define SEND_STATUS 0x21 1911da177e4SLinus Torvalds #define SEND_DATA 0x22 1921da177e4SLinus Torvalds #define DISCONN_SEQ 0x23 1931da177e4SLinus Torvalds #define TERMINATE_SEQ 0x24 1941da177e4SLinus Torvalds #define TARG_CMD_COMPLETE 0x25 1951da177e4SLinus Torvalds #define DISCONN 0x27 1961da177e4SLinus Torvalds #define RECV_MSG 0x28 1971da177e4SLinus Torvalds #define RECV_CMD 0x29 1981da177e4SLinus Torvalds #define RECV_DATA 0x2a 1991da177e4SLinus Torvalds #define RECV_CMD_SEQ 0x2b 2001da177e4SLinus Torvalds #define TARGET_ABORT_DMA 0x04 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvalds /* ================================================================== */ 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds struct scsi_info_t { 2051da177e4SLinus Torvalds dev_link_t link; 2061da177e4SLinus Torvalds dev_node_t node; 2071da177e4SLinus Torvalds struct Scsi_Host *host; 2081da177e4SLinus Torvalds unsigned short manf_id; 2091da177e4SLinus Torvalds }; 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds /* 2121da177e4SLinus Torvalds * Repository for per-instance host data. 2131da177e4SLinus Torvalds */ 2141da177e4SLinus Torvalds struct sym53c500_data { 2151da177e4SLinus Torvalds struct scsi_cmnd *current_SC; 2161da177e4SLinus Torvalds int fast_pio; 2171da177e4SLinus Torvalds }; 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds enum Phase { 2201da177e4SLinus Torvalds idle, 2211da177e4SLinus Torvalds data_out, 2221da177e4SLinus Torvalds data_in, 2231da177e4SLinus Torvalds command_ph, 2241da177e4SLinus Torvalds status_ph, 2251da177e4SLinus Torvalds message_out, 2261da177e4SLinus Torvalds message_in 2271da177e4SLinus Torvalds }; 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds /* ================================================================== */ 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds /* 2321da177e4SLinus Torvalds * Global (within this module) variables other than 2331da177e4SLinus Torvalds * sym53c500_driver_template (the scsi_host_template). 2341da177e4SLinus Torvalds */ 2351da177e4SLinus Torvalds static dev_link_t *dev_list; 2361da177e4SLinus Torvalds static dev_info_t dev_info = "sym53c500_cs"; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds /* ================================================================== */ 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds static void 2411da177e4SLinus Torvalds chip_init(int io_port) 2421da177e4SLinus Torvalds { 2431da177e4SLinus Torvalds REG1(io_port); 2441da177e4SLinus Torvalds outb(0x01, io_port + PIO_STATUS); 2451da177e4SLinus Torvalds outb(0x00, io_port + PIO_FLAG); 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds outb(C4_IMG, io_port + CONFIG4); /* REG0(io_port); */ 2481da177e4SLinus Torvalds outb(C3_IMG, io_port + CONFIG3); 2491da177e4SLinus Torvalds outb(C2_IMG, io_port + CONFIG2); 2501da177e4SLinus Torvalds outb(C1_IMG, io_port + CONFIG1); 2511da177e4SLinus Torvalds 2521da177e4SLinus Torvalds outb(0x05, io_port + CLKCONV); /* clock conversion factor */ 2531da177e4SLinus Torvalds outb(0x9C, io_port + SRTIMOUT); /* Selection timeout */ 2541da177e4SLinus Torvalds outb(0x05, io_port + SYNCPRD); /* Synchronous transfer period */ 2551da177e4SLinus Torvalds outb(SYNC_MODE, io_port + SYNCOFF); /* synchronous mode */ 2561da177e4SLinus Torvalds } 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds static void 2591da177e4SLinus Torvalds SYM53C500_int_host_reset(int io_port) 2601da177e4SLinus Torvalds { 2611da177e4SLinus Torvalds outb(C4_IMG, io_port + CONFIG4); /* REG0(io_port); */ 2621da177e4SLinus Torvalds outb(CHIP_RESET, io_port + CMD_REG); 2631da177e4SLinus Torvalds outb(SCSI_NOP, io_port + CMD_REG); /* required after reset */ 2641da177e4SLinus Torvalds outb(SCSI_RESET, io_port + CMD_REG); 2651da177e4SLinus Torvalds chip_init(io_port); 2661da177e4SLinus Torvalds } 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds static __inline__ int 2691da177e4SLinus Torvalds SYM53C500_pio_read(int fast_pio, int base, unsigned char *request, unsigned int reqlen) 2701da177e4SLinus Torvalds { 2711da177e4SLinus Torvalds int i; 2721da177e4SLinus Torvalds int len; /* current scsi fifo size */ 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds REG1(base); 2751da177e4SLinus Torvalds while (reqlen) { 2761da177e4SLinus Torvalds i = inb(base + PIO_STATUS); 2771da177e4SLinus Torvalds /* VDEB(printk("pio_status=%x\n", i)); */ 2781da177e4SLinus Torvalds if (i & 0x80) 2791da177e4SLinus Torvalds return 0; 2801da177e4SLinus Torvalds 2811da177e4SLinus Torvalds switch (i & 0x1e) { 2821da177e4SLinus Torvalds default: 2831da177e4SLinus Torvalds case 0x10: /* fifo empty */ 2841da177e4SLinus Torvalds len = 0; 2851da177e4SLinus Torvalds break; 2861da177e4SLinus Torvalds case 0x0: 2871da177e4SLinus Torvalds len = 1; 2881da177e4SLinus Torvalds break; 2891da177e4SLinus Torvalds case 0x8: /* fifo 1/3 full */ 2901da177e4SLinus Torvalds len = 42; 2911da177e4SLinus Torvalds break; 2921da177e4SLinus Torvalds case 0xc: /* fifo 2/3 full */ 2931da177e4SLinus Torvalds len = 84; 2941da177e4SLinus Torvalds break; 2951da177e4SLinus Torvalds case 0xe: /* fifo full */ 2961da177e4SLinus Torvalds len = 128; 2971da177e4SLinus Torvalds break; 2981da177e4SLinus Torvalds } 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds if ((i & 0x40) && len == 0) { /* fifo empty and interrupt occurred */ 3011da177e4SLinus Torvalds return 0; 3021da177e4SLinus Torvalds } 3031da177e4SLinus Torvalds 3041da177e4SLinus Torvalds if (len) { 3051da177e4SLinus Torvalds if (len > reqlen) 3061da177e4SLinus Torvalds len = reqlen; 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds if (fast_pio && len > 3) { 3091da177e4SLinus Torvalds insl(base + PIO_FIFO, request, len >> 2); 3101da177e4SLinus Torvalds request += len & 0xfc; 3111da177e4SLinus Torvalds reqlen -= len & 0xfc; 3121da177e4SLinus Torvalds } else { 3131da177e4SLinus Torvalds while (len--) { 3141da177e4SLinus Torvalds *request++ = inb(base + PIO_FIFO); 3151da177e4SLinus Torvalds reqlen--; 3161da177e4SLinus Torvalds } 3171da177e4SLinus Torvalds } 3181da177e4SLinus Torvalds } 3191da177e4SLinus Torvalds } 3201da177e4SLinus Torvalds return 0; 3211da177e4SLinus Torvalds } 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds static __inline__ int 3241da177e4SLinus Torvalds SYM53C500_pio_write(int fast_pio, int base, unsigned char *request, unsigned int reqlen) 3251da177e4SLinus Torvalds { 3261da177e4SLinus Torvalds int i = 0; 3271da177e4SLinus Torvalds int len; /* current scsi fifo size */ 3281da177e4SLinus Torvalds 3291da177e4SLinus Torvalds REG1(base); 3301da177e4SLinus Torvalds while (reqlen && !(i & 0x40)) { 3311da177e4SLinus Torvalds i = inb(base + PIO_STATUS); 3321da177e4SLinus Torvalds /* VDEB(printk("pio_status=%x\n", i)); */ 3331da177e4SLinus Torvalds if (i & 0x80) /* error */ 3341da177e4SLinus Torvalds return 0; 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvalds switch (i & 0x1e) { 3371da177e4SLinus Torvalds case 0x10: 3381da177e4SLinus Torvalds len = 128; 3391da177e4SLinus Torvalds break; 3401da177e4SLinus Torvalds case 0x0: 3411da177e4SLinus Torvalds len = 84; 3421da177e4SLinus Torvalds break; 3431da177e4SLinus Torvalds case 0x8: 3441da177e4SLinus Torvalds len = 42; 3451da177e4SLinus Torvalds break; 3461da177e4SLinus Torvalds case 0xc: 3471da177e4SLinus Torvalds len = 1; 3481da177e4SLinus Torvalds break; 3491da177e4SLinus Torvalds default: 3501da177e4SLinus Torvalds case 0xe: 3511da177e4SLinus Torvalds len = 0; 3521da177e4SLinus Torvalds break; 3531da177e4SLinus Torvalds } 3541da177e4SLinus Torvalds 3551da177e4SLinus Torvalds if (len) { 3561da177e4SLinus Torvalds if (len > reqlen) 3571da177e4SLinus Torvalds len = reqlen; 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvalds if (fast_pio && len > 3) { 3601da177e4SLinus Torvalds outsl(base + PIO_FIFO, request, len >> 2); 3611da177e4SLinus Torvalds request += len & 0xfc; 3621da177e4SLinus Torvalds reqlen -= len & 0xfc; 3631da177e4SLinus Torvalds } else { 3641da177e4SLinus Torvalds while (len--) { 3651da177e4SLinus Torvalds outb(*request++, base + PIO_FIFO); 3661da177e4SLinus Torvalds reqlen--; 3671da177e4SLinus Torvalds } 3681da177e4SLinus Torvalds } 3691da177e4SLinus Torvalds } 3701da177e4SLinus Torvalds } 3711da177e4SLinus Torvalds return 0; 3721da177e4SLinus Torvalds } 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds static irqreturn_t 3751da177e4SLinus Torvalds SYM53C500_intr(int irq, void *dev_id, struct pt_regs *regs) 3761da177e4SLinus Torvalds { 3771da177e4SLinus Torvalds unsigned long flags; 3781da177e4SLinus Torvalds struct Scsi_Host *dev = dev_id; 3791da177e4SLinus Torvalds DEB(unsigned char fifo_size;) 3801da177e4SLinus Torvalds DEB(unsigned char seq_reg;) 3811da177e4SLinus Torvalds unsigned char status, int_reg; 3821da177e4SLinus Torvalds unsigned char pio_status; 3831da177e4SLinus Torvalds struct scatterlist *sglist; 3841da177e4SLinus Torvalds unsigned int sgcount; 3851da177e4SLinus Torvalds int port_base = dev->io_port; 3861da177e4SLinus Torvalds struct sym53c500_data *data = 3871da177e4SLinus Torvalds (struct sym53c500_data *)dev->hostdata; 3881da177e4SLinus Torvalds struct scsi_cmnd *curSC = data->current_SC; 3891da177e4SLinus Torvalds int fast_pio = data->fast_pio; 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds spin_lock_irqsave(dev->host_lock, flags); 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvalds VDEB(printk("SYM53C500_intr called\n")); 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds REG1(port_base); 3961da177e4SLinus Torvalds pio_status = inb(port_base + PIO_STATUS); 3971da177e4SLinus Torvalds REG0(port_base); 3981da177e4SLinus Torvalds status = inb(port_base + STAT_REG); 3991da177e4SLinus Torvalds DEB(seq_reg = inb(port_base + SEQ_REG)); 4001da177e4SLinus Torvalds int_reg = inb(port_base + INT_REG); 4011da177e4SLinus Torvalds DEB(fifo_size = inb(port_base + FIFO_FLAGS) & 0x1f); 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvalds #if SYM53C500_DEBUG 4041da177e4SLinus Torvalds printk("status=%02x, seq_reg=%02x, int_reg=%02x, fifo_size=%02x", 4051da177e4SLinus Torvalds status, seq_reg, int_reg, fifo_size); 4061da177e4SLinus Torvalds printk(", pio=%02x\n", pio_status); 4071da177e4SLinus Torvalds #endif /* SYM53C500_DEBUG */ 4081da177e4SLinus Torvalds 4091da177e4SLinus Torvalds if (int_reg & 0x80) { /* SCSI reset intr */ 4101da177e4SLinus Torvalds DEB(printk("SYM53C500: reset intr received\n")); 4111da177e4SLinus Torvalds curSC->result = DID_RESET << 16; 4121da177e4SLinus Torvalds goto idle_out; 4131da177e4SLinus Torvalds } 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds if (pio_status & 0x80) { 4161da177e4SLinus Torvalds printk("SYM53C500: Warning: PIO error!\n"); 4171da177e4SLinus Torvalds curSC->result = DID_ERROR << 16; 4181da177e4SLinus Torvalds goto idle_out; 4191da177e4SLinus Torvalds } 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds if (status & 0x20) { /* Parity error */ 4221da177e4SLinus Torvalds printk("SYM53C500: Warning: parity error!\n"); 4231da177e4SLinus Torvalds curSC->result = DID_PARITY << 16; 4241da177e4SLinus Torvalds goto idle_out; 4251da177e4SLinus Torvalds } 4261da177e4SLinus Torvalds 4271da177e4SLinus Torvalds if (status & 0x40) { /* Gross error */ 4281da177e4SLinus Torvalds printk("SYM53C500: Warning: gross error!\n"); 4291da177e4SLinus Torvalds curSC->result = DID_ERROR << 16; 4301da177e4SLinus Torvalds goto idle_out; 4311da177e4SLinus Torvalds } 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvalds if (int_reg & 0x20) { /* Disconnect */ 4341da177e4SLinus Torvalds DEB(printk("SYM53C500: disconnect intr received\n")); 4351da177e4SLinus Torvalds if (curSC->SCp.phase != message_in) { /* Unexpected disconnect */ 4361da177e4SLinus Torvalds curSC->result = DID_NO_CONNECT << 16; 4371da177e4SLinus Torvalds } else { /* Command complete, return status and message */ 4381da177e4SLinus Torvalds curSC->result = (curSC->SCp.Status & 0xff) 4391da177e4SLinus Torvalds | ((curSC->SCp.Message & 0xff) << 8) | (DID_OK << 16); 4401da177e4SLinus Torvalds } 4411da177e4SLinus Torvalds goto idle_out; 4421da177e4SLinus Torvalds } 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvalds switch (status & 0x07) { /* scsi phase */ 4451da177e4SLinus Torvalds case 0x00: /* DATA-OUT */ 4461da177e4SLinus Torvalds if (int_reg & 0x10) { /* Target requesting info transfer */ 4471da177e4SLinus Torvalds curSC->SCp.phase = data_out; 4481da177e4SLinus Torvalds VDEB(printk("SYM53C500: Data-Out phase\n")); 4491da177e4SLinus Torvalds outb(FLUSH_FIFO, port_base + CMD_REG); 4501da177e4SLinus Torvalds LOAD_DMA_COUNT(port_base, curSC->request_bufflen); /* Max transfer size */ 4511da177e4SLinus Torvalds outb(TRANSFER_INFO | DMA_OP, port_base + CMD_REG); 4521da177e4SLinus Torvalds if (!curSC->use_sg) /* Don't use scatter-gather */ 4531da177e4SLinus Torvalds SYM53C500_pio_write(fast_pio, port_base, curSC->request_buffer, curSC->request_bufflen); 4541da177e4SLinus Torvalds else { /* use scatter-gather */ 4551da177e4SLinus Torvalds sgcount = curSC->use_sg; 4561da177e4SLinus Torvalds sglist = curSC->request_buffer; 4571da177e4SLinus Torvalds while (sgcount--) { 4581da177e4SLinus Torvalds SYM53C500_pio_write(fast_pio, port_base, page_address(sglist->page) + sglist->offset, sglist->length); 4591da177e4SLinus Torvalds sglist++; 4601da177e4SLinus Torvalds } 4611da177e4SLinus Torvalds } 4621da177e4SLinus Torvalds REG0(port_base); 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds break; 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds case 0x01: /* DATA-IN */ 4671da177e4SLinus Torvalds if (int_reg & 0x10) { /* Target requesting info transfer */ 4681da177e4SLinus Torvalds curSC->SCp.phase = data_in; 4691da177e4SLinus Torvalds VDEB(printk("SYM53C500: Data-In phase\n")); 4701da177e4SLinus Torvalds outb(FLUSH_FIFO, port_base + CMD_REG); 4711da177e4SLinus Torvalds LOAD_DMA_COUNT(port_base, curSC->request_bufflen); /* Max transfer size */ 4721da177e4SLinus Torvalds outb(TRANSFER_INFO | DMA_OP, port_base + CMD_REG); 4731da177e4SLinus Torvalds if (!curSC->use_sg) /* Don't use scatter-gather */ 4741da177e4SLinus Torvalds SYM53C500_pio_read(fast_pio, port_base, curSC->request_buffer, curSC->request_bufflen); 4751da177e4SLinus Torvalds else { /* Use scatter-gather */ 4761da177e4SLinus Torvalds sgcount = curSC->use_sg; 4771da177e4SLinus Torvalds sglist = curSC->request_buffer; 4781da177e4SLinus Torvalds while (sgcount--) { 4791da177e4SLinus Torvalds SYM53C500_pio_read(fast_pio, port_base, page_address(sglist->page) + sglist->offset, sglist->length); 4801da177e4SLinus Torvalds sglist++; 4811da177e4SLinus Torvalds } 4821da177e4SLinus Torvalds } 4831da177e4SLinus Torvalds REG0(port_base); 4841da177e4SLinus Torvalds } 4851da177e4SLinus Torvalds break; 4861da177e4SLinus Torvalds 4871da177e4SLinus Torvalds case 0x02: /* COMMAND */ 4881da177e4SLinus Torvalds curSC->SCp.phase = command_ph; 4891da177e4SLinus Torvalds printk("SYM53C500: Warning: Unknown interrupt occurred in command phase!\n"); 4901da177e4SLinus Torvalds break; 4911da177e4SLinus Torvalds 4921da177e4SLinus Torvalds case 0x03: /* STATUS */ 4931da177e4SLinus Torvalds curSC->SCp.phase = status_ph; 4941da177e4SLinus Torvalds VDEB(printk("SYM53C500: Status phase\n")); 4951da177e4SLinus Torvalds outb(FLUSH_FIFO, port_base + CMD_REG); 4961da177e4SLinus Torvalds outb(INIT_CMD_COMPLETE, port_base + CMD_REG); 4971da177e4SLinus Torvalds break; 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds case 0x04: /* Reserved */ 5001da177e4SLinus Torvalds case 0x05: /* Reserved */ 5011da177e4SLinus Torvalds printk("SYM53C500: WARNING: Reserved phase!!!\n"); 5021da177e4SLinus Torvalds break; 5031da177e4SLinus Torvalds 5041da177e4SLinus Torvalds case 0x06: /* MESSAGE-OUT */ 5051da177e4SLinus Torvalds DEB(printk("SYM53C500: Message-Out phase\n")); 5061da177e4SLinus Torvalds curSC->SCp.phase = message_out; 5071da177e4SLinus Torvalds outb(SET_ATN, port_base + CMD_REG); /* Reject the message */ 5081da177e4SLinus Torvalds outb(MSG_ACCEPT, port_base + CMD_REG); 5091da177e4SLinus Torvalds break; 5101da177e4SLinus Torvalds 5111da177e4SLinus Torvalds case 0x07: /* MESSAGE-IN */ 5121da177e4SLinus Torvalds VDEB(printk("SYM53C500: Message-In phase\n")); 5131da177e4SLinus Torvalds curSC->SCp.phase = message_in; 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvalds curSC->SCp.Status = inb(port_base + SCSI_FIFO); 5161da177e4SLinus Torvalds curSC->SCp.Message = inb(port_base + SCSI_FIFO); 5171da177e4SLinus Torvalds 5181da177e4SLinus Torvalds VDEB(printk("SCSI FIFO size=%d\n", inb(port_base + FIFO_FLAGS) & 0x1f)); 5191da177e4SLinus Torvalds DEB(printk("Status = %02x Message = %02x\n", curSC->SCp.Status, curSC->SCp.Message)); 5201da177e4SLinus Torvalds 5211da177e4SLinus Torvalds if (curSC->SCp.Message == SAVE_POINTERS || curSC->SCp.Message == DISCONNECT) { 5221da177e4SLinus Torvalds outb(SET_ATN, port_base + CMD_REG); /* Reject message */ 5231da177e4SLinus Torvalds DEB(printk("Discarding SAVE_POINTERS message\n")); 5241da177e4SLinus Torvalds } 5251da177e4SLinus Torvalds outb(MSG_ACCEPT, port_base + CMD_REG); 5261da177e4SLinus Torvalds break; 5271da177e4SLinus Torvalds } 5281da177e4SLinus Torvalds out: 5291da177e4SLinus Torvalds spin_unlock_irqrestore(dev->host_lock, flags); 5301da177e4SLinus Torvalds return IRQ_HANDLED; 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds idle_out: 5331da177e4SLinus Torvalds curSC->SCp.phase = idle; 5341da177e4SLinus Torvalds curSC->scsi_done(curSC); 5351da177e4SLinus Torvalds goto out; 5361da177e4SLinus Torvalds } 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds static void 5391da177e4SLinus Torvalds SYM53C500_release(dev_link_t *link) 5401da177e4SLinus Torvalds { 5411da177e4SLinus Torvalds struct scsi_info_t *info = link->priv; 5421da177e4SLinus Torvalds struct Scsi_Host *shost = info->host; 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds DEBUG(0, "SYM53C500_release(0x%p)\n", link); 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds /* 5471da177e4SLinus Torvalds * Do this before releasing/freeing resources. 5481da177e4SLinus Torvalds */ 5491da177e4SLinus Torvalds scsi_remove_host(shost); 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds /* 5521da177e4SLinus Torvalds * Interrupts getting hosed on card removal. Try 5531da177e4SLinus Torvalds * the following code, mostly from qlogicfas.c. 5541da177e4SLinus Torvalds */ 5551da177e4SLinus Torvalds if (shost->irq) 5561da177e4SLinus Torvalds free_irq(shost->irq, shost); 5571da177e4SLinus Torvalds if (shost->dma_channel != 0xff) 5581da177e4SLinus Torvalds free_dma(shost->dma_channel); 5591da177e4SLinus Torvalds if (shost->io_port && shost->n_io_port) 5601da177e4SLinus Torvalds release_region(shost->io_port, shost->n_io_port); 5611da177e4SLinus Torvalds 5621da177e4SLinus Torvalds link->dev = NULL; 5631da177e4SLinus Torvalds 5641da177e4SLinus Torvalds pcmcia_release_configuration(link->handle); 5651da177e4SLinus Torvalds pcmcia_release_io(link->handle, &link->io); 5661da177e4SLinus Torvalds pcmcia_release_irq(link->handle, &link->irq); 5671da177e4SLinus Torvalds 5681da177e4SLinus Torvalds link->state &= ~DEV_CONFIG; 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds scsi_host_put(shost); 5711da177e4SLinus Torvalds } /* SYM53C500_release */ 5721da177e4SLinus Torvalds 5731da177e4SLinus Torvalds static const char* 5741da177e4SLinus Torvalds SYM53C500_info(struct Scsi_Host *SChost) 5751da177e4SLinus Torvalds { 5761da177e4SLinus Torvalds static char info_msg[256]; 5771da177e4SLinus Torvalds struct sym53c500_data *data = 5781da177e4SLinus Torvalds (struct sym53c500_data *)SChost->hostdata; 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds DEB(printk("SYM53C500_info called\n")); 5811da177e4SLinus Torvalds (void)snprintf(info_msg, sizeof(info_msg), 5821da177e4SLinus Torvalds "SYM53C500 at 0x%lx, IRQ %d, %s PIO mode.", 5831da177e4SLinus Torvalds SChost->io_port, SChost->irq, data->fast_pio ? "fast" : "slow"); 5841da177e4SLinus Torvalds return (info_msg); 5851da177e4SLinus Torvalds } 5861da177e4SLinus Torvalds 5871da177e4SLinus Torvalds static int 5881da177e4SLinus Torvalds SYM53C500_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)) 5891da177e4SLinus Torvalds { 5901da177e4SLinus Torvalds int i; 5911da177e4SLinus Torvalds int port_base = SCpnt->device->host->io_port; 5921da177e4SLinus Torvalds struct sym53c500_data *data = 5931da177e4SLinus Torvalds (struct sym53c500_data *)SCpnt->device->host->hostdata; 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds VDEB(printk("SYM53C500_queue called\n")); 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds DEB(printk("cmd=%02x, cmd_len=%02x, target=%02x, lun=%02x, bufflen=%d\n", 5981da177e4SLinus Torvalds SCpnt->cmnd[0], SCpnt->cmd_len, SCpnt->device->id, 5991da177e4SLinus Torvalds SCpnt->device->lun, SCpnt->request_bufflen)); 6001da177e4SLinus Torvalds 6011da177e4SLinus Torvalds VDEB(for (i = 0; i < SCpnt->cmd_len; i++) 6021da177e4SLinus Torvalds printk("cmd[%d]=%02x ", i, SCpnt->cmnd[i])); 6031da177e4SLinus Torvalds VDEB(printk("\n")); 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds data->current_SC = SCpnt; 6061da177e4SLinus Torvalds data->current_SC->scsi_done = done; 6071da177e4SLinus Torvalds data->current_SC->SCp.phase = command_ph; 6081da177e4SLinus Torvalds data->current_SC->SCp.Status = 0; 6091da177e4SLinus Torvalds data->current_SC->SCp.Message = 0; 6101da177e4SLinus Torvalds 6111da177e4SLinus Torvalds /* We are locked here already by the mid layer */ 6121da177e4SLinus Torvalds REG0(port_base); 613422c0d61SJeff Garzik outb(scmd_id(SCpnt), port_base + DEST_ID); /* set destination */ 6141da177e4SLinus Torvalds outb(FLUSH_FIFO, port_base + CMD_REG); /* reset the fifos */ 6151da177e4SLinus Torvalds 6161da177e4SLinus Torvalds for (i = 0; i < SCpnt->cmd_len; i++) { 6171da177e4SLinus Torvalds outb(SCpnt->cmnd[i], port_base + SCSI_FIFO); 6181da177e4SLinus Torvalds } 6191da177e4SLinus Torvalds outb(SELECT_NO_ATN, port_base + CMD_REG); 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds return 0; 6221da177e4SLinus Torvalds } 6231da177e4SLinus Torvalds 6241da177e4SLinus Torvalds static int 6251da177e4SLinus Torvalds SYM53C500_host_reset(struct scsi_cmnd *SCpnt) 6261da177e4SLinus Torvalds { 6271da177e4SLinus Torvalds int port_base = SCpnt->device->host->io_port; 6281da177e4SLinus Torvalds 6291da177e4SLinus Torvalds DEB(printk("SYM53C500_host_reset called\n")); 630df0ae249SJeff Garzik spin_lock_irq(SCpnt->device->host->host_lock); 6311da177e4SLinus Torvalds SYM53C500_int_host_reset(port_base); 632df0ae249SJeff Garzik spin_unlock_irq(SCpnt->device->host->host_lock); 6331da177e4SLinus Torvalds 6341da177e4SLinus Torvalds return SUCCESS; 6351da177e4SLinus Torvalds } 6361da177e4SLinus Torvalds 6371da177e4SLinus Torvalds static int 6381da177e4SLinus Torvalds SYM53C500_biosparm(struct scsi_device *disk, 6391da177e4SLinus Torvalds struct block_device *dev, 6401da177e4SLinus Torvalds sector_t capacity, int *info_array) 6411da177e4SLinus Torvalds { 6421da177e4SLinus Torvalds int size; 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds DEB(printk("SYM53C500_biosparm called\n")); 6451da177e4SLinus Torvalds 6461da177e4SLinus Torvalds size = capacity; 6471da177e4SLinus Torvalds info_array[0] = 64; /* heads */ 6481da177e4SLinus Torvalds info_array[1] = 32; /* sectors */ 6491da177e4SLinus Torvalds info_array[2] = size >> 11; /* cylinders */ 6501da177e4SLinus Torvalds if (info_array[2] > 1024) { /* big disk */ 6511da177e4SLinus Torvalds info_array[0] = 255; 6521da177e4SLinus Torvalds info_array[1] = 63; 6531da177e4SLinus Torvalds info_array[2] = size / (255 * 63); 6541da177e4SLinus Torvalds } 6551da177e4SLinus Torvalds return 0; 6561da177e4SLinus Torvalds } 6571da177e4SLinus Torvalds 6581da177e4SLinus Torvalds static ssize_t 6591da177e4SLinus Torvalds SYM53C500_show_pio(struct class_device *cdev, char *buf) 6601da177e4SLinus Torvalds { 6611da177e4SLinus Torvalds struct Scsi_Host *SHp = class_to_shost(cdev); 6621da177e4SLinus Torvalds struct sym53c500_data *data = 6631da177e4SLinus Torvalds (struct sym53c500_data *)SHp->hostdata; 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds return snprintf(buf, 4, "%d\n", data->fast_pio); 6661da177e4SLinus Torvalds } 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds static ssize_t 6691da177e4SLinus Torvalds SYM53C500_store_pio(struct class_device *cdev, const char *buf, size_t count) 6701da177e4SLinus Torvalds { 6711da177e4SLinus Torvalds int pio; 6721da177e4SLinus Torvalds struct Scsi_Host *SHp = class_to_shost(cdev); 6731da177e4SLinus Torvalds struct sym53c500_data *data = 6741da177e4SLinus Torvalds (struct sym53c500_data *)SHp->hostdata; 6751da177e4SLinus Torvalds 6761da177e4SLinus Torvalds pio = simple_strtoul(buf, NULL, 0); 6771da177e4SLinus Torvalds if (pio == 0 || pio == 1) { 6781da177e4SLinus Torvalds data->fast_pio = pio; 6791da177e4SLinus Torvalds return count; 6801da177e4SLinus Torvalds } 6811da177e4SLinus Torvalds else 6821da177e4SLinus Torvalds return -EINVAL; 6831da177e4SLinus Torvalds } 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds /* 6861da177e4SLinus Torvalds * SCSI HBA device attributes we want to 6871da177e4SLinus Torvalds * make available via sysfs. 6881da177e4SLinus Torvalds */ 6891da177e4SLinus Torvalds static struct class_device_attribute SYM53C500_pio_attr = { 6901da177e4SLinus Torvalds .attr = { 6911da177e4SLinus Torvalds .name = "fast_pio", 6921da177e4SLinus Torvalds .mode = (S_IRUGO | S_IWUSR), 6931da177e4SLinus Torvalds }, 6941da177e4SLinus Torvalds .show = SYM53C500_show_pio, 6951da177e4SLinus Torvalds .store = SYM53C500_store_pio, 6961da177e4SLinus Torvalds }; 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds static struct class_device_attribute *SYM53C500_shost_attrs[] = { 6991da177e4SLinus Torvalds &SYM53C500_pio_attr, 7001da177e4SLinus Torvalds NULL, 7011da177e4SLinus Torvalds }; 7021da177e4SLinus Torvalds 7031da177e4SLinus Torvalds /* 7041da177e4SLinus Torvalds * scsi_host_template initializer 7051da177e4SLinus Torvalds */ 7061da177e4SLinus Torvalds static struct scsi_host_template sym53c500_driver_template = { 7071da177e4SLinus Torvalds .module = THIS_MODULE, 7081da177e4SLinus Torvalds .name = "SYM53C500", 7091da177e4SLinus Torvalds .info = SYM53C500_info, 7101da177e4SLinus Torvalds .queuecommand = SYM53C500_queue, 7111da177e4SLinus Torvalds .eh_host_reset_handler = SYM53C500_host_reset, 7121da177e4SLinus Torvalds .bios_param = SYM53C500_biosparm, 7131da177e4SLinus Torvalds .proc_name = "SYM53C500", 7141da177e4SLinus Torvalds .can_queue = 1, 7151da177e4SLinus Torvalds .this_id = 7, 7161da177e4SLinus Torvalds .sg_tablesize = 32, 7171da177e4SLinus Torvalds .cmd_per_lun = 1, 7181da177e4SLinus Torvalds .use_clustering = ENABLE_CLUSTERING, 7191da177e4SLinus Torvalds .shost_attrs = SYM53C500_shost_attrs 7201da177e4SLinus Torvalds }; 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds #define CS_CHECK(fn, ret) \ 7231da177e4SLinus Torvalds do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 7241da177e4SLinus Torvalds 7251da177e4SLinus Torvalds static void 7261da177e4SLinus Torvalds SYM53C500_config(dev_link_t *link) 7271da177e4SLinus Torvalds { 7281da177e4SLinus Torvalds client_handle_t handle = link->handle; 7291da177e4SLinus Torvalds struct scsi_info_t *info = link->priv; 7301da177e4SLinus Torvalds tuple_t tuple; 7311da177e4SLinus Torvalds cisparse_t parse; 7321da177e4SLinus Torvalds int i, last_ret, last_fn; 7331da177e4SLinus Torvalds int irq_level, port_base; 7341da177e4SLinus Torvalds unsigned short tuple_data[32]; 7351da177e4SLinus Torvalds struct Scsi_Host *host; 7361da177e4SLinus Torvalds struct scsi_host_template *tpnt = &sym53c500_driver_template; 7371da177e4SLinus Torvalds struct sym53c500_data *data; 7381da177e4SLinus Torvalds 7391da177e4SLinus Torvalds DEBUG(0, "SYM53C500_config(0x%p)\n", link); 7401da177e4SLinus Torvalds 7411da177e4SLinus Torvalds tuple.TupleData = (cisdata_t *)tuple_data; 7421da177e4SLinus Torvalds tuple.TupleDataMax = 64; 7431da177e4SLinus Torvalds tuple.TupleOffset = 0; 7441da177e4SLinus Torvalds tuple.DesiredTuple = CISTPL_CONFIG; 7451da177e4SLinus Torvalds CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 7461da177e4SLinus Torvalds CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 7471da177e4SLinus Torvalds CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 7481da177e4SLinus Torvalds link->conf.ConfigBase = parse.config.base; 7491da177e4SLinus Torvalds 7501da177e4SLinus Torvalds tuple.DesiredTuple = CISTPL_MANFID; 7511da177e4SLinus Torvalds if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && 7521da177e4SLinus Torvalds (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) 7531da177e4SLinus Torvalds info->manf_id = le16_to_cpu(tuple.TupleData[0]); 7541da177e4SLinus Torvalds 7551da177e4SLinus Torvalds /* Configure card */ 7561da177e4SLinus Torvalds link->state |= DEV_CONFIG; 7571da177e4SLinus Torvalds 7581da177e4SLinus Torvalds tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 7591da177e4SLinus Torvalds CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 7601da177e4SLinus Torvalds while (1) { 7611da177e4SLinus Torvalds if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 7621da177e4SLinus Torvalds pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 7631da177e4SLinus Torvalds goto next_entry; 7641da177e4SLinus Torvalds link->conf.ConfigIndex = parse.cftable_entry.index; 7651da177e4SLinus Torvalds link->io.BasePort1 = parse.cftable_entry.io.win[0].base; 7661da177e4SLinus Torvalds link->io.NumPorts1 = parse.cftable_entry.io.win[0].len; 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds if (link->io.BasePort1 != 0) { 7691da177e4SLinus Torvalds i = pcmcia_request_io(handle, &link->io); 7701da177e4SLinus Torvalds if (i == CS_SUCCESS) 7711da177e4SLinus Torvalds break; 7721da177e4SLinus Torvalds } 7731da177e4SLinus Torvalds next_entry: 7741da177e4SLinus Torvalds CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 7751da177e4SLinus Torvalds } 7761da177e4SLinus Torvalds 7771da177e4SLinus Torvalds CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 7781da177e4SLinus Torvalds CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds /* 7811da177e4SLinus Torvalds * That's the trouble with copying liberally from another driver. 7821da177e4SLinus Torvalds * Some things probably aren't relevant, and I suspect this entire 7831da177e4SLinus Torvalds * section dealing with manufacturer IDs can be scrapped. --rct 7841da177e4SLinus Torvalds */ 7851da177e4SLinus Torvalds if ((info->manf_id == MANFID_MACNICA) || 7861da177e4SLinus Torvalds (info->manf_id == MANFID_PIONEER) || 7871da177e4SLinus Torvalds (info->manf_id == 0x0098)) { 7881da177e4SLinus Torvalds /* set ATAcmd */ 7891da177e4SLinus Torvalds outb(0xb4, link->io.BasePort1 + 0xd); 7901da177e4SLinus Torvalds outb(0x24, link->io.BasePort1 + 0x9); 7911da177e4SLinus Torvalds outb(0x04, link->io.BasePort1 + 0xd); 7921da177e4SLinus Torvalds } 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds /* 7951da177e4SLinus Torvalds * irq_level == 0 implies tpnt->can_queue == 0, which 7961da177e4SLinus Torvalds * is not supported in 2.6. Thus, only irq_level > 0 7971da177e4SLinus Torvalds * will be allowed. 7981da177e4SLinus Torvalds * 7991da177e4SLinus Torvalds * Possible port_base values are as follows: 8001da177e4SLinus Torvalds * 8011da177e4SLinus Torvalds * 0x130, 0x230, 0x280, 0x290, 8021da177e4SLinus Torvalds * 0x320, 0x330, 0x340, 0x350 8031da177e4SLinus Torvalds */ 8041da177e4SLinus Torvalds port_base = link->io.BasePort1; 8051da177e4SLinus Torvalds irq_level = link->irq.AssignedIRQ; 8061da177e4SLinus Torvalds 8071da177e4SLinus Torvalds DEB(printk("SYM53C500: port_base=0x%x, irq=%d, fast_pio=%d\n", 8081da177e4SLinus Torvalds port_base, irq_level, USE_FAST_PIO);) 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds chip_init(port_base); 8111da177e4SLinus Torvalds 8121da177e4SLinus Torvalds host = scsi_host_alloc(tpnt, sizeof(struct sym53c500_data)); 8131da177e4SLinus Torvalds if (!host) { 8141da177e4SLinus Torvalds printk("SYM53C500: Unable to register host, giving up.\n"); 8151da177e4SLinus Torvalds goto err_release; 8161da177e4SLinus Torvalds } 8171da177e4SLinus Torvalds 8181da177e4SLinus Torvalds data = (struct sym53c500_data *)host->hostdata; 8191da177e4SLinus Torvalds 8201da177e4SLinus Torvalds if (irq_level > 0) { 8211da177e4SLinus Torvalds if (request_irq(irq_level, SYM53C500_intr, SA_SHIRQ, "SYM53C500", host)) { 8221da177e4SLinus Torvalds printk("SYM53C500: unable to allocate IRQ %d\n", irq_level); 8231da177e4SLinus Torvalds goto err_free_scsi; 8241da177e4SLinus Torvalds } 8251da177e4SLinus Torvalds DEB(printk("SYM53C500: allocated IRQ %d\n", irq_level)); 8261da177e4SLinus Torvalds } else if (irq_level == 0) { 8271da177e4SLinus Torvalds DEB(printk("SYM53C500: No interrupts detected\n")); 8281da177e4SLinus Torvalds goto err_free_scsi; 8291da177e4SLinus Torvalds } else { 8301da177e4SLinus Torvalds DEB(printk("SYM53C500: Shouldn't get here!\n")); 8311da177e4SLinus Torvalds goto err_free_scsi; 8321da177e4SLinus Torvalds } 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds host->unique_id = port_base; 8351da177e4SLinus Torvalds host->irq = irq_level; 8361da177e4SLinus Torvalds host->io_port = port_base; 8371da177e4SLinus Torvalds host->n_io_port = 0x10; 8381da177e4SLinus Torvalds host->dma_channel = -1; 8391da177e4SLinus Torvalds 8401da177e4SLinus Torvalds /* 8411da177e4SLinus Torvalds * Note fast_pio is set to USE_FAST_PIO by 8421da177e4SLinus Torvalds * default, but can be changed via "sysfs". 8431da177e4SLinus Torvalds */ 8441da177e4SLinus Torvalds data->fast_pio = USE_FAST_PIO; 8451da177e4SLinus Torvalds 8461da177e4SLinus Torvalds sprintf(info->node.dev_name, "scsi%d", host->host_no); 8471da177e4SLinus Torvalds link->dev = &info->node; 8481da177e4SLinus Torvalds info->host = host; 8491da177e4SLinus Torvalds 8501da177e4SLinus Torvalds if (scsi_add_host(host, NULL)) 8511da177e4SLinus Torvalds goto err_free_irq; 8521da177e4SLinus Torvalds 8531da177e4SLinus Torvalds scsi_scan_host(host); 8541da177e4SLinus Torvalds 8551da177e4SLinus Torvalds goto out; /* SUCCESS */ 8561da177e4SLinus Torvalds 8571da177e4SLinus Torvalds err_free_irq: 8581da177e4SLinus Torvalds free_irq(irq_level, host); 8591da177e4SLinus Torvalds err_free_scsi: 8601da177e4SLinus Torvalds scsi_host_put(host); 8611da177e4SLinus Torvalds err_release: 8621da177e4SLinus Torvalds release_region(port_base, 0x10); 8631da177e4SLinus Torvalds printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n"); 8641da177e4SLinus Torvalds 8651da177e4SLinus Torvalds out: 8661da177e4SLinus Torvalds link->state &= ~DEV_CONFIG_PENDING; 8671da177e4SLinus Torvalds return; 8681da177e4SLinus Torvalds 8691da177e4SLinus Torvalds cs_failed: 8701da177e4SLinus Torvalds cs_error(link->handle, last_fn, last_ret); 8711da177e4SLinus Torvalds SYM53C500_release(link); 8721da177e4SLinus Torvalds return; 8731da177e4SLinus Torvalds } /* SYM53C500_config */ 8741da177e4SLinus Torvalds 87598e4c28bSDominik Brodowski static int sym53c500_suspend(struct pcmcia_device *dev) 8761da177e4SLinus Torvalds { 87798e4c28bSDominik Brodowski dev_link_t *link = dev_to_instance(dev); 8781da177e4SLinus Torvalds 8791da177e4SLinus Torvalds link->state |= DEV_SUSPEND; 8801da177e4SLinus Torvalds if (link->state & DEV_CONFIG) 8811da177e4SLinus Torvalds pcmcia_release_configuration(link->handle); 88298e4c28bSDominik Brodowski 88398e4c28bSDominik Brodowski return 0; 88498e4c28bSDominik Brodowski } 88598e4c28bSDominik Brodowski 88698e4c28bSDominik Brodowski static int sym53c500_resume(struct pcmcia_device *dev) 88798e4c28bSDominik Brodowski { 88898e4c28bSDominik Brodowski dev_link_t *link = dev_to_instance(dev); 88998e4c28bSDominik Brodowski struct scsi_info_t *info = link->priv; 89098e4c28bSDominik Brodowski 8911da177e4SLinus Torvalds link->state &= ~DEV_SUSPEND; 8921da177e4SLinus Torvalds if (link->state & DEV_CONFIG) { 8931da177e4SLinus Torvalds pcmcia_request_configuration(link->handle, &link->conf); 89498e4c28bSDominik Brodowski 8951da177e4SLinus Torvalds /* See earlier comment about manufacturer IDs. */ 8961da177e4SLinus Torvalds if ((info->manf_id == MANFID_MACNICA) || 8971da177e4SLinus Torvalds (info->manf_id == MANFID_PIONEER) || 8981da177e4SLinus Torvalds (info->manf_id == 0x0098)) { 8991da177e4SLinus Torvalds outb(0x80, link->io.BasePort1 + 0xd); 9001da177e4SLinus Torvalds outb(0x24, link->io.BasePort1 + 0x9); 9011da177e4SLinus Torvalds outb(0x04, link->io.BasePort1 + 0xd); 9021da177e4SLinus Torvalds } 9031da177e4SLinus Torvalds /* 9041da177e4SLinus Torvalds * If things don't work after a "resume", 9051da177e4SLinus Torvalds * this is a good place to start looking. 9061da177e4SLinus Torvalds */ 9071da177e4SLinus Torvalds SYM53C500_int_host_reset(link->io.BasePort1); 9081da177e4SLinus Torvalds } 90998e4c28bSDominik Brodowski 91098e4c28bSDominik Brodowski return 0; 91198e4c28bSDominik Brodowski } 91298e4c28bSDominik Brodowski 91398e4c28bSDominik Brodowski static int 91498e4c28bSDominik Brodowski SYM53C500_event(event_t event, int priority, event_callback_args_t *args) 91598e4c28bSDominik Brodowski { 91698e4c28bSDominik Brodowski dev_link_t *link = args->client_data; 91798e4c28bSDominik Brodowski 91898e4c28bSDominik Brodowski DEBUG(1, "SYM53C500_event(0x%06x)\n", event); 91998e4c28bSDominik Brodowski 92098e4c28bSDominik Brodowski switch (event) { 92198e4c28bSDominik Brodowski case CS_EVENT_CARD_INSERTION: 92298e4c28bSDominik Brodowski link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 92398e4c28bSDominik Brodowski SYM53C500_config(link); 9241da177e4SLinus Torvalds break; 9251da177e4SLinus Torvalds } 9261da177e4SLinus Torvalds return 0; 9271da177e4SLinus Torvalds } /* SYM53C500_event */ 9281da177e4SLinus Torvalds 9291da177e4SLinus Torvalds static void 930*cc3b4866SDominik Brodowski SYM53C500_detach(struct pcmcia_device *p_dev) 9311da177e4SLinus Torvalds { 932*cc3b4866SDominik Brodowski dev_link_t *link = dev_to_instance(p_dev); 9331da177e4SLinus Torvalds dev_link_t **linkp; 9341da177e4SLinus Torvalds 9351da177e4SLinus Torvalds DEBUG(0, "SYM53C500_detach(0x%p)\n", link); 9361da177e4SLinus Torvalds 9371da177e4SLinus Torvalds /* Locate device structure */ 9381da177e4SLinus Torvalds for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) 9391da177e4SLinus Torvalds if (*linkp == link) 9401da177e4SLinus Torvalds break; 9411da177e4SLinus Torvalds if (*linkp == NULL) 9421da177e4SLinus Torvalds return; 9431da177e4SLinus Torvalds 9441da177e4SLinus Torvalds if (link->state & DEV_CONFIG) 9451da177e4SLinus Torvalds SYM53C500_release(link); 9461da177e4SLinus Torvalds 9471da177e4SLinus Torvalds /* Unlink device structure, free bits. */ 9481da177e4SLinus Torvalds *linkp = link->next; 9491da177e4SLinus Torvalds kfree(link->priv); 9501da177e4SLinus Torvalds link->priv = NULL; 9511da177e4SLinus Torvalds } /* SYM53C500_detach */ 9521da177e4SLinus Torvalds 9531da177e4SLinus Torvalds static dev_link_t * 9541da177e4SLinus Torvalds SYM53C500_attach(void) 9551da177e4SLinus Torvalds { 9561da177e4SLinus Torvalds struct scsi_info_t *info; 9571da177e4SLinus Torvalds client_reg_t client_reg; 9581da177e4SLinus Torvalds dev_link_t *link; 9591da177e4SLinus Torvalds int ret; 9601da177e4SLinus Torvalds 9611da177e4SLinus Torvalds DEBUG(0, "SYM53C500_attach()\n"); 9621da177e4SLinus Torvalds 9631da177e4SLinus Torvalds /* Create new SCSI device */ 9641da177e4SLinus Torvalds info = kmalloc(sizeof(*info), GFP_KERNEL); 9651da177e4SLinus Torvalds if (!info) 9661da177e4SLinus Torvalds return NULL; 9671da177e4SLinus Torvalds memset(info, 0, sizeof(*info)); 9681da177e4SLinus Torvalds link = &info->link; 9691da177e4SLinus Torvalds link->priv = info; 9701da177e4SLinus Torvalds link->io.NumPorts1 = 16; 9711da177e4SLinus Torvalds link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 9721da177e4SLinus Torvalds link->io.IOAddrLines = 10; 9731da177e4SLinus Torvalds link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 9741da177e4SLinus Torvalds link->irq.IRQInfo1 = IRQ_LEVEL_ID; 9751da177e4SLinus Torvalds link->conf.Attributes = CONF_ENABLE_IRQ; 9761da177e4SLinus Torvalds link->conf.Vcc = 50; 9771da177e4SLinus Torvalds link->conf.IntType = INT_MEMORY_AND_IO; 9781da177e4SLinus Torvalds link->conf.Present = PRESENT_OPTION; 9791da177e4SLinus Torvalds 9801da177e4SLinus Torvalds /* Register with Card Services */ 9811da177e4SLinus Torvalds link->next = dev_list; 9821da177e4SLinus Torvalds dev_list = link; 9831da177e4SLinus Torvalds client_reg.dev_info = &dev_info; 9841da177e4SLinus Torvalds client_reg.Version = 0x0210; 9851da177e4SLinus Torvalds client_reg.event_callback_args.client_data = link; 9861da177e4SLinus Torvalds ret = pcmcia_register_client(&link->handle, &client_reg); 9871da177e4SLinus Torvalds if (ret != 0) { 9881da177e4SLinus Torvalds cs_error(link->handle, RegisterClient, ret); 989*cc3b4866SDominik Brodowski SYM53C500_detach(link->handle); 9901da177e4SLinus Torvalds return NULL; 9911da177e4SLinus Torvalds } 9921da177e4SLinus Torvalds 9931da177e4SLinus Torvalds return link; 9941da177e4SLinus Torvalds } /* SYM53C500_attach */ 9951da177e4SLinus Torvalds 9961da177e4SLinus Torvalds MODULE_AUTHOR("Bob Tracy <rct@frus.com>"); 9971da177e4SLinus Torvalds MODULE_DESCRIPTION("SYM53C500 PCMCIA SCSI driver"); 9981da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 9991da177e4SLinus Torvalds 10002a355d07SDominik Brodowski static struct pcmcia_device_id sym53c500_ids[] = { 10012a355d07SDominik Brodowski PCMCIA_DEVICE_PROD_ID12("BASICS by New Media Corporation", "SCSI Sym53C500", 0x23c78a9d, 0x0099e7f7), 10022a355d07SDominik Brodowski PCMCIA_DEVICE_PROD_ID12("New Media Corporation", "SCSI Bus Toaster Sym53C500", 0x085a850b, 0x45432eb8), 10032a355d07SDominik Brodowski PCMCIA_DEVICE_PROD_ID2("SCSI9000", 0x21648f44), 10042a355d07SDominik Brodowski PCMCIA_DEVICE_NULL, 10052a355d07SDominik Brodowski }; 10062a355d07SDominik Brodowski MODULE_DEVICE_TABLE(pcmcia, sym53c500_ids); 10072a355d07SDominik Brodowski 10081da177e4SLinus Torvalds static struct pcmcia_driver sym53c500_cs_driver = { 10091da177e4SLinus Torvalds .owner = THIS_MODULE, 10101da177e4SLinus Torvalds .drv = { 10111da177e4SLinus Torvalds .name = "sym53c500_cs", 10121da177e4SLinus Torvalds }, 10131da177e4SLinus Torvalds .attach = SYM53C500_attach, 10141e212f36SDominik Brodowski .event = SYM53C500_event, 1015*cc3b4866SDominik Brodowski .remove = SYM53C500_detach, 10162a355d07SDominik Brodowski .id_table = sym53c500_ids, 101798e4c28bSDominik Brodowski .suspend = sym53c500_suspend, 101898e4c28bSDominik Brodowski .resume = sym53c500_resume, 10191da177e4SLinus Torvalds }; 10201da177e4SLinus Torvalds 10211da177e4SLinus Torvalds static int __init 10221da177e4SLinus Torvalds init_sym53c500_cs(void) 10231da177e4SLinus Torvalds { 10241da177e4SLinus Torvalds return pcmcia_register_driver(&sym53c500_cs_driver); 10251da177e4SLinus Torvalds } 10261da177e4SLinus Torvalds 10271da177e4SLinus Torvalds static void __exit 10281da177e4SLinus Torvalds exit_sym53c500_cs(void) 10291da177e4SLinus Torvalds { 10301da177e4SLinus Torvalds pcmcia_unregister_driver(&sym53c500_cs_driver); 10311da177e4SLinus Torvalds } 10321da177e4SLinus Torvalds 10331da177e4SLinus Torvalds module_init(init_sym53c500_cs); 10341da177e4SLinus Torvalds module_exit(exit_sym53c500_cs); 1035