hosts.c 19 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 *  hosts.c Copyright (C) 1992 Drew Eckhardt
 *          Copyright (C) 1993, 1994, 1995 Eric Youngdale
 *
 *  mid to lowlevel SCSI driver interface
 *      Initial versions: Drew Eckhardt
 *      Subsequent revisions: Eric Youngdale
 *
 *  <drew@colorado.edu>
 *
 *  Jiffies wrap fixes (host->resetting), 3 Dec 1998 Andrea Arcangeli
 *  Added QLOGIC QLA1280 SCSI controller kernel host support. 
 *     August 4, 1999 Fred Lewis, Intel DuPont
 *
 *  Updated to reflect the new initialization scheme for the higher 
 *  level of scsi drivers (sd/sr/st)
 *  September 17, 2000 Torben Mathiasen <tmm@image.dk>
18 19 20
 *
 *  Restructured scsi_host lists and associated functions.
 *  September 04, 2002 Mike Anderson (andmike@us.ibm.com)
Linus Torvalds's avatar
Linus Torvalds committed
21 22 23 24 25
 */


/*
 *  This file contains the medium level SCSI
26
 *  host interface initialization, as well as the scsi_hosts list of SCSI
Linus Torvalds's avatar
Linus Torvalds committed
27 28 29 30 31 32 33 34 35 36
 *  hosts currently present in the system.
 */

#include <linux/module.h>
#include <linux/blk.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/proc_fs.h>
#include <linux/init.h>
37 38
#include <linux/list.h>
#include <linux/smp_lock.h>
Linus Torvalds's avatar
Linus Torvalds committed
39 40 41 42

#define __KERNEL_SYSCALLS__

#include <linux/unistd.h>
43
#include <asm/dma.h>
Linus Torvalds's avatar
Linus Torvalds committed
44 45 46 47

#include "scsi.h"
#include "hosts.h"

48 49 50
static LIST_HEAD(scsi_host_hn_list);
static LIST_HEAD(scsi_host_list);
static spinlock_t scsi_host_list_lock = SPIN_LOCK_UNLOCKED;
51 52 53

static int scsi_host_next_hn;		/* host_no for next new host */
static int scsi_hosts_registered;	/* cnt of registered scsi hosts */
54 55
static int scsi_ignore_no_error_handling = 0;

56 57 58 59
/**
 * scsi_tp_for_each_host - call function for each scsi host off a template
 * @shost_tp:	a pointer to a scsi host template
 * @callback:	a pointer to callback function
Linus Torvalds's avatar
Linus Torvalds committed
60
 *
61 62 63 64 65 66 67 68
 * Return value:
 * 	0 on Success / 1 on Failure
 **/
int scsi_tp_for_each_host(Scsi_Host_Template *shost_tp, int
			    (*callback)(struct Scsi_Host *shost))
{
	struct list_head *lh, *lh_sf;
	struct Scsi_Host *shost;
Linus Torvalds's avatar
Linus Torvalds committed
69

70
	spin_lock(&scsi_host_list_lock);
Linus Torvalds's avatar
Linus Torvalds committed
71

72 73 74 75 76 77 78 79
	list_for_each_safe(lh, lh_sf, &scsi_host_list) {
		shost = list_entry(lh, struct Scsi_Host, sh_list);
		if (shost->hostt == shost_tp) {
			spin_unlock(&scsi_host_list_lock);
			callback(shost);
			spin_lock(&scsi_host_list_lock);
		}
	}
Linus Torvalds's avatar
Linus Torvalds committed
80

81
	spin_unlock(&scsi_host_list_lock);
Linus Torvalds's avatar
Linus Torvalds committed
82

83 84
	return 0;
}
Linus Torvalds's avatar
Linus Torvalds committed
85

86 87 88 89 90
/**
 * scsi_host_generic_release - default release function for hosts
 * @shost: 
 * 
 * Description:
91 92
 * 	This is the default case for the release function.  Its completely
 *	useless for anything but old ISA adapters
93
 **/
94
static void scsi_host_legacy_release(struct Scsi_Host *shost)
95 96 97 98 99 100 101 102 103
{
	if (shost->irq)
		free_irq(shost->irq, NULL);
	if (shost->dma_channel != 0xff)
		free_dma(shost->dma_channel);
	if (shost->io_port && shost->n_io_port)
		release_region(shost->io_port, shost->n_io_port);
}

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
static int scsi_remove_legacy_host(struct Scsi_Host *shost)
{
	int error, pcount = scsi_hosts_registered;

	error = scsi_remove_host(shost);
	if (error)
		return error;

	if (shost->hostt->release)
		(*shost->hostt->release)(shost);
	else
		scsi_host_legacy_release(shost);

	if (pcount == scsi_hosts_registered)
		scsi_unregister(shost);
	return 0;
}

