53c700.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:68k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* -*- mode: c; c-basic-offset: 8 -*- */
  2. /* NCR (or Symbios) 53c700 and 53c700-66 Driver
  3.  *
  4.  * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
  5. **-----------------------------------------------------------------------------
  6. **  
  7. **  This program is free software; you can redistribute it and/or modify
  8. **  it under the terms of the GNU General Public License as published by
  9. **  the Free Software Foundation; either version 2 of the License, or
  10. **  (at your option) any later version.
  11. **
  12. **  This program is distributed in the hope that it will be useful,
  13. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. **  GNU General Public License for more details.
  16. **
  17. **  You should have received a copy of the GNU General Public License
  18. **  along with this program; if not, write to the Free Software
  19. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. **
  21. **-----------------------------------------------------------------------------
  22.  */
  23. /* Notes:
  24.  *
  25.  * This driver is designed exclusively for these chips (virtually the
  26.  * earliest of the scripts engine chips).  They need their own drivers
  27.  * because they are missing so many of the scripts and snazzy register
  28.  * features of their elder brothers (the 710, 720 and 770).
  29.  *
  30.  * The 700 is the lowliest of the line, it can only do async SCSI.
  31.  * The 700-66 can at least do synchronous SCSI up to 10MHz.
  32.  * 
  33.  * The 700 chip has no host bus interface logic of its own.  However,
  34.  * it is usually mapped to a location with well defined register
  35.  * offsets.  Therefore, if you can determine the base address and the
  36.  * irq your board incorporating this chip uses, you can probably use
  37.  * this driver to run it (although you'll probably have to write a
  38.  * minimal wrapper for the purpose---see the NCR_D700 driver for
  39.  * details about how to do this).
  40.  *
  41.  *
  42.  * TODO List:
  43.  *
  44.  * 1. Better statistics in the proc fs
  45.  *
  46.  * 2. Implement message queue (queues SCSI messages like commands) and make
  47.  *    the abort and device reset functions use them.
  48.  * */
  49. /* CHANGELOG
  50.  *
  51.  * Version 2.8
  52.  *
  53.  * Fixed bad bug affecting tag starvation processing (previously the
  54.  * driver would hang the system if too many tags starved.  Also fixed
  55.  * bad bug having to do with 10 byte command processing and REQUEST
  56.  * SENSE (the command would loop forever getting a transfer length
  57.  * mismatch in the CMD phase).
  58.  *
  59.  * Version 2.7
  60.  *
  61.  * Fixed scripts problem which caused certain devices (notably CDRWs)
  62.  * to hang on initial INQUIRY.  Updated NCR_700_readl/writel to use
  63.  * __raw_readl/writel for parisc compatibility (Thomas
  64.  * Bogendoerfer). Added missing SCp->request_bufflen initialisation
  65.  * for sense requests (Ryan Bradetich).
  66.  *
  67.  * Version 2.6
  68.  *
  69.  * Following test of the 64 bit parisc kernel by Richard Hirst,
  70.  * several problems have now been corrected.  Also adds support for
  71.  * consistent memory allocation.
  72.  *
  73.  * Version 2.5
  74.  * 
  75.  * More Compatibility changes for 710 (now actually works).  Enhanced
  76.  * support for odd clock speeds which constrain SDTR negotiations.
  77.  * correct cacheline separation for scsi messages and status for
  78.  * incoherent architectures.  Use of the pci mapping functions on
  79.  * buffers to begin support for 64 bit drivers.
  80.  *
  81.  * Version 2.4
  82.  *
  83.  * Added support for the 53c710 chip (in 53c700 emulation mode only---no 
  84.  * special 53c710 instructions or registers are used).
  85.  *
  86.  * Version 2.3
  87.  *
  88.  * More endianness/cache coherency changes.
  89.  *
  90.  * Better bad device handling (handles devices lying about tag
  91.  * queueing support and devices which fail to provide sense data on
  92.  * contingent allegiance conditions)
  93.  *
  94.  * Many thanks to Richard Hirst <rhirst@linuxcare.com> for patiently
  95.  * debugging this driver on the parisc architecture and suggesting
  96.  * many improvements and bug fixes.
  97.  *
  98.  * Thanks also go to Linuxcare Inc. for providing several PARISC
  99.  * machines for me to debug the driver on.
  100.  *
  101.  * Version 2.2
  102.  *
  103.  * Made the driver mem or io mapped; added endian invariance; added
  104.  * dma cache flushing operations for architectures which need it;
  105.  * added support for more varied clocking speeds.
  106.  *
  107.  * Version 2.1
  108.  *
  109.  * Initial modularisation from the D700.  See NCR_D700.c for the rest of
  110.  * the changelog.
  111.  * */
  112. #define NCR_700_VERSION "2.8"
  113. #include <linux/config.h>
  114. #include <linux/version.h>
  115. #include <linux/kernel.h>
  116. #include <linux/types.h>
  117. #include <linux/string.h>
  118. #include <linux/ioport.h>
  119. #include <linux/delay.h>
  120. #include <linux/spinlock.h>
  121. #include <linux/sched.h>
  122. #include <linux/proc_fs.h>
  123. #include <linux/init.h>
  124. #include <linux/mca.h>
  125. #include <asm/dma.h>
  126. #include <asm/system.h>
  127. #include <asm/io.h>
  128. #include <asm/pgtable.h>
  129. #include <asm/byteorder.h>
  130. #include <linux/blk.h>
  131. #include <linux/module.h>
  132. #include <linux/pci.h>
  133. #include "scsi.h"
  134. #include "hosts.h"
  135. #include "constants.h"
  136. #include "53c700.h"
  137. /* NOTE: For 64 bit drivers there are points in the code where we use
  138.  * a non dereferenceable pointer to point to a structure in dma-able
  139.  * memory (which is 32 bits) so that we can use all of the structure
  140.  * operations but take the address at the end.  This macro allows us
  141.  * to truncate the 64 bit pointer down to 32 bits without the compiler
  142.  * complaining */
  143. #define to32bit(x) ((__u32)((unsigned long)(x)))
  144. #ifdef NCR_700_DEBUG
  145. #define STATIC
  146. #else
  147. #define STATIC static
  148. #endif
  149. MODULE_AUTHOR("James Bottomley");
  150. MODULE_DESCRIPTION("53c700 and 53c700-66 Driver");
  151. MODULE_LICENSE("GPL");
  152. /* This is the script */
  153. #include "53c700_d.h"
  154. STATIC int NCR_700_queuecommand(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
  155. STATIC int NCR_700_abort(Scsi_Cmnd * SCpnt);
  156. STATIC int NCR_700_bus_reset(Scsi_Cmnd * SCpnt);
  157. STATIC int NCR_700_dev_reset(Scsi_Cmnd * SCpnt);
  158. STATIC int NCR_700_host_reset(Scsi_Cmnd * SCpnt);
  159. STATIC int NCR_700_proc_directory_info(char *, char **, off_t, int, int, int);
  160. STATIC void NCR_700_chip_setup(struct Scsi_Host *host);
  161. STATIC void NCR_700_chip_reset(struct Scsi_Host *host);
  162. static char *NCR_700_phase[] = {
  163. "",
  164. "after selection",
  165. "before command phase",
  166. "after command phase",
  167. "after status phase",
  168. "after data in phase",
  169. "after data out phase",
  170. "during data phase",
  171. };
  172. static char *NCR_700_condition[] = {
  173. "",
  174. "NOT MSG_OUT",
  175. "UNEXPECTED PHASE",
  176. "NOT MSG_IN",
  177. "UNEXPECTED MSG",
  178. "MSG_IN",
  179. "SDTR_MSG RECEIVED",
  180. "REJECT_MSG RECEIVED",
  181. "DISCONNECT_MSG RECEIVED",
  182. "MSG_OUT",
  183. "DATA_IN",
  184. };
  185. static char *NCR_700_fatal_messages[] = {
  186. "unexpected message after reselection",
  187. "still MSG_OUT after message injection",
  188. "not MSG_IN after selection",
  189. "Illegal message length received",
  190. };
  191. static char *NCR_700_SBCL_bits[] = {
  192. "IO ",
  193. "CD ",
  194. "MSG ",
  195. "ATN ",
  196. "SEL ",
  197. "BSY ",
  198. "ACK ",
  199. "REQ ",
  200. };
  201. static char *NCR_700_SBCL_to_phase[] = {
  202. "DATA_OUT",
  203. "DATA_IN",
  204. "CMD_OUT",
  205. "STATE",
  206. "ILLEGAL PHASE",
  207. "ILLEGAL PHASE",
  208. "MSG OUT",
  209. "MSG IN",
  210. };
  211. static __u8 NCR_700_SDTR_msg[] = {
  212. 0x01, /* Extended message */
  213. 0x03, /* Extended message Length */
  214. 0x01, /* SDTR Extended message */
  215. NCR_700_MIN_PERIOD,
  216. NCR_700_MAX_OFFSET
  217. };
  218. struct Scsi_Host * __init
  219. NCR_700_detect(Scsi_Host_Template *tpnt,
  220.        struct NCR_700_Host_Parameters *hostdata)
  221. {
  222. dma_addr_t pScript, pMemory, pSlots;
  223. __u8 *memory;
  224. __u32 *script;
  225. struct Scsi_Host *host;
  226. static int banner = 0;
  227. int j;
  228. #ifdef CONFIG_53C700_USE_CONSISTENT
  229. memory = pci_alloc_consistent(hostdata->pci_dev, TOTAL_MEM_SIZE,
  230.       &pMemory);
  231. hostdata->consistent = 1;
  232. if(memory == NULL ) {
  233. printk(KERN_WARNING "53c700: consistent memory allocation failedn");
  234. #endif
  235. memory = kmalloc(TOTAL_MEM_SIZE, GFP_KERNEL);
  236. if(memory == NULL) {
  237. printk(KERN_ERR "53c700: Failed to allocate memory for driver, detatchingn");
  238. return NULL;
  239. }
  240. pMemory = pci_map_single(hostdata->pci_dev, memory,
  241.  TOTAL_MEM_SIZE, PCI_DMA_BIDIRECTIONAL);
  242. #ifdef CONFIG_53C700_USE_CONSISTENT
  243. hostdata->consistent = 0;
  244. }
  245. #endif
  246. script = (__u32 *)memory;
  247. pScript = pMemory;
  248. hostdata->msgin = memory + MSGIN_OFFSET;
  249. hostdata->msgout = memory + MSGOUT_OFFSET;
  250. hostdata->status = memory + STATUS_OFFSET;
  251. hostdata->slots = (struct NCR_700_command_slot *)(memory + SLOTS_OFFSET);
  252. pSlots = pMemory + SLOTS_OFFSET;
  253. /* Fill in the missing routines from the host template */
  254. tpnt->queuecommand = NCR_700_queuecommand;
  255. tpnt->eh_abort_handler = NCR_700_abort;
  256. tpnt->eh_device_reset_handler = NCR_700_dev_reset;
  257. tpnt->eh_bus_reset_handler = NCR_700_bus_reset;
  258. tpnt->eh_host_reset_handler = NCR_700_host_reset;
  259. tpnt->can_queue = NCR_700_COMMAND_SLOTS_PER_HOST;
  260. tpnt->sg_tablesize = NCR_700_SG_SEGMENTS;
  261. tpnt->cmd_per_lun = NCR_700_MAX_TAGS;
  262. tpnt->use_clustering = DISABLE_CLUSTERING;
  263. tpnt->use_new_eh_code = 1;
  264. tpnt->proc_info = NCR_700_proc_directory_info;
  265. if(tpnt->name == NULL)
  266. tpnt->name = "53c700";
  267. if(tpnt->proc_name == NULL)
  268. tpnt->proc_name = "53c700";
  269. if((host = scsi_register(tpnt, 4)) == NULL)
  270. return NULL;
  271. memset(hostdata->slots, 0, sizeof(struct NCR_700_command_slot)
  272.        * NCR_700_COMMAND_SLOTS_PER_HOST);
  273. for(j = 0; j < NCR_700_COMMAND_SLOTS_PER_HOST; j++) {
  274. dma_addr_t offset = (dma_addr_t)((unsigned long)&hostdata->slots[j].SG[0]
  275.   - (unsigned long)&hostdata->slots[0].SG[0]);
  276. hostdata->slots[j].pSG = (struct NCR_700_SG_List *)((unsigned long)(pSlots + offset));
  277. if(j == 0)
  278. hostdata->free_list = &hostdata->slots[j];
  279. else
  280. hostdata->slots[j-1].ITL_forw = &hostdata->slots[j];
  281. hostdata->slots[j].state = NCR_700_SLOT_FREE;
  282. }
  283. for(j = 0; j < sizeof(SCRIPT)/sizeof(SCRIPT[0]); j++) {
  284. script[j] = bS_to_host(SCRIPT[j]);
  285. }
  286. /* adjust all labels to be bus physical */
  287. for(j = 0; j < PATCHES; j++) {
  288. script[LABELPATCHES[j]] = bS_to_host(pScript + SCRIPT[LABELPATCHES[j]]);
  289. }
  290. /* now patch up fixed addresses. */
  291. script_patch_32(script, MessageLocation,
  292. pScript + MSGOUT_OFFSET);
  293. script_patch_32(script, StatusAddress,
  294. pScript + STATUS_OFFSET);
  295. script_patch_32(script, ReceiveMsgAddress,
  296. pScript + MSGIN_OFFSET);
  297. hostdata->script = script;
  298. hostdata->pScript = pScript;
  299. NCR_700_dma_cache_wback((unsigned long)script, sizeof(SCRIPT));
  300. hostdata->state = NCR_700_HOST_FREE;
  301. spin_lock_init(&hostdata->lock);
  302. hostdata->cmd = NULL;
  303. host->max_id = 7;
  304. host->max_lun = NCR_700_MAX_LUNS;
  305. host->unique_id = hostdata->base;
  306. host->base = hostdata->base;
  307. host->hostdata[0] = (unsigned long)hostdata;
  308. /* kick the chip */
  309. NCR_700_writeb(0xff, host, CTEST9_REG);
  310. if(hostdata->chip710) 
  311. hostdata->rev = (NCR_700_readb(host, CTEST8_REG)>>4) & 0x0f;
  312. else
  313. hostdata->rev = (NCR_700_readb(host, CTEST7_REG)>>4) & 0x0f;
  314. hostdata->fast = (NCR_700_readb(host, CTEST9_REG) == 0);
  315. if(banner == 0) {
  316. printk(KERN_NOTICE "53c700: Version " NCR_700_VERSION " By James.Bottomley@HansenPartnership.comn");
  317. banner = 1;
  318. }
  319. printk(KERN_NOTICE "scsi%d: %s rev %d %sn", host->host_no,
  320.        hostdata->chip710 ? "53c710" : 
  321.        (hostdata->fast ? "53c700-66" : "53c700"),
  322.        hostdata->rev, hostdata->differential ?
  323.        "(Differential)" : "");
  324. /* reset the chip */
  325. NCR_700_chip_reset(host);
  326. return host;
  327. }
  328. int
  329. NCR_700_release(struct Scsi_Host *host)
  330. {
  331. struct NCR_700_Host_Parameters *hostdata = 
  332. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  333. #ifdef CONFIG_53C700_USE_CONSISTENT
  334. if(hostdata->consistent) {
  335. pci_free_consistent(hostdata->pci_dev, TOTAL_MEM_SIZE,
  336.     hostdata->script, hostdata->pScript);
  337. } else {
  338. #endif
  339. pci_unmap_single(hostdata->pci_dev, hostdata->pScript,
  340.  TOTAL_MEM_SIZE, PCI_DMA_BIDIRECTIONAL);
  341. kfree(hostdata->script);
  342. #ifdef CONFIG_53C700_USE_CONSISTENT
  343. }
  344. #endif
  345. return 1;
  346. }
  347. static inline __u8
  348. NCR_700_identify(int can_disconnect, __u8 lun)
  349. {
  350. return IDENTIFY_BASE |
  351. ((can_disconnect) ? 0x40 : 0) |
  352. (lun & NCR_700_LUN_MASK);
  353. }
  354. /*
  355.  * Function : static int data_residual (Scsi_Host *host)
  356.  *
  357.  * Purpose : return residual data count of what's in the chip.  If you
  358.  * really want to know what this function is doing, it's almost a
  359.  * direct transcription of the algorithm described in the 53c710
  360.  * guide, except that the DBC and DFIFO registers are only 6 bits
  361.  * wide on a 53c700.
  362.  *
  363.  * Inputs : host - SCSI host */
  364. static inline int
  365. NCR_700_data_residual (struct Scsi_Host *host) {
  366. struct NCR_700_Host_Parameters *hostdata = 
  367. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  368. int count, synchronous = 0;
  369. unsigned int ddir;
  370. if(hostdata->chip710) {
  371. count = ((NCR_700_readb(host, DFIFO_REG) & 0x7f) -
  372.  (NCR_700_readl(host, DBC_REG) & 0x7f)) & 0x7f;
  373. } else {
  374. count = ((NCR_700_readb(host, DFIFO_REG) & 0x3f) -
  375.  (NCR_700_readl(host, DBC_REG) & 0x3f)) & 0x3f;
  376. }
  377. if(hostdata->fast)
  378. synchronous = NCR_700_readb(host, SXFER_REG) & 0x0f;
  379. /* get the data direction */
  380. ddir = NCR_700_readb(host, CTEST0_REG) & 0x01;
  381. if (ddir) {
  382. /* Receive */
  383. if (synchronous) 
  384. count += (NCR_700_readb(host, SSTAT2_REG) & 0xf0) >> 4;
  385. else
  386. if (NCR_700_readb(host, SSTAT1_REG) & SIDL_REG_FULL)
  387. ++count;
  388. } else {
  389. /* Send */
  390. __u8 sstat = NCR_700_readb(host, SSTAT1_REG);
  391. if (sstat & SODL_REG_FULL)
  392. ++count;
  393. if (synchronous && (sstat & SODR_REG_FULL))
  394. ++count;
  395. }
  396. #ifdef NCR_700_DEBUG
  397. if(count)
  398. printk("RESIDUAL IS %d (ddir %d)n", count, ddir);
  399. #endif
  400. return count;
  401. }
  402. /* print out the SCSI wires and corresponding phase from the SBCL register
  403.  * in the chip */
  404. static inline char *
  405. sbcl_to_string(__u8 sbcl)
  406. {
  407. int i;
  408. static char ret[256];
  409. ret[0]='';
  410. for(i=0; i<8; i++) {
  411. if((1<<i) & sbcl) 
  412. strcat(ret, NCR_700_SBCL_bits[i]);
  413. }
  414. strcat(ret, NCR_700_SBCL_to_phase[sbcl & 0x07]);
  415. return ret;
  416. }
  417. static inline __u8
  418. bitmap_to_number(__u8 bitmap)
  419. {
  420. __u8 i;
  421. for(i=0; i<8 && !(bitmap &(1<<i)); i++)
  422. ;
  423. return i;
  424. }
  425. /* Pull a slot off the free list */
  426. STATIC struct NCR_700_command_slot *
  427. find_empty_slot(struct NCR_700_Host_Parameters *hostdata)
  428. {
  429. struct NCR_700_command_slot *slot = hostdata->free_list;
  430. if(slot == NULL) {
  431. /* sanity check */
  432. if(hostdata->command_slot_count != NCR_700_COMMAND_SLOTS_PER_HOST)
  433. printk(KERN_ERR "SLOTS FULL, but count is %d, should be %dn", hostdata->command_slot_count, NCR_700_COMMAND_SLOTS_PER_HOST);
  434. return NULL;
  435. }
  436. if(slot->state != NCR_700_SLOT_FREE)
  437. /* should panic! */
  438. printk(KERN_ERR "BUSY SLOT ON FREE LIST!!!n");
  439. hostdata->free_list = slot->ITL_forw;
  440. slot->ITL_forw = NULL;
  441. /* NOTE: set the state to busy here, not queued, since this
  442.  * indicates the slot is in use and cannot be run by the IRQ
  443.  * finish routine.  If we cannot queue the command when it
  444.  * is properly build, we then change to NCR_700_SLOT_QUEUED */
  445. slot->state = NCR_700_SLOT_BUSY;
  446. hostdata->command_slot_count++;
  447. return slot;
  448. }
  449. STATIC void 
  450. free_slot(struct NCR_700_command_slot *slot,
  451.   struct NCR_700_Host_Parameters *hostdata)
  452. {
  453. int hash;
  454. struct NCR_700_command_slot **forw, **back;
  455. if((slot->state & NCR_700_SLOT_MASK) != NCR_700_SLOT_MAGIC) {
  456. printk(KERN_ERR "53c700: SLOT %p is not MAGIC!!!n", slot);
  457. }
  458. if(slot->state == NCR_700_SLOT_FREE) {
  459. printk(KERN_ERR "53c700: SLOT %p is FREE!!!n", slot);
  460. }
  461. /* remove from queues */
  462. if(slot->tag != NCR_700_NO_TAG) {
  463. hash = hash_ITLQ(slot->cmnd->target, slot->cmnd->lun,
  464.  slot->tag);
  465. if(slot->ITLQ_forw == NULL)
  466. back = &hostdata->ITLQ_Hash_back[hash];
  467. else
  468. back = &slot->ITLQ_forw->ITLQ_back;
  469. if(slot->ITLQ_back == NULL)
  470. forw = &hostdata->ITLQ_Hash_forw[hash];
  471. else
  472. forw = &slot->ITLQ_back->ITLQ_forw;
  473. *forw = slot->ITLQ_forw;
  474. *back = slot->ITLQ_back;
  475. }
  476. hash = hash_ITL(slot->cmnd->target, slot->cmnd->lun);
  477. if(slot->ITL_forw == NULL)
  478. back = &hostdata->ITL_Hash_back[hash];
  479. else
  480. back = &slot->ITL_forw->ITL_back;
  481. if(slot->ITL_back == NULL)
  482. forw = &hostdata->ITL_Hash_forw[hash];
  483. else
  484. forw = &slot->ITL_back->ITL_forw;
  485. *forw = slot->ITL_forw;
  486. *back = slot->ITL_back;
  487. slot->resume_offset = 0;
  488. slot->cmnd = NULL;
  489. slot->state = NCR_700_SLOT_FREE;
  490. slot->ITL_forw = hostdata->free_list;
  491. hostdata->free_list = slot;
  492. hostdata->command_slot_count--;
  493. }
  494. /* This routine really does very little.  The command is indexed on
  495.    the ITL and (if tagged) the ITLQ lists in _queuecommand */
  496. STATIC void
  497. save_for_reselection(struct NCR_700_Host_Parameters *hostdata,
  498.      Scsi_Cmnd *SCp, __u32 dsp)
  499. {
  500. /* Its just possible that this gets executed twice */
  501. if(SCp != NULL) {
  502. struct NCR_700_command_slot *slot =
  503. (struct NCR_700_command_slot *)SCp->host_scribble;
  504. slot->resume_offset = dsp;
  505. }
  506. hostdata->state = NCR_700_HOST_FREE;
  507. hostdata->cmd = NULL;
  508. }
  509. /* Most likely nexus is the oldest in each case */
  510. STATIC inline struct NCR_700_command_slot *
  511. find_ITL_Nexus(struct NCR_700_Host_Parameters *hostdata, __u8 pun, __u8 lun)
  512. {
  513. int hash = hash_ITL(pun, lun);
  514. struct NCR_700_command_slot *slot = hostdata->ITL_Hash_back[hash];
  515. while(slot != NULL && !(slot->cmnd->target == pun &&
  516. slot->cmnd->lun == lun))
  517. slot = slot->ITL_back;
  518. return slot;
  519. }
  520. STATIC inline struct NCR_700_command_slot *
  521. find_ITLQ_Nexus(struct NCR_700_Host_Parameters *hostdata, __u8 pun,
  522. __u8 lun, __u8 tag)
  523. {
  524. int hash = hash_ITLQ(pun, lun, tag);
  525. struct NCR_700_command_slot *slot = hostdata->ITLQ_Hash_back[hash];
  526. while(slot != NULL && !(slot->cmnd->target == pun 
  527.       && slot->cmnd->lun == lun && slot->tag == tag))
  528. slot = slot->ITLQ_back;
  529. #ifdef NCR_700_TAG_DEBUG
  530. if(slot != NULL) {
  531. struct NCR_700_command_slot *n = slot->ITLQ_back;
  532. while(n != NULL && n->cmnd->target != pun
  533.       && n->cmnd->lun != lun && n->tag != tag)
  534. n = n->ITLQ_back;
  535. if(n != NULL && n->cmnd->target == pun && n->cmnd->lun == lun
  536.    && n->tag == tag) {
  537. printk(KERN_WARNING "53c700: WARNING: DUPLICATE tag %dn",
  538.        tag);
  539. }
  540. }
  541. #endif
  542. return slot;
  543. }
  544. /* This translates the SDTR message offset and period to a value
  545.  * which can be loaded into the SXFER_REG.
  546.  *
  547.  * NOTE: According to SCSI-2, the true transfer period (in ns) is
  548.  *       actually four times this period value */
  549. STATIC inline __u8
  550. NCR_700_offset_period_to_sxfer(struct NCR_700_Host_Parameters *hostdata,
  551.        __u8 offset, __u8 period)
  552. {
  553. int XFERP;
  554. __u8 min_xferp = (hostdata->chip710
  555.   ? NCR_710_MIN_XFERP : NCR_700_MIN_XFERP);
  556. __u8 max_offset = (hostdata->chip710
  557.    ? NCR_710_MAX_OFFSET : NCR_700_MAX_OFFSET);
  558. /* NOTE: NCR_700_SDTR_msg[3] contains our offer of the minimum
  559.  * period.  It is set in NCR_700_chip_setup() */
  560. if(period < NCR_700_SDTR_msg[3]) {
  561. printk(KERN_WARNING "53c700: Period %dns is less than this chip's minimum, setting to %dn", period*4, NCR_700_SDTR_msg[3]*4);
  562. period = NCR_700_SDTR_msg[3];
  563. }
  564. XFERP = (period*4 * hostdata->sync_clock)/1000 - 4;
  565. if(offset > max_offset) {
  566. printk(KERN_WARNING "53c700: Offset %d exceeds chip maximum, setting to %dn",
  567.        offset, max_offset);
  568. offset = max_offset;
  569. }
  570. if(XFERP < min_xferp) {
  571. printk(KERN_WARNING "53c700: XFERP %d is less than minium, setting to %dn",
  572.        XFERP,  min_xferp);
  573. XFERP =  min_xferp;
  574. }
  575. return (offset & 0x0f) | (XFERP & 0x07)<<4;
  576. }
  577. STATIC inline void
  578. NCR_700_unmap(struct NCR_700_Host_Parameters *hostdata, Scsi_Cmnd *SCp,
  579.       struct NCR_700_command_slot *slot)
  580. {
  581. if(SCp->sc_data_direction != SCSI_DATA_NONE &&
  582.    SCp->sc_data_direction != SCSI_DATA_UNKNOWN) {
  583. int pci_direction = scsi_to_pci_dma_dir(SCp->sc_data_direction);
  584. if(SCp->use_sg) {
  585. pci_unmap_sg(hostdata->pci_dev, SCp->buffer,
  586.      SCp->use_sg, pci_direction);
  587. } else {
  588. pci_unmap_single(hostdata->pci_dev,
  589.  slot->dma_handle,
  590.  SCp->request_bufflen,
  591.  pci_direction);
  592. }
  593. }
  594. }
  595. STATIC inline void
  596. NCR_700_scsi_done(struct NCR_700_Host_Parameters *hostdata,
  597.        Scsi_Cmnd *SCp, int result)
  598. {
  599. hostdata->state = NCR_700_HOST_FREE;
  600. hostdata->cmd = NULL;
  601. if(SCp != NULL) {
  602. struct NCR_700_command_slot *slot = 
  603. (struct NCR_700_command_slot *)SCp->host_scribble;
  604. NCR_700_unmap(hostdata, SCp, slot);
  605. pci_unmap_single(hostdata->pci_dev, slot->pCmd,
  606.  sizeof(SCp->cmnd), PCI_DMA_TODEVICE);
  607. if(SCp->cmnd[0] == REQUEST_SENSE && SCp->cmnd[6] == NCR_700_INTERNAL_SENSE_MAGIC) {
  608. #ifdef NCR_700_DEBUG
  609. printk(" ORIGINAL CMD %p RETURNED %d, new return is %d sense isn",
  610.        SCp, SCp->cmnd[7], result);
  611. print_sense("53c700", SCp);
  612. #endif
  613. /* restore the old result if the request sense was
  614.  * successful */
  615. if(result == 0)
  616. result = SCp->cmnd[7];
  617. /* now restore the original command */
  618. memcpy((void *) SCp->cmnd, (void *) SCp->data_cmnd,
  619.        sizeof(SCp->data_cmnd));
  620. SCp->request_buffer = SCp->buffer;
  621. SCp->request_bufflen = SCp->bufflen;
  622. SCp->use_sg = SCp->old_use_sg;
  623. SCp->cmd_len = SCp->old_cmd_len;
  624. SCp->sc_data_direction = SCp->sc_old_data_direction;
  625. SCp->underflow = SCp->old_underflow;
  626. }
  627. free_slot(slot, hostdata);
  628. #ifdef NCR_700_DEBUG
  629. if(NCR_700_get_depth(SCp->device) == 0 ||
  630.    NCR_700_get_depth(SCp->device) > NCR_700_MAX_TAGS)
  631. printk(KERN_ERR "Invalid depth in NCR_700_scsi_done(): %dn",
  632.        NCR_700_get_depth(SCp->device));
  633. #endif /* NCR_700_DEBUG */
  634. NCR_700_set_depth(SCp->device, NCR_700_get_depth(SCp->device) - 1);
  635. SCp->host_scribble = NULL;
  636. SCp->result = result;
  637. SCp->scsi_done(SCp);
  638. } else {
  639. printk(KERN_ERR "53c700: SCSI DONE HAS NULL SCpn");
  640. }
  641. }
  642. STATIC void
  643. NCR_700_internal_bus_reset(struct Scsi_Host *host)
  644. {
  645. /* Bus reset */
  646. NCR_700_writeb(ASSERT_RST, host, SCNTL1_REG);
  647. udelay(50);
  648. NCR_700_writeb(0, host, SCNTL1_REG);
  649. }
  650. STATIC void
  651. NCR_700_chip_setup(struct Scsi_Host *host)
  652. {
  653. struct NCR_700_Host_Parameters *hostdata = 
  654. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  655. __u32 dcntl_extra = 0;
  656. __u8 min_period;
  657. __u8 min_xferp = (hostdata->chip710 ? NCR_710_MIN_XFERP : NCR_700_MIN_XFERP);
  658. if(hostdata->chip710) {
  659. __u8 burst_disable = hostdata->burst_disable
  660. ? BURST_DISABLE : 0;
  661. dcntl_extra = COMPAT_700_MODE;
  662. NCR_700_writeb(dcntl_extra, host, DCNTL_REG);
  663. NCR_700_writeb(BURST_LENGTH_8  | hostdata->dmode_extra,
  664.        host, DMODE_710_REG);
  665. NCR_700_writeb(burst_disable | (hostdata->differential ? 
  666. DIFF : 0), host, CTEST7_REG);
  667. NCR_700_writeb(BTB_TIMER_DISABLE, host, CTEST0_REG);
  668. NCR_700_writeb(FULL_ARBITRATION | ENABLE_PARITY | PARITY
  669.        | AUTO_ATN, host, SCNTL0_REG);
  670. } else {
  671. NCR_700_writeb(BURST_LENGTH_8 | hostdata->dmode_extra,
  672.        host, DMODE_700_REG);
  673. NCR_700_writeb(hostdata->differential ? 
  674.        DIFF : 0, host, CTEST7_REG);
  675. if(hostdata->fast) {
  676. /* this is for 700-66, does nothing on 700 */
  677. NCR_700_writeb(LAST_DIS_ENBL | ENABLE_ACTIVE_NEGATION 
  678.        | GENERATE_RECEIVE_PARITY, host,
  679.        CTEST8_REG);
  680. } else {
  681. NCR_700_writeb(FULL_ARBITRATION | ENABLE_PARITY
  682.        | PARITY | AUTO_ATN, host, SCNTL0_REG);
  683. }
  684. }
  685. NCR_700_writeb(1 << host->this_id, host, SCID_REG);
  686. NCR_700_writeb(0, host, SBCL_REG);
  687. NCR_700_writeb(ASYNC_OPERATION, host, SXFER_REG);
  688. NCR_700_writeb(PHASE_MM_INT | SEL_TIMEOUT_INT | GROSS_ERR_INT | UX_DISC_INT
  689.      | RST_INT | PAR_ERR_INT | SELECT_INT, host, SIEN_REG);
  690. NCR_700_writeb(ABORT_INT | INT_INST_INT | ILGL_INST_INT, host, DIEN_REG);
  691. NCR_700_writeb(ENABLE_SELECT, host, SCNTL1_REG);
  692. if(hostdata->clock > 75) {
  693. printk(KERN_ERR "53c700: Clock speed %dMHz is too high: 75Mhz is the maximum this chip can be driven atn", hostdata->clock);
  694. /* do the best we can, but the async clock will be out
  695.  * of spec: sync divider 2, async divider 3 */
  696. DEBUG(("53c700: sync 2 async 3n"));
  697. NCR_700_writeb(SYNC_DIV_2_0, host, SBCL_REG);
  698. NCR_700_writeb(ASYNC_DIV_3_0 | dcntl_extra, host, DCNTL_REG);
  699. hostdata->sync_clock = hostdata->clock/2;
  700. } else if(hostdata->clock > 50  && hostdata->clock <= 75) {
  701. /* sync divider 1.5, async divider 3 */
  702. DEBUG(("53c700: sync 1.5 async 3n"));
  703. NCR_700_writeb(SYNC_DIV_1_5, host, SBCL_REG);
  704. NCR_700_writeb(ASYNC_DIV_3_0 | dcntl_extra, host, DCNTL_REG);
  705. hostdata->sync_clock = hostdata->clock*2;
  706. hostdata->sync_clock /= 3;
  707. } else if(hostdata->clock > 37 && hostdata->clock <= 50) {
  708. /* sync divider 1, async divider 2 */
  709. DEBUG(("53c700: sync 1 async 2n"));
  710. NCR_700_writeb(SYNC_DIV_1_0, host, SBCL_REG);
  711. NCR_700_writeb(ASYNC_DIV_2_0 | dcntl_extra, host, DCNTL_REG);
  712. hostdata->sync_clock = hostdata->clock;
  713. } else if(hostdata->clock > 25 && hostdata->clock <=37) {
  714. /* sync divider 1, async divider 1.5 */
  715. DEBUG(("53c700: sync 1 async 1.5n"));
  716. NCR_700_writeb(SYNC_DIV_1_0, host, SBCL_REG);
  717. NCR_700_writeb(ASYNC_DIV_1_5 | dcntl_extra, host, DCNTL_REG);
  718. hostdata->sync_clock = hostdata->clock;
  719. } else {
  720. DEBUG(("53c700: sync 1 async 1n"));
  721. NCR_700_writeb(SYNC_DIV_1_0, host, SBCL_REG);
  722. NCR_700_writeb(ASYNC_DIV_1_0 | dcntl_extra, host, DCNTL_REG);
  723. /* sync divider 1, async divider 1 */
  724. hostdata->sync_clock = hostdata->clock;
  725. }
  726. /* Calculate the actual minimum period that can be supported
  727.  * by our synchronous clock speed.  See the 710 manual for
  728.  * exact details of this calculation which is based on a
  729.  * setting of the SXFER register */
  730. min_period = 1000*(4+min_xferp)/(4*hostdata->sync_clock);
  731. if(min_period > NCR_700_MIN_PERIOD) {
  732. NCR_700_SDTR_msg[3] = min_period;
  733. }
  734. if(hostdata->chip710)
  735. NCR_700_SDTR_msg[4] = NCR_710_MAX_OFFSET;
  736. }
  737. STATIC void
  738. NCR_700_chip_reset(struct Scsi_Host *host)
  739. {
  740. struct NCR_700_Host_Parameters *hostdata = 
  741. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  742. if(hostdata->chip710) {
  743. NCR_700_writeb(SOFTWARE_RESET_710, host, ISTAT_REG);
  744. udelay(100);
  745. NCR_700_writeb(0, host, ISTAT_REG);
  746. } else {
  747. NCR_700_writeb(SOFTWARE_RESET, host, DCNTL_REG);
  748. udelay(100);
  749. NCR_700_writeb(0, host, DCNTL_REG);
  750. }
  751. mdelay(1000);
  752. NCR_700_chip_setup(host);
  753. }
  754. /* The heart of the message processing engine is that the instruction
  755.  * immediately after the INT is the normal case (and so must be CLEAR
  756.  * ACK).  If we want to do something else, we call that routine in
  757.  * scripts and set temp to be the normal case + 8 (skipping the CLEAR
  758.  * ACK) so that the routine returns correctly to resume its activity
  759.  * */
  760. STATIC __u32
  761. process_extended_message(struct Scsi_Host *host, 
  762.  struct NCR_700_Host_Parameters *hostdata,
  763.  Scsi_Cmnd *SCp, __u32 dsp, __u32 dsps)
  764. {
  765. __u32 resume_offset = dsp, temp = dsp + 8;
  766. __u8 pun = 0xff, lun = 0xff;
  767. if(SCp != NULL) {
  768. pun = SCp->target;
  769. lun = SCp->lun;
  770. }
  771. switch(hostdata->msgin[2]) {
  772. case A_SDTR_MSG:
  773. if(SCp != NULL && NCR_700_is_flag_set(SCp->device, NCR_700_DEV_BEGIN_SYNC_NEGOTIATION)) {
  774. __u8 period = hostdata->msgin[3];
  775. __u8 offset = hostdata->msgin[4];
  776. __u8 sxfer;
  777. if(offset != 0 && period != 0)
  778. sxfer = NCR_700_offset_period_to_sxfer(hostdata, offset, period);
  779. else 
  780. sxfer = 0;
  781. if(sxfer != NCR_700_get_SXFER(SCp->device)) {
  782. printk(KERN_INFO "scsi%d: (%d:%d) Synchronous at offset %d, period %dnsn",
  783.        host->host_no, pun, lun,
  784.        offset, period*4);
  785. NCR_700_set_SXFER(SCp->device, sxfer);
  786. }
  787. NCR_700_set_flag(SCp->device, NCR_700_DEV_NEGOTIATED_SYNC);
  788. NCR_700_clear_flag(SCp->device, NCR_700_DEV_BEGIN_SYNC_NEGOTIATION);
  789. NCR_700_writeb(NCR_700_get_SXFER(SCp->device),
  790.        host, SXFER_REG);
  791. } else {
  792. /* SDTR message out of the blue, reject it */
  793. printk(KERN_WARNING "scsi%d Unexpected SDTR msgn",
  794.        host->host_no);
  795. hostdata->msgout[0] = A_REJECT_MSG;
  796. NCR_700_dma_cache_wback((unsigned long)hostdata->msgout, 1);
  797. script_patch_16(hostdata->script, MessageCount, 1);
  798. /* SendMsgOut returns, so set up the return
  799.  * address */
  800. resume_offset = hostdata->pScript + Ent_SendMessageWithATN;
  801. }
  802. break;
  803. case A_WDTR_MSG:
  804. printk(KERN_INFO "scsi%d: (%d:%d), Unsolicited WDTR after CMD, Rejectingn",
  805.        host->host_no, pun, lun);
  806. hostdata->msgout[0] = A_REJECT_MSG;
  807. NCR_700_dma_cache_wback((unsigned long)hostdata->msgout, 1);
  808. script_patch_16(hostdata->script, MessageCount, 1);
  809. resume_offset = hostdata->pScript + Ent_SendMessageWithATN;
  810. break;
  811. default:
  812. printk(KERN_INFO "scsi%d (%d:%d): Unexpected message %s: ",
  813.        host->host_no, pun, lun,
  814.        NCR_700_phase[(dsps & 0xf00) >> 8]);
  815. print_msg(hostdata->msgin);
  816. printk("n");
  817. /* just reject it */
  818. hostdata->msgout[0] = A_REJECT_MSG;
  819. NCR_700_dma_cache_wback((unsigned long)hostdata->msgout, 1);
  820. script_patch_16(hostdata->script, MessageCount, 1);
  821. /* SendMsgOut returns, so set up the return
  822.  * address */
  823. resume_offset = hostdata->pScript + Ent_SendMessageWithATN;
  824. }
  825. NCR_700_writel(temp, host, TEMP_REG);
  826. return resume_offset;
  827. }
  828. STATIC __u32
  829. process_message(struct Scsi_Host *host, struct NCR_700_Host_Parameters *hostdata,
  830. Scsi_Cmnd *SCp, __u32 dsp, __u32 dsps)
  831. {
  832. /* work out where to return to */
  833. __u32 temp = dsp + 8, resume_offset = dsp;
  834. __u8 pun = 0xff, lun = 0xff;
  835. if(SCp != NULL) {
  836. pun = SCp->target;
  837. lun = SCp->lun;
  838. }
  839. #ifdef NCR_700_DEBUG
  840. printk("scsi%d (%d:%d): message %s: ", host->host_no, pun, lun,
  841.        NCR_700_phase[(dsps & 0xf00) >> 8]);
  842. print_msg(hostdata->msgin);
  843. printk("n");
  844. #endif
  845. switch(hostdata->msgin[0]) {
  846. case A_EXTENDED_MSG:
  847. resume_offset =  process_extended_message(host, hostdata, SCp,
  848.   dsp, dsps);
  849. break;
  850. case A_REJECT_MSG:
  851. if(SCp != NULL && NCR_700_is_flag_set(SCp->device, NCR_700_DEV_BEGIN_SYNC_NEGOTIATION)) {
  852. /* Rejected our sync negotiation attempt */
  853. NCR_700_set_SXFER(SCp->device, 0);
  854. NCR_700_set_flag(SCp->device, NCR_700_DEV_NEGOTIATED_SYNC);
  855. NCR_700_clear_flag(SCp->device, NCR_700_DEV_BEGIN_SYNC_NEGOTIATION);
  856. } else if(SCp != NULL && NCR_700_is_flag_set(SCp->device, NCR_700_DEV_BEGIN_TAG_QUEUEING)) {
  857. /* rejected our first simple tag message */
  858. printk(KERN_WARNING "scsi%d (%d:%d) Rejected first tag queue attempt, turning off tag queueingn", host->host_no, pun, lun);
  859. NCR_700_clear_flag(SCp->device, NCR_700_DEV_BEGIN_TAG_QUEUEING);
  860. hostdata->tag_negotiated &= ~(1<<SCp->target);
  861. SCp->device->tagged_queue = 0;
  862. SCp->device->tagged_supported = 0;
  863. } else {
  864. printk(KERN_WARNING "scsi%d (%d:%d) Unexpected REJECT Message %sn",
  865.        host->host_no, pun, lun,
  866.        NCR_700_phase[(dsps & 0xf00) >> 8]);
  867. /* however, just ignore it */
  868. }
  869. break;
  870. case A_PARITY_ERROR_MSG:
  871. printk(KERN_ERR "scsi%d (%d:%d) Parity Error!n", host->host_no,
  872.        pun, lun);
  873. NCR_700_internal_bus_reset(host);
  874. break;
  875. case A_SIMPLE_TAG_MSG:
  876. printk(KERN_INFO "scsi%d (%d:%d) SIMPLE TAG %d %sn", host->host_no,
  877.        pun, lun, hostdata->msgin[1],
  878.        NCR_700_phase[(dsps & 0xf00) >> 8]);
  879. /* just ignore it */
  880. break;
  881. default:
  882. printk(KERN_INFO "scsi%d (%d:%d): Unexpected message %s: ",
  883.        host->host_no, pun, lun,
  884.        NCR_700_phase[(dsps & 0xf00) >> 8]);
  885. print_msg(hostdata->msgin);
  886. printk("n");
  887. /* just reject it */
  888. hostdata->msgout[0] = A_REJECT_MSG;
  889. NCR_700_dma_cache_wback((unsigned long)hostdata->msgout, 1);
  890. script_patch_16(hostdata->script, MessageCount, 1);
  891. /* SendMsgOut returns, so set up the return
  892.  * address */
  893. resume_offset = hostdata->pScript + Ent_SendMessageWithATN;
  894. break;
  895. }
  896. NCR_700_writel(temp, host, TEMP_REG);
  897. /* set us up to receive another message */
  898. NCR_700_dma_cache_inv((unsigned long)hostdata->msgin, MSG_ARRAY_SIZE);
  899. return resume_offset;
  900. }
  901. STATIC __u32
  902. process_script_interrupt(__u32 dsps, __u32 dsp, Scsi_Cmnd *SCp,
  903.  struct Scsi_Host *host,
  904.  struct NCR_700_Host_Parameters *hostdata)
  905. {
  906. __u32 resume_offset = 0;
  907. __u8 pun = 0xff, lun=0xff;
  908. if(SCp != NULL) {
  909. pun = SCp->target;
  910. lun = SCp->lun;
  911. }
  912. if(dsps == A_GOOD_STATUS_AFTER_STATUS) {
  913. DEBUG(("  COMMAND COMPLETE, status=%02xn",
  914.        hostdata->status[0]));
  915. /* OK, if TCQ still on, we know it works */
  916. NCR_700_clear_flag(SCp->device, NCR_700_DEV_BEGIN_TAG_QUEUEING);
  917. /* check for contingent allegiance contitions */
  918. if(status_byte(hostdata->status[0]) == CHECK_CONDITION ||
  919.    status_byte(hostdata->status[0]) == COMMAND_TERMINATED) {
  920. struct NCR_700_command_slot *slot =
  921. (struct NCR_700_command_slot *)SCp->host_scribble;
  922. if(SCp->cmnd[0] == REQUEST_SENSE) {
  923. /* OOPS: bad device, returning another
  924.  * contingent allegiance condition */
  925. printk(KERN_ERR "scsi%d (%d:%d) broken device is looping in contingent allegiance: ignoringn", host->host_no, pun, lun);
  926. NCR_700_scsi_done(hostdata, SCp, hostdata->status[0]);
  927. } else {
  928. #ifdef NCR_DEBUG
  929. print_command(SCp->cmnd);
  930. printk("  cmd %p has status %d, requesting sensen",
  931.        SCp, hostdata->status[0]);
  932. #endif
  933. /* we can destroy the command here
  934.  * because the contingent allegiance
  935.  * condition will cause a retry which
  936.  * will re-copy the command from the
  937.  * saved data_cmnd.  We also unmap any
  938.  * data associated with the command
  939.  * here */
  940. NCR_700_unmap(hostdata, SCp, slot);
  941. SCp->cmnd[0] = REQUEST_SENSE;
  942. SCp->cmnd[1] = (SCp->lun & 0x7) << 5;
  943. SCp->cmnd[2] = 0;
  944. SCp->cmnd[3] = 0;
  945. SCp->cmnd[4] = sizeof(SCp->sense_buffer);
  946. SCp->cmnd[5] = 0;
  947. SCp->cmd_len = 6;
  948. /* Here's a quiet hack: the
  949.  * REQUEST_SENSE command is six bytes,
  950.  * so store a flag indicating that
  951.  * this was an internal sense request
  952.  * and the original status at the end
  953.  * of the command */
  954. SCp->cmnd[6] = NCR_700_INTERNAL_SENSE_MAGIC;
  955. SCp->cmnd[7] = hostdata->status[0];
  956. SCp->use_sg = 0;
  957. SCp->sc_data_direction = SCSI_DATA_READ;
  958. pci_dma_sync_single(hostdata->pci_dev,
  959.     slot->pCmd,
  960.     SCp->cmd_len,
  961.     PCI_DMA_TODEVICE);
  962. SCp->request_bufflen = sizeof(SCp->sense_buffer);
  963. slot->dma_handle = pci_map_single(hostdata->pci_dev, SCp->sense_buffer, sizeof(SCp->sense_buffer), PCI_DMA_FROMDEVICE);
  964. slot->SG[0].ins = bS_to_host(SCRIPT_MOVE_DATA_IN | sizeof(SCp->sense_buffer));
  965. slot->SG[0].pAddr = bS_to_host(slot->dma_handle);
  966. slot->SG[1].ins = bS_to_host(SCRIPT_RETURN);
  967. slot->SG[1].pAddr = 0;
  968. slot->resume_offset = hostdata->pScript;
  969. NCR_700_dma_cache_wback((unsigned long)slot->SG, sizeof(slot->SG[0])*2);
  970. NCR_700_dma_cache_inv((unsigned long)SCp->sense_buffer, sizeof(SCp->sense_buffer));
  971. /* queue the command for reissue */
  972. slot->state = NCR_700_SLOT_QUEUED;
  973. hostdata->state = NCR_700_HOST_FREE;
  974. hostdata->cmd = NULL;
  975. }
  976. } else {
  977. // Currently rely on the mid layer evaluation
  978. // of the tag queuing capability
  979. //
  980. //if(status_byte(hostdata->status[0]) == GOOD &&
  981. //   SCp->cmnd[0] == INQUIRY && SCp->use_sg == 0) {
  982. // /* Piggy back the tag queueing support
  983. //  * on this command */
  984. // pci_dma_sync_single(hostdata->pci_dev,
  985. //     slot->dma_handle,
  986. //     SCp->request_bufflen,
  987. //     PCI_DMA_FROMDEVICE);
  988. // if(((char *)SCp->request_buffer)[7] & 0x02) {
  989. // printk(KERN_INFO "scsi%d: (%d:%d) Enabling Tag Command Queuingn", host->host_no, pun, lun);
  990. // hostdata->tag_negotiated |= (1<<SCp->target);
  991. // NCR_700_set_flag(SCp->device, NCR_700_DEV_BEGIN_TAG_QUEUEING);
  992. // } else {
  993. // NCR_700_clear_flag(SCp->device, NCR_700_DEV_BEGIN_TAG_QUEUEING);
  994. // hostdata->tag_negotiated &= ~(1<<SCp->target);
  995. // }
  996. //}
  997. NCR_700_scsi_done(hostdata, SCp, hostdata->status[0]);
  998. }
  999. } else if((dsps & 0xfffff0f0) == A_UNEXPECTED_PHASE) {
  1000. __u8 i = (dsps & 0xf00) >> 8;
  1001. printk(KERN_ERR "scsi%d: (%d:%d), UNEXPECTED PHASE %s (%s)n",
  1002.        host->host_no, pun, lun,
  1003.        NCR_700_phase[i],
  1004.        sbcl_to_string(NCR_700_readb(host, SBCL_REG)));
  1005. printk(KERN_ERR "         len = %d, cmd =", SCp->cmd_len);
  1006. print_command(SCp->cmnd);
  1007. NCR_700_internal_bus_reset(host);
  1008. } else if((dsps & 0xfffff000) == A_FATAL) {
  1009. int i = (dsps & 0xfff);
  1010. printk(KERN_ERR "scsi%d: (%d:%d) FATAL ERROR: %sn",
  1011.        host->host_no, pun, lun, NCR_700_fatal_messages[i]);
  1012. if(dsps == A_FATAL_ILLEGAL_MSG_LENGTH) {
  1013. printk(KERN_ERR "     msg begins %02x %02xn",
  1014.        hostdata->msgin[0], hostdata->msgin[1]);
  1015. }
  1016. NCR_700_internal_bus_reset(host);
  1017. } else if((dsps & 0xfffff0f0) == A_DISCONNECT) {
  1018. #ifdef NCR_700_DEBUG
  1019. __u8 i = (dsps & 0xf00) >> 8;
  1020. printk("scsi%d: (%d:%d), DISCONNECTED (%d) %sn",
  1021.        host->host_no, pun, lun,
  1022.        i, NCR_700_phase[i]);
  1023. #endif
  1024. save_for_reselection(hostdata, SCp, dsp);
  1025. } else if(dsps == A_RESELECTION_IDENTIFIED) {
  1026. __u8 lun;
  1027. struct NCR_700_command_slot *slot;
  1028. __u8 reselection_id = hostdata->reselection_id;
  1029. lun = hostdata->msgin[0] & 0x1f;
  1030. hostdata->reselection_id = 0xff;
  1031. DEBUG(("scsi%d: (%d:%d) RESELECTED!n",
  1032.        host->host_no, reselection_id, lun));
  1033. /* clear the reselection indicator */
  1034. if(hostdata->msgin[1] == A_SIMPLE_TAG_MSG) {
  1035. slot = find_ITLQ_Nexus(hostdata, reselection_id,
  1036.        lun, hostdata->msgin[2]);
  1037. } else {
  1038. slot = find_ITL_Nexus(hostdata, reselection_id, lun);
  1039. }
  1040. retry:
  1041. if(slot == NULL) {
  1042. struct NCR_700_command_slot *s = find_ITL_Nexus(hostdata, reselection_id, lun);
  1043. printk(KERN_ERR "scsi%d: (%d:%d) RESELECTED but no saved command (MSG = %02x %02x %02x)!!n",
  1044.        host->host_no, reselection_id, lun,
  1045.        hostdata->msgin[0], hostdata->msgin[1],
  1046.        hostdata->msgin[2]);
  1047. printk(KERN_ERR " OUTSTANDING TAGS:");
  1048. while(s != NULL) {
  1049. if(s->cmnd->target == reselection_id &&
  1050.    s->cmnd->lun == lun) {
  1051. printk("%d ", s->tag);
  1052. if(s->tag == hostdata->msgin[2]) {
  1053. printk(" ***FOUND*** n");
  1054. slot = s;
  1055. goto retry;
  1056. }
  1057. }
  1058. s = s->ITL_back;
  1059. }
  1060. printk("n");
  1061. } else {
  1062. if(hostdata->state != NCR_700_HOST_BUSY)
  1063. printk(KERN_ERR "scsi%d: FATAL, host not busy during valid reselection!n",
  1064.        host->host_no);
  1065. resume_offset = slot->resume_offset;
  1066. hostdata->cmd = slot->cmnd;
  1067. /* re-patch for this command */
  1068. script_patch_32_abs(hostdata->script, CommandAddress, 
  1069.     slot->pCmd);
  1070. script_patch_16(hostdata->script,
  1071. CommandCount, slot->cmnd->cmd_len);
  1072. script_patch_32_abs(hostdata->script, SGScriptStartAddress,
  1073.     to32bit(&slot->pSG[0].ins));
  1074. /* Note: setting SXFER only works if we're
  1075.  * still in the MESSAGE phase, so it is vital
  1076.  * that ACK is still asserted when we process
  1077.  * the reselection message.  The resume offset
  1078.  * should therefore always clear ACK */
  1079. NCR_700_writeb(NCR_700_get_SXFER(hostdata->cmd->device),
  1080.        host, SXFER_REG);
  1081. NCR_700_dma_cache_inv((unsigned long)hostdata->msgin,
  1082.       MSG_ARRAY_SIZE);
  1083. NCR_700_dma_cache_wback((unsigned long)hostdata->msgout,
  1084. MSG_ARRAY_SIZE);
  1085. /* I'm just being paranoid here, the command should
  1086.  * already have been flushed from the cache */
  1087. NCR_700_dma_cache_wback((unsigned long)slot->cmnd->cmnd,
  1088. slot->cmnd->cmd_len);
  1089. }
  1090. } else if(dsps == A_RESELECTED_DURING_SELECTION) {
  1091. /* This section is full of debugging code because I've
  1092.  * never managed to reach it.  I think what happens is
  1093.  * that, because the 700 runs with selection
  1094.  * interrupts enabled the whole time that we take a
  1095.  * selection interrupt before we manage to get to the
  1096.  * reselected script interrupt */
  1097. __u8 reselection_id = NCR_700_readb(host, SFBR_REG);
  1098. struct NCR_700_command_slot *slot;
  1099. /* Take out our own ID */
  1100. reselection_id &= ~(1<<host->this_id);
  1101. /* I've never seen this happen, so keep this as a printk rather
  1102.  * than a debug */
  1103. printk(KERN_INFO "scsi%d: (%d:%d) RESELECTION DURING SELECTION, dsp=%08x[%04x] state=%d, count=%dn",
  1104.        host->host_no, reselection_id, lun, dsp, dsp - hostdata->pScript, hostdata->state, hostdata->command_slot_count);
  1105. {
  1106. /* FIXME: DEBUGGING CODE */
  1107. __u32 SG = (__u32)bS_to_cpu(hostdata->script[A_SGScriptStartAddress_used[0]]);
  1108. int i;
  1109. for(i=0; i< NCR_700_COMMAND_SLOTS_PER_HOST; i++) {
  1110. if(SG >= to32bit(&hostdata->slots[i].pSG[0])
  1111.    && SG <= to32bit(&hostdata->slots[i].pSG[NCR_700_SG_SEGMENTS]))
  1112. break;
  1113. }
  1114. printk(KERN_INFO "IDENTIFIED SG segment as being %08x in slot %p, cmd %p, slot->resume_offset=%08xn", SG, &hostdata->slots[i], hostdata->slots[i].cmnd, hostdata->slots[i].resume_offset);
  1115. SCp =  hostdata->slots[i].cmnd;
  1116. }
  1117. if(SCp != NULL) {
  1118. slot = (struct NCR_700_command_slot *)SCp->host_scribble;
  1119. /* change slot from busy to queued to redo command */
  1120. slot->state = NCR_700_SLOT_QUEUED;
  1121. }
  1122. hostdata->cmd = NULL;
  1123. if(reselection_id == 0) {
  1124. if(hostdata->reselection_id == 0xff) {
  1125. printk(KERN_ERR "scsi%d: Invalid reselection during selection!!n", host->host_no);
  1126. return 0;
  1127. } else {
  1128. printk(KERN_ERR "scsi%d: script reselected and we took a selection interruptn",
  1129.        host->host_no);
  1130. reselection_id = hostdata->reselection_id;
  1131. }
  1132. } else {
  1133. /* convert to real ID */
  1134. reselection_id = bitmap_to_number(reselection_id);
  1135. }
  1136. hostdata->reselection_id = reselection_id;
  1137. /* just in case we have a stale simple tag message, clear it */
  1138. hostdata->msgin[1] = 0;
  1139. NCR_700_dma_cache_wback_inv((unsigned long)hostdata->msgin,
  1140.     MSG_ARRAY_SIZE);
  1141. if(hostdata->tag_negotiated & (1<<reselection_id)) {
  1142. resume_offset = hostdata->pScript + Ent_GetReselectionWithTag;
  1143. } else {
  1144. resume_offset = hostdata->pScript + Ent_GetReselectionData;
  1145. }
  1146. } else if(dsps == A_COMPLETED_SELECTION_AS_TARGET) {
  1147. /* we've just disconnected from the bus, do nothing since
  1148.  * a return here will re-run the queued command slot
  1149.  * that may have been interrupted by the initial selection */
  1150. DEBUG((" SELECTION COMPLETEDn"));
  1151. } else if((dsps & 0xfffff0f0) == A_MSG_IN) { 
  1152. resume_offset = process_message(host, hostdata, SCp,
  1153. dsp, dsps);
  1154. } else if((dsps &  0xfffff000) == 0) {
  1155. __u8 i = (dsps & 0xf0) >> 4, j = (dsps & 0xf00) >> 8;
  1156. printk(KERN_ERR "scsi%d: (%d:%d), unhandled script condition %s %s at %04xn",
  1157.        host->host_no, pun, lun, NCR_700_condition[i],
  1158.        NCR_700_phase[j], dsp - hostdata->pScript);
  1159. if(SCp != NULL) {
  1160. print_command(SCp->cmnd);
  1161. if(SCp->use_sg) {
  1162. for(i = 0; i < SCp->use_sg + 1; i++) {
  1163. printk(KERN_INFO " SG[%d].length = %d, move_insn=%08x, addr %08xn", i, ((struct scatterlist *)SCp->buffer)[i].length, ((struct NCR_700_command_slot *)SCp->host_scribble)->SG[i].ins, ((struct NCR_700_command_slot *)SCp->host_scribble)->SG[i].pAddr);
  1164. }
  1165. }
  1166. }        
  1167. NCR_700_internal_bus_reset(host);
  1168. } else if((dsps & 0xfffff000) == A_DEBUG_INTERRUPT) {
  1169. printk(KERN_NOTICE "scsi%d (%d:%d) DEBUG INTERRUPT %d AT %08x[%04x], continuingn",
  1170.        host->host_no, pun, lun, dsps & 0xfff, dsp, dsp - hostdata->pScript);
  1171. resume_offset = dsp;
  1172. } else {
  1173. printk(KERN_ERR "scsi%d: (%d:%d), unidentified script interrupt 0x%x at %04xn",
  1174.        host->host_no, pun, lun, dsps, dsp - hostdata->pScript);
  1175. NCR_700_internal_bus_reset(host);
  1176. }
  1177. return resume_offset;
  1178. }
  1179. /* We run the 53c700 with selection interrupts always enabled.  This
  1180.  * means that the chip may be selected as soon as the bus frees.  On a
  1181.  * busy bus, this can be before the scripts engine finishes its
  1182.  * processing.  Therefore, part of the selection processing has to be
  1183.  * to find out what the scripts engine is doing and complete the
  1184.  * function if necessary (i.e. process the pending disconnect or save
  1185.  * the interrupted initial selection */
  1186. STATIC inline __u32
  1187. process_selection(struct Scsi_Host *host, __u32 dsp)
  1188. {
  1189. __u8 id = 0; /* Squash compiler warning */
  1190. int count = 0;
  1191. __u32 resume_offset = 0;
  1192. struct NCR_700_Host_Parameters *hostdata =
  1193. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  1194. Scsi_Cmnd *SCp = hostdata->cmd;
  1195. __u8 sbcl;
  1196. for(count = 0; count < 5; count++) {
  1197. id = NCR_700_readb(host, hostdata->chip710 ?
  1198.    CTEST9_REG : SFBR_REG);
  1199. /* Take out our own ID */
  1200. id &= ~(1<<host->this_id);
  1201. if(id != 0) 
  1202. break;
  1203. udelay(5);
  1204. }
  1205. sbcl = NCR_700_readb(host, SBCL_REG);
  1206. if((sbcl & SBCL_IO) == 0) {
  1207. /* mark as having been selected rather than reselected */
  1208. id = 0xff;
  1209. } else {
  1210. /* convert to real ID */
  1211. hostdata->reselection_id = id = bitmap_to_number(id);
  1212. DEBUG(("scsi%d:  Reselected by %dn",
  1213.        host->host_no, id));
  1214. }
  1215. if(hostdata->state == NCR_700_HOST_BUSY && SCp != NULL) {
  1216. struct NCR_700_command_slot *slot =
  1217. (struct NCR_700_command_slot *)SCp->host_scribble;
  1218. DEBUG(("  ID %d WARNING: RESELECTION OF BUSY HOST, saving cmd %p, slot %p, addr %x [%04x], resume %x!n", id, hostdata->cmd, slot, dsp, dsp - hostdata->pScript, resume_offset));
  1219. switch(dsp - hostdata->pScript) {
  1220. case Ent_Disconnect1:
  1221. case Ent_Disconnect2:
  1222. save_for_reselection(hostdata, SCp, Ent_Disconnect2 + hostdata->pScript);
  1223. break;
  1224. case Ent_Disconnect3:
  1225. case Ent_Disconnect4:
  1226. save_for_reselection(hostdata, SCp, Ent_Disconnect4 + hostdata->pScript);
  1227. break;
  1228. case Ent_Disconnect5:
  1229. case Ent_Disconnect6:
  1230. save_for_reselection(hostdata, SCp, Ent_Disconnect6 + hostdata->pScript);
  1231. break;
  1232. case Ent_Disconnect7:
  1233. case Ent_Disconnect8:
  1234. save_for_reselection(hostdata, SCp, Ent_Disconnect8 + hostdata->pScript);
  1235. break;
  1236. case Ent_Finish1:
  1237. case Ent_Finish2:
  1238. process_script_interrupt(A_GOOD_STATUS_AFTER_STATUS, dsp, SCp, host, hostdata);
  1239. break;
  1240. default:
  1241. slot->state = NCR_700_SLOT_QUEUED;
  1242. break;
  1243. }
  1244. }
  1245. hostdata->state = NCR_700_HOST_BUSY;
  1246. hostdata->cmd = NULL;
  1247. /* clear any stale simple tag message */
  1248. hostdata->msgin[1] = 0;
  1249. NCR_700_dma_cache_wback_inv((unsigned long)hostdata->msgin, MSG_ARRAY_SIZE);
  1250. if(id == 0xff) {
  1251. /* Selected as target, Ignore */
  1252. resume_offset = hostdata->pScript + Ent_SelectedAsTarget;
  1253. } else if(hostdata->tag_negotiated & (1<<id)) {
  1254. resume_offset = hostdata->pScript + Ent_GetReselectionWithTag;
  1255. } else {
  1256. resume_offset = hostdata->pScript + Ent_GetReselectionData;
  1257. }
  1258. return resume_offset;
  1259. }
  1260. static inline void
  1261. NCR_700_clear_fifo(struct Scsi_Host *host) {
  1262. const struct NCR_700_Host_Parameters *hostdata
  1263. = (struct NCR_700_Host_Parameters *)host->hostdata[0];
  1264. if(hostdata->chip710) {
  1265. NCR_700_writeb(CLR_FIFO_710, host, CTEST8_REG);
  1266. } else {
  1267. NCR_700_writeb(CLR_FIFO, host, DFIFO_REG);
  1268. }
  1269. }
  1270. static inline void
  1271. NCR_700_flush_fifo(struct Scsi_Host *host) {
  1272. const struct NCR_700_Host_Parameters *hostdata
  1273. = (struct NCR_700_Host_Parameters *)host->hostdata[0];
  1274. if(hostdata->chip710) {
  1275. NCR_700_writeb(FLUSH_DMA_FIFO_710, host, CTEST8_REG);
  1276. udelay(10);
  1277. NCR_700_writeb(0, host, CTEST8_REG);
  1278. } else {
  1279. NCR_700_writeb(FLUSH_DMA_FIFO, host, DFIFO_REG);
  1280. udelay(10);
  1281. NCR_700_writeb(0, host, DFIFO_REG);
  1282. }
  1283. }
  1284. STATIC int
  1285. NCR_700_start_command(Scsi_Cmnd *SCp)
  1286. {
  1287. struct NCR_700_command_slot *slot =
  1288. (struct NCR_700_command_slot *)SCp->host_scribble;
  1289. struct NCR_700_Host_Parameters *hostdata =
  1290. (struct NCR_700_Host_Parameters *)SCp->host->hostdata[0];
  1291. unsigned long flags;
  1292. __u16 count = 1; /* for IDENTIFY message */
  1293. save_flags(flags);
  1294. cli();
  1295. if(hostdata->state != NCR_700_HOST_FREE) {
  1296. /* keep this inside the lock to close the race window where
  1297.  * the running command finishes on another CPU while we don't
  1298.  * change the state to queued on this one */
  1299. slot->state = NCR_700_SLOT_QUEUED;
  1300. restore_flags(flags);
  1301. DEBUG(("scsi%d: host busy, queueing command %p, slot %pn",
  1302.        SCp->host->host_no, slot->cmnd, slot));
  1303. return 0;
  1304. }
  1305. hostdata->state = NCR_700_HOST_BUSY;
  1306. hostdata->cmd = SCp;
  1307. slot->state = NCR_700_SLOT_BUSY;
  1308. /* keep interrupts disabled until we have the command correctly
  1309.  * set up so we cannot take a selection interrupt */
  1310. hostdata->msgout[0] = NCR_700_identify(SCp->cmnd[0] != REQUEST_SENSE,
  1311.        SCp->lun);
  1312. /* for INQUIRY or REQUEST_SENSE commands, we cannot be sure
  1313.  * if the negotiated transfer parameters still hold, so
  1314.  * always renegotiate them */
  1315. if(SCp->cmnd[0] == INQUIRY || SCp->cmnd[0] == REQUEST_SENSE) {
  1316. NCR_700_clear_flag(SCp->device, NCR_700_DEV_NEGOTIATED_SYNC);
  1317. }
  1318. /* REQUEST_SENSE is asking for contingent I_T_L(_Q) status.
  1319.  * If a contingent allegiance condition exists, the device
  1320.  * will refuse all tags, so send the request sense as untagged
  1321.  * */
  1322. if((hostdata->tag_negotiated & (1<<SCp->target))
  1323.    && (slot->tag != NCR_700_NO_TAG && SCp->cmnd[0] != REQUEST_SENSE)) {
  1324. hostdata->msgout[count++] = A_SIMPLE_TAG_MSG;
  1325. hostdata->msgout[count++] = slot->tag;
  1326. }
  1327. if(hostdata->fast &&
  1328.    NCR_700_is_flag_clear(SCp->device, NCR_700_DEV_NEGOTIATED_SYNC)) {
  1329. memcpy(&hostdata->msgout[count], NCR_700_SDTR_msg,
  1330.        sizeof(NCR_700_SDTR_msg));
  1331. count += sizeof(NCR_700_SDTR_msg);
  1332. NCR_700_set_flag(SCp->device, NCR_700_DEV_BEGIN_SYNC_NEGOTIATION);
  1333. }
  1334. script_patch_16(hostdata->script, MessageCount, count);
  1335. script_patch_ID(hostdata->script,
  1336. Device_ID, 1<<SCp->target);
  1337. script_patch_32_abs(hostdata->script, CommandAddress, 
  1338.     slot->pCmd);
  1339. script_patch_16(hostdata->script, CommandCount, SCp->cmd_len);
  1340. /* finally plumb the beginning of the SG list into the script
  1341.  * */
  1342. script_patch_32_abs(hostdata->script, SGScriptStartAddress,
  1343.     to32bit(&slot->pSG[0].ins));
  1344. NCR_700_clear_fifo(SCp->host);
  1345. if(slot->resume_offset == 0)
  1346. slot->resume_offset = hostdata->pScript;
  1347. /* now perform all the writebacks and invalidates */
  1348. NCR_700_dma_cache_wback((unsigned long)hostdata->msgout, count);
  1349. NCR_700_dma_cache_inv((unsigned long)hostdata->msgin, MSG_ARRAY_SIZE);
  1350. NCR_700_dma_cache_wback((unsigned long)SCp->cmnd, SCp->cmd_len);
  1351. NCR_700_dma_cache_inv((unsigned long)hostdata->status, 1);
  1352. /* set the synchronous period/offset */
  1353. NCR_700_writeb(NCR_700_get_SXFER(SCp->device),
  1354.        SCp->host, SXFER_REG);
  1355. NCR_700_writel(slot->temp, SCp->host, TEMP_REG);
  1356. NCR_700_writel(slot->resume_offset, SCp->host, DSP_REG);
  1357. /* allow interrupts here so that if we're selected we can take
  1358.  * a selection interrupt.  The script start may not be
  1359.  * effective in this case, but the selection interrupt will
  1360.  * save our command in that case */
  1361. restore_flags(flags);
  1362. return 1;
  1363. }
  1364. void
  1365. NCR_700_intr(int irq, void *dev_id, struct pt_regs *regs)
  1366. {
  1367. struct Scsi_Host *host = (struct Scsi_Host *)dev_id;
  1368. struct NCR_700_Host_Parameters *hostdata =
  1369. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  1370. __u8 istat;
  1371. __u32 resume_offset = 0;
  1372. __u8 pun = 0xff, lun = 0xff;
  1373. unsigned long flags;
  1374. /* Unfortunately, we have to take the io_request_lock here
  1375.  * rather than the host lock hostdata->lock because we're
  1376.  * looking to exclude queuecommand from messing with the
  1377.  * registers while we're processing the interrupt.  Since
  1378.  * queuecommand is called holding io_request_lock, and we have
  1379.  * to take io_request_lock before we call the command
  1380.  * scsi_done, we would get a deadlock if we took
  1381.  * hostdata->lock here and in queuecommand (because the order
  1382.  * of locking in queuecommand: 1) io_request_lock then 2)
  1383.  * hostdata->lock would be the reverse of taking it in this
  1384.  * routine */
  1385. spin_lock_irqsave(&io_request_lock, flags);
  1386. if((istat = NCR_700_readb(host, ISTAT_REG))
  1387.       & (SCSI_INT_PENDING | DMA_INT_PENDING)) {
  1388. __u32 dsps;
  1389. __u8 sstat0 = 0, dstat = 0;
  1390. __u32 dsp;
  1391. Scsi_Cmnd *SCp = hostdata->cmd;
  1392. enum NCR_700_Host_State state;
  1393. state = hostdata->state;
  1394. SCp = hostdata->cmd;
  1395. if(istat & SCSI_INT_PENDING) {
  1396. udelay(10);
  1397. sstat0 = NCR_700_readb(host, SSTAT0_REG);
  1398. }
  1399. if(istat & DMA_INT_PENDING) {
  1400. udelay(10);
  1401. dstat = NCR_700_readb(host, DSTAT_REG);
  1402. }
  1403. dsps = NCR_700_readl(host, DSPS_REG);
  1404. dsp = NCR_700_readl(host, DSP_REG);
  1405. DEBUG(("scsi%d: istat %02x sstat0 %02x dstat %02x dsp %04x[%08x] dsps 0x%xn",
  1406.        host->host_no, istat, sstat0, dstat,
  1407.        (dsp - (__u32)(hostdata->pScript))/4,
  1408.        dsp, dsps));
  1409. if(SCp != NULL) {
  1410. pun = SCp->target;
  1411. lun = SCp->lun;
  1412. }
  1413. if(sstat0 & SCSI_RESET_DETECTED) {
  1414. Scsi_Device *SDp;
  1415. int i;
  1416. hostdata->state = NCR_700_HOST_BUSY;
  1417. printk(KERN_ERR "scsi%d: Bus Reset detected, executing command %p, slot %p, dsp %08x[%04x]n",
  1418.        host->host_no, SCp, SCp == NULL ? NULL : SCp->host_scribble, dsp, dsp - hostdata->pScript);
  1419. /* clear all the negotiated parameters */
  1420. for(SDp = host->host_queue; SDp != NULL; SDp = SDp->next)
  1421. SDp->hostdata = 0;
  1422. /* clear all the slots and their pending commands */
  1423. for(i = 0; i < NCR_700_COMMAND_SLOTS_PER_HOST; i++) {
  1424. Scsi_Cmnd *SCp;
  1425. struct NCR_700_command_slot *slot =
  1426. &hostdata->slots[i];
  1427. if(slot->state == NCR_700_SLOT_FREE)
  1428. continue;
  1429. SCp = slot->cmnd;
  1430. printk(KERN_ERR " failing command because of reset, slot %p, cmnd %pn",
  1431.        slot, SCp);
  1432. free_slot(slot, hostdata);
  1433. SCp->host_scribble = NULL;
  1434. NCR_700_set_depth(SCp->device, 0);
  1435. /* NOTE: deadlock potential here: we
  1436.  * rely on mid-layer guarantees that
  1437.  * scsi_done won't try to issue the
  1438.  * command again otherwise we'll
  1439.  * deadlock on the
  1440.  * hostdata->state_lock */
  1441. SCp->result = DID_RESET << 16;
  1442. SCp->scsi_done(SCp);
  1443. }
  1444. mdelay(25);
  1445. NCR_700_chip_setup(host);
  1446. hostdata->state = NCR_700_HOST_FREE;
  1447. hostdata->cmd = NULL;
  1448. goto out_unlock;
  1449. } else if(sstat0 & SELECTION_TIMEOUT) {
  1450. DEBUG(("scsi%d: (%d:%d) selection timeoutn",
  1451.        host->host_no, pun, lun));
  1452. NCR_700_scsi_done(hostdata, SCp, DID_NO_CONNECT<<16);
  1453. } else if(sstat0 & PHASE_MISMATCH) {
  1454. struct NCR_700_command_slot *slot = (SCp == NULL) ? NULL :
  1455. (struct NCR_700_command_slot *)SCp->host_scribble;
  1456. if(dsp == Ent_SendMessage + 8 + hostdata->pScript) {
  1457. /* It wants to reply to some part of
  1458.  * our message */
  1459. #ifdef NCR_700_DEBUG
  1460. __u32 temp = NCR_700_readl(host, TEMP_REG);
  1461. int count = (hostdata->script[Ent_SendMessage/4] & 0xffffff) - ((NCR_700_readl(host, DBC_REG) & 0xffffff) + NCR_700_data_residual(host));
  1462. printk("scsi%d (%d:%d) PHASE MISMATCH IN SEND MESSAGE %d remain, return %p[%04x], phase %sn", host->host_no, pun, lun, count, (void *)temp, temp - hostdata->pScript, sbcl_to_string(NCR_700_readb(host, SBCL_REG)));
  1463. #endif
  1464. resume_offset = hostdata->pScript + Ent_SendMessagePhaseMismatch;
  1465. } else if(dsp >= to32bit(&slot->pSG[0].ins) &&
  1466.   dsp <= to32bit(&slot->pSG[NCR_700_SG_SEGMENTS].ins)) {
  1467. int data_transfer = NCR_700_readl(host, DBC_REG) & 0xffffff;
  1468. int SGcount = (dsp - to32bit(&slot->pSG[0].ins))/sizeof(struct NCR_700_SG_List);
  1469. int residual = NCR_700_data_residual(host);
  1470. int i;
  1471. #ifdef NCR_700_DEBUG
  1472. __u32 naddr = NCR_700_readl(host, DNAD_REG);
  1473. printk("scsi%d: (%d:%d) Expected phase mismatch in slot->SG[%d], transferred 0x%xn",
  1474.        host->host_no, pun, lun,
  1475.        SGcount, data_transfer);
  1476. print_command(SCp->cmnd);
  1477. if(residual) {
  1478. printk("scsi%d: (%d:%d) Expected phase mismatch in slot->SG[%d], transferred 0x%x, residual %dn",
  1479.        host->host_no, pun, lun,
  1480.        SGcount, data_transfer, residual);
  1481. }
  1482. #endif
  1483. data_transfer += residual;
  1484. if(data_transfer != 0) {
  1485. int count; 
  1486. __u32 pAddr;
  1487. SGcount--;
  1488. count = (bS_to_cpu(slot->SG[SGcount].ins) & 0x00ffffff);
  1489. DEBUG(("DATA TRANSFER MISMATCH, count = %d, transferred %dn", count, count-data_transfer));
  1490. slot->SG[SGcount].ins &= bS_to_host(0xff000000);
  1491. slot->SG[SGcount].ins |= bS_to_host(data_transfer);
  1492. pAddr = bS_to_cpu(slot->SG[SGcount].pAddr);
  1493. pAddr += (count - data_transfer);
  1494. #ifdef NCR_700_DEBUG
  1495. if(pAddr != naddr) {
  1496. printk("scsi%d (%d:%d) transfer mismatch pAddr=%lx, naddr=%lx, data_transfer=%d, residual=%dn", host->host_no, pun, lun, (unsigned long)pAddr, (unsigned long)naddr, data_transfer, residual);
  1497. }
  1498. #endif
  1499. slot->SG[SGcount].pAddr = bS_to_host(pAddr);
  1500. }
  1501. /* set the executed moves to nops */
  1502. for(i=0; i<SGcount; i++) {
  1503. slot->SG[i].ins = bS_to_host(SCRIPT_NOP);
  1504. slot->SG[i].pAddr = 0;
  1505. }
  1506. NCR_700_dma_cache_wback((unsigned long)slot->SG, sizeof(slot->SG));
  1507. /* and pretend we disconnected after
  1508.  * the command phase */
  1509. resume_offset = hostdata->pScript + Ent_MsgInDuringData;
  1510. /* make sure all the data is flushed */
  1511. NCR_700_flush_fifo(host);
  1512. } else {
  1513. __u8 sbcl = NCR_700_readb(host, SBCL_REG);
  1514. printk(KERN_ERR "scsi%d: (%d:%d) phase mismatch at %04x, phase %sn",
  1515.        host->host_no, pun, lun, dsp - hostdata->pScript, sbcl_to_string(sbcl));
  1516. NCR_700_internal_bus_reset(host);
  1517. }
  1518. } else if(sstat0 & SCSI_GROSS_ERROR) {
  1519. printk(KERN_ERR "scsi%d: (%d:%d) GROSS ERRORn",
  1520.        host->host_no, pun, lun);
  1521. NCR_700_scsi_done(hostdata, SCp, DID_ERROR<<16);
  1522. } else if(sstat0 & PARITY_ERROR) {
  1523. printk(KERN_ERR "scsi%d: (%d:%d) PARITY ERRORn",
  1524.        host->host_no, pun, lun);
  1525. NCR_700_scsi_done(hostdata, SCp, DID_ERROR<<16);
  1526. } else if(dstat & SCRIPT_INT_RECEIVED) {
  1527. DEBUG(("scsi%d: (%d:%d) ====>SCRIPT INTERRUPT<====n",
  1528.        host->host_no, pun, lun));
  1529. resume_offset = process_script_interrupt(dsps, dsp, SCp, host, hostdata);
  1530. } else if(dstat & (ILGL_INST_DETECTED)) {
  1531. printk(KERN_ERR "scsi%d: (%d:%d) Illegal Instruction detected at 0x%08x[0x%x]!!!n"
  1532.        "         Please email James.Bottomley@HansenPartnership.com with the detailsn",
  1533.        host->host_no, pun, lun,
  1534.        dsp, dsp - hostdata->pScript);
  1535. NCR_700_scsi_done(hostdata, SCp, DID_ERROR<<16);
  1536. } else if(dstat & (WATCH_DOG_INTERRUPT|ABORTED)) {
  1537. printk(KERN_ERR "scsi%d: (%d:%d) serious DMA problem, dstat=%02xn",
  1538.        host->host_no, pun, lun, dstat);
  1539. NCR_700_scsi_done(hostdata, SCp, DID_ERROR<<16);
  1540. }
  1541. /* NOTE: selection interrupt processing MUST occur
  1542.  * after script interrupt processing to correctly cope
  1543.  * with the case where we process a disconnect and
  1544.  * then get reselected before we process the
  1545.  * disconnection */
  1546. if(sstat0 & SELECTED) {
  1547. /* FIXME: It currently takes at least FOUR
  1548.  * interrupts to complete a command that
  1549.  * disconnects: one for the disconnect, one
  1550.  * for the reselection, one to get the
  1551.  * reselection data and one to complete the
  1552.  * command.  If we guess the reselected
  1553.  * command here and prepare it, we only need
  1554.  * to get a reselection data interrupt if we
  1555.  * guessed wrongly.  Since the interrupt
  1556.  * overhead is much greater than the command
  1557.  * setup, this would be an efficient
  1558.  * optimisation particularly as we probably
  1559.  * only have one outstanding command on a
  1560.  * target most of the time */
  1561. resume_offset = process_selection(host, dsp);
  1562. }
  1563. }
  1564. if(resume_offset) {
  1565. if(hostdata->state != NCR_700_HOST_BUSY) {
  1566. printk(KERN_ERR "scsi%d: Driver error: resume at 0x%08x [0x%04x] with non busy host!n",
  1567.        host->host_no, resume_offset, resume_offset - hostdata->pScript);
  1568. hostdata->state = NCR_700_HOST_BUSY;
  1569. }
  1570. DEBUG(("Attempting to resume at %xn", resume_offset));
  1571. NCR_700_clear_fifo(host);
  1572. NCR_700_writel(resume_offset, host, DSP_REG);
  1573. /* There is probably a technical no-no about this: If we're a
  1574.  * shared interrupt and we got this interrupt because the
  1575.  * other device needs servicing not us, we're still going to
  1576.  * check our queued commands here---of course, there shouldn't
  1577.  * be any outstanding.... */
  1578. if(hostdata->state == NCR_700_HOST_FREE) {
  1579. int i;
  1580. for(i = 0; i < NCR_700_COMMAND_SLOTS_PER_HOST; i++) {
  1581. /* fairness: always run the queue from the last
  1582.  * position we left off */
  1583. int j = (i + hostdata->saved_slot_position)
  1584. % NCR_700_COMMAND_SLOTS_PER_HOST;
  1585. if(hostdata->slots[j].state != NCR_700_SLOT_QUEUED)
  1586. continue;
  1587. if(NCR_700_start_command(hostdata->slots[j].cmnd)) {
  1588. DEBUG(("scsi%d: Issuing saved command slot %p, cmd %ptn",
  1589.        host->host_no, &hostdata->slots[j],
  1590.        hostdata->slots[j].cmnd));
  1591. hostdata->saved_slot_position = j + 1;
  1592. }
  1593. break;
  1594. }
  1595. }
  1596.  out_unlock:
  1597. spin_unlock_irqrestore(&io_request_lock, flags);
  1598. }
  1599. /* FIXME: Need to put some proc information in and plumb it
  1600.  * into the scsi proc system */
  1601. STATIC int
  1602. NCR_700_proc_directory_info(char *proc_buf, char **startp,
  1603.  off_t offset, int bytes_available,
  1604.  int host_no, int write)
  1605. {
  1606. static char buf[4096]; /* 1 page should be sufficient */
  1607. int len = 0;
  1608. struct Scsi_Host *host = scsi_hostlist;
  1609. struct NCR_700_Host_Parameters *hostdata;
  1610. Scsi_Device *SDp;
  1611. while(host != NULL && host->host_no != host_no)
  1612. host = host->next;
  1613. if(host == NULL)
  1614. return 0;
  1615. if(write) {
  1616. /* FIXME: Clear internal statistics here */
  1617. return 0;
  1618. }
  1619. hostdata = (struct NCR_700_Host_Parameters *)host->hostdata[0];
  1620. len += sprintf(&buf[len], "Total commands outstanding: %dn", hostdata->command_slot_count);
  1621. len += sprintf(&buf[len],"
  1622. Target Depth  Active  Next Tagn
  1623. ====== =====  ======  ========n");
  1624. for(SDp = host->host_queue; SDp != NULL; SDp = SDp->next) {
  1625. len += sprintf(&buf[len]," %2d:%2d   %4d    %4d      %4dn", SDp->id, SDp->lun, SDp->queue_depth, NCR_700_get_depth(SDp), SDp->current_tag);
  1626. }
  1627. if((len -= offset) <= 0)
  1628. return 0;
  1629. if(len > bytes_available)
  1630. len = bytes_available;
  1631. memcpy(proc_buf, buf + offset, len);
  1632. return len;
  1633. }
  1634. STATIC int
  1635. NCR_700_queuecommand(Scsi_Cmnd *SCp, void (*done)(Scsi_Cmnd *))
  1636. {
  1637. struct NCR_700_Host_Parameters *hostdata = 
  1638. (struct NCR_700_Host_Parameters *)SCp->host->hostdata[0];
  1639. __u32 move_ins;
  1640. int pci_direction;
  1641. struct NCR_700_command_slot *slot;
  1642. int hash;
  1643. if(hostdata->command_slot_count >= NCR_700_COMMAND_SLOTS_PER_HOST) {
  1644. /* We're over our allocation, this should never happen
  1645.  * since we report the max allocation to the mid layer */
  1646. printk(KERN_WARNING "scsi%d: Command depth has gone over queue depthn", SCp->host->host_no);
  1647. return 1;
  1648. }
  1649. if(NCR_700_get_depth(SCp->device) != 0 && !(hostdata->tag_negotiated & (1<<SCp->target))) {
  1650. DEBUG((KERN_ERR "scsi%d (%d:%d) has non zero depth %dn",
  1651.        SCp->host->host_no, SCp->target, SCp->lun,
  1652.        NCR_700_get_depth(SCp->device)));
  1653. return 1;
  1654. }
  1655. if(NCR_700_get_depth(SCp->device) >= NCR_700_MAX_TAGS) {
  1656. DEBUG((KERN_ERR "scsi%d (%d:%d) has max tag depth %dn",
  1657.        SCp->host->host_no, SCp->target, SCp->lun,
  1658.        NCR_700_get_depth(SCp->device)));
  1659. return 1;
  1660. }
  1661. NCR_700_set_depth(SCp->device, NCR_700_get_depth(SCp->device) + 1);
  1662. /* begin the command here */
  1663. /* no need to check for NULL, test for command_slot_cound above
  1664.  * ensures a slot is free */
  1665. slot = find_empty_slot(hostdata);
  1666. slot->cmnd = SCp;
  1667. SCp->scsi_done = done;
  1668. SCp->host_scribble = (unsigned char *)slot;
  1669. SCp->SCp.ptr = NULL;
  1670. SCp->SCp.buffer = NULL;
  1671. #ifdef NCR_700_DEBUG
  1672. printk("53c700: scsi%d, command ", SCp->host->host_no);
  1673. print_command(SCp->cmnd);
  1674. #endif
  1675. if(SCp->device->tagged_supported && !SCp->device->tagged_queue
  1676.    && (hostdata->tag_negotiated &(1<<SCp->target)) == 0
  1677.    && NCR_700_is_flag_clear(SCp->device, NCR_700_DEV_BEGIN_TAG_QUEUEING)) {
  1678. /* upper layer has indicated tags are supported.  We don't
  1679.  * necessarily believe it yet.
  1680.  *
  1681.  * NOTE: There is a danger here: the mid layer supports
  1682.  * tag queuing per LUN.  We only support it per PUN because
  1683.  * of potential reselection issues */
  1684. printk(KERN_INFO "scsi%d: (%d:%d) Enabling Tag Command Queuingn", SCp->device->host->host_no, SCp->target, SCp->lun);
  1685. hostdata->tag_negotiated |= (1<<SCp->target);
  1686. NCR_700_set_flag(SCp->device, NCR_700_DEV_BEGIN_TAG_QUEUEING);
  1687. SCp->device->tagged_queue = 1;
  1688. }
  1689. if(hostdata->tag_negotiated &(1<<SCp->target)) {
  1690. struct NCR_700_command_slot *old =
  1691. find_ITL_Nexus(hostdata, SCp->target, SCp->lun);
  1692. #ifdef NCR_700_TAG_DEBUG
  1693. struct NCR_700_command_slot *found;
  1694. #endif
  1695. if(old != NULL && old->tag == SCp->device->current_tag) {
  1696. /* On some badly starving drives, this can be
  1697.  * a frequent occurance, so print the message
  1698.  * only once */
  1699. if(NCR_700_is_flag_clear(SCp->device, NCR_700_DEV_TAG_STARVATION_WARNED)) {
  1700. printk(KERN_WARNING "scsi%d (%d:%d) Target is suffering from tag starvation.n", SCp->host->host_no, SCp->target, SCp->lun);
  1701. NCR_700_set_flag(SCp->device, NCR_700_DEV_TAG_STARVATION_WARNED);
  1702. }
  1703. /* Release the slot and ajust the depth before refusing
  1704.  * the command */
  1705. free_slot(slot, hostdata);
  1706. NCR_700_set_depth(SCp->device, NCR_700_get_depth(SCp->device) - 1);
  1707. return 1;
  1708. }
  1709. slot->tag = SCp->device->current_tag++;
  1710. #ifdef NCR_700_TAG_DEBUG
  1711. while((found = find_ITLQ_Nexus(hostdata, SCp->target, SCp->lun, slot->tag)) != NULL) {
  1712. printk("nn**ERROR** already using tag %d, but oldest is %dn", slot->tag, (old == NULL) ? -1 : old->tag);
  1713. printk("  FOUND = %p, tag = %d, pun = %d, lun = %dn",
  1714.        found, found->tag, found->cmnd->target, found->cmnd->lun);
  1715. slot->tag = SCp->device->current_tag++;
  1716. printk("   Tag list is: ");
  1717. while(old != NULL) {
  1718. if(old->cmnd->target == SCp->target &&
  1719.    old->cmnd->lun == SCp->lun)
  1720. printk("%d ", old->tag);
  1721. old = old->ITL_back;
  1722. }
  1723. printk("nn");
  1724. }
  1725. #endif
  1726. hash = hash_ITLQ(SCp->target, SCp->lun, slot->tag);
  1727. /* link into the ITLQ hash queues */
  1728. slot->ITLQ_forw = hostdata->ITLQ_Hash_forw[hash];
  1729. hostdata->ITLQ_Hash_forw[hash] = slot;
  1730. #ifdef NCR_700_TAG_DEBUG
  1731. if(slot->ITLQ_forw != NULL && slot->ITLQ_forw->ITLQ_back != NULL) {
  1732. printk(KERN_ERR "scsi%d (%d:%d) ITLQ_back is not NULL!!!!n", SCp->host->host_no, SCp->target, SCp->lun);
  1733. }
  1734. #endif
  1735. if(slot->ITLQ_forw != NULL)
  1736. slot->ITLQ_forw->ITLQ_back = slot;
  1737. else
  1738. hostdata->ITLQ_Hash_back[hash] = slot;
  1739. slot->ITLQ_back = NULL;
  1740. } else {
  1741. slot->tag = NCR_700_NO_TAG;
  1742. }
  1743. /* link into the ITL hash queues */
  1744. hash = hash_ITL(SCp->target, SCp->lun);
  1745. slot->ITL_forw = hostdata->ITL_Hash_forw[hash];
  1746. hostdata->ITL_Hash_forw[hash] = slot;
  1747. #ifdef NCR_700_TAG_DEBUG
  1748. if(slot->ITL_forw != NULL && slot->ITL_forw->ITL_back != NULL) {
  1749. printk(KERN_ERR "scsi%d (%d:%d) ITL_back is not NULL!!!!n",
  1750.        SCp->host->host_no, SCp->target, SCp->lun);
  1751. }
  1752. #endif
  1753. if(slot->ITL_forw != NULL)
  1754. slot->ITL_forw->ITL_back = slot;
  1755. else
  1756. hostdata->ITL_Hash_back[hash] = slot;
  1757. slot->ITL_back = NULL;
  1758. /* sanity check: some of the commands generated by the mid-layer
  1759.  * have an eccentric idea of their sc_data_direction */
  1760. if(!SCp->use_sg && !SCp->request_bufflen 
  1761.    && SCp->sc_data_direction != SCSI_DATA_NONE) {
  1762. #ifdef NCR_700_DEBUG
  1763. printk("53c700: Command");
  1764. print_command(SCp->cmnd);
  1765. printk("Has wrong data direction %dn", SCp->sc_data_direction);
  1766. #endif
  1767. SCp->sc_data_direction = SCSI_DATA_NONE;
  1768. }
  1769. switch (SCp->cmnd[0]) {
  1770. case REQUEST_SENSE:
  1771. /* clear the internal sense magic */
  1772. SCp->cmnd[6] = 0;
  1773. /* fall through */
  1774. default:
  1775. /* OK, get it from the command */
  1776. switch(SCp->sc_data_direction) {
  1777. case SCSI_DATA_UNKNOWN:
  1778. default:
  1779. printk(KERN_ERR "53c700: Unknown command for data direction ");
  1780. print_command(SCp->cmnd);
  1781. move_ins = 0;
  1782. break;
  1783. case SCSI_DATA_NONE:
  1784. move_ins = 0;
  1785. break;
  1786. case SCSI_DATA_READ:
  1787. move_ins = SCRIPT_MOVE_DATA_IN;
  1788. break;
  1789. case SCSI_DATA_WRITE:
  1790. move_ins = SCRIPT_MOVE_DATA_OUT;
  1791. break;
  1792. }
  1793. }
  1794. /* now build the scatter gather list */
  1795. pci_direction = scsi_to_pci_dma_dir(SCp->sc_data_direction);
  1796. if(move_ins != 0) {
  1797. int i;
  1798. int sg_count;
  1799. dma_addr_t vPtr = 0;
  1800. __u32 count = 0;
  1801. if(SCp->use_sg) {
  1802. sg_count = pci_map_sg(hostdata->pci_dev, SCp->buffer,
  1803.       SCp->use_sg, pci_direction);
  1804. } else {
  1805. vPtr = pci_map_single(hostdata->pci_dev,
  1806.       SCp->request_buffer, 
  1807.       SCp->request_bufflen,
  1808.       pci_direction);
  1809. count = SCp->request_bufflen;
  1810. slot->dma_handle = vPtr;
  1811. sg_count = 1;
  1812. }
  1813. for(i = 0; i < sg_count; i++) {
  1814. if(SCp->use_sg) {
  1815. struct scatterlist *sg = SCp->buffer;
  1816. vPtr = sg_dma_address(&sg[i]);
  1817. count = sg_dma_len(&sg[i]);
  1818. }
  1819. slot->SG[i].ins = bS_to_host(move_ins | count);
  1820. DEBUG((" scatter block %d: move %d[%08x] from 0x%lxn",
  1821.        i, count, slot->SG[i].ins, (unsigned long)vPtr));
  1822. slot->SG[i].pAddr = bS_to_host(vPtr);
  1823. }
  1824. slot->SG[i].ins = bS_to_host(SCRIPT_RETURN);
  1825. slot->SG[i].pAddr = 0;
  1826. NCR_700_dma_cache_wback((unsigned long)slot->SG, sizeof(slot->SG));
  1827. DEBUG((" SETTING %08lx to %xn",
  1828.        (&slot->pSG[i].ins), 
  1829.        slot->SG[i].ins));
  1830. }
  1831. slot->resume_offset = 0;
  1832. slot->pCmd = pci_map_single(hostdata->pci_dev, SCp->cmnd,
  1833.     sizeof(SCp->cmnd), PCI_DMA_TODEVICE);
  1834. NCR_700_start_command(SCp);
  1835. return 0;
  1836. }
  1837. STATIC int
  1838. NCR_700_abort(Scsi_Cmnd * SCp)
  1839. {
  1840. struct NCR_700_command_slot *slot;
  1841. struct NCR_700_Host_Parameters *hostdata = 
  1842. (struct NCR_700_Host_Parameters *)SCp->host->hostdata[0];
  1843. printk(KERN_INFO "scsi%d (%d:%d) New error handler wants to abort commandnt",
  1844.        SCp->host->host_no, SCp->target, SCp->lun);
  1845. print_command(SCp->cmnd);
  1846. slot = find_ITL_Nexus(hostdata, SCp->target, SCp->lun);
  1847. while(slot != NULL && slot->cmnd != SCp)
  1848. slot = slot->ITL_back;
  1849. if(slot == NULL)
  1850. /* no outstanding command to abort */
  1851. return SUCCESS;
  1852. if(SCp->cmnd[0] == TEST_UNIT_READY) {
  1853. /* FIXME: This is because of a problem in the new
  1854.  * error handler.  When it is in error recovery, it
  1855.  * will send a TUR to a device it thinks may still be
  1856.  * showing a problem.  If the TUR isn't responded to,
  1857.  * it will abort it and mark the device off line.
  1858.  * Unfortunately, it does no other error recovery, so
  1859.  * this would leave us with an outstanding command
  1860.  * occupying a slot.  Rather than allow this to
  1861.  * happen, we issue a bus reset to force all
  1862.  * outstanding commands to terminate here. */
  1863. NCR_700_internal_bus_reset(SCp->host);
  1864. /* still drop through and return failed */
  1865. }
  1866. return FAILED;
  1867. }
  1868. STATIC int
  1869. NCR_700_bus_reset(Scsi_Cmnd * SCp)
  1870. {
  1871. printk(KERN_INFO "scsi%d (%d:%d) New error handler wants BUS reset, cmd %pnt",
  1872.        SCp->host->host_no, SCp->target, SCp->lun, SCp);
  1873. print_command(SCp->cmnd);
  1874. NCR_700_internal_bus_reset(SCp->host);
  1875. return SUCCESS;
  1876. }
  1877. STATIC int
  1878. NCR_700_dev_reset(Scsi_Cmnd * SCp)
  1879. {
  1880. printk(KERN_INFO "scsi%d (%d:%d) New error handler wants device resetnt",
  1881.        SCp->host->host_no, SCp->target, SCp->lun);
  1882. print_command(SCp->cmnd);
  1883. return FAILED;
  1884. }
  1885. STATIC int
  1886. NCR_700_host_reset(Scsi_Cmnd * SCp)
  1887. {
  1888. printk(KERN_INFO "scsi%d (%d:%d) New error handler wants HOST resetnt",
  1889.        SCp->host->host_no, SCp->target, SCp->lun);
  1890. print_command(SCp->cmnd);
  1891. NCR_700_internal_bus_reset(SCp->host);
  1892. NCR_700_chip_reset(SCp->host);
  1893. return SUCCESS;
  1894. }
  1895. EXPORT_SYMBOL(NCR_700_detect);
  1896. EXPORT_SYMBOL(NCR_700_release);
  1897. EXPORT_SYMBOL(NCR_700_intr);