ip27-hubio.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright (C) 1992-1997, 2000-2003 Silicon Graphics, Inc.
  3. * Copyright (C) 2004 Christoph Hellwig.
  4. * Released under GPL v2.
  5. *
  6. * Support functions for the HUB ASIC - mostly PIO mapping related.
  7. */
  8. #include <linux/bitops.h>
  9. #include <linux/string.h>
  10. #include <linux/mmzone.h>
  11. #include <asm/sn/addrs.h>
  12. #include <asm/sn/arch.h>
  13. #include <asm/sn/hub.h>
  14. static int force_fire_and_forget = 1;
  15. /**
  16. * hub_pio_map - establish a HUB PIO mapping
  17. *
  18. * @hub: hub to perform PIO mapping on
  19. * @widget: widget ID to perform PIO mapping for
  20. * @xtalk_addr: xtalk_address that needs to be mapped
  21. * @size: size of the PIO mapping
  22. *
  23. **/
  24. unsigned long hub_pio_map(cnodeid_t cnode, xwidgetnum_t widget,
  25. unsigned long xtalk_addr, size_t size)
  26. {
  27. nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);
  28. unsigned i;
  29. /* use small-window mapping if possible */
  30. if ((xtalk_addr % SWIN_SIZE) + size <= SWIN_SIZE)
  31. return NODE_SWIN_BASE(nasid, widget) + (xtalk_addr % SWIN_SIZE);
  32. if ((xtalk_addr % BWIN_SIZE) + size > BWIN_SIZE) {
  33. printk(KERN_WARNING "PIO mapping at hub %d widget %d addr 0x%lx"
  34. " too big (%ld)\n",
  35. nasid, widget, xtalk_addr, size);
  36. return 0;
  37. }
  38. xtalk_addr &= ~(BWIN_SIZE-1);
  39. for (i = 0; i < HUB_NUM_BIG_WINDOW; i++) {
  40. if (test_and_set_bit(i, hub_data(cnode)->h_bigwin_used))
  41. continue;
  42. /*
  43. * The code below does a PIO write to setup an ITTE entry.
  44. *
  45. * We need to prevent other CPUs from seeing our updated
  46. * memory shadow of the ITTE (in the piomap) until the ITTE
  47. * entry is actually set up; otherwise, another CPU might
  48. * attempt a PIO prematurely.
  49. *
  50. * Also, the only way we can know that an entry has been
  51. * received by the hub and can be used by future PIO reads/
  52. * writes is by reading back the ITTE entry after writing it.
  53. *
  54. * For these two reasons, we PIO read back the ITTE entry
  55. * after we write it.
  56. */
  57. IIO_ITTE_PUT(nasid, i, HUB_PIO_MAP_TO_MEM, widget, xtalk_addr);
  58. (void) HUB_L(IIO_ITTE_GET(nasid, i));
  59. return NODE_BWIN_BASE(nasid, widget) + (xtalk_addr % BWIN_SIZE);
  60. }
  61. printk(KERN_WARNING "unable to establish PIO mapping for at"
  62. " hub %d widget %d addr 0x%lx\n",
  63. nasid, widget, xtalk_addr);
  64. return 0;
  65. }
  66. /*
  67. * hub_setup_prb(nasid, prbnum, credits, conveyor)
  68. *
  69. * Put a PRB into fire-and-forget mode if conveyor isn't set. Otherwise,
  70. * put it into conveyor belt mode with the specified number of credits.
  71. */
  72. static void hub_setup_prb(nasid_t nasid, int prbnum, int credits)
  73. {
  74. iprb_t prb;
  75. int prb_offset;
  76. /*
  77. * Get the current register value.
  78. */
  79. prb_offset = IIO_IOPRB(prbnum);
  80. prb.iprb_regval = REMOTE_HUB_L(nasid, prb_offset);
  81. /*
  82. * Clear out some fields.
  83. */
  84. prb.iprb_ovflow = 1;
  85. prb.iprb_bnakctr = 0;
  86. prb.iprb_anakctr = 0;
  87. /*
  88. * Enable or disable fire-and-forget mode.
  89. */
  90. prb.iprb_ff = force_fire_and_forget ? 1 : 0;
  91. /*
  92. * Set the appropriate number of PIO cresits for the widget.
  93. */
  94. prb.iprb_xtalkctr = credits;
  95. /*
  96. * Store the new value to the register.
  97. */
  98. REMOTE_HUB_S(nasid, prb_offset, prb.iprb_regval);
  99. }
  100. /**
  101. * hub_set_piomode - set pio mode for a given hub
  102. *
  103. * @nasid: physical node ID for the hub in question
  104. *
  105. * Put the hub into either "PIO conveyor belt" mode or "fire-and-forget" mode.
  106. * To do this, we have to make absolutely sure that no PIOs are in progress
  107. * so we turn off access to all widgets for the duration of the function.
  108. *
  109. * XXX - This code should really check what kind of widget we're talking
  110. * to. Bridges can only handle three requests, but XG will do more.
  111. * How many can crossbow handle to widget 0? We're assuming 1.
  112. *
  113. * XXX - There is a bug in the crossbow that link reset PIOs do not
  114. * return write responses. The easiest solution to this problem is to
  115. * leave widget 0 (xbow) in fire-and-forget mode at all times. This
  116. * only affects pio's to xbow registers, which should be rare.
  117. **/
  118. static void hub_set_piomode(nasid_t nasid)
  119. {
  120. hubreg_t ii_iowa;
  121. hubii_wcr_t ii_wcr;
  122. unsigned i;
  123. ii_iowa = REMOTE_HUB_L(nasid, IIO_OUTWIDGET_ACCESS);
  124. REMOTE_HUB_S(nasid, IIO_OUTWIDGET_ACCESS, 0);
  125. ii_wcr.wcr_reg_value = REMOTE_HUB_L(nasid, IIO_WCR);
  126. if (ii_wcr.iwcr_dir_con) {
  127. /*
  128. * Assume a bridge here.
  129. */
  130. hub_setup_prb(nasid, 0, 3);
  131. } else {
  132. /*
  133. * Assume a crossbow here.
  134. */
  135. hub_setup_prb(nasid, 0, 1);
  136. }
  137. /*
  138. * XXX - Here's where we should take the widget type into
  139. * when account assigning credits.
  140. */
  141. for (i = HUB_WIDGET_ID_MIN; i <= HUB_WIDGET_ID_MAX; i++)
  142. hub_setup_prb(nasid, i, 3);
  143. REMOTE_HUB_S(nasid, IIO_OUTWIDGET_ACCESS, ii_iowa);
  144. }
  145. /*
  146. * hub_pio_init - PIO-related hub initialization
  147. *
  148. * @hub: hubinfo structure for our hub
  149. */
  150. void hub_pio_init(cnodeid_t cnode)
  151. {
  152. nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);
  153. unsigned i;
  154. /* initialize big window piomaps for this hub */
  155. bitmap_zero(hub_data(cnode)->h_bigwin_used, HUB_NUM_BIG_WINDOW);
  156. for (i = 0; i < HUB_NUM_BIG_WINDOW; i++)
  157. IIO_ITTE_DISABLE(nasid, i);
  158. hub_set_piomode(nasid);
  159. }