iommu/msm: Add iommu_group support
[linux/fpc-iii.git] / arch / sparc / kernel / viohs.c
blobd4f13c037a40a3b63b1e39c771c279c730b9ea31
1 /* viohs.c: LDOM Virtual I/O handshake helper layer.
3 * Copyright (C) 2007 David S. Miller <davem@davemloft.net>
4 */
6 #include <linux/kernel.h>
7 #include <linux/export.h>
8 #include <linux/string.h>
9 #include <linux/delay.h>
10 #include <linux/sched.h>
11 #include <linux/sched/clock.h>
12 #include <linux/slab.h>
14 #include <asm/ldc.h>
15 #include <asm/vio.h>
17 int vio_ldc_send(struct vio_driver_state *vio, void *data, int len)
19 int err, limit = 1000;
21 err = -EINVAL;
22 while (limit-- > 0) {
23 err = ldc_write(vio->lp, data, len);
24 if (!err || (err != -EAGAIN))
25 break;
26 udelay(1);
29 return err;
31 EXPORT_SYMBOL(vio_ldc_send);
33 static int send_ctrl(struct vio_driver_state *vio,
34 struct vio_msg_tag *tag, int len)
36 tag->sid = vio_send_sid(vio);
37 return vio_ldc_send(vio, tag, len);
40 static void init_tag(struct vio_msg_tag *tag, u8 type, u8 stype, u16 stype_env)
42 tag->type = type;
43 tag->stype = stype;
44 tag->stype_env = stype_env;
47 static int send_version(struct vio_driver_state *vio, u16 major, u16 minor)
49 struct vio_ver_info pkt;
51 vio->_local_sid = (u32) sched_clock();
53 memset(&pkt, 0, sizeof(pkt));
54 init_tag(&pkt.tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO, VIO_VER_INFO);
55 pkt.major = major;
56 pkt.minor = minor;
57 pkt.dev_class = vio->dev_class;
59 viodbg(HS, "SEND VERSION INFO maj[%u] min[%u] devclass[%u]\n",
60 major, minor, vio->dev_class);
62 return send_ctrl(vio, &pkt.tag, sizeof(pkt));
65 static int start_handshake(struct vio_driver_state *vio)
67 int err;
69 viodbg(HS, "START HANDSHAKE\n");
71 vio->hs_state = VIO_HS_INVALID;
73 err = send_version(vio,
74 vio->ver_table[0].major,
75 vio->ver_table[0].minor);
76 if (err < 0)
77 return err;
79 return 0;
82 static void flush_rx_dring(struct vio_driver_state *vio)
84 struct vio_dring_state *dr;
85 u64 ident;
87 BUG_ON(!(vio->dr_state & VIO_DR_STATE_RXREG));
89 dr = &vio->drings[VIO_DRIVER_RX_RING];
90 ident = dr->ident;
92 BUG_ON(!vio->desc_buf);
93 kfree(vio->desc_buf);
94 vio->desc_buf = NULL;
96 memset(dr, 0, sizeof(*dr));
97 dr->ident = ident;
100 void vio_link_state_change(struct vio_driver_state *vio, int event)
102 if (event == LDC_EVENT_UP) {
103 vio->hs_state = VIO_HS_INVALID;
105 switch (vio->dev_class) {
106 case VDEV_NETWORK:
107 case VDEV_NETWORK_SWITCH:
108 vio->dr_state = (VIO_DR_STATE_TXREQ |
109 VIO_DR_STATE_RXREQ);
110 break;
112 case VDEV_DISK:
113 vio->dr_state = VIO_DR_STATE_TXREQ;
114 break;
115 case VDEV_DISK_SERVER:
116 vio->dr_state = VIO_DR_STATE_RXREQ;
117 break;
119 start_handshake(vio);
120 } else if (event == LDC_EVENT_RESET) {
121 vio->hs_state = VIO_HS_INVALID;
123 if (vio->dr_state & VIO_DR_STATE_RXREG)
124 flush_rx_dring(vio);
126 vio->dr_state = 0x00;
127 memset(&vio->ver, 0, sizeof(vio->ver));
129 ldc_disconnect(vio->lp);
132 EXPORT_SYMBOL(vio_link_state_change);
134 static int handshake_failure(struct vio_driver_state *vio)
136 struct vio_dring_state *dr;
138 /* XXX Put policy here... Perhaps start a timer to fire
139 * XXX in 100 ms, which will bring the link up and retry
140 * XXX the handshake.
143 viodbg(HS, "HANDSHAKE FAILURE\n");
145 vio->dr_state &= ~(VIO_DR_STATE_TXREG |
146 VIO_DR_STATE_RXREG);
148 dr = &vio->drings[VIO_DRIVER_RX_RING];
149 memset(dr, 0, sizeof(*dr));
151 kfree(vio->desc_buf);
152 vio->desc_buf = NULL;
153 vio->desc_buf_len = 0;
155 vio->hs_state = VIO_HS_INVALID;
157 return -ECONNRESET;
160 static int process_unknown(struct vio_driver_state *vio, void *arg)
162 struct vio_msg_tag *pkt = arg;
164 viodbg(HS, "UNKNOWN CONTROL [%02x:%02x:%04x:%08x]\n",
165 pkt->type, pkt->stype, pkt->stype_env, pkt->sid);
167 printk(KERN_ERR "vio: ID[%lu] Resetting connection.\n",
168 vio->vdev->channel_id);
170 ldc_disconnect(vio->lp);
172 return -ECONNRESET;
175 static int send_dreg(struct vio_driver_state *vio)
177 struct vio_dring_state *dr = &vio->drings[VIO_DRIVER_TX_RING];
178 union {
179 struct vio_dring_register pkt;
180 char all[sizeof(struct vio_dring_register) +
181 (sizeof(struct ldc_trans_cookie) *
182 dr->ncookies)];
183 } u;
184 int i;
186 memset(&u, 0, sizeof(u));
187 init_tag(&u.pkt.tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO, VIO_DRING_REG);
188 u.pkt.dring_ident = 0;
189 u.pkt.num_descr = dr->num_entries;
190 u.pkt.descr_size = dr->entry_size;
191 u.pkt.options = VIO_TX_DRING;
192 u.pkt.num_cookies = dr->ncookies;
194 viodbg(HS, "SEND DRING_REG INFO ndesc[%u] dsz[%u] opt[0x%x] "
195 "ncookies[%u]\n",
196 u.pkt.num_descr, u.pkt.descr_size, u.pkt.options,
197 u.pkt.num_cookies);
199 for (i = 0; i < dr->ncookies; i++) {
200 u.pkt.cookies[i] = dr->cookies[i];
202 viodbg(HS, "DRING COOKIE(%d) [%016llx:%016llx]\n",
204 (unsigned long long) u.pkt.cookies[i].cookie_addr,
205 (unsigned long long) u.pkt.cookies[i].cookie_size);
208 return send_ctrl(vio, &u.pkt.tag, sizeof(u));
211 static int send_rdx(struct vio_driver_state *vio)
213 struct vio_rdx pkt;
215 memset(&pkt, 0, sizeof(pkt));
217 init_tag(&pkt.tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO, VIO_RDX);
219 viodbg(HS, "SEND RDX INFO\n");
221 return send_ctrl(vio, &pkt.tag, sizeof(pkt));
224 static int send_attr(struct vio_driver_state *vio)
226 if (!vio->ops)
227 return -EINVAL;
229 return vio->ops->send_attr(vio);
232 static struct vio_version *find_by_major(struct vio_driver_state *vio,
233 u16 major)
235 struct vio_version *ret = NULL;
236 int i;
238 for (i = 0; i < vio->ver_table_entries; i++) {
239 struct vio_version *v = &vio->ver_table[i];
240 if (v->major <= major) {
241 ret = v;
242 break;
245 return ret;
248 static int process_ver_info(struct vio_driver_state *vio,
249 struct vio_ver_info *pkt)
251 struct vio_version *vap;
252 int err;
254 viodbg(HS, "GOT VERSION INFO maj[%u] min[%u] devclass[%u]\n",
255 pkt->major, pkt->minor, pkt->dev_class);
257 if (vio->hs_state != VIO_HS_INVALID) {
258 /* XXX Perhaps invoke start_handshake? XXX */
259 memset(&vio->ver, 0, sizeof(vio->ver));
260 vio->hs_state = VIO_HS_INVALID;
263 vap = find_by_major(vio, pkt->major);
265 vio->_peer_sid = pkt->tag.sid;
267 if (!vap) {
268 pkt->tag.stype = VIO_SUBTYPE_NACK;
269 pkt->major = 0;
270 pkt->minor = 0;
271 viodbg(HS, "SEND VERSION NACK maj[0] min[0]\n");
272 err = send_ctrl(vio, &pkt->tag, sizeof(*pkt));
273 } else if (vap->major != pkt->major) {
274 pkt->tag.stype = VIO_SUBTYPE_NACK;
275 pkt->major = vap->major;
276 pkt->minor = vap->minor;
277 viodbg(HS, "SEND VERSION NACK maj[%u] min[%u]\n",
278 pkt->major, pkt->minor);
279 err = send_ctrl(vio, &pkt->tag, sizeof(*pkt));
280 } else {
281 struct vio_version ver = {
282 .major = pkt->major,
283 .minor = pkt->minor,
285 if (ver.minor > vap->minor)
286 ver.minor = vap->minor;
287 pkt->minor = ver.minor;
288 pkt->tag.stype = VIO_SUBTYPE_ACK;
289 pkt->dev_class = vio->dev_class;
290 viodbg(HS, "SEND VERSION ACK maj[%u] min[%u]\n",
291 pkt->major, pkt->minor);
292 err = send_ctrl(vio, &pkt->tag, sizeof(*pkt));
293 if (err > 0) {
294 vio->ver = ver;
295 vio->hs_state = VIO_HS_GOTVERS;
298 if (err < 0)
299 return handshake_failure(vio);
301 return 0;
304 static int process_ver_ack(struct vio_driver_state *vio,
305 struct vio_ver_info *pkt)
307 viodbg(HS, "GOT VERSION ACK maj[%u] min[%u] devclass[%u]\n",
308 pkt->major, pkt->minor, pkt->dev_class);
310 if (vio->hs_state & VIO_HS_GOTVERS) {
311 if (vio->ver.major != pkt->major ||
312 vio->ver.minor != pkt->minor) {
313 pkt->tag.stype = VIO_SUBTYPE_NACK;
314 (void) send_ctrl(vio, &pkt->tag, sizeof(*pkt));
315 return handshake_failure(vio);
317 } else {
318 vio->ver.major = pkt->major;
319 vio->ver.minor = pkt->minor;
320 vio->hs_state = VIO_HS_GOTVERS;
323 switch (vio->dev_class) {
324 case VDEV_NETWORK:
325 case VDEV_DISK:
326 if (send_attr(vio) < 0)
327 return handshake_failure(vio);
328 break;
330 default:
331 break;
334 return 0;
337 static int process_ver_nack(struct vio_driver_state *vio,
338 struct vio_ver_info *pkt)
340 struct vio_version *nver;
342 viodbg(HS, "GOT VERSION NACK maj[%u] min[%u] devclass[%u]\n",
343 pkt->major, pkt->minor, pkt->dev_class);
345 if (pkt->major == 0 && pkt->minor == 0)
346 return handshake_failure(vio);
347 nver = find_by_major(vio, pkt->major);
348 if (!nver)
349 return handshake_failure(vio);
351 if (send_version(vio, nver->major, nver->minor) < 0)
352 return handshake_failure(vio);
354 return 0;
357 static int process_ver(struct vio_driver_state *vio, struct vio_ver_info *pkt)
359 switch (pkt->tag.stype) {
360 case VIO_SUBTYPE_INFO:
361 return process_ver_info(vio, pkt);
363 case VIO_SUBTYPE_ACK:
364 return process_ver_ack(vio, pkt);
366 case VIO_SUBTYPE_NACK:
367 return process_ver_nack(vio, pkt);
369 default:
370 return handshake_failure(vio);
374 static int process_attr(struct vio_driver_state *vio, void *pkt)
376 int err;
378 if (!(vio->hs_state & VIO_HS_GOTVERS))
379 return handshake_failure(vio);
381 if (!vio->ops)
382 return 0;
384 err = vio->ops->handle_attr(vio, pkt);
385 if (err < 0) {
386 return handshake_failure(vio);
387 } else {
388 vio->hs_state |= VIO_HS_GOT_ATTR;
390 if ((vio->dr_state & VIO_DR_STATE_TXREQ) &&
391 !(vio->hs_state & VIO_HS_SENT_DREG)) {
392 if (send_dreg(vio) < 0)
393 return handshake_failure(vio);
395 vio->hs_state |= VIO_HS_SENT_DREG;
399 return 0;
402 static int all_drings_registered(struct vio_driver_state *vio)
404 int need_rx, need_tx;
406 need_rx = (vio->dr_state & VIO_DR_STATE_RXREQ);
407 need_tx = (vio->dr_state & VIO_DR_STATE_TXREQ);
409 if (need_rx &&
410 !(vio->dr_state & VIO_DR_STATE_RXREG))
411 return 0;
413 if (need_tx &&
414 !(vio->dr_state & VIO_DR_STATE_TXREG))
415 return 0;
417 return 1;
420 static int process_dreg_info(struct vio_driver_state *vio,
421 struct vio_dring_register *pkt)
423 struct vio_dring_state *dr;
424 int i, len;
426 viodbg(HS, "GOT DRING_REG INFO ident[%llx] "
427 "ndesc[%u] dsz[%u] opt[0x%x] ncookies[%u]\n",
428 (unsigned long long) pkt->dring_ident,
429 pkt->num_descr, pkt->descr_size, pkt->options,
430 pkt->num_cookies);
432 if (!(vio->dr_state & VIO_DR_STATE_RXREQ))
433 goto send_nack;
435 if (vio->dr_state & VIO_DR_STATE_RXREG)
436 goto send_nack;
438 /* v1.6 and higher, ACK with desired, supported mode, or NACK */
439 if (vio_version_after_eq(vio, 1, 6)) {
440 if (!(pkt->options & VIO_TX_DRING))
441 goto send_nack;
442 pkt->options = VIO_TX_DRING;
445 BUG_ON(vio->desc_buf);
447 vio->desc_buf = kzalloc(pkt->descr_size, GFP_ATOMIC);
448 if (!vio->desc_buf)
449 goto send_nack;
451 vio->desc_buf_len = pkt->descr_size;
453 dr = &vio->drings[VIO_DRIVER_RX_RING];
455 dr->num_entries = pkt->num_descr;
456 dr->entry_size = pkt->descr_size;
457 dr->ncookies = pkt->num_cookies;
458 for (i = 0; i < dr->ncookies; i++) {
459 dr->cookies[i] = pkt->cookies[i];
461 viodbg(HS, "DRING COOKIE(%d) [%016llx:%016llx]\n",
463 (unsigned long long)
464 pkt->cookies[i].cookie_addr,
465 (unsigned long long)
466 pkt->cookies[i].cookie_size);
469 pkt->tag.stype = VIO_SUBTYPE_ACK;
470 pkt->dring_ident = ++dr->ident;
472 viodbg(HS, "SEND DRING_REG ACK ident[%llx] "
473 "ndesc[%u] dsz[%u] opt[0x%x] ncookies[%u]\n",
474 (unsigned long long) pkt->dring_ident,
475 pkt->num_descr, pkt->descr_size, pkt->options,
476 pkt->num_cookies);
478 len = (sizeof(*pkt) +
479 (dr->ncookies * sizeof(struct ldc_trans_cookie)));
480 if (send_ctrl(vio, &pkt->tag, len) < 0)
481 goto send_nack;
483 vio->dr_state |= VIO_DR_STATE_RXREG;
485 return 0;
487 send_nack:
488 pkt->tag.stype = VIO_SUBTYPE_NACK;
489 viodbg(HS, "SEND DRING_REG NACK\n");
490 (void) send_ctrl(vio, &pkt->tag, sizeof(*pkt));
492 return handshake_failure(vio);
495 static int process_dreg_ack(struct vio_driver_state *vio,
496 struct vio_dring_register *pkt)
498 struct vio_dring_state *dr;
500 viodbg(HS, "GOT DRING_REG ACK ident[%llx] "
501 "ndesc[%u] dsz[%u] opt[0x%x] ncookies[%u]\n",
502 (unsigned long long) pkt->dring_ident,
503 pkt->num_descr, pkt->descr_size, pkt->options,
504 pkt->num_cookies);
506 dr = &vio->drings[VIO_DRIVER_TX_RING];
508 if (!(vio->dr_state & VIO_DR_STATE_TXREQ))
509 return handshake_failure(vio);
511 dr->ident = pkt->dring_ident;
512 vio->dr_state |= VIO_DR_STATE_TXREG;
514 if (all_drings_registered(vio)) {
515 if (send_rdx(vio) < 0)
516 return handshake_failure(vio);
517 vio->hs_state = VIO_HS_SENT_RDX;
519 return 0;
522 static int process_dreg_nack(struct vio_driver_state *vio,
523 struct vio_dring_register *pkt)
525 viodbg(HS, "GOT DRING_REG NACK ident[%llx] "
526 "ndesc[%u] dsz[%u] opt[0x%x] ncookies[%u]\n",
527 (unsigned long long) pkt->dring_ident,
528 pkt->num_descr, pkt->descr_size, pkt->options,
529 pkt->num_cookies);
531 return handshake_failure(vio);
534 static int process_dreg(struct vio_driver_state *vio,
535 struct vio_dring_register *pkt)
537 if (!(vio->hs_state & VIO_HS_GOTVERS))
538 return handshake_failure(vio);
540 switch (pkt->tag.stype) {
541 case VIO_SUBTYPE_INFO:
542 return process_dreg_info(vio, pkt);
544 case VIO_SUBTYPE_ACK:
545 return process_dreg_ack(vio, pkt);
547 case VIO_SUBTYPE_NACK:
548 return process_dreg_nack(vio, pkt);
550 default:
551 return handshake_failure(vio);
555 static int process_dunreg(struct vio_driver_state *vio,
556 struct vio_dring_unregister *pkt)
558 struct vio_dring_state *dr = &vio->drings[VIO_DRIVER_RX_RING];
560 viodbg(HS, "GOT DRING_UNREG\n");
562 if (pkt->dring_ident != dr->ident)
563 return 0;
565 vio->dr_state &= ~VIO_DR_STATE_RXREG;
567 memset(dr, 0, sizeof(*dr));
569 kfree(vio->desc_buf);
570 vio->desc_buf = NULL;
571 vio->desc_buf_len = 0;
573 return 0;
576 static int process_rdx_info(struct vio_driver_state *vio, struct vio_rdx *pkt)
578 viodbg(HS, "GOT RDX INFO\n");
580 pkt->tag.stype = VIO_SUBTYPE_ACK;
581 viodbg(HS, "SEND RDX ACK\n");
582 if (send_ctrl(vio, &pkt->tag, sizeof(*pkt)) < 0)
583 return handshake_failure(vio);
585 vio->hs_state |= VIO_HS_SENT_RDX_ACK;
586 return 0;
589 static int process_rdx_ack(struct vio_driver_state *vio, struct vio_rdx *pkt)
591 viodbg(HS, "GOT RDX ACK\n");
593 if (!(vio->hs_state & VIO_HS_SENT_RDX))
594 return handshake_failure(vio);
596 vio->hs_state |= VIO_HS_GOT_RDX_ACK;
597 return 0;
600 static int process_rdx_nack(struct vio_driver_state *vio, struct vio_rdx *pkt)
602 viodbg(HS, "GOT RDX NACK\n");
604 return handshake_failure(vio);
607 static int process_rdx(struct vio_driver_state *vio, struct vio_rdx *pkt)
609 if (!all_drings_registered(vio))
610 handshake_failure(vio);
612 switch (pkt->tag.stype) {
613 case VIO_SUBTYPE_INFO:
614 return process_rdx_info(vio, pkt);
616 case VIO_SUBTYPE_ACK:
617 return process_rdx_ack(vio, pkt);
619 case VIO_SUBTYPE_NACK:
620 return process_rdx_nack(vio, pkt);
622 default:
623 return handshake_failure(vio);
627 int vio_control_pkt_engine(struct vio_driver_state *vio, void *pkt)
629 struct vio_msg_tag *tag = pkt;
630 u8 prev_state = vio->hs_state;
631 int err;
633 switch (tag->stype_env) {
634 case VIO_VER_INFO:
635 err = process_ver(vio, pkt);
636 break;
638 case VIO_ATTR_INFO:
639 err = process_attr(vio, pkt);
640 break;
642 case VIO_DRING_REG:
643 err = process_dreg(vio, pkt);
644 break;
646 case VIO_DRING_UNREG:
647 err = process_dunreg(vio, pkt);
648 break;
650 case VIO_RDX:
651 err = process_rdx(vio, pkt);
652 break;
654 default:
655 err = process_unknown(vio, pkt);
656 break;
659 if (!err &&
660 vio->hs_state != prev_state &&
661 (vio->hs_state & VIO_HS_COMPLETE)) {
662 if (vio->ops)
663 vio->ops->handshake_complete(vio);
666 return err;
668 EXPORT_SYMBOL(vio_control_pkt_engine);
670 void vio_conn_reset(struct vio_driver_state *vio)
673 EXPORT_SYMBOL(vio_conn_reset);
675 /* The issue is that the Solaris virtual disk server just mirrors the
676 * SID values it gets from the client peer. So we work around that
677 * here in vio_{validate,send}_sid() so that the drivers don't need
678 * to be aware of this crap.
680 int vio_validate_sid(struct vio_driver_state *vio, struct vio_msg_tag *tp)
682 u32 sid;
684 /* Always let VERSION+INFO packets through unchecked, they
685 * define the new SID.
687 if (tp->type == VIO_TYPE_CTRL &&
688 tp->stype == VIO_SUBTYPE_INFO &&
689 tp->stype_env == VIO_VER_INFO)
690 return 0;
692 /* Ok, now figure out which SID to use. */
693 switch (vio->dev_class) {
694 case VDEV_NETWORK:
695 case VDEV_NETWORK_SWITCH:
696 case VDEV_DISK_SERVER:
697 default:
698 sid = vio->_peer_sid;
699 break;
701 case VDEV_DISK:
702 sid = vio->_local_sid;
703 break;
706 if (sid == tp->sid)
707 return 0;
708 viodbg(DATA, "BAD SID tag->sid[%08x] peer_sid[%08x] local_sid[%08x]\n",
709 tp->sid, vio->_peer_sid, vio->_local_sid);
710 return -EINVAL;
712 EXPORT_SYMBOL(vio_validate_sid);
714 u32 vio_send_sid(struct vio_driver_state *vio)
716 switch (vio->dev_class) {
717 case VDEV_NETWORK:
718 case VDEV_NETWORK_SWITCH:
719 case VDEV_DISK:
720 default:
721 return vio->_local_sid;
723 case VDEV_DISK_SERVER:
724 return vio->_peer_sid;
727 EXPORT_SYMBOL(vio_send_sid);
729 int vio_ldc_alloc(struct vio_driver_state *vio,
730 struct ldc_channel_config *base_cfg,
731 void *event_arg)
733 struct ldc_channel_config cfg = *base_cfg;
734 struct ldc_channel *lp;
736 cfg.tx_irq = vio->vdev->tx_irq;
737 cfg.rx_irq = vio->vdev->rx_irq;
739 lp = ldc_alloc(vio->vdev->channel_id, &cfg, event_arg, vio->name);
740 if (IS_ERR(lp))
741 return PTR_ERR(lp);
743 vio->lp = lp;
745 return 0;
747 EXPORT_SYMBOL(vio_ldc_alloc);
749 void vio_ldc_free(struct vio_driver_state *vio)
751 ldc_free(vio->lp);
752 vio->lp = NULL;
754 kfree(vio->desc_buf);
755 vio->desc_buf = NULL;
756 vio->desc_buf_len = 0;
758 EXPORT_SYMBOL(vio_ldc_free);
760 void vio_port_up(struct vio_driver_state *vio)
762 unsigned long flags;
763 int err, state;
765 spin_lock_irqsave(&vio->lock, flags);
767 state = ldc_state(vio->lp);
769 err = 0;
770 if (state == LDC_STATE_INIT) {
771 err = ldc_bind(vio->lp);
772 if (err)
773 printk(KERN_WARNING "%s: Port %lu bind failed, "
774 "err=%d\n",
775 vio->name, vio->vdev->channel_id, err);
778 if (!err) {
779 if (ldc_mode(vio->lp) == LDC_MODE_RAW)
780 ldc_set_state(vio->lp, LDC_STATE_CONNECTED);
781 else
782 err = ldc_connect(vio->lp);
784 if (err)
785 printk(KERN_WARNING "%s: Port %lu connect failed, "
786 "err=%d\n",
787 vio->name, vio->vdev->channel_id, err);
789 if (err) {
790 unsigned long expires = jiffies + HZ;
792 expires = round_jiffies(expires);
793 mod_timer(&vio->timer, expires);
796 spin_unlock_irqrestore(&vio->lock, flags);
798 EXPORT_SYMBOL(vio_port_up);
800 static void vio_port_timer(unsigned long _arg)
802 struct vio_driver_state *vio = (struct vio_driver_state *) _arg;
804 vio_port_up(vio);
807 int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
808 u8 dev_class, struct vio_version *ver_table,
809 int ver_table_size, struct vio_driver_ops *ops,
810 char *name)
812 switch (dev_class) {
813 case VDEV_NETWORK:
814 case VDEV_NETWORK_SWITCH:
815 case VDEV_DISK:
816 case VDEV_DISK_SERVER:
817 break;
819 default:
820 return -EINVAL;
823 if (!ops || !ops->send_attr || !ops->handle_attr ||
824 !ops->handshake_complete)
825 return -EINVAL;
827 if (!ver_table || ver_table_size < 0)
828 return -EINVAL;
830 if (!name)
831 return -EINVAL;
833 spin_lock_init(&vio->lock);
835 vio->name = name;
837 vio->dev_class = dev_class;
838 vio->vdev = vdev;
840 vio->ver_table = ver_table;
841 vio->ver_table_entries = ver_table_size;
843 vio->ops = ops;
845 setup_timer(&vio->timer, vio_port_timer, (unsigned long) vio);
847 return 0;
849 EXPORT_SYMBOL(vio_driver_init);