Commit e376bc34 authored by Heiko Carstens's avatar Heiko Carstens Committed by Linus Torvalds

[PATCH] s390: SCLP device driver cleanup

From: Peter Oberparleiter <peter.oberparleiter@de.ibm.com>

sclp: core driver cleanup

Details:
- moved signal shutdown (quiesce) handling into a separate file
- cleanup of SCLP core driver:
  . introduced driver states instead of bits
  . introduced request retry count and retry limit
  . sclp_add_request now returns an error code if a request couldn't be started
  . introduced separate request structure for init_mask requests to simplify
    code
  . request timer is now manually checked in sclp_sync_wait because timer
    interrupts are disabled in this context
  . removed busy timer - request timer now handles both cases
  . split up sclp_start_request into __sclp_start_request and sclp_process
    queue
  . removed sclp_error_message (unused)
  . introduced sclp_check_handler function to split up initial init mask
    test from standard init mask request processing
  . introduced sclp_deactivate and sclp_reactivate for simplified reboot
    event handling (and potential use in suspend/resume scenario)
  . added protection against multiple concurrent init mask calls
- minor changes in SCLP core driver:
  . updated comments
  . renamed functions to be consistent with "function name starts with __ =>
    needs lock"
  . renamed internal functions for consistency reasons
  . introduced inlined helper functions to simplify code
  . moved EXPORT_SYMBOL definitions next to function definition
- changes in sclp console driver
  . removed callback recursion to prevent stack overflow
- changes to CPI module
  . added check for sclp_add_request return code
  . changed printks to specify a message level
- changes to generic sclp tty layer
  . removed timed buffer retry after error (timers may not work in some
    situations)
  . introduced return code for sclp_emit_buffer
- changes to sclp tty driver
  . removed callback recursion
- changes to sclp vt220 driver
  . removed callback recursion
  . removed timed buffer retry after error