122
/**
123
 * scsi_remove_host - check a scsi host for release and release
124 125 126 127 128
 * @shost:	a pointer to a scsi host to release
 *
 * Return value:
 * 	0 on Success / 1 on Failure
 **/
129
int scsi_remove_host(struct Scsi_Host *shost)
130
{
131 132
	struct scsi_device *sdev;
	struct scsi_cmnd *scmd;
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184

	/*
	 * Current policy is all shosts go away on unregister.
	 */
	if (shost->hostt->module && GET_USE_COUNT(shost->hostt->module))
		return 1;

	/*
	 * FIXME Do ref counting.  We force all of the devices offline to
	 * help prevent race conditions where other hosts/processors could
	 * try and get in and queue a command.
	 */
	for (sdev = shost->host_queue; sdev; sdev = sdev->next) 
		sdev->online = FALSE;

	for (sdev = shost->host_queue; sdev; sdev = sdev->next) {
		/*
		 * Loop over all of the commands associated with the
		 * device.  If any of them are busy, then set the state
		 * back to inactive and bail.
		 */
		for (scmd = sdev->device_queue; scmd; scmd = scmd->next) {
			if (scmd->request && scmd->request->rq_status !=
			    RQ_INACTIVE) {
				printk(KERN_ERR "SCSI device not inactive"
				       "- rq_status=%d, target=%d, pid=%ld,"
				       "state=%d, owner=%d.\n",
				       scmd->request->rq_status,
				       scmd->target, scmd->pid,
				       scmd->state, scmd->owner);
				for (sdev = shost->host_queue; sdev;
				     sdev = sdev->next) {
					for (scmd = sdev->device_queue; scmd;
					     scmd = scmd->next)
						if (scmd->request->rq_status ==
						    RQ_SCSI_DISCONNECTING)
							scmd->request->rq_status = RQ_INACTIVE;
				}
				printk(KERN_ERR "Device busy???\n");
				return 1;
			}
			/*
			 * No, this device is really free.  Mark it as such, and
			 * continue on.
			 */
			scmd->state = SCSI_STATE_DISCONNECTING;
			if (scmd->request)
				scmd->request->rq_status =
					RQ_SCSI_DISCONNECTING;	/* Mark as
								   busy */
		}
	}
Linus Torvalds's avatar
Linus Torvalds committed
185

186 187 188 189 190
	/*
	 * Next we detach the high level drivers from the Scsi_Device
	 * structures
	 */
	for (sdev = shost->host_queue; sdev; sdev = sdev->next) {
191
		scsi_detach_device(sdev);
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214

		/* If something still attached, punt */
		if (sdev->attached) {
			printk(KERN_ERR "Attached usage count = %d\n",
			       sdev->attached);
			return 1;
		}
		devfs_unregister(sdev->de);
		device_unregister(&sdev->sdev_driverfs_dev);
	}

	/* Next we free up the Scsi_Cmnd structures for this host */

	for (sdev = shost->host_queue; sdev;
	     sdev = shost->host_queue) {
		blk_cleanup_queue(&sdev->request_queue);
		/* Next free up the Scsi_Device structures for this host */
		shost->host_queue = sdev->next;
		if (sdev->inquiry)
			kfree(sdev->inquiry);
		kfree(sdev);
	}

215 216
	return 0;
}
217

218 219 220 221 222
int scsi_add_host(struct Scsi_Host *shost)
{
	Scsi_Host_Template *sht = shost->hostt;
	struct scsi_device *sdev;
	int error = 0;
223

224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
	printk(KERN_INFO "scsi%d : %s\n", shost->host_no,
			sht->info ? sht->info(shost) : sht->name);

	device_register(&shost->host_driverfs_dev);
	scan_scsis(shost, 0, 0, 0, 0);
			
	for (sdev = shost->host_queue; sdev; sdev = sdev->next) {
		if (sdev->host->hostt != sht)
			continue; /* XXX(hch): can this really happen? */
		error = scsi_attach_device(sdev);
		if (error)
			break;
	}

	return error;
Linus Torvalds's avatar
Linus Torvalds committed
239 240
}

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
/**
 * scsi_unregister - unregister a scsi host
 * @shost:	scsi host to be unregistered
 **/
