unsigned int gfp_mask = (shost->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC; 
gfp_t gfp_mask = (shost->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC; 
static int port_detect(unsigned long port_base, unsigned int j,		struct scsi_host_template *tpnt){	unsigned char irq, dma_channel, subversion, i, is_pci = 0;	unsigned char protocol_rev;	struct eata_info info;	char *bus_type, dma_name[16];	struct pci_dev *pdev;	/* Allowed DMA channels for ISA (0 indicates reserved) */	unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };	struct Scsi_Host *shost;	struct hostdata *ha;	char name[16];	sprintf(name, "%s%d", driver_name, j);	if (!request_region(port_base, REGION_SIZE, driver_name)) {#if defined(DEBUG_DETECT)		printk("%s: address 0x%03lx in use, skipping probe.\n", name,		       port_base);#endif		goto fail;	}	spin_lock_irq(&driver_lock);	if (do_dma(port_base, 0, READ_CONFIG_PIO)) {#if defined(DEBUG_DETECT)		printk("%s: detect, do_dma failed at 0x%03lx.\n", name,		       port_base);#endif		goto freelock;	}	/* Read the info structure */	if (read_pio(port_base, (ushort *) & info, (ushort *) & info.ipad[0])) {#if defined(DEBUG_DETECT)		printk("%s: detect, read_pio failed at 0x%03lx.\n", name,		       port_base);#endif		goto freelock;	}	info.data_len = DEV2H(info.data_len);	info.sign = DEV2H(info.sign);	info.cp_pad_len = DEV2H16(info.cp_pad_len);	info.cp_len = DEV2H(info.cp_len);	info.sp_len = DEV2H(info.sp_len);	info.scatt_size = DEV2H16(info.scatt_size);	info.queue_size = DEV2H16(info.queue_size);	/* Check the controller "EATA" signature */	if (info.sign != EATA_SIG_BE) {#if defined(DEBUG_DETECT)		printk("%s: signature 0x%04x discarded.\n", name, info.sign);#endif		goto freelock;	}	if (info.data_len < EATA_2_0A_SIZE) {		printk		    ("%s: config structure size (%d bytes) too short, detaching.\n",		     name, info.data_len);		goto freelock;	} else if (info.data_len == EATA_2_0A_SIZE)		protocol_rev = 'A';	else if (info.data_len == EATA_2_0B_SIZE)		protocol_rev = 'B';	else		protocol_rev = 'C';	if (protocol_rev != 'A' && info.forcaddr) {		printk("%s: warning, port address has been forced.\n", name);		bus_type = "PCI";		is_pci = 1;		subversion = ESA;	} else if (port_base > MAX_EISA_ADDR		   || (protocol_rev == 'C' && info.pci)) {		bus_type = "PCI";		is_pci = 1;		subversion = ESA;	} else if (port_base >= MIN_EISA_ADDR		   || (protocol_rev == 'C' && info.eisa)) {		bus_type = "EISA";		subversion = ESA;	} else if (protocol_rev == 'C' && !info.eisa && !info.pci) {		bus_type = "ISA";		subversion = ISA;	} else if (port_base > MAX_ISA_ADDR) {		bus_type = "PCI";		is_pci = 1;		subversion = ESA;	} else {		bus_type = "ISA";		subversion = ISA;	}	if (!info.haaval || info.ata) {		printk		    ("%s: address 0x%03lx, unusable %s board (%d%d), detaching.\n",		     name, port_base, bus_type, info.haaval, info.ata);		goto freelock;	}	if (info.drqvld) {		if (subversion == ESA)			printk("%s: warning, weird %s board using DMA.\n", name,			       bus_type);		subversion = ISA;		dma_channel = dma_channel_table[3 - info.drqx];	} else {		if (subversion == ISA)			printk("%s: warning, weird %s board not using DMA.\n",			       name, bus_type);		subversion = ESA;		dma_channel = NO_DMA;	}	if (!info.dmasup)		printk("%s: warning, DMA protocol support not asserted.\n",		       name);	irq = info.irq;	if (subversion == ESA && !info.irq_tr)		printk		    ("%s: warning, LEVEL triggering is suggested for IRQ %u.\n",		     name, irq);	if (is_pci) {		pdev = get_pci_dev(port_base);		if (!pdev)			printk			    ("%s: warning, failed to get pci_dev structure.\n",			     name);	} else		pdev = NULL;	if (pdev && (irq != pdev->irq)) {		printk("%s: IRQ %u mapped to IO-APIC IRQ %u.\n", name, irq,		       pdev->irq);		irq = pdev->irq;	}	/* Board detected, allocate its IRQ */	if (request_irq(irq, do_interrupt_handler,			SA_INTERRUPT | ((subversion == ESA) ? SA_SHIRQ : 0),			driver_name, (void *)&sha[j])) {		printk("%s: unable to allocate IRQ %u, detaching.\n", name,		       irq);		goto freelock;	}	if (subversion == ISA && request_dma(dma_channel, driver_name)) {		printk("%s: unable to allocate DMA channel %u, detaching.\n",		       name, dma_channel);		goto freeirq;	}#if defined(FORCE_CONFIG)	{		struct eata_config *cf;		dma_addr_t cf_dma_addr;		cf = pci_alloc_consistent(pdev, sizeof(struct eata_config),					  &cf_dma_addr);		if (!cf) {			printk			    ("%s: config, pci_alloc_consistent failed, detaching.\n",			     name);			goto freedma;		}		/* Set board configuration */		memset((char *)cf, 0, sizeof(struct eata_config));		cf->len = (ushort) H2DEV16((ushort) 510);		cf->ocena = 1;		if (do_dma(port_base, cf_dma_addr, SET_CONFIG_DMA)) {			printk			    ("%s: busy timeout sending configuration, detaching.\n",			     name);			pci_free_consistent(pdev, sizeof(struct eata_config),					    cf, cf_dma_addr);			goto freedma;		}	}#endif	spin_unlock_irq(&driver_lock);	sh[j] = shost = scsi_register(tpnt, sizeof(struct hostdata));	spin_lock_irq(&driver_lock);	if (shost == NULL) {		printk("%s: unable to register host, detaching.\n", name);		goto freedma;	}	shost->io_port = port_base;	shost->unique_id = port_base;	shost->n_io_port = REGION_SIZE;	shost->dma_channel = dma_channel;	shost->irq = irq;	shost->sg_tablesize = (ushort) info.scatt_size;	shost->this_id = (ushort) info.host_addr[3];	shost->can_queue = (ushort) info.queue_size;	shost->cmd_per_lun = MAX_CMD_PER_LUN;	ha = (struct hostdata *)shost->hostdata;		memset(ha, 0, sizeof(struct hostdata));	ha->subversion = subversion;	ha->protocol_rev = protocol_rev;	ha->is_pci = is_pci;	ha->pdev = pdev;	ha->board_number = j;	if (ha->subversion == ESA)		shost->unchecked_isa_dma = 0;	else {		unsigned long flags;		shost->unchecked_isa_dma = 1;		flags = claim_dma_lock();		disable_dma(dma_channel);		clear_dma_ff(dma_channel);		set_dma_mode(dma_channel, DMA_MODE_CASCADE);		enable_dma(dma_channel);		release_dma_lock(flags);	}	strcpy(ha->board_name, name);	/* DPT PM2012 does not allow to detect sg_tablesize correctly */	if (shost->sg_tablesize > MAX_SGLIST || shost->sg_tablesize < 2) {		printk("%s: detect, wrong n. of SG lists %d, fixed.\n",		       ha->board_name, shost->sg_tablesize);		shost->sg_tablesize = MAX_SGLIST;	}	/* DPT PM2012 does not allow to detect can_queue correctly */	if (shost->can_queue > MAX_MAILBOXES || shost->can_queue < 2) {		printk("%s: detect, wrong n. of mbox %d, fixed.\n",		       ha->board_name, shost->can_queue);		shost->can_queue = MAX_MAILBOXES;	}	if (protocol_rev != 'A') {		if (info.max_chan > 0 && info.max_chan < MAX_CHANNEL)			shost->max_channel = info.max_chan;		if (info.max_id > 7 && info.max_id < MAX_TARGET)			shost->max_id = info.max_id + 1;		if (info.large_sg && shost->sg_tablesize == MAX_SGLIST)			shost->sg_tablesize = MAX_LARGE_SGLIST;	}	if (protocol_rev == 'C') {		if (info.max_lun > 7 && info.max_lun < MAX_LUN)			shost->max_lun = info.max_lun + 1;	}	if (dma_channel == NO_DMA)		sprintf(dma_name, "%s", "BMST");	else		sprintf(dma_name, "DMA %u", dma_channel);	spin_unlock_irq(&driver_lock);	for (i = 0; i < shost->can_queue; i++)		ha->cp[i].cp_dma_addr = pci_map_single(ha->pdev,							  &ha->cp[i],							  sizeof(struct mscp),							  PCI_DMA_BIDIRECTIONAL);	for (i = 0; i < shost->can_queue; i++) {		size_t sz = shost->sg_tablesize *sizeof(struct sg_list);		unsigned int gfp_mask = (shost->unchecked_isa_dma ? GFP_DMA : 0) | GFP_ATOMIC;		ha->cp[i].sglist = kmalloc(sz, gfp_mask);		if (!ha->cp[i].sglist) {			printk			    ("%s: kmalloc SGlist failed, mbox %d, detaching.\n",			     ha->board_name, i);			goto release;		}	}	if (!(ha->sp_cpu_addr = pci_alloc_consistent(ha->pdev,							sizeof(struct mssp),							&ha->sp_dma_addr))) {		printk("%s: pci_alloc_consistent failed, detaching.\n", ha->board_name);		goto release;	}	if (max_queue_depth > MAX_TAGGED_CMD_PER_LUN)		max_queue_depth = MAX_TAGGED_CMD_PER_LUN;	if (max_queue_depth < MAX_CMD_PER_LUN)		max_queue_depth = MAX_CMD_PER_LUN;	if (tag_mode != TAG_DISABLED && tag_mode != TAG_SIMPLE)		tag_mode = TAG_ORDERED;	if (j == 0) {		printk		    ("EATA/DMA 2.0x: Copyright (C) 1994-2003 Dario Ballabio.\n");		printk		    ("%s config options -> tm:%d, lc:%c, mq:%d, rs:%c, et:%c, "		     "ip:%c, ep:%c, pp:%c.\n", driver_name, tag_mode,		     YESNO(linked_comm), max_queue_depth, YESNO(rev_scan),		     YESNO(ext_tran), YESNO(isa_probe), YESNO(eisa_probe),		     YESNO(pci_probe));	}	printk("%s: 2.0%c, %s 0x%03lx, IRQ %u, %s, SG %d, MB %d.\n",	       ha->board_name, ha->protocol_rev, bus_type,	       (unsigned long)shost->io_port, shost->irq, dma_name,	       shost->sg_tablesize, shost->can_queue);	if (shost->max_id > 8 || shost->max_lun > 8)		printk		    ("%s: wide SCSI support enabled, max_id %u, max_lun %u.\n",		     ha->board_name, shost->max_id, shost->max_lun);	for (i = 0; i <= shost->max_channel; i++)		printk("%s: SCSI channel %u enabled, host target ID %d.\n",		       ha->board_name, i, info.host_addr[3 - i]);#if defined(DEBUG_DETECT)	printk("%s: Vers. 0x%x, ocs %u, tar %u, trnxfr %u, more %u, SYNC 0x%x, "	       "sec. %u, infol %d, cpl %d spl %d.\n", name, info.version,	       info.ocsena, info.tarsup, info.trnxfr, info.morsup, info.sync,	       info.second, info.data_len, info.cp_len, info.sp_len);	if (protocol_rev == 'B' || protocol_rev == 'C')		printk("%s: isaena %u, forcaddr %u, max_id %u, max_chan %u, "		       "large_sg %u, res1 %u.\n", name, info.isaena,		       info.forcaddr, info.max_id, info.max_chan, info.large_sg,		       info.res1);	if (protocol_rev == 'C')		printk("%s: max_lun %u, m1 %u, idquest %u, pci %u, eisa %u, "		       "raidnum %u.\n", name, info.max_lun, info.m1,		       info.idquest, info.pci, info.eisa, info.raidnum);#endif	if (ha->pdev) {		pci_set_master(ha->pdev);		if (pci_set_dma_mask(ha->pdev, 0xffffffff))			printk("%s: warning, pci_set_dma_mask failed.\n",			       ha->board_name);	}	return 1;      freedma:	if (subversion == ISA)		free_dma(dma_channel);      freeirq:	free_irq(irq, &sha[j]);      freelock:	spin_unlock_irq(&driver_lock);	release_region(port_base, REGION_SIZE);      fail:	return 0;      release:	eata2x_release(shost);	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/c53033f6b0bd7cc133b7f433083f0394cf29ac70/eata.c/buggy/drivers/scsi/eata.c