isl_38xx.c 8.0 KB

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