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);
35static unsigned char next_portid;
36static DEFINE_SPINLOCK(rio_mmap_lock);
37
38
39
40
41
42
43
44
45
46u16 rio_local_get_device_id(struct rio_mport *port)
47{
48 u32 result;
49
50 rio_local_read_config_32(port, RIO_DID_CSR, &result);
51
52 return (RIO_GET_DID(port->sys_size, result));
53}
54
55
56
57
58
59
60
61
62
63
64
65
66int rio_request_inb_mbox(struct rio_mport *mport,
67 void *dev_id,
68 int mbox,
69 int entries,
70 void (*minb) (struct rio_mport * mport, void *dev_id, int mbox,
71 int slot))
72{
73 int rc = -ENOSYS;
74 struct resource *res;
75
76 if (mport->ops->open_inb_mbox == NULL)
77 goto out;
78
79 res = kmalloc(sizeof(struct resource), GFP_KERNEL);
80
81 if (res) {
82 rio_init_mbox_res(res, mbox, mbox);
83
84
85 if ((rc =
86 request_resource(&mport->riores[RIO_INB_MBOX_RESOURCE],
87 res)) < 0) {
88 kfree(res);
89 goto out;
90 }
91
92 mport->inb_msg[mbox].res = res;
93
94
95 mport->inb_msg[mbox].mcback = minb;
96
97 rc = mport->ops->open_inb_mbox(mport, dev_id, mbox, entries);
98 } else
99 rc = -ENOMEM;
100
101 out:
102 return rc;
103}
104
105
106
107
108
109
110
111
112
113int rio_release_inb_mbox(struct rio_mport *mport, int mbox)
114{
115 if (mport->ops->close_inb_mbox) {
116 mport->ops->close_inb_mbox(mport, mbox);
117
118
119 return release_resource(mport->inb_msg[mbox].res);
120 } else
121 return -ENOSYS;
122}
123
124
125
126
127
128
129
130
131
132
133
134
135int rio_request_outb_mbox(struct rio_mport *mport,
136 void *dev_id,
137 int mbox,
138 int entries,
139 void (*moutb) (struct rio_mport * mport, void *dev_id, int mbox, int slot))
140{
141 int rc = -ENOSYS;
142 struct resource *res;
143
144 if (mport->ops->open_outb_mbox == NULL)
145 goto out;
146
147 res = kmalloc(sizeof(struct resource), GFP_KERNEL);
148
149 if (res) {
150 rio_init_mbox_res(res, mbox, mbox);
151
152
153 if ((rc =
154 request_resource(&mport->riores[RIO_OUTB_MBOX_RESOURCE],
155 res)) < 0) {
156 kfree(res);
157 goto out;
158 }
159
160 mport->outb_msg[mbox].res = res;
161
162
163 mport->outb_msg[mbox].mcback = moutb;
164
165 rc = mport->ops->open_outb_mbox(mport, dev_id, mbox, entries);
166 } else
167 rc = -ENOMEM;
168
169 out:
170 return rc;
171}
172
173
174
175
176
177
178
179
180
181int rio_release_outb_mbox(struct rio_mport *mport, int mbox)
182{
183 if (mport->ops->close_outb_mbox) {
184 mport->ops->close_outb_mbox(mport, mbox);
185
186
187 return release_resource(mport->outb_msg[mbox].res);
188 } else
189 return -ENOSYS;
190}
191
192
193
194
195
196
197
198
199
200
201
202
203static int
204rio_setup_inb_dbell(struct rio_mport *mport, void *dev_id, struct resource *res,
205 void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src, u16 dst,
206 u16 info))
207{
208 int rc = 0;
209 struct rio_dbell *dbell;
210
211 if (!(dbell = kmalloc(sizeof(struct rio_dbell), GFP_KERNEL))) {
212 rc = -ENOMEM;
213 goto out;
214 }
215
216 dbell->res = res;
217 dbell->dinb = dinb;
218 dbell->dev_id = dev_id;
219
220 list_add_tail(&dbell->node, &mport->dbells);
221
222 out:
223 return rc;
224}
225
226
227
228
229
230
231
232
233
234
235
236
237
238int rio_request_inb_dbell(struct rio_mport *mport,
239 void *dev_id,
240 u16 start,
241 u16 end,
242 void (*dinb) (struct rio_mport * mport, void *dev_id, u16 src,
243 u16 dst, u16 info))
244{
245 int rc = 0;
246
247 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
248
249 if (res) {
250 rio_init_dbell_res(res, start, end);
251
252
253 if ((rc =
254 request_resource(&mport->riores[RIO_DOORBELL_RESOURCE],
255 res)) < 0) {
256 kfree(res);
257 goto out;
258 }
259
260
261 rc = rio_setup_inb_dbell(mport, dev_id, res, dinb);
262 } else
263 rc = -ENOMEM;
264
265 out:
266 return rc;
267}
268
269
270
271
272
273
274
275
276
277
278
279int rio_release_inb_dbell(struct rio_mport *mport, u16 start, u16 end)
280{
281 int rc = 0, found = 0;
282 struct rio_dbell *dbell;
283
284 list_for_each_entry(dbell, &mport->dbells, node) {
285 if ((dbell->res->start == start) && (dbell->res->end == end)) {
286 found = 1;
287 break;
288 }
289 }
290
291
292 if (!found) {
293 rc = -EINVAL;
294 goto out;
295 }
296
297
298 list_del(&dbell->node);
299
300
301 rc = release_resource(dbell->res);
302
303
304 kfree(dbell);
305
306 out:
307 return rc;
308}
309
310
311
312
313
314
315
316
317
318
319struct resource *rio_request_outb_dbell(struct rio_dev *rdev, u16 start,
320 u16 end)
321{
322 struct resource *res = kmalloc(sizeof(struct resource), GFP_KERNEL);
323
324 if (res) {
325 rio_init_dbell_res(res, start, end);
326
327
328 if (request_resource(&rdev->riores[RIO_DOORBELL_RESOURCE], res)
329 < 0) {
330 kfree(res);
331 res = NULL;
332 }
333 }
334
335 return res;
336}
337
338
339
340
341
342
343
344
345
346int rio_release_outb_dbell(struct rio_dev *rdev, struct resource *res)
347{
348 int rc = release_resource(res);
349
350 kfree(res);
351
352 return rc;
353}
354
355
356
357
358
359
360
361
362
363int rio_request_inb_pwrite(struct rio_dev *rdev,
364 int (*pwcback)(struct rio_dev *rdev, union rio_pw_msg *msg, int step))
365{
366 int rc = 0;
367
368 spin_lock(&rio_global_list_lock);
369 if (rdev->pwcback != NULL)
370 rc = -ENOMEM;
371 else
372 rdev->pwcback = pwcback;
373
374 spin_unlock(&rio_global_list_lock);
375 return rc;
376}
377EXPORT_SYMBOL_GPL(rio_request_inb_pwrite);
378
379
380
381
382
383
384
385
386int rio_release_inb_pwrite(struct rio_dev *rdev)
387{
388 int rc = -ENOMEM;
389
390 spin_lock(&rio_global_list_lock);
391 if (rdev->pwcback) {
392 rdev->pwcback = NULL;
393 rc = 0;
394 }
395
396 spin_unlock(&rio_global_list_lock);
397 return rc;
398}
399EXPORT_SYMBOL_GPL(rio_release_inb_pwrite);
400
401
402
403
404
405
406
407
408
409
410
411
412
413int rio_map_inb_region(struct rio_mport *mport, dma_addr_t local,
414 u64 rbase, u32 size, u32 rflags)
415{
416 int rc = 0;
417 unsigned long flags;
418
419 if (!mport->ops->map_inb)
420 return -1;
421 spin_lock_irqsave(&rio_mmap_lock, flags);
422 rc = mport->ops->map_inb(mport, local, rbase, size, rflags);
423 spin_unlock_irqrestore(&rio_mmap_lock, flags);
424 return rc;
425}
426EXPORT_SYMBOL_GPL(rio_map_inb_region);
427
428
429
430
431
432
433void rio_unmap_inb_region(struct rio_mport *mport, dma_addr_t lstart)
434{
435 unsigned long flags;
436 if (!mport->ops->unmap_inb)
437 return;
438 spin_lock_irqsave(&rio_mmap_lock, flags);
439 mport->ops->unmap_inb(mport, lstart);
440 spin_unlock_irqrestore(&rio_mmap_lock, flags);
441}
442EXPORT_SYMBOL_GPL(rio_unmap_inb_region);
443
444
445
446
447
448
449
450
451
452u32
453rio_mport_get_physefb(struct rio_mport *port, int local,
454 u16 destid, u8 hopcount)
455{
456 u32 ext_ftr_ptr;
457 u32 ftr_header;
458
459 ext_ftr_ptr = rio_mport_get_efb(port, local, destid, hopcount, 0);
460
461 while (ext_ftr_ptr) {
462 if (local)
463 rio_local_read_config_32(port, ext_ftr_ptr,
464 &ftr_header);
465 else
466 rio_mport_read_config_32(port, destid, hopcount,
467 ext_ftr_ptr, &ftr_header);
468
469 ftr_header = RIO_GET_BLOCK_ID(ftr_header);
470 switch (ftr_header) {
471
472 case RIO_EFB_SER_EP_ID_V13P:
473 case RIO_EFB_SER_EP_REC_ID_V13P:
474 case RIO_EFB_SER_EP_FREE_ID_V13P:
475 case RIO_EFB_SER_EP_ID:
476 case RIO_EFB_SER_EP_REC_ID:
477 case RIO_EFB_SER_EP_FREE_ID:
478 case RIO_EFB_SER_EP_FREC_ID:
479
480 return ext_ftr_ptr;
481
482 default:
483 break;
484 }
485
486 ext_ftr_ptr = rio_mport_get_efb(port, local, destid,
487 hopcount, ext_ftr_ptr);
488 }
489
490 return ext_ftr_ptr;
491}
492
493
494
495
496
497
498
499
500
501
502
503
504
505struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from)
506{
507 struct list_head *n;
508 struct rio_dev *rdev;
509
510 spin_lock(&rio_global_list_lock);
511 n = from ? from->global_list.next : rio_devices.next;
512
513 while (n && (n != &rio_devices)) {
514 rdev = rio_dev_g(n);
515 if (rdev->comp_tag == comp_tag)
516 goto exit;
517 n = n->next;
518 }
519 rdev = NULL;
520exit:
521 spin_unlock(&rio_global_list_lock);
522 return rdev;
523}
524
525
526
527
528
529
530
531int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
532{
533 u32 regval;
534
535 rio_read_config_32(rdev,
536 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
537 ®val);
538 if (lock)
539 regval |= RIO_PORT_N_CTL_LOCKOUT;
540 else
541 regval &= ~RIO_PORT_N_CTL_LOCKOUT;
542
543 rio_write_config_32(rdev,
544 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
545 regval);
546 return 0;
547}
548
549
550
551
552
553
554
555
556
557
558static int
559rio_chk_dev_route(struct rio_dev *rdev, struct rio_dev **nrdev, int *npnum)
560{
561 u32 result;
562 int p_port, rc = -EIO;
563 struct rio_dev *prev = NULL;
564
565
566 while (rdev->prev && (rdev->prev->pef & RIO_PEF_SWITCH)) {
567 if (!rio_read_config_32(rdev->prev, RIO_DEV_ID_CAR, &result)) {
568 prev = rdev->prev;
569 break;
570 }
571 rdev = rdev->prev;
572 }
573
574 if (prev == NULL)
575 goto err_out;
576
577 p_port = prev->rswitch->route_table[rdev->destid];
578
579 if (p_port != RIO_INVALID_ROUTE) {
580 pr_debug("RIO: link failed on [%s]-P%d\n",
581 rio_name(prev), p_port);
582 *nrdev = prev;
583 *npnum = p_port;
584 rc = 0;
585 } else
586 pr_debug("RIO: failed to trace route to %s\n", rio_name(rdev));
587err_out:
588 return rc;
589}
590
591
592
593
594
595
596
597int
598rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid, u8 hopcount)
599{
600 int i = 0;
601 u32 tmp;
602
603 while (rio_mport_read_config_32(mport, destid, hopcount,
604 RIO_DEV_ID_CAR, &tmp)) {
605 i++;
606 if (i == RIO_MAX_CHK_RETRY)
607 return -EIO;
608 mdelay(1);
609 }
610
611 return 0;
612}
613
614
615
616
617
618static int rio_chk_dev_access(struct rio_dev *rdev)
619{
620 return rio_mport_chk_dev_access(rdev->net->hport,
621 rdev->destid, rdev->hopcount);
622}
623
624
625
626
627
628
629
630
631static int
632rio_get_input_status(struct rio_dev *rdev, int pnum, u32 *lnkresp)
633{
634 u32 regval;
635 int checkcount;
636
637 if (lnkresp) {
638
639
640 rio_read_config_32(rdev,
641 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
642 ®val);
643 udelay(50);
644 }
645
646
647 rio_write_config_32(rdev,
648 rdev->phys_efptr + RIO_PORT_N_MNT_REQ_CSR(pnum),
649 RIO_MNT_REQ_CMD_IS);
650
651
652 if (lnkresp == NULL)
653 return 0;
654
655 checkcount = 3;
656 while (checkcount--) {
657 udelay(50);
658 rio_read_config_32(rdev,
659 rdev->phys_efptr + RIO_PORT_N_MNT_RSP_CSR(pnum),
660 ®val);
661 if (regval & RIO_PORT_N_MNT_RSP_RVAL) {
662 *lnkresp = regval;
663 return 0;
664 }
665 }
666
667 return -EIO;
668}
669
670
671
672
673
674
675
676static int rio_clr_err_stopped(struct rio_dev *rdev, u32 pnum, u32 err_status)
677{
678 struct rio_dev *nextdev = rdev->rswitch->nextdev[pnum];
679 u32 regval;
680 u32 far_ackid, far_linkstat, near_ackid;
681
682 if (err_status == 0)
683 rio_read_config_32(rdev,
684 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
685 &err_status);
686
687 if (err_status & RIO_PORT_N_ERR_STS_PW_OUT_ES) {
688 pr_debug("RIO_EM: servicing Output Error-Stopped state\n");
689
690
691
692 if (rio_get_input_status(rdev, pnum, ®val)) {
693 pr_debug("RIO_EM: Input-status response timeout\n");
694 goto rd_err;
695 }
696
697 pr_debug("RIO_EM: SP%d Input-status response=0x%08x\n",
698 pnum, regval);
699 far_ackid = (regval & RIO_PORT_N_MNT_RSP_ASTAT) >> 5;
700 far_linkstat = regval & RIO_PORT_N_MNT_RSP_LSTAT;
701 rio_read_config_32(rdev,
702 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
703 ®val);
704 pr_debug("RIO_EM: SP%d_ACK_STS_CSR=0x%08x\n", pnum, regval);
705 near_ackid = (regval & RIO_PORT_N_ACK_INBOUND) >> 24;
706 pr_debug("RIO_EM: SP%d far_ackID=0x%02x far_linkstat=0x%02x" \
707 " near_ackID=0x%02x\n",
708 pnum, far_ackid, far_linkstat, near_ackid);
709
710
711
712
713
714 if ((far_ackid != ((regval & RIO_PORT_N_ACK_OUTSTAND) >> 8)) ||
715 (far_ackid != (regval & RIO_PORT_N_ACK_OUTBOUND))) {
716
717
718
719 rio_write_config_32(rdev,
720 rdev->phys_efptr + RIO_PORT_N_ACK_STS_CSR(pnum),
721 (near_ackid << 24) |
722 (far_ackid << 8) | far_ackid);
723
724
725
726 far_ackid++;
727 if (nextdev)
728 rio_write_config_32(nextdev,
729 nextdev->phys_efptr +
730 RIO_PORT_N_ACK_STS_CSR(RIO_GET_PORT_NUM(nextdev->swpinfo)),
731 (far_ackid << 24) |
732 (near_ackid << 8) | near_ackid);
733 else
734 pr_debug("RIO_EM: Invalid nextdev pointer (NULL)\n");
735 }
736rd_err:
737 rio_read_config_32(rdev,
738 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
739 &err_status);
740 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
741 }
742
743 if ((err_status & RIO_PORT_N_ERR_STS_PW_INP_ES) && nextdev) {
744 pr_debug("RIO_EM: servicing Input Error-Stopped state\n");
745 rio_get_input_status(nextdev,
746 RIO_GET_PORT_NUM(nextdev->swpinfo), NULL);
747 udelay(50);
748
749 rio_read_config_32(rdev,
750 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(pnum),
751 &err_status);
752 pr_debug("RIO_EM: SP%d_ERR_STS_CSR=0x%08x\n", pnum, err_status);
753 }
754
755 return (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
756 RIO_PORT_N_ERR_STS_PW_INP_ES)) ? 1 : 0;
757}
758
759
760
761
762
763
764
765
766int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
767{
768 struct rio_dev *rdev;
769 u32 err_status, em_perrdet, em_ltlerrdet;
770 int rc, portnum;
771
772 rdev = rio_get_comptag((pw_msg->em.comptag & RIO_CTAG_UDEVID), NULL);
773 if (rdev == NULL) {
774
775 pr_debug("RIO: %s No matching device for CTag 0x%08x\n",
776 __func__, pw_msg->em.comptag);
777 return -EIO;
778 }
779
780 pr_debug("RIO: Port-Write message from %s\n", rio_name(rdev));
781
782#ifdef DEBUG_PW
783 {
784 u32 i;
785 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32);) {
786 pr_debug("0x%02x: %08x %08x %08x %08x\n",
787 i*4, pw_msg->raw[i], pw_msg->raw[i + 1],
788 pw_msg->raw[i + 2], pw_msg->raw[i + 3]);
789 i += 4;
790 }
791 }
792#endif
793
794
795
796
797
798
799
800 if (rdev->pwcback != NULL) {
801 rc = rdev->pwcback(rdev, pw_msg, 0);
802 if (rc == 0)
803 return 0;
804 }
805
806 portnum = pw_msg->em.is_port & 0xFF;
807
808
809
810
811
812 if (rio_chk_dev_access(rdev)) {
813 pr_debug("RIO: device access failed - get link partner\n");
814
815
816
817
818 if (rio_chk_dev_route(rdev, &rdev, &portnum)) {
819 pr_err("RIO: Route trace for %s failed\n",
820 rio_name(rdev));
821 return -EIO;
822 }
823 pw_msg = NULL;
824 }
825
826
827 if (!(rdev->pef & RIO_PEF_SWITCH))
828 return 0;
829
830 if (rdev->phys_efptr == 0) {
831 pr_err("RIO_PW: Bad switch initialization for %s\n",
832 rio_name(rdev));
833 return 0;
834 }
835
836
837
838
839 if (rdev->rswitch->em_handle)
840 rdev->rswitch->em_handle(rdev, portnum);
841
842 rio_read_config_32(rdev,
843 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
844 &err_status);
845 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status);
846
847 if (err_status & RIO_PORT_N_ERR_STS_PORT_OK) {
848
849 if (!(rdev->rswitch->port_ok & (1 << portnum))) {
850 rdev->rswitch->port_ok |= (1 << portnum);
851 rio_set_port_lockout(rdev, portnum, 0);
852
853 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n",
854 rio_name(rdev), portnum);
855 }
856
857
858
859
860
861 if (err_status & (RIO_PORT_N_ERR_STS_PW_OUT_ES |
862 RIO_PORT_N_ERR_STS_PW_INP_ES)) {
863 if (rio_clr_err_stopped(rdev, portnum, err_status))
864 rio_clr_err_stopped(rdev, portnum, 0);
865 }
866 } else {
867
868 if (rdev->rswitch->port_ok & (1 << portnum)) {
869 rdev->rswitch->port_ok &= ~(1 << portnum);
870 rio_set_port_lockout(rdev, portnum, 1);
871
872 rio_write_config_32(rdev,
873 rdev->phys_efptr +
874 RIO_PORT_N_ACK_STS_CSR(portnum),
875 RIO_PORT_N_ACK_CLEAR);
876
877
878 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n",
879 rio_name(rdev), portnum);
880 }
881 }
882
883 rio_read_config_32(rdev,
884 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), &em_perrdet);
885 if (em_perrdet) {
886 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
887 portnum, em_perrdet);
888
889 rio_write_config_32(rdev,
890 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0);
891 }
892
893 rio_read_config_32(rdev,
894 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, &em_ltlerrdet);
895 if (em_ltlerrdet) {
896 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
897 em_ltlerrdet);
898
899 rio_write_config_32(rdev,
900 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0);
901 }
902
903
904 rio_write_config_32(rdev,
905 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
906 err_status);
907
908 return 0;
909}
910EXPORT_SYMBOL_GPL(rio_inb_pwrite_handler);
911
912
913
914
915
916
917
918
919
920
921u32
922rio_mport_get_efb(struct rio_mport *port, int local, u16 destid,
923 u8 hopcount, u32 from)
924{
925 u32 reg_val;
926
927 if (from == 0) {
928 if (local)
929 rio_local_read_config_32(port, RIO_ASM_INFO_CAR,
930 ®_val);
931 else
932 rio_mport_read_config_32(port, destid, hopcount,
933 RIO_ASM_INFO_CAR, ®_val);
934 return reg_val & RIO_EXT_FTR_PTR_MASK;
935 } else {
936 if (local)
937 rio_local_read_config_32(port, from, ®_val);
938 else
939 rio_mport_read_config_32(port, destid, hopcount,
940 from, ®_val);
941 return RIO_GET_BLOCK_ID(reg_val);
942 }
943}
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971u32
972rio_mport_get_feature(struct rio_mport * port, int local, u16 destid,
973 u8 hopcount, int ftr)
974{
975 u32 asm_info, ext_ftr_ptr, ftr_header;
976
977 if (local)
978 rio_local_read_config_32(port, RIO_ASM_INFO_CAR, &asm_info);
979 else
980 rio_mport_read_config_32(port, destid, hopcount,
981 RIO_ASM_INFO_CAR, &asm_info);
982
983 ext_ftr_ptr = asm_info & RIO_EXT_FTR_PTR_MASK;
984
985 while (ext_ftr_ptr) {
986 if (local)
987 rio_local_read_config_32(port, ext_ftr_ptr,
988 &ftr_header);
989 else
990 rio_mport_read_config_32(port, destid, hopcount,
991 ext_ftr_ptr, &ftr_header);
992 if (RIO_GET_BLOCK_ID(ftr_header) == ftr)
993 return ext_ftr_ptr;
994 if (!(ext_ftr_ptr = RIO_GET_BLOCK_PTR(ftr_header)))
995 break;
996 }
997
998 return 0;
999}
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018struct rio_dev *rio_get_asm(u16 vid, u16 did,
1019 u16 asm_vid, u16 asm_did, struct rio_dev *from)
1020{
1021 struct list_head *n;
1022 struct rio_dev *rdev;
1023
1024 WARN_ON(in_interrupt());
1025 spin_lock(&rio_global_list_lock);
1026 n = from ? from->global_list.next : rio_devices.next;
1027
1028 while (n && (n != &rio_devices)) {
1029 rdev = rio_dev_g(n);
1030 if ((vid == RIO_ANY_ID || rdev->vid == vid) &&
1031 (did == RIO_ANY_ID || rdev->did == did) &&
1032 (asm_vid == RIO_ANY_ID || rdev->asm_vid == asm_vid) &&
1033 (asm_did == RIO_ANY_ID || rdev->asm_did == asm_did))
1034 goto exit;
1035 n = n->next;
1036 }
1037 rdev = NULL;
1038 exit:
1039 rio_dev_put(from);
1040 rdev = rio_dev_get(rdev);
1041 spin_unlock(&rio_global_list_lock);
1042 return rdev;
1043}
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from)
1060{
1061 return rio_get_asm(vid, did, RIO_ANY_ID, RIO_ANY_ID, from);
1062}
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074int rio_std_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
1075 u16 table, u16 route_destid, u8 route_port)
1076{
1077 if (table == RIO_GLOBAL_TABLE) {
1078 rio_mport_write_config_32(mport, destid, hopcount,
1079 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
1080 (u32)route_destid);
1081 rio_mport_write_config_32(mport, destid, hopcount,
1082 RIO_STD_RTE_CONF_PORT_SEL_CSR,
1083 (u32)route_port);
1084 }
1085
1086 udelay(10);
1087 return 0;
1088}
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101int rio_std_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
1102 u16 table, u16 route_destid, u8 *route_port)
1103{
1104 u32 result;
1105
1106 if (table == RIO_GLOBAL_TABLE) {
1107 rio_mport_write_config_32(mport, destid, hopcount,
1108 RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid);
1109 rio_mport_read_config_32(mport, destid, hopcount,
1110 RIO_STD_RTE_CONF_PORT_SEL_CSR, &result);
1111
1112 *route_port = (u8)result;
1113 }
1114
1115 return 0;
1116}
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
1127 u16 table)
1128{
1129 u32 max_destid = 0xff;
1130 u32 i, pef, id_inc = 1, ext_cfg = 0;
1131 u32 port_sel = RIO_INVALID_ROUTE;
1132
1133 if (table == RIO_GLOBAL_TABLE) {
1134 rio_mport_read_config_32(mport, destid, hopcount,
1135 RIO_PEF_CAR, &pef);
1136
1137 if (mport->sys_size) {
1138 rio_mport_read_config_32(mport, destid, hopcount,
1139 RIO_SWITCH_RT_LIMIT,
1140 &max_destid);
1141 max_destid &= RIO_RT_MAX_DESTID;
1142 }
1143
1144 if (pef & RIO_PEF_EXT_RT) {
1145 ext_cfg = 0x80000000;
1146 id_inc = 4;
1147 port_sel = (RIO_INVALID_ROUTE << 24) |
1148 (RIO_INVALID_ROUTE << 16) |
1149 (RIO_INVALID_ROUTE << 8) |
1150 RIO_INVALID_ROUTE;
1151 }
1152
1153 for (i = 0; i <= max_destid;) {
1154 rio_mport_write_config_32(mport, destid, hopcount,
1155 RIO_STD_RTE_CONF_DESTID_SEL_CSR,
1156 ext_cfg | i);
1157 rio_mport_write_config_32(mport, destid, hopcount,
1158 RIO_STD_RTE_CONF_PORT_SEL_CSR,
1159 port_sel);
1160 i += id_inc;
1161 }
1162 }
1163
1164 udelay(10);
1165 return 0;
1166}
1167
1168#ifdef CONFIG_RAPIDIO_DMA_ENGINE
1169
1170static bool rio_chan_filter(struct dma_chan *chan, void *arg)
1171{
1172 struct rio_dev *rdev = arg;
1173
1174
1175 return (rdev->net->hport ==
1176 container_of(chan->device, struct rio_mport, dma));
1177}
1178
1179
1180
1181
1182
1183
1184
1185
1186struct dma_chan *rio_request_dma(struct rio_dev *rdev)
1187{
1188 dma_cap_mask_t mask;
1189 struct dma_chan *dchan;
1190
1191 dma_cap_zero(mask);
1192 dma_cap_set(DMA_SLAVE, mask);
1193 dchan = dma_request_channel(mask, rio_chan_filter, rdev);
1194
1195 return dchan;
1196}
1197EXPORT_SYMBOL_GPL(rio_request_dma);
1198
1199
1200
1201
1202
1203void rio_release_dma(struct dma_chan *dchan)
1204{
1205 dma_release_channel(dchan);
1206}
1207EXPORT_SYMBOL_GPL(rio_release_dma);
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223struct dma_async_tx_descriptor *rio_dma_prep_slave_sg(struct rio_dev *rdev,
1224 struct dma_chan *dchan, struct rio_dma_data *data,
1225 enum dma_transfer_direction direction, unsigned long flags)
1226{
1227 struct dma_async_tx_descriptor *txd = NULL;
1228 struct rio_dma_ext rio_ext;
1229
1230 if (dchan->device->device_prep_slave_sg == NULL) {
1231 pr_err("%s: prep_rio_sg == NULL\n", __func__);
1232 return NULL;
1233 }
1234
1235 rio_ext.destid = rdev->destid;
1236 rio_ext.rio_addr_u = data->rio_addr_u;
1237 rio_ext.rio_addr = data->rio_addr;
1238 rio_ext.wr_type = data->wr_type;
1239
1240 txd = dmaengine_prep_rio_sg(dchan, data->sg, data->sg_len,
1241 direction, flags, &rio_ext);
1242
1243 return txd;
1244}
1245EXPORT_SYMBOL_GPL(rio_dma_prep_slave_sg);
1246
1247#endif
1248
1249static void rio_fixup_device(struct rio_dev *dev)
1250{
1251}
1252
1253static int rio_init(void)
1254{
1255 struct rio_dev *dev = NULL;
1256
1257 while ((dev = rio_get_device(RIO_ANY_ID, RIO_ANY_ID, dev)) != NULL) {
1258 rio_fixup_device(dev);
1259 }
1260 return 0;
1261}
1262
1263static struct workqueue_struct *rio_wq;
1264
1265struct rio_disc_work {
1266 struct work_struct work;
1267 struct rio_mport *mport;
1268};
1269
1270static void disc_work_handler(struct work_struct *_work)
1271{
1272 struct rio_disc_work *work;
1273
1274 work = container_of(_work, struct rio_disc_work, work);
1275 pr_debug("RIO: discovery work for mport %d %s\n",
1276 work->mport->id, work->mport->name);
1277 rio_disc_mport(work->mport);
1278}
1279
1280int rio_init_mports(void)
1281{
1282 struct rio_mport *port;
1283 struct rio_disc_work *work;
1284 int n = 0;
1285
1286 if (!next_portid)
1287 return -ENODEV;
1288
1289
1290
1291
1292
1293 list_for_each_entry(port, &rio_mports, node) {
1294 if (port->host_deviceid >= 0)
1295 rio_enum_mport(port);
1296 else
1297 n++;
1298 }
1299
1300 if (!n)
1301 goto no_disc;
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311 rio_wq = alloc_workqueue("riodisc", 0, 0);
1312 if (!rio_wq) {
1313 pr_err("RIO: unable allocate rio_wq\n");
1314 goto no_disc;
1315 }
1316
1317 work = kcalloc(n, sizeof *work, GFP_KERNEL);
1318 if (!work) {
1319 pr_err("RIO: no memory for work struct\n");
1320 destroy_workqueue(rio_wq);
1321 goto no_disc;
1322 }
1323
1324 n = 0;
1325 list_for_each_entry(port, &rio_mports, node) {
1326 if (port->host_deviceid < 0) {
1327 work[n].mport = port;
1328 INIT_WORK(&work[n].work, disc_work_handler);
1329 queue_work(rio_wq, &work[n].work);
1330 n++;
1331 }
1332 }
1333
1334 flush_workqueue(rio_wq);
1335 pr_debug("RIO: destroy discovery workqueue\n");
1336 destroy_workqueue(rio_wq);
1337 kfree(work);
1338
1339no_disc:
1340 rio_init();
1341
1342 return 0;
1343}
1344
1345device_initcall_sync(rio_init_mports);
1346
1347static int hdids[RIO_MAX_MPORTS + 1];
1348
1349static int rio_get_hdid(int index)
1350{
1351 if (!hdids[0] || hdids[0] <= index || index >= RIO_MAX_MPORTS)
1352 return -1;
1353
1354 return hdids[index + 1];
1355}
1356
1357static int rio_hdid_setup(char *str)
1358{
1359 (void)get_options(str, ARRAY_SIZE(hdids), hdids);
1360 return 1;
1361}
1362
1363__setup("riohdid=", rio_hdid_setup);
1364
1365int rio_register_mport(struct rio_mport *port)
1366{
1367 if (next_portid >= RIO_MAX_MPORTS) {
1368 pr_err("RIO: reached specified max number of mports\n");
1369 return 1;
1370 }
1371
1372 port->id = next_portid++;
1373 port->host_deviceid = rio_get_hdid(port->id);
1374 list_add_tail(&port->node, &rio_mports);
1375 return 0;
1376}
1377
1378EXPORT_SYMBOL_GPL(rio_local_get_device_id);
1379EXPORT_SYMBOL_GPL(rio_get_device);
1380EXPORT_SYMBOL_GPL(rio_get_asm);
1381EXPORT_SYMBOL_GPL(rio_request_inb_dbell);
1382EXPORT_SYMBOL_GPL(rio_release_inb_dbell);
1383EXPORT_SYMBOL_GPL(rio_request_outb_dbell);
1384EXPORT_SYMBOL_GPL(rio_release_outb_dbell);
1385EXPORT_SYMBOL_GPL(rio_request_inb_mbox);
1386EXPORT_SYMBOL_GPL(rio_release_inb_mbox);
1387EXPORT_SYMBOL_GPL(rio_request_outb_mbox);
1388EXPORT_SYMBOL_GPL(rio_release_outb_mbox);
1389