void scsi_unregister(struct Scsi_Host *shost)
{
	struct list_head *lh;
	Scsi_Host_Name *shost_name;

	/* Remove shost from scsi_host_list */
	spin_lock(&scsi_host_list_lock);
	list_del(&shost->sh_list);
	spin_unlock(&scsi_host_list_lock);

	/* Unregister from scsi_host_hn_list */
	list_for_each(lh, &scsi_host_hn_list) {
		shost_name = list_entry(lh, Scsi_Host_Name, shn_list);
		if (shost->host_no == shost_name->host_no)
			shost_name->host_registered = 0;
	}

	/*
	 * Next, kill the kernel error recovery thread for this host.
	 */
	if (shost->ehandler) {
		DECLARE_MUTEX_LOCKED(sem);
		shost->eh_notify = &sem;
		send_sig(SIGHUP, shost->ehandler, 1);
		down(&sem);
		shost->eh_notify = NULL;
	}

	scsi_hosts_registered--;
	shost->hostt->present--;

	/* Cleanup proc and driverfs */
#ifdef CONFIG_PROC_FS
	scsi_proc_host_rm(shost);
	if (!shost->hostt->present)
		remove_proc_entry(shost->hostt->proc_name, proc_scsi);
#endif
	device_unregister(&shost->host_driverfs_dev);

	kfree(shost);
}

/**
 * scsi_host_hn_add - allocate and add new Scsi_Host_Name
 * @name:	String to store in name field
 *
 * Return value:
 * 	Pointer to a new Scsi_Host_Name
 **/
Scsi_Host_Name *scsi_host_hn_add(char *name)
{
	Scsi_Host_Name *shost_name;
	int len;

	len = strlen(name);
	shost_name =  kmalloc(sizeof(*shost_name), GFP_KERNEL);
	if (!shost_name) {
		printk(KERN_ERR "%s: out of memory at line %d.\n",
		       __FUNCTION__, __LINE__);
		return NULL;
	}
	shost_name->name = kmalloc(len + 1, GFP_KERNEL);
	if (!shost_name->name) {
		kfree(shost_name);
		printk(KERN_ERR "%s: out of memory at line %d.\n",
		       __FUNCTION__, __LINE__);
		return NULL;
	}

	if (len)
		strncpy(shost_name->name, name, len);
	shost_name->name[len] = 0;
	shost_name->host_no = scsi_host_next_hn++;
	shost_name->host_registered = 0;
	list_add_tail(&shost_name->shn_list, &scsi_host_hn_list);

	return shost_name;
}

/**
 * scsi_register - register a scsi host adapter instance.
 * @shost_tp:	pointer to scsi host template
 * @xtr_bytes:	extra bytes to allocate for driver
 *
 * Note:
 * 	We call this when we come across a new host adapter. We only do
 * 	this once we are 100% sure that we want to use this host adapter -
 * 	it is a pain to reverse this, so we try to avoid it 
 *
 * Return value:
 * 	Pointer to a new Scsi_Host
 **/