- modified sclp_init_mask to prevent problems with some compiler versions
Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ae798b69
...@@ -11,7 +11,7 @@ obj-$(CONFIG_TN3270_FS) += fs3270.o ...@@ -11,7 +11,7 @@ obj-$(CONFIG_TN3270_FS) += fs3270.o
obj-$(CONFIG_TN3215) += con3215.o obj-$(CONFIG_TN3215) += con3215.o
obj-$(CONFIG_SCLP) += sclp.o sclp_rw.o obj-$(CONFIG_SCLP) += sclp.o sclp_rw.o sclp_quiesce.o
obj-$(CONFIG_SCLP_TTY) += sclp_tty.o obj-$(CONFIG_SCLP_TTY) += sclp_tty.o
obj-$(CONFIG_SCLP_CONSOLE) += sclp_con.o obj-$(CONFIG_SCLP_CONSOLE) += sclp_con.o
obj-$(CONFIG_SCLP_VT220_TTY) += sclp_vt220.o obj-$(CONFIG_SCLP_VT220_TTY) += sclp_vt220.o
......
...@@ -8,82 +8,99 @@ ...@@ -8,82 +8,99 @@
* Martin Schwidefsky <schwidefsky@de.ibm.com> * Martin Schwidefsky <schwidefsky@de.ibm.com>
*/ */
#include <linux/config.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/kmod.h>
#include <linux/bootmem.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/ptrace.h>
#include <linux/slab.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/init.h>
#include <linux/cpumask.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/jiffies.h>
#include <asm/types.h>
#include <asm/s390_ext.h> #include <asm/s390_ext.h>
#include <asm/processor.h>
#include "sclp.h" #include "sclp.h"
#define SCLP_CORE_PRINT_HEADER "sclp low level driver: " #define SCLP_HEADER "sclp: "
/* Structure for register_early_external_interrupt. */ /* Structure for register_early_external_interrupt. */
static ext_int_info_t ext_int_info_hwc; static ext_int_info_t ext_int_info_hwc;
/* spinlock to protect global variables of sclp_core */ /* Lock to protect internal data consistency. */
static spinlock_t sclp_lock; static spinlock_t sclp_lock = SPIN_LOCK_UNLOCKED;
/* Mask of valid sclp events */ /* Mask of events that we can receive from the sclp interface. */
static sccb_mask_t sclp_receive_mask; static sccb_mask_t sclp_receive_mask;
/* Mask of events that we can send to the sclp interface. */
static sccb_mask_t sclp_send_mask; static sccb_mask_t sclp_send_mask;
/* List of registered event types */ /* List of registered event listeners and senders. */
static struct list_head sclp_reg_list; static struct list_head sclp_reg_list;
/* sccb queue */ /* List of queued requests. */
static struct list_head sclp_req_queue; static struct list_head sclp_req_queue;
/* sccb for unconditional read */ /* Data for read and and init requests. */
static struct sclp_req sclp_read_req; static struct sclp_req sclp_read_req;
static struct sclp_req sclp_init_req;
static char sclp_read_sccb[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); static char sclp_read_sccb[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
/* sccb for write mask sccb */
static char sclp_init_sccb[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); static char sclp_init_sccb[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
/* Timer for init mask retries. */ /* Timer for request retries. */
static struct timer_list retry_timer; static struct timer_list sclp_request_timer;
/* Timer for busy retries. */ /* Internal state: is the driver initialized? */
static struct timer_list sclp_busy_timer; static volatile enum sclp_init_state_t {
sclp_init_state_uninitialized,
static volatile unsigned long sclp_status = 0; sclp_init_state_initializing,
/* some status flags */ sclp_init_state_initialized
#define SCLP_INIT 0 } sclp_init_state = sclp_init_state_uninitialized;
#define SCLP_RUNNING 1
#define SCLP_READING 2 /* Internal state: is a request active at the sclp? */
#define SCLP_SHUTDOWN 3 static volatile enum sclp_running_state_t {
sclp_running_state_idle,
#define SCLP_INIT_POLL_INTERVAL 1 sclp_running_state_running
#define SCLP_BUSY_POLL_INTERVAL 1 } sclp_running_state = sclp_running_state_idle;
#define SCLP_COMMAND_INITIATED 0 /* Internal state: is a read request pending? */
#define SCLP_BUSY 2 static volatile enum sclp_reading_state_t {
#define SCLP_NOT_OPERATIONAL 3 sclp_reading_state_idle,
sclp_reading_state_reading
/* } sclp_reading_state = sclp_reading_state_idle;
* assembler instruction for Service Call
*/ /* Internal state: is the driver currently serving requests? */
static volatile enum sclp_activation_state_t {
sclp_activation_state_active,
sclp_activation_state_deactivating,
sclp_activation_state_inactive,
sclp_activation_state_activating
} sclp_activation_state = sclp_activation_state_active;
/* Internal state: is an init mask request pending? */
static volatile enum sclp_mask_state_t {
sclp_mask_state_idle,
sclp_mask_state_initializing
} sclp_mask_state = sclp_mask_state_idle;
/* Maximum retry counts */
#define SCLP_INIT_RETRY 3
#define SCLP_MASK_RETRY 3
#define SCLP_REQUEST_RETRY 3
/* Timeout intervals in seconds.*/
#define SCLP_BUSY_INTERVAL 2
#define SCLP_RETRY_INTERVAL 5
static void sclp_process_queue(void);
static int sclp_init_mask(int calculate);
static int sclp_init(void);
/* Perform service call. Return 0 on success, non-zero otherwise. */
static int static int
__service_call(sclp_cmdw_t command, void *sccb) service_call(sclp_cmdw_t command, void *sccb)
{ {
int cc; int cc;
/*
* Mnemonic: SERVC Rx, Ry [RRE]
*
* Rx: SCLP command word
* Ry: address of SCCB
*/
__asm__ __volatile__( __asm__ __volatile__(
" .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */ " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
" ipm %0\n" " ipm %0\n"
...@@ -91,61 +108,94 @@ __service_call(sclp_cmdw_t command, void *sccb) ...@@ -91,61 +108,94 @@ __service_call(sclp_cmdw_t command, void *sccb)
: "=&d" (cc) : "=&d" (cc)
: "d" (command), "a" (__pa(sccb)) : "d" (command), "a" (__pa(sccb))
: "cc", "memory" ); : "cc", "memory" );
/* if (cc == 3)
* cc == 0: Service Call succesful initiated
* cc == 2: SCLP busy, new Service Call not initiated,
* new SCCB unchanged
* cc == 3: SCLP function not operational
*/
if (cc == SCLP_NOT_OPERATIONAL)
return -EIO; return -EIO;
if (cc == SCLP_BUSY) if (cc == 2)
return -EBUSY; return -EBUSY;
return 0; return 0;
} }
/* Request timeout handler. Restart the request queue. If DATA is non-zero,
* force restart of running request. */
static void static void
sclp_start_request(void) sclp_request_timeout(unsigned long data)
{
unsigned long flags;
if (data) {
spin_lock_irqsave(&sclp_lock, flags);
sclp_running_state = sclp_running_state_idle;
spin_unlock_irqrestore(&sclp_lock, flags);
}
sclp_process_queue();
}
/* Set up request retry timer. Called while sclp_lock is locked. */
static inline void
__sclp_set_request_timer(unsigned long time, void (*function)(unsigned long),
unsigned long data)
{
del_timer(&sclp_request_timer);
sclp_request_timer.function = function;
sclp_request_timer.data = data;
sclp_request_timer.expires = jiffies + time;
add_timer(&sclp_request_timer);
}
/* Try to start a request. Return zero if the request was successfully
* started or if it will be started at a later time. Return non-zero otherwise.
* Called while sclp_lock is locked. */
static int
__sclp_start_request(struct sclp_req *req)
{
int rc;
if (sclp_running_state != sclp_running_state_idle)
return 0;
del_timer(&sclp_request_timer);
if (req->start_count <= SCLP_REQUEST_RETRY) {
rc = service_call(req->command, req->sccb);
req->start_count++;
} else
rc = -EIO;
if (rc == 0) {
/* Sucessfully started request */
req->status = SCLP_REQ_RUNNING;
sclp_running_state = sclp_running_state_running;
__sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
sclp_request_timeout, 1);
return 0;
} else if (rc == -EBUSY) {
/* Try again later */
__sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
sclp_request_timeout, 0);
return 0;
}
/* Request failed */
req->status = SCLP_REQ_FAILED;
return rc;
}
/* Try to start queued requests. */
static void
sclp_process_queue(void)
{ {
struct sclp_req *req; struct sclp_req *req;
int rc; int rc;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&sclp_lock, flags); spin_lock_irqsave(&sclp_lock, flags);
/* quick exit if sclp is already in use */ if (sclp_running_state != sclp_running_state_idle) {
if (test_bit(SCLP_RUNNING, &sclp_status)) {
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
return; return;
} }
/* Try to start requests from the request queue. */ del_timer(&sclp_request_timer);
while (!list_empty(&sclp_req_queue)) { while (!list_empty(&sclp_req_queue)) {
req = list_entry(sclp_req_queue.next, struct sclp_req, list); req = list_entry(sclp_req_queue.next, struct sclp_req, list);
rc = __service_call(req->command, req->sccb); rc = __sclp_start_request(req);
if (rc == 0) { if (rc == 0)
/* Sucessfully started request. */
req->status = SCLP_REQ_RUNNING;
/* Request active. Set running indication. */
set_bit(SCLP_RUNNING, &sclp_status);
break; break;
}
if (rc == -EBUSY) {
/**
* SCLP is busy but no request is running.
* Try again later.
*/
if (!timer_pending(&sclp_busy_timer) ||
!mod_timer(&sclp_busy_timer,
jiffies + SCLP_BUSY_POLL_INTERVAL*HZ)) {
sclp_busy_timer.function =
(void *) sclp_start_request;
sclp_busy_timer.expires =
jiffies + SCLP_BUSY_POLL_INTERVAL*HZ;
add_timer(&sclp_busy_timer);
}
break;
}
/* Request failed. */ /* Request failed. */
req->status = SCLP_REQ_FAILED;
list_del(&req->list); list_del(&req->list);
if (req->callback) { if (req->callback) {
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
...@@ -156,265 +206,258 @@ sclp_start_request(void) ...@@ -156,265 +206,258 @@ sclp_start_request(void)
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
} }
/* Queue a new request. Return zero on success, non-zero otherwise. */
int
sclp_add_request(struct sclp_req *req)
{
unsigned long flags;
int rc;
spin_lock_irqsave(&sclp_lock, flags);
if ((sclp_init_state != sclp_init_state_initialized ||
sclp_activation_state != sclp_activation_state_active) &&
req != &sclp_init_req) {
spin_unlock_irqrestore(&sclp_lock, flags);
return -EIO;
}
req->status = SCLP_REQ_QUEUED;
req->start_count = 0;
list_add_tail(&req->list, &sclp_req_queue);
rc = 0;
/* Start if request is first in list */
if (req->list.prev == &sclp_req_queue) {
rc = __sclp_start_request(req);
if (rc)
list_del(&req->list);
}
spin_unlock_irqrestore(&sclp_lock, flags);
return rc;
}
EXPORT_SYMBOL(sclp_add_request);
/* Dispatch events found in request buffer to registered listeners. Return 0
* if all events were dispatched, non-zero otherwise. */
static int static int
sclp_process_evbufs(struct sccb_header *sccb) sclp_dispatch_evbufs(struct sccb_header *sccb)
{ {
int result;
unsigned long flags; unsigned long flags;
struct evbuf_header *evbuf; struct evbuf_header *evbuf;
struct list_head *l; struct list_head *l;
struct sclp_register *t; struct sclp_register *reg;
int offset;
int rc;
spin_lock_irqsave(&sclp_lock, flags); spin_lock_irqsave(&sclp_lock, flags);
evbuf = (struct evbuf_header *) (sccb + 1); rc = 0;
result = 0; for (offset = sizeof(struct sccb_header); offset < sccb->length;
while ((addr_t) evbuf < (addr_t) sccb + sccb->length) { offset += evbuf->length) {
/* check registered event */ /* Search for event handler */
t = NULL; evbuf = (struct evbuf_header *) ((addr_t) sccb + offset);
reg = NULL;
list_for_each(l, &sclp_reg_list) { list_for_each(l, &sclp_reg_list) {
t = list_entry(l, struct sclp_register, list); reg = list_entry(l, struct sclp_register, list);
if (t->receive_mask & (1 << (32 - evbuf->type))) { if (reg->receive_mask & (1 << (32 - evbuf->type)))
if (t->receiver_fn != NULL) {
spin_unlock_irqrestore(&sclp_lock,
flags);
t->receiver_fn(evbuf);
spin_lock_irqsave(&sclp_lock, flags);
}
break; break;
}
else else
t = NULL; reg = NULL;
} }
/* Check for unrequested event buffer */ if (reg && reg->receiver_fn) {
if (t == NULL) spin_unlock_irqrestore(&sclp_lock, flags);
result = -ENOSYS; reg->receiver_fn(evbuf);
evbuf = (struct evbuf_header *) spin_lock_irqsave(&sclp_lock, flags);
((addr_t) evbuf + evbuf->length); } else if (reg == NULL)
rc = -ENOSYS;
} }
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
return result; return rc;
}
char *
sclp_error_message(u16 rc)
{
static struct {
u16 code; char *msg;
} sclp_errors[] = {
{ 0x0000, "No response code stored (machine malfunction)" },
{ 0x0020, "Normal Completion" },
{ 0x0040, "SCLP equipment check" },
{ 0x0100, "SCCB boundary violation" },
{ 0x01f0, "Invalid command" },
{ 0x0220, "Normal Completion; suppressed buffers pending" },
{ 0x0300, "Insufficient SCCB length" },
{ 0x0340, "Contained SCLP equipment check" },
{ 0x05f0, "Target resource in improper state" },
{ 0x40f0, "Invalid function code/not installed" },
{ 0x60f0, "No buffers stored" },
{ 0x62f0, "No buffers stored; suppressed buffers pending" },
{ 0x70f0, "Invalid selection mask" },
{ 0x71f0, "Event buffer exceeds available space" },
{ 0x72f0, "Inconsistent lengths" },
{ 0x73f0, "Event buffer syntax error" }
};
int i;
for (i = 0; i < sizeof(sclp_errors)/sizeof(sclp_errors[0]); i++)
if (rc == sclp_errors[i].code)
return sclp_errors[i].msg;
return "Invalid response code";
} }
/* /* Read event data request callback. */
* postprocessing of unconditional read service call
*/
static void static void
sclp_unconditional_read_cb(struct sclp_req *read_req, void *data) sclp_read_cb(struct sclp_req *req, void *data)
{ {
unsigned long flags;
struct sccb_header *sccb; struct sccb_header *sccb;
sccb = read_req->sccb; sccb = (struct sccb_header *) req->sccb;
if (sccb->response_code == 0x0020 || if (req->status == SCLP_REQ_DONE && (sccb->response_code == 0x20 ||
sccb->response_code == 0x0220) { sccb->response_code == 0x220))
if (sclp_process_evbufs(sccb) != 0) sclp_dispatch_evbufs(sccb);
printk(KERN_WARNING SCLP_CORE_PRINT_HEADER spin_lock_irqsave(&sclp_lock, flags);
"unconditional read: " sclp_reading_state = sclp_reading_state_idle;
"unrequested event buffer received.\n"); spin_unlock_irqrestore(&sclp_lock, flags);
}
if (sccb->response_code != 0x0020)
printk(KERN_WARNING SCLP_CORE_PRINT_HEADER
"unconditional read: %s (response code=0x%x).\n",
sclp_error_message(sccb->response_code),
sccb->response_code);
clear_bit(SCLP_READING, &sclp_status);
} }
/* /* Prepare read event data request. Called while sclp_lock is locked. */
* Function to queue Read Event Data/Unconditional Read static inline void
*/ __sclp_make_read_req(void)
static void
__sclp_unconditional_read(void)
{ {
struct sccb_header *sccb; struct sccb_header *sccb;
struct sclp_req *read_req;
/*
* Don't try to initiate Unconditional Read if we are not able to
* receive anything
*/
if (sclp_receive_mask == 0)
return;
/* Don't try reading if a read is already outstanding */
if (test_and_set_bit(SCLP_READING, &sclp_status))
return;
/* Initialize read sccb */
sccb = (struct sccb_header *) sclp_read_sccb; sccb = (struct sccb_header *) sclp_read_sccb;
clear_page(sccb); clear_page(sccb);
memset(&sclp_read_req, 0, sizeof(struct sclp_req));
sclp_read_req.command = SCLP_CMDW_READDATA;
sclp_read_req.status = SCLP_REQ_QUEUED;
sclp_read_req.start_count = 0;
sclp_read_req.callback = sclp_read_cb;
sclp_read_req.sccb = sccb;
sccb->length = PAGE_SIZE; sccb->length = PAGE_SIZE;
sccb->function_code = 0; /* unconditional read */ sccb->function_code = 0;
sccb->control_mask[2] = 0x80; /* variable length response */ sccb->control_mask[2] = 0x80;
/* Initialize request structure */
read_req = &sclp_read_req;
read_req->command = SCLP_CMDW_READDATA;
read_req->status = SCLP_REQ_QUEUED;
read_req->callback = sclp_unconditional_read_cb;
read_req->sccb = sccb;
/* Add read request to the head of queue */
list_add(&read_req->list, &sclp_req_queue);
} }
/* Bit masks to interpret external interruption parameter contents. */ /* Search request list for request with matching sccb. Return request if found,
#define EXT_INT_SCCB_MASK 0xfffffff8 * NULL otherwise. Called while sclp_lock is locked. */
#define EXT_INT_STATECHANGE_PENDING 0x00000002 static inline struct sclp_req *
#define EXT_INT_EVBUF_PENDING 0x00000001 __sclp_find_req(u32 sccb)
{
struct list_head *l;
struct sclp_req *req;
/* list_for_each(l, &sclp_req_queue) {
* Handler for service-signal external interruptions req = list_entry(l, struct sclp_req, list);
*/ if (sccb == (u32) (addr_t) req->sccb)
return req;
}
return NULL;
}
/* Handler for external interruption. Perform request post-processing.
* Prepare read event data request if necessary. Start processing of next
* request on queue. */
static void static void
sclp_interrupt_handler(struct pt_regs *regs, __u16 code) sclp_interrupt_handler(struct pt_regs *regs, __u16 code)
{ {
u32 ext_int_param, finished_sccb, evbuf_pending; struct sclp_req *req;
struct list_head *l; u32 finished_sccb;
struct sclp_req *req, *tmp; u32 evbuf_pending;
spin_lock(&sclp_lock); spin_lock(&sclp_lock);
/* finished_sccb = S390_lowcore.ext_params & 0xfffffff8;
* Only process interrupt if sclp is initialized. evbuf_pending = S390_lowcore.ext_params & 0x3;
* This avoids strange effects for a pending request if (finished_sccb) {
* from before the last re-ipl. req = __sclp_find_req(finished_sccb);
*/ if (req) {
if (!test_bit(SCLP_INIT, &sclp_status)) { /* Request post-processing */
/* Now clear the running bit */ list_del(&req->list);
clear_bit(SCLP_RUNNING, &sclp_status); req->status = SCLP_REQ_DONE;
spin_unlock(&sclp_lock); if (req->callback) {
return; spin_unlock(&sclp_lock);
} req->callback(req, req->callback_data);
ext_int_param = S390_lowcore.ext_params; spin_lock(&sclp_lock);
finished_sccb = ext_int_param & EXT_INT_SCCB_MASK;
evbuf_pending = ext_int_param & (EXT_INT_EVBUF_PENDING |
EXT_INT_STATECHANGE_PENDING);
req = NULL;
if (finished_sccb != 0U) {
list_for_each(l, &sclp_req_queue) {
tmp = list_entry(l, struct sclp_req, list);
if (finished_sccb == (u32)(addr_t) tmp->sccb) {
list_del(&tmp->list);
req = tmp;
break;
} }
} }
sclp_running_state = sclp_running_state_idle;
} }
spin_unlock(&sclp_lock); if (evbuf_pending && sclp_receive_mask != 0 &&
/* Perform callback */ sclp_reading_state == sclp_reading_state_idle &&
if (req != NULL) { sclp_activation_state == sclp_activation_state_active ) {
req->status = SCLP_REQ_DONE; sclp_reading_state = sclp_reading_state_reading;
if (req->callback != NULL) __sclp_make_read_req();
req->callback(req, req->callback_data); /* Add request to head of queue */
list_add(&sclp_read_req.list, &sclp_req_queue);
} }
spin_lock(&sclp_lock);
/* Head queue a read sccb if an event buffer is pending */
if (evbuf_pending)
__sclp_unconditional_read();
/* Now clear the running bit if SCLP indicated a finished SCCB */
if (finished_sccb != 0U)
clear_bit(SCLP_RUNNING, &sclp_status);
spin_unlock(&sclp_lock); spin_unlock(&sclp_lock);
/* and start next request on the queue */ sclp_process_queue();
sclp_start_request();
} }
/* /* Return current Time-Of-Day clock. */
* Wait synchronously for external interrupt of sclp. We may not receive static inline u64
* any other external interrupt, so we disable all other external interrupts sclp_get_clock(void)
* in control register 0. {
*/ u64 result;
asm volatile ("STCK 0(%1)" : "=m" (result) : "a" (&(result)) : "cc");
return result;
}
/* Convert interval in jiffies to TOD ticks. */
static inline u64
sclp_tod_from_jiffies(unsigned long jiffies)
{
return (u64) (jiffies / HZ) << 32;
}
/* Wait until a currently running request finished. Note: while this function
* is running, no timers are served on the calling CPU. */
void void
sclp_sync_wait(void) sclp_sync_wait(void)
{ {
unsigned long psw_mask; unsigned long psw_mask;
unsigned long cr0, cr0_sync; unsigned long cr0, cr0_sync;
u64 timeout;
/* Prevent BH from executing. */
/* We'll be disabling timer interrupts, so we need a custom timeout
* mechanism */
timeout = 0;
if (timer_pending(&sclp_request_timer)) {
/* Get timeout TOD value */
timeout = sclp_get_clock() +
sclp_tod_from_jiffies(sclp_request_timer.expires -
jiffies);
}
/* Prevent bottom half from executing once we force interrupts open */
local_bh_disable(); local_bh_disable();
/* /* Enable service-signal interruption, disable timer interrupts */
* save cr0
* enable service signal external interruption (cr0.22)
* disable cr0.20-21, cr0.25, cr0.27, cr0.30-31
* don't touch any other bit in cr0
*/
__ctl_store(cr0, 0, 0); __ctl_store(cr0, 0, 0);
cr0_sync = cr0; cr0_sync = cr0;
cr0_sync |= 0x00000200; cr0_sync |= 0x00000200;
cr0_sync &= 0xFFFFF3AC; cr0_sync &= 0xFFFFF3AC;
__ctl_load(cr0_sync, 0, 0); __ctl_load(cr0_sync, 0, 0);
/* enable external interruptions (PSW-mask.7) */
asm volatile ("STOSM 0(%1),0x01" asm volatile ("STOSM 0(%1),0x01"
: "=m" (psw_mask) : "a" (&psw_mask) : "memory"); : "=m" (psw_mask) : "a" (&psw_mask) : "memory");
/* Loop until driver state indicates finished request */
/* wait until ISR signals receipt of interrupt */ while (sclp_running_state != sclp_running_state_idle) {
while (test_bit(SCLP_RUNNING, &sclp_status)) { /* Check for expired request timer */
if (timer_pending(&sclp_request_timer) &&
sclp_get_clock() > timeout &&
del_timer(&sclp_request_timer))
sclp_request_timer.function(sclp_request_timer.data);
barrier(); barrier();
cpu_relax(); cpu_relax();
} }
/* Restore interrupt settings */
/* disable external interruptions */
asm volatile ("SSM 0(%0)" asm volatile ("SSM 0(%0)"
: : "a" (&psw_mask) : "memory"); : : "a" (&psw_mask) : "memory");
/* restore cr0 */
__ctl_load(cr0, 0, 0); __ctl_load(cr0, 0, 0);
__local_bh_enable(); __local_bh_enable();
} }
/* EXPORT_SYMBOL(sclp_sync_wait);
* Queue an SCLP request. Request will immediately be processed if queue is
* empty. /* Dispatch changes in send and receive mask to registered listeners. */
*/ static inline void
void sclp_dispatch_state_change(void)
sclp_add_request(struct sclp_req *req)
{ {
struct list_head *l;
struct sclp_register *reg;
unsigned long flags; unsigned long flags;
sccb_mask_t receive_mask;
sccb_mask_t send_mask;
if (!test_bit(SCLP_INIT, &sclp_status)) { do {
req->status = SCLP_REQ_FAILED; spin_lock_irqsave(&sclp_lock, flags);
if (req->callback != NULL) reg = NULL;
req->callback(req, req->callback_data); list_for_each(l, &sclp_reg_list) {
return; reg = list_entry(l, struct sclp_register, list);
} receive_mask = reg->receive_mask & sclp_receive_mask;
spin_lock_irqsave(&sclp_lock, flags); send_mask = reg->send_mask & sclp_send_mask;
/* queue the request */ if (reg->sclp_receive_mask != receive_mask ||
req->status = SCLP_REQ_QUEUED; reg->sclp_send_mask != send_mask) {
list_add_tail(&req->list, &sclp_req_queue); reg->sclp_receive_mask = receive_mask;
spin_unlock_irqrestore(&sclp_lock, flags); reg->sclp_send_mask = send_mask;
/* try to start the first request on the queue */ break;
sclp_start_request(); } else
reg = NULL;
}
spin_unlock_irqrestore(&sclp_lock, flags);
if (reg && reg->state_change_fn)
reg->state_change_fn(reg);
} while (reg);
} }
/* state change notification */
struct sclp_statechangebuf { struct sclp_statechangebuf {
struct evbuf_header header; struct evbuf_header header;
u8 validity_sclp_active_facility_mask : 1; u8 validity_sclp_active_facility_mask : 1;
...@@ -429,148 +472,126 @@ struct sclp_statechangebuf { ...@@ -429,148 +472,126 @@ struct sclp_statechangebuf {
u32 read_data_function_mask; u32 read_data_function_mask;
} __attribute__((packed)); } __attribute__((packed));
static inline void
__sclp_notify_state_change(void)
{
struct list_head *l;
struct sclp_register *t;
sccb_mask_t receive_mask, send_mask;
list_for_each(l, &sclp_reg_list) {
t = list_entry(l, struct sclp_register, list);
receive_mask = t->receive_mask & sclp_receive_mask;
send_mask = t->send_mask & sclp_send_mask;
if (t->sclp_receive_mask != receive_mask ||
t->sclp_send_mask != send_mask) {
t->sclp_receive_mask = receive_mask;
t->sclp_send_mask = send_mask;
if (t->state_change_fn != NULL)
t->state_change_fn(t);
}
}
}
/* State change event callback. Inform listeners of changes. */
static void static void
sclp_state_change(struct evbuf_header *evbuf) sclp_state_change_cb(struct evbuf_header *evbuf)
{ {
unsigned long flags; unsigned long flags;
struct sclp_statechangebuf *scbuf; struct sclp_statechangebuf *scbuf;
spin_lock_irqsave(&sclp_lock, flags);
scbuf = (struct sclp_statechangebuf *) evbuf; scbuf = (struct sclp_statechangebuf *) evbuf;
if (scbuf->mask_length != sizeof(sccb_mask_t))
if (scbuf->validity_sclp_receive_mask) { return;
if (scbuf->mask_length != sizeof(sccb_mask_t)) spin_lock_irqsave(&sclp_lock, flags);
printk(KERN_WARNING SCLP_CORE_PRINT_HEADER if (scbuf->validity_sclp_receive_mask)
"state change event with mask length %i\n", sclp_receive_mask = scbuf->sclp_receive_mask;
scbuf->mask_length); if (scbuf->validity_sclp_send_mask)
else sclp_send_mask = scbuf->sclp_send_mask;
/* set new receive mask */
sclp_receive_mask = scbuf->sclp_receive_mask;
}
if (scbuf->validity_sclp_send_mask) {
if (scbuf->mask_length != sizeof(sccb_mask_t))
printk(KERN_WARNING SCLP_CORE_PRINT_HEADER
"state change event with mask length %i\n",
scbuf->mask_length);
else
/* set new send mask */
sclp_send_mask = scbuf->sclp_send_mask;
}
__sclp_notify_state_change();
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
sclp_dispatch_state_change();
} }
static struct sclp_register sclp_state_change_event = { static struct sclp_register sclp_state_change_event = {
.receive_mask = EvTyp_StateChange_Mask, .receive_mask = EvTyp_StateChange_Mask,
.receiver_fn = sclp_state_change .receiver_fn = sclp_state_change_cb
}; };
/* Calculate receive and send mask of currently registered listeners.
/* * Called while sclp_lock is locked. */
* SCLP quiesce event handler static inline void
*/ __sclp_get_mask(sccb_mask_t *receive_mask, sccb_mask_t *send_mask)
#ifdef CONFIG_SMP
static void
do_load_quiesce_psw(void * __unused)
{ {
static atomic_t cpuid = ATOMIC_INIT(-1); struct list_head *l;
psw_t quiesce_psw; struct sclp_register *t;
__u32 status;
int i; *receive_mask = 0;
*send_mask = 0;
if (atomic_compare_and_swap(-1, smp_processor_id(), &cpuid)) list_for_each(l, &sclp_reg_list) {
signal_processor(smp_processor_id(), sigp_stop); t = list_entry(l, struct sclp_register, list);
/* Wait for all other cpus to enter stopped state */ *receive_mask |= t->receive_mask;
i = 1; *send_mask |= t->send_mask;
while (i < NR_CPUS) {
if (!cpu_online(i)) {
i++;
continue;
}
switch (signal_processor_ps(&status, 0, i, sigp_sense)) {
case sigp_order_code_accepted:
case sigp_status_stored:
/* Check for stopped and check stop state */
if (status & 0x50)
i++;
break;
case sigp_busy:
break;
case sigp_not_operational:
i++;
break;
}
} }
/* Quiesce the last cpu with the special psw */
quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
quiesce_psw.addr = 0xfff;
__load_psw(quiesce_psw);
} }
static void /* Register event listener. Return 0 on success, non-zero otherwise. */
do_machine_quiesce(void) int
sclp_register(struct sclp_register *reg)
{ {
on_each_cpu(do_load_quiesce_psw, NULL, 0, 0); unsigned long flags;
sccb_mask_t receive_mask;
sccb_mask_t send_mask;
int rc;
rc = sclp_init();
if (rc)
return rc;
spin_lock_irqsave(&sclp_lock, flags);
/* Check event mask for collisions */
__sclp_get_mask(&receive_mask, &send_mask);
if (reg->receive_mask & receive_mask || reg->send_mask & send_mask) {
spin_unlock_irqrestore(&sclp_lock, flags);
return -EBUSY;
}
/* Trigger initial state change callback */
reg->sclp_receive_mask = 0;
reg->sclp_send_mask = 0;
list_add(&reg->list, &sclp_reg_list);
spin_unlock_irqrestore(&sclp_lock, flags);
rc = sclp_init_mask(1);
if (rc) {
spin_lock_irqsave(&sclp_lock, flags);
list_del(&reg->list);
spin_unlock_irqrestore(&sclp_lock, flags);
}
return rc;
} }
#else
static void EXPORT_SYMBOL(sclp_register);
do_machine_quiesce(void)
/* Unregister event listener. */
void
sclp_unregister(struct sclp_register *reg)
{ {
psw_t quiesce_psw; unsigned long flags;
quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT; spin_lock_irqsave(&sclp_lock, flags);
quiesce_psw.addr = 0xfff; list_del(&reg->list);
__load_psw(quiesce_psw); spin_unlock_irqrestore(&sclp_lock, flags);
sclp_init_mask(1);
} }
#endif
extern void ctrl_alt_del(void); EXPORT_SYMBOL(sclp_unregister);
static void /* Remove event buffers which are marked processed. Return the number of
sclp_quiesce(struct evbuf_header *evbuf) * remaining event buffers. */
int
sclp_remove_processed(struct sccb_header *sccb)
{ {
/* struct evbuf_header *evbuf;
* We got a "shutdown" request. int unprocessed;
* Add a call to an appropriate "shutdown" routine here. This u16 remaining;
* routine should set all PSWs to 'disabled-wait', 'stopped'
* or 'check-stopped' - except 1 PSW which needs to carry a evbuf = (struct evbuf_header *) (sccb + 1);
* special bit pattern called 'quiesce PSW'. unprocessed = 0;
*/ remaining = sccb->length - sizeof(struct sccb_header);
_machine_restart = (void *) do_machine_quiesce; while (remaining > 0) {
_machine_halt = do_machine_quiesce; remaining -= evbuf->length;
_machine_power_off = do_machine_quiesce; if (evbuf->flags & 0x80) {
ctrl_alt_del(); sccb->length -= evbuf->length;
memcpy(evbuf, (void *) ((addr_t) evbuf + evbuf->length),
remaining);
} else {
unprocessed++;
evbuf = (struct evbuf_header *)
((addr_t) evbuf + evbuf->length);
}
}
return unprocessed;
} }
static struct sclp_register sclp_quiesce_event = { EXPORT_SYMBOL(sclp_remove_processed);
.receive_mask = EvTyp_SigQuiesce_Mask,
.receiver_fn = sclp_quiesce
};
/* initialisation of SCLP */
struct init_sccb { struct init_sccb {
struct sccb_header header; struct sccb_header header;
u16 _reserved; u16 _reserved;
...@@ -581,273 +602,314 @@ struct init_sccb { ...@@ -581,273 +602,314 @@ struct init_sccb {
sccb_mask_t sclp_receive_mask; sccb_mask_t sclp_receive_mask;
} __attribute__((packed)); } __attribute__((packed));
static void sclp_init_mask_retry(unsigned long); /* Prepare init mask request. Called while sclp_lock is locked. */
static inline void
static int __sclp_make_init_req(u32 receive_mask, u32 send_mask)
sclp_init_mask(void)
{ {
unsigned long flags;
struct init_sccb *sccb; struct init_sccb *sccb;
struct sclp_req *req;
struct list_head *l;
struct sclp_register *t;
int rc;
sccb = (struct init_sccb *) sclp_init_sccb; sccb = (struct init_sccb *) sclp_init_sccb;
/* stick the request structure to the end of the init sccb page */ clear_page(sccb);
req = (struct sclp_req *) ((addr_t) sccb + PAGE_SIZE) - 1; memset(&sclp_init_req, 0, sizeof(struct sclp_req));
sclp_init_req.command = SCLP_CMDW_WRITEMASK;
/* SCLP setup concerning receiving and sending Event Buffers */ sclp_init_req.status = SCLP_REQ_FILLED;
req->command = SCLP_CMDW_WRITEMASK; sclp_init_req.start_count = 0;
req->status = SCLP_REQ_QUEUED; sclp_init_req.callback = NULL;
req->callback = NULL; sclp_init_req.callback_data = NULL;
req->sccb = sccb; sclp_init_req.sccb = sccb;
/* setup sccb for writemask command */
memset(sccb, 0, sizeof(struct init_sccb));
sccb->header.length = sizeof(struct init_sccb); sccb->header.length = sizeof(struct init_sccb);
sccb->mask_length = sizeof(sccb_mask_t); sccb->mask_length = sizeof(sccb_mask_t);
/* copy in the sccb mask of the registered event types */ sccb->receive_mask = receive_mask;
spin_lock_irqsave(&sclp_lock, flags); sccb->send_mask = send_mask;
if (!test_bit(SCLP_SHUTDOWN, &sclp_status)) {
list_for_each(l, &sclp_reg_list) {
t = list_entry(l, struct sclp_register, list);
sccb->receive_mask |= t->receive_mask;
sccb->send_mask |= t->send_mask;
}
}
sccb->sclp_receive_mask = 0; sccb->sclp_receive_mask = 0;
sccb->sclp_send_mask = 0; sccb->sclp_send_mask = 0;
if (test_bit(SCLP_INIT, &sclp_status)) { }
/* add request to sclp queue */
list_add_tail(&req->list, &sclp_req_queue); /* Start init mask request. If calculate is non-zero, calculate the mask as
* requested by registered listeners. Use zero mask otherwise. Return 0 on
* success, non-zero otherwise. */
static int
sclp_init_mask(int calculate)
{
unsigned long flags;
struct init_sccb *sccb = (struct init_sccb *) sclp_init_sccb;
sccb_mask_t receive_mask;
sccb_mask_t send_mask;
int retry;
int rc;
unsigned long wait;
spin_lock_irqsave(&sclp_lock, flags);
/* Check if interface is in appropriate state */
if (sclp_mask_state != sclp_mask_state_idle) {
spin_unlock_irqrestore(&sclp_lock, flags);
return -EBUSY;
}
if (sclp_activation_state == sclp_activation_state_inactive) {
spin_unlock_irqrestore(&sclp_lock, flags);
return -EINVAL;
}
sclp_mask_state = sclp_mask_state_initializing;
/* Determine mask */
if (calculate)
__sclp_get_mask(&receive_mask, &send_mask);
else {
receive_mask = 0;
send_mask = 0;
}
rc = -EIO;
for (retry = 0; retry <= SCLP_MASK_RETRY; retry++) {
/* Prepare request */
__sclp_make_init_req(receive_mask, send_mask);
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
/* and start if SCLP is idle */ if (sclp_add_request(&sclp_init_req)) {
sclp_start_request(); /* Try again later */
/* now wait for completion */ wait = jiffies + SCLP_BUSY_INTERVAL * HZ;
while (req->status != SCLP_REQ_DONE && while (time_before(jiffies, wait))
req->status != SCLP_REQ_FAILED) sclp_sync_wait();
spin_lock_irqsave(&sclp_lock, flags);
continue;
}
while (sclp_init_req.status != SCLP_REQ_DONE &&
sclp_init_req.status != SCLP_REQ_FAILED)
sclp_sync_wait(); sclp_sync_wait();
spin_lock_irqsave(&sclp_lock, flags); spin_lock_irqsave(&sclp_lock, flags);
} else { if (sclp_init_req.status == SCLP_REQ_DONE &&
/* sccb->header.response_code == 0x20) {
* Special case for the very first write mask command. /* Successful request */
* The interrupt handler is not removing request from if (calculate) {
* the request queue and doesn't call callbacks yet sclp_receive_mask = sccb->sclp_receive_mask;
* because there might be an pending old interrupt sclp_send_mask = sccb->sclp_send_mask;
* after a Re-IPL. We have to receive and ignore it. } else {
*/ sclp_receive_mask = 0;
do { sclp_send_mask = 0;
rc = __service_call(req->command, req->sccb); }
if (rc == 0)
set_bit(SCLP_RUNNING, &sclp_status);
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
if (rc == -EIO) sclp_dispatch_state_change();
return -ENOSYS;
sclp_sync_wait();
spin_lock_irqsave(&sclp_lock, flags); spin_lock_irqsave(&sclp_lock, flags);
} while (rc == -EBUSY); rc = 0;
} break;
if (sccb->header.response_code != 0x0020) {
/* WRITEMASK failed - we cannot rely on receiving a state
change event, so initially, polling is the only alternative
for us to ever become operational. */
if (!test_bit(SCLP_SHUTDOWN, &sclp_status) &&
(!timer_pending(&retry_timer) ||
!mod_timer(&retry_timer,
jiffies + SCLP_INIT_POLL_INTERVAL*HZ))) {
retry_timer.function = sclp_init_mask_retry;
retry_timer.data = 0;
retry_timer.expires = jiffies +
SCLP_INIT_POLL_INTERVAL*HZ;
add_timer(&retry_timer);
} }
} else {
sclp_receive_mask = sccb->sclp_receive_mask;
sclp_send_mask = sccb->sclp_send_mask;
__sclp_notify_state_change();
} }
sclp_mask_state = sclp_mask_state_idle;
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
return 0; return rc;
}
static void
sclp_init_mask_retry(unsigned long data)
{
sclp_init_mask();
} }
/* Reboot event handler - reset send and receive mask to prevent pending SCLP /* Deactivate SCLP interface. On success, new requests will be rejected,
* events from interfering with rebooted system. */ * events will no longer be dispatched. Return 0 on success, non-zero
static int * otherwise. */
sclp_reboot_event(struct notifier_block *this, unsigned long event, void *ptr) int
sclp_deactivate(void)
{ {
unsigned long flags; unsigned long flags;
int rc;
/* Note: need spinlock to maintain atomicity when accessing global
* variables. */
spin_lock_irqsave(&sclp_lock, flags); spin_lock_irqsave(&sclp_lock, flags);
set_bit(SCLP_SHUTDOWN, &sclp_status); /* Deactivate can only be called when active */
if (sclp_activation_state != sclp_activation_state_active) {
spin_unlock_irqrestore(&sclp_lock, flags);
return -EINVAL;
}
sclp_activation_state = sclp_activation_state_deactivating;
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
sclp_init_mask(); rc = sclp_init_mask(0);
return NOTIFY_DONE; spin_lock_irqsave(&sclp_lock, flags);
if (rc == 0)
sclp_activation_state = sclp_activation_state_inactive;
else
sclp_activation_state = sclp_activation_state_active;
spin_unlock_irqrestore(&sclp_lock, flags);
return rc;
} }
static struct notifier_block sclp_reboot_notifier = { EXPORT_SYMBOL(sclp_deactivate);
.notifier_call = sclp_reboot_event
};
/* /* Reactivate SCLP interface after sclp_deactivate. On success, new
* sclp setup function. Called early (no kmalloc!) from sclp_console_init(). * requests will be accepted, events will be dispatched again. Return 0 on
*/ * success, non-zero otherwise. */
static int int
sclp_init(void) sclp_reactivate(void)
{ {
unsigned long flags;
int rc; int rc;
if (test_bit(SCLP_INIT, &sclp_status)) spin_lock_irqsave(&sclp_lock, flags);
/* Already initialized. */ /* Reactivate can only be called when inactive */
return 0; if (sclp_activation_state != sclp_activation_state_inactive) {
spin_unlock_irqrestore(&sclp_lock, flags);
spin_lock_init(&sclp_lock); return -EINVAL;
INIT_LIST_HEAD(&sclp_req_queue); }
sclp_activation_state = sclp_activation_state_activating;
/* init event list */ spin_unlock_irqrestore(&sclp_lock, flags);
INIT_LIST_HEAD(&sclp_reg_list); rc = sclp_init_mask(1);
list_add(&sclp_state_change_event.list, &sclp_reg_list); spin_lock_irqsave(&sclp_lock, flags);
list_add(&sclp_quiesce_event.list, &sclp_reg_list); if (rc == 0)
sclp_activation_state = sclp_activation_state_active;
rc = register_reboot_notifier(&sclp_reboot_notifier); else
if (rc) sclp_activation_state = sclp_activation_state_inactive;
return rc; spin_unlock_irqrestore(&sclp_lock, flags);
return rc;
}
/* EXPORT_SYMBOL(sclp_reactivate);
* request the 0x2401 external interrupt
* The sclp driver is initialized early (before kmalloc works). We
* need to use register_early_external_interrupt.
*/
if (register_early_external_interrupt(0x2401, sclp_interrupt_handler,
&ext_int_info_hwc) != 0)
return -EBUSY;
/* enable service-signal external interruptions, /* Handler for external interruption used during initialization. Modify
* Control Register 0 bit 22 := 1 * request state to done. */
* (besides PSW bit 7 must be set to 1 sometimes for external static void
* interruptions) sclp_check_handler(struct pt_regs *regs, __u16 code)
*/ {
ctl_set_bit(0, 9); u32 finished_sccb;
init_timer(&retry_timer); finished_sccb = S390_lowcore.ext_params & 0xfffffff8;
init_timer(&sclp_busy_timer); /* Is this the interrupt we are waiting for? */
/* do the initial write event mask */ if (finished_sccb == 0)
rc = sclp_init_mask(); return;
if (rc == 0) { if (finished_sccb != (u32) (addr_t) sclp_init_sccb) {
/* Ok, now everything is setup right. */ printk(KERN_WARNING SCLP_HEADER "unsolicited interrupt "
set_bit(SCLP_INIT, &sclp_status); "for buffer at 0x%x\n", finished_sccb);
return 0; return;
} }
spin_lock(&sclp_lock);
/* The sclp_init_mask failed. SCLP is broken, unregister and exit. */ if (sclp_running_state == sclp_running_state_running) {
ctl_clear_bit(0,9); sclp_init_req.status = SCLP_REQ_DONE;
unregister_early_external_interrupt(0x2401, sclp_interrupt_handler, sclp_running_state = sclp_running_state_idle;
&ext_int_info_hwc); }
spin_unlock(&sclp_lock);
return rc;
} }
/* /* Initial init mask request timed out. Modify request state to failed. */
* Register the SCLP event listener identified by REG. Return 0 on success. static void
* Some error codes and their meaning: sclp_check_timeout(unsigned long data)
*
* -ENODEV = SCLP interface is not supported on this machine
* -EBUSY = there is already a listener registered for the requested
* event type
* -EIO = SCLP interface is currently not operational
*/
int
sclp_register(struct sclp_register *reg)
{ {
unsigned long flags; unsigned long flags;
struct list_head *l;
struct sclp_register *t;
if (!MACHINE_HAS_SCLP)
return -ENODEV;
if (!test_bit(SCLP_INIT, &sclp_status))
sclp_init();
spin_lock_irqsave(&sclp_lock, flags); spin_lock_irqsave(&sclp_lock, flags);
/* check already registered event masks for collisions */ if (sclp_running_state == sclp_running_state_running) {
list_for_each(l, &sclp_reg_list) { sclp_init_req.status = SCLP_REQ_FAILED;
t = list_entry(l, struct sclp_register, list); sclp_running_state = sclp_running_state_idle;
if (t->receive_mask & reg->receive_mask ||
t->send_mask & reg->send_mask) {
spin_unlock_irqrestore(&sclp_lock, flags);
return -EBUSY;
}
} }
/*
* set present mask to 0 to trigger state change
* callback in sclp_init_mask
*/
reg->sclp_receive_mask = 0;
reg->sclp_send_mask = 0;
list_add(&reg->list, &sclp_reg_list);
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
sclp_init_mask();
return 0;
} }
/* /* Perform a check of the SCLP interface. Return zero if the interface is
* Unregister the SCLP event listener identified by REG. * available and there are no pending requests from a previous instance.
*/ * Return non-zero otherwise. */
void static int
sclp_unregister(struct sclp_register *reg) sclp_check_interface(void)
{ {
struct init_sccb *sccb;
unsigned long flags; unsigned long flags;
int retry;
int rc;
spin_lock_irqsave(&sclp_lock, flags); spin_lock_irqsave(&sclp_lock, flags);
list_del(&reg->list); /* Prepare init mask command */
rc = register_early_external_interrupt(0x2401, sclp_check_handler,
&ext_int_info_hwc);
if (rc) {
spin_unlock_irqrestore(&sclp_lock, flags);
return rc;
}
for (retry = 0; retry <= SCLP_INIT_RETRY; retry++) {
__sclp_make_init_req(0, 0);
sccb = (struct init_sccb *) sclp_init_req.sccb;
rc = service_call(sclp_init_req.command, sccb);
if (rc == -EIO)
break;
sclp_init_req.status = SCLP_REQ_RUNNING;
sclp_running_state = sclp_running_state_running;
__sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
sclp_check_timeout, 0);
spin_unlock_irqrestore(&sclp_lock, flags);
/* Enable service-signal interruption - needs to happen
* with IRQs enabled. */
ctl_set_bit(0, 9);
/* Wait for signal from interrupt or timeout */
sclp_sync_wait();
/* Disable service-signal interruption - needs to happen
* with IRQs enabled. */
ctl_clear_bit(0,9);
spin_lock_irqsave(&sclp_lock, flags);
del_timer(&sclp_request_timer);
if (sclp_init_req.status == SCLP_REQ_DONE &&
sccb->header.response_code == 0x20) {
rc = 0;
break;
} else
rc = -EBUSY;
}
unregister_early_external_interrupt(0x2401, sclp_check_handler,
&ext_int_info_hwc);
spin_unlock_irqrestore(&sclp_lock, flags); spin_unlock_irqrestore(&sclp_lock, flags);
sclp_init_mask(); return rc;
} }
#define SCLP_EVBUF_PROCESSED 0x80 /* Reboot event handler. Reset send and receive mask to prevent pending SCLP
* events from interfering with rebooted system. */
static int
sclp_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
{
sclp_deactivate();
return NOTIFY_DONE;
}
/* static struct notifier_block sclp_reboot_notifier = {
* Traverse array of event buffers contained in SCCB and remove all buffers .notifier_call = sclp_reboot_event
* with a set "processed" flag. Return the number of unprocessed buffers. };
*/
int /* Initialize SCLP driver. Return zero if driver is operational, non-zero
sclp_remove_processed(struct sccb_header *sccb) * otherwise. */
static int
sclp_init(void)
{ {
struct evbuf_header *evbuf; unsigned long flags;
int unprocessed; int rc;
u16 remaining;
evbuf = (struct evbuf_header *) (sccb + 1); if (!MACHINE_HAS_SCLP)
unprocessed = 0; return -ENODEV;
remaining = sccb->length - sizeof(struct sccb_header); spin_lock_irqsave(&sclp_lock, flags);
while (remaining > 0) { /* Check for previous or running initialization */
remaining -= evbuf->length; if (sclp_init_state != sclp_init_state_uninitialized) {
if (evbuf->flags & SCLP_EVBUF_PROCESSED) { spin_unlock_irqrestore(&sclp_lock, flags);
sccb->length -= evbuf->length; return 0;
memcpy((void *) evbuf,
(void *) ((addr_t) evbuf + evbuf->length),
remaining);
} else {
unprocessed++;
evbuf = (struct evbuf_header *)
((addr_t) evbuf + evbuf->length);
}
} }
sclp_init_state = sclp_init_state_initializing;
return unprocessed; /* Set up variables */
INIT_LIST_HEAD(&sclp_req_queue);
INIT_LIST_HEAD(&sclp_reg_list);
list_add(&sclp_state_change_event.list, &sclp_reg_list);
init_timer(&sclp_request_timer);
/* Check interface */
spin_unlock_irqrestore(&sclp_lock, flags);
rc = sclp_check_interface();
spin_lock_irqsave(&sclp_lock, flags);
if (rc) {
sclp_init_state = sclp_init_state_uninitialized;
spin_unlock_irqrestore(&sclp_lock, flags);
return rc;
}
/* Register reboot handler */
rc = register_reboot_notifier(&sclp_reboot_notifier);
if (rc) {
sclp_init_state = sclp_init_state_uninitialized;
spin_unlock_irqrestore(&sclp_lock, flags);
return rc;
}
/* Register interrupt handler */
rc = register_early_external_interrupt(0x2401, sclp_interrupt_handler,
&ext_int_info_hwc);
if (rc) {
unregister_reboot_notifier(&sclp_reboot_notifier);
sclp_init_state = sclp_init_state_uninitialized;
spin_unlock_irqrestore(&sclp_lock, flags);
return rc;
}
sclp_init_state = sclp_init_state_initialized;
spin_unlock_irqrestore(&sclp_lock, flags);
/* Enable service-signal external interruption - needs to happen with
* IRQs enabled. */
ctl_set_bit(0, 9);
sclp_init_mask(1);
return 0;
} }
module_init(sclp_init);
EXPORT_SYMBOL(sclp_add_request);
EXPORT_SYMBOL(sclp_sync_wait);
EXPORT_SYMBOL(sclp_register);
EXPORT_SYMBOL(sclp_unregister);
EXPORT_SYMBOL(sclp_error_message);
...@@ -95,6 +95,7 @@ struct sclp_req { ...@@ -95,6 +95,7 @@ struct sclp_req {
sclp_cmdw_t command; /* sclp command to execute */ sclp_cmdw_t command; /* sclp command to execute */
void *sccb; /* pointer to the sccb to execute */ void *sccb; /* pointer to the sccb to execute */
char status; /* status of this request */ char status; /* status of this request */
int start_count; /* number of SVCs done for this req */
/* Callback that is called after reaching final status. */ /* Callback that is called after reaching final status. */
void (*callback)(struct sclp_req *, void *data); void (*callback)(struct sclp_req *, void *data);
void *callback_data; void *callback_data;
...@@ -123,12 +124,13 @@ struct sclp_register { ...@@ -123,12 +124,13 @@ struct sclp_register {
}; };
/* externals from sclp.c */ /* externals from sclp.c */
void sclp_add_request(struct sclp_req *req); int sclp_add_request(struct sclp_req *req);
void sclp_sync_wait(void); void sclp_sync_wait(void);
int sclp_register(struct sclp_register *reg); int sclp_register(struct sclp_register *reg);
void sclp_unregister(struct sclp_register *reg); void sclp_unregister(struct sclp_register *reg);
char *sclp_error_message(u16 response_code);
int sclp_remove_processed(struct sccb_header *sccb); int sclp_remove_processed(struct sccb_header *sccb);
int sclp_deactivate(void);
int sclp_reactivate(void);
/* useful inlines */ /* useful inlines */
......
...@@ -49,25 +49,22 @@ static void ...@@ -49,25 +49,22 @@ static void
sclp_conbuf_callback(struct sclp_buffer *buffer, int rc) sclp_conbuf_callback(struct sclp_buffer *buffer, int rc)
{ {
unsigned long flags; unsigned long flags;
struct sclp_buffer *next;
void *page; void *page;
/* Ignore return code - because console-writes aren't critical, do {
we do without a sophisticated error recovery mechanism. */ page = sclp_unmake_buffer(buffer);
page = sclp_unmake_buffer(buffer); spin_lock_irqsave(&sclp_con_lock, flags);
spin_lock_irqsave(&sclp_con_lock, flags); /* Remove buffer from outqueue */
/* Remove buffer from outqueue */ list_del(&buffer->list);
list_del(&buffer->list); sclp_con_buffer_count--;
sclp_con_buffer_count--; list_add_tail((struct list_head *) page, &sclp_con_pages);
list_add_tail((struct list_head *) page, &sclp_con_pages); /* Check if there is a pending buffer on the out queue. */
/* Check if there is a pending buffer on the out queue. */ buffer = NULL;
next = NULL; if (!list_empty(&sclp_con_outqueue))
if (!list_empty(&sclp_con_outqueue)) buffer = list_entry(sclp_con_outqueue.next,
next = list_entry(sclp_con_outqueue.next, struct sclp_buffer, list);
struct sclp_buffer, list); spin_unlock_irqrestore(&sclp_con_lock, flags);
spin_unlock_irqrestore(&sclp_con_lock, flags); } while (buffer && sclp_emit_buffer(buffer, sclp_conbuf_callback));
if (next != NULL)
sclp_emit_buffer(next, sclp_conbuf_callback);
} }
static inline void static inline void
...@@ -76,6 +73,7 @@ sclp_conbuf_emit(void) ...@@ -76,6 +73,7 @@ sclp_conbuf_emit(void)
struct sclp_buffer* buffer; struct sclp_buffer* buffer;
unsigned long flags; unsigned long flags;
int count; int count;
int rc;
spin_lock_irqsave(&sclp_con_lock, flags); spin_lock_irqsave(&sclp_con_lock, flags);
buffer = sclp_conbuf; buffer = sclp_conbuf;
...@@ -87,8 +85,11 @@ sclp_conbuf_emit(void) ...@@ -87,8 +85,11 @@ sclp_conbuf_emit(void)
list_add_tail(&buffer->list, &sclp_con_outqueue); list_add_tail(&buffer->list, &sclp_con_outqueue);
count = sclp_con_buffer_count++; count = sclp_con_buffer_count++;
spin_unlock_irqrestore(&sclp_con_lock, flags); spin_unlock_irqrestore(&sclp_con_lock, flags);
if (count == 0) if (count)
sclp_emit_buffer(buffer, sclp_conbuf_callback); return;
rc = sclp_emit_buffer(buffer, sclp_conbuf_callback);
if (rc)
sclp_conbuf_callback(buffer, rc);
} }
/* /*
......
...@@ -196,18 +196,20 @@ cpi_module_init(void) ...@@ -196,18 +196,20 @@ cpi_module_init(void)
rc = sclp_register(&sclp_cpi_event); rc = sclp_register(&sclp_cpi_event);
if (rc) { if (rc) {
/* could not register sclp event. Die. */ /* could not register sclp event. Die. */
printk("cpi: could not register to hardware console.\n"); printk(KERN_WARNING "cpi: could not register to hardware "
"console.\n");
return -EINVAL; return -EINVAL;
} }
if (!(sclp_cpi_event.sclp_send_mask & EvTyp_CtlProgIdent_Mask)) { if (!(sclp_cpi_event.sclp_send_mask & EvTyp_CtlProgIdent_Mask)) {
printk("cpi: no control program identification support\n"); printk(KERN_WARNING "cpi: no control program identification "
"support\n");
sclp_unregister(&sclp_cpi_event); sclp_unregister(&sclp_cpi_event);
return -ENOTSUPP; return -ENOTSUPP;
} }
req = cpi_prepare_req(); req = cpi_prepare_req();
if (IS_ERR(req)) { if (IS_ERR(req)) {
printk("cpi: couldn't allocate request\n"); printk(KERN_WARNING "cpi: couldn't allocate request\n");
sclp_unregister(&sclp_cpi_event); sclp_unregister(&sclp_cpi_event);
return PTR_ERR(req); return PTR_ERR(req);
} }
...@@ -216,13 +218,20 @@ cpi_module_init(void) ...@@ -216,13 +218,20 @@ cpi_module_init(void)
sema_init(&sem, 0); sema_init(&sem, 0);
req->callback_data = &sem; req->callback_data = &sem;
/* Add request to sclp queue */ /* Add request to sclp queue */
sclp_add_request(req); rc = sclp_add_request(req);
if (rc) {
printk(KERN_WARNING "cpi: could not start request\n");
cpi_free_req(req);
sclp_unregister(&sclp_cpi_event);
return rc;
}
/* make "insmod" sleep until callback arrives */ /* make "insmod" sleep until callback arrives */
down(&sem); down(&sem);
rc = ((struct cpi_sccb *) req->sccb)->header.response_code; rc = ((struct cpi_sccb *) req->sccb)->header.response_code;
if (rc != 0x0020) { if (rc != 0x0020) {
printk("cpi: failed with response code 0x%x\n", rc); printk(KERN_WARNING "cpi: failed with response code 0x%x\n",
rc);
rc = -ECOMM; rc = -ECOMM;
} else } else
rc = 0; rc = 0;
......
/*
* drivers/s390/char/sclp_quiesce.c
* signal quiesce handler
*
* (C) Copyright IBM Corp. 1999,2004
* Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
* Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/cpumask.h>
#include <linux/smp.h>
#include <linux/init.h>
#include <asm/atomic.h>
#include <asm/ptrace.h>
#include <asm/sigp.h>
#include "sclp.h"
#ifdef CONFIG_SMP
/* Signal completion of shutdown process. All CPUs except the first to enter
* this function: go to stopped state. First CPU: wait until all other
* CPUs are in stopped or check stop state. Afterwards, load special PSW
* to indicate completion. */
static void
do_load_quiesce_psw(void * __unused)
{
static atomic_t cpuid = ATOMIC_INIT(-1);
psw_t quiesce_psw;
__u32 status;
int i;
if (atomic_compare_and_swap(-1, smp_processor_id(), &cpuid))
signal_processor(smp_processor_id(), sigp_stop);
/* Wait for all other cpus to enter stopped state */
i = 1;
while (i < NR_CPUS) {
if (!cpu_online(i)) {
i++;
continue;
}
switch (signal_processor_ps(&status, 0, i, sigp_sense)) {
case sigp_order_code_accepted:
case sigp_status_stored:
/* Check for stopped and check stop state */
if (status & 0x50)
i++;
break;
case sigp_busy:
break;
case sigp_not_operational:
i++;
break;
}
}
/* Quiesce the last cpu with the special psw */
quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
quiesce_psw.addr = 0xfff;
__load_psw(quiesce_psw);
}
/* Shutdown handler. Perform shutdown function on all CPUs. */
static void
do_machine_quiesce(void)
{
on_each_cpu(do_load_quiesce_psw, NULL, 0, 0);
}
#else
/* Shutdown handler. Signal completion of shutdown by loading special PSW. */
static void
do_machine_quiesce(void)
{
psw_t quiesce_psw;
quiesce_psw.mask = PSW_BASE_BITS | PSW_MASK_WAIT;
quiesce_psw.addr = 0xfff;
__load_psw(quiesce_psw);
}
#endif
extern void ctrl_alt_del(void);
/* Handler for quiesce event. Start shutdown procedure. */
static void
sclp_quiesce_handler(struct evbuf_header *evbuf)
{
_machine_restart = (void *) do_machine_quiesce;
_machine_halt = do_machine_quiesce;
_machine_power_off = do_machine_quiesce;
ctrl_alt_del();
}
static struct sclp_register sclp_quiesce_event = {
.receive_mask = EvTyp_SigQuiesce_Mask,
.receiver_fn = sclp_quiesce_handler
};
/* Initialize quiesce driver. */
static int __init
sclp_quiesce_init(void)
{
int rc;
rc = sclp_register(&sclp_quiesce_event);
if (rc)
printk(KERN_WARNING "sclp: could not register quiesce handler "
"(rc=%d)\n", rc);
return rc;
}
module_init(sclp_quiesce_init);
...@@ -54,7 +54,6 @@ sclp_make_buffer(void *page, unsigned short columns, unsigned short htab) ...@@ -54,7 +54,6 @@ sclp_make_buffer(void *page, unsigned short columns, unsigned short htab)
buffer = ((struct sclp_buffer *) ((addr_t) sccb + PAGE_SIZE)) - 1; buffer = ((struct sclp_buffer *) ((addr_t) sccb + PAGE_SIZE)) - 1;
buffer->sccb = sccb; buffer->sccb = sccb;
buffer->retry_count = 0; buffer->retry_count = 0;
init_timer(&buffer->retry_timer);
buffer->mto_number = 0; buffer->mto_number = 0;
buffer->mto_char_sum = 0; buffer->mto_char_sum = 0;
buffer->current_line = NULL; buffer->current_line = NULL;
...@@ -365,17 +364,7 @@ sclp_rw_init(void) ...@@ -365,17 +364,7 @@ sclp_rw_init(void)
return rc; return rc;
} }
static void #define SCLP_BUFFER_MAX_RETRY 1
sclp_buffer_retry(unsigned long data)
{
struct sclp_buffer *buffer = (struct sclp_buffer *) data;
buffer->request.status = SCLP_REQ_FILLED;
buffer->sccb->header.response_code = 0x0000;
sclp_add_request(&buffer->request);
}
#define SCLP_BUFFER_MAX_RETRY 5
#define SCLP_BUFFER_RETRY_INTERVAL 2
/* /*
* second half of Write Event Data-function that has to be done after * second half of Write Event Data-function that has to be done after
...@@ -404,7 +393,7 @@ sclp_writedata_callback(struct sclp_req *request, void *data) ...@@ -404,7 +393,7 @@ sclp_writedata_callback(struct sclp_req *request, void *data)
break; break;
case 0x0340: /* Contained SCLP equipment check */ case 0x0340: /* Contained SCLP equipment check */
if (buffer->retry_count++ > SCLP_BUFFER_MAX_RETRY) { if (++buffer->retry_count > SCLP_BUFFER_MAX_RETRY) {
rc = -EIO; rc = -EIO;
break; break;
} }
...@@ -413,26 +402,26 @@ sclp_writedata_callback(struct sclp_req *request, void *data) ...@@ -413,26 +402,26 @@ sclp_writedata_callback(struct sclp_req *request, void *data)
/* not all buffers were processed */ /* not all buffers were processed */
sccb->header.response_code = 0x0000; sccb->header.response_code = 0x0000;
buffer->request.status = SCLP_REQ_FILLED; buffer->request.status = SCLP_REQ_FILLED;
sclp_add_request(request); rc = sclp_add_request(request);
return; if (rc == 0)
} return;
rc = 0; } else
rc = 0;
break; break;
case 0x0040: /* SCLP equipment check */ case 0x0040: /* SCLP equipment check */
case 0x05f0: /* Target resource in improper state */ case 0x05f0: /* Target resource in improper state */
if (buffer->retry_count++ > SCLP_BUFFER_MAX_RETRY) { if (++buffer->retry_count > SCLP_BUFFER_MAX_RETRY) {
rc = -EIO; rc = -EIO;
break; break;
} }
/* wait some time, then retry request */ /* retry request */
buffer->retry_timer.function = sclp_buffer_retry; sccb->header.response_code = 0x0000;
buffer->retry_timer.data = (unsigned long) buffer; buffer->request.status = SCLP_REQ_FILLED;
buffer->retry_timer.expires = jiffies + rc = sclp_add_request(request);
SCLP_BUFFER_RETRY_INTERVAL*HZ; if (rc == 0)
add_timer(&buffer->retry_timer); return;
return; break;
default: default:
if (sccb->header.response_code == 0x71f0) if (sccb->header.response_code == 0x71f0)
rc = -ENOMEM; rc = -ENOMEM;
...@@ -446,9 +435,10 @@ sclp_writedata_callback(struct sclp_req *request, void *data) ...@@ -446,9 +435,10 @@ sclp_writedata_callback(struct sclp_req *request, void *data)
/* /*
* Setup the request structure in the struct sclp_buffer to do SCLP Write * Setup the request structure in the struct sclp_buffer to do SCLP Write
* Event Data and pass the request to the core SCLP loop. * Event Data and pass the request to the core SCLP loop. Return zero on
* success, non-zero otherwise.
*/ */
void int
sclp_emit_buffer(struct sclp_buffer *buffer, sclp_emit_buffer(struct sclp_buffer *buffer,
void (*callback)(struct sclp_buffer *, int)) void (*callback)(struct sclp_buffer *, int))
{ {
...@@ -459,11 +449,8 @@ sclp_emit_buffer(struct sclp_buffer *buffer, ...@@ -459,11 +449,8 @@ sclp_emit_buffer(struct sclp_buffer *buffer,
sclp_finalize_mto(buffer); sclp_finalize_mto(buffer);
/* Are there messages in the output buffer ? */ /* Are there messages in the output buffer ? */
if (buffer->mto_number == 0) { if (buffer->mto_number == 0)
if (callback != NULL) return -EIO;
callback(buffer, 0);
return;
}
sccb = buffer->sccb; sccb = buffer->sccb;
if (sclp_rw_event.sclp_send_mask & EvTyp_Msg_Mask) if (sclp_rw_event.sclp_send_mask & EvTyp_Msg_Mask)
...@@ -472,16 +459,13 @@ sclp_emit_buffer(struct sclp_buffer *buffer, ...@@ -472,16 +459,13 @@ sclp_emit_buffer(struct sclp_buffer *buffer,
else if (sclp_rw_event.sclp_send_mask & EvTyp_PMsgCmd_Mask) else if (sclp_rw_event.sclp_send_mask & EvTyp_PMsgCmd_Mask)
/* Use write priority message */ /* Use write priority message */
sccb->msg_buf.header.type = EvTyp_PMsgCmd; sccb->msg_buf.header.type = EvTyp_PMsgCmd;
else { else
if (callback != NULL) return -ENOSYS;
callback(buffer, -ENOSYS);
return;
}
buffer->request.command = SCLP_CMDW_WRITEDATA; buffer->request.command = SCLP_CMDW_WRITEDATA;
buffer->request.status = SCLP_REQ_FILLED; buffer->request.status = SCLP_REQ_FILLED;
buffer->request.callback = sclp_writedata_callback; buffer->request.callback = sclp_writedata_callback;
buffer->request.callback_data = buffer; buffer->request.callback_data = buffer;
buffer->request.sccb = sccb; buffer->request.sccb = sccb;
buffer->callback = callback; buffer->callback = callback;
sclp_add_request(&buffer->request); return sclp_add_request(&buffer->request);
} }
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#define __SCLP_RW_H__ #define __SCLP_RW_H__
#include <linux/list.h> #include <linux/list.h>
#include <linux/timer.h>
struct mto { struct mto {
u16 length; u16 length;
...@@ -74,7 +73,6 @@ struct sclp_buffer { ...@@ -74,7 +73,6 @@ struct sclp_buffer {
char *current_line; char *current_line;
int current_length; int current_length;
int retry_count; int retry_count;
struct timer_list retry_timer;
/* output format settings */ /* output format settings */
unsigned short columns; unsigned short columns;
unsigned short htab; unsigned short htab;
...@@ -90,7 +88,7 @@ struct sclp_buffer *sclp_make_buffer(void *, unsigned short, unsigned short); ...@@ -90,7 +88,7 @@ struct sclp_buffer *sclp_make_buffer(void *, unsigned short, unsigned short);
void *sclp_unmake_buffer(struct sclp_buffer *); void *sclp_unmake_buffer(struct sclp_buffer *);
int sclp_buffer_space(struct sclp_buffer *); int sclp_buffer_space(struct sclp_buffer *);
int sclp_write(struct sclp_buffer *buffer, const unsigned char *, int); int sclp_write(struct sclp_buffer *buffer, const unsigned char *, int);
void sclp_emit_buffer(struct sclp_buffer *,void (*)(struct sclp_buffer *,int)); int sclp_emit_buffer(struct sclp_buffer *,void (*)(struct sclp_buffer *,int));
void sclp_set_columns(struct sclp_buffer *, unsigned short); void sclp_set_columns(struct sclp_buffer *, unsigned short);
void sclp_set_htab(struct sclp_buffer *, unsigned short); void sclp_set_htab(struct sclp_buffer *, unsigned short);
int sclp_chars_in_buffer(struct sclp_buffer *); int sclp_chars_in_buffer(struct sclp_buffer *);
......
...@@ -255,25 +255,22 @@ static void ...@@ -255,25 +255,22 @@ static void
sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc) sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc)
{ {
unsigned long flags; unsigned long flags;
struct sclp_buffer *next;
void *page; void *page;
/* Ignore return code - because tty-writes aren't critical, do {
we do without a sophisticated error recovery mechanism. */ page = sclp_unmake_buffer(buffer);
page = sclp_unmake_buffer(buffer); spin_lock_irqsave(&sclp_tty_lock, flags);
spin_lock_irqsave(&sclp_tty_lock, flags); /* Remove buffer from outqueue */
/* Remove buffer from outqueue */ list_del(&buffer->list);
list_del(&buffer->list); sclp_tty_buffer_count--;
sclp_tty_buffer_count--; list_add_tail((struct list_head *) page, &sclp_tty_pages);
list_add_tail((struct list_head *) page, &sclp_tty_pages); /* Check if there is a pending buffer on the out queue. */
/* Check if there is a pending buffer on the out queue. */ buffer = NULL;
next = NULL; if (!list_empty(&sclp_tty_outqueue))
if (!list_empty(&sclp_tty_outqueue)) buffer = list_entry(sclp_tty_outqueue.next,
next = list_entry(sclp_tty_outqueue.next, struct sclp_buffer, list);
struct sclp_buffer, list); spin_unlock_irqrestore(&sclp_tty_lock, flags);
spin_unlock_irqrestore(&sclp_tty_lock, flags); } while (buffer && sclp_emit_buffer(buffer, sclp_ttybuf_callback));
if (next != NULL)
sclp_emit_buffer(next, sclp_ttybuf_callback);
wake_up(&sclp_tty_waitq); wake_up(&sclp_tty_waitq);
/* check if the tty needs a wake up call */ /* check if the tty needs a wake up call */
if (sclp_tty != NULL) { if (sclp_tty != NULL) {
...@@ -286,14 +283,17 @@ __sclp_ttybuf_emit(struct sclp_buffer *buffer) ...@@ -286,14 +283,17 @@ __sclp_ttybuf_emit(struct sclp_buffer *buffer)
{ {
unsigned long flags; unsigned long flags;
int count; int count;
int rc;
spin_lock_irqsave(&sclp_tty_lock, flags); spin_lock_irqsave(&sclp_tty_lock, flags);
list_add_tail(&buffer->list, &sclp_tty_outqueue); list_add_tail(&buffer->list, &sclp_tty_outqueue);
count = sclp_tty_buffer_count++; count = sclp_tty_buffer_count++;
spin_unlock_irqrestore(&sclp_tty_lock, flags); spin_unlock_irqrestore(&sclp_tty_lock, flags);
if (count)
if (count == 0) return;
sclp_emit_buffer(buffer, sclp_ttybuf_callback); rc = sclp_emit_buffer(buffer, sclp_ttybuf_callback);
if (rc)
sclp_ttybuf_callback(buffer, rc);
} }
/* /*
......
...@@ -42,7 +42,6 @@ struct sclp_vt220_request { ...@@ -42,7 +42,6 @@ struct sclp_vt220_request {
struct list_head list; struct list_head list;
struct sclp_req sclp_req; struct sclp_req sclp_req;
int retry_count; int retry_count;
struct timer_list retry_timer;
}; };
/* VT220 SCCB */ /* VT220 SCCB */
...@@ -96,7 +95,7 @@ static int sclp_vt220_initialized = 0; ...@@ -96,7 +95,7 @@ static int sclp_vt220_initialized = 0;
static int sclp_vt220_flush_later; static int sclp_vt220_flush_later;
static void sclp_vt220_receiver_fn(struct evbuf_header *evbuf); static void sclp_vt220_receiver_fn(struct evbuf_header *evbuf);
static void __sclp_vt220_emit(struct sclp_vt220_request *request); static int __sclp_vt220_emit(struct sclp_vt220_request *request);
static void sclp_vt220_emit_current(void); static void sclp_vt220_emit_current(void);
/* Registration structure for our interest in SCLP event buffers */ /* Registration structure for our interest in SCLP event buffers */
...@@ -116,25 +115,24 @@ static void ...@@ -116,25 +115,24 @@ static void
sclp_vt220_process_queue(struct sclp_vt220_request *request) sclp_vt220_process_queue(struct sclp_vt220_request *request)
{ {
unsigned long flags; unsigned long flags;
struct sclp_vt220_request *next;
void *page; void *page;
/* Put buffer back to list of empty buffers */ do {
page = request->sclp_req.sccb; /* Put buffer back to list of empty buffers */
spin_lock_irqsave(&sclp_vt220_lock, flags); page = request->sclp_req.sccb;
/* Move request from outqueue to empty queue */ spin_lock_irqsave(&sclp_vt220_lock, flags);
list_del(&request->list); /* Move request from outqueue to empty queue */
sclp_vt220_outqueue_count--; list_del(&request->list);
list_add_tail((struct list_head *) page, &sclp_vt220_empty); sclp_vt220_outqueue_count--;
/* Check if there is a pending buffer on the out queue. */ list_add_tail((struct list_head *) page, &sclp_vt220_empty);
next = NULL; /* Check if there is a pending buffer on the out queue. */
if (!list_empty(&sclp_vt220_outqueue)) request = NULL;
next = list_entry(sclp_vt220_outqueue.next, if (!list_empty(&sclp_vt220_outqueue))
struct sclp_vt220_request, list); request = list_entry(sclp_vt220_outqueue.next,
spin_unlock_irqrestore(&sclp_vt220_lock, flags); struct sclp_vt220_request, list);
if (next != NULL) spin_unlock_irqrestore(&sclp_vt220_lock, flags);
__sclp_vt220_emit(next); } while (request && __sclp_vt220_emit(request));
else if (sclp_vt220_flush_later) if (request == NULL && sclp_vt220_flush_later)
sclp_vt220_emit_current(); sclp_vt220_emit_current();
wake_up(&sclp_vt220_waitq); wake_up(&sclp_vt220_waitq);
/* Check if the tty needs a wake up call */ /* Check if the tty needs a wake up call */
...@@ -143,25 +141,7 @@ sclp_vt220_process_queue(struct sclp_vt220_request *request) ...@@ -143,25 +141,7 @@ sclp_vt220_process_queue(struct sclp_vt220_request *request)
} }
} }
/* #define SCLP_BUFFER_MAX_RETRY 1
* Retry sclp write request after waiting some time for an sclp equipment
* check to pass.
*/
static void
sclp_vt220_retry(unsigned long data)
{
struct sclp_vt220_request *request;
struct sclp_vt220_sccb *sccb;
request = (struct sclp_vt220_request *) data;
request->sclp_req.status = SCLP_REQ_FILLED;
sccb = (struct sclp_vt220_sccb *) request->sclp_req.sccb;
sccb->header.response_code = 0x0000;
sclp_add_request(&request->sclp_req);
}
#define SCLP_BUFFER_MAX_RETRY 5
#define SCLP_BUFFER_RETRY_INTERVAL 2
/* /*
* Callback through which the result of a write request is reported by the * Callback through which the result of a write request is reported by the
...@@ -189,29 +169,26 @@ sclp_vt220_callback(struct sclp_req *request, void *data) ...@@ -189,29 +169,26 @@ sclp_vt220_callback(struct sclp_req *request, void *data)
break; break;
case 0x0340: /* Contained SCLP equipment check */ case 0x0340: /* Contained SCLP equipment check */
if (vt220_request->retry_count++ > SCLP_BUFFER_MAX_RETRY) if (++vt220_request->retry_count > SCLP_BUFFER_MAX_RETRY)
break; break;
/* Remove processed buffers and requeue rest */ /* Remove processed buffers and requeue rest */
if (sclp_remove_processed((struct sccb_header *) sccb) > 0) { if (sclp_remove_processed((struct sccb_header *) sccb) > 0) {
/* Not all buffers were processed */ /* Not all buffers were processed */
sccb->header.response_code = 0x0000; sccb->header.response_code = 0x0000;
vt220_request->sclp_req.status = SCLP_REQ_FILLED; vt220_request->sclp_req.status = SCLP_REQ_FILLED;
sclp_add_request(request); if (sclp_add_request(request) == 0)
return; return;
} }
break; break;
case 0x0040: /* SCLP equipment check */ case 0x0040: /* SCLP equipment check */
if (vt220_request->retry_count++ > SCLP_BUFFER_MAX_RETRY) if (++vt220_request->retry_count > SCLP_BUFFER_MAX_RETRY)
break; break;
/* Wait some time, then retry request */ sccb->header.response_code = 0x0000;
vt220_request->retry_timer.function = sclp_vt220_retry; vt220_request->sclp_req.status = SCLP_REQ_FILLED;
vt220_request->retry_timer.data = if (sclp_add_request(request) == 0)
(unsigned long) vt220_request; return;
vt220_request->retry_timer.expires = break;
jiffies + SCLP_BUFFER_RETRY_INTERVAL*HZ;
add_timer(&vt220_request->retry_timer);
return;
default: default:
break; break;
...@@ -220,22 +197,22 @@ sclp_vt220_callback(struct sclp_req *request, void *data) ...@@ -220,22 +197,22 @@ sclp_vt220_callback(struct sclp_req *request, void *data)
} }
/* /*
* Emit vt220 request buffer to SCLP. * Emit vt220 request buffer to SCLP. Return zero on success, non-zero
* otherwise.
*/ */
static void static int
__sclp_vt220_emit(struct sclp_vt220_request *request) __sclp_vt220_emit(struct sclp_vt220_request *request)
{ {
if (!(sclp_vt220_register.sclp_send_mask & EvTyp_VT220Msg_Mask)) { if (!(sclp_vt220_register.sclp_send_mask & EvTyp_VT220Msg_Mask)) {
request->sclp_req.status = SCLP_REQ_FAILED; request->sclp_req.status = SCLP_REQ_FAILED;
sclp_vt220_callback(&request->sclp_req, (void *) request); return -EIO;
return;
} }
request->sclp_req.command = SCLP_CMDW_WRITEDATA; request->sclp_req.command = SCLP_CMDW_WRITEDATA;
request->sclp_req.status = SCLP_REQ_FILLED; request->sclp_req.status = SCLP_REQ_FILLED;
request->sclp_req.callback = sclp_vt220_callback; request->sclp_req.callback = sclp_vt220_callback;
request->sclp_req.callback_data = (void *) request; request->sclp_req.callback_data = (void *) request;
sclp_add_request(&request->sclp_req); return sclp_add_request(&request->sclp_req);
} }
/* /*
...@@ -253,12 +230,12 @@ sclp_vt220_emit(struct sclp_vt220_request *request) ...@@ -253,12 +230,12 @@ sclp_vt220_emit(struct sclp_vt220_request *request)
spin_unlock_irqrestore(&sclp_vt220_lock, flags); spin_unlock_irqrestore(&sclp_vt220_lock, flags);
/* Emit only the first buffer immediately - callback takes care of /* Emit only the first buffer immediately - callback takes care of
* the rest */ * the rest */
if (count == 0) if (count == 0 && __sclp_vt220_emit(request))
__sclp_vt220_emit(request); sclp_vt220_process_queue(request);
} }
/* /*
* Queue and emit current request. * Queue and emit current request. Return zero on success, non-zero otherwise.
*/ */
static void static void
sclp_vt220_emit_current(void) sclp_vt220_emit_current(void)
...@@ -300,7 +277,6 @@ sclp_vt220_initialize_page(void *page) ...@@ -300,7 +277,6 @@ sclp_vt220_initialize_page(void *page)
/* Place request structure at end of page */ /* Place request structure at end of page */
request = ((struct sclp_vt220_request *) request = ((struct sclp_vt220_request *)
((addr_t) page + PAGE_SIZE)) - 1; ((addr_t) page + PAGE_SIZE)) - 1;
init_timer(&request->retry_timer);
request->retry_count = 0; request->retry_count = 0;
request->sclp_req.sccb = page; request->sclp_req.sccb = page;
/* SCCB goes at start of page */ /* SCCB goes at start of page */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment