ap_bus.c 47.7 KB
Newer Older
1
/*
2
 * Copyright IBM Corp. 2006, 2012
3 4 5
 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
 *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
 *	      Ralph Wuerthner <rwuerthn@de.ibm.com>
F
Felix Beck 已提交
6
 *	      Felix Beck <felix.beck@de.ibm.com>
7
 *	      Holger Dengler <hd@linux.vnet.ibm.com>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * Adjunct processor bus.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

26 27 28
#define KMSG_COMPONENT "ap"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt

29
#include <linux/kernel_stat.h>
30 31 32 33 34 35
#include <linux/module.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/workqueue.h>
36
#include <linux/slab.h>
37 38 39
#include <linux/notifier.h>
#include <linux/kthread.h>
#include <linux/mutex.h>
40
#include <linux/suspend.h>
41
#include <asm/reset.h>
F
Felix Beck 已提交
42
#include <asm/airq.h>
A
Arun Sharma 已提交
43
#include <linux/atomic.h>
F
Felix Beck 已提交
44
#include <asm/isc.h>
45 46
#include <linux/hrtimer.h>
#include <linux/ktime.h>
47
#include <asm/facility.h>
48
#include <linux/crypto.h>
49 50 51

#include "ap_bus.h"

52
/*
53 54 55
 * Module description.
 */
MODULE_AUTHOR("IBM Corporation");
56 57
MODULE_DESCRIPTION("Adjunct Processor Bus driver, " \
		   "Copyright IBM Corp. 2006, 2012");
58
MODULE_LICENSE("GPL");
59
MODULE_ALIAS_CRYPTO("z90crypt");
60

61
/*
62 63 64
 * Module parameter
 */
int ap_domain_index = -1;	/* Adjunct Processor Domain Index */
65
module_param_named(domain, ap_domain_index, int, S_IRUSR|S_IRGRP);
66 67 68
MODULE_PARM_DESC(domain, "domain index for ap devices");
EXPORT_SYMBOL(ap_domain_index);

69
static int ap_thread_flag = 0;
70
module_param_named(poll_thread, ap_thread_flag, int, S_IRUSR|S_IRGRP);
71
MODULE_PARM_DESC(poll_thread, "Turn on/off poll thread, default is 0 (off).");
72 73

static struct device *ap_root_device = NULL;
74
static struct ap_config_info *ap_configuration;
75
static DEFINE_SPINLOCK(ap_device_list_lock);
76
static LIST_HEAD(ap_device_list);
77
static bool initialised;
78

79
/*
80
 * Workqueue timer for bus rescan.
81 82 83
 */
static struct timer_list ap_config_timer;
static int ap_config_time = AP_CONFIG_TIME;
84
static void ap_scan_bus(struct work_struct *);
85
static DECLARE_WORK(ap_scan_work, ap_scan_bus);
86

87
/*
F
Felix Beck 已提交
88
 * Tasklet & timer for AP request polling and interrupts
89
 */
90 91
static void ap_tasklet_fn(unsigned long);
static DECLARE_TASKLET(ap_tasklet, ap_tasklet_fn, 0);
92 93 94 95
static atomic_t ap_poll_requests = ATOMIC_INIT(0);
static DECLARE_WAIT_QUEUE_HEAD(ap_poll_wait);
static struct task_struct *ap_poll_kthread = NULL;
static DEFINE_MUTEX(ap_poll_thread_mutex);
96
static DEFINE_SPINLOCK(ap_poll_timer_lock);
97 98 99 100
static struct hrtimer ap_poll_timer;
/* In LPAR poll with 4kHz frequency. Poll every 250000 nanoseconds.
 * If z/VM change to 1500000 nanoseconds to adjust to z/VM polling.*/
static unsigned long long poll_timeout = 250000;
101

102 103
/* Suspend flag */
static int ap_suspend_flag;
104 105
/* Maximum domain id */
static int ap_max_domain_id;
106 107 108 109
/* Flag to check if domain was set through module parameter domain=. This is
 * important when supsend and resume is done in a z/VM environment where the
 * domain might change. */
static int user_set_domain = 0;
110 111
static struct bus_type ap_bus_type;

112
/* Adapter interrupt definitions */
113 114
static void ap_interrupt_handler(struct airq_struct *airq);

115 116 117 118 119 120 121
static int ap_airq_flag;

static struct airq_struct ap_airq = {
	.handler = ap_interrupt_handler,
	.isc = AP_ISC,
};

F
Felix Beck 已提交
122 123 124 125 126 127
/**
 * ap_using_interrupts() - Returns non-zero if interrupt support is
 * available.
 */
static inline int ap_using_interrupts(void)
{
128
	return ap_airq_flag;
F
Felix Beck 已提交
129 130
}

131
/**
132
 * ap_intructions_available() - Test if AP instructions are available.
133
 *
134
 * Returns 0 if the AP instructions are installed.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
 */
static inline int ap_instructions_available(void)
{
	register unsigned long reg0 asm ("0") = AP_MKQID(0,0);
	register unsigned long reg1 asm ("1") = -ENODEV;
	register unsigned long reg2 asm ("2") = 0UL;

	asm volatile(
		"   .long 0xb2af0000\n"		/* PQAP(TAPQ) */
		"0: la    %1,0\n"
		"1:\n"
		EX_TABLE(0b, 1b)
		: "+d" (reg0), "+d" (reg1), "+d" (reg2) : : "cc" );
	return reg1;
}

F
Felix Beck 已提交
151 152 153 154 155 156 157
/**
 * ap_interrupts_available(): Test if AP interrupts are available.
 *
 * Returns 1 if AP interrupts are available.
 */
static int ap_interrupts_available(void)
{
158
	return test_facility(65);
F
Felix Beck 已提交
159 160
}

161 162 163 164 165 166 167 168
/**
 * ap_configuration_available(): Test if AP configuration
 * information is available.
 *
 * Returns 1 if AP configuration information is available.
 */
static int ap_configuration_available(void)
{
169
	return test_facility(12);
170 171
}

172
/**
173 174
 * ap_test_queue(): Test adjunct processor queue.
 * @qid: The AP queue number
175
 * @info: Pointer to queue descriptor
176
 *
177
 * Returns AP queue status structure.
178 179
 */