Linus Torvalds's avatar
Linus Torvalds committed
337
extern int blk_nohighio;
338
struct Scsi_Host * scsi_register(Scsi_Host_Template *shost_tp, int xtr_bytes)
Linus Torvalds's avatar
Linus Torvalds committed
339
{
340 341 342 343 344 345 346 347 348
	struct Scsi_Host *shost, *shost_scr;
	Scsi_Host_Name *shost_name = NULL;
	Scsi_Host_Name *shn = NULL;
	char *hname;
	size_t hname_len;
	struct list_head *lh;
	int gfp_mask;
	DECLARE_MUTEX_LOCKED(sem);

349 350 351 352 353 354 355 356 357 358 359 360 361
	/*
	 * Determine host number. Check reserved first before allocating
	 * new one
	 */
	hname = (shost_tp->proc_name) ?  shost_tp->proc_name : "";
	hname_len = strlen(hname);

        /* Check to see if this host has any error handling facilities */
        if(shost_tp->eh_strategy_handler == NULL &&
           shost_tp->eh_abort_handler == NULL &&
           shost_tp->eh_device_reset_handler == NULL &&
           shost_tp->eh_bus_reset_handler == NULL &&
           shost_tp->eh_host_reset_handler == NULL) {
362 363
		printk(KERN_ERR "ERROR: SCSI host `%s' has no error handling\nERROR: This is not a safe way to run your SCSI host\nERROR: The error handling must be added to this driver\n", hname);
		dump_stack();
364
        } 
365 366 367 368 369 370 371 372
	gfp_mask = GFP_KERNEL;
	if (shost_tp->unchecked_isa_dma && xtr_bytes)
		gfp_mask |= __GFP_DMA;

	shost = kmalloc(sizeof(struct Scsi_Host) + xtr_bytes, gfp_mask);
	if (!shost) {
		printk(KERN_ERR "%s: out of memory.\n", __FUNCTION__);
		return NULL;
Linus Torvalds's avatar
Linus Torvalds committed
373
	}
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392

	memset(shost, 0, sizeof(struct Scsi_Host) + xtr_bytes);

	if (hname_len)
		list_for_each(lh, &scsi_host_hn_list) {
			shn = list_entry(lh, Scsi_Host_Name, shn_list);
			if (!(shn->host_registered) &&
			    !strncmp(hname, shn->name, hname_len)) {
				shost_name = shn;
				break;
			}
		}

	if (!shost_name) {
		shost_name = scsi_host_hn_add(hname);
		if (!shost_name) {
			kfree(shost);
			return NULL;
		}
Linus Torvalds's avatar
Linus Torvalds committed
393
	}
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418

	shost->host_no = shost_name->host_no;
	shost_name->host_registered = 1;
	scsi_hosts_registered++;

	spin_lock_init(&shost->default_lock);
	scsi_assign_lock(shost, &shost->default_lock);
	atomic_set(&shost->host_active,0);

	init_waitqueue_head(&shost->host_wait);
	shost->dma_channel = 0xff;

	/* These three are default values which can be overridden */
	shost->max_channel = 0;
	shost->max_id = 8;
	shost->max_lun = 8;

	/*
	 * All drivers right now should be able to handle 12 byte
	 * commands.  Every so often there are requests for 16 byte
	 * commands, but individual low-level drivers need to certify that
	 * they actually do something sensible with such commands.
	 */
	shost->max_cmd_len = 12;
	shost->hostt = shost_tp;
419
	shost->host_blocked = 0;
420
	shost->host_self_blocked = FALSE;
421
	shost->max_host_blocked = shost_tp->max_host_blocked ? shost_tp->max_host_blocked : SCSI_DEFAULT_HOST_BLOCKED;
Linus Torvalds's avatar
Linus Torvalds committed
422 423

#ifdef DEBUG
424 425
	printk("%s: %x %x: %d\n", __FUNCTION_ (int)shost,
	       (int)shost->hostt, xtr_bytes);
Linus Torvalds's avatar
Linus Torvalds committed
426 427
#endif

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
	/*
	 * The next six are the default values which can be overridden if
	 * need be
	 */
	shost->this_id = shost_tp->this_id;
	shost->can_queue = shost_tp->can_queue;
	shost->sg_tablesize = shost_tp->sg_tablesize;
	shost->cmd_per_lun = shost_tp->cmd_per_lun;
	shost->unchecked_isa_dma = shost_tp->unchecked_isa_dma;
	shost->use_clustering = shost_tp->use_clustering;
	if (!blk_nohighio)
	shost->highmem_io = shost_tp->highmem_io;

	shost->max_sectors = shost_tp->max_sectors;
	shost->use_blk_tcq = shost_tp->use_blk_tcq;

	spin_lock(&scsi_host_list_lock);
	/*
	 * FIXME When device naming is complete remove this step that
	 * orders the scsi_host_list by host number and just do a
	 * list_add_tail.
	 */
	list_for_each(lh, &scsi_host_list) {
		shost_scr = list_entry(lh, struct Scsi_Host, sh_list);
		if (shost->host_no < shost_scr->host_no) {
			__list_add(&shost->sh_list, shost_scr->sh_list.prev,
				   &shost_scr->sh_list);
			goto found;
		}
Linus Torvalds's avatar
Linus Torvalds committed
457
	}
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
	list_add_tail(&shost->sh_list, &scsi_host_list);
found:
	spin_unlock(&scsi_host_list_lock);

#ifdef CONFIG_PROC_FS
	/* Add the new driver to /proc/scsi if not already there */
	if (!shost_tp->proc_dir)
		scsi_proc_host_mkdir(shost_tp);
	scsi_proc_host_add(shost);
#endif

	strncpy(shost->host_driverfs_dev.name, shost_tp->proc_name,
		DEVICE_NAME_SIZE-1);
	sprintf(shost->host_driverfs_dev.bus_id, "scsi%d",
		shost->host_no);

	shost->eh_notify = &sem;
	kernel_thread((int (*)(void *)) scsi_error_handler, (void *) shost, 0);
	/*
	 * Now wait for the kernel error thread to initialize itself
	 * as it might be needed when we scan the bus.
	 */
	down(&sem);
	shost->eh_notify = NULL;

	shost->hostt->present++;

	return shost;
}

