1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/types.h>
19#include <linux/kernel.h>
20
21#include <linux/delay.h>
22#include <linux/init.h>
23#include <linux/rio.h>
24#include <linux/rio_drv.h>
25#include <linux/rio_ids.h>
26#include <linux/rio_regs.h>
27#include <linux/module.h>
28#include <linux/spinlock.h>
29#include <linux/slab.h>
30#include <linux/interrupt.h>
31
32#include "rio.h"
33
34static LIST_HEAD(rio_mports);
35
36
37
38
39
40
41
42
43
44u16 rio_local_get_device_id(struct rio_mport *port)
45{
46 u32 result;
47
48 rio_local_read_config_32(port, RIO_DID_CSR, &result);
49
50 return (RIO_GET_DID(port->sys_size, result));
51}
52
53
54
55
56
57
58
59
60
61
62
63
64int rio_request_inb_mbox(struct rio_mport *mport,
65 void *dev_id,
66 int mbox,
67 int entries,
68 void (*minb) (struct rio_mport * mport, void *dev_id, int mbox,
69 int slot))
70{
71 int rc = 0;
72
73 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
74
75 if (res) {
76 rio_init_mbox_res(res, mbox, mbox);
77
78
79 if ((rc =
80 request_resource(&mport->riores[RIO_INB_MBOX_RESOURCE],
81 res)) < 0) {
82 kfree(res);
83 goto out;
84 }
85
86 mport->inb_msg[mbox].res = res;
87
88
89 mport->inb_msg[mbox].mcback = minb;
90
91 rc = rio_open_inb_mbox(mport, dev_id, mbox, entries);
92 } else
93 rc = -ENOMEM;
94
95 out:
96 return rc;
97}
98
99
100
101
102
103
104
105
106
107int rio_release_inb_mbox(struct rio_mport *mport, int mbox)
108{
109 rio_close_inb_mbox(mport, mbox);
110
111
112 return release_resource(mport->inb_msg[mbox].res);
113}
114
115
116
117
118
119
120
121
122
123
124
125
126int rio_request_outb_mbox(struct rio_mport *mport,
127 void *dev_id,
128 int mbox,
129 int entries,
130 void (*moutb) (struct rio_mport * mport, void *dev_id, int mbox, int slot))
131{
132 int rc = 0;
133
134 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
135
136 if (res) {
137 rio_init_mbox_res(res, mbox, mbox);
138
139
140 if ((rc =
141 request_resource(&mport->riores[RIO_OUTB_MBOX_RESOURCE],
142 res)) < 0) {
143 kfree(res);
144 goto out;
145 }
146
147 mport->outb_msg[mbox].res = res;
148
149
150 mport->outb_msg[mbox].mcback = moutb;
151
152 rc = rio_open_outb_mbox(mport, dev_id, mbox, entries);
153 } else
154 rc = -ENOMEM;
155
156 out:
157 return rc;
158}
159
160
161
162
163
164
165
166
167
168int rio_release_outb_mbox(struct rio_mport *mport, int mbox)
169{
170 rio_close_outb_mbox(mport, mbox);
171
172
173 return release_resource(mport->outb_msg[mbox].res);
174}
175
176
177
178
179
180
181
182
183
184
185
186
187static int
188rio_setup_inb_dbell(struct rio_mport *mport, void *dev_id, struct resource *res,
189 void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src, u16 dst,
190 u16 info))
191{
192 int rc = 0;
193 struct rio_dbell *dbell;
194
195 if (!(dbell = kmalloc(sizeof(struct rio_dbell), GFP_KERNEL))) {
196 rc = -ENOMEM;
197 goto out;
198 }
199
200 dbell->res = res;
201 dbell->dinb = dinb;
202 dbell->dev_id = dev_id;
203
204 list_add_tail(&dbell->node, &mport->dbells);
205
206 out:
207 return rc;
208}
209
210
211
212
213
214
215
216
217
218
219
220
221
222int rio_request_inb_dbell(struct rio_mport *mport,
223 void *dev_id,
224 u16 start,
225 u16 end,
226 void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src,
227 u16 dst, u16 info))
228{
229 int rc = 0;
230
231 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
232
233 if (res) {
234 rio_init_dbell_res(res, start, end);
235
236
237 if ((rc =
238 request_resource(&mport->riores[RIO_DOORBELL_RESOURCE],
239 res)) < 0) {
240 kfree(res);
241 goto out;
242 }
243
244
245 rc = rio_setup_inb_dbell(mport, dev_id, res, dinb);
246 } else
247 rc = -ENOMEM;
248
249 out:
250 return rc;
251}
252
253
254
255
256
257
258
259
260
261
262
263int rio_release_inb_dbell(struct rio_mport *mport, u16 start, u16 end)
264{
265 int rc = 0, found = 0;
266 struct rio_dbell *dbell;
267
268 list_for_each_entry(dbell, &mport->dbells, node) {
269 if ((dbell->res->start == start) && (dbell->res->end == end)) {
270 found = 1;
271 break;
272 }
273 }
274
275
276 if (!found) {
277 rc = -EINVAL;
278 goto out;
279 }
280
281
282 list_del(&dbell->node);
283
284
285 rc = release_resource(dbell->res);
286
287
288 kfree(dbell);
289
290 out:
291 return rc;
292}
293
294
295
296
297
298
299
300
301
302
303struct resource *rio_request_outb_dbell(struct rio_dev *rdev, u16 start,
304 u16 end)
305{
306 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
307
308 if (res) {
309 rio_init_dbell_res(res, start, end);
310
311
312 if (request_resource(&rdev->riores[RIO_DOORBELL_RESOURCE], res)
313 < 0) {
314 kfree(res);
315 res = NULL;
316 }
317 }
318
319 return res;
320}
321
322
323
324
325
326
327
328
329
330int rio_release_outb_dbell(struct rio_dev *rdev, struct resource *res)
331{
332 int rc = release_resource(res);
333
334 kfree(res);
335
336 return rc;
337}
338
339
340
341
342
343
344
345
346
347int rio_request_inb_pwrite(struct rio_dev *rdev,
348 int (*pwcback)(struct rio_dev *rdev, union rio_pw_msg *msg, int step))
349{
350 int rc = 0;
351
352 spin_lock(&rio_global_list_lock);
353 if (rdev->pwcback != NULL)
354 rc = -ENOMEM;
355 else
356 rdev->pwcback = pwcback;
357
358 spin_unlock(&rio_global_list_lock);
359 return rc;
360}
361EXPORT_SYMBOL_GPL(rio_request_inb_pwrite);
362
363
364
365
366
367
368
369
370int rio_release_inb_pwrite(struct rio_dev *rdev)
371{
372 int rc = -ENOMEM;
373
374 spin_lock(&rio_global_list_lock);
375 if (rdev->pwcback) {
376 rdev->pwcback = NULL;
377 rc = 0;
378 }
379
380 spin_unlock(&rio_global_list_lock);
381 return rc;
382}
383EXPORT_SYMBOL_GPL(rio_release_inb_pwrite);
384
385
386
387
388
389
390
391
392
393u32
394rio_mport_get_physefb(struct rio_mport *port, int local,
395 u16 destid, u8 hopcount)
396{
397 u32 ext_ftr_ptr;
398 u32 ftr_header;
399
400 ext_ftr_ptr = rio_mport_get_efb(port, local, destid, hopcount, 0);
401
402 while (ext_ftr_ptr) {
403 if (local)
404 rio_local_read_config_32(port, ext_ftr_ptr,
405 &ftr_header);
406 else
407 rio_mport_read_config_32(port, destid, hopcount,
408 ext_ftr_ptr, &ftr_header);
409
410 ftr_header = RIO_GET_BLOCK_ID(ftr_header);
411 switch (ftr_header) {
412
413 case RIO_EFB_SER_EP_ID_V13P:
414 case RIO_EFB_SER_EP_REC_ID_V13P:
415 case RIO_EFB_SER_EP_FREE_ID_V13P:
416 case RIO_EFB_SER_EP_ID:
417 case RIO_EFB_SER_EP_REC_ID:
418 case RIO_EFB_SER_EP_FREE_ID:
419 case RIO_EFB_SER_EP_FREC_ID:
420
421 return ext_ftr_ptr;
422
423 default:
424 break;
425 }
426
427 ext_ftr_ptr = rio_mport_get_efb(port, local, destid,
428 hopcount, ext_ftr_ptr);
429 }
430
431 return ext_ftr_ptr;
432}
433
434
435
436
437
438
439
440
441
442
443
444
445
446struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from)
447{
448 struct list_head *n;
449 struct rio_dev *rdev;
450
451 spin_lock(&rio_global_list_lock);
452 n = from ? from->global_list.next : rio_devices.next;
453
454 while (n && (n != &rio_devices)) {
455 rdev = rio_dev_g(n);
456 if (rdev->comp_tag == comp_tag)
457 goto exit;
458 n = n->next;
459 }
460 rdev = NULL;
461exit:
462 spin_unlock(&rio_global_list_lock);
463 return rdev;
464}
465
466
467
468
469
470
471
472int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
473{
474 u32 regval;
475
476 rio_read_config_32(rdev,
477 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
478 ®val);
479 if (lock)
480 regval |= RIO_PORT_N_CTL_LOCKOUT;
481 else
482 regval &= ~RIO_PORT_N_CTL_LOCKOUT;
483
484 rio_write_config_32(rdev,
485 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
486 regval);
487 return 0;
488}
489
490
491
492
493
494
495
496
497
498
499static int
500rio_chk_dev_route(struct rio_dev *rdev, struct rio_dev **nrdev, int *npnum)
501{
502 u32 result;
503 int p_port, rc = -EIO;
504 struct rio_dev *prev = NULL;
505
506
507 while (rdev->prev && (rdev->prev->pef & RIO_PEF_SWITCH)) {
508 if (!rio_read_config_32(rdev->prev, RIO_DEV_ID_CAR, &result)) {
509 prev = rdev->prev;
510 break;
511 }
512 rdev = rdev->prev;
513 }
514
515 if (prev == NULL)
516 goto err_out;
517
518 p_port = prev->rswitch->route_table[rdev->destid];
519
520 if (p_port != RIO_INVALID_ROUTE) {
521 pr_debug("RIO: link failed on [%s]-P%d\n",
522 rio_name(prev), p_port);
523 *nrdev = prev;
524 *npnum = p_port;
525 rc = 0;
526 } else
527 pr_debug("RIO: failed to trace route to %s\n", rio_name(rdev));
528err_out:
529 return rc;
530}
531
532
533
534
535
536
537
538int
539rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid, u8 hopcount)
540{
541 int i = 0;
542 u32 tmp;
543
544 while (rio_mport_read_config_32(mport, destid, hopcount,
545 RIO_DEV_ID_CAR, &tmp)) {
546 i++;
547 if (i == RIO_MAX_CHK_RETRY)
548 return -EIO;
549 mdelay(1);
550 }
551
552 return 0;
553}
554
555
556
557
558
559static int rio_chk_dev_access(struct rio_dev *rdev)
560{
561 return rio_mport_chk_dev_access(rdev->net->hport,
562 rdev->destid, rdev->hopcount);
563}
564
565
566
567
568
569
570
571
572static int
573rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp)
574{
575 u32 regval;
576 int checkcount;
577
578 if (lnkresp) {
579
580
581 rio_read_config_32(rdev,
582 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
583 ®val);
584 udelay(50);
585 }
586
587
588 rio_write_config_32(rdev,
589 rdev->phys_efptr + RIO_PORT_N_MNT_REQ_CSR(pnum),
590 RIO_MNT_REQ_CMD_IS);
591
592
593 if (lnkresp == NULL)
594 return 0;
595
596 checkcount = 3;
597 while (checkcount--) {
598 udelay(50);
599 rio_read_config_32(rdev,
600 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
601 ®val);
602 if (regval & RIO_PORT_N_MNT_RSP_RVAL) {
603 *lnkresp = regval;
604 return 0;
605 }
606 }
607
608 return -EIO;
609}
610
611
612
613
614
615
616
617static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)
618{
619 struct rio_dev *nextdev = rdev->rswitch->nextdev[pnum];
620 u32 regval;
621 u32 far_ackid, far_linkstat, near_ackid;
622
623 if (err_status == 0)
624 rio_read_config_32(rdev,
625 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
626 &err_status);
627
628 if (err_status & RIO_PORT_N_ERR_STS_PW_OUT_ES) {
629 pr_debug("RIO_EM: servicing Output Error-Stopped state\n");
630
631
632
633 if (rio_get_input_status(rdev, pnum, ®val)) {
634 pr_debug("RIO_EM: Input-status response timeout\n");
635 goto rd_err;
636 }
637
638 pr_debug("RIO_EM: SP%d Input-status response=0x%08x\n",
639 pnum, regval);
640 far_ackid = (regval & RIO_PORT_N_MNT_RSP_ASTAT) >> 5;
641 far_linkstat = regval & RIO_PORT_N_MNT_RSP_LSTAT;
642 rio_read_config_32(rdev,
643 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
644 ®val);
645 pr_debug("RIO_EM: SP%d_ACK_STS_CSR=0x%08x\n", pnum, regval);
646 near_ackid = (regval & RIO_PORT_N_ACK_INBOUND) >> 24;
647 pr_debug("RIO_EM: SP%d far_ackID=0x%02x far_linkstat=0x%02x" \
648 " near_ackID=0x%02x\n",
649 pnum, far_ackid, far_linkstat, near_ackid);
650
651
652
653
654
655 if ((far_ackid != ((regval & RIO_PORT_N_ACK_OUTSTAND) >> 8)) ||
656 (far_ackid != (regval & RIO_PORT_N_ACK_OUTBOUND))) {
657
658
659
660 rio_write_config_32(rdev,
661 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
662 (near_ackid << 24) |
663 (far_ackid << 8) | far_ackid);
664
665
666
667 far_ackid++;
668 if (nextdev)
669 rio_write_config_32(nextdev,
670 nextdev->phys_efptr +
671 RIO_PORT_N_ACK_STS_CSR(RIO_GET_PORT_NUM(nextdev->swpinfo)),
672 (far_ackid << 24) |
673 (near_ackid << 8) | near_ackid);
674 else
675 pr_debug("RIO_EM: Invalid nextdev pointer (NULL)\n");
676 }
677rd_err:
678 rio_read_config_32(rdev,
679 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
680 &err_status);
681 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
682 }
683
684 if ((err_status & RIO_PORT_N_ERR_STS_PW_INP_ES) && nextdev) {
685 pr_debug("RIO_EM: servicing Input Error-Stopped state\n");
686 rio_get_input_status(nextdev,
687 RIO_GET_PORT_NUM(nextdev->swpinfo), NULL);
688 udelay(50);
689
690 rio_read_config_32(rdev,
691 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
692 &err_status);
693 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
694 }
695
696 return (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
697 RIO_PORT_N_ERR_STS_PW_INP_ES)) ? 1 : 0;
698}
699
700
701
702
703
704
705
706
707int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
708{
709 struct rio_dev *rdev;
710 u32 err_status, em_perrdet, em_ltlerrdet;
711 int rc, portnum;
712
713 rdev = rio_get_comptag((pw_msg->em.comptag & RIO_CTAG_UDEVID), NULL);
714 if (rdev == NULL) {
715
716 pr_debug("RIO: %s No matching device for CTag 0x%08x\n",
717 __func__, pw_msg->em.comptag);
718 return -EIO;
719 }
720
721 pr_debug("RIO: Port-Write message from %s\n", rio_name(rdev));
722
723#ifdef DEBUG_PW
724 {
725 u32 i;
726 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32);) {
727 pr_debug("0x%02x: %08x %08x %08x %08x\n",
728 i*4, pw_msg->raw[i], pw_msg->raw[i + 1],
729 pw_msg->raw[i + 2], pw_msg->raw[i + 3]);
730 i += 4;
731 }
732 }
733#endif
734
735
736
737
738
739
740
741 if (rdev->pwcback != NULL) {
742 rc = rdev->pwcback(rdev, pw_msg, 0);
743 if (rc == 0)
744 return 0;
745 }
746
747 portnum = pw_msg->em.is_port & 0xFF;
748
749
750
751
752
753 if (rio_chk_dev_access(rdev)) {
754 pr_debug("RIO: device access failed - get link partner\n");
755
756
757
758
759 if (rio_chk_dev_route(rdev, &rdev, &portnum)) {
760 pr_err("RIO: Route trace for %s failed\n",
761 rio_name(rdev));
762 return -EIO;
763 }
764 pw_msg = NULL;
765 }
766
767
768 if (!(rdev->pef & RIO_PEF_SWITCH))
769 return 0;
770
771 if (rdev->phys_efptr == 0) {
772 pr_err("RIO_PW: Bad switch initialization for %s\n",
773 rio_name(rdev));
774 return 0;
775 }
776
777
778
779
780 if (rdev->rswitch->em_handle)
781 rdev->rswitch->em_handle(rdev, portnum);
782
783 rio_read_config_32(rdev,
784 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
785 &err_status);
786 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status);
787
788 if (err_status & RIO_PORT_N_ERR_STS_PORT_OK) {
789
790 if (!(rdev->rswitch->port_ok & (1 << portnum))) {
791 rdev->rswitch->port_ok |= (1 << portnum);
792 rio_set_port_lockout(rdev, portnum, 0);
793
794 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n",
795 rio_name(rdev), portnum);
796 }
797
798
799
800
801
802 if (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
803 RIO_PORT_N_ERR_STS_PW_INP_ES)) {
804 if (rio_clr_err_stopped(rdev, portnum, err_status))
805 rio_clr_err_stopped(rdev, portnum, 0);
806 }
807 } else {
808
809 if (rdev->rswitch->port_ok & (1 << portnum)) {
810 rdev->rswitch->port_ok &= ~(1 << portnum);
811 rio_set_port_lockout(rdev, portnum, 1);
812
813 rio_write_config_32(rdev,
814 rdev->phys_efptr +
815 RIO_PORT_N_ACK_STS_CSR(portnum),
816 RIO_PORT_N_ACK_CLEAR);
817
818
819 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n",
820 rio_name(rdev), portnum);
821 }
822 }
823
824 rio_read_config_32(rdev,
825 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
826 if (em_perrdet) {
827 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
828 portnum, em_perrdet);
829
830 rio_write_config_32(rdev,
831 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0);
832 }
833
834 rio_read_config_32(rdev,
835 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
836 if (em_ltlerrdet) {
837 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
838 em_ltlerrdet);
839
840 rio_write_config_32(rdev,
841 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0);
842 }
843
844
845 rio_write_config_32(rdev,
846 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
847 err_status);
848
849 return 0;
850}
851EXPORT_SYMBOL_GPL(rio_inb_pwrite_handler);
852
853
854
855
856
857
858
859
860
861
862u32
863rio_mport_get_efb(struct rio_mport *port, int local, u16 destid,
864 u8 hopcount, u32 from)
865{
866 u32 reg_val;
867
868 if (from == 0) {
869 if (local)
870 rio_local_read_config_32(port, RIO_ASM_INFO_CAR,
871 ®_val);
872 else
873 rio_mport_read_config_32(port, destid, hopcount,
874 RIO_ASM_INFO_CAR, ®_val);
875 return reg_val & RIO_EXT_FTR_PTR_MASK;
876 } else {
877 if (local)
878 rio_local_read_config_32(port, from, ®_val);
879 else
880 rio_mport_read_config_32(port, destid, hopcount,
881 from, ®_val);
882 return RIO_GET_BLOCK_ID(reg_val);
883 }
884}
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912u32
913rio_mport_get_feature(struct rio_mport * port, int local, u16 destid,
914 u8 hopcount, int ftr)
915{
916 u32 asm_info, ext_ftr_ptr, ftr_header;
917
918 if (local)
919 rio_local_read_config_32(port, RIO_ASM_INFO_CAR, &asm_info);
920 else
921 rio_mport_read_config_32(port, destid, hopcount,
922 RIO_ASM_INFO_CAR, &asm_info);
923
924 ext_ftr_ptr = asm_info & RIO_EXT_FTR_PTR_MASK;
925
926 while (ext_ftr_ptr) {
927 if (local)
928 rio_local_read_config_32(port, ext_ftr_ptr,
929 &ftr_header);
930 else
931 rio_mport_read_config_32(port, destid, hopcount,
932 ext_ftr_ptr, &ftr_header);
933 if (RIO_GET_BLOCK_ID(ftr_header) == ftr)
934 return ext_ftr_ptr;
935 if (!(ext_ftr_ptr = RIO_GET_BLOCK_PTR(ftr_header)))
936 break;
937 }
938
939 return 0;
940}
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959struct rio_dev *rio_get_asm(u16 vid, u16 did,
960 u16 asm_vid, u16 asm_did, struct rio_dev *from)
961{
962 struct list_head *n;
963 struct rio_dev *rdev;
964
965 WARN_ON(in_interrupt());
966 spin_lock(&rio_global_list_lock);
967 n = from ? from->global_list.next : rio_devices.next;
968
969 while (n && (n != &rio_devices)) {
970 rdev = rio_dev_g(n);
971 if ((vid == RIO_ANY_ID || rdev->vid == vid) &&
972 (did == RIO_ANY_ID || rdev->did == did) &&
973 (asm_vid == RIO_ANY_ID || rdev->asm_vid == asm_vid) &&
974 (asm_did == RIO_ANY_ID || rdev->asm_did == asm_did))
975 goto exit;
976 n = n->next;
977 }
978 rdev = NULL;
979 exit:
980 rio_dev_put(from);
981 rdev = rio_dev_get(rdev);
982 spin_unlock(&rio_global_list_lock);
983 return rdev;
984}
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from)
1001{
1002 return rio_get_asm(vid, did, RIO_ANY_ID, RIO_ANY_ID, from);
1003}
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015int rio_std_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
1016 u16 table, u16 route_destid, u8 route_port)
1017{
1018 if (table == RIO_GLOBAL_TABLE) {
1019 rio_mport_write_config_32(mport, destid, hopcount,
1020 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
1021 (u32)route_destid);
1022 rio_mport_write_config_32(mport, destid, hopcount,
1023 RIO_STD_RTE_CONF_PORT_SEL_CSR,
1024 (u32)route_port);
1025 }
1026
1027 udelay(10);
1028 return 0;
1029}
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042int rio_std_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
1043 u16 table, u16 route_destid, u8 *route_port)
1044{
1045 u32 result;
1046
1047 if (table == RIO_GLOBAL_TABLE) {
1048 rio_mport_write_config_32(mport, destid, hopcount,
1049 RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
1050 rio_mport_read_config_32(mport, destid, hopcount,
1051 RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
1052
1053 *route_port = (u8)result;
1054 }
1055
1056 return 0;
1057}
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
1068 u16 table)
1069{
1070 u32 max_destid = 0xff;
1071 u32 i, pef, id_inc = 1, ext_cfg = 0;
1072 u32 port_sel = RIO_INVALID_ROUTE;
1073
1074 if (table == RIO_GLOBAL_TABLE) {
1075 rio_mport_read_config_32(mport, destid, hopcount,
1076 RIO_PEF_CAR, &pef);
1077
1078 if (mport->sys_size) {
1079 rio_mport_read_config_32(mport, destid, hopcount,
1080 RIO_SWITCH_RT_LIMIT,
1081 &max_destid);
1082 max_destid &= RIO_RT_MAX_DESTID;
1083 }
1084
1085 if (pef & RIO_PEF_EXT_RT) {
1086 ext_cfg = 0x80000000;
1087 id_inc = 4;
1088 port_sel = (RIO_INVALID_ROUTE << 24) |
1089 (RIO_INVALID_ROUTE << 16) |
1090 (RIO_INVALID_ROUTE << 8) |
1091 RIO_INVALID_ROUTE;
1092 }
1093
1094 for (i = 0; i <= max_destid;) {
1095 rio_mport_write_config_32(mport, destid, hopcount,
1096 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
1097 ext_cfg | i);
1098 rio_mport_write_config_32(mport, destid, hopcount,
1099 RIO_STD_RTE_CONF_PORT_SEL_CSR,
1100 port_sel);
1101 i += id_inc;
1102 }
1103 }
1104
1105 udelay(10);
1106 return 0;
1107}
1108
1109static void rio_fixup_device(struct rio_dev *dev)
1110{
1111}
1112
1113static int __devinit rio_init(void)
1114{
1115 struct rio_dev *dev = NULL;
1116
1117 while ((dev = rio_get_device(RIO_ANY_ID, RIO_ANY_ID, dev)) != NULL) {
1118 rio_fixup_device(dev);
1119 }
1120 return 0;
1121}
1122
1123device_initcall(rio_init);
1124
1125int __devinit rio_init_mports(void)
1126{
1127 int rc = 0;
1128 struct rio_mport *port;
1129
1130 list_for_each_entry(port, &rio_mports, node) {
1131 if (!request_mem_region(port->iores.start,
1132 resource_size(&port->iores),
1133 port->name)) {
1134 printk(KERN_ERR
1135 "RIO: Error requesting master port region 0x%016llx-0x%016llx\n",
1136 (u64)port->iores.start, (u64)port->iores.end);
1137 rc = -ENOMEM;
1138 goto out;
1139 }
1140
1141 if (port->host_deviceid >= 0)
1142 rio_enum_mport(port);
1143 else
1144 rio_disc_mport(port);
1145 }
1146
1147 out:
1148 return rc;
1149}
1150
1151void rio_register_mport(struct rio_mport *port)
1152{
1153 list_add_tail(&port->node, &rio_mports);
1154}
1155
1156EXPORT_SYMBOL_GPL(rio_local_get_device_id);
1157EXPORT_SYMBOL_GPL(rio_get_device);
1158EXPORT_SYMBOL_GPL(rio_get_asm);
1159EXPORT_SYMBOL_GPL(rio_request_inb_dbell);
1160EXPORT_SYMBOL_GPL(rio_release_inb_dbell);
1161EXPORT_SYMBOL_GPL(rio_request_outb_dbell);
1162EXPORT_SYMBOL_GPL(rio_release_outb_dbell);
1163EXPORT_SYMBOL_GPL(rio_request_inb_mbox);
1164EXPORT_SYMBOL_GPL(rio_release_inb_mbox);
1165EXPORT_SYMBOL_GPL(rio_request_outb_mbox);
1166EXPORT_SYMBOL_GPL(rio_release_outb_mbox);
1167