Lines Matching refs:pv

10 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
12 packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
15 return pv->put_chars(pv->termno, (char *)packet, packet->len);
18 static void hvsi_start_handshake(struct hvsi_priv *pv)
23 pv->established = 0;
24 atomic_set(&pv->seqno, 0);
26 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
32 hvsi_send_packet(pv, &q.hdr);
35 static int hvsi_send_close(struct hvsi_priv *pv)
39 pv->established = 0;
44 return hvsi_send_packet(pv, &ctrl.hdr);
47 static void hvsi_cd_change(struct hvsi_priv *pv, int cd)
50 pv->mctrl |= TIOCM_CD;
52 pv->mctrl &= ~TIOCM_CD;
60 if (!pv->is_console && pv->opened) {
62 pv->termno);
63 hvsi_send_close(pv);
68 static void hvsi_got_control(struct hvsi_priv *pv)
70 struct hvsi_control *pkt = (struct hvsi_control *)pv->inbuf;
75 hvsi_start_handshake(pv);
79 hvsi_cd_change(pv, be32_to_cpu(pkt->word) & HVSI_TSCD);
84 static void hvsi_got_query(struct hvsi_priv *pv)
86 struct hvsi_query *pkt = (struct hvsi_query *)pv->inbuf;
94 pv->termno);
102 hvsi_send_packet(pv, &r.hdr);
105 pv->established = 1;
108 static void hvsi_got_response(struct hvsi_priv *pv)
111 (struct hvsi_query_response *)pv->inbuf;
115 hvsi_cd_change(pv, be32_to_cpu(r->u.mctrl_word) & HVSI_TSCD);
116 pv->mctrl_update = 1;
121 static int hvsi_check_packet(struct hvsi_priv *pv)
128 if (pv->inbuf[0] < 0xfc) {
129 pv->inbuf_len = pv->inbuf_pktlen = 0;
132 type = pv->inbuf[0];
133 len = pv->inbuf[1];
136 if (pv->inbuf_len < len)
140 pv->termno, type, len);
145 pv->inbuf_pktlen = len - 4;
146 pv->inbuf_cur = 4;
149 hvsi_got_control(pv);
152 hvsi_got_query(pv);
155 hvsi_got_response(pv);
160 pv->inbuf_len -= len;
161 memmove(pv->inbuf, &pv->inbuf[len], pv->inbuf_len);
165 static int hvsi_get_packet(struct hvsi_priv *pv)
168 if (pv->inbuf_len < HVSI_INBUF_SIZE)
169 pv->inbuf_len += pv->get_chars(pv->termno,
170 &pv->inbuf[pv->inbuf_len],
171 HVSI_INBUF_SIZE - pv->inbuf_len);
176 if (pv->inbuf_len >= 4)
177 return hvsi_check_packet(pv);
181 int hvsilib_get_chars(struct hvsi_priv *pv, char *buf, int count)
185 if (WARN_ON(!pv))
193 if (!pv->opened)
201 if (pv->inbuf_pktlen) {
202 unsigned int l = min(count, (int)pv->inbuf_pktlen);
203 memcpy(&buf[read], &pv->inbuf[pv->inbuf_cur], l);
204 pv->inbuf_cur += l;
205 pv->inbuf_pktlen -= l;
213 if (pv->inbuf_cur) {
214 pv->inbuf_len -= pv->inbuf_cur;
215 memmove(pv->inbuf, &pv->inbuf[pv->inbuf_cur],
216 pv->inbuf_len);
217 pv->inbuf_cur = 0;
221 if (hvsi_get_packet(pv))
224 if (!pv->established) {
225 pr_devel("HVSI@%x: returning -EPIPE\n", pv->termno);
231 int hvsilib_put_chars(struct hvsi_priv *pv, const char *buf, int count)
236 if (WARN_ON(!pv))
242 rc = hvsi_send_packet(pv, &dp.hdr);
257 int hvsilib_read_mctrl(struct hvsi_priv *pv)
263 pv->termno);
265 pv->mctrl_update = 0;
269 rc = hvsi_send_packet(pv, &q.hdr);
271 pr_devel("HVSI@%x: Error %d...\n", pv->termno, rc);
277 if (!pv->established)
279 if (pv->mctrl_update)
281 if (!hvsi_get_packet(pv))
287 int hvsilib_write_mctrl(struct hvsi_priv *pv, int dtr)
292 mctrl = pv->mctrl;
297 if (mctrl == pv->mctrl)
299 pv->mctrl = mctrl;
301 pr_devel("HVSI@%x: %s DTR...\n", pv->termno,
309 return hvsi_send_packet(pv, &ctrl.hdr);
312 void hvsilib_establish(struct hvsi_priv *pv)
316 pr_devel("HVSI@%x: Establishing...\n", pv->termno);
322 if (pv->established)
324 if (!hvsi_get_packet(pv))
331 pr_devel("HVSI@%x: ... sending close\n", pv->termno);
333 hvsi_send_close(pv);
337 pr_devel("HVSI@%x: ... restarting handshake\n", pv->termno);
339 hvsi_start_handshake(pv);
341 pr_devel("HVSI@%x: ... waiting handshake\n", pv->termno);
345 if (pv->established)
347 if (!hvsi_get_packet(pv))
351 if (!pv->established) {
353 pv->termno);
359 pr_devel("HVSI@%x: ... established, reading mctrl\n", pv->termno);
361 hvsilib_read_mctrl(pv);
365 pr_devel("HVSI@%x: ... setting mctrl\n", pv->termno);
367 hvsilib_write_mctrl(pv, 1);
371 pv->opened = 1;
374 int hvsilib_open(struct hvsi_priv *pv, struct hvc_struct *hp)
376 pr_devel("HVSI@%x: open !\n", pv->termno);
379 pv->tty = tty_port_tty_get(&hp->port);
381 hvsilib_establish(pv);
386 void hvsilib_close(struct hvsi_priv *pv, struct hvc_struct *hp)
390 pr_devel("HVSI@%x: close !\n", pv->termno);
392 if (!pv->is_console) {
394 pv->termno);
398 pv->opened = 0;
402 if (!pv->tty || (pv->tty->termios.c_cflag & HUPCL))
403 hvsilib_write_mctrl(pv, 0);
406 hvsi_send_close(pv);
409 tty_kref_put(pv->tty);
410 pv->tty = NULL;
413 void hvsilib_init(struct hvsi_priv *pv,
419 memset(pv, 0, sizeof(*pv));
420 pv->get_chars = get_chars;
421 pv->put_chars = put_chars;
422 pv->termno = termno;
423 pv->is_console = is_console;