• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/char/

Lines Matching refs:hp

100 static int (*hvsi_wait)(struct hvsi_struct *hp, int state);
174 static inline int is_console(struct hvsi_struct *hp)
176 return hp->flags & HVSI_CONSOLE;
179 static inline int is_open(struct hvsi_struct *hp)
182 return (hp->state == HVSI_OPEN)
183 || (hp->state == HVSI_WAIT_FOR_MCTRL_RESPONSE);
186 static inline void print_state(struct hvsi_struct *hp)
197 const char *name = (hp->state < ARRAY_SIZE(state_names))
198 ? state_names[hp->state] : "UNKNOWN";
200 pr_debug("hvsi%i: state = %s\n", hp->index, name);
204 static inline void __set_state(struct hvsi_struct *hp, int state)
206 hp->state = state;
207 print_state(hp);
208 wake_up_all(&hp->stateq);
211 static inline void set_state(struct hvsi_struct *hp, int state)
215 spin_lock_irqsave(&hp->lock, flags);
216 __set_state(hp, state);
217 spin_unlock_irqrestore(&hp->lock, flags);
231 static inline int got_packet(const struct hvsi_struct *hp, uint8_t *packet)
233 if (hp->inbuf_end < packet + sizeof(struct hvsi_header))
236 if (hp->inbuf_end < (packet + len_packet(packet)))
243 static void compact_inbuf(struct hvsi_struct *hp, uint8_t *read_to)
245 int remaining = (int)(hp->inbuf_end - read_to);
249 if (read_to != hp->inbuf)
250 memmove(hp->inbuf, read_to, remaining);
252 hp->inbuf_end = hp->inbuf + remaining;
291 static int hvsi_read(struct hvsi_struct *hp, char *buf, int count)
295 got = hvc_get_chars(hp->vtermno, buf, count);
300 static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
309 pr_debug("hvsi%i: CD dropped\n", hp->index);
310 hp->mctrl &= TIOCM_CD;
311 /* If userland hasn't done an open(2) yet, hp->tty is NULL. */
312 if (hp->tty && !(hp->tty->flags & CLOCAL))
313 *to_hangup = hp->tty;
317 pr_debug("hvsi%i: service processor came back\n", hp->index);
318 if (hp->state != HVSI_CLOSED) {
319 *to_handshake = hp;
324 hp->index);
330 static void hvsi_recv_response(struct hvsi_struct *hp, uint8_t *packet)
334 switch (hp->state) {
336 __set_state(hp, HVSI_WAIT_FOR_VER_QUERY);
339 hp->mctrl = 0;
341 hp->mctrl |= TIOCM_DTR;
343 hp->mctrl |= TIOCM_CD;
344 __set_state(hp, HVSI_OPEN);
347 printk(KERN_ERR "hvsi%i: unexpected query response: ", hp->index);
354 static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
361 packet.seqno = atomic_inc_return(&hp->seqno);
369 wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
372 hp->index);
379 static void hvsi_recv_query(struct hvsi_struct *hp, uint8_t *packet)
383 switch (hp->state) {
385 hvsi_version_respond(hp, query->seqno);
386 __set_state(hp, HVSI_OPEN);
389 printk(KERN_ERR "hvsi%i: unexpected query: ", hp->index);
395 static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len)
403 hp->sysrq = 1;
405 } else if (hp->sysrq) {
407 hp->sysrq = 0;
411 tty_insert_flip_char(hp->tty, c, 0);
424 static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp,
442 hvsi_insert_chars(hp, data, datalen);
450 memcpy(hp->throttle_buf, data + TTY_THRESHOLD_THROTTLE, overflow);
451 hp->n_throttle = overflow;
454 return hp->tty;
463 static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,
466 uint8_t *packet = hp->inbuf;
473 chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ);
480 dbg_dump_hex(hp->inbuf_end, chunklen);
482 hp->inbuf_end += chunklen;
485 while ((packet < hp->inbuf_end) && got_packet(hp, packet)) {
489 printk(KERN_ERR "hvsi%i: got malformed packet\n", hp->index);
491 while ((packet < hp->inbuf_end) && (!is_header(packet)))
502 if (!is_open(hp))
504 if (hp->tty == NULL)
506 *flip = hvsi_recv_data(hp, packet);
509 hvsi_recv_control(hp, packet, hangup, handshake);
512 hvsi_recv_response(hp, packet);
515 hvsi_recv_query(hp, packet);
519 hp->index, header->type);
537 compact_inbuf(hp, packet);
542 static void hvsi_send_overflow(struct hvsi_struct *hp)
545 hp->n_throttle);
547 hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle);
548 hp->n_throttle = 0;
557 struct hvsi_struct *hp = (struct hvsi_struct *)arg;
567 spin_lock_irqsave(&hp->lock, flags);
568 again = hvsi_load_chunk(hp, &flip, &hangup, &handshake);
569 spin_unlock_irqrestore(&hp->lock, flags);
593 spin_lock_irqsave(&hp->lock, flags);
594 if (hp->tty && hp->n_throttle
595 && (!test_bit(TTY_THROTTLED, &hp->tty->flags))) {
598 flip = hp->tty;
599 hvsi_send_overflow(hp);
601 spin_unlock_irqrestore(&hp->lock, flags);
611 static int __init poll_for_state(struct hvsi_struct *hp, int state)
616 hvsi_interrupt(hp->virq, (void *)hp); /* get pending data */
618 if (hp->state == state)
628 static int wait_for_state(struct hvsi_struct *hp, int state)
632 if (!wait_event_timeout(hp->stateq, (hp->state == state), HVSI_TIMEOUT))
638 static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
645 packet.seqno = atomic_inc_return(&hp->seqno);
651 wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
653 printk(KERN_ERR "hvsi%i: couldn't send query (%i)!\n", hp->index,
661 static int hvsi_get_mctrl(struct hvsi_struct *hp)
665 set_state(hp, HVSI_WAIT_FOR_MCTRL_RESPONSE);
666 hvsi_query(hp, VSV_SEND_MODEM_CTL_STATUS);
668 ret = hvsi_wait(hp, HVSI_OPEN);
670 printk(KERN_ERR "hvsi%i: didn't get modem flags\n", hp->index);
671 set_state(hp, HVSI_OPEN);
675 pr_debug("%s: mctrl 0x%x\n", __func__, hp->mctrl);
681 static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
687 packet.seqno = atomic_inc_return(&hp->seqno);
698 wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
700 printk(KERN_ERR "hvsi%i: couldn't set DTR!\n", hp->index);
707 static void hvsi_drain_input(struct hvsi_struct *hp)
713 if (0 == hvsi_read(hp, buf, HVSI_MAX_READ))
717 static int hvsi_handshake(struct hvsi_struct *hp)
728 hvsi_drain_input(hp);
730 set_state(hp, HVSI_WAIT_FOR_VER_RESPONSE);
731 ret = hvsi_query(hp, VSV_SEND_VERSION_NUMBER);
733 printk(KERN_ERR "hvsi%i: couldn't send version query\n", hp->index);
737 ret = hvsi_wait(hp, HVSI_OPEN);
746 struct hvsi_struct *hp =
749 if (hvsi_handshake(hp) >= 0)
752 printk(KERN_ERR "hvsi%i: re-handshaking failed\n", hp->index);
753 if (is_console(hp)) {
758 printk(KERN_ERR "hvsi%i: lost console!\n", hp->index);
762 static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
770 packet.seqno = atomic_inc_return(&hp->seqno);
774 ret = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
782 static void hvsi_close_protocol(struct hvsi_struct *hp)
787 packet.seqno = atomic_inc_return(&hp->seqno);
794 hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
799 struct hvsi_struct *hp;
808 hp = &hvsi_ports[line];
810 tty->driver_data = hp;
813 if (hp->state == HVSI_FSP_DIED)
816 spin_lock_irqsave(&hp->lock, flags);
817 hp->tty = tty;
818 hp->count++;
819 atomic_set(&hp->seqno, 0);
820 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
821 spin_unlock_irqrestore(&hp->lock, flags);
823 if (is_console(hp))
826 ret = hvsi_handshake(hp);
832 ret = hvsi_get_mctrl(hp);
838 ret = hvsi_set_mctrl(hp, hp->mctrl | TIOCM_DTR);
847 /* wait for hvsi_write_worker to empty hp->outbuf */
848 static void hvsi_flush_output(struct hvsi_struct *hp)
850 wait_event_timeout(hp->emptyq, (hp->n_outbuf <= 0), HVSI_TIMEOUT);
853 cancel_delayed_work(&hp->writer);
860 hp->n_outbuf = 0;
865 struct hvsi_struct *hp = tty->driver_data;
873 spin_lock_irqsave(&hp->lock, flags);
875 if (--hp->count == 0) {
876 hp->tty = NULL;
877 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
880 if (!is_console(hp)) {
881 h_vio_signal(hp->vtermno, VIO_IRQ_DISABLE); /* no more irqs */
882 __set_state(hp, HVSI_CLOSED);
889 spin_unlock_irqrestore(&hp->lock, flags);
892 synchronize_irq(hp->virq);
895 hvsi_flush_output(hp);
898 hvsi_close_protocol(hp);
904 hvsi_drain_input(hp);
906 spin_lock_irqsave(&hp->lock, flags);
908 } else if (hp->count < 0)
910 hp - hvsi_ports, hp->count);
912 spin_unlock_irqrestore(&hp->lock, flags);
917 struct hvsi_struct *hp = tty->driver_data;
922 spin_lock_irqsave(&hp->lock, flags);
924 hp->count = 0;
925 hp->n_outbuf = 0;
926 hp->tty = NULL;
928 spin_unlock_irqrestore(&hp->lock, flags);
931 /* called with hp->lock held */
932 static void hvsi_push(struct hvsi_struct *hp)
936 if (hp->n_outbuf <= 0)
939 n = hvsi_put_chars(hp, hp->outbuf, hp->n_outbuf);
943 hp->n_outbuf = 0;
945 __set_state(hp, HVSI_FSP_DIED);
946 printk(KERN_ERR "hvsi%i: service processor died\n", hp->index);
953 struct hvsi_struct *hp =
963 spin_lock_irqsave(&hp->lock, flags);
965 pr_debug("%s: %i chars in buffer\n", __func__, hp->n_outbuf);
967 if (!is_open(hp)) {
974 schedule_delayed_work(&hp->writer, HZ);
978 hvsi_push(hp);
979 if (hp->n_outbuf > 0)
980 schedule_delayed_work(&hp->writer, 10);
987 wake_up_all(&hp->emptyq);
988 tty_wakeup(hp->tty);
992 spin_unlock_irqrestore(&hp->lock, flags);
997 struct hvsi_struct *hp = tty->driver_data;
999 return N_OUTBUF - hp->n_outbuf;
1004 struct hvsi_struct *hp = tty->driver_data;
1006 return hp->n_outbuf;
1012 struct hvsi_struct *hp = tty->driver_data;
1018 spin_lock_irqsave(&hp->lock, flags);
1020 pr_debug("%s: %i chars in buffer\n", __func__, hp->n_outbuf);
1022 if (!is_open(hp)) {
1029 * when the hypervisor buffer (16K) fills, data will stay in hp->outbuf
1033 while ((count > 0) && (hvsi_write_room(hp->tty) > 0)) {
1034 int chunksize = min(count, hvsi_write_room(hp->tty));
1036 BUG_ON(hp->n_outbuf < 0);
1037 memcpy(hp->outbuf + hp->n_outbuf, source, chunksize);
1038 hp->n_outbuf += chunksize;
1043 hvsi_push(hp);
1046 if (hp->n_outbuf > 0) {
1051 schedule_delayed_work(&hp->writer, 10);
1055 spin_unlock_irqrestore(&hp->lock, flags);
1070 struct hvsi_struct *hp = tty->driver_data;
1074 h_vio_signal(hp->vtermno, VIO_IRQ_DISABLE);
1079 struct hvsi_struct *hp = tty->driver_data;
1085 spin_lock_irqsave(&hp->lock, flags);
1086 if (hp->n_throttle) {
1087 hvsi_send_overflow(hp);
1090 spin_unlock_irqrestore(&hp->lock, flags);
1093 tty_flip_buffer_push(hp->tty);
1095 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
1100 struct hvsi_struct *hp = tty->driver_data;
1102 hvsi_get_mctrl(hp);
1103 return hp->mctrl;
1109 struct hvsi_struct *hp = tty->driver_data;
1117 spin_lock_irqsave(&hp->lock, flags);
1119 new_mctrl = (hp->mctrl & ~clear) | set;
1121 if (hp->mctrl != new_mctrl) {
1122 hvsi_set_mctrl(hp, new_mctrl);
1123 hp->mctrl = new_mctrl;
1125 spin_unlock_irqrestore(&hp->lock, flags);
1166 struct hvsi_struct *hp = &hvsi_ports[i];
1169 ret = request_irq(hp->virq, hvsi_interrupt, IRQF_DISABLED, "hvsi", hp);
1172 hp->virq, ret);
1190 struct hvsi_struct *hp = &hvsi_ports[console->index];
1196 if (!is_open(hp))
1214 ret = hvsi_put_chars(hp, c, i);
1231 struct hvsi_struct *hp;
1236 hp = &hvsi_ports[console->index];
1239 hvsi_close_protocol(hp);
1241 ret = hvsi_handshake(hp);
1245 ret = hvsi_get_mctrl(hp);
1249 ret = hvsi_set_mctrl(hp, hp->mctrl | TIOCM_DTR);
1253 hp->flags |= HVSI_CONSOLE;
1277 struct hvsi_struct *hp;
1290 hp = &hvsi_ports[hvsi_count];
1291 INIT_DELAYED_WORK(&hp->writer, hvsi_write_worker);
1292 INIT_WORK(&hp->handshaker, hvsi_handshaker);
1293 init_waitqueue_head(&hp->emptyq);
1294 init_waitqueue_head(&hp->stateq);
1295 spin_lock_init(&hp->lock);
1296 hp->index = hvsi_count;
1297 hp->inbuf_end = hp->inbuf;
1298 hp->state = HVSI_CLOSED;
1299 hp->vtermno = *vtermno;
1300 hp->virq = irq_create_mapping(NULL, irq[0]);
1301 if (hp->virq == NO_IRQ) {