static inline struct ap_queue_status
180
ap_test_queue(ap_qid_t qid, unsigned long *info)
181 182 183 184 185
{
	register unsigned long reg0 asm ("0") = qid;
	register struct ap_queue_status reg1 asm ("1");
	register unsigned long reg2 asm ("2") = 0UL;

186 187
	if (test_facility(15))
		reg0 |= 1UL << 23;		/* set APFT T bit*/
188 189
	asm volatile(".long 0xb2af0000"		/* PQAP(TAPQ) */
		     : "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
190 191
	if (info)
		*info = reg2;
192 193 194 195
	return reg1;
}

/**
196 197
 * ap_reset_queue(): Reset adjunct processor queue.
 * @qid: The AP queue number
198
 *
199
 * Returns AP queue status structure.
200 201 202 203 204 205 206 207 208 209 210 211 212
 */
static inline struct ap_queue_status ap_reset_queue(ap_qid_t qid)
{
	register unsigned long reg0 asm ("0") = qid | 0x01000000UL;
	register struct ap_queue_status reg1 asm ("1");
	register unsigned long reg2 asm ("2") = 0UL;

	asm volatile(
		".long 0xb2af0000"		/* PQAP(RAPQ) */
		: "+d" (reg0), "=d" (reg1), "+d" (reg2) : : "cc");
	return reg1;
}

F
Felix Beck 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
/**
 * ap_queue_interruption_control(): Enable interruption for a specific AP.
 * @qid: The AP queue number
 * @ind: The notification indicator byte
 *
 * Returns AP queue status.
 */
static inline struct ap_queue_status
ap_queue_interruption_control(ap_qid_t qid, void *ind)
{
	register unsigned long reg0 asm ("0") = qid | 0x03000000UL;
	register unsigned long reg1_in asm ("1") = 0x0000800000000000UL | AP_ISC;
	register struct ap_queue_status reg1_out asm ("1");
	register void *reg2 asm ("2") = ind;
	asm volatile(
228
		".long 0xb2af0000"		/* PQAP(AQIC) */
F
Felix Beck 已提交
229 230 231 232 233 234
		: "+d" (reg0), "+d" (reg1_in), "=d" (reg1_out), "+d" (reg2)
		:
		: "cc" );
	return reg1_out;
}

235 236 237 238 239 240
/**
 * ap_query_configuration(): Get AP configuration data
 *
 * Returns 0 on success, or -EOPNOTSUPP.
 */
static inline int ap_query_configuration(void)
241 242 243
{
	register unsigned long reg0 asm ("0") = 0x04000000UL;
	register unsigned long reg1 asm ("1") = -EINVAL;
244
	register void *reg2 asm ("2") = (void *) ap_configuration;
245

246 247
	if (!ap_configuration)
		return -EOPNOTSUPP;
248 249 250 251 252 253 254 255 256 257 258 259
	asm volatile(
		".long 0xb2af0000\n"		/* PQAP(QCI) */
		"0: la    %1,0\n"
		"1:\n"
		EX_TABLE(0b, 1b)
		: "+d" (reg0), "+d" (reg1), "+d" (reg2)
		:
		: "cc");

	return reg1;
}

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
/**
 * ap_init_configuration(): Allocate and query configuration array.
 */
static void ap_init_configuration(void)
{
	if (!ap_configuration_available())
		return;

	ap_configuration = kzalloc(sizeof(*ap_configuration), GFP_KERNEL);
	if (!ap_configuration)
		return;
	if (ap_query_configuration() != 0) {
		kfree(ap_configuration);
		ap_configuration = NULL;
		return;
	}
}

/*
 * ap_test_config(): helper function to extract the nrth bit
 *		     within the unsigned int array field.
 */
static inline int ap_test_config(unsigned int *field, unsigned int nr)
{
	return ap_test_bit((field + (nr >> 5)), (nr & 0x1f));
}

/*
 * ap_test_config_card_id(): Test, whether an AP card ID is configured.
 * @id AP card ID
 *
 * Returns 0 if the card is not configured
 *	   1 if the card is configured or
 *	     if the configuration information is not available
 */
static inline int ap_test_config_card_id(unsigned int id)
{
	if (!ap_configuration)	/* QCI not supported */
		return 1;
	return ap_test_config(ap_configuration->apm, id);
}

/*
 * ap_test_config_domain(): Test, whether an AP usage domain is configured.
 * @domain AP usage domain ID
 *
 * Returns 0 if the usage domain is not configured
 *	   1 if the usage domain is configured or
 *	     if the configuration information is not available
 */
static inline int ap_test_config_domain(unsigned int domain)
{
	if (!ap_configuration)	/* QCI not supported */
		return domain < 16;
	return ap_test_config(ap_configuration->aqm, domain);
}

F
Felix Beck 已提交
317 318 319 320 321 322 323 324 325
/**
 * ap_queue_enable_interruption(): Enable interruption on an AP.
 * @qid: The AP queue number
 * @ind: the notification indicator byte
 *
 * Enables interruption on AP queue via ap_queue_interruption_control(). Based
 * on the return value it waits a while and tests the AP queue if interrupts
 * have been switched on using ap_test_queue().
 */
326
static int ap_queue_enable_interruption(struct ap_device *ap_dev, void *ind)
F
Felix Beck 已提交
327 328 329
{
	struct ap_queue_status status;

330 331 332 333 334 335 336 337 338
	status = ap_queue_interruption_control(ap_dev->qid, ind);
	switch (status.response_code) {
	case AP_RESPONSE_NORMAL:
	case AP_RESPONSE_OTHERWISE_CHANGED:
		return 0;
	case AP_RESPONSE_Q_NOT_AVAIL:
	case AP_RESPONSE_DECONFIGURED:
	case AP_RESPONSE_CHECKSTOPPED:
	case AP_RESPONSE_INVALID_ADDRESS:
339 340 341
		pr_err("Registering adapter interrupts for AP %d failed\n",
		       AP_QID_DEVICE(ap_dev->qid));
		return -EOPNOTSUPP;
342 343 344 345
	case AP_RESPONSE_RESET_IN_PROGRESS:
	case AP_RESPONSE_BUSY:
	default:
		return -EBUSY;
F
Felix Beck 已提交
346 347 348
	}
}

349
/**
350 351 352 353 354
 * __ap_send(): Send message to adjunct processor queue.
 * @qid: The AP queue number
 * @psmid: The program supplied message identifier
 * @msg: The message text
 * @length: The message length
355
 * @special: Special Bit
356
 *
357
 * Returns AP queue status structure.
358 359 360 361 362
 * Condition code 1 on NQAP can't happen because the L bit is 1.
 * Condition code 2 on NQAP also means the send is incomplete,
 * because a segment boundary was reached. The NQAP is repeated.
 */
static inline struct ap_queue_status
363 364
__ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length,
	  unsigned int special)
365 366 367 368 369 370 371
{
	typedef struct { char _[length]; } msgblock;
	register unsigned long reg0 asm ("0") = qid | 0x40000000UL;
	register struct ap_queue_status reg1 asm ("1");
	register unsigned long reg2 asm ("2") = (unsigned long) msg;
	register unsigned long reg3 asm ("3") = (unsigned long) length;
	register unsigned long reg4 asm ("4") = (unsigned int) (psmid >> 32);
372
	register unsigned long reg5 asm ("5") = psmid & 0xffffffff;
373

374 375 376
	if (special == 1)
		reg0 |= 0x400000UL;

377
	asm volatile (
378
		"0: .long 0xb2ad0042\n"		/* NQAP */
379 380 381 382 383 384 385 386 387 388 389
		"   brc   2,0b"
		: "+d" (reg0), "=d" (reg1), "+d" (reg2), "+d" (reg3)
		: "d" (reg4), "d" (reg5), "m" (*(msgblock *) msg)
		: "cc" );
	return reg1;
}

int ap_send(ap_qid_t qid, unsigned long long psmid, void *msg, size_t length)
{
	struct ap_queue_status status;

390
	status = __ap_send(qid, psmid, msg, length, 0);
391 392 393 394
	switch (status.response_code) {
	case AP_RESPONSE_NORMAL:
		return 0;
	case AP_RESPONSE_Q_FULL:
395
	case AP_RESPONSE_RESET_IN_PROGRESS:
396
		return -EBUSY;
397 398
	case AP_RESPONSE_REQ_FAC_NOT_INST:
		return -EINVAL;
399 400 401 402 403 404
	default:	/* Device is gone. */
		return -ENODEV;
	}
}
EXPORT_SYMBOL(ap_send);

405 406 407 408 409 410
/**
 * __ap_recv(): Receive message from adjunct processor queue.
 * @qid: The AP queue number
 * @psmid: Pointer to program supplied message identifier
 * @msg: The message text
 * @length: The message length
411
 *
412
 * Returns AP queue status structure.
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
 * Condition code 1 on DQAP means the receive has taken place
 * but only partially.	The response is incomplete, hence the
 * DQAP is repeated.
 * Condition code 2 on DQAP also means the receive is incomplete,
 * this time because a segment boundary was reached. Again, the
 * DQAP is repeated.
 * Note that gpr2 is used by the DQAP instruction to keep track of
 * any 'residual' length, in case the instruction gets interrupted.
 * Hence it gets zeroed before the instruction.
 */
static inline struct ap_queue_status
__ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
{
	typedef struct { char _[length]; } msgblock;
	register unsigned long reg0 asm("0") = qid | 0x80000000UL;
	register struct ap_queue_status reg1 asm ("1");
	register unsigned long reg2 asm("2") = 0UL;
	register unsigned long reg4 asm("4") = (unsigned long) msg;
	register unsigned long reg5 asm("5") = (unsigned long) length;
	register unsigned long reg6 asm("6") = 0UL;
	register unsigned long reg7 asm("7") = 0UL;


	asm volatile(
437
		"0: .long 0xb2ae0064\n"		/* DQAP */
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
		"   brc   6,0b\n"
		: "+d" (reg0), "=d" (reg1), "+d" (reg2),
		"+d" (reg4), "+d" (reg5), "+d" (reg6), "+d" (reg7),
		"=m" (*(msgblock *) msg) : : "cc" );
	*psmid = (((unsigned long long) reg6) << 32) + reg7;
	return reg1;
}

int ap_recv(ap_qid_t qid, unsigned long long *psmid, void *msg, size_t length)
{
	struct ap_queue_status status;

	status = __ap_recv(qid, psmid, msg, length);
	switch (status.response_code) {
	case AP_RESPONSE_NORMAL:
		return 0;
	case AP_RESPONSE_NO_PENDING_REPLY:
		if (status.queue_empty)
			return -ENOENT;
		return -EBUSY;
458 459
	case AP_RESPONSE_RESET_IN_PROGRESS:
		return -EBUSY;
460 461 462 463 464 465 466
	default:
		return -ENODEV;
	}
}
EXPORT_SYMBOL(ap_recv);

