rtsx.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* Driver for Realtek PCI-Express card reader
  2. * Header file
  3. *
  4. * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * Author:
  20. * Wei WANG (wei_wang@realsil.com.cn)
  21. * Micky Ching (micky_ching@realsil.com.cn)
  22. */
  23. #ifndef __REALTEK_RTSX_H
  24. #define __REALTEK_RTSX_H
  25. #include <linux/io.h>
  26. #include <linux/bitops.h>
  27. #include <linux/delay.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/moduleparam.h>
  32. #include <linux/slab.h>
  33. #include <linux/pci.h>
  34. #include <linux/mutex.h>
  35. #include <linux/cdrom.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/timer.h>
  38. #include <linux/time.h>
  39. #include <scsi/scsi.h>
  40. #include <scsi/scsi_cmnd.h>
  41. #include <scsi/scsi_device.h>
  42. #include <scsi/scsi_devinfo.h>
  43. #include <scsi/scsi_eh.h>
  44. #include <scsi/scsi_host.h>
  45. #include "trace.h"
  46. #include "general.h"
  47. #define CR_DRIVER_NAME "rts5208"
  48. #define pci_get_bus_and_slot(bus, devfn) \
  49. pci_get_domain_bus_and_slot(0, (bus), (devfn))
  50. /*
  51. * macros for easy use
  52. */
  53. #define rtsx_writel(chip, reg, value) \
  54. iowrite32(value, (chip)->rtsx->remap_addr + reg)
  55. #define rtsx_readl(chip, reg) \
  56. ioread32((chip)->rtsx->remap_addr + reg)
  57. #define rtsx_writew(chip, reg, value) \
  58. iowrite16(value, (chip)->rtsx->remap_addr + reg)
  59. #define rtsx_readw(chip, reg) \
  60. ioread16((chip)->rtsx->remap_addr + reg)
  61. #define rtsx_writeb(chip, reg, value) \
  62. iowrite8(value, (chip)->rtsx->remap_addr + reg)
  63. #define rtsx_readb(chip, reg) \
  64. ioread8((chip)->rtsx->remap_addr + reg)
  65. #define rtsx_read_config_byte(chip, where, val) \
  66. pci_read_config_byte((chip)->rtsx->pci, where, val)
  67. #define rtsx_write_config_byte(chip, where, val) \
  68. pci_write_config_byte((chip)->rtsx->pci, where, val)
  69. #define wait_timeout_x(task_state, msecs) \
  70. do { \
  71. set_current_state((task_state)); \
  72. schedule_timeout((msecs) * HZ / 1000); \
  73. } while (0)
  74. #define wait_timeout(msecs) wait_timeout_x(TASK_INTERRUPTIBLE, (msecs))
  75. #define STATE_TRANS_NONE 0
  76. #define STATE_TRANS_CMD 1
  77. #define STATE_TRANS_BUF 2
  78. #define STATE_TRANS_SG 3
  79. #define TRANS_NOT_READY 0
  80. #define TRANS_RESULT_OK 1
  81. #define TRANS_RESULT_FAIL 2
  82. #define SCSI_LUN(srb) ((srb)->device->lun)
  83. typedef unsigned long DELAY_PARA_T;
  84. struct rtsx_chip;
  85. struct rtsx_dev {
  86. struct pci_dev *pci;
  87. /* pci resources */
  88. unsigned long addr;
  89. void __iomem *remap_addr;
  90. int irq;
  91. /* locks */
  92. spinlock_t reg_lock;
  93. struct task_struct *ctl_thread; /* the control thread */
  94. struct task_struct *polling_thread; /* the polling thread */
  95. /* mutual exclusion and synchronization structures */
  96. struct completion cmnd_ready; /* to sleep thread on */
  97. struct completion control_exit; /* control thread exit */
  98. struct completion polling_exit; /* polling thread exit */
  99. struct completion notify; /* thread begin/end */
  100. struct completion scanning_done; /* wait for scan thread */
  101. wait_queue_head_t delay_wait; /* wait during scan, reset */
  102. struct mutex dev_mutex;
  103. /* host reserved buffer */
  104. void *rtsx_resv_buf;
  105. dma_addr_t rtsx_resv_buf_addr;
  106. char trans_result;
  107. char trans_state;
  108. struct completion *done;
  109. /* Whether interrupt handler should care card cd info */
  110. u32 check_card_cd;
  111. struct rtsx_chip *chip;
  112. };
  113. typedef struct rtsx_dev rtsx_dev_t;
  114. /* Convert between rtsx_dev and the corresponding Scsi_Host */
  115. static inline struct Scsi_Host *rtsx_to_host(struct rtsx_dev *dev)
  116. {
  117. return container_of((void *) dev, struct Scsi_Host, hostdata);
  118. }
  119. static inline struct rtsx_dev *host_to_rtsx(struct Scsi_Host *host)
  120. {
  121. return (struct rtsx_dev *) host->hostdata;
  122. }
  123. static inline void get_current_time(u8 *timeval_buf, int buf_len)
  124. {
  125. struct timeval tv;
  126. if (!timeval_buf || (buf_len < 8))
  127. return;
  128. do_gettimeofday(&tv);
  129. timeval_buf[0] = (u8)(tv.tv_sec >> 24);
  130. timeval_buf[1] = (u8)(tv.tv_sec >> 16);
  131. timeval_buf[2] = (u8)(tv.tv_sec >> 8);
  132. timeval_buf[3] = (u8)(tv.tv_sec);
  133. timeval_buf[4] = (u8)(tv.tv_usec >> 24);
  134. timeval_buf[5] = (u8)(tv.tv_usec >> 16);
  135. timeval_buf[6] = (u8)(tv.tv_usec >> 8);
  136. timeval_buf[7] = (u8)(tv.tv_usec);
  137. }
  138. /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
  139. * single queue element srb for write access */
  140. #define scsi_unlock(host) spin_unlock_irq(host->host_lock)
  141. #define scsi_lock(host) spin_lock_irq(host->host_lock)
  142. #define lock_state(chip) spin_lock_irq(&((chip)->rtsx->reg_lock))
  143. #define unlock_state(chip) spin_unlock_irq(&((chip)->rtsx->reg_lock))
  144. /* struct scsi_cmnd transfer buffer access utilities */
  145. enum xfer_buf_dir {TO_XFER_BUF, FROM_XFER_BUF};
  146. int rtsx_read_pci_cfg_byte(u8 bus, u8 dev, u8 func, u8 offset, u8 *val);
  147. #endif /* __REALTEK_RTSX_H */