isl_38xx.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * Copyright (C) 2002 Intersil Americas Inc.
  3. * Copyright (C) 2003-2004 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>_
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/delay.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/io.h>
  23. #include "prismcompat.h"
  24. #include "isl_38xx.h"
  25. #include "islpci_dev.h"
  26. #include "islpci_mgt.h"
  27. /******************************************************************************
  28. Device Interface & Control functions
  29. ******************************************************************************/
  30. /**
  31. * isl38xx_disable_interrupts - disable all interrupts
  32. * @device: pci memory base address
  33. *
  34. * Instructs the device to disable all interrupt reporting by asserting
  35. * the IRQ line. New events may still show up in the interrupt identification
  36. * register located at offset %ISL38XX_INT_IDENT_REG.
  37. */
  38. void
  39. isl38xx_disable_interrupts(void __iomem *device)
  40. {
  41. isl38xx_w32_flush(device, 0x00000000, ISL38XX_INT_EN_REG);
  42. udelay(ISL38XX_WRITEIO_DELAY);
  43. }
  44. void
  45. isl38xx_handle_sleep_request(isl38xx_control_block *control_block,
  46. int *powerstate, void __iomem *device_base)
  47. {
  48. /* device requests to go into sleep mode
  49. * check whether the transmit queues for data and management are empty */
  50. if (isl38xx_in_queue(control_block, ISL38XX_CB_TX_DATA_LQ))
  51. /* data tx queue not empty */
  52. return;
  53. if (isl38xx_in_queue(control_block, ISL38XX_CB_TX_MGMTQ))
  54. /* management tx queue not empty */
  55. return;
  56. /* check also whether received frames are pending */
  57. if (isl38xx_in_queue(control_block, ISL38XX_CB_RX_DATA_LQ))
  58. /* data rx queue not empty */
  59. return;
  60. if (isl38xx_in_queue(control_block, ISL38XX_CB_RX_MGMTQ))
  61. /* management rx queue not empty */
  62. return;
  63. #if VERBOSE > SHOW_ERROR_MESSAGES
  64. DEBUG(SHOW_TRACING, "Device going to sleep mode\n");
  65. #endif
  66. /* all queues are empty, allow the device to go into sleep mode */
  67. *powerstate = ISL38XX_PSM_POWERSAVE_STATE;
  68. /* assert the Sleep interrupt in the Device Interrupt Register */
  69. isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_SLEEP,
  70. ISL38XX_DEV_INT_REG);
  71. udelay(ISL38XX_WRITEIO_DELAY);
  72. }
  73. void
  74. isl38xx_handle_wakeup(isl38xx_control_block *control_block,
  75. int *powerstate, void __iomem *device_base)
  76. {
  77. /* device is in active state, update the powerstate flag */
  78. *powerstate = ISL38XX_PSM_ACTIVE_STATE;
  79. /* now check whether there are frames pending for the card */
  80. if (!isl38xx_in_queue(control_block, ISL38XX_CB_TX_DATA_LQ)
  81. && !isl38xx_in_queue(control_block, ISL38XX_CB_TX_MGMTQ))
  82. return;
  83. #if VERBOSE > SHOW_ERROR_MESSAGES
  84. DEBUG(SHOW_ANYTHING, "Wake up handler trigger the device\n");
  85. #endif
  86. /* either data or management transmit queue has a frame pending
  87. * trigger the device by setting the Update bit in the Device Int reg */
  88. isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_UPDATE,
  89. ISL38XX_DEV_INT_REG);
  90. udelay(ISL38XX_WRITEIO_DELAY);
  91. }
  92. void
  93. isl38xx_trigger_device(int asleep, void __iomem *device_base)
  94. {
  95. u32 reg;
  96. #if VERBOSE > SHOW_ERROR_MESSAGES
  97. u32 counter = 0;
  98. struct timeval current_time;
  99. DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
  100. #endif
  101. /* check whether the device is in power save mode */
  102. if (asleep) {
  103. /* device is in powersave, trigger the device for wakeup */
  104. #if VERBOSE > SHOW_ERROR_MESSAGES
  105. do_gettimeofday(&current_time);
  106. DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
  107. current_time.tv_sec, (long)current_time.tv_usec);
  108. DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
  109. current_time.tv_sec, (long)current_time.tv_usec,
  110. readl(device_base + ISL38XX_CTRL_STAT_REG));
  111. #endif
  112. reg = readl(device_base + ISL38XX_INT_IDENT_REG);
  113. if (reg == 0xabadface) {
  114. #if VERBOSE > SHOW_ERROR_MESSAGES
  115. do_gettimeofday(&current_time);
  116. DEBUG(SHOW_TRACING,
  117. "%08li.%08li Device register abadface\n",
  118. current_time.tv_sec, (long)current_time.tv_usec);
  119. #endif
  120. /* read the Device Status Register until Sleepmode bit is set */
  121. while (reg = readl(device_base + ISL38XX_CTRL_STAT_REG),
  122. (reg & ISL38XX_CTRL_STAT_SLEEPMODE) == 0) {
  123. udelay(ISL38XX_WRITEIO_DELAY);
  124. #if VERBOSE > SHOW_ERROR_MESSAGES
  125. counter++;
  126. #endif
  127. }
  128. #if VERBOSE > SHOW_ERROR_MESSAGES
  129. DEBUG(SHOW_TRACING,
  130. "%08li.%08li Device register read %08x\n",
  131. current_time.tv_sec, (long)current_time.tv_usec,
  132. readl(device_base + ISL38XX_CTRL_STAT_REG));
  133. do_gettimeofday(&current_time);
  134. DEBUG(SHOW_TRACING,
  135. "%08li.%08li Device asleep counter %i\n",
  136. current_time.tv_sec, (long)current_time.tv_usec,
  137. counter);
  138. #endif
  139. }
  140. /* assert the Wakeup interrupt in the Device Interrupt Register */
  141. isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_WAKEUP,
  142. ISL38XX_DEV_INT_REG);
  143. #if VERBOSE > SHOW_ERROR_MESSAGES
  144. udelay(ISL38XX_WRITEIO_DELAY);
  145. /* perform another read on the Device Status Register */
  146. reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
  147. do_gettimeofday(&current_time);
  148. DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
  149. current_time.tv_sec, (long)current_time.tv_usec, reg);
  150. #endif
  151. } else {
  152. /* device is (still) awake */
  153. #if VERBOSE > SHOW_ERROR_MESSAGES
  154. DEBUG(SHOW_TRACING, "Device is in active state\n");
  155. #endif
  156. /* trigger the device by setting the Update bit in the Device Int reg */
  157. isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_UPDATE,
  158. ISL38XX_DEV_INT_REG);
  159. }
  160. }
  161. void
  162. isl38xx_interface_reset(void __iomem *device_base, dma_addr_t host_address)
  163. {
  164. #if VERBOSE > SHOW_ERROR_MESSAGES
  165. DEBUG(SHOW_FUNCTION_CALLS, "isl38xx_interface_reset\n");
  166. #endif
  167. /* load the address of the control block in the device */
  168. isl38xx_w32_flush(device_base, host_address, ISL38XX_CTRL_BLK_BASE_REG);
  169. udelay(ISL38XX_WRITEIO_DELAY);
  170. /* set the reset bit in the Device Interrupt Register */
  171. isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_RESET, ISL38XX_DEV_INT_REG);
  172. udelay(ISL38XX_WRITEIO_DELAY);
  173. /* enable the interrupt for detecting initialization */
  174. /* Note: Do not enable other interrupts here. We want the
  175. * device to have come up first 100% before allowing any other
  176. * interrupts. */
  177. isl38xx_w32_flush(device_base, ISL38XX_INT_IDENT_INIT, ISL38XX_INT_EN_REG);
  178. udelay(ISL38XX_WRITEIO_DELAY); /* allow complete full reset */
  179. }
  180. void
  181. isl38xx_enable_common_interrupts(void __iomem *device_base)
  182. {
  183. u32 reg;
  184. reg = ISL38XX_INT_IDENT_UPDATE | ISL38XX_INT_IDENT_SLEEP |
  185. ISL38XX_INT_IDENT_WAKEUP;
  186. isl38xx_w32_flush(device_base, reg, ISL38XX_INT_EN_REG);
  187. udelay(ISL38XX_WRITEIO_DELAY);
  188. }
  189. int
  190. isl38xx_in_queue(isl38xx_control_block *cb, int queue)
  191. {
  192. const s32 delta = (le32_to_cpu(cb->driver_curr_frag[queue]) -
  193. le32_to_cpu(cb->device_curr_frag[queue]));
  194. /* determine the amount of fragments in the queue depending on the type
  195. * of the queue, either transmit or receive */
  196. BUG_ON(delta < 0); /* driver ptr must be ahead of device ptr */
  197. switch (queue) {
  198. /* send queues */
  199. case ISL38XX_CB_TX_MGMTQ:
  200. BUG_ON(delta > ISL38XX_CB_MGMT_QSIZE);
  201. case ISL38XX_CB_TX_DATA_LQ:
  202. case ISL38XX_CB_TX_DATA_HQ:
  203. BUG_ON(delta > ISL38XX_CB_TX_QSIZE);
  204. return delta;
  205. /* receive queues */
  206. case ISL38XX_CB_RX_MGMTQ:
  207. BUG_ON(delta > ISL38XX_CB_MGMT_QSIZE);
  208. return ISL38XX_CB_MGMT_QSIZE - delta;
  209. case ISL38XX_CB_RX_DATA_LQ:
  210. case ISL38XX_CB_RX_DATA_HQ:
  211. BUG_ON(delta > ISL38XX_CB_RX_QSIZE);
  212. return ISL38XX_CB_RX_QSIZE - delta;
  213. }
  214. BUG();
  215. return 0;
  216. }