/**
467 468 469 470
 * ap_query_queue(): Check if an AP queue is available.
 * @qid: The AP queue number
 * @queue_depth: Pointer to queue depth value
 * @device_type: Pointer to device type value
471
 * @facilities: Pointer to facility indicator
472
 */
473 474
static int ap_query_queue(ap_qid_t qid, int *queue_depth, int *device_type,
			  unsigned int *facilities)
475 476
{
	struct ap_queue_status status;
477
	unsigned long info;
478 479 480 481
	int nd;

	if (!ap_test_config_card_id(AP_QID_DEVICE(qid)))
		return -ENODEV;
482

483
	status = ap_test_queue(qid, &info);
484 485
	switch (status.response_code) {
	case AP_RESPONSE_NORMAL:
486 487 488
		*queue_depth = (int)(info & 0xff);
		*device_type = (int)((info >> 24) & 0xff);
		*facilities = (unsigned int)(info >> 32);
489 490 491 492
		/* Update maximum domain id */
		nd = (info >> 16) & 0xff;
		if ((info & (1UL << 57)) && nd > 0)
			ap_max_domain_id = nd;
493 494 495 496 497 498 499 500 501 502 503 504
		return 0;
	case AP_RESPONSE_Q_NOT_AVAIL:
	case AP_RESPONSE_DECONFIGURED:
	case AP_RESPONSE_CHECKSTOPPED:
	case AP_RESPONSE_INVALID_ADDRESS:
		return -ENODEV;
	case AP_RESPONSE_RESET_IN_PROGRESS:
	case AP_RESPONSE_OTHERWISE_CHANGED:
	case AP_RESPONSE_BUSY:
		return -EBUSY;
	default:
		BUG();
505 506 507
	}
}

508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 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 591 592 593 594 595 596 597 598 599 600 601
/* State machine definitions and helpers */

static void ap_sm_wait(enum ap_wait wait)
{
	ktime_t hr_time;

	switch (wait) {
	case AP_WAIT_AGAIN:
	case AP_WAIT_INTERRUPT:
		if (ap_using_interrupts())
			break;
		if (ap_poll_kthread) {
			wake_up(&ap_poll_wait);
			break;
		}
		/* Fall through */
	case AP_WAIT_TIMEOUT:
		spin_lock_bh(&ap_poll_timer_lock);
		if (!hrtimer_is_queued(&ap_poll_timer)) {
			hr_time = ktime_set(0, poll_timeout);
			hrtimer_forward_now(&ap_poll_timer, hr_time);
			hrtimer_restart(&ap_poll_timer);
		}
		spin_unlock_bh(&ap_poll_timer_lock);
		break;
	case AP_WAIT_NONE:
	default:
		break;
	}
}

static enum ap_wait ap_sm_nop(struct ap_device *ap_dev)
{
	return AP_WAIT_NONE;
}

/**
 * ap_sm_recv(): Receive pending reply messages from an AP device but do
 *	not change the state of the device.
 * @ap_dev: pointer to the AP device
 *
 * Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
 */
static struct ap_queue_status ap_sm_recv(struct ap_device *ap_dev)
{
	struct ap_queue_status status;
	struct ap_message *ap_msg;

	status = __ap_recv(ap_dev->qid, &ap_dev->reply->psmid,
			   ap_dev->reply->message, ap_dev->reply->length);
	switch (status.response_code) {
	case AP_RESPONSE_NORMAL:
		atomic_dec(&ap_poll_requests);
		ap_dev->queue_count--;
		if (ap_dev->queue_count > 0)
			mod_timer(&ap_dev->timeout,
				  jiffies + ap_dev->drv->request_timeout);
		list_for_each_entry(ap_msg, &ap_dev->pendingq, list) {
			if (ap_msg->psmid != ap_dev->reply->psmid)
				continue;
			list_del_init(&ap_msg->list);
			ap_dev->pendingq_count--;
			ap_msg->receive(ap_dev, ap_msg, ap_dev->reply);
			break;
		}
	case AP_RESPONSE_NO_PENDING_REPLY:
		if (!status.queue_empty || ap_dev->queue_count <= 0)
			break;
		/* The card shouldn't forget requests but who knows. */
		atomic_sub(ap_dev->queue_count, &ap_poll_requests);
		ap_dev->queue_count = 0;
		list_splice_init(&ap_dev->pendingq, &ap_dev->requestq);
		ap_dev->requestq_count += ap_dev->pendingq_count;
		ap_dev->pendingq_count = 0;
		break;
	default:
		break;
	}
	return status;
}

/**
 * ap_sm_read(): Receive pending reply messages from an AP device.
 * @ap_dev: pointer to the AP device
 *
 * Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
 */
static enum ap_wait ap_sm_read(struct ap_device *ap_dev)
{
	struct ap_queue_status status;

	status = ap_sm_recv(ap_dev);
	switch (status.response_code) {
	case AP_RESPONSE_NORMAL:
602 603
		if (ap_dev->queue_count > 0) {
			ap_dev->state = AP_STATE_WORKING;
604
			return AP_WAIT_AGAIN;
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
		ap_dev->state = AP_STATE_IDLE;
		return AP_WAIT_NONE;
	case AP_RESPONSE_NO_PENDING_REPLY:
		if (ap_dev->queue_count > 0)
			return AP_WAIT_INTERRUPT;
		ap_dev->state = AP_STATE_IDLE;
		return AP_WAIT_NONE;
	default:
		ap_dev->state = AP_STATE_BORKED;
		return AP_WAIT_NONE;
	}
}

/**
 * ap_sm_write(): Send messages from the request queue to an AP device.
 * @ap_dev: pointer to the AP device
 *
 * Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
 */
static enum ap_wait ap_sm_write(struct ap_device *ap_dev)
{
	struct ap_queue_status status;
	struct ap_message *ap_msg;

