isl_38xx.c 8.1 KB

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