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 int __devinit rio_add_device(struct rio_dev *rdev)
267{
268 int err;
269
270 err = device_add(&rdev->dev);
271 if (err)
272 return err;
273
274 spin_lock(&rio_global_list_lock);
275 list_add_tail(&rdev->global_list, &rio_devices);
276 spin_unlock(&rio_global_list_lock);
277
278 rio_create_sysfs_dev_files(rdev);
279
280 return 0;
281}
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
300 struct rio_mport *port, u16 destid,
301 u8 hopcount, int do_enum)
302{
303 int ret = 0;
304 struct rio_dev *rdev;
305 struct rio_switch *rswitch = NULL;
306 int result, rdid;
307
308 rdev = kzalloc(sizeof(struct rio_dev), GFP_KERNEL);
309 if (!rdev)
310 return NULL;
311
312 rdev->net = net;
313 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_ID_CAR,
314 &result);
315 rdev->did = result >> 16;
316 rdev->vid = result & 0xffff;
317 rio_mport_read_config_32(port, destid, hopcount, RIO_DEV_INFO_CAR,
318 &rdev->device_rev);
319 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_ID_CAR,
320 &result);
321 rdev->asm_did = result >> 16;
322 rdev->asm_vid = result & 0xffff;
323 rio_mport_read_config_32(port, destid, hopcount, RIO_ASM_INFO_CAR,
324 &result);
325 rdev->asm_rev = result >> 16;
326 rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR,
327 &rdev->pef);
328 if (rdev->pef & RIO_PEF_EXT_FEATURES)
329 rdev->efptr = result & 0xffff;
330
331 rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR,
332 &rdev->src_ops);
333 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR,
334 &rdev->dst_ops);
335
336 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) {
337 if (do_enum) {
338 rio_set_device_id(port, destid, hopcount, next_destid);
339 rdev->destid = next_destid++;
340 if (next_destid == port->host_deviceid)
341 next_destid++;
342 } else
343 rdev->destid = rio_get_device_id(port, destid, hopcount);
344 } else
345
346 rdev->destid = RIO_INVALID_DESTID;
347
348
349 if (rio_is_switch(rdev)) {
350 rio_mport_read_config_32(port, destid, hopcount,
351 RIO_SWP_INFO_CAR, &rdev->swpinfo);
352 rswitch = kmalloc(sizeof(struct rio_switch), GFP_KERNEL);
353 if (!rswitch)
354 goto cleanup;
355 rswitch->switchid = next_switchid;
356 rswitch->hopcount = hopcount;
357 rswitch->destid = destid;
358 rswitch->route_table = kzalloc(sizeof(u8)*
359 RIO_MAX_ROUTE_ENTRIES(port->sys_size),
360 GFP_KERNEL);
361 if (!rswitch->route_table)
362 goto cleanup;
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 dev_set_name(&rdev->dev, "%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 dev_set_name(&rdev->dev, "%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_BIT_MASK(32);
385 rdev->dev.dma_mask = &rdev->dma_mask;
386 rdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
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 ret = rio_add_device(rdev);
394 if (ret)
395 goto cleanup;
396
397 return rdev;
398
399cleanup:
400 if (rswitch) {
401 kfree(rswitch->route_table);
402 kfree(rswitch);
403 }
404 kfree(rdev);
405 return NULL;
406}
407
408
409
410
411
412
413
414
415
416
417
418
419
420static int
421rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport)
422{
423 u32 result;
424 u32 ext_ftr_ptr;
425
426 int *entry = rio_sport_phys_table;
427
428 do {
429 if ((ext_ftr_ptr =
430 rio_mport_get_feature(port, 0, destid, hopcount, *entry)))
431
432 break;
433 } while (*++entry >= 0);
434
435 if (ext_ftr_ptr)
436 rio_mport_read_config_32(port, destid, hopcount,
437 ext_ftr_ptr +
438 RIO_PORT_N_ERR_STS_CSR(sport),
439 &result);
440
441 return (result & PORT_N_ERR_STS_PORT_OK);
442}
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459static int rio_route_add_entry(struct rio_mport *mport, struct rio_switch *rswitch,
460 u16 table, u16 route_destid, u8 route_port)
461{
462 return rswitch->add_entry(mport, rswitch->destid,
463 rswitch->hopcount, table,
464 route_destid, route_port);
465}
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482static int
483rio_route_get_entry(struct rio_mport *mport, struct rio_switch *rswitch, u16 table,
484 u16 route_destid, u8 * route_port)
485{
486 return rswitch->get_entry(mport, rswitch->destid,
487 rswitch->hopcount, table,
488 route_destid, route_port);
489}
490
491
492
493
494
495
496
497
498
499static u16 rio_get_host_deviceid_lock(struct rio_mport *port, u8 hopcount)
500{
501 u32 result;
502
503 rio_mport_read_config_32(port, RIO_ANY_DESTID(port->sys_size), hopcount,
504 RIO_HOST_DID_LOCK_CSR, &result);
505
506 return (u16) (result & 0xffff);
507}
508
509
510
511
512
513
514
515
516
517static u8
518rio_get_swpinfo_inport(struct rio_mport *mport, u16 destid, u8 hopcount)
519{
520 u32 result;
521
522 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
523 &result);
524
525 return (u8) (result & 0xff);
526}
527
528
529
530
531
532
533
534
535
536static u8 rio_get_swpinfo_tports(struct rio_mport *mport, u16 destid,
537 u8 hopcount)
538{
539 u32 result;
540
541 rio_mport_read_config_32(mport, destid, hopcount, RIO_SWP_INFO_CAR,
542 &result);
543
544 return RIO_GET_TOTAL_PORTS(result);
545}
546
547
548
549
550
551
552
553
554
555static void rio_net_add_mport(struct rio_net *net, struct rio_mport *port)
556{
557 spin_lock(&rio_global_list_lock);
558 list_add_tail(&port->nnode, &net->mports);
559 spin_unlock(&rio_global_list_lock);
560}
561
562
563
564
565
566
567
568
569
570
571static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
572 u8 hopcount)
573{
574 int port_num;
575 int num_ports;
576 int cur_destid;
577 int sw_destid;
578 int sw_inport;
579 struct rio_dev *rdev;
580 u16 destid;
581 int tmp;
582
583 if (rio_get_host_deviceid_lock(port, hopcount) == port->host_deviceid) {
584 pr_debug("RIO: PE already discovered by this host\n");
585
586
587
588
589 rio_net_add_mport(net, port);
590 return 0;
591 }
592
593
594 rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size),
595 hopcount,
596 RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
597 while ((tmp = rio_get_host_deviceid_lock(port, hopcount))
598 < port->host_deviceid) {
599
600 mdelay(1);
601
602 rio_mport_write_config_32(port, RIO_ANY_DESTID(port->sys_size),
603 hopcount,
604 RIO_HOST_DID_LOCK_CSR,
605 port->host_deviceid);
606 }
607
608 if (rio_get_host_deviceid_lock(port, hopcount) > port->host_deviceid) {
609 pr_debug(
610 "RIO: PE locked by a higher priority host...retreating\n");
611 return -1;
612 }
613
614
615 rdev = rio_setup_device(net, port, RIO_ANY_DESTID(port->sys_size),
616 hopcount, 1);
617 if (rdev) {
618
619 list_add_tail(&rdev->net_list, &net->devices);
620 } else
621 return -1;
622
623 if (rio_is_switch(rdev)) {
624 next_switchid++;
625 sw_inport = rio_get_swpinfo_inport(port,
626 RIO_ANY_DESTID(port->sys_size), hopcount);
627 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE,
628 port->host_deviceid, sw_inport);
629 rdev->rswitch->route_table[port->host_deviceid] = sw_inport;
630
631 for (destid = 0; destid < next_destid; destid++) {
632 if (destid == port->host_deviceid)
633 continue;
634 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE,
635 destid, sw_inport);
636 rdev->rswitch->route_table[destid] = sw_inport;
637 }
638
639 num_ports =
640 rio_get_swpinfo_tports(port, RIO_ANY_DESTID(port->sys_size),
641 hopcount);
642 pr_debug(
643 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
644 rio_name(rdev), rdev->vid, rdev->did, num_ports);
645 sw_destid = next_destid;
646 for (port_num = 0; port_num < num_ports; port_num++) {
647 if (sw_inport == port_num)
648 continue;
649
650 cur_destid = next_destid;
651
652 if (rio_sport_is_active
653 (port, RIO_ANY_DESTID(port->sys_size), hopcount,
654 port_num)) {
655 pr_debug(
656 "RIO: scanning device on port %d\n",
657 port_num);
658 rio_route_add_entry(port, rdev->rswitch,
659 RIO_GLOBAL_TABLE,
660 RIO_ANY_DESTID(port->sys_size),
661 port_num);
662
663 if (rio_enum_peer(net, port, hopcount + 1) < 0)
664 return -1;
665
666
667 if (next_destid > cur_destid) {
668 for (destid = cur_destid;
669 destid < next_destid; destid++) {
670 if (destid == port->host_deviceid)
671 continue;
672 rio_route_add_entry(port, rdev->rswitch,
673 RIO_GLOBAL_TABLE,
674 destid,
675 port_num);
676 rdev->rswitch->
677 route_table[destid] =
678 port_num;
679 }
680 }
681 }
682 }
683
684
685 if (next_destid == sw_destid) {
686 next_destid++;
687 if (next_destid == port->host_deviceid)
688 next_destid++;
689 }
690
691 rdev->rswitch->destid = sw_destid;
692 } else
693 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
694 rio_name(rdev), rdev->vid, rdev->did);
695
696 return 0;
697}
698
699
700
701
702
703
704
705
706
707static int rio_enum_complete(struct rio_mport *port)
708{
709 u32 tag_csr;
710 int ret = 0;
711
712 rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr);
713
714 if (tag_csr == RIO_ENUM_CMPL_MAGIC)
715 ret = 1;
716
717 return ret;
718}
719
720
721
722
723
724
725
726
727
728
729
730static int __devinit
731rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
732 u8 hopcount)
733{
734 u8 port_num, route_port;
735 int num_ports;
736 struct rio_dev *rdev;
737 u16 ndestid;
738
739
740 if ((rdev = rio_setup_device(net, port, destid, hopcount, 0))) {
741
742 list_add_tail(&rdev->net_list, &net->devices);
743 } else
744 return -1;
745
746 if (rio_is_switch(rdev)) {
747 next_switchid++;
748
749
750 rdev->rswitch->destid = destid;
751
752 num_ports = rio_get_swpinfo_tports(port, destid, hopcount);
753 pr_debug(
754 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
755 rio_name(rdev), rdev->vid, rdev->did, num_ports);
756 for (port_num = 0; port_num < num_ports; port_num++) {
757 if (rio_get_swpinfo_inport(port, destid, hopcount) ==
758 port_num)
759 continue;
760
761 if (rio_sport_is_active
762 (port, destid, hopcount, port_num)) {
763 pr_debug(
764 "RIO: scanning device on port %d\n",
765 port_num);
766 for (ndestid = 0;
767 ndestid < RIO_ANY_DESTID(port->sys_size);
768 ndestid++) {
769 rio_route_get_entry(port, rdev->rswitch,
770 RIO_GLOBAL_TABLE,
771 ndestid,
772 &route_port);
773 if (route_port == port_num)
774 break;
775 }
776
777 if (rio_disc_peer
778 (net, port, ndestid, hopcount + 1) < 0)
779 return -1;
780 }
781 }
782 } else
783 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
784 rio_name(rdev), rdev->vid, rdev->did);
785
786 return 0;
787}
788
789
790
791
792
793
794
795
796
797
798static int rio_mport_is_active(struct rio_mport *port)
799{
800 u32 result = 0;
801 u32 ext_ftr_ptr;
802 int *entry = rio_mport_phys_table;
803
804 do {
805 if ((ext_ftr_ptr =
806 rio_mport_get_feature(port, 1, 0, 0, *entry)))
807 break;
808 } while (*++entry >= 0);
809
810 if (ext_ftr_ptr)
811 rio_local_read_config_32(port,
812 ext_ftr_ptr +
813 RIO_PORT_N_ERR_STS_CSR(port->index),
814 &result);
815
816 return (result & PORT_N_ERR_STS_PORT_OK);
817}
818
819
820
821
822
823
824
825
826
827
828static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port)
829{
830 struct rio_net *net;
831
832 net = kzalloc(sizeof(struct rio_net), GFP_KERNEL);
833 if (net) {
834 INIT_LIST_HEAD(&net->node);
835 INIT_LIST_HEAD(&net->devices);
836 INIT_LIST_HEAD(&net->mports);
837 list_add_tail(&port->nnode, &net->mports);
838 net->hport = port;
839 net->id = next_net++;
840 }
841 return net;
842}
843
844
845
846
847
848
849
850
851
852static void rio_update_route_tables(struct rio_mport *port)
853{
854 struct rio_dev *rdev;
855 struct rio_switch *rswitch;
856 u8 sport;
857 u16 destid;
858
859 list_for_each_entry(rdev, &rio_devices, global_list) {
860
861 destid = (rio_is_switch(rdev))?rdev->rswitch->destid:rdev->destid;
862
863 list_for_each_entry(rswitch, &rio_switches, node) {
864
865 if (rio_is_switch(rdev) && (rdev->rswitch == rswitch))
866 continue;
867
868 if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) {
869
870 sport = rio_get_swpinfo_inport(port,
871 rswitch->destid, rswitch->hopcount);
872
873 if (rswitch->add_entry) {
874 rio_route_add_entry(port, rswitch, RIO_GLOBAL_TABLE, destid, sport);
875 rswitch->route_table[destid] = sport;
876 }
877 }
878 }
879 }
880}
881
882
883
884
885
886
887
888
889
890
891int __devinit rio_enum_mport(struct rio_mport *mport)
892{
893 struct rio_net *net = NULL;
894 int rc = 0;
895
896 printk(KERN_INFO "RIO: enumerate master port %d, %s\n", mport->id,
897 mport->name);
898
899 if (rio_enum_host(mport) < 0) {
900 printk(KERN_INFO
901 "RIO: master port %d device has been enumerated by a remote host\n",
902 mport->id);
903 rc = -EBUSY;
904 goto out;
905 }
906
907
908 if (rio_mport_is_active(mport)) {
909 if (!(net = rio_alloc_net(mport))) {
910 printk(KERN_ERR "RIO: failed to allocate new net\n");
911 rc = -ENOMEM;
912 goto out;
913 }
914 if (rio_enum_peer(net, mport, 0) < 0) {
915
916 printk(KERN_INFO
917 "RIO: master port %d device has lost enumeration to a remote host\n",
918 mport->id);
919 rio_clear_locks(mport);
920 rc = -EBUSY;
921 goto out;
922 }
923 rio_update_route_tables(mport);
924 rio_clear_locks(mport);
925 } else {
926 printk(KERN_INFO "RIO: master port %d link inactive\n",
927 mport->id);
928 rc = -EINVAL;
929 }
930
931 out:
932 return rc;
933}
934
935
936
937
938
939
940
941static void rio_build_route_tables(void)
942{
943 struct rio_dev *rdev;
944 int i;
945 u8 sport;
946
947 list_for_each_entry(rdev, &rio_devices, global_list)
948 if (rio_is_switch(rdev))
949 for (i = 0;
950 i < RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size);
951 i++) {
952 if (rio_route_get_entry
953 (rdev->net->hport, rdev->rswitch, RIO_GLOBAL_TABLE,
954 i, &sport) < 0)
955 continue;
956 rdev->rswitch->route_table[i] = sport;
957 }
958}
959
960
961
962
963
964
965
966
967
968static void rio_enum_timeout(unsigned long data)
969{
970
971 *(int *)data = 1;
972}
973
974
975
976
977
978
979
980
981
982
983
984int __devinit rio_disc_mport(struct rio_mport *mport)
985{
986 struct rio_net *net = NULL;
987 int enum_timeout_flag = 0;
988
989 printk(KERN_INFO "RIO: discover master port %d, %s\n", mport->id,
990 mport->name);
991
992
993 if (rio_mport_is_active(mport)) {
994 if (!(net = rio_alloc_net(mport))) {
995 printk(KERN_ERR "RIO: Failed to allocate new net\n");
996 goto bail;
997 }
998
999 pr_debug("RIO: wait for enumeration complete...");
1000
1001 rio_enum_timer.expires =
1002 jiffies + CONFIG_RAPIDIO_DISC_TIMEOUT * HZ;
1003 rio_enum_timer.data = (unsigned long)&enum_timeout_flag;
1004 add_timer(&rio_enum_timer);
1005 while (!rio_enum_complete(mport)) {
1006 mdelay(1);
1007 if (enum_timeout_flag) {
1008 del_timer_sync(&rio_enum_timer);
1009 goto timeout;
1010 }
1011 }
1012 del_timer_sync(&rio_enum_timer);
1013
1014 pr_debug("done\n");
1015 if (rio_disc_peer(net, mport, RIO_ANY_DESTID(mport->sys_size),
1016 0) < 0) {
1017 printk(KERN_INFO
1018 "RIO: master port %d device has failed discovery\n",
1019 mport->id);
1020 goto bail;
1021 }
1022
1023 rio_build_route_tables();
1024 }
1025
1026 return 0;
1027
1028 timeout:
1029 pr_debug("timeout\n");
1030 bail:
1031 return -EBUSY;
1032}
1033