/**
 * scsi_register_host - register a low level host driver
 * @shost_tp:	pointer to a scsi host driver template
 *
 * Return value:
 * 	0 on Success / 1 on Failure.
 **/
int scsi_register_host(Scsi_Host_Template *shost_tp)
{
	struct Scsi_Host *shost;
498
	int cur_cnt;
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525

	/*
	 * Check no detect routine.
	 */
	if (!shost_tp->detect)
		return 1;

	/* If max_sectors isn't set, default to max */
	if (!shost_tp->max_sectors)
		shost_tp->max_sectors = 1024;

	cur_cnt = scsi_hosts_registered;

	MOD_INC_USE_COUNT;

	/*
	 * The detect routine must carefully spinunlock/spinlock if it
	 * enables interrupts, since all interrupt handlers do spinlock as
	 * well.
	 */

	/*
	 * detect should do its own locking
	 * FIXME present is now set is scsi_register which breaks manual
	 * registration code below.
	 */
	shost_tp->detect(shost_tp);
526 527 528 529 530 531 532 533 534
	if (!shost_tp->present)
		return 0;

	if (cur_cnt == scsi_hosts_registered) {
		if (shost_tp->present > 1) {
			printk(KERN_ERR "scsi: Failure to register"
			       "low-level scsi driver");
			scsi_unregister_host(shost_tp);
			return 1;
535 536 537
		}

		/*
538 539 540 541
		 * The low-level driver failed to register a driver.
		 * We can do this now.
		 *
	 	 * XXX Who needs manual registration and why???
542
		 */
543 544 545 546
		if (!scsi_register(shost_tp, 0)) {
			printk(KERN_ERR "scsi: register failed.\n");
			scsi_unregister_host(shost_tp);
			return 1;
547 548 549
		}
	}

550 551 552 553 554 555 556 557 558 559
	
	/*
	 * XXX(hch) use scsi_tp_for_each_host() once it propagates
	 *	    error returns properly.
	 */
	list_for_each_entry(shost, &scsi_host_list, sh_list)
		if (shost->hostt == shost_tp)
			if (scsi_add_host(shost))
				goto out_of_space;

560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
	return 0;

out_of_space:
	scsi_unregister_host(shost_tp); /* easiest way to clean up?? */
	return 1;
}

/**
 * scsi_unregister_host - unregister a low level host adapter driver
 * @shost_tp:	scsi host template to unregister.
 *
 * Description:
 * 	Similarly, this entry point should be called by a loadable module
 * 	if it is trying to remove a low level scsi driver from the system.
 *
 * Return value:
 * 	0 on Success / 1 on Failure
 *
 * Notes:
 * 	rmmod does not care what we return here the module will be
 * 	removed.
 **/
int scsi_unregister_host(Scsi_Host_Template *shost_tp)
{
	int pcount;

	/* get the big kernel lock, so we don't race with open() */
	lock_kernel();

	pcount = scsi_hosts_registered;

591
	scsi_tp_for_each_host(shost_tp, scsi_remove_legacy_host);
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709

	if (pcount != scsi_hosts_registered)
		printk(KERN_INFO "scsi : %d host%s left.\n", scsi_hosts_registered,
		       (scsi_hosts_registered == 1) ? "" : "s");

	MOD_DEC_USE_COUNT;

	unlock_kernel();
	return 0;

}

/**
 * *scsi_host_get_next - get scsi host and inc ref count
 * @shost:	pointer to a Scsi_Host or NULL to start.
 *
 * Return value:
 * 	A pointer to next Scsi_Host in list or NULL.
 **/
struct Scsi_Host *scsi_host_get_next(struct Scsi_Host *shost)
{
	struct list_head *lh = NULL;

	spin_lock(&scsi_host_list_lock);
	if (shost) {
		/* XXX Dec ref on cur shost */
		lh = shost->sh_list.next;
	} else {
		lh = scsi_host_list.next;
	}

	if (lh == &scsi_host_list) {
		shost = (struct Scsi_Host *)NULL;
		goto done;
	}

