18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 1996 John Shifflett, GeoLog Consulting 48c2ecf20Sopenharmony_ci * john@geolog.com 58c2ecf20Sopenharmony_ci * jshiffle@netcom.com 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* 98c2ecf20Sopenharmony_ci * Drew Eckhardt's excellent 'Generic NCR5380' sources from Linux-PC 108c2ecf20Sopenharmony_ci * provided much of the inspiration and some of the code for this 118c2ecf20Sopenharmony_ci * driver. Everything I know about Amiga DMA was gleaned from careful 128c2ecf20Sopenharmony_ci * reading of Hamish Mcdonald's original wd33c93 driver; in fact, I 138c2ecf20Sopenharmony_ci * borrowed shamelessly from all over that source. Thanks Hamish! 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * _This_ driver is (I feel) an improvement over the old one in 168c2ecf20Sopenharmony_ci * several respects: 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * - Target Disconnection/Reconnection is now supported. Any 198c2ecf20Sopenharmony_ci * system with more than one device active on the SCSI bus 208c2ecf20Sopenharmony_ci * will benefit from this. The driver defaults to what I 218c2ecf20Sopenharmony_ci * call 'adaptive disconnect' - meaning that each command 228c2ecf20Sopenharmony_ci * is evaluated individually as to whether or not it should 238c2ecf20Sopenharmony_ci * be run with the option to disconnect/reselect (if the 248c2ecf20Sopenharmony_ci * device chooses), or as a "SCSI-bus-hog". 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci * - Synchronous data transfers are now supported. Because of 278c2ecf20Sopenharmony_ci * a few devices that choke after telling the driver that 288c2ecf20Sopenharmony_ci * they can do sync transfers, we don't automatically use 298c2ecf20Sopenharmony_ci * this faster protocol - it can be enabled via the command- 308c2ecf20Sopenharmony_ci * line on a device-by-device basis. 318c2ecf20Sopenharmony_ci * 328c2ecf20Sopenharmony_ci * - Runtime operating parameters can now be specified through 338c2ecf20Sopenharmony_ci * the 'amiboot' or the 'insmod' command line. For amiboot do: 348c2ecf20Sopenharmony_ci * "amiboot [usual stuff] wd33c93=blah,blah,blah" 358c2ecf20Sopenharmony_ci * The defaults should be good for most people. See the comment 368c2ecf20Sopenharmony_ci * for 'setup_strings' below for more details. 378c2ecf20Sopenharmony_ci * 388c2ecf20Sopenharmony_ci * - The old driver relied exclusively on what the Western Digital 398c2ecf20Sopenharmony_ci * docs call "Combination Level 2 Commands", which are a great 408c2ecf20Sopenharmony_ci * idea in that the CPU is relieved of a lot of interrupt 418c2ecf20Sopenharmony_ci * overhead. However, by accepting a certain (user-settable) 428c2ecf20Sopenharmony_ci * amount of additional interrupts, this driver achieves 438c2ecf20Sopenharmony_ci * better control over the SCSI bus, and data transfers are 448c2ecf20Sopenharmony_ci * almost as fast while being much easier to define, track, 458c2ecf20Sopenharmony_ci * and debug. 468c2ecf20Sopenharmony_ci * 478c2ecf20Sopenharmony_ci * 488c2ecf20Sopenharmony_ci * TODO: 498c2ecf20Sopenharmony_ci * more speed. linked commands. 508c2ecf20Sopenharmony_ci * 518c2ecf20Sopenharmony_ci * 528c2ecf20Sopenharmony_ci * People with bug reports, wish-lists, complaints, comments, 538c2ecf20Sopenharmony_ci * or improvements are asked to pah-leeez email me (John Shifflett) 548c2ecf20Sopenharmony_ci * at john@geolog.com or jshiffle@netcom.com! I'm anxious to get 558c2ecf20Sopenharmony_ci * this thing into as good a shape as possible, and I'm positive 568c2ecf20Sopenharmony_ci * there are lots of lurking bugs and "Stupid Places". 578c2ecf20Sopenharmony_ci * 588c2ecf20Sopenharmony_ci * Updates: 598c2ecf20Sopenharmony_ci * 608c2ecf20Sopenharmony_ci * Added support for pre -A chips, which don't have advanced features 618c2ecf20Sopenharmony_ci * and will generate CSR_RESEL rather than CSR_RESEL_AM. 628c2ecf20Sopenharmony_ci * Richard Hirst <richard@sleepie.demon.co.uk> August 2000 638c2ecf20Sopenharmony_ci * 648c2ecf20Sopenharmony_ci * Added support for Burst Mode DMA and Fast SCSI. Enabled the use of 658c2ecf20Sopenharmony_ci * default_sx_per for asynchronous data transfers. Added adjustment 668c2ecf20Sopenharmony_ci * of transfer periods in sx_table to the actual input-clock. 678c2ecf20Sopenharmony_ci * peter fuerst <post@pfrst.de> February 2007 688c2ecf20Sopenharmony_ci */ 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#include <linux/module.h> 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#include <linux/string.h> 738c2ecf20Sopenharmony_ci#include <linux/delay.h> 748c2ecf20Sopenharmony_ci#include <linux/init.h> 758c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 768c2ecf20Sopenharmony_ci#include <linux/blkdev.h> 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci#include <scsi/scsi.h> 798c2ecf20Sopenharmony_ci#include <scsi/scsi_cmnd.h> 808c2ecf20Sopenharmony_ci#include <scsi/scsi_device.h> 818c2ecf20Sopenharmony_ci#include <scsi/scsi_host.h> 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci#include <asm/irq.h> 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#include "wd33c93.h" 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#define optimum_sx_per(hostdata) (hostdata)->sx_table[1].period_ns 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#define WD33C93_VERSION "1.26++" 918c2ecf20Sopenharmony_ci#define WD33C93_DATE "10/Feb/2007" 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ciMODULE_AUTHOR("John Shifflett"); 948c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Generic WD33C93 SCSI driver"); 958c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/* 988c2ecf20Sopenharmony_ci * 'setup_strings' is a single string used to pass operating parameters and 998c2ecf20Sopenharmony_ci * settings from the kernel/module command-line to the driver. 'setup_args[]' 1008c2ecf20Sopenharmony_ci * is an array of strings that define the compile-time default values for 1018c2ecf20Sopenharmony_ci * these settings. If Linux boots with an amiboot or insmod command-line, 1028c2ecf20Sopenharmony_ci * those settings are combined with 'setup_args[]'. Note that amiboot 1038c2ecf20Sopenharmony_ci * command-lines are prefixed with "wd33c93=" while insmod uses a 1048c2ecf20Sopenharmony_ci * "setup_strings=" prefix. The driver recognizes the following keywords 1058c2ecf20Sopenharmony_ci * (lower case required) and arguments: 1068c2ecf20Sopenharmony_ci * 1078c2ecf20Sopenharmony_ci * - nosync:bitmask -bitmask is a byte where the 1st 7 bits correspond with 1088c2ecf20Sopenharmony_ci * the 7 possible SCSI devices. Set a bit to negotiate for 1098c2ecf20Sopenharmony_ci * asynchronous transfers on that device. To maintain 1108c2ecf20Sopenharmony_ci * backwards compatibility, a command-line such as 1118c2ecf20Sopenharmony_ci * "wd33c93=255" will be automatically translated to 1128c2ecf20Sopenharmony_ci * "wd33c93=nosync:0xff". 1138c2ecf20Sopenharmony_ci * - nodma:x -x = 1 to disable DMA, x = 0 to enable it. Argument is 1148c2ecf20Sopenharmony_ci * optional - if not present, same as "nodma:1". 1158c2ecf20Sopenharmony_ci * - period:ns -ns is the minimum # of nanoseconds in a SCSI data transfer 1168c2ecf20Sopenharmony_ci * period. Default is 500; acceptable values are 250 - 1000. 1178c2ecf20Sopenharmony_ci * - disconnect:x -x = 0 to never allow disconnects, 2 to always allow them. 1188c2ecf20Sopenharmony_ci * x = 1 does 'adaptive' disconnects, which is the default 1198c2ecf20Sopenharmony_ci * and generally the best choice. 1208c2ecf20Sopenharmony_ci * - debug:x -If 'DEBUGGING_ON' is defined, x is a bit mask that causes 1218c2ecf20Sopenharmony_ci * various types of debug output to printed - see the DB_xxx 1228c2ecf20Sopenharmony_ci * defines in wd33c93.h 1238c2ecf20Sopenharmony_ci * - clock:x -x = clock input in MHz for WD33c93 chip. Normal values 1248c2ecf20Sopenharmony_ci * would be from 8 through 20. Default is 8. 1258c2ecf20Sopenharmony_ci * - burst:x -x = 1 to use Burst Mode (or Demand-Mode) DMA, x = 0 to use 1268c2ecf20Sopenharmony_ci * Single Byte DMA, which is the default. Argument is 1278c2ecf20Sopenharmony_ci * optional - if not present, same as "burst:1". 1288c2ecf20Sopenharmony_ci * - fast:x -x = 1 to enable Fast SCSI, which is only effective with 1298c2ecf20Sopenharmony_ci * input-clock divisor 4 (WD33C93_FS_16_20), x = 0 to disable 1308c2ecf20Sopenharmony_ci * it, which is the default. Argument is optional - if not 1318c2ecf20Sopenharmony_ci * present, same as "fast:1". 1328c2ecf20Sopenharmony_ci * - next -No argument. Used to separate blocks of keywords when 1338c2ecf20Sopenharmony_ci * there's more than one host adapter in the system. 1348c2ecf20Sopenharmony_ci * 1358c2ecf20Sopenharmony_ci * Syntax Notes: 1368c2ecf20Sopenharmony_ci * - Numeric arguments can be decimal or the '0x' form of hex notation. There 1378c2ecf20Sopenharmony_ci * _must_ be a colon between a keyword and its numeric argument, with no 1388c2ecf20Sopenharmony_ci * spaces. 1398c2ecf20Sopenharmony_ci * - Keywords are separated by commas, no spaces, in the standard kernel 1408c2ecf20Sopenharmony_ci * command-line manner. 1418c2ecf20Sopenharmony_ci * - A keyword in the 'nth' comma-separated command-line member will overwrite 1428c2ecf20Sopenharmony_ci * the 'nth' element of setup_args[]. A blank command-line member (in 1438c2ecf20Sopenharmony_ci * other words, a comma with no preceding keyword) will _not_ overwrite 1448c2ecf20Sopenharmony_ci * the corresponding setup_args[] element. 1458c2ecf20Sopenharmony_ci * - If a keyword is used more than once, the first one applies to the first 1468c2ecf20Sopenharmony_ci * SCSI host found, the second to the second card, etc, unless the 'next' 1478c2ecf20Sopenharmony_ci * keyword is used to change the order. 1488c2ecf20Sopenharmony_ci * 1498c2ecf20Sopenharmony_ci * Some amiboot examples (for insmod, use 'setup_strings' instead of 'wd33c93'): 1508c2ecf20Sopenharmony_ci * - wd33c93=nosync:255 1518c2ecf20Sopenharmony_ci * - wd33c93=nodma 1528c2ecf20Sopenharmony_ci * - wd33c93=nodma:1 1538c2ecf20Sopenharmony_ci * - wd33c93=disconnect:2,nosync:0x08,period:250 1548c2ecf20Sopenharmony_ci * - wd33c93=debug:0x1c 1558c2ecf20Sopenharmony_ci */ 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci/* Normally, no defaults are specified */ 1588c2ecf20Sopenharmony_cistatic char *setup_args[] = { "", "", "", "", "", "", "", "", "", "" }; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_cistatic char *setup_strings; 1618c2ecf20Sopenharmony_cimodule_param(setup_strings, charp, 0); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistatic void wd33c93_execute(struct Scsi_Host *instance); 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci#ifdef CONFIG_WD33C93_PIO 1668c2ecf20Sopenharmony_cistatic inline uchar 1678c2ecf20Sopenharmony_ciread_wd33c93(const wd33c93_regs regs, uchar reg_num) 1688c2ecf20Sopenharmony_ci{ 1698c2ecf20Sopenharmony_ci uchar data; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci outb(reg_num, regs.SASR); 1728c2ecf20Sopenharmony_ci data = inb(regs.SCMD); 1738c2ecf20Sopenharmony_ci return data; 1748c2ecf20Sopenharmony_ci} 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_cistatic inline unsigned long 1778c2ecf20Sopenharmony_ciread_wd33c93_count(const wd33c93_regs regs) 1788c2ecf20Sopenharmony_ci{ 1798c2ecf20Sopenharmony_ci unsigned long value; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci outb(WD_TRANSFER_COUNT_MSB, regs.SASR); 1828c2ecf20Sopenharmony_ci value = inb(regs.SCMD) << 16; 1838c2ecf20Sopenharmony_ci value |= inb(regs.SCMD) << 8; 1848c2ecf20Sopenharmony_ci value |= inb(regs.SCMD); 1858c2ecf20Sopenharmony_ci return value; 1868c2ecf20Sopenharmony_ci} 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_cistatic inline uchar 1898c2ecf20Sopenharmony_ciread_aux_stat(const wd33c93_regs regs) 1908c2ecf20Sopenharmony_ci{ 1918c2ecf20Sopenharmony_ci return inb(regs.SASR); 1928c2ecf20Sopenharmony_ci} 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cistatic inline void 1958c2ecf20Sopenharmony_ciwrite_wd33c93(const wd33c93_regs regs, uchar reg_num, uchar value) 1968c2ecf20Sopenharmony_ci{ 1978c2ecf20Sopenharmony_ci outb(reg_num, regs.SASR); 1988c2ecf20Sopenharmony_ci outb(value, regs.SCMD); 1998c2ecf20Sopenharmony_ci} 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cistatic inline void 2028c2ecf20Sopenharmony_ciwrite_wd33c93_count(const wd33c93_regs regs, unsigned long value) 2038c2ecf20Sopenharmony_ci{ 2048c2ecf20Sopenharmony_ci outb(WD_TRANSFER_COUNT_MSB, regs.SASR); 2058c2ecf20Sopenharmony_ci outb((value >> 16) & 0xff, regs.SCMD); 2068c2ecf20Sopenharmony_ci outb((value >> 8) & 0xff, regs.SCMD); 2078c2ecf20Sopenharmony_ci outb( value & 0xff, regs.SCMD); 2088c2ecf20Sopenharmony_ci} 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci#define write_wd33c93_cmd(regs, cmd) \ 2118c2ecf20Sopenharmony_ci write_wd33c93((regs), WD_COMMAND, (cmd)) 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_cistatic inline void 2148c2ecf20Sopenharmony_ciwrite_wd33c93_cdb(const wd33c93_regs regs, uint len, uchar cmnd[]) 2158c2ecf20Sopenharmony_ci{ 2168c2ecf20Sopenharmony_ci int i; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci outb(WD_CDB_1, regs.SASR); 2198c2ecf20Sopenharmony_ci for (i=0; i<len; i++) 2208c2ecf20Sopenharmony_ci outb(cmnd[i], regs.SCMD); 2218c2ecf20Sopenharmony_ci} 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci#else /* CONFIG_WD33C93_PIO */ 2248c2ecf20Sopenharmony_cistatic inline uchar 2258c2ecf20Sopenharmony_ciread_wd33c93(const wd33c93_regs regs, uchar reg_num) 2268c2ecf20Sopenharmony_ci{ 2278c2ecf20Sopenharmony_ci *regs.SASR = reg_num; 2288c2ecf20Sopenharmony_ci mb(); 2298c2ecf20Sopenharmony_ci return (*regs.SCMD); 2308c2ecf20Sopenharmony_ci} 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistatic unsigned long 2338c2ecf20Sopenharmony_ciread_wd33c93_count(const wd33c93_regs regs) 2348c2ecf20Sopenharmony_ci{ 2358c2ecf20Sopenharmony_ci unsigned long value; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci *regs.SASR = WD_TRANSFER_COUNT_MSB; 2388c2ecf20Sopenharmony_ci mb(); 2398c2ecf20Sopenharmony_ci value = *regs.SCMD << 16; 2408c2ecf20Sopenharmony_ci value |= *regs.SCMD << 8; 2418c2ecf20Sopenharmony_ci value |= *regs.SCMD; 2428c2ecf20Sopenharmony_ci mb(); 2438c2ecf20Sopenharmony_ci return value; 2448c2ecf20Sopenharmony_ci} 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_cistatic inline uchar 2478c2ecf20Sopenharmony_ciread_aux_stat(const wd33c93_regs regs) 2488c2ecf20Sopenharmony_ci{ 2498c2ecf20Sopenharmony_ci return *regs.SASR; 2508c2ecf20Sopenharmony_ci} 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_cistatic inline void 2538c2ecf20Sopenharmony_ciwrite_wd33c93(const wd33c93_regs regs, uchar reg_num, uchar value) 2548c2ecf20Sopenharmony_ci{ 2558c2ecf20Sopenharmony_ci *regs.SASR = reg_num; 2568c2ecf20Sopenharmony_ci mb(); 2578c2ecf20Sopenharmony_ci *regs.SCMD = value; 2588c2ecf20Sopenharmony_ci mb(); 2598c2ecf20Sopenharmony_ci} 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_cistatic void 2628c2ecf20Sopenharmony_ciwrite_wd33c93_count(const wd33c93_regs regs, unsigned long value) 2638c2ecf20Sopenharmony_ci{ 2648c2ecf20Sopenharmony_ci *regs.SASR = WD_TRANSFER_COUNT_MSB; 2658c2ecf20Sopenharmony_ci mb(); 2668c2ecf20Sopenharmony_ci *regs.SCMD = value >> 16; 2678c2ecf20Sopenharmony_ci *regs.SCMD = value >> 8; 2688c2ecf20Sopenharmony_ci *regs.SCMD = value; 2698c2ecf20Sopenharmony_ci mb(); 2708c2ecf20Sopenharmony_ci} 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_cistatic inline void 2738c2ecf20Sopenharmony_ciwrite_wd33c93_cmd(const wd33c93_regs regs, uchar cmd) 2748c2ecf20Sopenharmony_ci{ 2758c2ecf20Sopenharmony_ci *regs.SASR = WD_COMMAND; 2768c2ecf20Sopenharmony_ci mb(); 2778c2ecf20Sopenharmony_ci *regs.SCMD = cmd; 2788c2ecf20Sopenharmony_ci mb(); 2798c2ecf20Sopenharmony_ci} 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_cistatic inline void 2828c2ecf20Sopenharmony_ciwrite_wd33c93_cdb(const wd33c93_regs regs, uint len, uchar cmnd[]) 2838c2ecf20Sopenharmony_ci{ 2848c2ecf20Sopenharmony_ci int i; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci *regs.SASR = WD_CDB_1; 2878c2ecf20Sopenharmony_ci for (i = 0; i < len; i++) 2888c2ecf20Sopenharmony_ci *regs.SCMD = cmnd[i]; 2898c2ecf20Sopenharmony_ci} 2908c2ecf20Sopenharmony_ci#endif /* CONFIG_WD33C93_PIO */ 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_cistatic inline uchar 2938c2ecf20Sopenharmony_ciread_1_byte(const wd33c93_regs regs) 2948c2ecf20Sopenharmony_ci{ 2958c2ecf20Sopenharmony_ci uchar asr; 2968c2ecf20Sopenharmony_ci uchar x = 0; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED); 2998c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_TRANS_INFO | 0x80); 3008c2ecf20Sopenharmony_ci do { 3018c2ecf20Sopenharmony_ci asr = read_aux_stat(regs); 3028c2ecf20Sopenharmony_ci if (asr & ASR_DBR) 3038c2ecf20Sopenharmony_ci x = read_wd33c93(regs, WD_DATA); 3048c2ecf20Sopenharmony_ci } while (!(asr & ASR_INT)); 3058c2ecf20Sopenharmony_ci return x; 3068c2ecf20Sopenharmony_ci} 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_cistatic int 3098c2ecf20Sopenharmony_ciround_period(unsigned int period, const struct sx_period *sx_table) 3108c2ecf20Sopenharmony_ci{ 3118c2ecf20Sopenharmony_ci int x; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci for (x = 1; sx_table[x].period_ns; x++) { 3148c2ecf20Sopenharmony_ci if ((period <= sx_table[x - 0].period_ns) && 3158c2ecf20Sopenharmony_ci (period > sx_table[x - 1].period_ns)) { 3168c2ecf20Sopenharmony_ci return x; 3178c2ecf20Sopenharmony_ci } 3188c2ecf20Sopenharmony_ci } 3198c2ecf20Sopenharmony_ci return 7; 3208c2ecf20Sopenharmony_ci} 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci/* 3238c2ecf20Sopenharmony_ci * Calculate Synchronous Transfer Register value from SDTR code. 3248c2ecf20Sopenharmony_ci */ 3258c2ecf20Sopenharmony_cistatic uchar 3268c2ecf20Sopenharmony_cicalc_sync_xfer(unsigned int period, unsigned int offset, unsigned int fast, 3278c2ecf20Sopenharmony_ci const struct sx_period *sx_table) 3288c2ecf20Sopenharmony_ci{ 3298c2ecf20Sopenharmony_ci /* When doing Fast SCSI synchronous data transfers, the corresponding 3308c2ecf20Sopenharmony_ci * value in 'sx_table' is two times the actually used transfer period. 3318c2ecf20Sopenharmony_ci */ 3328c2ecf20Sopenharmony_ci uchar result; 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci if (offset && fast) { 3358c2ecf20Sopenharmony_ci fast = STR_FSS; 3368c2ecf20Sopenharmony_ci period *= 2; 3378c2ecf20Sopenharmony_ci } else { 3388c2ecf20Sopenharmony_ci fast = 0; 3398c2ecf20Sopenharmony_ci } 3408c2ecf20Sopenharmony_ci period *= 4; /* convert SDTR code to ns */ 3418c2ecf20Sopenharmony_ci result = sx_table[round_period(period,sx_table)].reg_value; 3428c2ecf20Sopenharmony_ci result |= (offset < OPTIMUM_SX_OFF) ? offset : OPTIMUM_SX_OFF; 3438c2ecf20Sopenharmony_ci result |= fast; 3448c2ecf20Sopenharmony_ci return result; 3458c2ecf20Sopenharmony_ci} 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci/* 3488c2ecf20Sopenharmony_ci * Calculate SDTR code bytes [3],[4] from period and offset. 3498c2ecf20Sopenharmony_ci */ 3508c2ecf20Sopenharmony_cistatic inline void 3518c2ecf20Sopenharmony_cicalc_sync_msg(unsigned int period, unsigned int offset, unsigned int fast, 3528c2ecf20Sopenharmony_ci uchar msg[2]) 3538c2ecf20Sopenharmony_ci{ 3548c2ecf20Sopenharmony_ci /* 'period' is a "normal"-mode value, like the ones in 'sx_table'. The 3558c2ecf20Sopenharmony_ci * actually used transfer period for Fast SCSI synchronous data 3568c2ecf20Sopenharmony_ci * transfers is half that value. 3578c2ecf20Sopenharmony_ci */ 3588c2ecf20Sopenharmony_ci period /= 4; 3598c2ecf20Sopenharmony_ci if (offset && fast) 3608c2ecf20Sopenharmony_ci period /= 2; 3618c2ecf20Sopenharmony_ci msg[0] = period; 3628c2ecf20Sopenharmony_ci msg[1] = offset; 3638c2ecf20Sopenharmony_ci} 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_cistatic int 3668c2ecf20Sopenharmony_ciwd33c93_queuecommand_lck(struct scsi_cmnd *cmd, 3678c2ecf20Sopenharmony_ci void (*done)(struct scsi_cmnd *)) 3688c2ecf20Sopenharmony_ci{ 3698c2ecf20Sopenharmony_ci struct WD33C93_hostdata *hostdata; 3708c2ecf20Sopenharmony_ci struct scsi_cmnd *tmp; 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci hostdata = (struct WD33C93_hostdata *) cmd->device->host->hostdata; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci DB(DB_QUEUE_COMMAND, 3758c2ecf20Sopenharmony_ci printk("Q-%d-%02x( ", cmd->device->id, cmd->cmnd[0])) 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci/* Set up a few fields in the scsi_cmnd structure for our own use: 3788c2ecf20Sopenharmony_ci * - host_scribble is the pointer to the next cmd in the input queue 3798c2ecf20Sopenharmony_ci * - scsi_done points to the routine we call when a cmd is finished 3808c2ecf20Sopenharmony_ci * - result is what you'd expect 3818c2ecf20Sopenharmony_ci */ 3828c2ecf20Sopenharmony_ci cmd->host_scribble = NULL; 3838c2ecf20Sopenharmony_ci cmd->scsi_done = done; 3848c2ecf20Sopenharmony_ci cmd->result = 0; 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci/* We use the Scsi_Pointer structure that's included with each command 3878c2ecf20Sopenharmony_ci * as a scratchpad (as it's intended to be used!). The handy thing about 3888c2ecf20Sopenharmony_ci * the SCp.xxx fields is that they're always associated with a given 3898c2ecf20Sopenharmony_ci * cmd, and are preserved across disconnect-reselect. This means we 3908c2ecf20Sopenharmony_ci * can pretty much ignore SAVE_POINTERS and RESTORE_POINTERS messages 3918c2ecf20Sopenharmony_ci * if we keep all the critical pointers and counters in SCp: 3928c2ecf20Sopenharmony_ci * - SCp.ptr is the pointer into the RAM buffer 3938c2ecf20Sopenharmony_ci * - SCp.this_residual is the size of that buffer 3948c2ecf20Sopenharmony_ci * - SCp.buffer points to the current scatter-gather buffer 3958c2ecf20Sopenharmony_ci * - SCp.buffers_residual tells us how many S.G. buffers there are 3968c2ecf20Sopenharmony_ci * - SCp.have_data_in is not used 3978c2ecf20Sopenharmony_ci * - SCp.sent_command is not used 3988c2ecf20Sopenharmony_ci * - SCp.phase records this command's SRCID_ER bit setting 3998c2ecf20Sopenharmony_ci */ 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci if (scsi_bufflen(cmd)) { 4028c2ecf20Sopenharmony_ci cmd->SCp.buffer = scsi_sglist(cmd); 4038c2ecf20Sopenharmony_ci cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1; 4048c2ecf20Sopenharmony_ci cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); 4058c2ecf20Sopenharmony_ci cmd->SCp.this_residual = cmd->SCp.buffer->length; 4068c2ecf20Sopenharmony_ci } else { 4078c2ecf20Sopenharmony_ci cmd->SCp.buffer = NULL; 4088c2ecf20Sopenharmony_ci cmd->SCp.buffers_residual = 0; 4098c2ecf20Sopenharmony_ci cmd->SCp.ptr = NULL; 4108c2ecf20Sopenharmony_ci cmd->SCp.this_residual = 0; 4118c2ecf20Sopenharmony_ci } 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci/* WD docs state that at the conclusion of a "LEVEL2" command, the 4148c2ecf20Sopenharmony_ci * status byte can be retrieved from the LUN register. Apparently, 4158c2ecf20Sopenharmony_ci * this is the case only for *uninterrupted* LEVEL2 commands! If 4168c2ecf20Sopenharmony_ci * there are any unexpected phases entered, even if they are 100% 4178c2ecf20Sopenharmony_ci * legal (different devices may choose to do things differently), 4188c2ecf20Sopenharmony_ci * the LEVEL2 command sequence is exited. This often occurs prior 4198c2ecf20Sopenharmony_ci * to receiving the status byte, in which case the driver does a 4208c2ecf20Sopenharmony_ci * status phase interrupt and gets the status byte on its own. 4218c2ecf20Sopenharmony_ci * While such a command can then be "resumed" (ie restarted to 4228c2ecf20Sopenharmony_ci * finish up as a LEVEL2 command), the LUN register will NOT be 4238c2ecf20Sopenharmony_ci * a valid status byte at the command's conclusion, and we must 4248c2ecf20Sopenharmony_ci * use the byte obtained during the earlier interrupt. Here, we 4258c2ecf20Sopenharmony_ci * preset SCp.Status to an illegal value (0xff) so that when 4268c2ecf20Sopenharmony_ci * this command finally completes, we can tell where the actual 4278c2ecf20Sopenharmony_ci * status byte is stored. 4288c2ecf20Sopenharmony_ci */ 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci cmd->SCp.Status = ILLEGAL_STATUS_BYTE; 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci /* 4338c2ecf20Sopenharmony_ci * Add the cmd to the end of 'input_Q'. Note that REQUEST SENSE 4348c2ecf20Sopenharmony_ci * commands are added to the head of the queue so that the desired 4358c2ecf20Sopenharmony_ci * sense data is not lost before REQUEST_SENSE executes. 4368c2ecf20Sopenharmony_ci */ 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci spin_lock_irq(&hostdata->lock); 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci if (!(hostdata->input_Q) || (cmd->cmnd[0] == REQUEST_SENSE)) { 4418c2ecf20Sopenharmony_ci cmd->host_scribble = (uchar *) hostdata->input_Q; 4428c2ecf20Sopenharmony_ci hostdata->input_Q = cmd; 4438c2ecf20Sopenharmony_ci } else { /* find the end of the queue */ 4448c2ecf20Sopenharmony_ci for (tmp = (struct scsi_cmnd *) hostdata->input_Q; 4458c2ecf20Sopenharmony_ci tmp->host_scribble; 4468c2ecf20Sopenharmony_ci tmp = (struct scsi_cmnd *) tmp->host_scribble) ; 4478c2ecf20Sopenharmony_ci tmp->host_scribble = (uchar *) cmd; 4488c2ecf20Sopenharmony_ci } 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci/* We know that there's at least one command in 'input_Q' now. 4518c2ecf20Sopenharmony_ci * Go see if any of them are runnable! 4528c2ecf20Sopenharmony_ci */ 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci wd33c93_execute(cmd->device->host); 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci DB(DB_QUEUE_COMMAND, printk(")Q ")) 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci spin_unlock_irq(&hostdata->lock); 4598c2ecf20Sopenharmony_ci return 0; 4608c2ecf20Sopenharmony_ci} 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ciDEF_SCSI_QCMD(wd33c93_queuecommand) 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci/* 4658c2ecf20Sopenharmony_ci * This routine attempts to start a scsi command. If the host_card is 4668c2ecf20Sopenharmony_ci * already connected, we give up immediately. Otherwise, look through 4678c2ecf20Sopenharmony_ci * the input_Q, using the first command we find that's intended 4688c2ecf20Sopenharmony_ci * for a currently non-busy target/lun. 4698c2ecf20Sopenharmony_ci * 4708c2ecf20Sopenharmony_ci * wd33c93_execute() is always called with interrupts disabled or from 4718c2ecf20Sopenharmony_ci * the wd33c93_intr itself, which means that a wd33c93 interrupt 4728c2ecf20Sopenharmony_ci * cannot occur while we are in here. 4738c2ecf20Sopenharmony_ci */ 4748c2ecf20Sopenharmony_cistatic void 4758c2ecf20Sopenharmony_ciwd33c93_execute(struct Scsi_Host *instance) 4768c2ecf20Sopenharmony_ci{ 4778c2ecf20Sopenharmony_ci struct WD33C93_hostdata *hostdata = 4788c2ecf20Sopenharmony_ci (struct WD33C93_hostdata *) instance->hostdata; 4798c2ecf20Sopenharmony_ci const wd33c93_regs regs = hostdata->regs; 4808c2ecf20Sopenharmony_ci struct scsi_cmnd *cmd, *prev; 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci DB(DB_EXECUTE, printk("EX(")) 4838c2ecf20Sopenharmony_ci if (hostdata->selecting || hostdata->connected) { 4848c2ecf20Sopenharmony_ci DB(DB_EXECUTE, printk(")EX-0 ")) 4858c2ecf20Sopenharmony_ci return; 4868c2ecf20Sopenharmony_ci } 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_ci /* 4898c2ecf20Sopenharmony_ci * Search through the input_Q for a command destined 4908c2ecf20Sopenharmony_ci * for an idle target/lun. 4918c2ecf20Sopenharmony_ci */ 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) hostdata->input_Q; 4948c2ecf20Sopenharmony_ci prev = NULL; 4958c2ecf20Sopenharmony_ci while (cmd) { 4968c2ecf20Sopenharmony_ci if (!(hostdata->busy[cmd->device->id] & 4978c2ecf20Sopenharmony_ci (1 << (cmd->device->lun & 0xff)))) 4988c2ecf20Sopenharmony_ci break; 4998c2ecf20Sopenharmony_ci prev = cmd; 5008c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) cmd->host_scribble; 5018c2ecf20Sopenharmony_ci } 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci /* quit if queue empty or all possible targets are busy */ 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci if (!cmd) { 5068c2ecf20Sopenharmony_ci DB(DB_EXECUTE, printk(")EX-1 ")) 5078c2ecf20Sopenharmony_ci return; 5088c2ecf20Sopenharmony_ci } 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci /* remove command from queue */ 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci if (prev) 5138c2ecf20Sopenharmony_ci prev->host_scribble = cmd->host_scribble; 5148c2ecf20Sopenharmony_ci else 5158c2ecf20Sopenharmony_ci hostdata->input_Q = (struct scsi_cmnd *) cmd->host_scribble; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci#ifdef PROC_STATISTICS 5188c2ecf20Sopenharmony_ci hostdata->cmd_cnt[cmd->device->id]++; 5198c2ecf20Sopenharmony_ci#endif 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci /* 5228c2ecf20Sopenharmony_ci * Start the selection process 5238c2ecf20Sopenharmony_ci */ 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci if (cmd->sc_data_direction == DMA_TO_DEVICE) 5268c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_DESTINATION_ID, cmd->device->id); 5278c2ecf20Sopenharmony_ci else 5288c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_DESTINATION_ID, cmd->device->id | DSTID_DPD); 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci/* Now we need to figure out whether or not this command is a good 5318c2ecf20Sopenharmony_ci * candidate for disconnect/reselect. We guess to the best of our 5328c2ecf20Sopenharmony_ci * ability, based on a set of hierarchical rules. When several 5338c2ecf20Sopenharmony_ci * devices are operating simultaneously, disconnects are usually 5348c2ecf20Sopenharmony_ci * an advantage. In a single device system, or if only 1 device 5358c2ecf20Sopenharmony_ci * is being accessed, transfers usually go faster if disconnects 5368c2ecf20Sopenharmony_ci * are not allowed: 5378c2ecf20Sopenharmony_ci * 5388c2ecf20Sopenharmony_ci * + Commands should NEVER disconnect if hostdata->disconnect = 5398c2ecf20Sopenharmony_ci * DIS_NEVER (this holds for tape drives also), and ALWAYS 5408c2ecf20Sopenharmony_ci * disconnect if hostdata->disconnect = DIS_ALWAYS. 5418c2ecf20Sopenharmony_ci * + Tape drive commands should always be allowed to disconnect. 5428c2ecf20Sopenharmony_ci * + Disconnect should be allowed if disconnected_Q isn't empty. 5438c2ecf20Sopenharmony_ci * + Commands should NOT disconnect if input_Q is empty. 5448c2ecf20Sopenharmony_ci * + Disconnect should be allowed if there are commands in input_Q 5458c2ecf20Sopenharmony_ci * for a different target/lun. In this case, the other commands 5468c2ecf20Sopenharmony_ci * should be made disconnect-able, if not already. 5478c2ecf20Sopenharmony_ci * 5488c2ecf20Sopenharmony_ci * I know, I know - this code would flunk me out of any 5498c2ecf20Sopenharmony_ci * "C Programming 101" class ever offered. But it's easy 5508c2ecf20Sopenharmony_ci * to change around and experiment with for now. 5518c2ecf20Sopenharmony_ci */ 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ci cmd->SCp.phase = 0; /* assume no disconnect */ 5548c2ecf20Sopenharmony_ci if (hostdata->disconnect == DIS_NEVER) 5558c2ecf20Sopenharmony_ci goto no; 5568c2ecf20Sopenharmony_ci if (hostdata->disconnect == DIS_ALWAYS) 5578c2ecf20Sopenharmony_ci goto yes; 5588c2ecf20Sopenharmony_ci if (cmd->device->type == 1) /* tape drive? */ 5598c2ecf20Sopenharmony_ci goto yes; 5608c2ecf20Sopenharmony_ci if (hostdata->disconnected_Q) /* other commands disconnected? */ 5618c2ecf20Sopenharmony_ci goto yes; 5628c2ecf20Sopenharmony_ci if (!(hostdata->input_Q)) /* input_Q empty? */ 5638c2ecf20Sopenharmony_ci goto no; 5648c2ecf20Sopenharmony_ci for (prev = (struct scsi_cmnd *) hostdata->input_Q; prev; 5658c2ecf20Sopenharmony_ci prev = (struct scsi_cmnd *) prev->host_scribble) { 5668c2ecf20Sopenharmony_ci if ((prev->device->id != cmd->device->id) || 5678c2ecf20Sopenharmony_ci (prev->device->lun != cmd->device->lun)) { 5688c2ecf20Sopenharmony_ci for (prev = (struct scsi_cmnd *) hostdata->input_Q; prev; 5698c2ecf20Sopenharmony_ci prev = (struct scsi_cmnd *) prev->host_scribble) 5708c2ecf20Sopenharmony_ci prev->SCp.phase = 1; 5718c2ecf20Sopenharmony_ci goto yes; 5728c2ecf20Sopenharmony_ci } 5738c2ecf20Sopenharmony_ci } 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci goto no; 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci yes: 5788c2ecf20Sopenharmony_ci cmd->SCp.phase = 1; 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ci#ifdef PROC_STATISTICS 5818c2ecf20Sopenharmony_ci hostdata->disc_allowed_cnt[cmd->device->id]++; 5828c2ecf20Sopenharmony_ci#endif 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci no: 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_SOURCE_ID, ((cmd->SCp.phase) ? SRCID_ER : 0)); 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_TARGET_LUN, (u8)cmd->device->lun); 5898c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER, 5908c2ecf20Sopenharmony_ci hostdata->sync_xfer[cmd->device->id]); 5918c2ecf20Sopenharmony_ci hostdata->busy[cmd->device->id] |= (1 << (cmd->device->lun & 0xFF)); 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci if ((hostdata->level2 == L2_NONE) || 5948c2ecf20Sopenharmony_ci (hostdata->sync_stat[cmd->device->id] == SS_UNSET)) { 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci /* 5978c2ecf20Sopenharmony_ci * Do a 'Select-With-ATN' command. This will end with 5988c2ecf20Sopenharmony_ci * one of the following interrupts: 5998c2ecf20Sopenharmony_ci * CSR_RESEL_AM: failure - can try again later. 6008c2ecf20Sopenharmony_ci * CSR_TIMEOUT: failure - give up. 6018c2ecf20Sopenharmony_ci * CSR_SELECT: success - proceed. 6028c2ecf20Sopenharmony_ci */ 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci hostdata->selecting = cmd; 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci/* Every target has its own synchronous transfer setting, kept in the 6078c2ecf20Sopenharmony_ci * sync_xfer array, and a corresponding status byte in sync_stat[]. 6088c2ecf20Sopenharmony_ci * Each target's sync_stat[] entry is initialized to SX_UNSET, and its 6098c2ecf20Sopenharmony_ci * sync_xfer[] entry is initialized to the default/safe value. SS_UNSET 6108c2ecf20Sopenharmony_ci * means that the parameters are undetermined as yet, and that we 6118c2ecf20Sopenharmony_ci * need to send an SDTR message to this device after selection is 6128c2ecf20Sopenharmony_ci * complete: We set SS_FIRST to tell the interrupt routine to do so. 6138c2ecf20Sopenharmony_ci * If we've been asked not to try synchronous transfers on this 6148c2ecf20Sopenharmony_ci * target (and _all_ luns within it), we'll still send the SDTR message 6158c2ecf20Sopenharmony_ci * later, but at that time we'll negotiate for async by specifying a 6168c2ecf20Sopenharmony_ci * sync fifo depth of 0. 6178c2ecf20Sopenharmony_ci */ 6188c2ecf20Sopenharmony_ci if (hostdata->sync_stat[cmd->device->id] == SS_UNSET) 6198c2ecf20Sopenharmony_ci hostdata->sync_stat[cmd->device->id] = SS_FIRST; 6208c2ecf20Sopenharmony_ci hostdata->state = S_SELECTING; 6218c2ecf20Sopenharmony_ci write_wd33c93_count(regs, 0); /* guarantee a DATA_PHASE interrupt */ 6228c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_SEL_ATN); 6238c2ecf20Sopenharmony_ci } else { 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci /* 6268c2ecf20Sopenharmony_ci * Do a 'Select-With-ATN-Xfer' command. This will end with 6278c2ecf20Sopenharmony_ci * one of the following interrupts: 6288c2ecf20Sopenharmony_ci * CSR_RESEL_AM: failure - can try again later. 6298c2ecf20Sopenharmony_ci * CSR_TIMEOUT: failure - give up. 6308c2ecf20Sopenharmony_ci * anything else: success - proceed. 6318c2ecf20Sopenharmony_ci */ 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci hostdata->connected = cmd; 6348c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_COMMAND_PHASE, 0); 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci /* copy command_descriptor_block into WD chip 6378c2ecf20Sopenharmony_ci * (take advantage of auto-incrementing) 6388c2ecf20Sopenharmony_ci */ 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci write_wd33c93_cdb(regs, cmd->cmd_len, cmd->cmnd); 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci /* The wd33c93 only knows about Group 0, 1, and 5 commands when 6438c2ecf20Sopenharmony_ci * it's doing a 'select-and-transfer'. To be safe, we write the 6448c2ecf20Sopenharmony_ci * size of the CDB into the OWN_ID register for every case. This 6458c2ecf20Sopenharmony_ci * way there won't be problems with vendor-unique, audio, etc. 6468c2ecf20Sopenharmony_ci */ 6478c2ecf20Sopenharmony_ci 6488c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_OWN_ID, cmd->cmd_len); 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci /* When doing a non-disconnect command with DMA, we can save 6518c2ecf20Sopenharmony_ci * ourselves a DATA phase interrupt later by setting everything 6528c2ecf20Sopenharmony_ci * up ahead of time. 6538c2ecf20Sopenharmony_ci */ 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_ci if ((cmd->SCp.phase == 0) && (hostdata->no_dma == 0)) { 6568c2ecf20Sopenharmony_ci if (hostdata->dma_setup(cmd, 6578c2ecf20Sopenharmony_ci (cmd->sc_data_direction == DMA_TO_DEVICE) ? 6588c2ecf20Sopenharmony_ci DATA_OUT_DIR : DATA_IN_DIR)) 6598c2ecf20Sopenharmony_ci write_wd33c93_count(regs, 0); /* guarantee a DATA_PHASE interrupt */ 6608c2ecf20Sopenharmony_ci else { 6618c2ecf20Sopenharmony_ci write_wd33c93_count(regs, 6628c2ecf20Sopenharmony_ci cmd->SCp.this_residual); 6638c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_CONTROL, 6648c2ecf20Sopenharmony_ci CTRL_IDI | CTRL_EDI | hostdata->dma_mode); 6658c2ecf20Sopenharmony_ci hostdata->dma = D_DMA_RUNNING; 6668c2ecf20Sopenharmony_ci } 6678c2ecf20Sopenharmony_ci } else 6688c2ecf20Sopenharmony_ci write_wd33c93_count(regs, 0); /* guarantee a DATA_PHASE interrupt */ 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci hostdata->state = S_RUNNING_LEVEL2; 6718c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER); 6728c2ecf20Sopenharmony_ci } 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci /* 6758c2ecf20Sopenharmony_ci * Since the SCSI bus can handle only 1 connection at a time, 6768c2ecf20Sopenharmony_ci * we get out of here now. If the selection fails, or when 6778c2ecf20Sopenharmony_ci * the command disconnects, we'll come back to this routine 6788c2ecf20Sopenharmony_ci * to search the input_Q again... 6798c2ecf20Sopenharmony_ci */ 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ci DB(DB_EXECUTE, 6828c2ecf20Sopenharmony_ci printk("%s)EX-2 ", (cmd->SCp.phase) ? "d:" : "")) 6838c2ecf20Sopenharmony_ci} 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_cistatic void 6868c2ecf20Sopenharmony_citransfer_pio(const wd33c93_regs regs, uchar * buf, int cnt, 6878c2ecf20Sopenharmony_ci int data_in_dir, struct WD33C93_hostdata *hostdata) 6888c2ecf20Sopenharmony_ci{ 6898c2ecf20Sopenharmony_ci uchar asr; 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci DB(DB_TRANSFER, 6928c2ecf20Sopenharmony_ci printk("(%p,%d,%s:", buf, cnt, data_in_dir ? "in" : "out")) 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED); 6958c2ecf20Sopenharmony_ci write_wd33c93_count(regs, cnt); 6968c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_TRANS_INFO); 6978c2ecf20Sopenharmony_ci if (data_in_dir) { 6988c2ecf20Sopenharmony_ci do { 6998c2ecf20Sopenharmony_ci asr = read_aux_stat(regs); 7008c2ecf20Sopenharmony_ci if (asr & ASR_DBR) 7018c2ecf20Sopenharmony_ci *buf++ = read_wd33c93(regs, WD_DATA); 7028c2ecf20Sopenharmony_ci } while (!(asr & ASR_INT)); 7038c2ecf20Sopenharmony_ci } else { 7048c2ecf20Sopenharmony_ci do { 7058c2ecf20Sopenharmony_ci asr = read_aux_stat(regs); 7068c2ecf20Sopenharmony_ci if (asr & ASR_DBR) 7078c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_DATA, *buf++); 7088c2ecf20Sopenharmony_ci } while (!(asr & ASR_INT)); 7098c2ecf20Sopenharmony_ci } 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci /* Note: we are returning with the interrupt UN-cleared. 7128c2ecf20Sopenharmony_ci * Since (presumably) an entire I/O operation has 7138c2ecf20Sopenharmony_ci * completed, the bus phase is probably different, and 7148c2ecf20Sopenharmony_ci * the interrupt routine will discover this when it 7158c2ecf20Sopenharmony_ci * responds to the uncleared int. 7168c2ecf20Sopenharmony_ci */ 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_ci} 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_cistatic void 7218c2ecf20Sopenharmony_citransfer_bytes(const wd33c93_regs regs, struct scsi_cmnd *cmd, 7228c2ecf20Sopenharmony_ci int data_in_dir) 7238c2ecf20Sopenharmony_ci{ 7248c2ecf20Sopenharmony_ci struct WD33C93_hostdata *hostdata; 7258c2ecf20Sopenharmony_ci unsigned long length; 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci hostdata = (struct WD33C93_hostdata *) cmd->device->host->hostdata; 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ci/* Normally, you'd expect 'this_residual' to be non-zero here. 7308c2ecf20Sopenharmony_ci * In a series of scatter-gather transfers, however, this 7318c2ecf20Sopenharmony_ci * routine will usually be called with 'this_residual' equal 7328c2ecf20Sopenharmony_ci * to 0 and 'buffers_residual' non-zero. This means that a 7338c2ecf20Sopenharmony_ci * previous transfer completed, clearing 'this_residual', and 7348c2ecf20Sopenharmony_ci * now we need to setup the next scatter-gather buffer as the 7358c2ecf20Sopenharmony_ci * source or destination for THIS transfer. 7368c2ecf20Sopenharmony_ci */ 7378c2ecf20Sopenharmony_ci if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) { 7388c2ecf20Sopenharmony_ci cmd->SCp.buffer = sg_next(cmd->SCp.buffer); 7398c2ecf20Sopenharmony_ci --cmd->SCp.buffers_residual; 7408c2ecf20Sopenharmony_ci cmd->SCp.this_residual = cmd->SCp.buffer->length; 7418c2ecf20Sopenharmony_ci cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); 7428c2ecf20Sopenharmony_ci } 7438c2ecf20Sopenharmony_ci if (!cmd->SCp.this_residual) /* avoid bogus setups */ 7448c2ecf20Sopenharmony_ci return; 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER, 7478c2ecf20Sopenharmony_ci hostdata->sync_xfer[cmd->device->id]); 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_ci/* 'hostdata->no_dma' is TRUE if we don't even want to try DMA. 7508c2ecf20Sopenharmony_ci * Update 'this_residual' and 'ptr' after 'transfer_pio()' returns. 7518c2ecf20Sopenharmony_ci */ 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci if (hostdata->no_dma || hostdata->dma_setup(cmd, data_in_dir)) { 7548c2ecf20Sopenharmony_ci#ifdef PROC_STATISTICS 7558c2ecf20Sopenharmony_ci hostdata->pio_cnt++; 7568c2ecf20Sopenharmony_ci#endif 7578c2ecf20Sopenharmony_ci transfer_pio(regs, (uchar *) cmd->SCp.ptr, 7588c2ecf20Sopenharmony_ci cmd->SCp.this_residual, data_in_dir, hostdata); 7598c2ecf20Sopenharmony_ci length = cmd->SCp.this_residual; 7608c2ecf20Sopenharmony_ci cmd->SCp.this_residual = read_wd33c93_count(regs); 7618c2ecf20Sopenharmony_ci cmd->SCp.ptr += (length - cmd->SCp.this_residual); 7628c2ecf20Sopenharmony_ci } 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci/* We are able to do DMA (in fact, the Amiga hardware is 7658c2ecf20Sopenharmony_ci * already going!), so start up the wd33c93 in DMA mode. 7668c2ecf20Sopenharmony_ci * We set 'hostdata->dma' = D_DMA_RUNNING so that when the 7678c2ecf20Sopenharmony_ci * transfer completes and causes an interrupt, we're 7688c2ecf20Sopenharmony_ci * reminded to tell the Amiga to shut down its end. We'll 7698c2ecf20Sopenharmony_ci * postpone the updating of 'this_residual' and 'ptr' 7708c2ecf20Sopenharmony_ci * until then. 7718c2ecf20Sopenharmony_ci */ 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_ci else { 7748c2ecf20Sopenharmony_ci#ifdef PROC_STATISTICS 7758c2ecf20Sopenharmony_ci hostdata->dma_cnt++; 7768c2ecf20Sopenharmony_ci#endif 7778c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | hostdata->dma_mode); 7788c2ecf20Sopenharmony_ci write_wd33c93_count(regs, cmd->SCp.this_residual); 7798c2ecf20Sopenharmony_ci 7808c2ecf20Sopenharmony_ci if ((hostdata->level2 >= L2_DATA) || 7818c2ecf20Sopenharmony_ci (hostdata->level2 == L2_BASIC && cmd->SCp.phase == 0)) { 7828c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_COMMAND_PHASE, 0x45); 7838c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER); 7848c2ecf20Sopenharmony_ci hostdata->state = S_RUNNING_LEVEL2; 7858c2ecf20Sopenharmony_ci } else 7868c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_TRANS_INFO); 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ci hostdata->dma = D_DMA_RUNNING; 7898c2ecf20Sopenharmony_ci } 7908c2ecf20Sopenharmony_ci} 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_civoid 7938c2ecf20Sopenharmony_ciwd33c93_intr(struct Scsi_Host *instance) 7948c2ecf20Sopenharmony_ci{ 7958c2ecf20Sopenharmony_ci struct WD33C93_hostdata *hostdata = 7968c2ecf20Sopenharmony_ci (struct WD33C93_hostdata *) instance->hostdata; 7978c2ecf20Sopenharmony_ci const wd33c93_regs regs = hostdata->regs; 7988c2ecf20Sopenharmony_ci struct scsi_cmnd *patch, *cmd; 7998c2ecf20Sopenharmony_ci uchar asr, sr, phs, id, lun, *ucp, msg; 8008c2ecf20Sopenharmony_ci unsigned long length, flags; 8018c2ecf20Sopenharmony_ci 8028c2ecf20Sopenharmony_ci asr = read_aux_stat(regs); 8038c2ecf20Sopenharmony_ci if (!(asr & ASR_INT) || (asr & ASR_BSY)) 8048c2ecf20Sopenharmony_ci return; 8058c2ecf20Sopenharmony_ci 8068c2ecf20Sopenharmony_ci spin_lock_irqsave(&hostdata->lock, flags); 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_ci#ifdef PROC_STATISTICS 8098c2ecf20Sopenharmony_ci hostdata->int_cnt++; 8108c2ecf20Sopenharmony_ci#endif 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) hostdata->connected; /* assume we're connected */ 8138c2ecf20Sopenharmony_ci sr = read_wd33c93(regs, WD_SCSI_STATUS); /* clear the interrupt */ 8148c2ecf20Sopenharmony_ci phs = read_wd33c93(regs, WD_COMMAND_PHASE); 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci DB(DB_INTR, printk("{%02x:%02x-", asr, sr)) 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci/* After starting a DMA transfer, the next interrupt 8198c2ecf20Sopenharmony_ci * is guaranteed to be in response to completion of 8208c2ecf20Sopenharmony_ci * the transfer. Since the Amiga DMA hardware runs in 8218c2ecf20Sopenharmony_ci * in an open-ended fashion, it needs to be told when 8228c2ecf20Sopenharmony_ci * to stop; do that here if D_DMA_RUNNING is true. 8238c2ecf20Sopenharmony_ci * Also, we have to update 'this_residual' and 'ptr' 8248c2ecf20Sopenharmony_ci * based on the contents of the TRANSFER_COUNT register, 8258c2ecf20Sopenharmony_ci * in case the device decided to do an intermediate 8268c2ecf20Sopenharmony_ci * disconnect (a device may do this if it has to do a 8278c2ecf20Sopenharmony_ci * seek, or just to be nice and let other devices have 8288c2ecf20Sopenharmony_ci * some bus time during long transfers). After doing 8298c2ecf20Sopenharmony_ci * whatever is needed, we go on and service the WD3393 8308c2ecf20Sopenharmony_ci * interrupt normally. 8318c2ecf20Sopenharmony_ci */ 8328c2ecf20Sopenharmony_ci if (hostdata->dma == D_DMA_RUNNING) { 8338c2ecf20Sopenharmony_ci DB(DB_TRANSFER, 8348c2ecf20Sopenharmony_ci printk("[%p/%d:", cmd->SCp.ptr, cmd->SCp.this_residual)) 8358c2ecf20Sopenharmony_ci hostdata->dma_stop(cmd->device->host, cmd, 1); 8368c2ecf20Sopenharmony_ci hostdata->dma = D_DMA_OFF; 8378c2ecf20Sopenharmony_ci length = cmd->SCp.this_residual; 8388c2ecf20Sopenharmony_ci cmd->SCp.this_residual = read_wd33c93_count(regs); 8398c2ecf20Sopenharmony_ci cmd->SCp.ptr += (length - cmd->SCp.this_residual); 8408c2ecf20Sopenharmony_ci DB(DB_TRANSFER, 8418c2ecf20Sopenharmony_ci printk("%p/%d]", cmd->SCp.ptr, cmd->SCp.this_residual)) 8428c2ecf20Sopenharmony_ci } 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci/* Respond to the specific WD3393 interrupt - there are quite a few! */ 8458c2ecf20Sopenharmony_ci switch (sr) { 8468c2ecf20Sopenharmony_ci case CSR_TIMEOUT: 8478c2ecf20Sopenharmony_ci DB(DB_INTR, printk("TIMEOUT")) 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_ci if (hostdata->state == S_RUNNING_LEVEL2) 8508c2ecf20Sopenharmony_ci hostdata->connected = NULL; 8518c2ecf20Sopenharmony_ci else { 8528c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) hostdata->selecting; /* get a valid cmd */ 8538c2ecf20Sopenharmony_ci hostdata->selecting = NULL; 8548c2ecf20Sopenharmony_ci } 8558c2ecf20Sopenharmony_ci 8568c2ecf20Sopenharmony_ci cmd->result = DID_NO_CONNECT << 16; 8578c2ecf20Sopenharmony_ci hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff)); 8588c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 8598c2ecf20Sopenharmony_ci cmd->scsi_done(cmd); 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci /* From esp.c: 8628c2ecf20Sopenharmony_ci * There is a window of time within the scsi_done() path 8638c2ecf20Sopenharmony_ci * of execution where interrupts are turned back on full 8648c2ecf20Sopenharmony_ci * blast and left that way. During that time we could 8658c2ecf20Sopenharmony_ci * reconnect to a disconnected command, then we'd bomb 8668c2ecf20Sopenharmony_ci * out below. We could also end up executing two commands 8678c2ecf20Sopenharmony_ci * at _once_. ...just so you know why the restore_flags() 8688c2ecf20Sopenharmony_ci * is here... 8698c2ecf20Sopenharmony_ci */ 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_ci/* We are not connected to a target - check to see if there 8748c2ecf20Sopenharmony_ci * are commands waiting to be executed. 8758c2ecf20Sopenharmony_ci */ 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci wd33c93_execute(instance); 8788c2ecf20Sopenharmony_ci break; 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci/* Note: this interrupt should not occur in a LEVEL2 command */ 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci case CSR_SELECT: 8838c2ecf20Sopenharmony_ci DB(DB_INTR, printk("SELECT")) 8848c2ecf20Sopenharmony_ci hostdata->connected = cmd = 8858c2ecf20Sopenharmony_ci (struct scsi_cmnd *) hostdata->selecting; 8868c2ecf20Sopenharmony_ci hostdata->selecting = NULL; 8878c2ecf20Sopenharmony_ci 8888c2ecf20Sopenharmony_ci /* construct an IDENTIFY message with correct disconnect bit */ 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ci hostdata->outgoing_msg[0] = IDENTIFY(0, cmd->device->lun); 8918c2ecf20Sopenharmony_ci if (cmd->SCp.phase) 8928c2ecf20Sopenharmony_ci hostdata->outgoing_msg[0] |= 0x40; 8938c2ecf20Sopenharmony_ci 8948c2ecf20Sopenharmony_ci if (hostdata->sync_stat[cmd->device->id] == SS_FIRST) { 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_ci hostdata->sync_stat[cmd->device->id] = SS_WAITING; 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_ci/* Tack on a 2nd message to ask about synchronous transfers. If we've 8998c2ecf20Sopenharmony_ci * been asked to do only asynchronous transfers on this device, we 9008c2ecf20Sopenharmony_ci * request a fifo depth of 0, which is equivalent to async - should 9018c2ecf20Sopenharmony_ci * solve the problems some people have had with GVP's Guru ROM. 9028c2ecf20Sopenharmony_ci */ 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci hostdata->outgoing_msg[1] = EXTENDED_MESSAGE; 9058c2ecf20Sopenharmony_ci hostdata->outgoing_msg[2] = 3; 9068c2ecf20Sopenharmony_ci hostdata->outgoing_msg[3] = EXTENDED_SDTR; 9078c2ecf20Sopenharmony_ci if (hostdata->no_sync & (1 << cmd->device->id)) { 9088c2ecf20Sopenharmony_ci calc_sync_msg(hostdata->default_sx_per, 0, 9098c2ecf20Sopenharmony_ci 0, hostdata->outgoing_msg + 4); 9108c2ecf20Sopenharmony_ci } else { 9118c2ecf20Sopenharmony_ci calc_sync_msg(optimum_sx_per(hostdata), 9128c2ecf20Sopenharmony_ci OPTIMUM_SX_OFF, 9138c2ecf20Sopenharmony_ci hostdata->fast, 9148c2ecf20Sopenharmony_ci hostdata->outgoing_msg + 4); 9158c2ecf20Sopenharmony_ci } 9168c2ecf20Sopenharmony_ci hostdata->outgoing_len = 6; 9178c2ecf20Sopenharmony_ci#ifdef SYNC_DEBUG 9188c2ecf20Sopenharmony_ci ucp = hostdata->outgoing_msg + 1; 9198c2ecf20Sopenharmony_ci printk(" sending SDTR %02x03%02x%02x%02x ", 9208c2ecf20Sopenharmony_ci ucp[0], ucp[2], ucp[3], ucp[4]); 9218c2ecf20Sopenharmony_ci#endif 9228c2ecf20Sopenharmony_ci } else 9238c2ecf20Sopenharmony_ci hostdata->outgoing_len = 1; 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 9268c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 9278c2ecf20Sopenharmony_ci break; 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci case CSR_XFER_DONE | PHS_DATA_IN: 9308c2ecf20Sopenharmony_ci case CSR_UNEXP | PHS_DATA_IN: 9318c2ecf20Sopenharmony_ci case CSR_SRV_REQ | PHS_DATA_IN: 9328c2ecf20Sopenharmony_ci DB(DB_INTR, 9338c2ecf20Sopenharmony_ci printk("IN-%d.%d", cmd->SCp.this_residual, 9348c2ecf20Sopenharmony_ci cmd->SCp.buffers_residual)) 9358c2ecf20Sopenharmony_ci transfer_bytes(regs, cmd, DATA_IN_DIR); 9368c2ecf20Sopenharmony_ci if (hostdata->state != S_RUNNING_LEVEL2) 9378c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 9388c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 9398c2ecf20Sopenharmony_ci break; 9408c2ecf20Sopenharmony_ci 9418c2ecf20Sopenharmony_ci case CSR_XFER_DONE | PHS_DATA_OUT: 9428c2ecf20Sopenharmony_ci case CSR_UNEXP | PHS_DATA_OUT: 9438c2ecf20Sopenharmony_ci case CSR_SRV_REQ | PHS_DATA_OUT: 9448c2ecf20Sopenharmony_ci DB(DB_INTR, 9458c2ecf20Sopenharmony_ci printk("OUT-%d.%d", cmd->SCp.this_residual, 9468c2ecf20Sopenharmony_ci cmd->SCp.buffers_residual)) 9478c2ecf20Sopenharmony_ci transfer_bytes(regs, cmd, DATA_OUT_DIR); 9488c2ecf20Sopenharmony_ci if (hostdata->state != S_RUNNING_LEVEL2) 9498c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 9508c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 9518c2ecf20Sopenharmony_ci break; 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_ci/* Note: this interrupt should not occur in a LEVEL2 command */ 9548c2ecf20Sopenharmony_ci 9558c2ecf20Sopenharmony_ci case CSR_XFER_DONE | PHS_COMMAND: 9568c2ecf20Sopenharmony_ci case CSR_UNEXP | PHS_COMMAND: 9578c2ecf20Sopenharmony_ci case CSR_SRV_REQ | PHS_COMMAND: 9588c2ecf20Sopenharmony_ci DB(DB_INTR, printk("CMND-%02x", cmd->cmnd[0])) 9598c2ecf20Sopenharmony_ci transfer_pio(regs, cmd->cmnd, cmd->cmd_len, DATA_OUT_DIR, 9608c2ecf20Sopenharmony_ci hostdata); 9618c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 9628c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 9638c2ecf20Sopenharmony_ci break; 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ci case CSR_XFER_DONE | PHS_STATUS: 9668c2ecf20Sopenharmony_ci case CSR_UNEXP | PHS_STATUS: 9678c2ecf20Sopenharmony_ci case CSR_SRV_REQ | PHS_STATUS: 9688c2ecf20Sopenharmony_ci DB(DB_INTR, printk("STATUS=")) 9698c2ecf20Sopenharmony_ci cmd->SCp.Status = read_1_byte(regs); 9708c2ecf20Sopenharmony_ci DB(DB_INTR, printk("%02x", cmd->SCp.Status)) 9718c2ecf20Sopenharmony_ci if (hostdata->level2 >= L2_BASIC) { 9728c2ecf20Sopenharmony_ci sr = read_wd33c93(regs, WD_SCSI_STATUS); /* clear interrupt */ 9738c2ecf20Sopenharmony_ci udelay(7); 9748c2ecf20Sopenharmony_ci hostdata->state = S_RUNNING_LEVEL2; 9758c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_COMMAND_PHASE, 0x50); 9768c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER); 9778c2ecf20Sopenharmony_ci } else { 9788c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 9798c2ecf20Sopenharmony_ci } 9808c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 9818c2ecf20Sopenharmony_ci break; 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci case CSR_XFER_DONE | PHS_MESS_IN: 9848c2ecf20Sopenharmony_ci case CSR_UNEXP | PHS_MESS_IN: 9858c2ecf20Sopenharmony_ci case CSR_SRV_REQ | PHS_MESS_IN: 9868c2ecf20Sopenharmony_ci DB(DB_INTR, printk("MSG_IN=")) 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_ci msg = read_1_byte(regs); 9898c2ecf20Sopenharmony_ci sr = read_wd33c93(regs, WD_SCSI_STATUS); /* clear interrupt */ 9908c2ecf20Sopenharmony_ci udelay(7); 9918c2ecf20Sopenharmony_ci 9928c2ecf20Sopenharmony_ci hostdata->incoming_msg[hostdata->incoming_ptr] = msg; 9938c2ecf20Sopenharmony_ci if (hostdata->incoming_msg[0] == EXTENDED_MESSAGE) 9948c2ecf20Sopenharmony_ci msg = EXTENDED_MESSAGE; 9958c2ecf20Sopenharmony_ci else 9968c2ecf20Sopenharmony_ci hostdata->incoming_ptr = 0; 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci cmd->SCp.Message = msg; 9998c2ecf20Sopenharmony_ci switch (msg) { 10008c2ecf20Sopenharmony_ci 10018c2ecf20Sopenharmony_ci case COMMAND_COMPLETE: 10028c2ecf20Sopenharmony_ci DB(DB_INTR, printk("CCMP")) 10038c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK); 10048c2ecf20Sopenharmony_ci hostdata->state = S_PRE_CMP_DISC; 10058c2ecf20Sopenharmony_ci break; 10068c2ecf20Sopenharmony_ci 10078c2ecf20Sopenharmony_ci case SAVE_POINTERS: 10088c2ecf20Sopenharmony_ci DB(DB_INTR, printk("SDP")) 10098c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK); 10108c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 10118c2ecf20Sopenharmony_ci break; 10128c2ecf20Sopenharmony_ci 10138c2ecf20Sopenharmony_ci case RESTORE_POINTERS: 10148c2ecf20Sopenharmony_ci DB(DB_INTR, printk("RDP")) 10158c2ecf20Sopenharmony_ci if (hostdata->level2 >= L2_BASIC) { 10168c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_COMMAND_PHASE, 0x45); 10178c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER); 10188c2ecf20Sopenharmony_ci hostdata->state = S_RUNNING_LEVEL2; 10198c2ecf20Sopenharmony_ci } else { 10208c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK); 10218c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 10228c2ecf20Sopenharmony_ci } 10238c2ecf20Sopenharmony_ci break; 10248c2ecf20Sopenharmony_ci 10258c2ecf20Sopenharmony_ci case DISCONNECT: 10268c2ecf20Sopenharmony_ci DB(DB_INTR, printk("DIS")) 10278c2ecf20Sopenharmony_ci cmd->device->disconnect = 1; 10288c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK); 10298c2ecf20Sopenharmony_ci hostdata->state = S_PRE_TMP_DISC; 10308c2ecf20Sopenharmony_ci break; 10318c2ecf20Sopenharmony_ci 10328c2ecf20Sopenharmony_ci case MESSAGE_REJECT: 10338c2ecf20Sopenharmony_ci DB(DB_INTR, printk("REJ")) 10348c2ecf20Sopenharmony_ci#ifdef SYNC_DEBUG 10358c2ecf20Sopenharmony_ci printk("-REJ-"); 10368c2ecf20Sopenharmony_ci#endif 10378c2ecf20Sopenharmony_ci if (hostdata->sync_stat[cmd->device->id] == SS_WAITING) { 10388c2ecf20Sopenharmony_ci hostdata->sync_stat[cmd->device->id] = SS_SET; 10398c2ecf20Sopenharmony_ci /* we want default_sx_per, not DEFAULT_SX_PER */ 10408c2ecf20Sopenharmony_ci hostdata->sync_xfer[cmd->device->id] = 10418c2ecf20Sopenharmony_ci calc_sync_xfer(hostdata->default_sx_per 10428c2ecf20Sopenharmony_ci / 4, 0, 0, hostdata->sx_table); 10438c2ecf20Sopenharmony_ci } 10448c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK); 10458c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 10468c2ecf20Sopenharmony_ci break; 10478c2ecf20Sopenharmony_ci 10488c2ecf20Sopenharmony_ci case EXTENDED_MESSAGE: 10498c2ecf20Sopenharmony_ci DB(DB_INTR, printk("EXT")) 10508c2ecf20Sopenharmony_ci 10518c2ecf20Sopenharmony_ci ucp = hostdata->incoming_msg; 10528c2ecf20Sopenharmony_ci 10538c2ecf20Sopenharmony_ci#ifdef SYNC_DEBUG 10548c2ecf20Sopenharmony_ci printk("%02x", ucp[hostdata->incoming_ptr]); 10558c2ecf20Sopenharmony_ci#endif 10568c2ecf20Sopenharmony_ci /* Is this the last byte of the extended message? */ 10578c2ecf20Sopenharmony_ci 10588c2ecf20Sopenharmony_ci if ((hostdata->incoming_ptr >= 2) && 10598c2ecf20Sopenharmony_ci (hostdata->incoming_ptr == (ucp[1] + 1))) { 10608c2ecf20Sopenharmony_ci 10618c2ecf20Sopenharmony_ci switch (ucp[2]) { /* what's the EXTENDED code? */ 10628c2ecf20Sopenharmony_ci case EXTENDED_SDTR: 10638c2ecf20Sopenharmony_ci /* default to default async period */ 10648c2ecf20Sopenharmony_ci id = calc_sync_xfer(hostdata-> 10658c2ecf20Sopenharmony_ci default_sx_per / 4, 0, 10668c2ecf20Sopenharmony_ci 0, hostdata->sx_table); 10678c2ecf20Sopenharmony_ci if (hostdata->sync_stat[cmd->device->id] != 10688c2ecf20Sopenharmony_ci SS_WAITING) { 10698c2ecf20Sopenharmony_ci 10708c2ecf20Sopenharmony_ci/* A device has sent an unsolicited SDTR message; rather than go 10718c2ecf20Sopenharmony_ci * through the effort of decoding it and then figuring out what 10728c2ecf20Sopenharmony_ci * our reply should be, we're just gonna say that we have a 10738c2ecf20Sopenharmony_ci * synchronous fifo depth of 0. This will result in asynchronous 10748c2ecf20Sopenharmony_ci * transfers - not ideal but so much easier. 10758c2ecf20Sopenharmony_ci * Actually, this is OK because it assures us that if we don't 10768c2ecf20Sopenharmony_ci * specifically ask for sync transfers, we won't do any. 10778c2ecf20Sopenharmony_ci */ 10788c2ecf20Sopenharmony_ci 10798c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */ 10808c2ecf20Sopenharmony_ci hostdata->outgoing_msg[0] = 10818c2ecf20Sopenharmony_ci EXTENDED_MESSAGE; 10828c2ecf20Sopenharmony_ci hostdata->outgoing_msg[1] = 3; 10838c2ecf20Sopenharmony_ci hostdata->outgoing_msg[2] = 10848c2ecf20Sopenharmony_ci EXTENDED_SDTR; 10858c2ecf20Sopenharmony_ci calc_sync_msg(hostdata-> 10868c2ecf20Sopenharmony_ci default_sx_per, 0, 10878c2ecf20Sopenharmony_ci 0, hostdata->outgoing_msg + 3); 10888c2ecf20Sopenharmony_ci hostdata->outgoing_len = 5; 10898c2ecf20Sopenharmony_ci } else { 10908c2ecf20Sopenharmony_ci if (ucp[4]) /* well, sync transfer */ 10918c2ecf20Sopenharmony_ci id = calc_sync_xfer(ucp[3], ucp[4], 10928c2ecf20Sopenharmony_ci hostdata->fast, 10938c2ecf20Sopenharmony_ci hostdata->sx_table); 10948c2ecf20Sopenharmony_ci else if (ucp[3]) /* very unlikely... */ 10958c2ecf20Sopenharmony_ci id = calc_sync_xfer(ucp[3], ucp[4], 10968c2ecf20Sopenharmony_ci 0, hostdata->sx_table); 10978c2ecf20Sopenharmony_ci } 10988c2ecf20Sopenharmony_ci hostdata->sync_xfer[cmd->device->id] = id; 10998c2ecf20Sopenharmony_ci#ifdef SYNC_DEBUG 11008c2ecf20Sopenharmony_ci printk(" sync_xfer=%02x\n", 11018c2ecf20Sopenharmony_ci hostdata->sync_xfer[cmd->device->id]); 11028c2ecf20Sopenharmony_ci#endif 11038c2ecf20Sopenharmony_ci hostdata->sync_stat[cmd->device->id] = 11048c2ecf20Sopenharmony_ci SS_SET; 11058c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, 11068c2ecf20Sopenharmony_ci WD_CMD_NEGATE_ACK); 11078c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 11088c2ecf20Sopenharmony_ci break; 11098c2ecf20Sopenharmony_ci case EXTENDED_WDTR: 11108c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */ 11118c2ecf20Sopenharmony_ci printk("sending WDTR "); 11128c2ecf20Sopenharmony_ci hostdata->outgoing_msg[0] = 11138c2ecf20Sopenharmony_ci EXTENDED_MESSAGE; 11148c2ecf20Sopenharmony_ci hostdata->outgoing_msg[1] = 2; 11158c2ecf20Sopenharmony_ci hostdata->outgoing_msg[2] = 11168c2ecf20Sopenharmony_ci EXTENDED_WDTR; 11178c2ecf20Sopenharmony_ci hostdata->outgoing_msg[3] = 0; /* 8 bit transfer width */ 11188c2ecf20Sopenharmony_ci hostdata->outgoing_len = 4; 11198c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, 11208c2ecf20Sopenharmony_ci WD_CMD_NEGATE_ACK); 11218c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 11228c2ecf20Sopenharmony_ci break; 11238c2ecf20Sopenharmony_ci default: 11248c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */ 11258c2ecf20Sopenharmony_ci printk 11268c2ecf20Sopenharmony_ci ("Rejecting Unknown Extended Message(%02x). ", 11278c2ecf20Sopenharmony_ci ucp[2]); 11288c2ecf20Sopenharmony_ci hostdata->outgoing_msg[0] = 11298c2ecf20Sopenharmony_ci MESSAGE_REJECT; 11308c2ecf20Sopenharmony_ci hostdata->outgoing_len = 1; 11318c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, 11328c2ecf20Sopenharmony_ci WD_CMD_NEGATE_ACK); 11338c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 11348c2ecf20Sopenharmony_ci break; 11358c2ecf20Sopenharmony_ci } 11368c2ecf20Sopenharmony_ci hostdata->incoming_ptr = 0; 11378c2ecf20Sopenharmony_ci } 11388c2ecf20Sopenharmony_ci 11398c2ecf20Sopenharmony_ci /* We need to read more MESS_IN bytes for the extended message */ 11408c2ecf20Sopenharmony_ci 11418c2ecf20Sopenharmony_ci else { 11428c2ecf20Sopenharmony_ci hostdata->incoming_ptr++; 11438c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK); 11448c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 11458c2ecf20Sopenharmony_ci } 11468c2ecf20Sopenharmony_ci break; 11478c2ecf20Sopenharmony_ci 11488c2ecf20Sopenharmony_ci default: 11498c2ecf20Sopenharmony_ci printk("Rejecting Unknown Message(%02x) ", msg); 11508c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_ASSERT_ATN); /* want MESS_OUT */ 11518c2ecf20Sopenharmony_ci hostdata->outgoing_msg[0] = MESSAGE_REJECT; 11528c2ecf20Sopenharmony_ci hostdata->outgoing_len = 1; 11538c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK); 11548c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 11558c2ecf20Sopenharmony_ci } 11568c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 11578c2ecf20Sopenharmony_ci break; 11588c2ecf20Sopenharmony_ci 11598c2ecf20Sopenharmony_ci/* Note: this interrupt will occur only after a LEVEL2 command */ 11608c2ecf20Sopenharmony_ci 11618c2ecf20Sopenharmony_ci case CSR_SEL_XFER_DONE: 11628c2ecf20Sopenharmony_ci 11638c2ecf20Sopenharmony_ci/* Make sure that reselection is enabled at this point - it may 11648c2ecf20Sopenharmony_ci * have been turned off for the command that just completed. 11658c2ecf20Sopenharmony_ci */ 11668c2ecf20Sopenharmony_ci 11678c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER); 11688c2ecf20Sopenharmony_ci if (phs == 0x60) { 11698c2ecf20Sopenharmony_ci DB(DB_INTR, printk("SX-DONE")) 11708c2ecf20Sopenharmony_ci cmd->SCp.Message = COMMAND_COMPLETE; 11718c2ecf20Sopenharmony_ci lun = read_wd33c93(regs, WD_TARGET_LUN); 11728c2ecf20Sopenharmony_ci DB(DB_INTR, printk(":%d.%d", cmd->SCp.Status, lun)) 11738c2ecf20Sopenharmony_ci hostdata->connected = NULL; 11748c2ecf20Sopenharmony_ci hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff)); 11758c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 11768c2ecf20Sopenharmony_ci if (cmd->SCp.Status == ILLEGAL_STATUS_BYTE) 11778c2ecf20Sopenharmony_ci cmd->SCp.Status = lun; 11788c2ecf20Sopenharmony_ci if (cmd->cmnd[0] == REQUEST_SENSE 11798c2ecf20Sopenharmony_ci && cmd->SCp.Status != GOOD) 11808c2ecf20Sopenharmony_ci cmd->result = 11818c2ecf20Sopenharmony_ci (cmd-> 11828c2ecf20Sopenharmony_ci result & 0x00ffff) | (DID_ERROR << 16); 11838c2ecf20Sopenharmony_ci else 11848c2ecf20Sopenharmony_ci cmd->result = 11858c2ecf20Sopenharmony_ci cmd->SCp.Status | (cmd->SCp.Message << 8); 11868c2ecf20Sopenharmony_ci cmd->scsi_done(cmd); 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ci/* We are no longer connected to a target - check to see if 11898c2ecf20Sopenharmony_ci * there are commands waiting to be executed. 11908c2ecf20Sopenharmony_ci */ 11918c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 11928c2ecf20Sopenharmony_ci wd33c93_execute(instance); 11938c2ecf20Sopenharmony_ci } else { 11948c2ecf20Sopenharmony_ci printk 11958c2ecf20Sopenharmony_ci ("%02x:%02x:%02x: Unknown SEL_XFER_DONE phase!!---", 11968c2ecf20Sopenharmony_ci asr, sr, phs); 11978c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 11988c2ecf20Sopenharmony_ci } 11998c2ecf20Sopenharmony_ci break; 12008c2ecf20Sopenharmony_ci 12018c2ecf20Sopenharmony_ci/* Note: this interrupt will occur only after a LEVEL2 command */ 12028c2ecf20Sopenharmony_ci 12038c2ecf20Sopenharmony_ci case CSR_SDP: 12048c2ecf20Sopenharmony_ci DB(DB_INTR, printk("SDP")) 12058c2ecf20Sopenharmony_ci hostdata->state = S_RUNNING_LEVEL2; 12068c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_COMMAND_PHASE, 0x41); 12078c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER); 12088c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 12098c2ecf20Sopenharmony_ci break; 12108c2ecf20Sopenharmony_ci 12118c2ecf20Sopenharmony_ci case CSR_XFER_DONE | PHS_MESS_OUT: 12128c2ecf20Sopenharmony_ci case CSR_UNEXP | PHS_MESS_OUT: 12138c2ecf20Sopenharmony_ci case CSR_SRV_REQ | PHS_MESS_OUT: 12148c2ecf20Sopenharmony_ci DB(DB_INTR, printk("MSG_OUT=")) 12158c2ecf20Sopenharmony_ci 12168c2ecf20Sopenharmony_ci/* To get here, we've probably requested MESSAGE_OUT and have 12178c2ecf20Sopenharmony_ci * already put the correct bytes in outgoing_msg[] and filled 12188c2ecf20Sopenharmony_ci * in outgoing_len. We simply send them out to the SCSI bus. 12198c2ecf20Sopenharmony_ci * Sometimes we get MESSAGE_OUT phase when we're not expecting 12208c2ecf20Sopenharmony_ci * it - like when our SDTR message is rejected by a target. Some 12218c2ecf20Sopenharmony_ci * targets send the REJECT before receiving all of the extended 12228c2ecf20Sopenharmony_ci * message, and then seem to go back to MESSAGE_OUT for a byte 12238c2ecf20Sopenharmony_ci * or two. Not sure why, or if I'm doing something wrong to 12248c2ecf20Sopenharmony_ci * cause this to happen. Regardless, it seems that sending 12258c2ecf20Sopenharmony_ci * NOP messages in these situations results in no harm and 12268c2ecf20Sopenharmony_ci * makes everyone happy. 12278c2ecf20Sopenharmony_ci */ 12288c2ecf20Sopenharmony_ci if (hostdata->outgoing_len == 0) { 12298c2ecf20Sopenharmony_ci hostdata->outgoing_len = 1; 12308c2ecf20Sopenharmony_ci hostdata->outgoing_msg[0] = NOP; 12318c2ecf20Sopenharmony_ci } 12328c2ecf20Sopenharmony_ci transfer_pio(regs, hostdata->outgoing_msg, 12338c2ecf20Sopenharmony_ci hostdata->outgoing_len, DATA_OUT_DIR, hostdata); 12348c2ecf20Sopenharmony_ci DB(DB_INTR, printk("%02x", hostdata->outgoing_msg[0])) 12358c2ecf20Sopenharmony_ci hostdata->outgoing_len = 0; 12368c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 12378c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 12388c2ecf20Sopenharmony_ci break; 12398c2ecf20Sopenharmony_ci 12408c2ecf20Sopenharmony_ci case CSR_UNEXP_DISC: 12418c2ecf20Sopenharmony_ci 12428c2ecf20Sopenharmony_ci/* I think I've seen this after a request-sense that was in response 12438c2ecf20Sopenharmony_ci * to an error condition, but not sure. We certainly need to do 12448c2ecf20Sopenharmony_ci * something when we get this interrupt - the question is 'what?'. 12458c2ecf20Sopenharmony_ci * Let's think positively, and assume some command has finished 12468c2ecf20Sopenharmony_ci * in a legal manner (like a command that provokes a request-sense), 12478c2ecf20Sopenharmony_ci * so we treat it as a normal command-complete-disconnect. 12488c2ecf20Sopenharmony_ci */ 12498c2ecf20Sopenharmony_ci 12508c2ecf20Sopenharmony_ci/* Make sure that reselection is enabled at this point - it may 12518c2ecf20Sopenharmony_ci * have been turned off for the command that just completed. 12528c2ecf20Sopenharmony_ci */ 12538c2ecf20Sopenharmony_ci 12548c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER); 12558c2ecf20Sopenharmony_ci if (cmd == NULL) { 12568c2ecf20Sopenharmony_ci printk(" - Already disconnected! "); 12578c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 12588c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 12598c2ecf20Sopenharmony_ci return; 12608c2ecf20Sopenharmony_ci } 12618c2ecf20Sopenharmony_ci DB(DB_INTR, printk("UNEXP_DISC")) 12628c2ecf20Sopenharmony_ci hostdata->connected = NULL; 12638c2ecf20Sopenharmony_ci hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff)); 12648c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 12658c2ecf20Sopenharmony_ci if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != GOOD) 12668c2ecf20Sopenharmony_ci cmd->result = 12678c2ecf20Sopenharmony_ci (cmd->result & 0x00ffff) | (DID_ERROR << 16); 12688c2ecf20Sopenharmony_ci else 12698c2ecf20Sopenharmony_ci cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8); 12708c2ecf20Sopenharmony_ci cmd->scsi_done(cmd); 12718c2ecf20Sopenharmony_ci 12728c2ecf20Sopenharmony_ci/* We are no longer connected to a target - check to see if 12738c2ecf20Sopenharmony_ci * there are commands waiting to be executed. 12748c2ecf20Sopenharmony_ci */ 12758c2ecf20Sopenharmony_ci /* look above for comments on scsi_done() */ 12768c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 12778c2ecf20Sopenharmony_ci wd33c93_execute(instance); 12788c2ecf20Sopenharmony_ci break; 12798c2ecf20Sopenharmony_ci 12808c2ecf20Sopenharmony_ci case CSR_DISC: 12818c2ecf20Sopenharmony_ci 12828c2ecf20Sopenharmony_ci/* Make sure that reselection is enabled at this point - it may 12838c2ecf20Sopenharmony_ci * have been turned off for the command that just completed. 12848c2ecf20Sopenharmony_ci */ 12858c2ecf20Sopenharmony_ci 12868c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER); 12878c2ecf20Sopenharmony_ci DB(DB_INTR, printk("DISC")) 12888c2ecf20Sopenharmony_ci if (cmd == NULL) { 12898c2ecf20Sopenharmony_ci printk(" - Already disconnected! "); 12908c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 12918c2ecf20Sopenharmony_ci } 12928c2ecf20Sopenharmony_ci switch (hostdata->state) { 12938c2ecf20Sopenharmony_ci case S_PRE_CMP_DISC: 12948c2ecf20Sopenharmony_ci hostdata->connected = NULL; 12958c2ecf20Sopenharmony_ci hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff)); 12968c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 12978c2ecf20Sopenharmony_ci DB(DB_INTR, printk(":%d", cmd->SCp.Status)) 12988c2ecf20Sopenharmony_ci if (cmd->cmnd[0] == REQUEST_SENSE 12998c2ecf20Sopenharmony_ci && cmd->SCp.Status != GOOD) 13008c2ecf20Sopenharmony_ci cmd->result = 13018c2ecf20Sopenharmony_ci (cmd-> 13028c2ecf20Sopenharmony_ci result & 0x00ffff) | (DID_ERROR << 16); 13038c2ecf20Sopenharmony_ci else 13048c2ecf20Sopenharmony_ci cmd->result = 13058c2ecf20Sopenharmony_ci cmd->SCp.Status | (cmd->SCp.Message << 8); 13068c2ecf20Sopenharmony_ci cmd->scsi_done(cmd); 13078c2ecf20Sopenharmony_ci break; 13088c2ecf20Sopenharmony_ci case S_PRE_TMP_DISC: 13098c2ecf20Sopenharmony_ci case S_RUNNING_LEVEL2: 13108c2ecf20Sopenharmony_ci cmd->host_scribble = (uchar *) hostdata->disconnected_Q; 13118c2ecf20Sopenharmony_ci hostdata->disconnected_Q = cmd; 13128c2ecf20Sopenharmony_ci hostdata->connected = NULL; 13138c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 13148c2ecf20Sopenharmony_ci 13158c2ecf20Sopenharmony_ci#ifdef PROC_STATISTICS 13168c2ecf20Sopenharmony_ci hostdata->disc_done_cnt[cmd->device->id]++; 13178c2ecf20Sopenharmony_ci#endif 13188c2ecf20Sopenharmony_ci 13198c2ecf20Sopenharmony_ci break; 13208c2ecf20Sopenharmony_ci default: 13218c2ecf20Sopenharmony_ci printk("*** Unexpected DISCONNECT interrupt! ***"); 13228c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 13238c2ecf20Sopenharmony_ci } 13248c2ecf20Sopenharmony_ci 13258c2ecf20Sopenharmony_ci/* We are no longer connected to a target - check to see if 13268c2ecf20Sopenharmony_ci * there are commands waiting to be executed. 13278c2ecf20Sopenharmony_ci */ 13288c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 13298c2ecf20Sopenharmony_ci wd33c93_execute(instance); 13308c2ecf20Sopenharmony_ci break; 13318c2ecf20Sopenharmony_ci 13328c2ecf20Sopenharmony_ci case CSR_RESEL_AM: 13338c2ecf20Sopenharmony_ci case CSR_RESEL: 13348c2ecf20Sopenharmony_ci DB(DB_INTR, printk("RESEL%s", sr == CSR_RESEL_AM ? "_AM" : "")) 13358c2ecf20Sopenharmony_ci 13368c2ecf20Sopenharmony_ci /* Old chips (pre -A ???) don't have advanced features and will 13378c2ecf20Sopenharmony_ci * generate CSR_RESEL. In that case we have to extract the LUN the 13388c2ecf20Sopenharmony_ci * hard way (see below). 13398c2ecf20Sopenharmony_ci * First we have to make sure this reselection didn't 13408c2ecf20Sopenharmony_ci * happen during Arbitration/Selection of some other device. 13418c2ecf20Sopenharmony_ci * If yes, put losing command back on top of input_Q. 13428c2ecf20Sopenharmony_ci */ 13438c2ecf20Sopenharmony_ci if (hostdata->level2 <= L2_NONE) { 13448c2ecf20Sopenharmony_ci 13458c2ecf20Sopenharmony_ci if (hostdata->selecting) { 13468c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) hostdata->selecting; 13478c2ecf20Sopenharmony_ci hostdata->selecting = NULL; 13488c2ecf20Sopenharmony_ci hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff)); 13498c2ecf20Sopenharmony_ci cmd->host_scribble = 13508c2ecf20Sopenharmony_ci (uchar *) hostdata->input_Q; 13518c2ecf20Sopenharmony_ci hostdata->input_Q = cmd; 13528c2ecf20Sopenharmony_ci } 13538c2ecf20Sopenharmony_ci } 13548c2ecf20Sopenharmony_ci 13558c2ecf20Sopenharmony_ci else { 13568c2ecf20Sopenharmony_ci 13578c2ecf20Sopenharmony_ci if (cmd) { 13588c2ecf20Sopenharmony_ci if (phs == 0x00) { 13598c2ecf20Sopenharmony_ci hostdata->busy[cmd->device->id] &= 13608c2ecf20Sopenharmony_ci ~(1 << (cmd->device->lun & 0xff)); 13618c2ecf20Sopenharmony_ci cmd->host_scribble = 13628c2ecf20Sopenharmony_ci (uchar *) hostdata->input_Q; 13638c2ecf20Sopenharmony_ci hostdata->input_Q = cmd; 13648c2ecf20Sopenharmony_ci } else { 13658c2ecf20Sopenharmony_ci printk 13668c2ecf20Sopenharmony_ci ("---%02x:%02x:%02x-TROUBLE: Intrusive ReSelect!---", 13678c2ecf20Sopenharmony_ci asr, sr, phs); 13688c2ecf20Sopenharmony_ci while (1) 13698c2ecf20Sopenharmony_ci printk("\r"); 13708c2ecf20Sopenharmony_ci } 13718c2ecf20Sopenharmony_ci } 13728c2ecf20Sopenharmony_ci 13738c2ecf20Sopenharmony_ci } 13748c2ecf20Sopenharmony_ci 13758c2ecf20Sopenharmony_ci /* OK - find out which device reselected us. */ 13768c2ecf20Sopenharmony_ci 13778c2ecf20Sopenharmony_ci id = read_wd33c93(regs, WD_SOURCE_ID); 13788c2ecf20Sopenharmony_ci id &= SRCID_MASK; 13798c2ecf20Sopenharmony_ci 13808c2ecf20Sopenharmony_ci /* and extract the lun from the ID message. (Note that we don't 13818c2ecf20Sopenharmony_ci * bother to check for a valid message here - I guess this is 13828c2ecf20Sopenharmony_ci * not the right way to go, but...) 13838c2ecf20Sopenharmony_ci */ 13848c2ecf20Sopenharmony_ci 13858c2ecf20Sopenharmony_ci if (sr == CSR_RESEL_AM) { 13868c2ecf20Sopenharmony_ci lun = read_wd33c93(regs, WD_DATA); 13878c2ecf20Sopenharmony_ci if (hostdata->level2 < L2_RESELECT) 13888c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_NEGATE_ACK); 13898c2ecf20Sopenharmony_ci lun &= 7; 13908c2ecf20Sopenharmony_ci } else { 13918c2ecf20Sopenharmony_ci /* Old chip; wait for msgin phase to pick up the LUN. */ 13928c2ecf20Sopenharmony_ci for (lun = 255; lun; lun--) { 13938c2ecf20Sopenharmony_ci if ((asr = read_aux_stat(regs)) & ASR_INT) 13948c2ecf20Sopenharmony_ci break; 13958c2ecf20Sopenharmony_ci udelay(10); 13968c2ecf20Sopenharmony_ci } 13978c2ecf20Sopenharmony_ci if (!(asr & ASR_INT)) { 13988c2ecf20Sopenharmony_ci printk 13998c2ecf20Sopenharmony_ci ("wd33c93: Reselected without IDENTIFY\n"); 14008c2ecf20Sopenharmony_ci lun = 0; 14018c2ecf20Sopenharmony_ci } else { 14028c2ecf20Sopenharmony_ci /* Verify this is a change to MSG_IN and read the message */ 14038c2ecf20Sopenharmony_ci sr = read_wd33c93(regs, WD_SCSI_STATUS); 14048c2ecf20Sopenharmony_ci udelay(7); 14058c2ecf20Sopenharmony_ci if (sr == (CSR_ABORT | PHS_MESS_IN) || 14068c2ecf20Sopenharmony_ci sr == (CSR_UNEXP | PHS_MESS_IN) || 14078c2ecf20Sopenharmony_ci sr == (CSR_SRV_REQ | PHS_MESS_IN)) { 14088c2ecf20Sopenharmony_ci /* Got MSG_IN, grab target LUN */ 14098c2ecf20Sopenharmony_ci lun = read_1_byte(regs); 14108c2ecf20Sopenharmony_ci /* Now we expect a 'paused with ACK asserted' int.. */ 14118c2ecf20Sopenharmony_ci asr = read_aux_stat(regs); 14128c2ecf20Sopenharmony_ci if (!(asr & ASR_INT)) { 14138c2ecf20Sopenharmony_ci udelay(10); 14148c2ecf20Sopenharmony_ci asr = read_aux_stat(regs); 14158c2ecf20Sopenharmony_ci if (!(asr & ASR_INT)) 14168c2ecf20Sopenharmony_ci printk 14178c2ecf20Sopenharmony_ci ("wd33c93: No int after LUN on RESEL (%02x)\n", 14188c2ecf20Sopenharmony_ci asr); 14198c2ecf20Sopenharmony_ci } 14208c2ecf20Sopenharmony_ci sr = read_wd33c93(regs, WD_SCSI_STATUS); 14218c2ecf20Sopenharmony_ci udelay(7); 14228c2ecf20Sopenharmony_ci if (sr != CSR_MSGIN) 14238c2ecf20Sopenharmony_ci printk 14248c2ecf20Sopenharmony_ci ("wd33c93: Not paused with ACK on RESEL (%02x)\n", 14258c2ecf20Sopenharmony_ci sr); 14268c2ecf20Sopenharmony_ci lun &= 7; 14278c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, 14288c2ecf20Sopenharmony_ci WD_CMD_NEGATE_ACK); 14298c2ecf20Sopenharmony_ci } else { 14308c2ecf20Sopenharmony_ci printk 14318c2ecf20Sopenharmony_ci ("wd33c93: Not MSG_IN on reselect (%02x)\n", 14328c2ecf20Sopenharmony_ci sr); 14338c2ecf20Sopenharmony_ci lun = 0; 14348c2ecf20Sopenharmony_ci } 14358c2ecf20Sopenharmony_ci } 14368c2ecf20Sopenharmony_ci } 14378c2ecf20Sopenharmony_ci 14388c2ecf20Sopenharmony_ci /* Now we look for the command that's reconnecting. */ 14398c2ecf20Sopenharmony_ci 14408c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) hostdata->disconnected_Q; 14418c2ecf20Sopenharmony_ci patch = NULL; 14428c2ecf20Sopenharmony_ci while (cmd) { 14438c2ecf20Sopenharmony_ci if (id == cmd->device->id && lun == (u8)cmd->device->lun) 14448c2ecf20Sopenharmony_ci break; 14458c2ecf20Sopenharmony_ci patch = cmd; 14468c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) cmd->host_scribble; 14478c2ecf20Sopenharmony_ci } 14488c2ecf20Sopenharmony_ci 14498c2ecf20Sopenharmony_ci /* Hmm. Couldn't find a valid command.... What to do? */ 14508c2ecf20Sopenharmony_ci 14518c2ecf20Sopenharmony_ci if (!cmd) { 14528c2ecf20Sopenharmony_ci printk 14538c2ecf20Sopenharmony_ci ("---TROUBLE: target %d.%d not in disconnect queue---", 14548c2ecf20Sopenharmony_ci id, (u8)lun); 14558c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 14568c2ecf20Sopenharmony_ci return; 14578c2ecf20Sopenharmony_ci } 14588c2ecf20Sopenharmony_ci 14598c2ecf20Sopenharmony_ci /* Ok, found the command - now start it up again. */ 14608c2ecf20Sopenharmony_ci 14618c2ecf20Sopenharmony_ci if (patch) 14628c2ecf20Sopenharmony_ci patch->host_scribble = cmd->host_scribble; 14638c2ecf20Sopenharmony_ci else 14648c2ecf20Sopenharmony_ci hostdata->disconnected_Q = 14658c2ecf20Sopenharmony_ci (struct scsi_cmnd *) cmd->host_scribble; 14668c2ecf20Sopenharmony_ci hostdata->connected = cmd; 14678c2ecf20Sopenharmony_ci 14688c2ecf20Sopenharmony_ci /* We don't need to worry about 'initialize_SCp()' or 'hostdata->busy[]' 14698c2ecf20Sopenharmony_ci * because these things are preserved over a disconnect. 14708c2ecf20Sopenharmony_ci * But we DO need to fix the DPD bit so it's correct for this command. 14718c2ecf20Sopenharmony_ci */ 14728c2ecf20Sopenharmony_ci 14738c2ecf20Sopenharmony_ci if (cmd->sc_data_direction == DMA_TO_DEVICE) 14748c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_DESTINATION_ID, cmd->device->id); 14758c2ecf20Sopenharmony_ci else 14768c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_DESTINATION_ID, 14778c2ecf20Sopenharmony_ci cmd->device->id | DSTID_DPD); 14788c2ecf20Sopenharmony_ci if (hostdata->level2 >= L2_RESELECT) { 14798c2ecf20Sopenharmony_ci write_wd33c93_count(regs, 0); /* we want a DATA_PHASE interrupt */ 14808c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_COMMAND_PHASE, 0x45); 14818c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER); 14828c2ecf20Sopenharmony_ci hostdata->state = S_RUNNING_LEVEL2; 14838c2ecf20Sopenharmony_ci } else 14848c2ecf20Sopenharmony_ci hostdata->state = S_CONNECTED; 14858c2ecf20Sopenharmony_ci 14868c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 14878c2ecf20Sopenharmony_ci break; 14888c2ecf20Sopenharmony_ci 14898c2ecf20Sopenharmony_ci default: 14908c2ecf20Sopenharmony_ci printk("--UNKNOWN INTERRUPT:%02x:%02x:%02x--", asr, sr, phs); 14918c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&hostdata->lock, flags); 14928c2ecf20Sopenharmony_ci } 14938c2ecf20Sopenharmony_ci 14948c2ecf20Sopenharmony_ci DB(DB_INTR, printk("} ")) 14958c2ecf20Sopenharmony_ci 14968c2ecf20Sopenharmony_ci} 14978c2ecf20Sopenharmony_ci 14988c2ecf20Sopenharmony_cistatic void 14998c2ecf20Sopenharmony_cireset_wd33c93(struct Scsi_Host *instance) 15008c2ecf20Sopenharmony_ci{ 15018c2ecf20Sopenharmony_ci struct WD33C93_hostdata *hostdata = 15028c2ecf20Sopenharmony_ci (struct WD33C93_hostdata *) instance->hostdata; 15038c2ecf20Sopenharmony_ci const wd33c93_regs regs = hostdata->regs; 15048c2ecf20Sopenharmony_ci uchar sr; 15058c2ecf20Sopenharmony_ci 15068c2ecf20Sopenharmony_ci#ifdef CONFIG_SGI_IP22 15078c2ecf20Sopenharmony_ci { 15088c2ecf20Sopenharmony_ci int busycount = 0; 15098c2ecf20Sopenharmony_ci extern void sgiwd93_reset(unsigned long); 15108c2ecf20Sopenharmony_ci /* wait 'til the chip gets some time for us */ 15118c2ecf20Sopenharmony_ci while ((read_aux_stat(regs) & ASR_BSY) && busycount++ < 100) 15128c2ecf20Sopenharmony_ci udelay (10); 15138c2ecf20Sopenharmony_ci /* 15148c2ecf20Sopenharmony_ci * there are scsi devices out there, which manage to lock up 15158c2ecf20Sopenharmony_ci * the wd33c93 in a busy condition. In this state it won't 15168c2ecf20Sopenharmony_ci * accept the reset command. The only way to solve this is to 15178c2ecf20Sopenharmony_ci * give the chip a hardware reset (if possible). The code below 15188c2ecf20Sopenharmony_ci * does this for the SGI Indy, where this is possible 15198c2ecf20Sopenharmony_ci */ 15208c2ecf20Sopenharmony_ci /* still busy ? */ 15218c2ecf20Sopenharmony_ci if (read_aux_stat(regs) & ASR_BSY) 15228c2ecf20Sopenharmony_ci sgiwd93_reset(instance->base); /* yeah, give it the hard one */ 15238c2ecf20Sopenharmony_ci } 15248c2ecf20Sopenharmony_ci#endif 15258c2ecf20Sopenharmony_ci 15268c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_OWN_ID, OWNID_EAF | OWNID_RAF | 15278c2ecf20Sopenharmony_ci instance->this_id | hostdata->clock_freq); 15288c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED); 15298c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_SYNCHRONOUS_TRANSFER, 15308c2ecf20Sopenharmony_ci calc_sync_xfer(hostdata->default_sx_per / 4, 15318c2ecf20Sopenharmony_ci DEFAULT_SX_OFF, 0, hostdata->sx_table)); 15328c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_COMMAND, WD_CMD_RESET); 15338c2ecf20Sopenharmony_ci 15348c2ecf20Sopenharmony_ci 15358c2ecf20Sopenharmony_ci#ifdef CONFIG_MVME147_SCSI 15368c2ecf20Sopenharmony_ci udelay(25); /* The old wd33c93 on MVME147 needs this, at least */ 15378c2ecf20Sopenharmony_ci#endif 15388c2ecf20Sopenharmony_ci 15398c2ecf20Sopenharmony_ci while (!(read_aux_stat(regs) & ASR_INT)) 15408c2ecf20Sopenharmony_ci ; 15418c2ecf20Sopenharmony_ci sr = read_wd33c93(regs, WD_SCSI_STATUS); 15428c2ecf20Sopenharmony_ci 15438c2ecf20Sopenharmony_ci hostdata->microcode = read_wd33c93(regs, WD_CDB_1); 15448c2ecf20Sopenharmony_ci if (sr == 0x00) 15458c2ecf20Sopenharmony_ci hostdata->chip = C_WD33C93; 15468c2ecf20Sopenharmony_ci else if (sr == 0x01) { 15478c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_QUEUE_TAG, 0xa5); /* any random number */ 15488c2ecf20Sopenharmony_ci sr = read_wd33c93(regs, WD_QUEUE_TAG); 15498c2ecf20Sopenharmony_ci if (sr == 0xa5) { 15508c2ecf20Sopenharmony_ci hostdata->chip = C_WD33C93B; 15518c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_QUEUE_TAG, 0); 15528c2ecf20Sopenharmony_ci } else 15538c2ecf20Sopenharmony_ci hostdata->chip = C_WD33C93A; 15548c2ecf20Sopenharmony_ci } else 15558c2ecf20Sopenharmony_ci hostdata->chip = C_UNKNOWN_CHIP; 15568c2ecf20Sopenharmony_ci 15578c2ecf20Sopenharmony_ci if (hostdata->chip != C_WD33C93B) /* Fast SCSI unavailable */ 15588c2ecf20Sopenharmony_ci hostdata->fast = 0; 15598c2ecf20Sopenharmony_ci 15608c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_TIMEOUT_PERIOD, TIMEOUT_PERIOD_VALUE); 15618c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_CONTROL, CTRL_IDI | CTRL_EDI | CTRL_POLLED); 15628c2ecf20Sopenharmony_ci} 15638c2ecf20Sopenharmony_ci 15648c2ecf20Sopenharmony_ciint 15658c2ecf20Sopenharmony_ciwd33c93_host_reset(struct scsi_cmnd * SCpnt) 15668c2ecf20Sopenharmony_ci{ 15678c2ecf20Sopenharmony_ci struct Scsi_Host *instance; 15688c2ecf20Sopenharmony_ci struct WD33C93_hostdata *hostdata; 15698c2ecf20Sopenharmony_ci int i; 15708c2ecf20Sopenharmony_ci 15718c2ecf20Sopenharmony_ci instance = SCpnt->device->host; 15728c2ecf20Sopenharmony_ci spin_lock_irq(instance->host_lock); 15738c2ecf20Sopenharmony_ci hostdata = (struct WD33C93_hostdata *) instance->hostdata; 15748c2ecf20Sopenharmony_ci 15758c2ecf20Sopenharmony_ci printk("scsi%d: reset. ", instance->host_no); 15768c2ecf20Sopenharmony_ci disable_irq(instance->irq); 15778c2ecf20Sopenharmony_ci 15788c2ecf20Sopenharmony_ci hostdata->dma_stop(instance, NULL, 0); 15798c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) { 15808c2ecf20Sopenharmony_ci hostdata->busy[i] = 0; 15818c2ecf20Sopenharmony_ci hostdata->sync_xfer[i] = 15828c2ecf20Sopenharmony_ci calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF, 15838c2ecf20Sopenharmony_ci 0, hostdata->sx_table); 15848c2ecf20Sopenharmony_ci hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */ 15858c2ecf20Sopenharmony_ci } 15868c2ecf20Sopenharmony_ci hostdata->input_Q = NULL; 15878c2ecf20Sopenharmony_ci hostdata->selecting = NULL; 15888c2ecf20Sopenharmony_ci hostdata->connected = NULL; 15898c2ecf20Sopenharmony_ci hostdata->disconnected_Q = NULL; 15908c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 15918c2ecf20Sopenharmony_ci hostdata->dma = D_DMA_OFF; 15928c2ecf20Sopenharmony_ci hostdata->incoming_ptr = 0; 15938c2ecf20Sopenharmony_ci hostdata->outgoing_len = 0; 15948c2ecf20Sopenharmony_ci 15958c2ecf20Sopenharmony_ci reset_wd33c93(instance); 15968c2ecf20Sopenharmony_ci SCpnt->result = DID_RESET << 16; 15978c2ecf20Sopenharmony_ci enable_irq(instance->irq); 15988c2ecf20Sopenharmony_ci spin_unlock_irq(instance->host_lock); 15998c2ecf20Sopenharmony_ci return SUCCESS; 16008c2ecf20Sopenharmony_ci} 16018c2ecf20Sopenharmony_ci 16028c2ecf20Sopenharmony_ciint 16038c2ecf20Sopenharmony_ciwd33c93_abort(struct scsi_cmnd * cmd) 16048c2ecf20Sopenharmony_ci{ 16058c2ecf20Sopenharmony_ci struct Scsi_Host *instance; 16068c2ecf20Sopenharmony_ci struct WD33C93_hostdata *hostdata; 16078c2ecf20Sopenharmony_ci wd33c93_regs regs; 16088c2ecf20Sopenharmony_ci struct scsi_cmnd *tmp, *prev; 16098c2ecf20Sopenharmony_ci 16108c2ecf20Sopenharmony_ci disable_irq(cmd->device->host->irq); 16118c2ecf20Sopenharmony_ci 16128c2ecf20Sopenharmony_ci instance = cmd->device->host; 16138c2ecf20Sopenharmony_ci hostdata = (struct WD33C93_hostdata *) instance->hostdata; 16148c2ecf20Sopenharmony_ci regs = hostdata->regs; 16158c2ecf20Sopenharmony_ci 16168c2ecf20Sopenharmony_ci/* 16178c2ecf20Sopenharmony_ci * Case 1 : If the command hasn't been issued yet, we simply remove it 16188c2ecf20Sopenharmony_ci * from the input_Q. 16198c2ecf20Sopenharmony_ci */ 16208c2ecf20Sopenharmony_ci 16218c2ecf20Sopenharmony_ci tmp = (struct scsi_cmnd *) hostdata->input_Q; 16228c2ecf20Sopenharmony_ci prev = NULL; 16238c2ecf20Sopenharmony_ci while (tmp) { 16248c2ecf20Sopenharmony_ci if (tmp == cmd) { 16258c2ecf20Sopenharmony_ci if (prev) 16268c2ecf20Sopenharmony_ci prev->host_scribble = cmd->host_scribble; 16278c2ecf20Sopenharmony_ci else 16288c2ecf20Sopenharmony_ci hostdata->input_Q = 16298c2ecf20Sopenharmony_ci (struct scsi_cmnd *) cmd->host_scribble; 16308c2ecf20Sopenharmony_ci cmd->host_scribble = NULL; 16318c2ecf20Sopenharmony_ci cmd->result = DID_ABORT << 16; 16328c2ecf20Sopenharmony_ci printk 16338c2ecf20Sopenharmony_ci ("scsi%d: Abort - removing command from input_Q. ", 16348c2ecf20Sopenharmony_ci instance->host_no); 16358c2ecf20Sopenharmony_ci enable_irq(cmd->device->host->irq); 16368c2ecf20Sopenharmony_ci cmd->scsi_done(cmd); 16378c2ecf20Sopenharmony_ci return SUCCESS; 16388c2ecf20Sopenharmony_ci } 16398c2ecf20Sopenharmony_ci prev = tmp; 16408c2ecf20Sopenharmony_ci tmp = (struct scsi_cmnd *) tmp->host_scribble; 16418c2ecf20Sopenharmony_ci } 16428c2ecf20Sopenharmony_ci 16438c2ecf20Sopenharmony_ci/* 16448c2ecf20Sopenharmony_ci * Case 2 : If the command is connected, we're going to fail the abort 16458c2ecf20Sopenharmony_ci * and let the high level SCSI driver retry at a later time or 16468c2ecf20Sopenharmony_ci * issue a reset. 16478c2ecf20Sopenharmony_ci * 16488c2ecf20Sopenharmony_ci * Timeouts, and therefore aborted commands, will be highly unlikely 16498c2ecf20Sopenharmony_ci * and handling them cleanly in this situation would make the common 16508c2ecf20Sopenharmony_ci * case of noresets less efficient, and would pollute our code. So, 16518c2ecf20Sopenharmony_ci * we fail. 16528c2ecf20Sopenharmony_ci */ 16538c2ecf20Sopenharmony_ci 16548c2ecf20Sopenharmony_ci if (hostdata->connected == cmd) { 16558c2ecf20Sopenharmony_ci uchar sr, asr; 16568c2ecf20Sopenharmony_ci unsigned long timeout; 16578c2ecf20Sopenharmony_ci 16588c2ecf20Sopenharmony_ci printk("scsi%d: Aborting connected command - ", 16598c2ecf20Sopenharmony_ci instance->host_no); 16608c2ecf20Sopenharmony_ci 16618c2ecf20Sopenharmony_ci printk("stopping DMA - "); 16628c2ecf20Sopenharmony_ci if (hostdata->dma == D_DMA_RUNNING) { 16638c2ecf20Sopenharmony_ci hostdata->dma_stop(instance, cmd, 0); 16648c2ecf20Sopenharmony_ci hostdata->dma = D_DMA_OFF; 16658c2ecf20Sopenharmony_ci } 16668c2ecf20Sopenharmony_ci 16678c2ecf20Sopenharmony_ci printk("sending wd33c93 ABORT command - "); 16688c2ecf20Sopenharmony_ci write_wd33c93(regs, WD_CONTROL, 16698c2ecf20Sopenharmony_ci CTRL_IDI | CTRL_EDI | CTRL_POLLED); 16708c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_ABORT); 16718c2ecf20Sopenharmony_ci 16728c2ecf20Sopenharmony_ci/* Now we have to attempt to flush out the FIFO... */ 16738c2ecf20Sopenharmony_ci 16748c2ecf20Sopenharmony_ci printk("flushing fifo - "); 16758c2ecf20Sopenharmony_ci timeout = 1000000; 16768c2ecf20Sopenharmony_ci do { 16778c2ecf20Sopenharmony_ci asr = read_aux_stat(regs); 16788c2ecf20Sopenharmony_ci if (asr & ASR_DBR) 16798c2ecf20Sopenharmony_ci read_wd33c93(regs, WD_DATA); 16808c2ecf20Sopenharmony_ci } while (!(asr & ASR_INT) && timeout-- > 0); 16818c2ecf20Sopenharmony_ci sr = read_wd33c93(regs, WD_SCSI_STATUS); 16828c2ecf20Sopenharmony_ci printk 16838c2ecf20Sopenharmony_ci ("asr=%02x, sr=%02x, %ld bytes un-transferred (timeout=%ld) - ", 16848c2ecf20Sopenharmony_ci asr, sr, read_wd33c93_count(regs), timeout); 16858c2ecf20Sopenharmony_ci 16868c2ecf20Sopenharmony_ci /* 16878c2ecf20Sopenharmony_ci * Abort command processed. 16888c2ecf20Sopenharmony_ci * Still connected. 16898c2ecf20Sopenharmony_ci * We must disconnect. 16908c2ecf20Sopenharmony_ci */ 16918c2ecf20Sopenharmony_ci 16928c2ecf20Sopenharmony_ci printk("sending wd33c93 DISCONNECT command - "); 16938c2ecf20Sopenharmony_ci write_wd33c93_cmd(regs, WD_CMD_DISCONNECT); 16948c2ecf20Sopenharmony_ci 16958c2ecf20Sopenharmony_ci timeout = 1000000; 16968c2ecf20Sopenharmony_ci asr = read_aux_stat(regs); 16978c2ecf20Sopenharmony_ci while ((asr & ASR_CIP) && timeout-- > 0) 16988c2ecf20Sopenharmony_ci asr = read_aux_stat(regs); 16998c2ecf20Sopenharmony_ci sr = read_wd33c93(regs, WD_SCSI_STATUS); 17008c2ecf20Sopenharmony_ci printk("asr=%02x, sr=%02x.", asr, sr); 17018c2ecf20Sopenharmony_ci 17028c2ecf20Sopenharmony_ci hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff)); 17038c2ecf20Sopenharmony_ci hostdata->connected = NULL; 17048c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 17058c2ecf20Sopenharmony_ci cmd->result = DID_ABORT << 16; 17068c2ecf20Sopenharmony_ci 17078c2ecf20Sopenharmony_ci/* sti();*/ 17088c2ecf20Sopenharmony_ci wd33c93_execute(instance); 17098c2ecf20Sopenharmony_ci 17108c2ecf20Sopenharmony_ci enable_irq(cmd->device->host->irq); 17118c2ecf20Sopenharmony_ci cmd->scsi_done(cmd); 17128c2ecf20Sopenharmony_ci return SUCCESS; 17138c2ecf20Sopenharmony_ci } 17148c2ecf20Sopenharmony_ci 17158c2ecf20Sopenharmony_ci/* 17168c2ecf20Sopenharmony_ci * Case 3: If the command is currently disconnected from the bus, 17178c2ecf20Sopenharmony_ci * we're not going to expend much effort here: Let's just return 17188c2ecf20Sopenharmony_ci * an ABORT_SNOOZE and hope for the best... 17198c2ecf20Sopenharmony_ci */ 17208c2ecf20Sopenharmony_ci 17218c2ecf20Sopenharmony_ci tmp = (struct scsi_cmnd *) hostdata->disconnected_Q; 17228c2ecf20Sopenharmony_ci while (tmp) { 17238c2ecf20Sopenharmony_ci if (tmp == cmd) { 17248c2ecf20Sopenharmony_ci printk 17258c2ecf20Sopenharmony_ci ("scsi%d: Abort - command found on disconnected_Q - ", 17268c2ecf20Sopenharmony_ci instance->host_no); 17278c2ecf20Sopenharmony_ci printk("Abort SNOOZE. "); 17288c2ecf20Sopenharmony_ci enable_irq(cmd->device->host->irq); 17298c2ecf20Sopenharmony_ci return FAILED; 17308c2ecf20Sopenharmony_ci } 17318c2ecf20Sopenharmony_ci tmp = (struct scsi_cmnd *) tmp->host_scribble; 17328c2ecf20Sopenharmony_ci } 17338c2ecf20Sopenharmony_ci 17348c2ecf20Sopenharmony_ci/* 17358c2ecf20Sopenharmony_ci * Case 4 : If we reached this point, the command was not found in any of 17368c2ecf20Sopenharmony_ci * the queues. 17378c2ecf20Sopenharmony_ci * 17388c2ecf20Sopenharmony_ci * We probably reached this point because of an unlikely race condition 17398c2ecf20Sopenharmony_ci * between the command completing successfully and the abortion code, 17408c2ecf20Sopenharmony_ci * so we won't panic, but we will notify the user in case something really 17418c2ecf20Sopenharmony_ci * broke. 17428c2ecf20Sopenharmony_ci */ 17438c2ecf20Sopenharmony_ci 17448c2ecf20Sopenharmony_ci/* sti();*/ 17458c2ecf20Sopenharmony_ci wd33c93_execute(instance); 17468c2ecf20Sopenharmony_ci 17478c2ecf20Sopenharmony_ci enable_irq(cmd->device->host->irq); 17488c2ecf20Sopenharmony_ci printk("scsi%d: warning : SCSI command probably completed successfully" 17498c2ecf20Sopenharmony_ci " before abortion. ", instance->host_no); 17508c2ecf20Sopenharmony_ci return FAILED; 17518c2ecf20Sopenharmony_ci} 17528c2ecf20Sopenharmony_ci 17538c2ecf20Sopenharmony_ci#define MAX_WD33C93_HOSTS 4 17548c2ecf20Sopenharmony_ci#define MAX_SETUP_ARGS ARRAY_SIZE(setup_args) 17558c2ecf20Sopenharmony_ci#define SETUP_BUFFER_SIZE 200 17568c2ecf20Sopenharmony_cistatic char setup_buffer[SETUP_BUFFER_SIZE]; 17578c2ecf20Sopenharmony_cistatic char setup_used[MAX_SETUP_ARGS]; 17588c2ecf20Sopenharmony_cistatic int done_setup = 0; 17598c2ecf20Sopenharmony_ci 17608c2ecf20Sopenharmony_cistatic int 17618c2ecf20Sopenharmony_ciwd33c93_setup(char *str) 17628c2ecf20Sopenharmony_ci{ 17638c2ecf20Sopenharmony_ci int i; 17648c2ecf20Sopenharmony_ci char *p1, *p2; 17658c2ecf20Sopenharmony_ci 17668c2ecf20Sopenharmony_ci /* The kernel does some processing of the command-line before calling 17678c2ecf20Sopenharmony_ci * this function: If it begins with any decimal or hex number arguments, 17688c2ecf20Sopenharmony_ci * ints[0] = how many numbers found and ints[1] through [n] are the values 17698c2ecf20Sopenharmony_ci * themselves. str points to where the non-numeric arguments (if any) 17708c2ecf20Sopenharmony_ci * start: We do our own parsing of those. We construct synthetic 'nosync' 17718c2ecf20Sopenharmony_ci * keywords out of numeric args (to maintain compatibility with older 17728c2ecf20Sopenharmony_ci * versions) and then add the rest of the arguments. 17738c2ecf20Sopenharmony_ci */ 17748c2ecf20Sopenharmony_ci 17758c2ecf20Sopenharmony_ci p1 = setup_buffer; 17768c2ecf20Sopenharmony_ci *p1 = '\0'; 17778c2ecf20Sopenharmony_ci if (str) 17788c2ecf20Sopenharmony_ci strncpy(p1, str, SETUP_BUFFER_SIZE - strlen(setup_buffer)); 17798c2ecf20Sopenharmony_ci setup_buffer[SETUP_BUFFER_SIZE - 1] = '\0'; 17808c2ecf20Sopenharmony_ci p1 = setup_buffer; 17818c2ecf20Sopenharmony_ci i = 0; 17828c2ecf20Sopenharmony_ci while (*p1 && (i < MAX_SETUP_ARGS)) { 17838c2ecf20Sopenharmony_ci p2 = strchr(p1, ','); 17848c2ecf20Sopenharmony_ci if (p2) { 17858c2ecf20Sopenharmony_ci *p2 = '\0'; 17868c2ecf20Sopenharmony_ci if (p1 != p2) 17878c2ecf20Sopenharmony_ci setup_args[i] = p1; 17888c2ecf20Sopenharmony_ci p1 = p2 + 1; 17898c2ecf20Sopenharmony_ci i++; 17908c2ecf20Sopenharmony_ci } else { 17918c2ecf20Sopenharmony_ci setup_args[i] = p1; 17928c2ecf20Sopenharmony_ci break; 17938c2ecf20Sopenharmony_ci } 17948c2ecf20Sopenharmony_ci } 17958c2ecf20Sopenharmony_ci for (i = 0; i < MAX_SETUP_ARGS; i++) 17968c2ecf20Sopenharmony_ci setup_used[i] = 0; 17978c2ecf20Sopenharmony_ci done_setup = 1; 17988c2ecf20Sopenharmony_ci 17998c2ecf20Sopenharmony_ci return 1; 18008c2ecf20Sopenharmony_ci} 18018c2ecf20Sopenharmony_ci__setup("wd33c93=", wd33c93_setup); 18028c2ecf20Sopenharmony_ci 18038c2ecf20Sopenharmony_ci/* check_setup_args() returns index if key found, 0 if not 18048c2ecf20Sopenharmony_ci */ 18058c2ecf20Sopenharmony_cistatic int 18068c2ecf20Sopenharmony_cicheck_setup_args(char *key, int *flags, int *val, char *buf) 18078c2ecf20Sopenharmony_ci{ 18088c2ecf20Sopenharmony_ci int x; 18098c2ecf20Sopenharmony_ci char *cp; 18108c2ecf20Sopenharmony_ci 18118c2ecf20Sopenharmony_ci for (x = 0; x < MAX_SETUP_ARGS; x++) { 18128c2ecf20Sopenharmony_ci if (setup_used[x]) 18138c2ecf20Sopenharmony_ci continue; 18148c2ecf20Sopenharmony_ci if (!strncmp(setup_args[x], key, strlen(key))) 18158c2ecf20Sopenharmony_ci break; 18168c2ecf20Sopenharmony_ci if (!strncmp(setup_args[x], "next", strlen("next"))) 18178c2ecf20Sopenharmony_ci return 0; 18188c2ecf20Sopenharmony_ci } 18198c2ecf20Sopenharmony_ci if (x == MAX_SETUP_ARGS) 18208c2ecf20Sopenharmony_ci return 0; 18218c2ecf20Sopenharmony_ci setup_used[x] = 1; 18228c2ecf20Sopenharmony_ci cp = setup_args[x] + strlen(key); 18238c2ecf20Sopenharmony_ci *val = -1; 18248c2ecf20Sopenharmony_ci if (*cp != ':') 18258c2ecf20Sopenharmony_ci return ++x; 18268c2ecf20Sopenharmony_ci cp++; 18278c2ecf20Sopenharmony_ci if ((*cp >= '0') && (*cp <= '9')) { 18288c2ecf20Sopenharmony_ci *val = simple_strtoul(cp, NULL, 0); 18298c2ecf20Sopenharmony_ci } 18308c2ecf20Sopenharmony_ci return ++x; 18318c2ecf20Sopenharmony_ci} 18328c2ecf20Sopenharmony_ci 18338c2ecf20Sopenharmony_ci/* 18348c2ecf20Sopenharmony_ci * Calculate internal data-transfer-clock cycle from input-clock 18358c2ecf20Sopenharmony_ci * frequency (/MHz) and fill 'sx_table'. 18368c2ecf20Sopenharmony_ci * 18378c2ecf20Sopenharmony_ci * The original driver used to rely on a fixed sx_table, containing periods 18388c2ecf20Sopenharmony_ci * for (only) the lower limits of the respective input-clock-frequency ranges 18398c2ecf20Sopenharmony_ci * (8-10/12-15/16-20 MHz). Although it seems, that no problems occurred with 18408c2ecf20Sopenharmony_ci * this setting so far, it might be desirable to adjust the transfer periods 18418c2ecf20Sopenharmony_ci * closer to the really attached, possibly 25% higher, input-clock, since 18428c2ecf20Sopenharmony_ci * - the wd33c93 may really use a significant shorter period, than it has 18438c2ecf20Sopenharmony_ci * negotiated (eg. thrashing the target, which expects 4/8MHz, with 5/10MHz 18448c2ecf20Sopenharmony_ci * instead). 18458c2ecf20Sopenharmony_ci * - the wd33c93 may ask the target for a lower transfer rate, than the target 18468c2ecf20Sopenharmony_ci * is capable of (eg. negotiating for an assumed minimum of 252ns instead of 18478c2ecf20Sopenharmony_ci * possible 200ns, which indeed shows up in tests as an approx. 10% lower 18488c2ecf20Sopenharmony_ci * transfer rate). 18498c2ecf20Sopenharmony_ci */ 18508c2ecf20Sopenharmony_cistatic inline unsigned int 18518c2ecf20Sopenharmony_ciround_4(unsigned int x) 18528c2ecf20Sopenharmony_ci{ 18538c2ecf20Sopenharmony_ci switch (x & 3) { 18548c2ecf20Sopenharmony_ci case 1: --x; 18558c2ecf20Sopenharmony_ci break; 18568c2ecf20Sopenharmony_ci case 2: ++x; 18578c2ecf20Sopenharmony_ci fallthrough; 18588c2ecf20Sopenharmony_ci case 3: ++x; 18598c2ecf20Sopenharmony_ci } 18608c2ecf20Sopenharmony_ci return x; 18618c2ecf20Sopenharmony_ci} 18628c2ecf20Sopenharmony_ci 18638c2ecf20Sopenharmony_cistatic void 18648c2ecf20Sopenharmony_cicalc_sx_table(unsigned int mhz, struct sx_period sx_table[9]) 18658c2ecf20Sopenharmony_ci{ 18668c2ecf20Sopenharmony_ci unsigned int d, i; 18678c2ecf20Sopenharmony_ci if (mhz < 11) 18688c2ecf20Sopenharmony_ci d = 2; /* divisor for 8-10 MHz input-clock */ 18698c2ecf20Sopenharmony_ci else if (mhz < 16) 18708c2ecf20Sopenharmony_ci d = 3; /* divisor for 12-15 MHz input-clock */ 18718c2ecf20Sopenharmony_ci else 18728c2ecf20Sopenharmony_ci d = 4; /* divisor for 16-20 MHz input-clock */ 18738c2ecf20Sopenharmony_ci 18748c2ecf20Sopenharmony_ci d = (100000 * d) / 2 / mhz; /* 100 x DTCC / nanosec */ 18758c2ecf20Sopenharmony_ci 18768c2ecf20Sopenharmony_ci sx_table[0].period_ns = 1; 18778c2ecf20Sopenharmony_ci sx_table[0].reg_value = 0x20; 18788c2ecf20Sopenharmony_ci for (i = 1; i < 8; i++) { 18798c2ecf20Sopenharmony_ci sx_table[i].period_ns = round_4((i+1)*d / 100); 18808c2ecf20Sopenharmony_ci sx_table[i].reg_value = (i+1)*0x10; 18818c2ecf20Sopenharmony_ci } 18828c2ecf20Sopenharmony_ci sx_table[7].reg_value = 0; 18838c2ecf20Sopenharmony_ci sx_table[8].period_ns = 0; 18848c2ecf20Sopenharmony_ci sx_table[8].reg_value = 0; 18858c2ecf20Sopenharmony_ci} 18868c2ecf20Sopenharmony_ci 18878c2ecf20Sopenharmony_ci/* 18888c2ecf20Sopenharmony_ci * check and, maybe, map an init- or "clock:"- argument. 18898c2ecf20Sopenharmony_ci */ 18908c2ecf20Sopenharmony_cistatic uchar 18918c2ecf20Sopenharmony_ciset_clk_freq(int freq, int *mhz) 18928c2ecf20Sopenharmony_ci{ 18938c2ecf20Sopenharmony_ci int x = freq; 18948c2ecf20Sopenharmony_ci if (WD33C93_FS_8_10 == freq) 18958c2ecf20Sopenharmony_ci freq = 8; 18968c2ecf20Sopenharmony_ci else if (WD33C93_FS_12_15 == freq) 18978c2ecf20Sopenharmony_ci freq = 12; 18988c2ecf20Sopenharmony_ci else if (WD33C93_FS_16_20 == freq) 18998c2ecf20Sopenharmony_ci freq = 16; 19008c2ecf20Sopenharmony_ci else if (freq > 7 && freq < 11) 19018c2ecf20Sopenharmony_ci x = WD33C93_FS_8_10; 19028c2ecf20Sopenharmony_ci else if (freq > 11 && freq < 16) 19038c2ecf20Sopenharmony_ci x = WD33C93_FS_12_15; 19048c2ecf20Sopenharmony_ci else if (freq > 15 && freq < 21) 19058c2ecf20Sopenharmony_ci x = WD33C93_FS_16_20; 19068c2ecf20Sopenharmony_ci else { 19078c2ecf20Sopenharmony_ci /* Hmm, wouldn't it be safer to assume highest freq here? */ 19088c2ecf20Sopenharmony_ci x = WD33C93_FS_8_10; 19098c2ecf20Sopenharmony_ci freq = 8; 19108c2ecf20Sopenharmony_ci } 19118c2ecf20Sopenharmony_ci *mhz = freq; 19128c2ecf20Sopenharmony_ci return x; 19138c2ecf20Sopenharmony_ci} 19148c2ecf20Sopenharmony_ci 19158c2ecf20Sopenharmony_ci/* 19168c2ecf20Sopenharmony_ci * to be used with the resync: fast: ... options 19178c2ecf20Sopenharmony_ci */ 19188c2ecf20Sopenharmony_cistatic inline void set_resync ( struct WD33C93_hostdata *hd, int mask ) 19198c2ecf20Sopenharmony_ci{ 19208c2ecf20Sopenharmony_ci int i; 19218c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) 19228c2ecf20Sopenharmony_ci if (mask & (1 << i)) 19238c2ecf20Sopenharmony_ci hd->sync_stat[i] = SS_UNSET; 19248c2ecf20Sopenharmony_ci} 19258c2ecf20Sopenharmony_ci 19268c2ecf20Sopenharmony_civoid 19278c2ecf20Sopenharmony_ciwd33c93_init(struct Scsi_Host *instance, const wd33c93_regs regs, 19288c2ecf20Sopenharmony_ci dma_setup_t setup, dma_stop_t stop, int clock_freq) 19298c2ecf20Sopenharmony_ci{ 19308c2ecf20Sopenharmony_ci struct WD33C93_hostdata *hostdata; 19318c2ecf20Sopenharmony_ci int i; 19328c2ecf20Sopenharmony_ci int flags; 19338c2ecf20Sopenharmony_ci int val; 19348c2ecf20Sopenharmony_ci char buf[32]; 19358c2ecf20Sopenharmony_ci 19368c2ecf20Sopenharmony_ci if (!done_setup && setup_strings) 19378c2ecf20Sopenharmony_ci wd33c93_setup(setup_strings); 19388c2ecf20Sopenharmony_ci 19398c2ecf20Sopenharmony_ci hostdata = (struct WD33C93_hostdata *) instance->hostdata; 19408c2ecf20Sopenharmony_ci 19418c2ecf20Sopenharmony_ci hostdata->regs = regs; 19428c2ecf20Sopenharmony_ci hostdata->clock_freq = set_clk_freq(clock_freq, &i); 19438c2ecf20Sopenharmony_ci calc_sx_table(i, hostdata->sx_table); 19448c2ecf20Sopenharmony_ci hostdata->dma_setup = setup; 19458c2ecf20Sopenharmony_ci hostdata->dma_stop = stop; 19468c2ecf20Sopenharmony_ci hostdata->dma_bounce_buffer = NULL; 19478c2ecf20Sopenharmony_ci hostdata->dma_bounce_len = 0; 19488c2ecf20Sopenharmony_ci for (i = 0; i < 8; i++) { 19498c2ecf20Sopenharmony_ci hostdata->busy[i] = 0; 19508c2ecf20Sopenharmony_ci hostdata->sync_xfer[i] = 19518c2ecf20Sopenharmony_ci calc_sync_xfer(DEFAULT_SX_PER / 4, DEFAULT_SX_OFF, 19528c2ecf20Sopenharmony_ci 0, hostdata->sx_table); 19538c2ecf20Sopenharmony_ci hostdata->sync_stat[i] = SS_UNSET; /* using default sync values */ 19548c2ecf20Sopenharmony_ci#ifdef PROC_STATISTICS 19558c2ecf20Sopenharmony_ci hostdata->cmd_cnt[i] = 0; 19568c2ecf20Sopenharmony_ci hostdata->disc_allowed_cnt[i] = 0; 19578c2ecf20Sopenharmony_ci hostdata->disc_done_cnt[i] = 0; 19588c2ecf20Sopenharmony_ci#endif 19598c2ecf20Sopenharmony_ci } 19608c2ecf20Sopenharmony_ci hostdata->input_Q = NULL; 19618c2ecf20Sopenharmony_ci hostdata->selecting = NULL; 19628c2ecf20Sopenharmony_ci hostdata->connected = NULL; 19638c2ecf20Sopenharmony_ci hostdata->disconnected_Q = NULL; 19648c2ecf20Sopenharmony_ci hostdata->state = S_UNCONNECTED; 19658c2ecf20Sopenharmony_ci hostdata->dma = D_DMA_OFF; 19668c2ecf20Sopenharmony_ci hostdata->level2 = L2_BASIC; 19678c2ecf20Sopenharmony_ci hostdata->disconnect = DIS_ADAPTIVE; 19688c2ecf20Sopenharmony_ci hostdata->args = DEBUG_DEFAULTS; 19698c2ecf20Sopenharmony_ci hostdata->incoming_ptr = 0; 19708c2ecf20Sopenharmony_ci hostdata->outgoing_len = 0; 19718c2ecf20Sopenharmony_ci hostdata->default_sx_per = DEFAULT_SX_PER; 19728c2ecf20Sopenharmony_ci hostdata->no_dma = 0; /* default is DMA enabled */ 19738c2ecf20Sopenharmony_ci 19748c2ecf20Sopenharmony_ci#ifdef PROC_INTERFACE 19758c2ecf20Sopenharmony_ci hostdata->proc = PR_VERSION | PR_INFO | PR_STATISTICS | 19768c2ecf20Sopenharmony_ci PR_CONNECTED | PR_INPUTQ | PR_DISCQ | PR_STOP; 19778c2ecf20Sopenharmony_ci#ifdef PROC_STATISTICS 19788c2ecf20Sopenharmony_ci hostdata->dma_cnt = 0; 19798c2ecf20Sopenharmony_ci hostdata->pio_cnt = 0; 19808c2ecf20Sopenharmony_ci hostdata->int_cnt = 0; 19818c2ecf20Sopenharmony_ci#endif 19828c2ecf20Sopenharmony_ci#endif 19838c2ecf20Sopenharmony_ci 19848c2ecf20Sopenharmony_ci if (check_setup_args("clock", &flags, &val, buf)) { 19858c2ecf20Sopenharmony_ci hostdata->clock_freq = set_clk_freq(val, &val); 19868c2ecf20Sopenharmony_ci calc_sx_table(val, hostdata->sx_table); 19878c2ecf20Sopenharmony_ci } 19888c2ecf20Sopenharmony_ci 19898c2ecf20Sopenharmony_ci if (check_setup_args("nosync", &flags, &val, buf)) 19908c2ecf20Sopenharmony_ci hostdata->no_sync = val; 19918c2ecf20Sopenharmony_ci 19928c2ecf20Sopenharmony_ci if (check_setup_args("nodma", &flags, &val, buf)) 19938c2ecf20Sopenharmony_ci hostdata->no_dma = (val == -1) ? 1 : val; 19948c2ecf20Sopenharmony_ci 19958c2ecf20Sopenharmony_ci if (check_setup_args("period", &flags, &val, buf)) 19968c2ecf20Sopenharmony_ci hostdata->default_sx_per = 19978c2ecf20Sopenharmony_ci hostdata->sx_table[round_period((unsigned int) val, 19988c2ecf20Sopenharmony_ci hostdata->sx_table)].period_ns; 19998c2ecf20Sopenharmony_ci 20008c2ecf20Sopenharmony_ci if (check_setup_args("disconnect", &flags, &val, buf)) { 20018c2ecf20Sopenharmony_ci if ((val >= DIS_NEVER) && (val <= DIS_ALWAYS)) 20028c2ecf20Sopenharmony_ci hostdata->disconnect = val; 20038c2ecf20Sopenharmony_ci else 20048c2ecf20Sopenharmony_ci hostdata->disconnect = DIS_ADAPTIVE; 20058c2ecf20Sopenharmony_ci } 20068c2ecf20Sopenharmony_ci 20078c2ecf20Sopenharmony_ci if (check_setup_args("level2", &flags, &val, buf)) 20088c2ecf20Sopenharmony_ci hostdata->level2 = val; 20098c2ecf20Sopenharmony_ci 20108c2ecf20Sopenharmony_ci if (check_setup_args("debug", &flags, &val, buf)) 20118c2ecf20Sopenharmony_ci hostdata->args = val & DB_MASK; 20128c2ecf20Sopenharmony_ci 20138c2ecf20Sopenharmony_ci if (check_setup_args("burst", &flags, &val, buf)) 20148c2ecf20Sopenharmony_ci hostdata->dma_mode = val ? CTRL_BURST:CTRL_DMA; 20158c2ecf20Sopenharmony_ci 20168c2ecf20Sopenharmony_ci if (WD33C93_FS_16_20 == hostdata->clock_freq /* divisor 4 */ 20178c2ecf20Sopenharmony_ci && check_setup_args("fast", &flags, &val, buf)) 20188c2ecf20Sopenharmony_ci hostdata->fast = !!val; 20198c2ecf20Sopenharmony_ci 20208c2ecf20Sopenharmony_ci if ((i = check_setup_args("next", &flags, &val, buf))) { 20218c2ecf20Sopenharmony_ci while (i) 20228c2ecf20Sopenharmony_ci setup_used[--i] = 1; 20238c2ecf20Sopenharmony_ci } 20248c2ecf20Sopenharmony_ci#ifdef PROC_INTERFACE 20258c2ecf20Sopenharmony_ci if (check_setup_args("proc", &flags, &val, buf)) 20268c2ecf20Sopenharmony_ci hostdata->proc = val; 20278c2ecf20Sopenharmony_ci#endif 20288c2ecf20Sopenharmony_ci 20298c2ecf20Sopenharmony_ci spin_lock_irq(&hostdata->lock); 20308c2ecf20Sopenharmony_ci reset_wd33c93(instance); 20318c2ecf20Sopenharmony_ci spin_unlock_irq(&hostdata->lock); 20328c2ecf20Sopenharmony_ci 20338c2ecf20Sopenharmony_ci printk("wd33c93-%d: chip=%s/%d no_sync=0x%x no_dma=%d", 20348c2ecf20Sopenharmony_ci instance->host_no, 20358c2ecf20Sopenharmony_ci (hostdata->chip == C_WD33C93) ? "WD33c93" : (hostdata->chip == 20368c2ecf20Sopenharmony_ci C_WD33C93A) ? 20378c2ecf20Sopenharmony_ci "WD33c93A" : (hostdata->chip == 20388c2ecf20Sopenharmony_ci C_WD33C93B) ? "WD33c93B" : "unknown", 20398c2ecf20Sopenharmony_ci hostdata->microcode, hostdata->no_sync, hostdata->no_dma); 20408c2ecf20Sopenharmony_ci#ifdef DEBUGGING_ON 20418c2ecf20Sopenharmony_ci printk(" debug_flags=0x%02x\n", hostdata->args); 20428c2ecf20Sopenharmony_ci#else 20438c2ecf20Sopenharmony_ci printk(" debugging=OFF\n"); 20448c2ecf20Sopenharmony_ci#endif 20458c2ecf20Sopenharmony_ci printk(" setup_args="); 20468c2ecf20Sopenharmony_ci for (i = 0; i < MAX_SETUP_ARGS; i++) 20478c2ecf20Sopenharmony_ci printk("%s,", setup_args[i]); 20488c2ecf20Sopenharmony_ci printk("\n"); 20498c2ecf20Sopenharmony_ci printk(" Version %s - %s\n", WD33C93_VERSION, WD33C93_DATE); 20508c2ecf20Sopenharmony_ci} 20518c2ecf20Sopenharmony_ci 20528c2ecf20Sopenharmony_ciint wd33c93_write_info(struct Scsi_Host *instance, char *buf, int len) 20538c2ecf20Sopenharmony_ci{ 20548c2ecf20Sopenharmony_ci#ifdef PROC_INTERFACE 20558c2ecf20Sopenharmony_ci char *bp; 20568c2ecf20Sopenharmony_ci struct WD33C93_hostdata *hd; 20578c2ecf20Sopenharmony_ci int x; 20588c2ecf20Sopenharmony_ci 20598c2ecf20Sopenharmony_ci hd = (struct WD33C93_hostdata *) instance->hostdata; 20608c2ecf20Sopenharmony_ci 20618c2ecf20Sopenharmony_ci/* We accept the following 20628c2ecf20Sopenharmony_ci * keywords (same format as command-line, but arguments are not optional): 20638c2ecf20Sopenharmony_ci * debug 20648c2ecf20Sopenharmony_ci * disconnect 20658c2ecf20Sopenharmony_ci * period 20668c2ecf20Sopenharmony_ci * resync 20678c2ecf20Sopenharmony_ci * proc 20688c2ecf20Sopenharmony_ci * nodma 20698c2ecf20Sopenharmony_ci * level2 20708c2ecf20Sopenharmony_ci * burst 20718c2ecf20Sopenharmony_ci * fast 20728c2ecf20Sopenharmony_ci * nosync 20738c2ecf20Sopenharmony_ci */ 20748c2ecf20Sopenharmony_ci 20758c2ecf20Sopenharmony_ci buf[len] = '\0'; 20768c2ecf20Sopenharmony_ci for (bp = buf; *bp; ) { 20778c2ecf20Sopenharmony_ci while (',' == *bp || ' ' == *bp) 20788c2ecf20Sopenharmony_ci ++bp; 20798c2ecf20Sopenharmony_ci if (!strncmp(bp, "debug:", 6)) { 20808c2ecf20Sopenharmony_ci hd->args = simple_strtoul(bp+6, &bp, 0) & DB_MASK; 20818c2ecf20Sopenharmony_ci } else if (!strncmp(bp, "disconnect:", 11)) { 20828c2ecf20Sopenharmony_ci x = simple_strtoul(bp+11, &bp, 0); 20838c2ecf20Sopenharmony_ci if (x < DIS_NEVER || x > DIS_ALWAYS) 20848c2ecf20Sopenharmony_ci x = DIS_ADAPTIVE; 20858c2ecf20Sopenharmony_ci hd->disconnect = x; 20868c2ecf20Sopenharmony_ci } else if (!strncmp(bp, "period:", 7)) { 20878c2ecf20Sopenharmony_ci x = simple_strtoul(bp+7, &bp, 0); 20888c2ecf20Sopenharmony_ci hd->default_sx_per = 20898c2ecf20Sopenharmony_ci hd->sx_table[round_period((unsigned int) x, 20908c2ecf20Sopenharmony_ci hd->sx_table)].period_ns; 20918c2ecf20Sopenharmony_ci } else if (!strncmp(bp, "resync:", 7)) { 20928c2ecf20Sopenharmony_ci set_resync(hd, (int)simple_strtoul(bp+7, &bp, 0)); 20938c2ecf20Sopenharmony_ci } else if (!strncmp(bp, "proc:", 5)) { 20948c2ecf20Sopenharmony_ci hd->proc = simple_strtoul(bp+5, &bp, 0); 20958c2ecf20Sopenharmony_ci } else if (!strncmp(bp, "nodma:", 6)) { 20968c2ecf20Sopenharmony_ci hd->no_dma = simple_strtoul(bp+6, &bp, 0); 20978c2ecf20Sopenharmony_ci } else if (!strncmp(bp, "level2:", 7)) { 20988c2ecf20Sopenharmony_ci hd->level2 = simple_strtoul(bp+7, &bp, 0); 20998c2ecf20Sopenharmony_ci } else if (!strncmp(bp, "burst:", 6)) { 21008c2ecf20Sopenharmony_ci hd->dma_mode = 21018c2ecf20Sopenharmony_ci simple_strtol(bp+6, &bp, 0) ? CTRL_BURST:CTRL_DMA; 21028c2ecf20Sopenharmony_ci } else if (!strncmp(bp, "fast:", 5)) { 21038c2ecf20Sopenharmony_ci x = !!simple_strtol(bp+5, &bp, 0); 21048c2ecf20Sopenharmony_ci if (x != hd->fast) 21058c2ecf20Sopenharmony_ci set_resync(hd, 0xff); 21068c2ecf20Sopenharmony_ci hd->fast = x; 21078c2ecf20Sopenharmony_ci } else if (!strncmp(bp, "nosync:", 7)) { 21088c2ecf20Sopenharmony_ci x = simple_strtoul(bp+7, &bp, 0); 21098c2ecf20Sopenharmony_ci set_resync(hd, x ^ hd->no_sync); 21108c2ecf20Sopenharmony_ci hd->no_sync = x; 21118c2ecf20Sopenharmony_ci } else { 21128c2ecf20Sopenharmony_ci break; /* unknown keyword,syntax-error,... */ 21138c2ecf20Sopenharmony_ci } 21148c2ecf20Sopenharmony_ci } 21158c2ecf20Sopenharmony_ci return len; 21168c2ecf20Sopenharmony_ci#else 21178c2ecf20Sopenharmony_ci return 0; 21188c2ecf20Sopenharmony_ci#endif 21198c2ecf20Sopenharmony_ci} 21208c2ecf20Sopenharmony_ci 21218c2ecf20Sopenharmony_ciint 21228c2ecf20Sopenharmony_ciwd33c93_show_info(struct seq_file *m, struct Scsi_Host *instance) 21238c2ecf20Sopenharmony_ci{ 21248c2ecf20Sopenharmony_ci#ifdef PROC_INTERFACE 21258c2ecf20Sopenharmony_ci struct WD33C93_hostdata *hd; 21268c2ecf20Sopenharmony_ci struct scsi_cmnd *cmd; 21278c2ecf20Sopenharmony_ci int x; 21288c2ecf20Sopenharmony_ci 21298c2ecf20Sopenharmony_ci hd = (struct WD33C93_hostdata *) instance->hostdata; 21308c2ecf20Sopenharmony_ci 21318c2ecf20Sopenharmony_ci spin_lock_irq(&hd->lock); 21328c2ecf20Sopenharmony_ci if (hd->proc & PR_VERSION) 21338c2ecf20Sopenharmony_ci seq_printf(m, "\nVersion %s - %s.", 21348c2ecf20Sopenharmony_ci WD33C93_VERSION, WD33C93_DATE); 21358c2ecf20Sopenharmony_ci 21368c2ecf20Sopenharmony_ci if (hd->proc & PR_INFO) { 21378c2ecf20Sopenharmony_ci seq_printf(m, "\nclock_freq=%02x no_sync=%02x no_dma=%d" 21388c2ecf20Sopenharmony_ci " dma_mode=%02x fast=%d", 21398c2ecf20Sopenharmony_ci hd->clock_freq, hd->no_sync, hd->no_dma, hd->dma_mode, hd->fast); 21408c2ecf20Sopenharmony_ci seq_puts(m, "\nsync_xfer[] = "); 21418c2ecf20Sopenharmony_ci for (x = 0; x < 7; x++) 21428c2ecf20Sopenharmony_ci seq_printf(m, "\t%02x", hd->sync_xfer[x]); 21438c2ecf20Sopenharmony_ci seq_puts(m, "\nsync_stat[] = "); 21448c2ecf20Sopenharmony_ci for (x = 0; x < 7; x++) 21458c2ecf20Sopenharmony_ci seq_printf(m, "\t%02x", hd->sync_stat[x]); 21468c2ecf20Sopenharmony_ci } 21478c2ecf20Sopenharmony_ci#ifdef PROC_STATISTICS 21488c2ecf20Sopenharmony_ci if (hd->proc & PR_STATISTICS) { 21498c2ecf20Sopenharmony_ci seq_puts(m, "\ncommands issued: "); 21508c2ecf20Sopenharmony_ci for (x = 0; x < 7; x++) 21518c2ecf20Sopenharmony_ci seq_printf(m, "\t%ld", hd->cmd_cnt[x]); 21528c2ecf20Sopenharmony_ci seq_puts(m, "\ndisconnects allowed:"); 21538c2ecf20Sopenharmony_ci for (x = 0; x < 7; x++) 21548c2ecf20Sopenharmony_ci seq_printf(m, "\t%ld", hd->disc_allowed_cnt[x]); 21558c2ecf20Sopenharmony_ci seq_puts(m, "\ndisconnects done: "); 21568c2ecf20Sopenharmony_ci for (x = 0; x < 7; x++) 21578c2ecf20Sopenharmony_ci seq_printf(m, "\t%ld", hd->disc_done_cnt[x]); 21588c2ecf20Sopenharmony_ci seq_printf(m, 21598c2ecf20Sopenharmony_ci "\ninterrupts: %ld, DATA_PHASE ints: %ld DMA, %ld PIO", 21608c2ecf20Sopenharmony_ci hd->int_cnt, hd->dma_cnt, hd->pio_cnt); 21618c2ecf20Sopenharmony_ci } 21628c2ecf20Sopenharmony_ci#endif 21638c2ecf20Sopenharmony_ci if (hd->proc & PR_CONNECTED) { 21648c2ecf20Sopenharmony_ci seq_puts(m, "\nconnected: "); 21658c2ecf20Sopenharmony_ci if (hd->connected) { 21668c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) hd->connected; 21678c2ecf20Sopenharmony_ci seq_printf(m, " %d:%llu(%02x)", 21688c2ecf20Sopenharmony_ci cmd->device->id, cmd->device->lun, cmd->cmnd[0]); 21698c2ecf20Sopenharmony_ci } 21708c2ecf20Sopenharmony_ci } 21718c2ecf20Sopenharmony_ci if (hd->proc & PR_INPUTQ) { 21728c2ecf20Sopenharmony_ci seq_puts(m, "\ninput_Q: "); 21738c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) hd->input_Q; 21748c2ecf20Sopenharmony_ci while (cmd) { 21758c2ecf20Sopenharmony_ci seq_printf(m, " %d:%llu(%02x)", 21768c2ecf20Sopenharmony_ci cmd->device->id, cmd->device->lun, cmd->cmnd[0]); 21778c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) cmd->host_scribble; 21788c2ecf20Sopenharmony_ci } 21798c2ecf20Sopenharmony_ci } 21808c2ecf20Sopenharmony_ci if (hd->proc & PR_DISCQ) { 21818c2ecf20Sopenharmony_ci seq_puts(m, "\ndisconnected_Q:"); 21828c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) hd->disconnected_Q; 21838c2ecf20Sopenharmony_ci while (cmd) { 21848c2ecf20Sopenharmony_ci seq_printf(m, " %d:%llu(%02x)", 21858c2ecf20Sopenharmony_ci cmd->device->id, cmd->device->lun, cmd->cmnd[0]); 21868c2ecf20Sopenharmony_ci cmd = (struct scsi_cmnd *) cmd->host_scribble; 21878c2ecf20Sopenharmony_ci } 21888c2ecf20Sopenharmony_ci } 21898c2ecf20Sopenharmony_ci seq_putc(m, '\n'); 21908c2ecf20Sopenharmony_ci spin_unlock_irq(&hd->lock); 21918c2ecf20Sopenharmony_ci#endif /* PROC_INTERFACE */ 21928c2ecf20Sopenharmony_ci return 0; 21938c2ecf20Sopenharmony_ci} 21948c2ecf20Sopenharmony_ci 21958c2ecf20Sopenharmony_ciEXPORT_SYMBOL(wd33c93_host_reset); 21968c2ecf20Sopenharmony_ciEXPORT_SYMBOL(wd33c93_init); 21978c2ecf20Sopenharmony_ciEXPORT_SYMBOL(wd33c93_abort); 21988c2ecf20Sopenharmony_ciEXPORT_SYMBOL(wd33c93_queuecommand); 21998c2ecf20Sopenharmony_ciEXPORT_SYMBOL(wd33c93_intr); 22008c2ecf20Sopenharmony_ciEXPORT_SYMBOL(wd33c93_show_info); 22018c2ecf20Sopenharmony_ciEXPORT_SYMBOL(wd33c93_write_info); 2202