hvsi.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  1. /*
  2. * Copyright (C) 2004 Hollis Blanchard <hollisb@us.ibm.com>, IBM
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. /* Host Virtual Serial Interface (HVSI) is a protocol between the hosted OS
  19. * and the service processor on IBM pSeries servers. On these servers, there
  20. * are no serial ports under the OS's control, and sometimes there is no other
  21. * console available either. However, the service processor has two standard
  22. * serial ports, so this over-complicated protocol allows the OS to control
  23. * those ports by proxy.
  24. *
  25. * Besides data, the procotol supports the reading/writing of the serial
  26. * port's DTR line, and the reading of the CD line. This is to allow the OS to
  27. * control a modem attached to the service processor's serial port. Note that
  28. * the OS cannot change the speed of the port through this protocol.
  29. */
  30. #undef DEBUG
  31. #include <linux/console.h>
  32. #include <linux/ctype.h>
  33. #include <linux/delay.h>
  34. #include <linux/init.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/module.h>
  37. #include <linux/major.h>
  38. #include <linux/kernel.h>
  39. #include <linux/spinlock.h>
  40. #include <linux/sysrq.h>
  41. #include <linux/tty.h>
  42. #include <linux/tty_flip.h>
  43. #include <asm/hvcall.h>
  44. #include <asm/hvconsole.h>
  45. #include <asm/prom.h>
  46. #include <asm/uaccess.h>
  47. #include <asm/vio.h>
  48. #include <asm/param.h>
  49. #define HVSI_MAJOR 229
  50. #define HVSI_MINOR 128
  51. #define MAX_NR_HVSI_CONSOLES 4
  52. #define HVSI_TIMEOUT (5*HZ)
  53. #define HVSI_VERSION 1
  54. #define HVSI_MAX_PACKET 256
  55. #define HVSI_MAX_READ 16
  56. #define HVSI_MAX_OUTGOING_DATA 12
  57. #define N_OUTBUF 12
  58. /*
  59. * we pass data via two 8-byte registers, so we would like our char arrays
  60. * properly aligned for those loads.
  61. */
  62. #define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))
  63. struct hvsi_struct {
  64. struct delayed_work writer;
  65. struct work_struct handshaker;
  66. wait_queue_head_t emptyq; /* woken when outbuf is emptied */
  67. wait_queue_head_t stateq; /* woken when HVSI state changes */
  68. spinlock_t lock;
  69. int index;
  70. struct tty_struct *tty;
  71. unsigned int count;
  72. uint8_t throttle_buf[128];
  73. uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */
  74. /* inbuf is for packet reassembly. leave a little room for leftovers. */
  75. uint8_t inbuf[HVSI_MAX_PACKET + HVSI_MAX_READ];
  76. uint8_t *inbuf_end;
  77. int n_throttle;
  78. int n_outbuf;
  79. uint32_t vtermno;
  80. uint32_t virq;
  81. atomic_t seqno; /* HVSI packet sequence number */
  82. uint16_t mctrl;
  83. uint8_t state; /* HVSI protocol state */
  84. uint8_t flags;
  85. #ifdef CONFIG_MAGIC_SYSRQ
  86. uint8_t sysrq;
  87. #endif /* CONFIG_MAGIC_SYSRQ */
  88. };
  89. static struct hvsi_struct hvsi_ports[MAX_NR_HVSI_CONSOLES];
  90. static struct tty_driver *hvsi_driver;
  91. static int hvsi_count;
  92. static int (*hvsi_wait)(struct hvsi_struct *hp, int state);
  93. enum HVSI_PROTOCOL_STATE {
  94. HVSI_CLOSED,
  95. HVSI_WAIT_FOR_VER_RESPONSE,
  96. HVSI_WAIT_FOR_VER_QUERY,
  97. HVSI_OPEN,
  98. HVSI_WAIT_FOR_MCTRL_RESPONSE,
  99. HVSI_FSP_DIED,
  100. };
  101. #define HVSI_CONSOLE 0x1
  102. #define VS_DATA_PACKET_HEADER 0xff
  103. #define VS_CONTROL_PACKET_HEADER 0xfe
  104. #define VS_QUERY_PACKET_HEADER 0xfd
  105. #define VS_QUERY_RESPONSE_PACKET_HEADER 0xfc
  106. /* control verbs */
  107. #define VSV_SET_MODEM_CTL 1 /* to service processor only */
  108. #define VSV_MODEM_CTL_UPDATE 2 /* from service processor only */
  109. #define VSV_CLOSE_PROTOCOL 3
  110. /* query verbs */
  111. #define VSV_SEND_VERSION_NUMBER 1
  112. #define VSV_SEND_MODEM_CTL_STATUS 2
  113. /* yes, these masks are not consecutive. */
  114. #define HVSI_TSDTR 0x01
  115. #define HVSI_TSCD 0x20
  116. struct hvsi_header {
  117. uint8_t type;
  118. uint8_t len;
  119. uint16_t seqno;
  120. } __attribute__((packed));
  121. struct hvsi_data {
  122. uint8_t type;
  123. uint8_t len;
  124. uint16_t seqno;
  125. uint8_t data[HVSI_MAX_OUTGOING_DATA];
  126. } __attribute__((packed));
  127. struct hvsi_control {
  128. uint8_t type;
  129. uint8_t len;
  130. uint16_t seqno;
  131. uint16_t verb;
  132. /* optional depending on verb: */
  133. uint32_t word;
  134. uint32_t mask;
  135. } __attribute__((packed));
  136. struct hvsi_query {
  137. uint8_t type;
  138. uint8_t len;
  139. uint16_t seqno;
  140. uint16_t verb;
  141. } __attribute__((packed));
  142. struct hvsi_query_response {
  143. uint8_t type;
  144. uint8_t len;
  145. uint16_t seqno;
  146. uint16_t verb;
  147. uint16_t query_seqno;
  148. union {
  149. uint8_t version;
  150. uint32_t mctrl_word;
  151. } u;
  152. } __attribute__((packed));
  153. static inline int is_console(struct hvsi_struct *hp)
  154. {
  155. return hp->flags & HVSI_CONSOLE;
  156. }
  157. static inline int is_open(struct hvsi_struct *hp)
  158. {
  159. /* if we're waiting for an mctrl then we're already open */
  160. return (hp->state == HVSI_OPEN)
  161. || (hp->state == HVSI_WAIT_FOR_MCTRL_RESPONSE);
  162. }
  163. static inline void print_state(struct hvsi_struct *hp)
  164. {
  165. #ifdef DEBUG
  166. static const char *state_names[] = {
  167. "HVSI_CLOSED",
  168. "HVSI_WAIT_FOR_VER_RESPONSE",
  169. "HVSI_WAIT_FOR_VER_QUERY",
  170. "HVSI_OPEN",
  171. "HVSI_WAIT_FOR_MCTRL_RESPONSE",
  172. "HVSI_FSP_DIED",
  173. };
  174. const char *name = state_names[hp->state];
  175. if (hp->state > ARRAY_SIZE(state_names))
  176. name = "UNKNOWN";
  177. pr_debug("hvsi%i: state = %s\n", hp->index, name);
  178. #endif /* DEBUG */
  179. }
  180. static inline void __set_state(struct hvsi_struct *hp, int state)
  181. {
  182. hp->state = state;
  183. print_state(hp);
  184. wake_up_all(&hp->stateq);
  185. }
  186. static inline void set_state(struct hvsi_struct *hp, int state)
  187. {
  188. unsigned long flags;
  189. spin_lock_irqsave(&hp->lock, flags);
  190. __set_state(hp, state);
  191. spin_unlock_irqrestore(&hp->lock, flags);
  192. }
  193. static inline int len_packet(const uint8_t *packet)
  194. {
  195. return (int)((struct hvsi_header *)packet)->len;
  196. }
  197. static inline int is_header(const uint8_t *packet)
  198. {
  199. struct hvsi_header *header = (struct hvsi_header *)packet;
  200. return header->type >= VS_QUERY_RESPONSE_PACKET_HEADER;
  201. }
  202. static inline int got_packet(const struct hvsi_struct *hp, uint8_t *packet)
  203. {
  204. if (hp->inbuf_end < packet + sizeof(struct hvsi_header))
  205. return 0; /* don't even have the packet header */
  206. if (hp->inbuf_end < (packet + len_packet(packet)))
  207. return 0; /* don't have the rest of the packet */
  208. return 1;
  209. }
  210. /* shift remaining bytes in packetbuf down */
  211. static void compact_inbuf(struct hvsi_struct *hp, uint8_t *read_to)
  212. {
  213. int remaining = (int)(hp->inbuf_end - read_to);
  214. pr_debug("%s: %i chars remain\n", __FUNCTION__, remaining);
  215. if (read_to != hp->inbuf)
  216. memmove(hp->inbuf, read_to, remaining);
  217. hp->inbuf_end = hp->inbuf + remaining;
  218. }
  219. #ifdef DEBUG
  220. #define dbg_dump_packet(packet) dump_packet(packet)
  221. #define dbg_dump_hex(data, len) dump_hex(data, len)
  222. #else
  223. #define dbg_dump_packet(packet) do { } while (0)
  224. #define dbg_dump_hex(data, len) do { } while (0)
  225. #endif
  226. static void dump_hex(const uint8_t *data, int len)
  227. {
  228. int i;
  229. printk(" ");
  230. for (i=0; i < len; i++)
  231. printk("%.2x", data[i]);
  232. printk("\n ");
  233. for (i=0; i < len; i++) {
  234. if (isprint(data[i]))
  235. printk("%c", data[i]);
  236. else
  237. printk(".");
  238. }
  239. printk("\n");
  240. }
  241. static void dump_packet(uint8_t *packet)
  242. {
  243. struct hvsi_header *header = (struct hvsi_header *)packet;
  244. printk("type 0x%x, len %i, seqno %i:\n", header->type, header->len,
  245. header->seqno);
  246. dump_hex(packet, header->len);
  247. }
  248. static int hvsi_read(struct hvsi_struct *hp, char *buf, int count)
  249. {
  250. unsigned long got;
  251. got = hvc_get_chars(hp->vtermno, buf, count);
  252. return got;
  253. }
  254. static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
  255. struct tty_struct **to_hangup, struct hvsi_struct **to_handshake)
  256. {
  257. struct hvsi_control *header = (struct hvsi_control *)packet;
  258. switch (header->verb) {
  259. case VSV_MODEM_CTL_UPDATE:
  260. if ((header->word & HVSI_TSCD) == 0) {
  261. /* CD went away; no more connection */
  262. pr_debug("hvsi%i: CD dropped\n", hp->index);
  263. hp->mctrl &= TIOCM_CD;
  264. /* If userland hasn't done an open(2) yet, hp->tty is NULL. */
  265. if (hp->tty && !(hp->tty->flags & CLOCAL))
  266. *to_hangup = hp->tty;
  267. }
  268. break;
  269. case VSV_CLOSE_PROTOCOL:
  270. pr_debug("hvsi%i: service processor came back\n", hp->index);
  271. if (hp->state != HVSI_CLOSED) {
  272. *to_handshake = hp;
  273. }
  274. break;
  275. default:
  276. printk(KERN_WARNING "hvsi%i: unknown HVSI control packet: ",
  277. hp->index);
  278. dump_packet(packet);
  279. break;
  280. }
  281. }
  282. static void hvsi_recv_response(struct hvsi_struct *hp, uint8_t *packet)
  283. {
  284. struct hvsi_query_response *resp = (struct hvsi_query_response *)packet;
  285. switch (hp->state) {
  286. case HVSI_WAIT_FOR_VER_RESPONSE:
  287. __set_state(hp, HVSI_WAIT_FOR_VER_QUERY);
  288. break;
  289. case HVSI_WAIT_FOR_MCTRL_RESPONSE:
  290. hp->mctrl = 0;
  291. if (resp->u.mctrl_word & HVSI_TSDTR)
  292. hp->mctrl |= TIOCM_DTR;
  293. if (resp->u.mctrl_word & HVSI_TSCD)
  294. hp->mctrl |= TIOCM_CD;
  295. __set_state(hp, HVSI_OPEN);
  296. break;
  297. default:
  298. printk(KERN_ERR "hvsi%i: unexpected query response: ", hp->index);
  299. dump_packet(packet);
  300. break;
  301. }
  302. }
  303. /* respond to service processor's version query */
  304. static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
  305. {
  306. struct hvsi_query_response packet __ALIGNED__;
  307. int wrote;
  308. packet.type = VS_QUERY_RESPONSE_PACKET_HEADER;
  309. packet.len = sizeof(struct hvsi_query_response);
  310. packet.seqno = atomic_inc_return(&hp->seqno);
  311. packet.verb = VSV_SEND_VERSION_NUMBER;
  312. packet.u.version = HVSI_VERSION;
  313. packet.query_seqno = query_seqno+1;
  314. pr_debug("%s: sending %i bytes\n", __FUNCTION__, packet.len);
  315. dbg_dump_hex((uint8_t*)&packet, packet.len);
  316. wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
  317. if (wrote != packet.len) {
  318. printk(KERN_ERR "hvsi%i: couldn't send query response!\n",
  319. hp->index);
  320. return -EIO;
  321. }
  322. return 0;
  323. }
  324. static void hvsi_recv_query(struct hvsi_struct *hp, uint8_t *packet)
  325. {
  326. struct hvsi_query *query = (struct hvsi_query *)packet;
  327. switch (hp->state) {
  328. case HVSI_WAIT_FOR_VER_QUERY:
  329. hvsi_version_respond(hp, query->seqno);
  330. __set_state(hp, HVSI_OPEN);
  331. break;
  332. default:
  333. printk(KERN_ERR "hvsi%i: unexpected query: ", hp->index);
  334. dump_packet(packet);
  335. break;
  336. }
  337. }
  338. static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len)
  339. {
  340. int i;
  341. for (i=0; i < len; i++) {
  342. char c = buf[i];
  343. #ifdef CONFIG_MAGIC_SYSRQ
  344. if (c == '\0') {
  345. hp->sysrq = 1;
  346. continue;
  347. } else if (hp->sysrq) {
  348. handle_sysrq(c, hp->tty);
  349. hp->sysrq = 0;
  350. continue;
  351. }
  352. #endif /* CONFIG_MAGIC_SYSRQ */
  353. tty_insert_flip_char(hp->tty, c, 0);
  354. }
  355. }
  356. /*
  357. * We could get 252 bytes of data at once here. But the tty layer only
  358. * throttles us at TTY_THRESHOLD_THROTTLE (128) bytes, so we could overflow
  359. * it. Accordingly we won't send more than 128 bytes at a time to the flip
  360. * buffer, which will give the tty buffer a chance to throttle us. Should the
  361. * value of TTY_THRESHOLD_THROTTLE change in n_tty.c, this code should be
  362. * revisited.
  363. */
  364. #define TTY_THRESHOLD_THROTTLE 128
  365. static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp,
  366. const uint8_t *packet)
  367. {
  368. const struct hvsi_header *header = (const struct hvsi_header *)packet;
  369. const uint8_t *data = packet + sizeof(struct hvsi_header);
  370. int datalen = header->len - sizeof(struct hvsi_header);
  371. int overflow = datalen - TTY_THRESHOLD_THROTTLE;
  372. pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data);
  373. if (datalen == 0)
  374. return NULL;
  375. if (overflow > 0) {
  376. pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __FUNCTION__);
  377. datalen = TTY_THRESHOLD_THROTTLE;
  378. }
  379. hvsi_insert_chars(hp, data, datalen);
  380. if (overflow > 0) {
  381. /*
  382. * we still have more data to deliver, so we need to save off the
  383. * overflow and send it later
  384. */
  385. pr_debug("%s: deferring overflow\n", __FUNCTION__);
  386. memcpy(hp->throttle_buf, data + TTY_THRESHOLD_THROTTLE, overflow);
  387. hp->n_throttle = overflow;
  388. }
  389. return hp->tty;
  390. }
  391. /*
  392. * Returns true/false indicating data successfully read from hypervisor.
  393. * Used both to get packets for tty connections and to advance the state
  394. * machine during console handshaking (in which case tty = NULL and we ignore
  395. * incoming data).
  396. */
  397. static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,
  398. struct tty_struct **hangup, struct hvsi_struct **handshake)
  399. {
  400. uint8_t *packet = hp->inbuf;
  401. int chunklen;
  402. *flip = NULL;
  403. *hangup = NULL;
  404. *handshake = NULL;
  405. chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ);
  406. if (chunklen == 0) {
  407. pr_debug("%s: 0-length read\n", __FUNCTION__);
  408. return 0;
  409. }
  410. pr_debug("%s: got %i bytes\n", __FUNCTION__, chunklen);
  411. dbg_dump_hex(hp->inbuf_end, chunklen);
  412. hp->inbuf_end += chunklen;
  413. /* handle all completed packets */
  414. while ((packet < hp->inbuf_end) && got_packet(hp, packet)) {
  415. struct hvsi_header *header = (struct hvsi_header *)packet;
  416. if (!is_header(packet)) {
  417. printk(KERN_ERR "hvsi%i: got malformed packet\n", hp->index);
  418. /* skip bytes until we find a header or run out of data */
  419. while ((packet < hp->inbuf_end) && (!is_header(packet)))
  420. packet++;
  421. continue;
  422. }
  423. pr_debug("%s: handling %i-byte packet\n", __FUNCTION__,
  424. len_packet(packet));
  425. dbg_dump_packet(packet);
  426. switch (header->type) {
  427. case VS_DATA_PACKET_HEADER:
  428. if (!is_open(hp))
  429. break;
  430. if (hp->tty == NULL)
  431. break; /* no tty buffer to put data in */
  432. *flip = hvsi_recv_data(hp, packet);
  433. break;
  434. case VS_CONTROL_PACKET_HEADER:
  435. hvsi_recv_control(hp, packet, hangup, handshake);
  436. break;
  437. case VS_QUERY_RESPONSE_PACKET_HEADER:
  438. hvsi_recv_response(hp, packet);
  439. break;
  440. case VS_QUERY_PACKET_HEADER:
  441. hvsi_recv_query(hp, packet);
  442. break;
  443. default:
  444. printk(KERN_ERR "hvsi%i: unknown HVSI packet type 0x%x\n",
  445. hp->index, header->type);
  446. dump_packet(packet);
  447. break;
  448. }
  449. packet += len_packet(packet);
  450. if (*hangup || *handshake) {
  451. pr_debug("%s: hangup or handshake\n", __FUNCTION__);
  452. /*
  453. * we need to send the hangup now before receiving any more data.
  454. * If we get "data, hangup, data", we can't deliver the second
  455. * data before the hangup.
  456. */
  457. break;
  458. }
  459. }
  460. compact_inbuf(hp, packet);
  461. return 1;
  462. }
  463. static void hvsi_send_overflow(struct hvsi_struct *hp)
  464. {
  465. pr_debug("%s: delivering %i bytes overflow\n", __FUNCTION__,
  466. hp->n_throttle);
  467. hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle);
  468. hp->n_throttle = 0;
  469. }
  470. /*
  471. * must get all pending data because we only get an irq on empty->non-empty
  472. * transition
  473. */
  474. static irqreturn_t hvsi_interrupt(int irq, void *arg)
  475. {
  476. struct hvsi_struct *hp = (struct hvsi_struct *)arg;
  477. struct tty_struct *flip;
  478. struct tty_struct *hangup;
  479. struct hvsi_struct *handshake;
  480. unsigned long flags;
  481. int again = 1;
  482. pr_debug("%s\n", __FUNCTION__);
  483. while (again) {
  484. spin_lock_irqsave(&hp->lock, flags);
  485. again = hvsi_load_chunk(hp, &flip, &hangup, &handshake);
  486. spin_unlock_irqrestore(&hp->lock, flags);
  487. /*
  488. * we have to call tty_flip_buffer_push() and tty_hangup() outside our
  489. * spinlock. But we also have to keep going until we've read all the
  490. * available data.
  491. */
  492. if (flip) {
  493. /* there was data put in the tty flip buffer */
  494. tty_flip_buffer_push(flip);
  495. flip = NULL;
  496. }
  497. if (hangup) {
  498. tty_hangup(hangup);
  499. }
  500. if (handshake) {
  501. pr_debug("hvsi%i: attempting re-handshake\n", handshake->index);
  502. schedule_work(&handshake->handshaker);
  503. }
  504. }
  505. spin_lock_irqsave(&hp->lock, flags);
  506. if (hp->tty && hp->n_throttle
  507. && (!test_bit(TTY_THROTTLED, &hp->tty->flags))) {
  508. /* we weren't hung up and we weren't throttled, so we can deliver the
  509. * rest now */
  510. flip = hp->tty;
  511. hvsi_send_overflow(hp);
  512. }
  513. spin_unlock_irqrestore(&hp->lock, flags);
  514. if (flip) {
  515. tty_flip_buffer_push(flip);
  516. }
  517. return IRQ_HANDLED;
  518. }
  519. /* for boot console, before the irq handler is running */
  520. static int __init poll_for_state(struct hvsi_struct *hp, int state)
  521. {
  522. unsigned long end_jiffies = jiffies + HVSI_TIMEOUT;
  523. for (;;) {
  524. hvsi_interrupt(hp->virq, (void *)hp); /* get pending data */
  525. if (hp->state == state)
  526. return 0;
  527. mdelay(5);
  528. if (time_after(jiffies, end_jiffies))
  529. return -EIO;
  530. }
  531. }
  532. /* wait for irq handler to change our state */
  533. static int wait_for_state(struct hvsi_struct *hp, int state)
  534. {
  535. int ret = 0;
  536. if (!wait_event_timeout(hp->stateq, (hp->state == state), HVSI_TIMEOUT))
  537. ret = -EIO;
  538. return ret;
  539. }
  540. static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
  541. {
  542. struct hvsi_query packet __ALIGNED__;
  543. int wrote;
  544. packet.type = VS_QUERY_PACKET_HEADER;
  545. packet.len = sizeof(struct hvsi_query);
  546. packet.seqno = atomic_inc_return(&hp->seqno);
  547. packet.verb = verb;
  548. pr_debug("%s: sending %i bytes\n", __FUNCTION__, packet.len);
  549. dbg_dump_hex((uint8_t*)&packet, packet.len);
  550. wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
  551. if (wrote != packet.len) {
  552. printk(KERN_ERR "hvsi%i: couldn't send query (%i)!\n", hp->index,
  553. wrote);
  554. return -EIO;
  555. }
  556. return 0;
  557. }
  558. static int hvsi_get_mctrl(struct hvsi_struct *hp)
  559. {
  560. int ret;
  561. set_state(hp, HVSI_WAIT_FOR_MCTRL_RESPONSE);
  562. hvsi_query(hp, VSV_SEND_MODEM_CTL_STATUS);
  563. ret = hvsi_wait(hp, HVSI_OPEN);
  564. if (ret < 0) {
  565. printk(KERN_ERR "hvsi%i: didn't get modem flags\n", hp->index);
  566. set_state(hp, HVSI_OPEN);
  567. return ret;
  568. }
  569. pr_debug("%s: mctrl 0x%x\n", __FUNCTION__, hp->mctrl);
  570. return 0;
  571. }
  572. /* note that we can only set DTR */
  573. static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
  574. {
  575. struct hvsi_control packet __ALIGNED__;
  576. int wrote;
  577. packet.type = VS_CONTROL_PACKET_HEADER,
  578. packet.seqno = atomic_inc_return(&hp->seqno);
  579. packet.len = sizeof(struct hvsi_control);
  580. packet.verb = VSV_SET_MODEM_CTL;
  581. packet.mask = HVSI_TSDTR;
  582. if (mctrl & TIOCM_DTR)
  583. packet.word = HVSI_TSDTR;
  584. pr_debug("%s: sending %i bytes\n", __FUNCTION__, packet.len);
  585. dbg_dump_hex((uint8_t*)&packet, packet.len);
  586. wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
  587. if (wrote != packet.len) {
  588. printk(KERN_ERR "hvsi%i: couldn't set DTR!\n", hp->index);
  589. return -EIO;
  590. }
  591. return 0;
  592. }
  593. static void hvsi_drain_input(struct hvsi_struct *hp)
  594. {
  595. uint8_t buf[HVSI_MAX_READ] __ALIGNED__;
  596. unsigned long end_jiffies = jiffies + HVSI_TIMEOUT;
  597. while (time_before(end_jiffies, jiffies))
  598. if (0 == hvsi_read(hp, buf, HVSI_MAX_READ))
  599. break;
  600. }
  601. static int hvsi_handshake(struct hvsi_struct *hp)
  602. {
  603. int ret;
  604. /*
  605. * We could have a CLOSE or other data waiting for us before we even try
  606. * to open; try to throw it all away so we don't get confused. (CLOSE
  607. * is the first message sent up the pipe when the FSP comes online. We
  608. * need to distinguish between "it came up a while ago and we're the first
  609. * user" and "it was just reset before it saw our handshake packet".)
  610. */
  611. hvsi_drain_input(hp);
  612. set_state(hp, HVSI_WAIT_FOR_VER_RESPONSE);
  613. ret = hvsi_query(hp, VSV_SEND_VERSION_NUMBER);
  614. if (ret < 0) {
  615. printk(KERN_ERR "hvsi%i: couldn't send version query\n", hp->index);
  616. return ret;
  617. }
  618. ret = hvsi_wait(hp, HVSI_OPEN);
  619. if (ret < 0)
  620. return ret;
  621. return 0;
  622. }
  623. static void hvsi_handshaker(struct work_struct *work)
  624. {
  625. struct hvsi_struct *hp =
  626. container_of(work, struct hvsi_struct, handshaker);
  627. if (hvsi_handshake(hp) >= 0)
  628. return;
  629. printk(KERN_ERR "hvsi%i: re-handshaking failed\n", hp->index);
  630. if (is_console(hp)) {
  631. /*
  632. * ttys will re-attempt the handshake via hvsi_open, but
  633. * the console will not.
  634. */
  635. printk(KERN_ERR "hvsi%i: lost console!\n", hp->index);
  636. }
  637. }
  638. static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
  639. {
  640. struct hvsi_data packet __ALIGNED__;
  641. int ret;
  642. BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
  643. packet.type = VS_DATA_PACKET_HEADER;
  644. packet.seqno = atomic_inc_return(&hp->seqno);
  645. packet.len = count + sizeof(struct hvsi_header);
  646. memcpy(&packet.data, buf, count);
  647. ret = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
  648. if (ret == packet.len) {
  649. /* return the number of chars written, not the packet length */
  650. return count;
  651. }
  652. return ret; /* return any errors */
  653. }
  654. static void hvsi_close_protocol(struct hvsi_struct *hp)
  655. {
  656. struct hvsi_control packet __ALIGNED__;
  657. packet.type = VS_CONTROL_PACKET_HEADER;
  658. packet.seqno = atomic_inc_return(&hp->seqno);
  659. packet.len = 6;
  660. packet.verb = VSV_CLOSE_PROTOCOL;
  661. pr_debug("%s: sending %i bytes\n", __FUNCTION__, packet.len);
  662. dbg_dump_hex((uint8_t*)&packet, packet.len);
  663. hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
  664. }
  665. static int hvsi_open(struct tty_struct *tty, struct file *filp)
  666. {
  667. struct hvsi_struct *hp;
  668. unsigned long flags;
  669. int line = tty->index;
  670. int ret;
  671. pr_debug("%s\n", __FUNCTION__);
  672. if (line < 0 || line >= hvsi_count)
  673. return -ENODEV;
  674. hp = &hvsi_ports[line];
  675. tty->driver_data = hp;
  676. tty->low_latency = 1; /* avoid throttle/tty_flip_buffer_push race */
  677. mb();
  678. if (hp->state == HVSI_FSP_DIED)
  679. return -EIO;
  680. spin_lock_irqsave(&hp->lock, flags);
  681. hp->tty = tty;
  682. hp->count++;
  683. atomic_set(&hp->seqno, 0);
  684. h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
  685. spin_unlock_irqrestore(&hp->lock, flags);
  686. if (is_console(hp))
  687. return 0; /* this has already been handshaked as the console */
  688. ret = hvsi_handshake(hp);
  689. if (ret < 0) {
  690. printk(KERN_ERR "%s: HVSI handshaking failed\n", tty->name);
  691. return ret;
  692. }
  693. ret = hvsi_get_mctrl(hp);
  694. if (ret < 0) {
  695. printk(KERN_ERR "%s: couldn't get initial modem flags\n", tty->name);
  696. return ret;
  697. }
  698. ret = hvsi_set_mctrl(hp, hp->mctrl | TIOCM_DTR);
  699. if (ret < 0) {
  700. printk(KERN_ERR "%s: couldn't set DTR\n", tty->name);
  701. return ret;
  702. }
  703. return 0;
  704. }
  705. /* wait for hvsi_write_worker to empty hp->outbuf */
  706. static void hvsi_flush_output(struct hvsi_struct *hp)
  707. {
  708. wait_event_timeout(hp->emptyq, (hp->n_outbuf <= 0), HVSI_TIMEOUT);
  709. /* 'writer' could still be pending if it didn't see n_outbuf = 0 yet */
  710. cancel_delayed_work(&hp->writer);
  711. flush_scheduled_work();
  712. /*
  713. * it's also possible that our timeout expired and hvsi_write_worker
  714. * didn't manage to push outbuf. poof.
  715. */
  716. hp->n_outbuf = 0;
  717. }
  718. static void hvsi_close(struct tty_struct *tty, struct file *filp)
  719. {
  720. struct hvsi_struct *hp = tty->driver_data;
  721. unsigned long flags;
  722. pr_debug("%s\n", __FUNCTION__);
  723. if (tty_hung_up_p(filp))
  724. return;
  725. spin_lock_irqsave(&hp->lock, flags);
  726. if (--hp->count == 0) {
  727. hp->tty = NULL;
  728. hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
  729. /* only close down connection if it is not the console */
  730. if (!is_console(hp)) {
  731. h_vio_signal(hp->vtermno, VIO_IRQ_DISABLE); /* no more irqs */
  732. __set_state(hp, HVSI_CLOSED);
  733. /*
  734. * any data delivered to the tty layer after this will be
  735. * discarded (except for XON/XOFF)
  736. */
  737. tty->closing = 1;
  738. spin_unlock_irqrestore(&hp->lock, flags);
  739. /* let any existing irq handlers finish. no more will start. */
  740. synchronize_irq(hp->virq);
  741. /* hvsi_write_worker will re-schedule until outbuf is empty. */
  742. hvsi_flush_output(hp);
  743. /* tell FSP to stop sending data */
  744. hvsi_close_protocol(hp);
  745. /*
  746. * drain anything FSP is still in the middle of sending, and let
  747. * hvsi_handshake drain the rest on the next open.
  748. */
  749. hvsi_drain_input(hp);
  750. spin_lock_irqsave(&hp->lock, flags);
  751. }
  752. } else if (hp->count < 0)
  753. printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
  754. hp - hvsi_ports, hp->count);
  755. spin_unlock_irqrestore(&hp->lock, flags);
  756. }
  757. static void hvsi_hangup(struct tty_struct *tty)
  758. {
  759. struct hvsi_struct *hp = tty->driver_data;
  760. unsigned long flags;
  761. pr_debug("%s\n", __FUNCTION__);
  762. spin_lock_irqsave(&hp->lock, flags);
  763. hp->count = 0;
  764. hp->n_outbuf = 0;
  765. hp->tty = NULL;
  766. spin_unlock_irqrestore(&hp->lock, flags);
  767. }
  768. /* called with hp->lock held */
  769. static void hvsi_push(struct hvsi_struct *hp)
  770. {
  771. int n;
  772. if (hp->n_outbuf <= 0)
  773. return;
  774. n = hvsi_put_chars(hp, hp->outbuf, hp->n_outbuf);
  775. if (n > 0) {
  776. /* success */
  777. pr_debug("%s: wrote %i chars\n", __FUNCTION__, n);
  778. hp->n_outbuf = 0;
  779. } else if (n == -EIO) {
  780. __set_state(hp, HVSI_FSP_DIED);
  781. printk(KERN_ERR "hvsi%i: service processor died\n", hp->index);
  782. }
  783. }
  784. /* hvsi_write_worker will keep rescheduling itself until outbuf is empty */
  785. static void hvsi_write_worker(struct work_struct *work)
  786. {
  787. struct hvsi_struct *hp =
  788. container_of(work, struct hvsi_struct, writer.work);
  789. unsigned long flags;
  790. #ifdef DEBUG
  791. static long start_j = 0;
  792. if (start_j == 0)
  793. start_j = jiffies;
  794. #endif /* DEBUG */
  795. spin_lock_irqsave(&hp->lock, flags);
  796. pr_debug("%s: %i chars in buffer\n", __FUNCTION__, hp->n_outbuf);
  797. if (!is_open(hp)) {
  798. /*
  799. * We could have a non-open connection if the service processor died
  800. * while we were busily scheduling ourselves. In that case, it could
  801. * be minutes before the service processor comes back, so only try
  802. * again once a second.
  803. */
  804. schedule_delayed_work(&hp->writer, HZ);
  805. goto out;
  806. }
  807. hvsi_push(hp);
  808. if (hp->n_outbuf > 0)
  809. schedule_delayed_work(&hp->writer, 10);
  810. else {
  811. #ifdef DEBUG
  812. pr_debug("%s: outbuf emptied after %li jiffies\n", __FUNCTION__,
  813. jiffies - start_j);
  814. start_j = 0;
  815. #endif /* DEBUG */
  816. wake_up_all(&hp->emptyq);
  817. tty_wakeup(hp->tty);
  818. }
  819. out:
  820. spin_unlock_irqrestore(&hp->lock, flags);
  821. }
  822. static int hvsi_write_room(struct tty_struct *tty)
  823. {
  824. struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data;
  825. return N_OUTBUF - hp->n_outbuf;
  826. }
  827. static int hvsi_chars_in_buffer(struct tty_struct *tty)
  828. {
  829. struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data;
  830. return hp->n_outbuf;
  831. }
  832. static int hvsi_write(struct tty_struct *tty,
  833. const unsigned char *buf, int count)
  834. {
  835. struct hvsi_struct *hp = tty->driver_data;
  836. const char *source = buf;
  837. unsigned long flags;
  838. int total = 0;
  839. int origcount = count;
  840. spin_lock_irqsave(&hp->lock, flags);
  841. pr_debug("%s: %i chars in buffer\n", __FUNCTION__, hp->n_outbuf);
  842. if (!is_open(hp)) {
  843. /* we're either closing or not yet open; don't accept data */
  844. pr_debug("%s: not open\n", __FUNCTION__);
  845. goto out;
  846. }
  847. /*
  848. * when the hypervisor buffer (16K) fills, data will stay in hp->outbuf
  849. * and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls
  850. * will see there is no room in outbuf and return.
  851. */
  852. while ((count > 0) && (hvsi_write_room(hp->tty) > 0)) {
  853. int chunksize = min(count, hvsi_write_room(hp->tty));
  854. BUG_ON(hp->n_outbuf < 0);
  855. memcpy(hp->outbuf + hp->n_outbuf, source, chunksize);
  856. hp->n_outbuf += chunksize;
  857. total += chunksize;
  858. source += chunksize;
  859. count -= chunksize;
  860. hvsi_push(hp);
  861. }
  862. if (hp->n_outbuf > 0) {
  863. /*
  864. * we weren't able to write it all to the hypervisor.
  865. * schedule another push attempt.
  866. */
  867. schedule_delayed_work(&hp->writer, 10);
  868. }
  869. out:
  870. spin_unlock_irqrestore(&hp->lock, flags);
  871. if (total != origcount)
  872. pr_debug("%s: wanted %i, only wrote %i\n", __FUNCTION__, origcount,
  873. total);
  874. return total;
  875. }
  876. /*
  877. * I have never seen throttle or unthrottle called, so this little throttle
  878. * buffering scheme may or may not work.
  879. */
  880. static void hvsi_throttle(struct tty_struct *tty)
  881. {
  882. struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data;
  883. pr_debug("%s\n", __FUNCTION__);
  884. h_vio_signal(hp->vtermno, VIO_IRQ_DISABLE);
  885. }
  886. static void hvsi_unthrottle(struct tty_struct *tty)
  887. {
  888. struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data;
  889. unsigned long flags;
  890. int shouldflip = 0;
  891. pr_debug("%s\n", __FUNCTION__);
  892. spin_lock_irqsave(&hp->lock, flags);
  893. if (hp->n_throttle) {
  894. hvsi_send_overflow(hp);
  895. shouldflip = 1;
  896. }
  897. spin_unlock_irqrestore(&hp->lock, flags);
  898. if (shouldflip)
  899. tty_flip_buffer_push(hp->tty);
  900. h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
  901. }
  902. static int hvsi_tiocmget(struct tty_struct *tty, struct file *file)
  903. {
  904. struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data;
  905. hvsi_get_mctrl(hp);
  906. return hp->mctrl;
  907. }
  908. static int hvsi_tiocmset(struct tty_struct *tty, struct file *file,
  909. unsigned int set, unsigned int clear)
  910. {
  911. struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data;
  912. unsigned long flags;
  913. uint16_t new_mctrl;
  914. /* we can only alter DTR */
  915. clear &= TIOCM_DTR;
  916. set &= TIOCM_DTR;
  917. spin_lock_irqsave(&hp->lock, flags);
  918. new_mctrl = (hp->mctrl & ~clear) | set;
  919. if (hp->mctrl != new_mctrl) {
  920. hvsi_set_mctrl(hp, new_mctrl);
  921. hp->mctrl = new_mctrl;
  922. }
  923. spin_unlock_irqrestore(&hp->lock, flags);
  924. return 0;
  925. }
  926. static const struct tty_operations hvsi_ops = {
  927. .open = hvsi_open,
  928. .close = hvsi_close,
  929. .write = hvsi_write,
  930. .hangup = hvsi_hangup,
  931. .write_room = hvsi_write_room,
  932. .chars_in_buffer = hvsi_chars_in_buffer,
  933. .throttle = hvsi_throttle,
  934. .unthrottle = hvsi_unthrottle,
  935. .tiocmget = hvsi_tiocmget,
  936. .tiocmset = hvsi_tiocmset,
  937. };
  938. static int __init hvsi_init(void)
  939. {
  940. int i;
  941. hvsi_driver = alloc_tty_driver(hvsi_count);
  942. if (!hvsi_driver)
  943. return -ENOMEM;
  944. hvsi_driver->owner = THIS_MODULE;
  945. hvsi_driver->driver_name = "hvsi";
  946. hvsi_driver->name = "hvsi";
  947. hvsi_driver->major = HVSI_MAJOR;
  948. hvsi_driver->minor_start = HVSI_MINOR;
  949. hvsi_driver->type = TTY_DRIVER_TYPE_SYSTEM;
  950. hvsi_driver->init_termios = tty_std_termios;
  951. hvsi_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
  952. hvsi_driver->init_termios.c_ispeed = 9600;
  953. hvsi_driver->init_termios.c_ospeed = 9600;
  954. hvsi_driver->flags = TTY_DRIVER_REAL_RAW;
  955. tty_set_operations(hvsi_driver, &hvsi_ops);
  956. for (i=0; i < hvsi_count; i++) {
  957. struct hvsi_struct *hp = &hvsi_ports[i];
  958. int ret = 1;
  959. ret = request_irq(hp->virq, hvsi_interrupt, IRQF_DISABLED, "hvsi", hp);
  960. if (ret)
  961. printk(KERN_ERR "HVSI: couldn't reserve irq 0x%x (error %i)\n",
  962. hp->virq, ret);
  963. }
  964. hvsi_wait = wait_for_state; /* irqs active now */
  965. if (tty_register_driver(hvsi_driver))
  966. panic("Couldn't register hvsi console driver\n");
  967. printk(KERN_DEBUG "HVSI: registered %i devices\n", hvsi_count);
  968. return 0;
  969. }
  970. device_initcall(hvsi_init);
  971. /***** console (not tty) code: *****/
  972. static void hvsi_console_print(struct console *console, const char *buf,
  973. unsigned int count)
  974. {
  975. struct hvsi_struct *hp = &hvsi_ports[console->index];
  976. char c[HVSI_MAX_OUTGOING_DATA] __ALIGNED__;
  977. unsigned int i = 0, n = 0;
  978. int ret, donecr = 0;
  979. mb();
  980. if (!is_open(hp))
  981. return;
  982. /*
  983. * ugh, we have to translate LF -> CRLF ourselves, in place.
  984. * copied from hvc_console.c:
  985. */
  986. while (count > 0 || i > 0) {
  987. if (count > 0 && i < sizeof(c)) {
  988. if (buf[n] == '\n' && !donecr) {
  989. c[i++] = '\r';
  990. donecr = 1;
  991. } else {
  992. c[i++] = buf[n++];
  993. donecr = 0;
  994. --count;
  995. }
  996. } else {
  997. ret = hvsi_put_chars(hp, c, i);
  998. if (ret < 0)
  999. i = 0;
  1000. i -= ret;
  1001. }
  1002. }
  1003. }
  1004. static struct tty_driver *hvsi_console_device(struct console *console,
  1005. int *index)
  1006. {
  1007. *index = console->index;
  1008. return hvsi_driver;
  1009. }
  1010. static int __init hvsi_console_setup(struct console *console, char *options)
  1011. {
  1012. struct hvsi_struct *hp = &hvsi_ports[console->index];
  1013. int ret;
  1014. if (console->index < 0 || console->index >= hvsi_count)
  1015. return -1;
  1016. /* give the FSP a chance to change the baud rate when we re-open */
  1017. hvsi_close_protocol(hp);
  1018. ret = hvsi_handshake(hp);
  1019. if (ret < 0)
  1020. return ret;
  1021. ret = hvsi_get_mctrl(hp);
  1022. if (ret < 0)
  1023. return ret;
  1024. ret = hvsi_set_mctrl(hp, hp->mctrl | TIOCM_DTR);
  1025. if (ret < 0)
  1026. return ret;
  1027. hp->flags |= HVSI_CONSOLE;
  1028. return 0;
  1029. }
  1030. static struct console hvsi_con_driver = {
  1031. .name = "hvsi",
  1032. .write = hvsi_console_print,
  1033. .device = hvsi_console_device,
  1034. .setup = hvsi_console_setup,
  1035. .flags = CON_PRINTBUFFER,
  1036. .index = -1,
  1037. };
  1038. static int __init hvsi_console_init(void)
  1039. {
  1040. struct device_node *vty;
  1041. hvsi_wait = poll_for_state; /* no irqs yet; must poll */
  1042. /* search device tree for vty nodes */
  1043. for (vty = of_find_compatible_node(NULL, "serial", "hvterm-protocol");
  1044. vty != NULL;
  1045. vty = of_find_compatible_node(vty, "serial", "hvterm-protocol")) {
  1046. struct hvsi_struct *hp;
  1047. const uint32_t *vtermno, *irq;
  1048. vtermno = get_property(vty, "reg", NULL);
  1049. irq = get_property(vty, "interrupts", NULL);
  1050. if (!vtermno || !irq)
  1051. continue;
  1052. if (hvsi_count >= MAX_NR_HVSI_CONSOLES) {
  1053. of_node_put(vty);
  1054. break;
  1055. }
  1056. hp = &hvsi_ports[hvsi_count];
  1057. INIT_DELAYED_WORK(&hp->writer, hvsi_write_worker);
  1058. INIT_WORK(&hp->handshaker, hvsi_handshaker);
  1059. init_waitqueue_head(&hp->emptyq);
  1060. init_waitqueue_head(&hp->stateq);
  1061. spin_lock_init(&hp->lock);
  1062. hp->index = hvsi_count;
  1063. hp->inbuf_end = hp->inbuf;
  1064. hp->state = HVSI_CLOSED;
  1065. hp->vtermno = *vtermno;
  1066. hp->virq = irq_create_mapping(NULL, irq[0]);
  1067. if (hp->virq == NO_IRQ) {
  1068. printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n",
  1069. __FUNCTION__, irq[0]);
  1070. continue;
  1071. }
  1072. hvsi_count++;
  1073. }
  1074. if (hvsi_count)
  1075. register_console(&hvsi_con_driver);
  1076. return 0;
  1077. }
  1078. console_initcall(hvsi_console_init);