isl_38xx.c 7.9 KB

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