Lines Matching defs:vio

16 #include <asm/vio.h>
18 int vio_ldc_send(struct vio_driver_state *vio, void *data, int len)
24 err = ldc_write(vio->lp, data, len);
34 static int send_ctrl(struct vio_driver_state *vio,
37 tag->sid = vio_send_sid(vio);
38 return vio_ldc_send(vio, tag, len);
48 static int send_version(struct vio_driver_state *vio, u16 major, u16 minor)
52 vio->_local_sid = (u32) sched_clock();
58 pkt.dev_class = vio->dev_class;
61 major, minor, vio->dev_class);
63 return send_ctrl(vio, &pkt.tag, sizeof(pkt));
66 static int start_handshake(struct vio_driver_state *vio)
72 vio->hs_state = VIO_HS_INVALID;
74 err = send_version(vio,
75 vio->ver_table[0].major,
76 vio->ver_table[0].minor);
83 static void flush_rx_dring(struct vio_driver_state *vio)
88 BUG_ON(!(vio->dr_state & VIO_DR_STATE_RXREG));
90 dr = &vio->drings[VIO_DRIVER_RX_RING];
93 BUG_ON(!vio->desc_buf);
94 kfree(vio->desc_buf);
95 vio->desc_buf = NULL;
101 void vio_link_state_change(struct vio_driver_state *vio, int event)
104 vio->hs_state = VIO_HS_INVALID;
106 switch (vio->dev_class) {
109 vio->dr_state = (VIO_DR_STATE_TXREQ |
114 vio->dr_state = VIO_DR_STATE_TXREQ;
117 vio->dr_state = VIO_DR_STATE_RXREQ;
120 start_handshake(vio);
122 vio->hs_state = VIO_HS_INVALID;
124 if (vio->dr_state & VIO_DR_STATE_RXREG)
125 flush_rx_dring(vio);
127 vio->dr_state = 0x00;
128 memset(&vio->ver, 0, sizeof(vio->ver));
130 ldc_disconnect(vio->lp);
135 static int handshake_failure(struct vio_driver_state *vio)
146 vio->dr_state &= ~(VIO_DR_STATE_TXREG |
149 dr = &vio->drings[VIO_DRIVER_RX_RING];
152 kfree(vio->desc_buf);
153 vio->desc_buf = NULL;
154 vio->desc_buf_len = 0;
156 vio->hs_state = VIO_HS_INVALID;
161 static int process_unknown(struct vio_driver_state *vio, void *arg)
168 printk(KERN_ERR "vio: ID[%lu] Resetting connection.\n",
169 vio->vdev->channel_id);
171 ldc_disconnect(vio->lp);
176 static int send_dreg(struct vio_driver_state *vio)
178 struct vio_dring_state *dr = &vio->drings[VIO_DRIVER_TX_RING];
215 return send_ctrl(vio, &u.pkt.tag, bytes);
218 static int send_rdx(struct vio_driver_state *vio)
228 return send_ctrl(vio, &pkt.tag, sizeof(pkt));
231 static int send_attr(struct vio_driver_state *vio)
233 if (!vio->ops)
236 return vio->ops->send_attr(vio);
239 static struct vio_version *find_by_major(struct vio_driver_state *vio,
245 for (i = 0; i < vio->ver_table_entries; i++) {
246 struct vio_version *v = &vio->ver_table[i];
255 static int process_ver_info(struct vio_driver_state *vio,
264 if (vio->hs_state != VIO_HS_INVALID) {
266 memset(&vio->ver, 0, sizeof(vio->ver));
267 vio->hs_state = VIO_HS_INVALID;
270 vap = find_by_major(vio, pkt->major);
272 vio->_peer_sid = pkt->tag.sid;
279 err = send_ctrl(vio, &pkt->tag, sizeof(*pkt));
286 err = send_ctrl(vio, &pkt->tag, sizeof(*pkt));
296 pkt->dev_class = vio->dev_class;
299 err = send_ctrl(vio, &pkt->tag, sizeof(*pkt));
301 vio->ver = ver;
302 vio->hs_state = VIO_HS_GOTVERS;
306 return handshake_failure(vio);
311 static int process_ver_ack(struct vio_driver_state *vio,
317 if (vio->hs_state & VIO_HS_GOTVERS) {
318 if (vio->ver.major != pkt->major ||
319 vio->ver.minor != pkt->minor) {
321 (void) send_ctrl(vio, &pkt->tag, sizeof(*pkt));
322 return handshake_failure(vio);
325 vio->ver.major = pkt->major;
326 vio->ver.minor = pkt->minor;
327 vio->hs_state = VIO_HS_GOTVERS;
330 switch (vio->dev_class) {
333 if (send_attr(vio) < 0)
334 return handshake_failure(vio);
344 static int process_ver_nack(struct vio_driver_state *vio,
353 return handshake_failure(vio);
354 nver = find_by_major(vio, pkt->major);
356 return handshake_failure(vio);
358 if (send_version(vio, nver->major, nver->minor) < 0)
359 return handshake_failure(vio);
364 static int process_ver(struct vio_driver_state *vio, struct vio_ver_info *pkt)
368 return process_ver_info(vio, pkt);
371 return process_ver_ack(vio, pkt);
374 return process_ver_nack(vio, pkt);
377 return handshake_failure(vio);
381 static int process_attr(struct vio_driver_state *vio, void *pkt)
385 if (!(vio->hs_state & VIO_HS_GOTVERS))
386 return handshake_failure(vio);
388 if (!vio->ops)
391 err = vio->ops->handle_attr(vio, pkt);
393 return handshake_failure(vio);
395 vio->hs_state |= VIO_HS_GOT_ATTR;
397 if ((vio->dr_state & VIO_DR_STATE_TXREQ) &&
398 !(vio->hs_state & VIO_HS_SENT_DREG)) {
399 if (send_dreg(vio) < 0)
400 return handshake_failure(vio);
402 vio->hs_state |= VIO_HS_SENT_DREG;
409 static int all_drings_registered(struct vio_driver_state *vio)
413 need_rx = (vio->dr_state & VIO_DR_STATE_RXREQ);
414 need_tx = (vio->dr_state & VIO_DR_STATE_TXREQ);
417 !(vio->dr_state & VIO_DR_STATE_RXREG))
421 !(vio->dr_state & VIO_DR_STATE_TXREG))
427 static int process_dreg_info(struct vio_driver_state *vio,
439 if (!(vio->dr_state & VIO_DR_STATE_RXREQ))
442 if (vio->dr_state & VIO_DR_STATE_RXREG)
446 if (vio_version_after_eq(vio, 1, 6)) {
452 BUG_ON(vio->desc_buf);
454 vio->desc_buf = kzalloc(pkt->descr_size, GFP_ATOMIC);
455 if (!vio->desc_buf)
458 vio->desc_buf_len = pkt->descr_size;
460 dr = &vio->drings[VIO_DRIVER_RX_RING];
485 if (send_ctrl(vio, &pkt->tag, struct_size(pkt, cookies, dr->ncookies)) < 0)
488 vio->dr_state |= VIO_DR_STATE_RXREG;
495 (void) send_ctrl(vio, &pkt->tag, sizeof(*pkt));
497 return handshake_failure(vio);
500 static int process_dreg_ack(struct vio_driver_state *vio,
511 dr = &vio->drings[VIO_DRIVER_TX_RING];
513 if (!(vio->dr_state & VIO_DR_STATE_TXREQ))
514 return handshake_failure(vio);
517 vio->dr_state |= VIO_DR_STATE_TXREG;
519 if (all_drings_registered(vio)) {
520 if (send_rdx(vio) < 0)
521 return handshake_failure(vio);
522 vio->hs_state = VIO_HS_SENT_RDX;
527 static int process_dreg_nack(struct vio_driver_state *vio,
536 return handshake_failure(vio);
539 static int process_dreg(struct vio_driver_state *vio,
542 if (!(vio->hs_state & VIO_HS_GOTVERS))
543 return handshake_failure(vio);
547 return process_dreg_info(vio, pkt);
550 return process_dreg_ack(vio, pkt);
553 return process_dreg_nack(vio, pkt);
556 return handshake_failure(vio);
560 static int process_dunreg(struct vio_driver_state *vio,
563 struct vio_dring_state *dr = &vio->drings[VIO_DRIVER_RX_RING];
570 vio->dr_state &= ~VIO_DR_STATE_RXREG;
574 kfree(vio->desc_buf);
575 vio->desc_buf = NULL;
576 vio->desc_buf_len = 0;
581 static int process_rdx_info(struct vio_driver_state *vio, struct vio_rdx *pkt)
587 if (send_ctrl(vio, &pkt->tag, sizeof(*pkt)) < 0)
588 return handshake_failure(vio);
590 vio->hs_state |= VIO_HS_SENT_RDX_ACK;
594 static int process_rdx_ack(struct vio_driver_state *vio, struct vio_rdx *pkt)
598 if (!(vio->hs_state & VIO_HS_SENT_RDX))
599 return handshake_failure(vio);
601 vio->hs_state |= VIO_HS_GOT_RDX_ACK;
605 static int process_rdx_nack(struct vio_driver_state *vio, struct vio_rdx *pkt)
609 return handshake_failure(vio);
612 static int process_rdx(struct vio_driver_state *vio, struct vio_rdx *pkt)
614 if (!all_drings_registered(vio))
615 handshake_failure(vio);
619 return process_rdx_info(vio, pkt);
622 return process_rdx_ack(vio, pkt);
625 return process_rdx_nack(vio, pkt);
628 return handshake_failure(vio);
632 int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt)
635 u8 prev_state = vio->hs_state;
640 err = process_ver(vio, pkt);
644 err = process_attr(vio, pkt);
648 err = process_dreg(vio, pkt);
652 err = process_dunreg(vio, pkt);
656 err = process_rdx(vio, pkt);
660 err = process_unknown(vio, pkt);
665 vio->hs_state != prev_state &&
666 (vio->hs_state & VIO_HS_COMPLETE)) {
667 if (vio->ops)
668 vio->ops->handshake_complete(vio);
675 void vio_conn_reset(struct vio_driver_state *vio)
685 int vio_validate_sid(struct vio_driver_state *vio, struct vio_msg_tag *tp)
698 switch (vio->dev_class) {
703 sid = vio->_peer_sid;
707 sid = vio->_local_sid;
714 tp->sid, vio->_peer_sid, vio->_local_sid);
719 u32 vio_send_sid(struct vio_driver_state *vio)
721 switch (vio->dev_class) {
726 return vio->_local_sid;
729 return vio->_peer_sid;
734 int vio_ldc_alloc(struct vio_driver_state *vio,
741 cfg.tx_irq = vio->vdev->tx_irq;
742 cfg.rx_irq = vio->vdev->rx_irq;
744 lp = ldc_alloc(vio->vdev->channel_id, &cfg, event_arg, vio->name);
748 vio->lp = lp;
754 void vio_ldc_free(struct vio_driver_state *vio)
756 ldc_free(vio->lp);
757 vio->lp = NULL;
759 kfree(vio->desc_buf);
760 vio->desc_buf = NULL;
761 vio->desc_buf_len = 0;
765 void vio_port_up(struct vio_driver_state *vio)
770 spin_lock_irqsave(&vio->lock, flags);
772 state = ldc_state(vio->lp);
776 err = ldc_bind(vio->lp);
780 vio->name, vio->vdev->channel_id, err);
784 if (ldc_mode(vio->lp) == LDC_MODE_RAW)
785 ldc_set_state(vio->lp, LDC_STATE_CONNECTED);
787 err = ldc_connect(vio->lp);
792 vio->name, vio->vdev->channel_id, err);
798 mod_timer(&vio->timer, expires);
801 spin_unlock_irqrestore(&vio->lock, flags);
807 struct vio_driver_state *vio = from_timer(vio, t, timer);
809 vio_port_up(vio);
812 int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
844 spin_lock_init(&vio->lock);
846 vio->name = name;
848 vio->dev_class = dev_class;
849 vio->vdev = vdev;
851 vio->ver_table = ver_table;
852 vio->ver_table_entries = ver_table_size;
854 vio->ops = ops;
856 timer_setup(&vio->timer, vio_port_timer, 0);