	if (ap_dev->requestq_count <= 0)
		return AP_WAIT_NONE;
	/* Start the next request on the queue. */
	ap_msg = list_entry(ap_dev->requestq.next, struct ap_message, list);
	status = __ap_send(ap_dev->qid, ap_msg->psmid,
			   ap_msg->message, ap_msg->length, ap_msg->special);
	switch (status.response_code) {
	case AP_RESPONSE_NORMAL:
		atomic_inc(&ap_poll_requests);
		ap_dev->queue_count++;
		if (ap_dev->queue_count == 1)
			mod_timer(&ap_dev->timeout,
				  jiffies + ap_dev->drv->request_timeout);
		list_move_tail(&ap_msg->list, &ap_dev->pendingq);
		ap_dev->requestq_count--;
		ap_dev->pendingq_count++;
		if (ap_dev->queue_count < ap_dev->queue_depth) {
			ap_dev->state = AP_STATE_WORKING;
			return AP_WAIT_AGAIN;
		}
		/* fall through */
	case AP_RESPONSE_Q_FULL:
		ap_dev->state = AP_STATE_QUEUE_FULL;
		return AP_WAIT_INTERRUPT;
	case AP_RESPONSE_RESET_IN_PROGRESS:
		ap_dev->state = AP_STATE_RESET_WAIT;
		return AP_WAIT_TIMEOUT;
	case AP_RESPONSE_MESSAGE_TOO_BIG:
	case AP_RESPONSE_REQ_FAC_NOT_INST:
		list_del_init(&ap_msg->list);
		ap_dev->requestq_count--;
		ap_msg->rc = -EINVAL;
		ap_msg->receive(ap_dev, ap_msg, NULL);
		return AP_WAIT_AGAIN;
	default:
		ap_dev->state = AP_STATE_BORKED;
		return AP_WAIT_NONE;
	}
}

670
/**
671 672 673 674 675 676 677 678 679 680 681 682
 * ap_sm_read_write(): Send and receive messages to/from an AP device.
 * @ap_dev: pointer to the AP device
 *
 * Returns AP_WAIT_NONE, AP_WAIT_AGAIN, or AP_WAIT_INTERRUPT
 */
static enum ap_wait ap_sm_read_write(struct ap_device *ap_dev)
{
	return min(ap_sm_read(ap_dev), ap_sm_write(ap_dev));
}

/**
 * ap_sm_reset(): Reset an AP queue.
683 684
 * @qid: The AP queue number
 *
685
 * Submit the Reset command to an AP queue.
686
 */
687
static enum ap_wait ap_sm_reset(struct ap_device *ap_dev)
688 689 690
{
	struct ap_queue_status status;

691 692 693 694
	status = ap_reset_queue(ap_dev->qid);
	switch (status.response_code) {
	case AP_RESPONSE_NORMAL:
	case AP_RESPONSE_RESET_IN_PROGRESS:
695 696 697
		ap_dev->state = AP_STATE_RESET_WAIT;
		ap_dev->interrupt = AP_INTR_DISABLED;
		return AP_WAIT_TIMEOUT;
698
	case AP_RESPONSE_BUSY:
699
		return AP_WAIT_TIMEOUT;
700 701 702 703
	case AP_RESPONSE_Q_NOT_AVAIL:
	case AP_RESPONSE_DECONFIGURED:
	case AP_RESPONSE_CHECKSTOPPED:
	default:
704 705
		ap_dev->state = AP_STATE_BORKED;
		return AP_WAIT_NONE;
F
Felix Beck 已提交
706
	}
707 708
}

709
/**
710 711
 * ap_sm_reset_wait(): Test queue for completion of the reset operation
 * @ap_dev: pointer to the AP device
712
 *
713
 * Returns AP_POLL_IMMEDIATELY, AP_POLL_AFTER_TIMEROUT or 0.
714
 */
715
static enum ap_wait ap_sm_reset_wait(struct ap_device *ap_dev)
716
{
717 718
	struct ap_queue_status status;
	unsigned long info;
719

720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
	if (ap_dev->queue_count > 0)
		/* Try to read a completed message and get the status */
		status = ap_sm_recv(ap_dev);
	else
		/* Get the status with TAPQ */
		status = ap_test_queue(ap_dev->qid, &info);

	switch (status.response_code) {
	case AP_RESPONSE_NORMAL:
		if (ap_using_interrupts() &&
		    ap_queue_enable_interruption(ap_dev,
						 ap_airq.lsi_ptr) == 0)
			ap_dev->state = AP_STATE_SETIRQ_WAIT;
		else
			ap_dev->state = (ap_dev->queue_count > 0) ?
				AP_STATE_WORKING : AP_STATE_IDLE;
		return AP_WAIT_AGAIN;
	case AP_RESPONSE_BUSY:
	case AP_RESPONSE_RESET_IN_PROGRESS:
		return AP_WAIT_TIMEOUT;
	case AP_RESPONSE_Q_NOT_AVAIL:
	case AP_RESPONSE_DECONFIGURED:
	case AP_RESPONSE_CHECKSTOPPED:
	default:
		ap_dev->state = AP_STATE_BORKED;
		return AP_WAIT_NONE;
746 747 748 749
	}
}

/**
750 751
 * ap_sm_setirq_wait(): Test queue for completion of the irq enablement
 * @ap_dev: pointer to the AP device
752
 *
753
 * Returns AP_POLL_IMMEDIATELY, AP_POLL_AFTER_TIMEROUT or 0.
754
 */
755
static enum ap_wait ap_sm_setirq_wait(struct ap_device *ap_dev)
756
{
757 758
	struct ap_queue_status status;
	unsigned long info;
759 760

	if (ap_dev->queue_count > 0)
761 762
		/* Try to read a completed message and get the status */
		status = ap_sm_recv(ap_dev);
763
	else
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
		/* Get the status with TAPQ */
		status = ap_test_queue(ap_dev->qid, &info);

	if (status.int_enabled == 1) {
		/* Irqs are now enabled */
		ap_dev->interrupt = AP_INTR_ENABLED;
		ap_dev->state = (ap_dev->queue_count > 0) ?
			AP_STATE_WORKING : AP_STATE_IDLE;
	}

	switch (status.response_code) {
	case AP_RESPONSE_NORMAL:
		if (ap_dev->queue_count > 0)
			return AP_WAIT_AGAIN;
		/* fallthrough */
	case AP_RESPONSE_NO_PENDING_REPLY:
		return AP_WAIT_TIMEOUT;
	default:
		ap_dev->state = AP_STATE_BORKED;
		return AP_WAIT_NONE;
	}
}

/*
 * AP state machine jump table
 */
ap_func_t *ap_jumptable[NR_AP_STATES][NR_AP_EVENTS] = {
	[AP_STATE_RESET_START] = {
		[AP_EVENT_POLL] = ap_sm_reset,
		[AP_EVENT_TIMEOUT] = ap_sm_nop,
	},
	[AP_STATE_RESET_WAIT] = {
		[AP_EVENT_POLL] = ap_sm_reset_wait,
		[AP_EVENT_TIMEOUT] = ap_sm_nop,
	},
	[AP_STATE_SETIRQ_WAIT] = {
		[AP_EVENT_POLL] = ap_sm_setirq_wait,
		[AP_EVENT_TIMEOUT] = ap_sm_nop,
	},
	[AP_STATE_IDLE] = {
		[AP_EVENT_POLL] = ap_sm_write,
		[AP_EVENT_TIMEOUT] = ap_sm_nop,
	},
	[AP_STATE_WORKING] = {
		[AP_EVENT_POLL] = ap_sm_read_write,
		[AP_EVENT_TIMEOUT] = ap_sm_reset,
	},
	[AP_STATE_QUEUE_FULL] = {
		[AP_EVENT_POLL] = ap_sm_read,
		[AP_EVENT_TIMEOUT] = ap_sm_reset,
	},
	[AP_STATE_SUSPEND_WAIT] = {
		[AP_EVENT_POLL] = ap_sm_read,
		[AP_EVENT_TIMEOUT] = ap_sm_nop,
	},
	[AP_STATE_BORKED] = {
		[AP_EVENT_POLL] = ap_sm_nop,
		[AP_EVENT_TIMEOUT] = ap_sm_nop,
	},
};

static inline enum ap_wait ap_sm_event(struct ap_device *ap_dev,
				       enum ap_event event)
{
	return ap_jumptable[ap_dev->state][event](ap_dev);
}

static inline enum ap_wait ap_sm_event_loop(struct ap_device *ap_dev,
					    enum ap_event event)
{
	enum ap_wait wait;