	shost = list_entry(lh, struct Scsi_Host, sh_list);
	/* XXX Inc ref count */

done:
	spin_unlock(&scsi_host_list_lock);
	return shost;
}

/**
 * scsi_host_hn_get - get a Scsi_Host by host no and inc ref count
 * @host_no:	host number to locate
 *
 * Return value:
 * 	A pointer to located Scsi_Host or NULL.
 **/
struct Scsi_Host *scsi_host_hn_get(unsigned short host_no)
{
	struct list_head *lh;
	struct Scsi_Host *shost;

	spin_lock(&scsi_host_list_lock);
	list_for_each(lh, &scsi_host_list) {
		shost = list_entry(lh, struct Scsi_Host, sh_list);
		if (shost->host_no == host_no) {
			/* XXX Inc ref count */
			goto done;
		}
	}

	shost = (struct Scsi_Host *)NULL;
done:
	spin_unlock(&scsi_host_list_lock);
	return shost;
}

/**
 * *scsi_host_put - dec a Scsi_Host ref count
 * @shost:	Pointer to Scsi_Host to dec.
 **/
void scsi_host_put(struct Scsi_Host *shost)
{

	/* XXX Get list lock */
	/* XXX dec ref count */
	/* XXX Release list lock */
	return;
}

/**
 * scsi_host_hn_init - init scsi host number list from string
 * @shost_hn:	string of scsi host driver names.
 **/
void __init scsi_host_hn_init(char *shost_hn)
{
	char *temp = shost_hn;

	while (temp) {
		while (*temp && (*temp != ':') && (*temp != ','))
			temp++;
		if (!*temp)
			temp = NULL;
		else
			*temp++ = 0;
		(void)scsi_host_hn_add(shost_hn);
		shost_hn = temp;
	}
}

/**
 * scsi_host_no_release - free all entries in scsi host number list
 **/
void __exit scsi_host_hn_release()
{
	struct list_head *lh, *next;
	Scsi_Host_Name *shn;

	list_for_each_safe(lh, next, &scsi_host_hn_list) {
		shn = list_entry(lh, Scsi_Host_Name, shn_list);
		if (shn->name)
			kfree(shn->name);
		kfree(shn);
	}
Linus Torvalds's avatar
Linus Torvalds committed
710 711
}

712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
void scsi_host_busy_inc(struct Scsi_Host *shost, Scsi_Device *sdev)
{
	unsigned long flags;

	spin_lock_irqsave(shost->host_lock, flags);
	shost->host_busy++;
	sdev->device_busy++;
	spin_unlock_irqrestore(shost->host_lock, flags);
}

void scsi_host_busy_dec_and_test(struct Scsi_Host *shost, Scsi_Device *sdev)
{
	unsigned long flags;

	spin_lock_irqsave(shost->host_lock, flags);
	shost->host_busy--;
	sdev->device_busy--;
	if (shost->in_recovery && (shost->host_busy == shost->host_failed)) {
		up(shost->eh_wait);
		SCSI_LOG_ERROR_RECOVERY(5, printk("Waking error handler"
732
					  " thread\n"));
733 734 735 736 737 738 739 740 741 742 743 744 745 746
	}
	spin_unlock_irqrestore(shost->host_lock, flags);
}

void scsi_host_failed_inc_and_test(struct Scsi_Host *shost)
{
	unsigned long flags;

	spin_lock_irqsave(shost->host_lock, flags);
	shost->in_recovery = 1;
	shost->host_failed++;
	if (shost->host_busy == shost->host_failed) {
		up(shost->eh_wait);
		SCSI_LOG_ERROR_RECOVERY(5, printk("Waking error handler"
747
					  " thread\n"));
748 749 750 751
	}
	spin_unlock_irqrestore(shost->host_lock, flags);
}

Linus Torvalds's avatar
Linus Torvalds committed
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
/*
 * Overrides for Emacs so that we follow Linus's tabbing style.
 * Emacs will notice this stuff at the end of the file and automatically
 * adjust the settings for this buffer only.  This must remain at the end
 * of the file.
 * ---------------------------------------------------------------------------
 * Local variables:
 * c-indent-level: 4
 * c-brace-imaginary-offset: 0
 * c-brace-offset: -4
 * c-argdecl-indent: 4
 * c-label-offset: -4
 * c-continued-statement-offset: 4
 * c-continued-brace-offset: 0
 * indent-tabs-mode: nil
 * tab-width: 8
 * End:
 */