init_MUTEX(&ioc->sas_mgmt.mutex); init_completion(&ioc->sas_mgmt.done); 
mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id){	struct Scsi_Host	*sh;	MPT_SCSI_HOST		*hd;	MPT_ADAPTER 		*ioc;	unsigned long		 flags;	int			 sz, ii;	int			 numSGE = 0;	int			 scale;	int			 ioc_cap;	u8			*mem;	int			error=0;	int			r;	r = mpt_attach(pdev,id);	if (r)		return r;	ioc = pci_get_drvdata(pdev);	ioc->DoneCtx = mptsasDoneCtx;	ioc->TaskCtx = mptsasTaskCtx;	ioc->InternalCtx = mptsasInternalCtx;	/*  Added sanity check on readiness of the MPT adapter.	 */	if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {		printk(MYIOC_s_WARN_FMT		  "Skipping because it's not operational!\n",		  ioc->name);		return -ENODEV;	}	if (!ioc->active) {		printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",		  ioc->name);		return -ENODEV;	}	/*  Sanity check - ensure at least 1 port is INITIATOR capable	 */	ioc_cap = 0;	for (ii = 0; ii < ioc->facts.NumberOfPorts; ii++) {		if (ioc->pfacts[ii].ProtocolFlags &				MPI_PORTFACTS_PROTOCOL_INITIATOR)			ioc_cap++;	}	if (!ioc_cap) {		printk(MYIOC_s_WARN_FMT			"Skipping ioc=%p because SCSI Initiator mode "			"is NOT enabled!\n", ioc->name, ioc);		return 0;	}	sh = scsi_host_alloc(&mptsas_driver_template, sizeof(MPT_SCSI_HOST));	if (!sh) {		printk(MYIOC_s_WARN_FMT			"Unable to register controller with SCSI subsystem\n",			ioc->name);                return -1;        }	spin_lock_irqsave(&ioc->FreeQlock, flags);	/* Attach the SCSI Host to the IOC structure	 */	ioc->sh = sh;	sh->io_port = 0;	sh->n_io_port = 0;	sh->irq = 0;	/* set 16 byte cdb's */	sh->max_cmd_len = 16;	sh->max_id = ioc->pfacts->MaxDevices + 1;	sh->transportt = mptsas_transport_template;	sh->max_lun = MPT_LAST_LUN + 1;	sh->max_channel = 0;	sh->this_id = ioc->pfacts[0].PortSCSIID;	/* Required entry.	 */	sh->unique_id = ioc->id;	INIT_LIST_HEAD(&ioc->sas_topology);	/* Verify that we won't exceed the maximum	 * number of chain buffers	 * We can optimize:  ZZ = req_sz/sizeof(SGE)	 * For 32bit SGE's:	 *  numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ	 *               + (req_sz - 64)/sizeof(SGE)	 * A slightly different algorithm is required for	 * 64bit SGEs.	 */	scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));	if (sizeof(dma_addr_t) == sizeof(u64)) {		numSGE = (scale - 1) *		  (ioc->facts.MaxChainDepth-1) + scale +		  (ioc->req_sz - 60) / (sizeof(dma_addr_t) +		  sizeof(u32));	} else {		numSGE = 1 + (scale - 1) *		  (ioc->facts.MaxChainDepth-1) + scale +		  (ioc->req_sz - 64) / (sizeof(dma_addr_t) +		  sizeof(u32));	}	if (numSGE < sh->sg_tablesize) {		/* Reset this value */		dprintk((MYIOC_s_INFO_FMT		  "Resetting sg_tablesize to %d from %d\n",		  ioc->name, numSGE, sh->sg_tablesize));		sh->sg_tablesize = numSGE;	}	spin_unlock_irqrestore(&ioc->FreeQlock, flags);	hd = (MPT_SCSI_HOST *) sh->hostdata;	hd->ioc = ioc;	/* SCSI needs scsi_cmnd lookup table!	 * (with size equal to req_depth*PtrSz!)	 */	sz = ioc->req_depth * sizeof(void *);	mem = kmalloc(sz, GFP_ATOMIC);	if (mem == NULL) {		error = -ENOMEM;		goto mptsas_probe_failed;	}	memset(mem, 0, sz);	hd->ScsiLookup = (struct scsi_cmnd **) mem;	dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p, sz=%d\n",		 ioc->name, hd->ScsiLookup, sz));	/* Allocate memory for the device structures.	 * A non-Null pointer at an offset	 * indicates a device exists.	 * max_id = 1 + maximum id (hosts.h)	 */	sz = sh->max_id * sizeof(void *);	mem = kmalloc(sz, GFP_ATOMIC);	if (mem == NULL) {		error = -ENOMEM;		goto mptsas_probe_failed;	}	memset(mem, 0, sz);	hd->Targets = (VirtDevice **) mem;	dprintk((KERN_INFO	  "  Targets @ %p, sz=%d\n", hd->Targets, sz));	/* Clear the TM flags	 */	hd->tmPending = 0;	hd->tmState = TM_STATE_NONE;	hd->resetPending = 0;	hd->abortSCpnt = NULL;	/* Clear the pointer used to store	 * single-threaded commands, i.e., those	 * issued during a bus scan, dv and	 * configuration pages.	 */	hd->cmdPtr = NULL;	/* Initialize this SCSI Hosts' timers	 * To use, set the timer expires field	 * and add_timer	 */	init_timer(&hd->timer);	hd->timer.data = (unsigned long) hd;	hd->timer.function = mptscsih_timer_expired;	hd->mpt_pq_filter = mpt_pq_filter;	ioc->sas_data.ptClear = mpt_pt_clear;	if (ioc->sas_data.ptClear==1) {		mptbase_sas_persist_operation(		    ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);	}	ddvprintk((MYIOC_s_INFO_FMT		"mpt_pq_filter %x mpt_pq_filter %x\n",		ioc->name,		mpt_pq_filter,		mpt_pq_filter));	init_waitqueue_head(&hd->scandv_waitq);	hd->scandv_wait_done = 0;	hd->last_queue_full = 0;	error = scsi_add_host(sh, &ioc->pcidev->dev);	if (error) {		dprintk((KERN_ERR MYNAM		  "scsi_add_host failed\n"));		goto mptsas_probe_failed;	}	mptsas_scan_sas_topology(ioc);	return 0;mptsas_probe_failed:	mptscsih_remove(pdev);	return error;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/da4fa65596733914b3c21fdffa02593959c67f56/mptsas.c/clean/drivers/message/fusion/mptsas.c