	while ((wait = ap_sm_event(ap_dev, event)) == AP_WAIT_AGAIN)
		;
	return wait;
}

/**
 * ap_request_timeout(): Handling of request timeouts
 * @data: Holds the AP device.
 *
 * Handles request timeouts.
 */
static void ap_request_timeout(unsigned long data)
{
	struct ap_device *ap_dev = (struct ap_device *) data;

	if (ap_suspend_flag)
		return;
	spin_lock_bh(&ap_dev->lock);
	ap_sm_wait(ap_sm_event(ap_dev, AP_EVENT_TIMEOUT));
	spin_unlock_bh(&ap_dev->lock);
}

/**
 * ap_poll_timeout(): AP receive polling for finished AP requests.
 * @unused: Unused pointer.
 *
 * Schedules the AP tasklet using a high resolution timer.
 */
static enum hrtimer_restart ap_poll_timeout(struct hrtimer *unused)
{
	if (!ap_suspend_flag)
		tasklet_schedule(&ap_tasklet);
	return HRTIMER_NORESTART;
}

/**
 * ap_interrupt_handler() - Schedule ap_tasklet on interrupt
 * @airq: pointer to adapter interrupt descriptor
 */
static void ap_interrupt_handler(struct airq_struct *airq)
{
	inc_irq_stat(IRQIO_APB);
	if (!ap_suspend_flag)
		tasklet_schedule(&ap_tasklet);
}

/**
 * ap_tasklet_fn(): Tasklet to poll all AP devices.
 * @dummy: Unused variable
 *
 * Poll all AP devices on the bus.
 */
static void ap_tasklet_fn(unsigned long dummy)
{
	struct ap_device *ap_dev;
	enum ap_wait wait = AP_WAIT_NONE;

	/* Reset the indicator if interrupts are used. Thus new interrupts can
	 * be received. Doing it in the beginning of the tasklet is therefor
	 * important that no requests on any AP get lost.
	 */
	if (ap_using_interrupts())
		xchg(ap_airq.lsi_ptr, 0);

	spin_lock(&ap_device_list_lock);
	list_for_each_entry(ap_dev, &ap_device_list, list) {
		spin_lock_bh(&ap_dev->lock);
		wait = min(wait, ap_sm_event_loop(ap_dev, AP_EVENT_POLL));
		spin_unlock_bh(&ap_dev->lock);
	}
	spin_unlock(&ap_device_list_lock);
	ap_sm_wait(wait);
908 909
}

910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940
/**
 * ap_poll_thread(): Thread that polls for finished requests.
 * @data: Unused pointer
 *
 * AP bus poll thread. The purpose of this thread is to poll for
 * finished requests in a loop if there is a "free" cpu - that is
 * a cpu that doesn't have anything better to do. The polling stops
 * as soon as there is another task or if all messages have been
 * delivered.
 */
static int ap_poll_thread(void *data)
{
	DECLARE_WAITQUEUE(wait, current);

	set_user_nice(current, MAX_NICE);
	set_freezable();
	while (!kthread_should_stop()) {
		add_wait_queue(&ap_poll_wait, &wait);
		set_current_state(TASK_INTERRUPTIBLE);
		if (ap_suspend_flag ||
		    atomic_read(&ap_poll_requests) <= 0) {
			schedule();
			try_to_freeze();
		}
		set_current_state(TASK_RUNNING);
		remove_wait_queue(&ap_poll_wait, &wait);
		if (need_resched()) {
			schedule();
			try_to_freeze();
			continue;
		}
941
		ap_tasklet_fn(0);
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
	} while (!kthread_should_stop());
	return 0;
}

static int ap_poll_thread_start(void)
{
	int rc;

	if (ap_using_interrupts() || ap_poll_kthread)
		return 0;
	mutex_lock(&ap_poll_thread_mutex);
	ap_poll_kthread = kthread_run(ap_poll_thread, NULL, "appoll");
	rc = PTR_RET(ap_poll_kthread);
	if (rc)
		ap_poll_kthread = NULL;
	mutex_unlock(&ap_poll_thread_mutex);
	return rc;
}

static void ap_poll_thread_stop(void)
{
	if (!ap_poll_kthread)
		return;
	mutex_lock(&ap_poll_thread_mutex);
	kthread_stop(ap_poll_kthread);
	ap_poll_kthread = NULL;
	mutex_unlock(&ap_poll_thread_mutex);
}

971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
/**
 * ap_queue_message(): Queue a request to an AP device.
 * @ap_dev: The AP device to queue the message to
 * @ap_msg: The message that is to be added
 */
void ap_queue_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
{
	/* For asynchronous message handling a valid receive-callback
	 * is required. */
	BUG_ON(!ap_msg->receive);

	spin_lock_bh(&ap_dev->lock);
	/* Queue the message. */
	list_add_tail(&ap_msg->list, &ap_dev->requestq);
	ap_dev->requestq_count++;
	ap_dev->total_request_count++;
	/* Send/receive as many request from the queue as possible. */
	ap_sm_wait(ap_sm_event_loop(ap_dev, AP_EVENT_POLL));
	spin_unlock_bh(&ap_dev->lock);
}
EXPORT_SYMBOL(ap_queue_message);

/**
 * ap_cancel_message(): Cancel a crypto request.
 * @ap_dev: The AP device that has the message queued
 * @ap_msg: The message that is to be removed
 *
 * Cancel a crypto request. This is done by removing the request
 * from the device pending or request queue. Note that the
 * request stays on the AP queue. When it finishes the message
 * reply will be discarded because the psmid can't be found.
 */
void ap_cancel_message(struct ap_device *ap_dev, struct ap_message *ap_msg)
{
	struct ap_message *tmp;

	spin_lock_bh(&ap_dev->lock);
	if (!list_empty(&ap_msg->list)) {
		list_for_each_entry(tmp, &ap_dev->pendingq, list)
			if (tmp->psmid == ap_msg->psmid) {
				ap_dev->pendingq_count--;
				goto found;
			}
		ap_dev->requestq_count--;
found:
		list_del_init(&ap_msg->list);
	}
	spin_unlock_bh(&ap_dev->lock);
}
EXPORT_SYMBOL(ap_cancel_message);

1022
/*
1023 1024 1025 1026 1027 1028 1029 1030 1031
 * AP device related attributes.
 */
static ssize_t ap_hwtype_show(struct device *dev,
			      struct device_attribute *attr, char *buf)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
	return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->device_type);
}

1032
static DEVICE_ATTR(hwtype, 0444, ap_hwtype_show, NULL);
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043

static ssize_t ap_raw_hwtype_show(struct device *dev,
			      struct device_attribute *attr, char *buf)
{
	struct ap_device *ap_dev = to_ap_dev(dev);

	return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->raw_hwtype);
}

static DEVICE_ATTR(raw_hwtype, 0444, ap_raw_hwtype_show, NULL);

1044 1045 1046 1047 1048 1049 1050
static ssize_t ap_depth_show(struct device *dev, struct device_attribute *attr,
			     char *buf)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
	return snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->queue_depth);
}

1051
static DEVICE_ATTR(depth, 0444, ap_depth_show, NULL);
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
static ssize_t ap_request_count_show(struct device *dev,
				     struct device_attribute *attr,
				     char *buf)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
	int rc;

	spin_lock_bh(&ap_dev->lock);
	rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->total_request_count);
	spin_unlock_bh(&ap_dev->lock);
	return rc;
}

static DEVICE_ATTR(request_count, 0444, ap_request_count_show, NULL);

1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
static ssize_t ap_requestq_count_show(struct device *dev,
				      struct device_attribute *attr, char *buf)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
	int rc;

	spin_lock_bh(&ap_dev->lock);
	rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->requestq_count);
	spin_unlock_bh(&ap_dev->lock);
	return rc;
}

static DEVICE_ATTR(requestq_count, 0444, ap_requestq_count_show, NULL);

static ssize_t ap_pendingq_count_show(struct device *dev,
				      struct device_attribute *attr, char *buf)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
	int rc;

	spin_lock_bh(&ap_dev->lock);
	rc = snprintf(buf, PAGE_SIZE, "%d\n", ap_dev->pendingq_count);
	spin_unlock_bh(&ap_dev->lock);
	return rc;
}

static DEVICE_ATTR(pendingq_count, 0444, ap_pendingq_count_show, NULL);

1095 1096 1097 1098 1099 1100 1101
static ssize_t ap_reset_show(struct device *dev,
				      struct device_attribute *attr, char *buf)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
	int rc = 0;

	spin_lock_bh(&ap_dev->lock);
1102 1103 1104 1105
	switch (ap_dev->state) {
	case AP_STATE_RESET_START:
	case AP_STATE_RESET_WAIT:
		rc = snprintf(buf, PAGE_SIZE, "Reset in progress.\n");
1106
		break;
1107 1108
	case AP_STATE_WORKING:
	case AP_STATE_QUEUE_FULL:
1109 1110 1111
		rc = snprintf(buf, PAGE_SIZE, "Reset Timer armed.\n");
		break;
	default:
1112
		rc = snprintf(buf, PAGE_SIZE, "No Reset Timer set.\n");
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
	}
	spin_unlock_bh(&ap_dev->lock);
	return rc;
}

static DEVICE_ATTR(reset, 0444, ap_reset_show, NULL);

static ssize_t ap_interrupt_show(struct device *dev,
				      struct device_attribute *attr, char *buf)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
	int rc = 0;

	spin_lock_bh(&ap_dev->lock);
1127
	if (ap_dev->state == AP_STATE_SETIRQ_WAIT)
1128
		rc = snprintf(buf, PAGE_SIZE, "Enable Interrupt pending.\n");
1129 1130 1131 1132
	else if (ap_dev->interrupt == AP_INTR_ENABLED)
		rc = snprintf(buf, PAGE_SIZE, "Interrupts enabled.\n");
	else
		rc = snprintf(buf, PAGE_SIZE, "Interrupts disabled.\n");
1133 1134 1135 1136 1137 1138
	spin_unlock_bh(&ap_dev->lock);
	return rc;
}

static DEVICE_ATTR(interrupt, 0444, ap_interrupt_show, NULL);

1139 1140 1141
static ssize_t ap_modalias_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{
1142
	return sprintf(buf, "ap:t%02X\n", to_ap_dev(dev)->device_type);
1143 1144 1145 1146
}

static DEVICE_ATTR(modalias, 0444, ap_modalias_show, NULL);

1147 1148 1149 1150 1151 1152 1153 1154 1155
static ssize_t ap_functions_show(struct device *dev,
				 struct device_attribute *attr, char *buf)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
	return snprintf(buf, PAGE_SIZE, "0x%08X\n", ap_dev->functions);
}

static DEVICE_ATTR(ap_functions, 0444, ap_functions_show, NULL);

1156 1157
static struct attribute *ap_dev_attrs[] = {
	&dev_attr_hwtype.attr,
1158
	&dev_attr_raw_hwtype.attr,
1159 1160
	&dev_attr_depth.attr,
	&dev_attr_request_count.attr,
1161 1162
	&dev_attr_requestq_count.attr,
	&dev_attr_pendingq_count.attr,
1163 1164
	&dev_attr_reset.attr,
	&dev_attr_interrupt.attr,
1165
	&dev_attr_modalias.attr,
1166
	&dev_attr_ap_functions.attr,
1167 1168 1169 1170 1171 1172 1173
	NULL
};
static struct attribute_group ap_dev_attr_group = {
	.attrs = ap_dev_attrs
};

