1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Driver for Realtek PCI-Express card reader
5 * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
8 * Wei WANG (wei_wang@realsil.com.cn)
9 * Micky Ching (micky_ching@realsil.com.cn)
12 #ifndef __REALTEK_RTSX_H
13 #define __REALTEK_RTSX_H
16 #include <linux/bitops.h>
17 #include <linux/delay.h>
18 #include <linux/interrupt.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/moduleparam.h>
22 #include <linux/slab.h>
23 #include <linux/pci.h>
24 #include <linux/mutex.h>
25 #include <linux/cdrom.h>
26 #include <linux/workqueue.h>
27 #include <linux/timer.h>
28 #include <linux/time64.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_cmnd.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_devinfo.h>
34 #include <scsi/scsi_eh.h>
35 #include <scsi/scsi_host.h>
37 #define CR_DRIVER_NAME "rts5208"
42 #define rtsx_writel(chip, reg, value) \
43 iowrite32(value, (chip)->rtsx->remap_addr + reg)
44 #define rtsx_readl(chip, reg) \
45 ioread32((chip)->rtsx->remap_addr + reg)
46 #define rtsx_writew(chip, reg, value) \
47 iowrite16(value, (chip)->rtsx->remap_addr + reg)
48 #define rtsx_readw(chip, reg) \
49 ioread16((chip)->rtsx->remap_addr + reg)
50 #define rtsx_writeb(chip, reg, value) \
51 iowrite8(value, (chip)->rtsx->remap_addr + reg)
52 #define rtsx_readb(chip, reg) \
53 ioread8((chip)->rtsx->remap_addr + reg)
55 #define rtsx_read_config_byte(chip, where, val) \
56 pci_read_config_byte((chip)->rtsx->pci, where, val)
58 #define rtsx_write_config_byte(chip, where, val) \
59 pci_write_config_byte((chip)->rtsx->pci, where, val)
61 #define wait_timeout_x(task_state, msecs) \
63 set_current_state((task_state)); \
64 schedule_timeout((msecs) * HZ / 1000); \
66 #define wait_timeout(msecs) wait_timeout_x(TASK_INTERRUPTIBLE, (msecs))
68 #define STATE_TRANS_NONE 0
69 #define STATE_TRANS_CMD 1
70 #define STATE_TRANS_BUF 2
71 #define STATE_TRANS_SG 3
73 #define TRANS_NOT_READY 0
74 #define TRANS_RESULT_OK 1
75 #define TRANS_RESULT_FAIL 2
77 #define SCSI_LUN(srb) ((srb)->device->lun)
86 void __iomem
*remap_addr
;
92 struct task_struct
*ctl_thread
; /* the control thread */
93 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 */
102 wait_queue_head_t delay_wait
; /* wait during scan, reset */
103 struct mutex dev_mutex
;
105 /* host reserved buffer */
107 dma_addr_t rtsx_resv_buf_addr
;
112 struct completion
*done
;
113 /* Whether interrupt handler should care card cd info */
116 struct rtsx_chip
*chip
;
119 /* Convert between rtsx_dev and the corresponding Scsi_Host */
120 static inline struct Scsi_Host
*rtsx_to_host(struct rtsx_dev
*dev
)
122 return container_of((void *)dev
, struct Scsi_Host
, hostdata
);
125 static inline struct rtsx_dev
*host_to_rtsx(struct Scsi_Host
*host
)
127 return (struct rtsx_dev
*)host
->hostdata
;
131 * The scsi_lock() and scsi_unlock() macros protect the sm_state and the
132 * single queue element srb for write access
134 #define scsi_unlock(host) spin_unlock_irq(host->host_lock)
135 #define scsi_lock(host) spin_lock_irq(host->host_lock)
137 #define lock_state(chip) spin_lock_irq(&((chip)->rtsx->reg_lock))
138 #define unlock_state(chip) spin_unlock_irq(&((chip)->rtsx->reg_lock))
140 /* struct scsi_cmnd transfer buffer access utilities */
141 enum xfer_buf_dir
{TO_XFER_BUF
, FROM_XFER_BUF
};
143 #include "rtsx_chip.h"
144 #include "rtsx_transport.h"
145 #include "rtsx_scsi.h"
146 #include "rtsx_card.h"
147 #include "rtsx_sys.h"
150 #endif /* __REALTEK_RTSX_H */