2017-11-06 17:11:51 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 Hollis Blanchard <hollisb@us.ibm.com>, IBM
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Host Virtual Serial Interface (HVSI) is a protocol between the hosted OS
|
|
|
|
* and the service processor on IBM pSeries servers. On these servers, there
|
|
|
|
* are no serial ports under the OS's control, and sometimes there is no other
|
|
|
|
* console available either. However, the service processor has two standard
|
|
|
|
* serial ports, so this over-complicated protocol allows the OS to control
|
|
|
|
* those ports by proxy.
|
|
|
|
*
|
|
|
|
* Besides data, the procotol supports the reading/writing of the serial
|
|
|
|
* port's DTR line, and the reading of the CD line. This is to allow the OS to
|
|
|
|
* control a modem attached to the service processor's serial port. Note that
|
|
|
|
* the OS cannot change the speed of the port through this protocol.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/sysrq.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <asm/hvcall.h>
|
|
|
|
#include <asm/hvconsole.h>
|
|
|
|
#include <asm/prom.h>
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/vio.h>
|
|
|
|
#include <asm/param.h>
|
2011-06-16 15:08:12 +00:00
|
|
|
#include <asm/hvsi.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define HVSI_MAJOR 229
|
|
|
|
#define HVSI_MINOR 128
|
|
|
|
#define MAX_NR_HVSI_CONSOLES 4
|
|
|
|
|
|
|
|
#define HVSI_TIMEOUT (5*HZ)
|
|
|
|
#define HVSI_VERSION 1
|
|
|
|
#define HVSI_MAX_PACKET 256
|
|
|
|
#define HVSI_MAX_READ 16
|
|
|
|
#define HVSI_MAX_OUTGOING_DATA 12
|
|
|
|
#define N_OUTBUF 12
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we pass data via two 8-byte registers, so we would like our char arrays
|
|
|
|
* properly aligned for those loads.
|
|
|
|
*/
|
|
|
|
#define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))
|
|
|
|
|
|
|
|
struct hvsi_struct {
|
2012-04-02 11:54:28 +00:00
|
|
|
struct tty_port port;
|
2006-11-22 14:57:56 +00:00
|
|
|
struct delayed_work writer;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct work_struct handshaker;
|
|
|
|
wait_queue_head_t emptyq; /* woken when outbuf is emptied */
|
|
|
|
wait_queue_head_t stateq; /* woken when HVSI state changes */
|
|
|
|
spinlock_t lock;
|
|
|
|
int index;
|
|
|
|
uint8_t throttle_buf[128];
|
|
|
|
uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */
|
|
|
|
/* inbuf is for packet reassembly. leave a little room for leftovers. */
|
|
|
|
uint8_t inbuf[HVSI_MAX_PACKET + HVSI_MAX_READ];
|
|
|
|
uint8_t *inbuf_end;
|
|
|
|
int n_throttle;
|
|
|
|
int n_outbuf;
|
|
|
|
uint32_t vtermno;
|
|
|
|
uint32_t virq;
|
|
|
|
atomic_t seqno; /* HVSI packet sequence number */
|
|
|
|
uint16_t mctrl;
|
|
|
|
uint8_t state; /* HVSI protocol state */
|
|
|
|
uint8_t flags;
|
|
|
|
#ifdef CONFIG_MAGIC_SYSRQ
|
|
|
|
uint8_t sysrq;
|
|
|
|
#endif /* CONFIG_MAGIC_SYSRQ */
|
|
|
|
};
|
|
|
|
static struct hvsi_struct hvsi_ports[MAX_NR_HVSI_CONSOLES];
|
|
|
|
|
|
|
|
static struct tty_driver *hvsi_driver;
|
|
|
|
static int hvsi_count;
|
|
|
|
static int (*hvsi_wait)(struct hvsi_struct *hp, int state);
|
|
|
|
|
|
|
|
enum HVSI_PROTOCOL_STATE {
|
|
|
|
HVSI_CLOSED,
|
|
|
|
HVSI_WAIT_FOR_VER_RESPONSE,
|
|
|
|
HVSI_WAIT_FOR_VER_QUERY,
|
|
|
|
HVSI_OPEN,
|
|
|
|
HVSI_WAIT_FOR_MCTRL_RESPONSE,
|
|
|
|
HVSI_FSP_DIED,
|
|
|
|
};
|
|
|
|
#define HVSI_CONSOLE 0x1
|
|
|
|
|
|
|
|
static inline int is_console(struct hvsi_struct *hp)
|
|
|
|
{
|
|
|
|
return hp->flags & HVSI_CONSOLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_open(struct hvsi_struct *hp)
|
|
|
|
{
|
|
|
|
/* if we're waiting for an mctrl then we're already open */
|
|
|
|
return (hp->state == HVSI_OPEN)
|
|
|
|
|| (hp->state == HVSI_WAIT_FOR_MCTRL_RESPONSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void print_state(struct hvsi_struct *hp)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
static const char *state_names[] = {
|
|
|
|
"HVSI_CLOSED",
|
|
|
|
"HVSI_WAIT_FOR_VER_RESPONSE",
|
|
|
|
"HVSI_WAIT_FOR_VER_QUERY",
|
|
|
|
"HVSI_OPEN",
|
|
|
|
"HVSI_WAIT_FOR_MCTRL_RESPONSE",
|
|
|
|
"HVSI_FSP_DIED",
|
|
|
|
};
|
2010-05-24 21:33:04 +00:00
|
|
|
const char *name = (hp->state < ARRAY_SIZE(state_names))
|
|
|
|
? state_names[hp->state] : "UNKNOWN";
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
pr_debug("hvsi%i: state = %s\n", hp->index, name);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void __set_state(struct hvsi_struct *hp, int state)
|
|
|
|
{
|
|
|
|
hp->state = state;
|
|
|
|
print_state(hp);
|
|
|
|
wake_up_all(&hp->stateq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void set_state(struct hvsi_struct *hp, int state)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
|
|
|
__set_state(hp, state);
|
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int len_packet(const uint8_t *packet)
|
|
|
|
{
|
|
|
|
return (int)((struct hvsi_header *)packet)->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_header(const uint8_t *packet)
|
|
|
|
{
|
|
|
|
struct hvsi_header *header = (struct hvsi_header *)packet;
|
|
|
|
return header->type >= VS_QUERY_RESPONSE_PACKET_HEADER;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int got_packet(const struct hvsi_struct *hp, uint8_t *packet)
|
|
|
|
{
|
|
|
|
if (hp->inbuf_end < packet + sizeof(struct hvsi_header))
|
|
|
|
return 0; /* don't even have the packet header */
|
|
|
|
|
|
|
|
if (hp->inbuf_end < (packet + len_packet(packet)))
|
|
|
|
return 0; /* don't have the rest of the packet */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* shift remaining bytes in packetbuf down */
|
|
|
|
static void compact_inbuf(struct hvsi_struct *hp, uint8_t *read_to)
|
|
|
|
{
|
|
|
|
int remaining = (int)(hp->inbuf_end - read_to);
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: %i chars remain\n", __func__, remaining);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (read_to != hp->inbuf)
|
|
|
|
memmove(hp->inbuf, read_to, remaining);
|
|
|
|
|
|
|
|
hp->inbuf_end = hp->inbuf + remaining;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define dbg_dump_packet(packet) dump_packet(packet)
|
|
|
|
#define dbg_dump_hex(data, len) dump_hex(data, len)
|
|
|
|
#else
|
|
|
|
#define dbg_dump_packet(packet) do { } while (0)
|
|
|
|
#define dbg_dump_hex(data, len) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void dump_hex(const uint8_t *data, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printk(" ");
|
|
|
|
for (i=0; i < len; i++)
|
|
|
|
printk("%.2x", data[i]);
|
|
|
|
|
|
|
|
printk("\n ");
|
|
|
|
for (i=0; i < len; i++) {
|
|
|
|
if (isprint(data[i]))
|
|
|
|
printk("%c", data[i]);
|
|
|
|
else
|
|
|
|
printk(".");
|
|
|
|
}
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_packet(uint8_t *packet)
|
|
|
|
{
|
|
|
|
struct hvsi_header *header = (struct hvsi_header *)packet;
|
|
|
|
|
|
|
|
printk("type 0x%x, len %i, seqno %i:\n", header->type, header->len,
|
|
|
|
header->seqno);
|
|
|
|
|
|
|
|
dump_hex(packet, header->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hvsi_read(struct hvsi_struct *hp, char *buf, int count)
|
|
|
|
{
|
|
|
|
unsigned long got;
|
|
|
|
|
2005-07-08 00:56:27 +00:00
|
|
|
got = hvc_get_chars(hp->vtermno, buf, count);
|
|
|
|
|
|
|
|
return got;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
|
2012-04-02 11:54:29 +00:00
|
|
|
struct tty_struct *tty, struct hvsi_struct **to_handshake)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct hvsi_control *header = (struct hvsi_control *)packet;
|
|
|
|
|
2015-07-31 09:29:50 +00:00
|
|
|
switch (be16_to_cpu(header->verb)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
case VSV_MODEM_CTL_UPDATE:
|
2015-07-31 09:29:50 +00:00
|
|
|
if ((be32_to_cpu(header->word) & HVSI_TSCD) == 0) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* CD went away; no more connection */
|
|
|
|
pr_debug("hvsi%i: CD dropped\n", hp->index);
|
|
|
|
hp->mctrl &= TIOCM_CD;
|
2012-04-02 11:54:29 +00:00
|
|
|
if (tty && !C_CLOCAL(tty))
|
|
|
|
tty_hangup(tty);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VSV_CLOSE_PROTOCOL:
|
|
|
|
pr_debug("hvsi%i: service processor came back\n", hp->index);
|
|
|
|
if (hp->state != HVSI_CLOSED) {
|
|
|
|
*to_handshake = hp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_WARNING "hvsi%i: unknown HVSI control packet: ",
|
|
|
|
hp->index);
|
|
|
|
dump_packet(packet);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hvsi_recv_response(struct hvsi_struct *hp, uint8_t *packet)
|
|
|
|
{
|
|
|
|
struct hvsi_query_response *resp = (struct hvsi_query_response *)packet;
|
2015-07-31 09:29:50 +00:00
|
|
|
uint32_t mctrl_word;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch (hp->state) {
|
|
|
|
case HVSI_WAIT_FOR_VER_RESPONSE:
|
|
|
|
__set_state(hp, HVSI_WAIT_FOR_VER_QUERY);
|
|
|
|
break;
|
|
|
|
case HVSI_WAIT_FOR_MCTRL_RESPONSE:
|
|
|
|
hp->mctrl = 0;
|
2015-07-31 09:29:50 +00:00
|
|
|
mctrl_word = be32_to_cpu(resp->u.mctrl_word);
|
|
|
|
if (mctrl_word & HVSI_TSDTR)
|
2005-04-16 22:20:36 +00:00
|
|
|
hp->mctrl |= TIOCM_DTR;
|
2015-07-31 09:29:50 +00:00
|
|
|
if (mctrl_word & HVSI_TSCD)
|
2005-04-16 22:20:36 +00:00
|
|
|
hp->mctrl |= TIOCM_CD;
|
|
|
|
__set_state(hp, HVSI_OPEN);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "hvsi%i: unexpected query response: ", hp->index);
|
|
|
|
dump_packet(packet);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* respond to service processor's version query */
|
|
|
|
static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
|
|
|
|
{
|
|
|
|
struct hvsi_query_response packet __ALIGNED__;
|
|
|
|
int wrote;
|
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
|
|
|
|
packet.hdr.len = sizeof(struct hvsi_query_response);
|
2015-07-31 09:29:50 +00:00
|
|
|
packet.hdr.seqno = cpu_to_be16(atomic_inc_return(&hp->seqno));
|
|
|
|
packet.verb = cpu_to_be16(VSV_SEND_VERSION_NUMBER);
|
2005-04-16 22:20:36 +00:00
|
|
|
packet.u.version = HVSI_VERSION;
|
2015-07-31 09:29:50 +00:00
|
|
|
packet.query_seqno = cpu_to_be16(query_seqno+1);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
|
|
|
|
dbg_dump_hex((uint8_t*)&packet, packet.hdr.len);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.hdr.len);
|
|
|
|
if (wrote != packet.hdr.len) {
|
2005-04-16 22:20:36 +00:00
|
|
|
printk(KERN_ERR "hvsi%i: couldn't send query response!\n",
|
|
|
|
hp->index);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hvsi_recv_query(struct hvsi_struct *hp, uint8_t *packet)
|
|
|
|
{
|
|
|
|
struct hvsi_query *query = (struct hvsi_query *)packet;
|
|
|
|
|
|
|
|
switch (hp->state) {
|
|
|
|
case HVSI_WAIT_FOR_VER_QUERY:
|
2015-07-31 09:29:50 +00:00
|
|
|
hvsi_version_respond(hp, be16_to_cpu(query->hdr.seqno));
|
2005-04-16 22:20:36 +00:00
|
|
|
__set_state(hp, HVSI_OPEN);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "hvsi%i: unexpected query: ", hp->index);
|
|
|
|
dump_packet(packet);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 14:53:03 +00:00
|
|
|
static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < len; i++) {
|
|
|
|
char c = buf[i];
|
|
|
|
#ifdef CONFIG_MAGIC_SYSRQ
|
|
|
|
if (c == '\0') {
|
|
|
|
hp->sysrq = 1;
|
|
|
|
continue;
|
|
|
|
} else if (hp->sysrq) {
|
2010-08-18 04:15:47 +00:00
|
|
|
handle_sysrq(c);
|
2005-04-16 22:20:36 +00:00
|
|
|
hp->sysrq = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_MAGIC_SYSRQ */
|
2013-01-03 14:53:03 +00:00
|
|
|
tty_insert_flip_char(&hp->port, c, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We could get 252 bytes of data at once here. But the tty layer only
|
|
|
|
* throttles us at TTY_THRESHOLD_THROTTLE (128) bytes, so we could overflow
|
|
|
|
* it. Accordingly we won't send more than 128 bytes at a time to the flip
|
|
|
|
* buffer, which will give the tty buffer a chance to throttle us. Should the
|
|
|
|
* value of TTY_THRESHOLD_THROTTLE change in n_tty.c, this code should be
|
|
|
|
* revisited.
|
|
|
|
*/
|
|
|
|
#define TTY_THRESHOLD_THROTTLE 128
|
2013-01-03 14:53:03 +00:00
|
|
|
static bool hvsi_recv_data(struct hvsi_struct *hp, const uint8_t *packet)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
const struct hvsi_header *header = (const struct hvsi_header *)packet;
|
|
|
|
const uint8_t *data = packet + sizeof(struct hvsi_header);
|
|
|
|
int datalen = header->len - sizeof(struct hvsi_header);
|
|
|
|
int overflow = datalen - TTY_THRESHOLD_THROTTLE;
|
|
|
|
|
|
|
|
pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data);
|
|
|
|
|
|
|
|
if (datalen == 0)
|
2012-04-02 11:54:29 +00:00
|
|
|
return false;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (overflow > 0) {
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
datalen = TTY_THRESHOLD_THROTTLE;
|
|
|
|
}
|
|
|
|
|
2013-01-03 14:53:03 +00:00
|
|
|
hvsi_insert_chars(hp, data, datalen);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (overflow > 0) {
|
|
|
|
/*
|
|
|
|
* we still have more data to deliver, so we need to save off the
|
|
|
|
* overflow and send it later
|
|
|
|
*/
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: deferring overflow\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
memcpy(hp->throttle_buf, data + TTY_THRESHOLD_THROTTLE, overflow);
|
|
|
|
hp->n_throttle = overflow;
|
|
|
|
}
|
|
|
|
|
2012-04-02 11:54:29 +00:00
|
|
|
return true;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns true/false indicating data successfully read from hypervisor.
|
|
|
|
* Used both to get packets for tty connections and to advance the state
|
|
|
|
* machine during console handshaking (in which case tty = NULL and we ignore
|
|
|
|
* incoming data).
|
|
|
|
*/
|
2012-04-02 11:54:29 +00:00
|
|
|
static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct *tty,
|
|
|
|
struct hvsi_struct **handshake)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
uint8_t *packet = hp->inbuf;
|
|
|
|
int chunklen;
|
2012-04-02 11:54:29 +00:00
|
|
|
bool flip = false;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
*handshake = NULL;
|
|
|
|
|
|
|
|
chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ);
|
|
|
|
if (chunklen == 0) {
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: 0-length read\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: got %i bytes\n", __func__, chunklen);
|
2005-04-16 22:20:36 +00:00
|
|
|
dbg_dump_hex(hp->inbuf_end, chunklen);
|
|
|
|
|
|
|
|
hp->inbuf_end += chunklen;
|
|
|
|
|
|
|
|
/* handle all completed packets */
|
|
|
|
while ((packet < hp->inbuf_end) && got_packet(hp, packet)) {
|
|
|
|
struct hvsi_header *header = (struct hvsi_header *)packet;
|
|
|
|
|
|
|
|
if (!is_header(packet)) {
|
|
|
|
printk(KERN_ERR "hvsi%i: got malformed packet\n", hp->index);
|
|
|
|
/* skip bytes until we find a header or run out of data */
|
|
|
|
while ((packet < hp->inbuf_end) && (!is_header(packet)))
|
|
|
|
packet++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: handling %i-byte packet\n", __func__,
|
2005-04-16 22:20:36 +00:00
|
|
|
len_packet(packet));
|
|
|
|
dbg_dump_packet(packet);
|
|
|
|
|
|
|
|
switch (header->type) {
|
|
|
|
case VS_DATA_PACKET_HEADER:
|
|
|
|
if (!is_open(hp))
|
|
|
|
break;
|
2013-01-03 14:53:03 +00:00
|
|
|
flip = hvsi_recv_data(hp, packet);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case VS_CONTROL_PACKET_HEADER:
|
2012-04-02 11:54:29 +00:00
|
|
|
hvsi_recv_control(hp, packet, tty, handshake);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
case VS_QUERY_RESPONSE_PACKET_HEADER:
|
|
|
|
hvsi_recv_response(hp, packet);
|
|
|
|
break;
|
|
|
|
case VS_QUERY_PACKET_HEADER:
|
|
|
|
hvsi_recv_query(hp, packet);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "hvsi%i: unknown HVSI packet type 0x%x\n",
|
|
|
|
hp->index, header->type);
|
|
|
|
dump_packet(packet);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
packet += len_packet(packet);
|
|
|
|
|
2012-04-02 11:54:29 +00:00
|
|
|
if (*handshake) {
|
|
|
|
pr_debug("%s: handshake\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compact_inbuf(hp, packet);
|
|
|
|
|
2012-04-02 11:54:29 +00:00
|
|
|
if (flip)
|
2013-01-03 14:53:06 +00:00
|
|
|
tty_flip_buffer_push(&hp->port);
|
2012-04-02 11:54:29 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-01-03 14:53:03 +00:00
|
|
|
static void hvsi_send_overflow(struct hvsi_struct *hp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: delivering %i bytes overflow\n", __func__,
|
2005-04-16 22:20:36 +00:00
|
|
|
hp->n_throttle);
|
|
|
|
|
2013-01-03 14:53:03 +00:00
|
|
|
hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle);
|
2005-04-16 22:20:36 +00:00
|
|
|
hp->n_throttle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* must get all pending data because we only get an irq on empty->non-empty
|
|
|
|
* transition
|
|
|
|
*/
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t hvsi_interrupt(int irq, void *arg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct hvsi_struct *hp = (struct hvsi_struct *)arg;
|
|
|
|
struct hvsi_struct *handshake;
|
2012-04-02 11:54:30 +00:00
|
|
|
struct tty_struct *tty;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
int again = 1;
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-04-02 11:54:30 +00:00
|
|
|
tty = tty_port_tty_get(&hp->port);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
while (again) {
|
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
2012-04-02 11:54:30 +00:00
|
|
|
again = hvsi_load_chunk(hp, tty, &handshake);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
|
|
|
|
if (handshake) {
|
|
|
|
pr_debug("hvsi%i: attempting re-handshake\n", handshake->index);
|
|
|
|
schedule_work(&handshake->handshaker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
2016-04-10 00:11:36 +00:00
|
|
|
if (tty && hp->n_throttle && !tty_throttled(tty)) {
|
2012-04-02 11:54:30 +00:00
|
|
|
/* we weren't hung up and we weren't throttled, so we can
|
|
|
|
* deliver the rest now */
|
2013-01-03 14:53:03 +00:00
|
|
|
hvsi_send_overflow(hp);
|
2013-01-03 14:53:06 +00:00
|
|
|
tty_flip_buffer_push(&hp->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
|
2012-04-02 11:54:30 +00:00
|
|
|
tty_kref_put(tty);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for boot console, before the irq handler is running */
|
|
|
|
static int __init poll_for_state(struct hvsi_struct *hp, int state)
|
|
|
|
{
|
|
|
|
unsigned long end_jiffies = jiffies + HVSI_TIMEOUT;
|
|
|
|
|
|
|
|
for (;;) {
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
hvsi_interrupt(hp->virq, (void *)hp); /* get pending data */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (hp->state == state)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mdelay(5);
|
|
|
|
if (time_after(jiffies, end_jiffies))
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for irq handler to change our state */
|
|
|
|
static int wait_for_state(struct hvsi_struct *hp, int state)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!wait_event_timeout(hp->stateq, (hp->state == state), HVSI_TIMEOUT))
|
|
|
|
ret = -EIO;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
|
|
|
|
{
|
|
|
|
struct hvsi_query packet __ALIGNED__;
|
|
|
|
int wrote;
|
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
packet.hdr.type = VS_QUERY_PACKET_HEADER;
|
|
|
|
packet.hdr.len = sizeof(struct hvsi_query);
|
2015-07-31 09:29:50 +00:00
|
|
|
packet.hdr.seqno = cpu_to_be16(atomic_inc_return(&hp->seqno));
|
|
|
|
packet.verb = cpu_to_be16(verb);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
|
|
|
|
dbg_dump_hex((uint8_t*)&packet, packet.hdr.len);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.hdr.len);
|
|
|
|
if (wrote != packet.hdr.len) {
|
2005-04-16 22:20:36 +00:00
|
|
|
printk(KERN_ERR "hvsi%i: couldn't send query (%i)!\n", hp->index,
|
|
|
|
wrote);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hvsi_get_mctrl(struct hvsi_struct *hp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
set_state(hp, HVSI_WAIT_FOR_MCTRL_RESPONSE);
|
|
|
|
hvsi_query(hp, VSV_SEND_MODEM_CTL_STATUS);
|
|
|
|
|
|
|
|
ret = hvsi_wait(hp, HVSI_OPEN);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "hvsi%i: didn't get modem flags\n", hp->index);
|
|
|
|
set_state(hp, HVSI_OPEN);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: mctrl 0x%x\n", __func__, hp->mctrl);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note that we can only set DTR */
|
|
|
|
static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
|
|
|
|
{
|
|
|
|
struct hvsi_control packet __ALIGNED__;
|
|
|
|
int wrote;
|
|
|
|
|
2015-07-31 09:29:50 +00:00
|
|
|
packet.hdr.type = VS_CONTROL_PACKET_HEADER;
|
|
|
|
packet.hdr.seqno = cpu_to_be16(atomic_inc_return(&hp->seqno));
|
2011-06-16 15:08:24 +00:00
|
|
|
packet.hdr.len = sizeof(struct hvsi_control);
|
2015-07-31 09:29:50 +00:00
|
|
|
packet.verb = cpu_to_be16(VSV_SET_MODEM_CTL);
|
|
|
|
packet.mask = cpu_to_be32(HVSI_TSDTR);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (mctrl & TIOCM_DTR)
|
2015-07-31 09:29:50 +00:00
|
|
|
packet.word = cpu_to_be32(HVSI_TSDTR);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
|
|
|
|
dbg_dump_hex((uint8_t*)&packet, packet.hdr.len);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.hdr.len);
|
|
|
|
if (wrote != packet.hdr.len) {
|
2005-04-16 22:20:36 +00:00
|
|
|
printk(KERN_ERR "hvsi%i: couldn't set DTR!\n", hp->index);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hvsi_drain_input(struct hvsi_struct *hp)
|
|
|
|
{
|
|
|
|
uint8_t buf[HVSI_MAX_READ] __ALIGNED__;
|
|
|
|
unsigned long end_jiffies = jiffies + HVSI_TIMEOUT;
|
|
|
|
|
|
|
|
while (time_before(end_jiffies, jiffies))
|
|
|
|
if (0 == hvsi_read(hp, buf, HVSI_MAX_READ))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hvsi_handshake(struct hvsi_struct *hp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We could have a CLOSE or other data waiting for us before we even try
|
|
|
|
* to open; try to throw it all away so we don't get confused. (CLOSE
|
|
|
|
* is the first message sent up the pipe when the FSP comes online. We
|
|
|
|
* need to distinguish between "it came up a while ago and we're the first
|
|
|
|
* user" and "it was just reset before it saw our handshake packet".)
|
|
|
|
*/
|
|
|
|
hvsi_drain_input(hp);
|
|
|
|
|
|
|
|
set_state(hp, HVSI_WAIT_FOR_VER_RESPONSE);
|
|
|
|
ret = hvsi_query(hp, VSV_SEND_VERSION_NUMBER);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "hvsi%i: couldn't send version query\n", hp->index);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = hvsi_wait(hp, HVSI_OPEN);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-22 14:57:56 +00:00
|
|
|
static void hvsi_handshaker(struct work_struct *work)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-11-22 14:57:56 +00:00
|
|
|
struct hvsi_struct *hp =
|
|
|
|
container_of(work, struct hvsi_struct, handshaker);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (hvsi_handshake(hp) >= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
printk(KERN_ERR "hvsi%i: re-handshaking failed\n", hp->index);
|
|
|
|
if (is_console(hp)) {
|
|
|
|
/*
|
|
|
|
* ttys will re-attempt the handshake via hvsi_open, but
|
|
|
|
* the console will not.
|
|
|
|
*/
|
|
|
|
printk(KERN_ERR "hvsi%i: lost console!\n", hp->index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
|
|
|
|
{
|
|
|
|
struct hvsi_data packet __ALIGNED__;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
|
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
packet.hdr.type = VS_DATA_PACKET_HEADER;
|
2015-07-31 09:29:50 +00:00
|
|
|
packet.hdr.seqno = cpu_to_be16(atomic_inc_return(&hp->seqno));
|
2011-06-16 15:08:24 +00:00
|
|
|
packet.hdr.len = count + sizeof(struct hvsi_header);
|
2005-04-16 22:20:36 +00:00
|
|
|
memcpy(&packet.data, buf, count);
|
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
ret = hvc_put_chars(hp->vtermno, (char *)&packet, packet.hdr.len);
|
|
|
|
if (ret == packet.hdr.len) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* return the number of chars written, not the packet length */
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
return ret; /* return any errors */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hvsi_close_protocol(struct hvsi_struct *hp)
|
|
|
|
{
|
|
|
|
struct hvsi_control packet __ALIGNED__;
|
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
packet.hdr.type = VS_CONTROL_PACKET_HEADER;
|
2015-07-31 09:29:50 +00:00
|
|
|
packet.hdr.seqno = cpu_to_be16(atomic_inc_return(&hp->seqno));
|
2011-06-16 15:08:24 +00:00
|
|
|
packet.hdr.len = 6;
|
2015-07-31 09:29:50 +00:00
|
|
|
packet.verb = cpu_to_be16(VSV_CLOSE_PROTOCOL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
|
|
|
|
dbg_dump_hex((uint8_t*)&packet, packet.hdr.len);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-06-16 15:08:24 +00:00
|
|
|
hvc_put_chars(hp->vtermno, (char *)&packet, packet.hdr.len);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hvsi_open(struct tty_struct *tty, struct file *filp)
|
|
|
|
{
|
|
|
|
struct hvsi_struct *hp;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-03-05 13:52:01 +00:00
|
|
|
hp = &hvsi_ports[tty->index];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
tty->driver_data = hp;
|
|
|
|
|
|
|
|
mb();
|
|
|
|
if (hp->state == HVSI_FSP_DIED)
|
|
|
|
return -EIO;
|
|
|
|
|
2012-04-02 11:54:30 +00:00
|
|
|
tty_port_tty_set(&hp->port, tty);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
2012-04-02 11:54:28 +00:00
|
|
|
hp->port.count++;
|
2005-04-16 22:20:36 +00:00
|
|
|
atomic_set(&hp->seqno, 0);
|
|
|
|
h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
|
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
|
|
|
|
if (is_console(hp))
|
|
|
|
return 0; /* this has already been handshaked as the console */
|
|
|
|
|
|
|
|
ret = hvsi_handshake(hp);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "%s: HVSI handshaking failed\n", tty->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = hvsi_get_mctrl(hp);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "%s: couldn't get initial modem flags\n", tty->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = hvsi_set_mctrl(hp, hp->mctrl | TIOCM_DTR);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "%s: couldn't set DTR\n", tty->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for hvsi_write_worker to empty hp->outbuf */
|
|
|
|
static void hvsi_flush_output(struct hvsi_struct *hp)
|
|
|
|
{
|
|
|
|
wait_event_timeout(hp->emptyq, (hp->n_outbuf <= 0), HVSI_TIMEOUT);
|
|
|
|
|
|
|
|
/* 'writer' could still be pending if it didn't see n_outbuf = 0 yet */
|
2010-12-24 14:59:07 +00:00
|
|
|
cancel_delayed_work_sync(&hp->writer);
|
2012-08-20 21:51:24 +00:00
|
|
|
flush_work(&hp->handshaker);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* it's also possible that our timeout expired and hvsi_write_worker
|
|
|
|
* didn't manage to push outbuf. poof.
|
|
|
|
*/
|
|
|
|
hp->n_outbuf = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hvsi_close(struct tty_struct *tty, struct file *filp)
|
|
|
|
{
|
|
|
|
struct hvsi_struct *hp = tty->driver_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (tty_hung_up_p(filp))
|
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
|
|
|
|
2012-04-02 11:54:28 +00:00
|
|
|
if (--hp->port.count == 0) {
|
2012-04-02 11:54:30 +00:00
|
|
|
tty_port_tty_set(&hp->port, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
|
|
|
|
|
|
|
|
/* only close down connection if it is not the console */
|
|
|
|
if (!is_console(hp)) {
|
|
|
|
h_vio_signal(hp->vtermno, VIO_IRQ_DISABLE); /* no more irqs */
|
|
|
|
__set_state(hp, HVSI_CLOSED);
|
|
|
|
/*
|
|
|
|
* any data delivered to the tty layer after this will be
|
|
|
|
* discarded (except for XON/XOFF)
|
|
|
|
*/
|
|
|
|
tty->closing = 1;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
|
|
|
|
/* let any existing irq handlers finish. no more will start. */
|
|
|
|
synchronize_irq(hp->virq);
|
|
|
|
|
|
|
|
/* hvsi_write_worker will re-schedule until outbuf is empty. */
|
|
|
|
hvsi_flush_output(hp);
|
|
|
|
|
|
|
|
/* tell FSP to stop sending data */
|
|
|
|
hvsi_close_protocol(hp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* drain anything FSP is still in the middle of sending, and let
|
|
|
|
* hvsi_handshake drain the rest on the next open.
|
|
|
|
*/
|
|
|
|
hvsi_drain_input(hp);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
|
|
|
}
|
2012-04-02 11:54:28 +00:00
|
|
|
} else if (hp->port.count < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
|
2012-04-02 11:54:28 +00:00
|
|
|
hp - hvsi_ports, hp->port.count);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hvsi_hangup(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct hvsi_struct *hp = tty->driver_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-04-02 11:54:30 +00:00
|
|
|
tty_port_tty_set(&hp->port, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-04-02 11:54:30 +00:00
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
2012-04-02 11:54:28 +00:00
|
|
|
hp->port.count = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
hp->n_outbuf = 0;
|
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called with hp->lock held */
|
|
|
|
static void hvsi_push(struct hvsi_struct *hp)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (hp->n_outbuf <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
n = hvsi_put_chars(hp, hp->outbuf, hp->n_outbuf);
|
|
|
|
if (n > 0) {
|
|
|
|
/* success */
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: wrote %i chars\n", __func__, n);
|
2005-04-16 22:20:36 +00:00
|
|
|
hp->n_outbuf = 0;
|
|
|
|
} else if (n == -EIO) {
|
|
|
|
__set_state(hp, HVSI_FSP_DIED);
|
|
|
|
printk(KERN_ERR "hvsi%i: service processor died\n", hp->index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* hvsi_write_worker will keep rescheduling itself until outbuf is empty */
|
2006-11-22 14:57:56 +00:00
|
|
|
static void hvsi_write_worker(struct work_struct *work)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-11-22 14:57:56 +00:00
|
|
|
struct hvsi_struct *hp =
|
|
|
|
container_of(work, struct hvsi_struct, writer.work);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
#ifdef DEBUG
|
|
|
|
static long start_j = 0;
|
|
|
|
|
|
|
|
if (start_j == 0)
|
|
|
|
start_j = jiffies;
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: %i chars in buffer\n", __func__, hp->n_outbuf);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!is_open(hp)) {
|
|
|
|
/*
|
|
|
|
* We could have a non-open connection if the service processor died
|
|
|
|
* while we were busily scheduling ourselves. In that case, it could
|
|
|
|
* be minutes before the service processor comes back, so only try
|
|
|
|
* again once a second.
|
|
|
|
*/
|
|
|
|
schedule_delayed_work(&hp->writer, HZ);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
hvsi_push(hp);
|
|
|
|
if (hp->n_outbuf > 0)
|
|
|
|
schedule_delayed_work(&hp->writer, 10);
|
|
|
|
else {
|
|
|
|
#ifdef DEBUG
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: outbuf emptied after %li jiffies\n", __func__,
|
2005-04-16 22:20:36 +00:00
|
|
|
jiffies - start_j);
|
|
|
|
start_j = 0;
|
|
|
|
#endif /* DEBUG */
|
|
|
|
wake_up_all(&hp->emptyq);
|
2013-03-07 12:12:29 +00:00
|
|
|
tty_port_tty_wakeup(&hp->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
}
|
|
|
|
|
2021-05-05 09:19:15 +00:00
|
|
|
static unsigned int hvsi_write_room(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-01-02 13:47:26 +00:00
|
|
|
struct hvsi_struct *hp = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return N_OUTBUF - hp->n_outbuf;
|
|
|
|
}
|
|
|
|
|
2021-05-05 09:19:19 +00:00
|
|
|
static unsigned int hvsi_chars_in_buffer(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-01-02 13:47:26 +00:00
|
|
|
struct hvsi_struct *hp = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return hp->n_outbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hvsi_write(struct tty_struct *tty,
|
|
|
|
const unsigned char *buf, int count)
|
|
|
|
{
|
|
|
|
struct hvsi_struct *hp = tty->driver_data;
|
|
|
|
const char *source = buf;
|
|
|
|
unsigned long flags;
|
|
|
|
int total = 0;
|
|
|
|
int origcount = count;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: %i chars in buffer\n", __func__, hp->n_outbuf);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!is_open(hp)) {
|
|
|
|
/* we're either closing or not yet open; don't accept data */
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: not open\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* when the hypervisor buffer (16K) fills, data will stay in hp->outbuf
|
|
|
|
* and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls
|
|
|
|
* will see there is no room in outbuf and return.
|
|
|
|
*/
|
2012-04-02 11:54:29 +00:00
|
|
|
while ((count > 0) && (hvsi_write_room(tty) > 0)) {
|
2021-05-05 09:19:15 +00:00
|
|
|
int chunksize = min_t(int, count, hvsi_write_room(tty));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
BUG_ON(hp->n_outbuf < 0);
|
|
|
|
memcpy(hp->outbuf + hp->n_outbuf, source, chunksize);
|
|
|
|
hp->n_outbuf += chunksize;
|
|
|
|
|
|
|
|
total += chunksize;
|
|
|
|
source += chunksize;
|
|
|
|
count -= chunksize;
|
|
|
|
hvsi_push(hp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hp->n_outbuf > 0) {
|
|
|
|
/*
|
|
|
|
* we weren't able to write it all to the hypervisor.
|
|
|
|
* schedule another push attempt.
|
|
|
|
*/
|
|
|
|
schedule_delayed_work(&hp->writer, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
|
|
|
|
if (total != origcount)
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s: wanted %i, only wrote %i\n", __func__, origcount,
|
2005-04-16 22:20:36 +00:00
|
|
|
total);
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I have never seen throttle or unthrottle called, so this little throttle
|
|
|
|
* buffering scheme may or may not work.
|
|
|
|
*/
|
|
|
|
static void hvsi_throttle(struct tty_struct *tty)
|
|
|
|
{
|
2009-01-02 13:47:26 +00:00
|
|
|
struct hvsi_struct *hp = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
h_vio_signal(hp->vtermno, VIO_IRQ_DISABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hvsi_unthrottle(struct tty_struct *tty)
|
|
|
|
{
|
2009-01-02 13:47:26 +00:00
|
|
|
struct hvsi_struct *hp = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2008-04-30 07:55:10 +00:00
|
|
|
pr_debug("%s\n", __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
|
|
|
if (hp->n_throttle) {
|
2013-01-03 14:53:03 +00:00
|
|
|
hvsi_send_overflow(hp);
|
2013-01-03 14:53:06 +00:00
|
|
|
tty_flip_buffer_push(&hp->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
|
|
|
|
|
|
|
|
h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
|
|
|
|
}
|
|
|
|
|
2011-02-14 16:26:14 +00:00
|
|
|
static int hvsi_tiocmget(struct tty_struct *tty)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-01-02 13:47:26 +00:00
|
|
|
struct hvsi_struct *hp = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
hvsi_get_mctrl(hp);
|
|
|
|
return hp->mctrl;
|
|
|
|
}
|
|
|
|
|
2011-02-14 16:26:50 +00:00
|
|
|
static int hvsi_tiocmset(struct tty_struct *tty,
|
|
|
|
unsigned int set, unsigned int clear)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-01-02 13:47:26 +00:00
|
|
|
struct hvsi_struct *hp = tty->driver_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned long flags;
|
|
|
|
uint16_t new_mctrl;
|
|
|
|
|
|
|
|
/* we can only alter DTR */
|
|
|
|
clear &= TIOCM_DTR;
|
|
|
|
set &= TIOCM_DTR;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&hp->lock, flags);
|
|
|
|
|
|
|
|
new_mctrl = (hp->mctrl & ~clear) | set;
|
|
|
|
|
|
|
|
if (hp->mctrl != new_mctrl) {
|
|
|
|
hvsi_set_mctrl(hp, new_mctrl);
|
|
|
|
hp->mctrl = new_mctrl;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&hp->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-02 09:17:18 +00:00
|
|
|
static const struct tty_operations hvsi_ops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = hvsi_open,
|
|
|
|
.close = hvsi_close,
|
|
|
|
.write = hvsi_write,
|
|
|
|
.hangup = hvsi_hangup,
|
|
|
|
.write_room = hvsi_write_room,
|
|
|
|
.chars_in_buffer = hvsi_chars_in_buffer,
|
|
|
|
.throttle = hvsi_throttle,
|
|
|
|
.unthrottle = hvsi_unthrottle,
|
|
|
|
.tiocmget = hvsi_tiocmget,
|
|
|
|
.tiocmset = hvsi_tiocmset,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init hvsi_init(void)
|
|
|
|
{
|
2021-07-23 07:43:12 +00:00
|
|
|
struct tty_driver *driver;
|
2021-07-23 07:43:11 +00:00
|
|
|
int i, ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-07-23 07:43:13 +00:00
|
|
|
driver = tty_alloc_driver(hvsi_count, TTY_DRIVER_REAL_RAW);
|
|
|
|
if (IS_ERR(driver))
|
|
|
|
return PTR_ERR(driver);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-07-23 07:43:12 +00:00
|
|
|
driver->driver_name = "hvsi";
|
|
|
|
driver->name = "hvsi";
|
|
|
|
driver->major = HVSI_MAJOR;
|
|
|
|
driver->minor_start = HVSI_MINOR;
|
|
|
|
driver->type = TTY_DRIVER_TYPE_SYSTEM;
|
|
|
|
driver->init_termios = tty_std_termios;
|
|
|
|
driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
|
|
|
|
driver->init_termios.c_ispeed = 9600;
|
|
|
|
driver->init_termios.c_ospeed = 9600;
|
|
|
|
tty_set_operations(driver, &hvsi_ops);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i=0; i < hvsi_count; i++) {
|
|
|
|
struct hvsi_struct *hp = &hvsi_ports[i];
|
|
|
|
int ret = 1;
|
|
|
|
|
2021-07-23 07:43:12 +00:00
|
|
|
tty_port_link_device(&hp->port, driver, i);
|
2012-08-07 19:47:51 +00:00
|
|
|
|
2011-09-22 08:59:15 +00:00
|
|
|
ret = request_irq(hp->virq, hvsi_interrupt, 0, "hvsi", hp);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ret)
|
|
|
|
printk(KERN_ERR "HVSI: couldn't reserve irq 0x%x (error %i)\n",
|
|
|
|
hp->virq, ret);
|
|
|
|
}
|
|
|
|
hvsi_wait = wait_for_state; /* irqs active now */
|
|
|
|
|
2021-07-23 07:43:12 +00:00
|
|
|
ret = tty_register_driver(driver);
|
2021-07-23 07:43:11 +00:00
|
|
|
if (ret) {
|
|
|
|
pr_err("Couldn't register hvsi console driver\n");
|
|
|
|
goto err_free_irq;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-07-23 07:43:12 +00:00
|
|
|
hvsi_driver = driver;
|
|
|
|
|
2006-04-12 20:19:50 +00:00
|
|
|
printk(KERN_DEBUG "HVSI: registered %i devices\n", hvsi_count);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return 0;
|
2021-07-23 07:43:11 +00:00
|
|
|
err_free_irq:
|
|
|
|
hvsi_wait = poll_for_state;
|
|
|
|
for (i = 0; i < hvsi_count; i++) {
|
|
|
|
struct hvsi_struct *hp = &hvsi_ports[i];
|
|
|
|
|
|
|
|
free_irq(hp->virq, hp);
|
|
|
|
}
|
2021-07-23 07:43:12 +00:00
|
|
|
tty_driver_kref_put(driver);
|
2021-07-23 07:43:11 +00:00
|
|
|
|
|
|
|
return ret;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
device_initcall(hvsi_init);
|
|
|
|
|
|
|
|
/***** console (not tty) code: *****/
|
|
|
|
|
|
|
|
static void hvsi_console_print(struct console *console, const char *buf,
|
|
|
|
unsigned int count)
|
|
|
|
{
|
|
|
|
struct hvsi_struct *hp = &hvsi_ports[console->index];
|
|
|
|
char c[HVSI_MAX_OUTGOING_DATA] __ALIGNED__;
|
|
|
|
unsigned int i = 0, n = 0;
|
|
|
|
int ret, donecr = 0;
|
|
|
|
|
|
|
|
mb();
|
|
|
|
if (!is_open(hp))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ugh, we have to translate LF -> CRLF ourselves, in place.
|
|
|
|
* copied from hvc_console.c:
|
|
|
|
*/
|
|
|
|
while (count > 0 || i > 0) {
|
|
|
|
if (count > 0 && i < sizeof(c)) {
|
|
|
|
if (buf[n] == '\n' && !donecr) {
|
|
|
|
c[i++] = '\r';
|
|
|
|
donecr = 1;
|
|
|
|
} else {
|
|
|
|
c[i++] = buf[n++];
|
|
|
|
donecr = 0;
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = hvsi_put_chars(hp, c, i);
|
|
|
|
if (ret < 0)
|
|
|
|
i = 0;
|
|
|
|
i -= ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct tty_driver *hvsi_console_device(struct console *console,
|
|
|
|
int *index)
|
|
|
|
{
|
|
|
|
*index = console->index;
|
|
|
|
return hvsi_driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init hvsi_console_setup(struct console *console, char *options)
|
|
|
|
{
|
2009-08-06 13:00:37 +00:00
|
|
|
struct hvsi_struct *hp;
|
2005-04-16 22:20:36 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (console->index < 0 || console->index >= hvsi_count)
|
2020-06-18 16:47:49 +00:00
|
|
|
return -EINVAL;
|
2009-08-06 13:00:37 +00:00
|
|
|
hp = &hvsi_ports[console->index];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* give the FSP a chance to change the baud rate when we re-open */
|
|
|
|
hvsi_close_protocol(hp);
|
|
|
|
|
|
|
|
ret = hvsi_handshake(hp);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = hvsi_get_mctrl(hp);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = hvsi_set_mctrl(hp, hp->mctrl | TIOCM_DTR);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
hp->flags |= HVSI_CONSOLE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-06 08:03:16 +00:00
|
|
|
static struct console hvsi_console = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.name = "hvsi",
|
|
|
|
.write = hvsi_console_print,
|
|
|
|
.device = hvsi_console_device,
|
|
|
|
.setup = hvsi_console_setup,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init hvsi_console_init(void)
|
|
|
|
{
|
|
|
|
struct device_node *vty;
|
|
|
|
|
|
|
|
hvsi_wait = poll_for_state; /* no irqs yet; must poll */
|
|
|
|
|
|
|
|
/* search device tree for vty nodes */
|
2012-12-04 05:16:18 +00:00
|
|
|
for_each_compatible_node(vty, "serial", "hvterm-protocol") {
|
2005-04-16 22:20:36 +00:00
|
|
|
struct hvsi_struct *hp;
|
2015-07-31 09:29:50 +00:00
|
|
|
const __be32 *vtermno, *irq;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-04-27 03:41:15 +00:00
|
|
|
vtermno = of_get_property(vty, "reg", NULL);
|
|
|
|
irq = of_get_property(vty, "interrupts", NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!vtermno || !irq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (hvsi_count >= MAX_NR_HVSI_CONSOLES) {
|
|
|
|
of_node_put(vty);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
hp = &hvsi_ports[hvsi_count];
|
2006-11-22 14:57:56 +00:00
|
|
|
INIT_DELAYED_WORK(&hp->writer, hvsi_write_worker);
|
|
|
|
INIT_WORK(&hp->handshaker, hvsi_handshaker);
|
2005-04-16 22:20:36 +00:00
|
|
|
init_waitqueue_head(&hp->emptyq);
|
|
|
|
init_waitqueue_head(&hp->stateq);
|
|
|
|
spin_lock_init(&hp->lock);
|
2012-04-02 11:54:28 +00:00
|
|
|
tty_port_init(&hp->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
hp->index = hvsi_count;
|
|
|
|
hp->inbuf_end = hp->inbuf;
|
|
|
|
hp->state = HVSI_CLOSED;
|
2015-07-31 09:29:50 +00:00
|
|
|
hp->vtermno = be32_to_cpup(vtermno);
|
|
|
|
hp->virq = irq_create_mapping(NULL, be32_to_cpup(irq));
|
2012-01-26 17:44:09 +00:00
|
|
|
if (hp->virq == 0) {
|
2005-04-16 22:20:36 +00:00
|
|
|
printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n",
|
2015-07-31 09:29:50 +00:00
|
|
|
__func__, be32_to_cpup(irq));
|
2012-11-15 08:49:56 +00:00
|
|
|
tty_port_destroy(&hp->port);
|
2005-04-16 22:20:36 +00:00
|
|
|
continue;
|
2006-07-03 11:36:01 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
hvsi_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hvsi_count)
|
2010-07-06 08:03:16 +00:00
|
|
|
register_console(&hvsi_console);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
console_initcall(hvsi_console_init);
|