/**
1174 1175 1176 1177
 * ap_bus_match()
 * @dev: Pointer to device
 * @drv: Pointer to device_driver
 *
1178 1179 1180 1181 1182 1183 1184 1185
 * AP bus driver registration/unregistration.
 */
static int ap_bus_match(struct device *dev, struct device_driver *drv)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
	struct ap_driver *ap_drv = to_ap_drv(drv);
	struct ap_device_id *id;

1186
	/*
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
	 * Compare device type of the device with the list of
	 * supported types of the device_driver.
	 */
	for (id = ap_drv->ids; id->match_flags; id++) {
		if ((id->match_flags & AP_DEVICE_ID_MATCH_DEVICE_TYPE) &&
		    (id->dev_type != ap_dev->device_type))
			continue;
		return 1;
	}
	return 0;
}

/**
1200 1201 1202 1203 1204 1205
 * ap_uevent(): Uevent function for AP devices.
 * @dev: Pointer to device
 * @env: Pointer to kobj_uevent_env
 *
 * It sets up a single environment variable DEV_TYPE which contains the
 * hardware device type.
1206
 */
1207
static int ap_uevent (struct device *dev, struct kobj_uevent_env *env)
1208 1209
{
	struct ap_device *ap_dev = to_ap_dev(dev);
1210
	int retval = 0;
1211 1212 1213 1214 1215

	if (!ap_dev)
		return -ENODEV;

	/* Set up DEV_TYPE environment variable. */
1216
	retval = add_uevent_var(env, "DEV_TYPE=%04X", ap_dev->device_type);
1217 1218 1219
	if (retval)
		return retval;

1220
	/* Add MODALIAS= */
1221
	retval = add_uevent_var(env, "MODALIAS=ap:t%02X", ap_dev->device_type);
1222 1223

	return retval;
1224 1225
}

1226
static int ap_dev_suspend(struct device *dev, pm_message_t state)
1227 1228 1229 1230
{
	struct ap_device *ap_dev = to_ap_dev(dev);

	/* Poll on the device until all requests are finished. */
1231 1232 1233 1234 1235 1236
	spin_lock_bh(&ap_dev->lock);
	ap_dev->state = AP_STATE_SUSPEND_WAIT;
	while (ap_sm_event(ap_dev, AP_EVENT_POLL) != AP_WAIT_NONE)
		;
	ap_dev->state = AP_STATE_BORKED;
	spin_unlock_bh(&ap_dev->lock);
1237 1238
	return 0;
}
1239

1240 1241
static int ap_dev_resume(struct device *dev)
{
1242 1243 1244
	return 0;
}

1245 1246 1247 1248 1249 1250 1251
static void ap_bus_suspend(void)
{
	ap_suspend_flag = 1;
	/*
	 * Disable scanning for devices, thus we do not want to scan
	 * for them after removing.
	 */
1252
	flush_work(&ap_scan_work);
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
	tasklet_disable(&ap_tasklet);
}

static int __ap_devices_unregister(struct device *dev, void *dummy)
{
	device_unregister(dev);
	return 0;
}

static void ap_bus_resume(void)
1263
{
1264
	int rc;
1265

1266 1267 1268 1269 1270 1271
	/* Unconditionally remove all AP devices */
	bus_for_each_dev(&ap_bus_type, NULL, NULL, __ap_devices_unregister);
	/* Reset thin interrupt setting */
	if (ap_interrupts_available() && !ap_using_interrupts()) {
		rc = register_adapter_interrupt(&ap_airq);
		ap_airq_flag = (rc == 0);
1272
	}
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
	if (!ap_interrupts_available() && ap_using_interrupts()) {
		unregister_adapter_interrupt(&ap_airq);
		ap_airq_flag = 0;
	}
	/* Reset domain */
	if (!user_set_domain)
		ap_domain_index = -1;
	/* Get things going again */
	ap_suspend_flag = 0;
	if (ap_airq_flag)
		xchg(ap_airq.lsi_ptr, 0);
	tasklet_enable(&ap_tasklet);
1285
	queue_work(system_long_wq, &ap_scan_work);
1286
}
1287

1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
static int ap_power_event(struct notifier_block *this, unsigned long event,
			  void *ptr)
{
	switch (event) {
	case PM_HIBERNATION_PREPARE:
	case PM_SUSPEND_PREPARE:
		ap_bus_suspend();
		break;
	case PM_POST_HIBERNATION:
	case PM_POST_SUSPEND:
		ap_bus_resume();
		break;
	default:
		break;
	}
	return NOTIFY_DONE;
1304
}
1305 1306 1307
static struct notifier_block ap_power_notifier = {
	.notifier_call = ap_power_event,
};
1308

1309 1310 1311 1312
static struct bus_type ap_bus_type = {
	.name = "ap",
	.match = &ap_bus_match,
	.uevent = &ap_uevent,
1313 1314
	.suspend = ap_dev_suspend,
	.resume = ap_dev_resume,
1315 1316 1317 1318 1319
};

static int ap_device_probe(struct device *dev)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
1320 1321
	struct ap_driver *ap_drv = to_ap_drv(dev->driver);
	int rc;
1322

1323
	ap_dev->drv = ap_drv;
1324
	rc = ap_drv->probe ? ap_drv->probe(ap_dev) : -ENODEV;
1325 1326
	if (rc)
		ap_dev->drv = NULL;
1327 1328 1329 1330
	return rc;
}

/**
1331 1332 1333
 * __ap_flush_queue(): Flush requests.
 * @ap_dev: Pointer to the AP device
 *
1334 1335
 * Flush all requests from the request/pending queue of an AP device.
 */
1336
static void __ap_flush_queue(struct ap_device *ap_dev)
1337 1338 1339 1340 1341 1342
{
	struct ap_message *ap_msg, *next;

	list_for_each_entry_safe(ap_msg, next, &ap_dev->pendingq, list) {
		list_del_init(&ap_msg->list);
		ap_dev->pendingq_count--;
1343 1344
		ap_msg->rc = -EAGAIN;
		ap_msg->receive(ap_dev, ap_msg, NULL);
1345 1346 1347 1348
	}
	list_for_each_entry_safe(ap_msg, next, &ap_dev->requestq, list) {
		list_del_init(&ap_msg->list);
		ap_dev->requestq_count--;
1349 1350
		ap_msg->rc = -EAGAIN;
		ap_msg->receive(ap_dev, ap_msg, NULL);
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
	}
}

void ap_flush_queue(struct ap_device *ap_dev)
{
	spin_lock_bh(&ap_dev->lock);
	__ap_flush_queue(ap_dev);
	spin_unlock_bh(&ap_dev->lock);
}
EXPORT_SYMBOL(ap_flush_queue);

static int ap_device_remove(struct device *dev)
{
	struct ap_device *ap_dev = to_ap_dev(dev);
	struct ap_driver *ap_drv = ap_dev->drv;

1367
	ap_flush_queue(ap_dev);
1368
	del_timer_sync(&ap_dev->timeout);
1369
	spin_lock_bh(&ap_device_list_lock);
1370
	list_del_init(&ap_dev->list);
1371
	spin_unlock_bh(&ap_device_list_lock);
1372 1373
	if (ap_drv->remove)
		ap_drv->remove(ap_dev);
1374 1375 1376
	spin_lock_bh(&ap_dev->lock);
	atomic_sub(ap_dev->queue_count, &ap_poll_requests);
	spin_unlock_bh(&ap_dev->lock);
1377 1378 1379
	return 0;
}

1380 1381 1382 1383 1384
static void ap_device_release(struct device *dev)
{
	kfree(to_ap_dev(dev));
}

1385 1386 1387 1388 1389
int ap_driver_register(struct ap_driver *ap_drv, struct module *owner,
		       char *name)
{
	struct device_driver *drv = &ap_drv->driver;

1390 1391 1392
	if (!initialised)
		return -ENODEV;

1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
	drv->bus = &ap_bus_type;
	drv->probe = ap_device_probe;
	drv->remove = ap_device_remove;
	drv->owner = owner;
	drv->name = name;
	return driver_register(drv);
}
EXPORT_SYMBOL(ap_driver_register);

void ap_driver_unregister(struct ap_driver *ap_drv)
{
	driver_unregister(&ap_drv->driver);
}
EXPORT_SYMBOL(ap_driver_unregister);

1408 1409
void ap_bus_force_rescan(void)
{
1410 1411
	if (ap_suspend_flag)
		return;
1412
	/* processing a asynchronous bus rescan */
1413
	del_timer(&ap_config_timer);
1414 1415
	queue_work(system_long_wq, &ap_scan_work);
	flush_work(&ap_scan_work);
1416 1417 1418
}
EXPORT_SYMBOL(ap_bus_force_rescan);

