1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/types.h>
14#include <linux/kernel.h>
15
16#include <linux/delay.h>
17#include <linux/dma-mapping.h>
18#include <linux/init.h>
19#include <linux/rio.h>
20#include <linux/rio_drv.h>
21#include <linux/rio_ids.h>
22#include <linux/rio_regs.h>
23#include <linux/module.h>
24#include <linux/spinlock.h>
25#include <linux/timer.h>
26#include <linux/jiffies.h>
27#include <linux/slab.h>
28
29#include "rio.h"
30
31LIST_HEAD(rio_devices);
32static LIST_HEAD(rio_switches);
33
34#define RIO_ENUM_CMPL_MAGIC 0xdeadbeef
35
36static void rio_enum_timeout(unsigned long);
37
38DEFINE_SPINLOCK(rio_global_list_lock);
39
40static int next_destid = 0;
41static int next_switchid = 0;
42static int next_net = 0;
43
44static struct timer_list rio_enum_timer =
45TIMER_INITIALIZER(rio_enum_timeout, 0, 0);
46
47static int rio_mport_phys_table[] = {
48 RIO_EFB_PAR_EP_ID,
49 RIO_EFB_PAR_EP_REC_ID,
50 RIO_EFB_SER_EP_ID,
51 RIO_EFB_SER_EP_REC_ID,
52 -1,
53};
54
55static int rio_sport_phys_table[] = {
56 RIO_EFB_PAR_EP_FREE_ID,
57 RIO_EFB_SER_EP_FREE_ID,
58 -1,
59};
60
61
62
63
64
65
66
67
68
69
70static u16 rio_get_device_id(struct rio_mport *port, u16 destid, u8 hopcount)
71{
72 u32 result;
73
74 rio_mport_read_config_32(port, destid, hopcount, RIO_DID_CSR, &result);
75
76 return RIO_GET_DID(port->sys_size, result);
77}
78
79
80
81
82
83
84
85
86
87
88static void rio_set_device_id(struct rio_mport *port, u16 destid, u8 hopcount, u16 did)
89{
90 rio_mport_write_config_32(port, destid, hopcount, RIO_DID_CSR,
91 RIO_SET_DID(port->sys_size, did));
92}
93
94
95
96
97
98
99
100
101static void rio_local_set_device_id(struct rio_mport *port, u16 did)
102{
103 rio_local_write_config_32(port, RIO_DID_CSR, RIO_SET_DID(port->sys_size,
104 did));
105}
106
107
108
109
110
111
112
113
114
115static int rio_clear_locks(struct rio_mport *port)
116{
117 struct rio_dev *rdev;
118 u32 result;
119 int ret = 0;
120
121
122 rio_local_write_config_32(port, RIO_COMPONENT_TAG_CSR,
123 RIO_ENUM_CMPL_MAGIC);
124 list_for_each_entry(rdev, &rio_devices, global_list)
125 rio_write_config_32(rdev, RIO_COMPONENT_TAG_CSR,
126 RIO_ENUM_CMPL_MAGIC);
127
128
129 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR,
130 port->host_deviceid);
131 rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result);
132 if ((result & 0xffff) != 0xffff) {
133 printk(KERN_INFO
134 "RIO: badness when releasing host lock on master port, result %8.8x\n",
135 result);
136 ret = -EINVAL;
137 }
138 list_for_each_entry(rdev, &rio_devices, global_list) {
139 rio_write_config_32(rdev, RIO_HOST_DID_LOCK_CSR,
140 port->host_deviceid);
141 rio_read_config_32(rdev, RIO_HOST_DID_LOCK_CSR, &result);
142 if ((result & 0xffff) != 0xffff) {
143 printk(KERN_INFO
144 "RIO: badness when releasing host lock on vid %4.4x did %4.4x\n",
145 rdev->vid, rdev->did);
146 ret = -EINVAL;
147 }
148 }
149
150 return ret;
151}
152
153
154
155
156
157
158
159
160
161static int rio_enum_host(struct rio_mport *port)
162{
163 u32 result;
164
165
166 rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR,
167 port->host_deviceid);
168
169 rio_local_read_config_32(port, RIO_HOST_DID_LOCK_CSR, &result);
170 if ((result & 0xffff) != port->host_deviceid)
171 return -1;
172
173
174 rio_local_set_device_id(port, port->host_deviceid);
175
176 if (next_destid == port->host_deviceid)
177 next_destid++;
178
179 return 0;
180}
181
182
183
184
185
186
187
188
189
190
191
192static int rio_device_has_destid(struct rio_mport *port, int src_ops,
193 int dst_ops)
194{
195 u32 mask = RIO_OPS_READ | RIO_OPS_WRITE | RIO_OPS_ATOMIC_TST_SWP | RIO_OPS_ATOMIC_INC | RIO_OPS_ATOMIC_DEC | RIO_OPS_ATOMIC_SET | RIO_OPS_ATOMIC_CLR;
196
197 return !!((src_ops | dst_ops) & mask);
198}
199
200
201
202
203
204
205
206
207static void rio_release_dev(struct device *dev)
208{
209 struct rio_dev *rdev;
210
211 rdev = to_rio_dev(dev);
212 kfree(rdev);
213}
214
215
216
217
218
219
220
221
222
223
224static int rio_is_switch(struct rio_dev *rdev)
225{
226 if (rdev->pef & RIO_PEF_SWITCH)
227 return 1;
228 return 0;
229}
230
231
232
233
234
235
236
237
238
239static void rio_route_set_ops(struct rio_dev *rdev)
240{
241 struct rio_route_ops *cur = __start_rio_route_ops;
242 struct rio_route_ops *end = __end_rio_route_ops;
243
244 while (cur < end) {
245 if ((cur->vid == rdev->vid) && (cur->did == rdev->did)) {
246 pr_debug("RIO: adding routing ops for %s\n", rio_name(rdev));
247 rdev->rswitch->add_entry = cur->add_hook;
248 rdev->rswitch->get_entry = cur->get_hook;
249 }
250 cur++;
251 }
252
253 if (!rdev->rswitch->add_entry || !rdev->rswitch->get_entry)
254 printk(KERN_ERR "RIO: missing routing ops for %s\n",
255 rio_name(rdev));
256}
257
258
259
260
261
262
263
264
265
266static void __devinit rio_add_device(struct rio_dev *rdev)
267{
268 device_add(&rdev->dev);
269
270 spin_lock(&rio_global_list_lock);
271 list_add_tail(&rdev->global_list, &rio_devices);
272 spin_unlock(&rio_global_list_lock);
273
274 rio_create_sysfs_dev_files(rdev);
275}
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293static struct rio_dev *rio_setup_device(struct rio_net *net,
294 struct rio_mport *port, u16 destid,
295 u8 hopcount, int do_enum)
296{
297 struct rio_dev *rdev;
298 struct rio_switch *rswitch;
299 int result, rdid;
300
301 rdev = kzalloc(sizeof(struct rio_dev), GFP_KERNEL);
302 if (!rdev)
303 goto out;
304
305 rdev->net = net;
306 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR,
307 &result);
308 rdev->did = result >> 16;
309 rdev->vid = result & 0xffff;
310 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_INFO_CAR,
311 &rdev->device_rev);
312 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_ID_CAR,
313 &result);
314 rdev->asm_did = result >> 16;
315 rdev->asm_vid = result & 0xffff;
316 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR,
317 &result);
318 rdev->asm_rev = result >> 16;
319 rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR,
320 &rdev->pef);
321 if (rdev->pef & RIO_PEF_EXT_FEATURES)
322 rdev->efptr = result & 0xffff;
323
324 rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR,
325 &rdev->src_ops);
326 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR,
327 &rdev->dst_ops);
328
329 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) {
330 if (do_enum) {
331 rio_set_device_id(port, destid, hopcount, next_destid);
332 rdev->destid = next_destid++;
333 if (next_destid == port->host_deviceid)
334 next_destid++;
335 } else
336 rdev->destid = rio_get_device_id(port, destid, hopcount);
337 } else
338
339 rdev->destid = RIO_INVALID_DESTID;
340
341
342 if (rio_is_switch(rdev)) {
343 rio_mport_read_config_32(port, destid, hopcount,
344 RIO_SWP_INFO_CAR, &rdev->swpinfo);
345 rswitch = kmalloc(sizeof(struct rio_switch), GFP_KERNEL);
346 if (!rswitch) {
347 kfree(rdev);
348 rdev = NULL;
349 goto out;
350 }
351 rswitch->switchid = next_switchid;
352 rswitch->hopcount = hopcount;
353 rswitch->destid = destid;
354 rswitch->route_table = kzalloc(sizeof(u8)*
355 RIO_MAX_ROUTE_ENTRIES(port->sys_size),
356 GFP_KERNEL);
357 if (!rswitch->route_table) {
358 kfree(rdev);
359 rdev = NULL;
360 kfree(rswitch);
361 goto out;
362 }
363
364 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES(port->sys_size);
365 rdid++)
366 rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
367 rdev->rswitch = rswitch;
368 sprintf(rio_name(rdev), "%02x:s:%04x", rdev->net->id,
369 rdev->rswitch->switchid);
370 rio_route_set_ops(rdev);
371
372 list_add_tail(&rswitch->node, &rio_switches);
373
374 } else
375 sprintf(rio_name(rdev), "%02x:e:%04x", rdev->net->id,
376 rdev->destid);
377
378 rdev->dev.bus = &rio_bus_type;
379
380 device_initialize(&rdev->dev);
381 rdev->dev.release = rio_release_dev;
382 rio_dev_get(rdev);
383
384 rdev->dma_mask = DMA_32BIT_MASK;
385 rdev->dev.dma_mask = &rdev->dma_mask;
386 rdev->dev.coherent_dma_mask = DMA_32BIT_MASK;
387
388 if ((rdev->pef & RIO_PEF_INB_DOORBELL) &&
389 (rdev->dst_ops & RIO_DST_OPS_DOORBELL))
390 rio_init_dbell_res(&rdev->riores[RIO_DOORBELL_RESOURCE],
391 0, 0xffff);
392
393 rio_add_device(rdev);
394
395 out:
396 return rdev;
397}
398
399
400
401
402
403
404
405
406
407
408
409
410
411static int
412rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport)
413{
414 u32 result;
415 u32 ext_ftr_ptr;
416
417 int *entry = rio_sport_phys_table;
418
419 do {
420 if ((ext_ftr_ptr =
421 rio_mport_get_feature(port, 0, destid, hopcount, *entry)))
422
423 break;
424 } while (*++entry >= 0);
425
426 if (ext_ftr_ptr)
427 rio_mport_read_config_32(port, destid, hopcount,
428 ext_ftr_ptr +
429 RIO_PORT_N_ERR_STS_CSR(sport),
430 &result);
431
432 return (result & PORT_N_ERR_STS_PORT_OK);
433}
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450static int rio_route_add_entry(struct rio_mport *mport, struct rio_switch *rswitch,
451 u16 table, u16 route_destid, u8 route_port)
452{
453 return rswitch->add_entry(mport, rswitch->destid,
454 rswitch->hopcount, table,
455 route_destid, route_port);
456}
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473static int
474rio_route_get_entry(struct rio_mport *mport, struct rio_switch *rswitch, u16 table,
475 u16 route_destid, u8 * route_port)
476{
477 return rswitch->get_entry(mport, rswitch->destid,
478 rswitch->hopcount, table,
479 route_destid, route_port);
480}
481
482
483
484
485
486
487
488
489
490static u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount)
491{
492 u32 result;
493
494 rio_mport_read_config_32(port, RIO_ANY_DESTID(port->sys_size), hopcount,
495 RIO_HOST_DID_LOCK_CSR, &result);
496
497 return (u16) (result & 0xffff);
498}
499
500
501
502
503
504
505
506
507
508static u8
509rio_get_swpinfo_inport(struct rio_mport *mport, u16 destid, u8 hopcount)
510{
511 u32 result;
512
513 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
514 &result);
515
516 return (u8) (result & 0xff);
517}
518
519
520
521
522
523
524
525
526
527static u8 rio_get_swpinfo_tports(struct rio_mport *mport, u16 destid,
528 u8 hopcount)
529{
530 u32 result;
531
532 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
533 &result);
534
535 return RIO_GET_TOTAL_PORTS(result);
536}
537
538
539
540
541
542
543
544
545
546static void rio_net_add_mport(struct rio_net *net, struct rio_mport *port)
547{
548 spin_lock(&rio_global_list_lock);
549 list_add_tail(&port->nnode, &net->mports);
550 spin_unlock(&rio_global_list_lock);
551}
552
553
554
555
556
557
558
559
560
561
562static int rio_enum_peer(struct rio_net *net, struct rio_mport *port,
563 u8 hopcount)
564{
565 int port_num;
566 int num_ports;
567 int cur_destid;
568 int sw_destid;
569 int sw_inport;
570 struct rio_dev *rdev;
571 u16 destid;
572 int tmp;
573
574 if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) {
575 pr_debug("RIO: PE already discovered by this host\n");
576
577
578
579
580 rio_net_add_mport(net, port);
581 return 0;
582 }
583
584
585 rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size),
586 hopcount,
587 RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
588 while ((tmp = rio_get_host_deviceid_lock(port, hopcount))
589 < port->host_deviceid) {
590
591 mdelay(1);
592
593 rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size),
594 hopcount,
595 RIO_HOST_DID_LOCK_CSR,
596 port->host_deviceid);
597 }
598
599 if (rio_get_host_deviceid_lock(port, hopcount) > port->host_deviceid) {
600 pr_debug(
601 "RIO: PE locked by a higher priority host...retreating\n");
602 return -1;
603 }
604
605
606 rdev = rio_setup_device(net, port, RIO_ANY_DESTID(port->sys_size),
607 hopcount, 1);
608 if (rdev) {
609
610 list_add_tail(&rdev->net_list, &net->devices);
611 } else
612 return -1;
613
614 if (rio_is_switch(rdev)) {
615 next_switchid++;
616 sw_inport = rio_get_swpinfo_inport(port,
617 RIO_ANY_DESTID(port->sys_size), hopcount);
618 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE,
619 port->host_deviceid, sw_inport);
620 rdev->rswitch->route_table[port->host_deviceid] = sw_inport;
621
622 for (destid = 0; destid < next_destid; destid++) {
623 if (destid == port->host_deviceid)
624 continue;
625 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE,
626 destid, sw_inport);
627 rdev->rswitch->route_table[destid] = sw_inport;
628 }
629
630 num_ports =
631 rio_get_swpinfo_tports(port, RIO_ANY_DESTID(port->sys_size),
632 hopcount);
633 pr_debug(
634 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
635 rio_name(rdev), rdev->vid, rdev->did, num_ports);
636 sw_destid = next_destid;
637 for (port_num = 0; port_num < num_ports; port_num++) {
638 if (sw_inport == port_num)
639 continue;
640
641 cur_destid = next_destid;
642
643 if (rio_sport_is_active
644 (port, RIO_ANY_DESTID(port->sys_size), hopcount,
645 port_num)) {
646 pr_debug(
647 "RIO: scanning device on port %d\n",
648 port_num);
649 rio_route_add_entry(port, rdev->rswitch,
650 RIO_GLOBAL_TABLE,
651 RIO_ANY_DESTID(port->sys_size),
652 port_num);
653
654 if (rio_enum_peer(net, port, hopcount + 1) < 0)
655 return -1;
656
657
658 if (next_destid > cur_destid) {
659 for (destid = cur_destid;
660 destid < next_destid; destid++) {
661 if (destid == port->host_deviceid)
662 continue;
663 rio_route_add_entry(port, rdev->rswitch,
664 RIO_GLOBAL_TABLE,
665 destid,
666 port_num);
667 rdev->rswitch->
668 route_table[destid] =
669 port_num;
670 }
671 }
672 }
673 }
674
675
676 if (next_destid == sw_destid) {
677 next_destid++;
678 if (next_destid == port->host_deviceid)
679 next_destid++;
680 }
681
682 rdev->rswitch->destid = sw_destid;
683 } else
684 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
685 rio_name(rdev), rdev->vid, rdev->did);
686
687 return 0;
688}
689
690
691
692
693
694
695
696
697
698static int rio_enum_complete(struct rio_mport *port)
699{
700 u32 tag_csr;
701 int ret = 0;
702
703 rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr);
704
705 if (tag_csr == RIO_ENUM_CMPL_MAGIC)
706 ret = 1;
707
708 return ret;
709}
710
711
712
713
714
715
716
717
718
719
720
721static int
722rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
723 u8 hopcount)
724{
725 u8 port_num, route_port;
726 int num_ports;
727 struct rio_dev *rdev;
728 u16 ndestid;
729
730
731 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) {
732
733 list_add_tail(&rdev->net_list, &net->devices);
734 } else
735 return -1;
736
737 if (rio_is_switch(rdev)) {
738 next_switchid++;
739
740
741 rdev->rswitch->destid = destid;
742
743 num_ports = rio_get_swpinfo_tports(port, destid, hopcount);
744 pr_debug(
745 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
746 rio_name(rdev), rdev->vid, rdev->did, num_ports);
747 for (port_num = 0; port_num < num_ports; port_num++) {
748 if (rio_get_swpinfo_inport(port, destid, hopcount) ==
749 port_num)
750 continue;
751
752 if (rio_sport_is_active
753 (port, destid, hopcount, port_num)) {
754 pr_debug(
755 "RIO: scanning device on port %d\n",
756 port_num);
757 for (ndestid = 0;
758 ndestid < RIO_ANY_DESTID(port->sys_size);
759 ndestid++) {
760 rio_route_get_entry(port, rdev->rswitch,
761 RIO_GLOBAL_TABLE,
762 ndestid,
763 &route_port);
764 if (route_port == port_num)
765 break;
766 }
767
768 if (rio_disc_peer
769 (net, port, ndestid, hopcount + 1) < 0)
770 return -1;
771 }
772 }
773 } else
774 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
775 rio_name(rdev), rdev->vid, rdev->did);
776
777 return 0;
778}
779
780
781
782
783
784
785
786
787
788
789static int rio_mport_is_active(struct rio_mport *port)
790{
791 u32 result = 0;
792 u32 ext_ftr_ptr;
793 int *entry = rio_mport_phys_table;
794
795 do {
796 if ((ext_ftr_ptr =
797 rio_mport_get_feature(port, 1, 0, 0, *entry)))
798 break;
799 } while (*++entry >= 0);
800
801 if (ext_ftr_ptr)
802 rio_local_read_config_32(port,
803 ext_ftr_ptr +
804 RIO_PORT_N_ERR_STS_CSR(port->index),
805 &result);
806
807 return (result & PORT_N_ERR_STS_PORT_OK);
808}
809
810
811
812
813
814
815
816
817
818
819static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port)
820{
821 struct rio_net *net;
822
823 net = kzalloc(sizeof(struct rio_net), GFP_KERNEL);
824 if (net) {
825 INIT_LIST_HEAD(&net->node);
826 INIT_LIST_HEAD(&net->devices);
827 INIT_LIST_HEAD(&net->mports);
828 list_add_tail(&port->nnode, &net->mports);
829 net->hport = port;
830 net->id = next_net++;
831 }
832 return net;
833}
834
835
836
837
838
839
840
841
842
843static void rio_update_route_tables(struct rio_mport *port)
844{
845 struct rio_dev *rdev;
846 struct rio_switch *rswitch;
847 u8 sport;
848 u16 destid;
849
850 list_for_each_entry(rdev, &rio_devices, global_list) {
851
852 destid = (rio_is_switch(rdev))?rdev->rswitch->destid:rdev->destid;
853
854 list_for_each_entry(rswitch, &rio_switches, node) {
855
856 if (rio_is_switch(rdev) && (rdev->rswitch == rswitch))
857 continue;
858
859 if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) {
860
861 sport = rio_get_swpinfo_inport(port,
862 rswitch->destid, rswitch->hopcount);
863
864 if (rswitch->add_entry) {
865 rio_route_add_entry(port, rswitch, RIO_GLOBAL_TABLE, destid, sport);
866 rswitch->route_table[destid] = sport;
867 }
868 }
869 }
870 }
871}
872
873
874
875
876
877
878
879
880
881
882int rio_enum_mport(struct rio_mport *mport)
883{
884 struct rio_net *net = NULL;
885 int rc = 0;
886
887 printk(KERN_INFO "RIO: enumerate master port %d, %s\n", mport->id,
888 mport->name);
889
890 if (rio_enum_host(mport) < 0) {
891 printk(KERN_INFO
892 "RIO: master port %d device has been enumerated by a remote host\n",
893 mport->id);
894 rc = -EBUSY;
895 goto out;
896 }
897
898
899 if (rio_mport_is_active(mport)) {
900 if (!(net = rio_alloc_net(mport))) {
901 printk(KERN_ERR "RIO: failed to allocate new net\n");
902 rc = -ENOMEM;
903 goto out;
904 }
905 if (rio_enum_peer(net, mport, 0) < 0) {
906
907 printk(KERN_INFO
908 "RIO: master port %d device has lost enumeration to a remote host\n",
909 mport->id);
910 rio_clear_locks(mport);
911 rc = -EBUSY;
912 goto out;
913 }
914 rio_update_route_tables(mport);
915 rio_clear_locks(mport);
916 } else {
917 printk(KERN_INFO "RIO: master port %d link inactive\n",
918 mport->id);
919 rc = -EINVAL;
920 }
921
922 out:
923 return rc;
924}
925
926
927
928
929
930
931
932static void rio_build_route_tables(void)
933{
934 struct rio_dev *rdev;
935 int i;
936 u8 sport;
937
938 list_for_each_entry(rdev, &rio_devices, global_list)
939 if (rio_is_switch(rdev))
940 for (i = 0;
941 i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size);
942 i++) {
943 if (rio_route_get_entry
944 (rdev->net->hport, rdev->rswitch, RIO_GLOBAL_TABLE,
945 i, &sport) < 0)
946 continue;
947 rdev->rswitch->route_table[i] = sport;
948 }
949}
950
951
952
953
954
955
956
957
958
959static void rio_enum_timeout(unsigned long data)
960{
961
962 *(int *)data = 1;
963}
964
965
966
967
968
969
970
971
972
973
974
975int rio_disc_mport(struct rio_mport *mport)
976{
977 struct rio_net *net = NULL;
978 int enum_timeout_flag = 0;
979
980 printk(KERN_INFO "RIO: discover master port %d, %s\n", mport->id,
981 mport->name);
982
983
984 if (rio_mport_is_active(mport)) {
985 if (!(net = rio_alloc_net(mport))) {
986 printk(KERN_ERR "RIO: Failed to allocate new net\n");
987 goto bail;
988 }
989
990 pr_debug("RIO: wait for enumeration complete...");
991
992 rio_enum_timer.expires =
993 jiffies + CONFIG_RAPIDIO_DISC_TIMEOUT * HZ;
994 rio_enum_timer.data = (unsigned long)&enum_timeout_flag;
995 add_timer(&rio_enum_timer);
996 while (!rio_enum_complete(mport)) {
997 mdelay(1);
998 if (enum_timeout_flag) {
999 del_timer_sync(&rio_enum_timer);
1000 goto timeout;
1001 }
1002 }
1003 del_timer_sync(&rio_enum_timer);
1004
1005 pr_debug("done\n");
1006 if (rio_disc_peer(net, mport, RIO_ANY_DESTID(mport->sys_size),
1007 0) < 0) {
1008 printk(KERN_INFO
1009 "RIO: master port %d device has failed discovery\n",
1010 mport->id);
1011 goto bail;
1012 }
1013
1014 rio_build_route_tables();
1015 }
1016
1017 return 0;
1018
1019 timeout:
1020 pr_debug("timeout\n");
1021 bail:
1022 return -EBUSY;
1023}
1024