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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /**************************************************************************
  2.  * Initio 9100 device driver for Linux.
  3.  *
  4.  * Copyright (c) 1994-1998 Initio Corporation
  5.  * Copyright (c) 1998 Bas Vermeulen <bvermeul@blackstar.xs4all.nl>
  6.  * All rights reserved.
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2, or (at your option)
  11.  * any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; see the file COPYING.  If not, write to
  20.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  * --------------------------------------------------------------------------
  23.  *
  24.  * Redistribution and use in source and binary forms, with or without
  25.  * modification, are permitted provided that the following conditions
  26.  * are met:
  27.  * 1. Redistributions of source code must retain the above copyright
  28.  *    notice, this list of conditions, and the following disclaimer,
  29.  *    without modification, immediately at the beginning of the file.
  30.  * 2. Redistributions in binary form must reproduce the above copyright
  31.  *    notice, this list of conditions and the following disclaimer in the
  32.  *    documentation and/or other materials provided with the distribution.
  33.  * 3. The name of the author may not be used to endorse or promote products
  34.  *    derived from this software without specific prior written permission.
  35.  *
  36.  * Where this Software is combined with software released under the terms of 
  37.  * the GNU General Public License ("GPL") and the terms of the GPL would require the 
  38.  * combined work to also be released under the terms of the GPL, the terms
  39.  * and conditions of this License will apply in addition to those of the
  40.  * GPL with the exception of any terms or conditions of this License that
  41.  * conflict with, or are expressly prohibited by, the GPL.
  42.  *
  43.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  44.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  45.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  46.  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  47.  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  48.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  49.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  50.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  53.  * SUCH DAMAGE.
  54.  *
  55.  *************************************************************************
  56.  *
  57.  * DESCRIPTION:
  58.  *
  59.  * This is the Linux low-level SCSI driver for Initio INI-9X00U/UW SCSI host
  60.  * adapters
  61.  *
  62.  * 08/06/97 hc - v1.01h
  63.  * - Support inic-940 and inic-935
  64.  * 09/26/97 hc - v1.01i
  65.  * - Make correction from J.W. Schultz suggestion
  66.  * 10/13/97 hc - Support reset function
  67.  * 10/21/97 hc - v1.01j
  68.  * - Support 32 LUN (SCSI 3)
  69.  * 01/14/98 hc - v1.01k
  70.  * - Fix memory allocation problem
  71.  * 03/04/98 hc - v1.01l
  72.  * - Fix tape rewind which will hang the system problem
  73.  * - Set can_queue to tul_num_scb
  74.  * 06/25/98 hc - v1.01m
  75.  * - Get it work for kernel version >= 2.1.75
  76.  * - Dynamic assign SCSI bus reset holding time in init_tulip()
  77.  * 07/02/98 hc - v1.01n
  78.  * - Support 0002134A
  79.  * 08/07/98 hc  - v1.01o
  80.  * - Change the tul_abort_srb routine to use scsi_done. <01>
  81.  * 09/07/98 hl  - v1.02
  82.  *              - Change the INI9100U define and proc_dir_entry to
  83.  *                reflect the newer Kernel 2.1.118, but the v1.o1o
  84.  *                should work with Kernel 2.1.118.
  85.  * 09/20/98 wh  - v1.02a
  86.  *              - Support Abort command.
  87.  *              - Handle reset routine.
  88.  * 09/21/98 hl  - v1.03
  89.  *              - remove comments.
  90.  * 12/09/98 bv - v1.03a
  91.  * - Removed unused code
  92.  * 12/13/98 bv - v1.03b
  93.  * - Remove cli() locking for kernels >= 2.1.95. This uses
  94.  *   spinlocks to serialize access to the pSRB_head and
  95.  *   pSRB_tail members of the HCS structure.
  96.  * 09/01/99 bv - v1.03d
  97.  * - Fixed a deadlock problem in SMP.
  98.  * 21/01/99 bv - v1.03e
  99.  * - Add support for the Domex 3192U PCI SCSI
  100.  *   This is a slightly modified patch by
  101.  *   Brian Macy <bmacy@sunshinecomputing.com>
  102.  * 22/02/99 bv - v1.03f
  103.  * - Didn't detect the INIC-950 in 2.0.x correctly.
  104.  *   Now fixed.
  105.  * 05/07/99 bv - v1.03g
  106.  * - Changed the assumption that HZ = 100
  107.  **************************************************************************/
  108. #define CVT_LINUX_VERSION(V,P,S)        (V * 65536 + P * 256 + S)
  109. #ifndef LINUX_VERSION_CODE
  110. #include <linux/version.h>
  111. #endif
  112. #include <linux/module.h>
  113. #include <stdarg.h>
  114. #include <asm/irq.h>
  115. #include <linux/errno.h>
  116. #include <linux/delay.h>
  117. #include <linux/pci.h>
  118. #include <linux/init.h>
  119. #include <linux/blk.h>
  120. #include <linux/spinlock.h>
  121. #include <linux/stat.h>
  122. #include <linux/config.h>
  123. #include <linux/kernel.h>
  124. #include <linux/string.h>
  125. #include <linux/ioport.h>
  126. #include <linux/sched.h>
  127. #include <linux/proc_fs.h>
  128. #include <asm/io.h>
  129. #include "scsi.h"
  130. #include "sd.h"
  131. #include "hosts.h"
  132. #include <linux/slab.h>
  133. #include "ini9100u.h"
  134. #ifdef DEBUG_i91u
  135. unsigned int i91u_debug = DEBUG_DEFAULT;
  136. #endif
  137. static Scsi_Host_Template driver_template = INI9100U;
  138. #include "scsi_module.c"
  139. char *i91uCopyright = "Copyright (C) 1996-98";
  140. char *i91uInitioName = "by Initio Corporation";
  141. char *i91uProductName = "INI-9X00U/UW";
  142. char *i91uVersion = "v1.03g";
  143. #define TULSZ(sz)     (sizeof(sz) / sizeof(sz[0]))
  144. #define TUL_RDWORD(x,y)         (short)(inl((int)((ULONG)((ULONG)x+(UCHAR)y)) ))
  145. /* set by i91_setup according to the command line */
  146. static int setup_called = 0;
  147. static int tul_num_ch = 4; /* Maximum 4 adapters           */
  148. static int tul_num_scb;
  149. static int tul_tag_enable = 1;
  150. static SCB *tul_scb;
  151. #ifdef DEBUG_i91u
  152. static int setup_debug = 0;
  153. #endif
  154. static char *setup_str = (char *) NULL;
  155. static void i91u_intr0(int irq, void *dev_id, struct pt_regs *);
  156. static void i91u_intr1(int irq, void *dev_id, struct pt_regs *);
  157. static void i91u_intr2(int irq, void *dev_id, struct pt_regs *);
  158. static void i91u_intr3(int irq, void *dev_id, struct pt_regs *);
  159. static void i91u_intr4(int irq, void *dev_id, struct pt_regs *);
  160. static void i91u_intr5(int irq, void *dev_id, struct pt_regs *);
  161. static void i91u_intr6(int irq, void *dev_id, struct pt_regs *);
  162. static void i91u_intr7(int irq, void *dev_id, struct pt_regs *);
  163. static void i91u_panic(char *msg);
  164. static void i91uSCBPost(BYTE * pHcb, BYTE * pScb);
  165. /* ---- EXTERNAL FUNCTIONS ---- */
  166. /* Get total number of adapters */
  167. extern void init_i91uAdapter_table(void);
  168. extern int Addi91u_into_Adapter_table(WORD, WORD, BYTE, BYTE, BYTE);
  169. extern int tul_ReturnNumberOfAdapters(void);
  170. extern void get_tulipPCIConfig(HCS * pHCB, int iChannel_index);
  171. extern int init_tulip(HCS * pHCB, SCB * pSCB, int tul_num_scb, BYTE * pbBiosAdr, int reset_time);
  172. extern SCB *tul_alloc_scb(HCS * pHCB);
  173. extern int tul_abort_srb(HCS * pHCB, Scsi_Cmnd * pSRB);
  174. extern void tul_exec_scb(HCS * pHCB, SCB * pSCB);
  175. extern void tul_release_scb(HCS * pHCB, SCB * pSCB);
  176. extern void tul_stop_bm(HCS * pHCB);
  177. extern int tul_reset_scsi(HCS * pCurHcb, int seconds);
  178. extern int tul_isr(HCS * pHCB);
  179. extern int tul_reset(HCS * pHCB, Scsi_Cmnd * pSRB, unsigned char target);
  180. extern int tul_reset_scsi_bus(HCS * pCurHcb);
  181. extern int tul_device_reset(HCS * pCurHcb, ULONG pSrb, unsigned int target, unsigned int ResetFlags);
  182. /* ---- EXTERNAL VARIABLES ---- */
  183. extern HCS tul_hcs[];
  184. const PCI_ID i91u_pci_devices[] = {
  185. { INI_VENDOR_ID, I950_DEVICE_ID },
  186. { INI_VENDOR_ID, I940_DEVICE_ID },
  187. { INI_VENDOR_ID, I935_DEVICE_ID },
  188. { INI_VENDOR_ID, I920_DEVICE_ID },
  189. { DMX_VENDOR_ID, I920_DEVICE_ID },
  190. };
  191. /*
  192.  *  queue services:
  193.  */
  194. /*****************************************************************************
  195.  Function name  : i91uAppendSRBToQueue
  196.  Description    : This function will push current request into save list
  197.  Input          : pSRB  -       Pointer to SCSI request block.
  198.   pHCB  -       Pointer to host adapter structure
  199.  Output         : None.
  200.  Return         : None.
  201. *****************************************************************************/
  202. static void i91uAppendSRBToQueue(HCS * pHCB, Scsi_Cmnd * pSRB)
  203. {
  204. ULONG flags;
  205. spin_lock_irqsave(&(pHCB->pSRB_lock), flags);
  206. pSRB->next = NULL; /* Pointer to next              */
  207. if (pHCB->pSRB_head == NULL)
  208. pHCB->pSRB_head = pSRB;
  209. else
  210. pHCB->pSRB_tail->next = pSRB; /* Pointer to next              */
  211. pHCB->pSRB_tail = pSRB;
  212. spin_unlock_irqrestore(&(pHCB->pSRB_lock), flags);
  213. return;
  214. }
  215. /*****************************************************************************
  216.  Function name  : i91uPopSRBFromQueue
  217.  Description    : This function will pop current request from save list
  218.  Input          : pHCB  -       Pointer to host adapter structure
  219.  Output         : None.
  220.  Return         : pSRB  -       Pointer to SCSI request block.
  221. *****************************************************************************/
  222. static Scsi_Cmnd *i91uPopSRBFromQueue(HCS * pHCB)
  223. {
  224. Scsi_Cmnd *pSRB;
  225. ULONG flags;
  226. spin_lock_irqsave(&(pHCB->pSRB_lock), flags);
  227. if ((pSRB = pHCB->pSRB_head) != NULL) {
  228. pHCB->pSRB_head = pHCB->pSRB_head->next;
  229. pSRB->next = NULL;
  230. }
  231. spin_unlock_irqrestore(&(pHCB->pSRB_lock), flags);
  232. return (pSRB);
  233. }
  234. /* called from init/main.c */
  235. void i91u_setup(char *str, int *ints)
  236. {
  237. if (setup_called)
  238. i91u_panic("i91u: i91u_setup called twice.n");
  239. setup_called = ints[0];
  240. setup_str = str;
  241. #ifdef DEBUG_i91u
  242. setup_debug = ints[0] >= 1 ? ints[1] : DEBUG_DEFAULT;
  243. #endif
  244. }
  245. int tul_NewReturnNumberOfAdapters(void)
  246. {
  247. struct pci_dev *pDev = NULL; /* Start from none              */
  248. int iAdapters = 0;
  249. long dRegValue;
  250. WORD wBIOS;
  251. int i = 0;
  252. init_i91uAdapter_table();
  253. for (i = 0; i < TULSZ(i91u_pci_devices); i++)
  254. {
  255. while ((pDev = pci_find_device(i91u_pci_devices[i].vendor_id, i91u_pci_devices[i].device_id, pDev)) != NULL) {
  256. if (pci_enable_device(pDev))
  257. continue;
  258. pci_read_config_dword(pDev, 0x44, (u32 *) & dRegValue);
  259. wBIOS = (UWORD) (dRegValue & 0xFF);
  260. if (((dRegValue & 0xFF00) >> 8) == 0xFF)
  261. dRegValue = 0;
  262. wBIOS = (wBIOS << 8) + ((UWORD) ((dRegValue & 0xFF00) >> 8));
  263. if (Addi91u_into_Adapter_table(wBIOS,
  264. (pDev->resource[0].start),
  265.         pDev->irq,
  266.         pDev->bus->number,
  267.         (pDev->devfn >> 3)
  268.      ) == 0)
  269. iAdapters++;
  270. }
  271. }
  272. return (iAdapters);
  273. }
  274. int i91u_detect(Scsi_Host_Template * tpnt)
  275. {
  276. SCB *pSCB;
  277. HCS *pHCB;
  278. struct Scsi_Host *hreg;
  279. unsigned long i; /* 01/14/98                     */
  280. int ok = 0, iAdapters;
  281. ULONG dBiosAdr;
  282. BYTE *pbBiosAdr;
  283. tpnt->proc_name = "INI9100U";
  284. if (setup_called) { /* Setup by i91u_setup          */
  285. printk("i91u: processing commandline: ");
  286. #ifdef DEBUG_i91u
  287. if (setup_called > 1) {
  288. printk("ni91u: %sn", setup_str);
  289. printk("i91u: usage: i91u[=<DEBUG>]n");
  290. i91u_panic("i91u panics in line %d", __LINE__);
  291. }
  292. i91u_debug = setup_debug;
  293. #endif
  294. }
  295. /* Get total number of adapters in the motherboard */
  296. #ifdef CONFIG_PCI
  297. iAdapters = tul_NewReturnNumberOfAdapters();
  298. #else
  299. iAdapters = tul_ReturnNumberOfAdapters();
  300. #endif
  301. if (iAdapters == 0) /* If no tulip founded, return */
  302. return (0);
  303. tul_num_ch = (iAdapters > tul_num_ch) ? tul_num_ch : iAdapters;
  304. /* Update actually channel number */
  305. if (tul_tag_enable) { /* 1.01i                  */
  306. tul_num_scb = MAX_TARGETS * i91u_MAXQUEUE;
  307. } else {
  308. tul_num_scb = MAX_TARGETS + 3; /* 1-tape, 1-CD_ROM, 1- extra */
  309. } /* Update actually SCBs per adapter */
  310. /* Get total memory needed for HCS */
  311. i = tul_num_ch * sizeof(HCS);
  312. memset((unsigned char *) &tul_hcs[0], 0, i); /* Initialize tul_hcs 0 */
  313. /* Get total memory needed for SCB */
  314. for (; tul_num_scb >= MAX_TARGETS + 3; tul_num_scb--) {
  315. i = tul_num_ch * tul_num_scb * sizeof(SCB);
  316. if ((tul_scb = (SCB *) kmalloc(i, GFP_ATOMIC | GFP_DMA)) != NULL)
  317. break;
  318. }
  319. if (tul_scb == NULL) {
  320. printk("i91u: SCB memory allocation errorn");
  321. return (0);
  322. }
  323. memset((unsigned char *) tul_scb, 0, i);
  324. pSCB = tul_scb;
  325. for (i = 0; i < tul_num_ch * tul_num_scb; i++, pSCB++) {
  326. pSCB->SCB_SGPAddr = (U32) VIRT_TO_BUS(&pSCB->SCB_SGList[0]);
  327. }
  328. for (i = 0, pHCB = &tul_hcs[0]; /* Get pointer for control block */
  329.      i < tul_num_ch;
  330.      i++, pHCB++) {
  331. pHCB->pSRB_head = NULL; /* Initial SRB save queue       */
  332. pHCB->pSRB_tail = NULL; /* Initial SRB save queue       */
  333. pHCB->pSRB_lock = SPIN_LOCK_UNLOCKED; /* SRB save queue lock */
  334. get_tulipPCIConfig(pHCB, i);
  335. dBiosAdr = pHCB->HCS_BIOS;
  336. dBiosAdr = (dBiosAdr << 4);
  337. pbBiosAdr = phys_to_virt(dBiosAdr);
  338. init_tulip(pHCB, tul_scb + (i * tul_num_scb), tul_num_scb, pbBiosAdr, 10);
  339. request_region(pHCB->HCS_Base, 256, "i91u"); /* Register */ 
  340. pHCB->HCS_Index = i; /* 7/29/98 */
  341. hreg = scsi_register(tpnt, sizeof(HCS));
  342. if(hreg == NULL)
  343. {
  344. release_region(pHCB->HCS_Base, 256);
  345. return 0;
  346. }
  347. hreg->io_port = pHCB->HCS_Base;
  348. hreg->n_io_port = 0xff;
  349. hreg->can_queue = tul_num_scb; /* 03/05/98                      */
  350. hreg->unique_id = pHCB->HCS_Base;
  351. hreg->max_id = pHCB->HCS_MaxTar;
  352. hreg->max_lun = 32; /* 10/21/97                     */
  353. hreg->irq = pHCB->HCS_Intr;
  354. hreg->this_id = pHCB->HCS_SCSI_ID; /* Assign HCS index           */
  355. hreg->base = (unsigned long)pHCB;
  356. hreg->sg_tablesize = TOTAL_SG_ENTRY; /* Maximun support is 32 */
  357. /* Initial tulip chip           */
  358. switch (i) {
  359. case 0:
  360. ok = request_irq(pHCB->HCS_Intr, i91u_intr0, SA_INTERRUPT | SA_SHIRQ, "i91u", hreg);
  361. break;
  362. case 1:
  363. ok = request_irq(pHCB->HCS_Intr, i91u_intr1, SA_INTERRUPT | SA_SHIRQ, "i91u", hreg);
  364. break;
  365. case 2:
  366. ok = request_irq(pHCB->HCS_Intr, i91u_intr2, SA_INTERRUPT | SA_SHIRQ, "i91u", hreg);
  367. break;
  368. case 3:
  369. ok = request_irq(pHCB->HCS_Intr, i91u_intr3, SA_INTERRUPT | SA_SHIRQ, "i91u", hreg);
  370. break;
  371. case 4:
  372. ok = request_irq(pHCB->HCS_Intr, i91u_intr4, SA_INTERRUPT | SA_SHIRQ, "i91u", hreg);
  373. break;
  374. case 5:
  375. ok = request_irq(pHCB->HCS_Intr, i91u_intr5, SA_INTERRUPT | SA_SHIRQ, "i91u", hreg);
  376. break;
  377. case 6:
  378. ok = request_irq(pHCB->HCS_Intr, i91u_intr6, SA_INTERRUPT | SA_SHIRQ, "i91u", hreg);
  379. break;
  380. case 7:
  381. ok = request_irq(pHCB->HCS_Intr, i91u_intr7, SA_INTERRUPT | SA_SHIRQ, "i91u", hreg);
  382. break;
  383. default:
  384. i91u_panic("i91u: Too many host adaptersn");
  385. break;
  386. }
  387. if (ok < 0) {
  388. if (ok == -EINVAL) {
  389. printk("i91u: bad IRQ %d.n", pHCB->HCS_Intr);
  390. printk("         Contact author.n");
  391. } else if (ok == -EBUSY)
  392. printk("i91u: IRQ %d already in use. Configure another.n",
  393.        pHCB->HCS_Intr);
  394. else {
  395. printk("ni91u: Unexpected error code on requesting IRQ %d.n",
  396.        pHCB->HCS_Intr);
  397. printk("         Contact author.n");
  398. }
  399. i91u_panic("i91u: driver needs an IRQ.n");
  400. }
  401. }
  402. tpnt->this_id = -1;
  403. tpnt->can_queue = 1;
  404. return 1;
  405. }
  406. static void i91uBuildSCB(HCS * pHCB, SCB * pSCB, Scsi_Cmnd * SCpnt)
  407. { /* Create corresponding SCB     */
  408. struct scatterlist *pSrbSG;
  409. SG *pSG; /* Pointer to SG list           */
  410. int i;
  411. long TotalLen;
  412. pSCB->SCB_Post = i91uSCBPost; /* i91u's callback routine      */
  413. pSCB->SCB_Srb = SCpnt;
  414. pSCB->SCB_Opcode = ExecSCSI;
  415. pSCB->SCB_Flags = SCF_POST; /* After SCSI done, call post routine */
  416. pSCB->SCB_Target = SCpnt->target;
  417. pSCB->SCB_Lun = SCpnt->lun;
  418. pSCB->SCB_Ident = SCpnt->lun | DISC_ALLOW;
  419. pSCB->SCB_Flags |= SCF_SENSE; /* Turn on auto request sense   */
  420. pSCB->SCB_SensePtr = (U32) VIRT_TO_BUS(SCpnt->sense_buffer);
  421. pSCB->SCB_SenseLen = SENSE_SIZE;
  422. pSCB->SCB_CDBLen = SCpnt->cmd_len;
  423. pSCB->SCB_HaStat = 0;
  424. pSCB->SCB_TaStat = 0;
  425. memcpy(&pSCB->SCB_CDB[0], &SCpnt->cmnd, SCpnt->cmd_len);
  426. if (SCpnt->device->tagged_supported) { /* Tag Support                  */
  427. pSCB->SCB_TagMsg = SIMPLE_QUEUE_TAG; /* Do simple tag only   */
  428. } else {
  429. pSCB->SCB_TagMsg = 0; /* No tag support               */
  430. }
  431. if (SCpnt->use_sg) {
  432. pSrbSG = (struct scatterlist *) SCpnt->request_buffer;
  433. if (SCpnt->use_sg == 1) { /* If only one entry in the list *//*      treat it as regular I/O */
  434. pSCB->SCB_BufPtr = (U32) VIRT_TO_BUS(pSrbSG->address);
  435. TotalLen = pSrbSG->length;
  436. pSCB->SCB_SGLen = 0;
  437. } else { /* Assign SG physical address   */
  438. pSCB->SCB_BufPtr = pSCB->SCB_SGPAddr;
  439. pSCB->SCB_Flags |= SCF_SG; /* Turn on SG list flag       */
  440. for (i = 0, TotalLen = 0, pSG = &pSCB->SCB_SGList[0]; /* 1.01g */
  441.      i < SCpnt->use_sg;
  442.      i++, pSG++, pSrbSG++) {
  443. pSG->SG_Ptr = (U32) VIRT_TO_BUS(pSrbSG->address);
  444. TotalLen += pSG->SG_Len = pSrbSG->length;
  445. }
  446. pSCB->SCB_SGLen = i;
  447. }
  448. pSCB->SCB_BufLen = (SCpnt->request_bufflen > TotalLen) ?
  449.     TotalLen : SCpnt->request_bufflen;
  450. } else { /* Non SG                       */
  451. pSCB->SCB_BufPtr = (U32) VIRT_TO_BUS(SCpnt->request_buffer);
  452. pSCB->SCB_BufLen = SCpnt->request_bufflen;
  453. pSCB->SCB_SGLen = 0;
  454. }
  455. return;
  456. }
  457. /* 
  458.  *  Queue a command and setup interrupts for a free bus.
  459.  */
  460. int i91u_queue(Scsi_Cmnd * SCpnt, void (*done) (Scsi_Cmnd *))
  461. {
  462. register SCB *pSCB;
  463. HCS *pHCB; /* Point to Host adapter control block */
  464. if (SCpnt->lun > 16) { /* 07/22/98 */
  465. SCpnt->result = (DID_TIME_OUT << 16);
  466. done(SCpnt); /* Notify system DONE           */
  467. return (0);
  468. }
  469. pHCB = (HCS *) SCpnt->host->base;
  470. SCpnt->scsi_done = done;
  471. /* Get free SCSI control block  */
  472. if ((pSCB = tul_alloc_scb(pHCB)) == NULL) {
  473. i91uAppendSRBToQueue(pHCB, SCpnt); /* Buffer this request  */
  474. return (0);
  475. }
  476. i91uBuildSCB(pHCB, pSCB, SCpnt);
  477. tul_exec_scb(pHCB, pSCB); /* Start execute SCB            */
  478. return (0);
  479. }
  480. /*
  481.  *  We only support command in interrupt-driven fashion
  482.  */
  483. int i91u_command(Scsi_Cmnd * SCpnt)
  484. {
  485. printk("i91u: interrupt driven driver; use i91u_queue()n");
  486. return -1;
  487. }
  488. /*
  489.  *  Abort a queued command
  490.  *  (commands that are on the bus can't be aborted easily)
  491.  */
  492. int i91u_abort(Scsi_Cmnd * SCpnt)
  493. {
  494. HCS *pHCB;
  495. pHCB = (HCS *) SCpnt->host->base;
  496. return tul_abort_srb(pHCB, SCpnt);
  497. }
  498. /*
  499.  *  Reset registers, reset a hanging bus and
  500.  *  kill active and disconnected commands for target w/o soft reset
  501.  */
  502. int i91u_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags)
  503. { /* I need Host Control Block Information */
  504. HCS *pHCB;
  505. pHCB = (HCS *) SCpnt->host->base;
  506. if (reset_flags & (SCSI_RESET_SUGGEST_BUS_RESET | SCSI_RESET_SUGGEST_HOST_RESET))
  507. return tul_reset_scsi_bus(pHCB);
  508. else
  509. return tul_device_reset(pHCB, (ULONG) SCpnt, SCpnt->target, reset_flags);
  510. }
  511. /*
  512.  * Return the "logical geometry"
  513.  */
  514. int i91u_biosparam(Scsi_Disk * disk, kdev_t dev, int *info_array)
  515. {
  516. HCS *pHcb; /* Point to Host adapter control block */
  517. TCS *pTcb;
  518. pHcb = (HCS *) disk->device->host->base;
  519. pTcb = &pHcb->HCS_Tcs[disk->device->id];
  520. if (pTcb->TCS_DrvHead) {
  521. info_array[0] = pTcb->TCS_DrvHead;
  522. info_array[1] = pTcb->TCS_DrvSector;
  523. info_array[2] = disk->capacity / pTcb->TCS_DrvHead / pTcb->TCS_DrvSector;
  524. } else {
  525. if (pTcb->TCS_DrvFlags & TCF_DRV_255_63) {
  526. info_array[0] = 255;
  527. info_array[1] = 63;
  528. info_array[2] = disk->capacity / 255 / 63;
  529. } else {
  530. info_array[0] = 64;
  531. info_array[1] = 32;
  532. info_array[2] = disk->capacity >> 11;
  533. }
  534. }
  535. #if defined(DEBUG_BIOSPARAM)
  536. if (i91u_debug & debug_biosparam) {
  537. printk("bios geometry: head=%d, sec=%d, cyl=%dn",
  538.        info_array[0], info_array[1], info_array[2]);
  539. printk("WARNING: check, if the bios geometry is correct.n");
  540. }
  541. #endif
  542. return 0;
  543. }
  544. /*****************************************************************************
  545.  Function name  : i91uSCBPost
  546.  Description    : This is callback routine be called when tulip finish one
  547. SCSI command.
  548.  Input          : pHCB  -       Pointer to host adapter control block.
  549.   pSCB  -       Pointer to SCSI control block.
  550.  Output         : None.
  551.  Return         : None.
  552. *****************************************************************************/
  553. static void i91uSCBPost(BYTE * pHcb, BYTE * pScb)
  554. {
  555. Scsi_Cmnd *pSRB; /* Pointer to SCSI request block */
  556. HCS *pHCB;
  557. SCB *pSCB;
  558. pHCB = (HCS *) pHcb;
  559. pSCB = (SCB *) pScb;
  560. if ((pSRB = pSCB->SCB_Srb) == 0) {
  561. printk("i91uSCBPost: SRB pointer is emptyn");
  562. tul_release_scb(pHCB, pSCB); /* Release SCB for current channel */
  563. return;
  564. }
  565. switch (pSCB->SCB_HaStat) {
  566. case 0x0:
  567. case 0xa: /* Linked command complete without error and linked normally */
  568. case 0xb: /* Linked command complete without error interrupt generated */
  569. pSCB->SCB_HaStat = 0;
  570. break;
  571. case 0x11: /* Selection time out-The initiator selection or target
  572.    reselection was not complete within the SCSI Time out period */
  573. pSCB->SCB_HaStat = DID_TIME_OUT;
  574. break;
  575. case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
  576.    phase sequence was requested by the target. The host adapter
  577.    will generate a SCSI Reset Condition, notifying the host with
  578.    a SCRD interrupt */
  579. pSCB->SCB_HaStat = DID_RESET;
  580. break;
  581. case 0x1a: /* SCB Aborted. 07/21/98 */
  582. pSCB->SCB_HaStat = DID_ABORT;
  583. break;
  584. case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
  585.    than was allocated by the Data Length field or the sum of the
  586.    Scatter / Gather Data Length fields. */
  587. case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
  588. case 0x16: /* Invalid SCB Operation Code. */
  589. default:
  590. printk("ini9100u: %x %xn", pSCB->SCB_HaStat, pSCB->SCB_TaStat);
  591. pSCB->SCB_HaStat = DID_ERROR; /* Couldn't find any better */
  592. break;
  593. }
  594. pSRB->result = pSCB->SCB_TaStat | (pSCB->SCB_HaStat << 16);
  595. if (pSRB == NULL) {
  596. printk("pSRB is NULLn");
  597. }
  598. pSRB->scsi_done(pSRB); /* Notify system DONE           */
  599. if ((pSRB = i91uPopSRBFromQueue(pHCB)) != NULL)
  600. /* Find the next pending SRB    */
  601. { /* Assume resend will success   */
  602. /* Reuse old SCB                */
  603. i91uBuildSCB(pHCB, pSCB, pSRB); /* Create corresponding SCB     */
  604. tul_exec_scb(pHCB, pSCB); /* Start execute SCB            */
  605. } else { /* No Pending SRB               */
  606. tul_release_scb(pHCB, pSCB); /* Release SCB for current channel */
  607. }
  608. return;
  609. }
  610. /*
  611.  * Interrupts handler (main routine of the driver)
  612.  */
  613. static void i91u_intr0(int irqno, void *dev_id, struct pt_regs *regs)
  614. {
  615. unsigned long flags;
  616. if (tul_hcs[0].HCS_Intr != irqno)
  617. return;
  618. spin_lock_irqsave(&io_request_lock, flags);
  619. tul_isr(&tul_hcs[0]);
  620. spin_unlock_irqrestore(&io_request_lock, flags);
  621. }
  622. static void i91u_intr1(int irqno, void *dev_id, struct pt_regs *regs)
  623. {
  624. unsigned long flags;
  625. if (tul_hcs[1].HCS_Intr != irqno)
  626. return;
  627. spin_lock_irqsave(&io_request_lock, flags);
  628. tul_isr(&tul_hcs[1]);
  629. spin_unlock_irqrestore(&io_request_lock, flags);
  630. }
  631. static void i91u_intr2(int irqno, void *dev_id, struct pt_regs *regs)
  632. {
  633. unsigned long flags;
  634. if (tul_hcs[2].HCS_Intr != irqno)
  635. return;
  636. spin_lock_irqsave(&io_request_lock, flags);
  637. tul_isr(&tul_hcs[2]);
  638. spin_unlock_irqrestore(&io_request_lock, flags);
  639. }
  640. static void i91u_intr3(int irqno, void *dev_id, struct pt_regs *regs)
  641. {
  642. unsigned long flags;
  643. if (tul_hcs[3].HCS_Intr != irqno)
  644. return;
  645. spin_lock_irqsave(&io_request_lock, flags);
  646. tul_isr(&tul_hcs[3]);
  647. spin_unlock_irqrestore(&io_request_lock, flags);
  648. }
  649. static void i91u_intr4(int irqno, void *dev_id, struct pt_regs *regs)
  650. {
  651. unsigned long flags;
  652. if (tul_hcs[4].HCS_Intr != irqno)
  653. return;
  654. spin_lock_irqsave(&io_request_lock, flags);
  655. tul_isr(&tul_hcs[4]);
  656. spin_unlock_irqrestore(&io_request_lock, flags);
  657. }
  658. static void i91u_intr5(int irqno, void *dev_id, struct pt_regs *regs)
  659. {
  660. unsigned long flags;
  661. if (tul_hcs[5].HCS_Intr != irqno)
  662. return;
  663. spin_lock_irqsave(&io_request_lock, flags);
  664. tul_isr(&tul_hcs[5]);
  665. spin_unlock_irqrestore(&io_request_lock, flags);
  666. }
  667. static void i91u_intr6(int irqno, void *dev_id, struct pt_regs *regs)
  668. {
  669. unsigned long flags;
  670. if (tul_hcs[6].HCS_Intr != irqno)
  671. return;
  672. spin_lock_irqsave(&io_request_lock, flags);
  673. tul_isr(&tul_hcs[6]);
  674. spin_unlock_irqrestore(&io_request_lock, flags);
  675. }
  676. static void i91u_intr7(int irqno, void *dev_id, struct pt_regs *regs)
  677. {
  678. unsigned long flags;
  679. if (tul_hcs[7].HCS_Intr != irqno)
  680. return;
  681. spin_lock_irqsave(&io_request_lock, flags);
  682. tul_isr(&tul_hcs[7]);
  683. spin_unlock_irqrestore(&io_request_lock, flags);
  684. }
  685. /* 
  686.  * Dump the current driver status and panic...
  687.  */
  688. static void i91u_panic(char *msg)
  689. {
  690. printk("ni91u_panic: %sn", msg);
  691. panic("i91u panic");
  692. }
  693. /*
  694.  * Release ressources
  695.  */
  696. int i91u_release(struct Scsi_Host *hreg)
  697. {
  698. free_irq(hreg->irq, hreg);
  699. release_region(hreg->io_port, 256);
  700. return 0;
  701. }
  702. MODULE_LICENSE("Dual BSD/GPL");