1419
/*
1420 1421 1422 1423 1424 1425 1426 1427 1428
 * AP bus attributes.
 */
static ssize_t ap_domain_show(struct bus_type *bus, char *buf)
{
	return snprintf(buf, PAGE_SIZE, "%d\n", ap_domain_index);
}

static BUS_ATTR(ap_domain, 0444, ap_domain_show, NULL);

1429 1430
static ssize_t ap_control_domain_mask_show(struct bus_type *bus, char *buf)
{
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
	if (!ap_configuration)	/* QCI not supported */
		return snprintf(buf, PAGE_SIZE, "not supported\n");
	if (!test_facility(76))
		/* format 0 - 16 bit domain field */
		return snprintf(buf, PAGE_SIZE, "%08x%08x\n",
				ap_configuration->adm[0],
				ap_configuration->adm[1]);
	/* format 1 - 256 bit domain field */
	return snprintf(buf, PAGE_SIZE,
			"0x%08x%08x%08x%08x%08x%08x%08x%08x\n",
1441 1442 1443 1444 1445 1446 1447 1448 1449
			ap_configuration->adm[0], ap_configuration->adm[1],
			ap_configuration->adm[2], ap_configuration->adm[3],
			ap_configuration->adm[4], ap_configuration->adm[5],
			ap_configuration->adm[6], ap_configuration->adm[7]);
}

static BUS_ATTR(ap_control_domain_mask, 0444,
		ap_control_domain_mask_show, NULL);

1450 1451 1452 1453 1454
static ssize_t ap_config_time_show(struct bus_type *bus, char *buf)
{
	return snprintf(buf, PAGE_SIZE, "%d\n", ap_config_time);
}

F
Felix Beck 已提交
1455 1456 1457 1458 1459 1460 1461 1462
static ssize_t ap_interrupts_show(struct bus_type *bus, char *buf)
{
	return snprintf(buf, PAGE_SIZE, "%d\n",
			ap_using_interrupts() ? 1 : 0);
}

static BUS_ATTR(ap_interrupts, 0444, ap_interrupts_show, NULL);

1463 1464 1465 1466 1467 1468 1469 1470
static ssize_t ap_config_time_store(struct bus_type *bus,
				    const char *buf, size_t count)
{
	int time;

	if (sscanf(buf, "%d\n", &time) != 1 || time < 5 || time > 120)
		return -EINVAL;
	ap_config_time = time;
1471
	mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
	return count;
}

static BUS_ATTR(config_time, 0644, ap_config_time_show, ap_config_time_store);

static ssize_t ap_poll_thread_show(struct bus_type *bus, char *buf)
{
	return snprintf(buf, PAGE_SIZE, "%d\n", ap_poll_kthread ? 1 : 0);
}

static ssize_t ap_poll_thread_store(struct bus_type *bus,
				    const char *buf, size_t count)
{
	int flag, rc;

	if (sscanf(buf, "%d\n", &flag) != 1)
		return -EINVAL;
	if (flag) {
		rc = ap_poll_thread_start();
		if (rc)
1492 1493
			count = rc;
	} else
1494 1495 1496 1497 1498 1499
		ap_poll_thread_stop();
	return count;
}

static BUS_ATTR(poll_thread, 0644, ap_poll_thread_show, ap_poll_thread_store);

1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511
static ssize_t poll_timeout_show(struct bus_type *bus, char *buf)
{
	return snprintf(buf, PAGE_SIZE, "%llu\n", poll_timeout);
}

static ssize_t poll_timeout_store(struct bus_type *bus, const char *buf,
				  size_t count)
{
	unsigned long long time;
	ktime_t hr_time;

	/* 120 seconds = maximum poll interval */
F
Felix Beck 已提交
1512 1513
	if (sscanf(buf, "%llu\n", &time) != 1 || time < 1 ||
	    time > 120000000000ULL)
1514 1515 1516 1517
		return -EINVAL;
	poll_timeout = time;
	hr_time = ktime_set(0, poll_timeout);

1518 1519 1520 1521 1522 1523
	spin_lock_bh(&ap_poll_timer_lock);
	hrtimer_cancel(&ap_poll_timer);
	hrtimer_set_expires(&ap_poll_timer, hr_time);
	hrtimer_start_expires(&ap_poll_timer, HRTIMER_MODE_ABS);
	spin_unlock_bh(&ap_poll_timer_lock);

1524 1525 1526 1527 1528
	return count;
}

static BUS_ATTR(poll_timeout, 0644, poll_timeout_show, poll_timeout_store);

1529 1530
static ssize_t ap_max_domain_id_show(struct bus_type *bus, char *buf)
{
1531 1532 1533 1534 1535
	int max_domain_id;

	if (ap_configuration)
		max_domain_id = ap_max_domain_id ? : -1;
	else
1536 1537 1538 1539 1540 1541
		max_domain_id = 15;
	return snprintf(buf, PAGE_SIZE, "%d\n", max_domain_id);
}

static BUS_ATTR(ap_max_domain_id, 0444, ap_max_domain_id_show, NULL);

1542 1543
static struct bus_attribute *const ap_bus_attrs[] = {
	&bus_attr_ap_domain,
1544
	&bus_attr_ap_control_domain_mask,
1545 1546
	&bus_attr_config_time,
	&bus_attr_poll_thread,
F
Felix Beck 已提交
1547
	&bus_attr_ap_interrupts,
1548
	&bus_attr_poll_timeout,
1549
	&bus_attr_ap_max_domain_id,
1550
	NULL,
1551 1552 1553
};

/**
1554 1555 1556
 * ap_select_domain(): Select an AP domain.
 *
 * Pick one of the 16 AP domains.
1557
 */
1558
static int ap_select_domain(void)
1559
{
1560 1561 1562
	int count, max_count, best_domain;
	struct ap_queue_status status;
	int i, j;
1563

1564
	/*
1565 1566 1567 1568
	 * We want to use a single domain. Either the one specified with
	 * the "domain=" parameter or the domain with the maximum number
	 * of devices.
	 */
1569
	if (ap_domain_index >= 0)
1570 1571 1572 1573 1574
		/* Domain has already been selected. */
		return 0;
	best_domain = -1;
	max_count = 0;
	for (i = 0; i < AP_DOMAINS; i++) {
1575 1576
		if (!ap_test_config_domain(i))
			continue;
1577 1578
		count = 0;
		for (j = 0; j < AP_DEVICES; j++) {
1579 1580
			if (!ap_test_config_card_id(j))
				continue;
1581 1582
			status = ap_test_queue(AP_MKQID(j, i), NULL);
			if (status.response_code != AP_RESPONSE_NORMAL)
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598
				continue;
			count++;
		}
		if (count > max_count) {
			max_count = count;
			best_domain = i;
		}
	}
	if (best_domain >= 0){
		ap_domain_index = best_domain;
		return 0;
	}
	return -ENODEV;
}

/**
1599 1600 1601 1602 1603
 * __ap_scan_bus(): Scan the AP bus.
 * @dev: Pointer to device
 * @data: Pointer to data
 *
 * Scan the AP bus for new devices.
1604 1605 1606 1607 1608 1609
 */
static int __ap_scan_bus(struct device *dev, void *data)
{
	return to_ap_dev(dev)->qid == (ap_qid_t)(unsigned long) data;
}

1610
static void ap_scan_bus(struct work_struct *unused)
1611 1612 1613 1614
{
	struct ap_device *ap_dev;
	struct device *dev;
	ap_qid_t qid;
1615
	int queue_depth = 0, device_type = 0;
1616 1617
	unsigned int device_functions = 0;
	int rc, i, borked;
1618

1619
	ap_query_configuration();
1620
	if (ap_select_domain() != 0)
1621
		goto out;
1622

1623 1624 1625 1626 1627
	for (i = 0; i < AP_DEVICES; i++) {
		qid = AP_MKQID(i, ap_domain_index);
		dev = bus_find_device(&ap_bus_type, NULL,
				      (void *)(unsigned long)qid,
				      __ap_scan_bus);
1628 1629
		rc = ap_query_queue(qid, &queue_depth, &device_type,
				    &device_functions);
1630 1631 1632
		if (dev) {
			ap_dev = to_ap_dev(dev);
			spin_lock_bh(&ap_dev->lock);
1633 1634 1635
			if (rc == -ENODEV)
				ap_dev->state = AP_STATE_BORKED;
			borked = ap_dev->state == AP_STATE_BORKED;
1636
			spin_unlock_bh(&ap_dev->lock);
1637 1638
			if (borked)	/* Remove broken device */
				device_unregister(dev);
1639
			put_device(dev);
1640 1641
			if (!borked)
				continue;
1642 1643 1644 1645 1646 1647 1648
		}
		if (rc)
			continue;
		ap_dev = kzalloc(sizeof(*ap_dev), GFP_KERNEL);
		if (!ap_dev)
			break;
		ap_dev->qid = qid;
1649 1650
		ap_dev->state = AP_STATE_RESET_START;
		ap_dev->interrupt = AP_INTR_DISABLED;
1651
		ap_dev->queue_depth = queue_depth;
1652 1653 1654
		ap_dev->raw_hwtype = device_type;
		ap_dev->device_type = device_type;
		ap_dev->functions = device_functions;
1655 1656 1657
		spin_lock_init(&ap_dev->lock);
		INIT_LIST_HEAD(&ap_dev->pendingq);
		INIT_LIST_HEAD(&ap_dev->requestq);
1658
		INIT_LIST_HEAD(&ap_dev->list);
1659 1660
		setup_timer(&ap_dev->timeout, ap_request_timeout,
			    (unsigned long) ap_dev);
1661

1662 1663
		ap_dev->device.bus = &ap_bus_type;
		ap_dev->device.parent = ap_root_device;
1664 1665 1666
		rc = dev_set_name(&ap_dev->device, "card%02x",
				  AP_QID_DEVICE(ap_dev->qid));
		if (rc) {
1667 1668 1669
			kfree(ap_dev);
			continue;
		}
1670 1671 1672 1673 1674 1675 1676 1677 1678
		/* Add to list of devices */
		spin_lock_bh(&ap_device_list_lock);
		list_add(&ap_dev->list, &ap_device_list);
		spin_unlock_bh(&ap_device_list_lock);
		/* Start with a device reset */
		spin_lock_bh(&ap_dev->lock);
		ap_sm_wait(ap_sm_event(ap_dev, AP_EVENT_POLL));
		spin_unlock_bh(&ap_dev->lock);
		/* Register device */
1679 1680 1681
		ap_dev->device.release = ap_device_release;
		rc = device_register(&ap_dev->device);
		if (rc) {
1682 1683 1684
			spin_lock_bh(&ap_dev->lock);
			list_del_init(&ap_dev->list);
			spin_unlock_bh(&ap_dev->lock);
1685
			put_device(&ap_dev->device);
1686 1687 1688 1689 1690
			continue;
		}
		/* Add device attributes. */
		rc = sysfs_create_group(&ap_dev->device.kobj,
					&ap_dev_attr_group);
1691
		if (rc) {
1692
			device_unregister(&ap_dev->device);
1693 1694
			continue;
		}
1695
	}
1696 1697
out:
	mod_timer(&ap_config_timer, jiffies + ap_config_time * HZ);
1698 1699
}

1700
static void ap_config_timeout(unsigned long ptr)
1701
{
1702 1703
	if (ap_suspend_flag)
		return;
1704
	queue_work(system_long_wq, &ap_scan_work);
1705 1706
}

1707 1708 1709 1710
static void ap_reset_domain(void)
{
	int i;

1711 1712 1713 1714
	if (ap_domain_index == -1 || !ap_test_config_domain(ap_domain_index))
		return;
	for (i = 0; i < AP_DEVICES; i++)
		ap_reset_queue(AP_MKQID(i, ap_domain_index));
1715 1716 1717
}

static void ap_reset_all(void)
1718 1719 1720
{
	int i, j;

1721 1722 1723 1724 1725 1726
	for (i = 0; i < AP_DOMAINS; i++) {
		if (!ap_test_config_domain(i))
			continue;
		for (j = 0; j < AP_DEVICES; j++) {
			if (!ap_test_config_card_id(j))
				continue;
1727
			ap_reset_queue(AP_MKQID(j, i));
1728 1729
		}
	}
1730 1731 1732
}

static struct reset_call ap_reset_call = {
1733
	.fn = ap_reset_all,
1734 1735
};

1736
/**
1737 1738 1739
 * ap_module_init(): The module initialization code.
 *
 * Initializes the module.
1740 1741 1742
 */
int __init ap_module_init(void)
{
1743
	int max_domain_id;
1744 1745
	int rc, i;

1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760
	if (ap_instructions_available() != 0) {
		pr_warn("The hardware system does not support AP instructions\n");
		return -ENODEV;
	}

	/* Get AP configuration data if available */
	ap_init_configuration();

	if (ap_configuration)
		max_domain_id = ap_max_domain_id ? : (AP_DOMAINS - 1);
	else
		max_domain_id = 15;
	if (ap_domain_index < -1 || ap_domain_index > max_domain_id) {
		pr_warn("%d is not a valid cryptographic domain\n",
			ap_domain_index);
1761 1762
		return -EINVAL;
	}
1763 1764 1765 1766 1767 1768
	/* In resume callback we need to know if the user had set the domain.
	 * If so, we can not just reset it.
	 */
	if (ap_domain_index >= 0)
		user_set_domain = 1;

F
Felix Beck 已提交
1769
	if (ap_interrupts_available()) {
1770 1771
		rc = register_adapter_interrupt(&ap_airq);
		ap_airq_flag = (rc == 0);
F
Felix Beck 已提交
1772 1773
	}

1774
	register_reset_call(&ap_reset_call);
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786

	/* Create /sys/bus/ap. */
	rc = bus_register(&ap_bus_type);
	if (rc)
		goto out;
	for (i = 0; ap_bus_attrs[i]; i++) {
		rc = bus_create_file(&ap_bus_type, ap_bus_attrs[i]);
		if (rc)
			goto out_bus;
	}

	/* Create /sys/devices/ap. */
M
Mark McLoughlin 已提交
1787
	ap_root_device = root_device_register("ap");
1788
	rc = PTR_RET(ap_root_device);
1789 1790 1791
	if (rc)
		goto out_bus;

1792
	/* Setup the AP bus rescan timer. */
1793
	setup_timer(&ap_config_timer, ap_config_timeout, 0);
1794

1795 1796
	/*
	 * Setup the high resultion poll timer.
1797 1798 1799 1800
	 * If we are running under z/VM adjust polling to z/VM polling rate.
	 */
	if (MACHINE_IS_VM)
		poll_timeout = 1500000;
1801
	spin_lock_init(&ap_poll_timer_lock);
1802 1803 1804
	hrtimer_init(&ap_poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
	ap_poll_timer.function = ap_poll_timeout;

1805 1806 1807 1808 1809 1810 1811
	/* Start the low priority AP bus poll thread. */
	if (ap_thread_flag) {
		rc = ap_poll_thread_start();
		if (rc)
			goto out_work;
	}

1812 1813 1814 1815
	rc = register_pm_notifier(&ap_power_notifier);
	if (rc)
		goto out_pm;

1816
	queue_work(system_long_wq, &ap_scan_work);
1817
	initialised = true;
1818

1819 1820
	return 0;

1821 1822
out_pm:
	ap_poll_thread_stop();
1823
out_work:
1824
	hrtimer_cancel(&ap_poll_timer);
M
Mark McLoughlin 已提交
1825
	root_device_unregister(ap_root_device);
1826 1827 1828 1829 1830
out_bus:
	while (i--)
		bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
	bus_unregister(&ap_bus_type);
out:
1831
	unregister_reset_call(&ap_reset_call);
1832 1833
	if (ap_using_interrupts())
		unregister_adapter_interrupt(&ap_airq);
1834
	kfree(ap_configuration);
1835 1836 1837 1838
	return rc;
}

/**
1839 1840 1841
 * ap_modules_exit(): The module termination code
 *
 * Terminates the module.
1842 1843 1844 1845 1846
 */
void ap_module_exit(void)
{
	int i;

1847
	initialised = false;
1848
	ap_reset_domain();
1849 1850
	ap_poll_thread_stop();
	del_timer_sync(&ap_config_timer);
1851
	hrtimer_cancel(&ap_poll_timer);
1852
	tasklet_kill(&ap_tasklet);
1853
	bus_for_each_dev(&ap_bus_type, NULL, NULL, __ap_devices_unregister);
1854 1855
	for (i = 0; ap_bus_attrs[i]; i++)
		bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
1856
	unregister_pm_notifier(&ap_power_notifier);
1857
	root_device_unregister(ap_root_device);
1858
	bus_unregister(&ap_bus_type);
1859
	kfree(ap_configuration);
1860
	unregister_reset_call(&ap_reset_call);
1861 1862
	if (ap_using_interrupts())
		unregister_adapter_interrupt(&ap_airq);
1863 1864 1865 1866
}

module_init(ap_module_init);
module_exit(ap_module_exit);