Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * Driver for Realtek PCI-Express card reader
0004  *
0005  * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
0006  *
0007  * Author:
0008  *   Wei WANG (wei_wang@realsil.com.cn)
0009  *   Micky Ching (micky_ching@realsil.com.cn)
0010  */
0011 
0012 #ifndef __REALTEK_RTSX_H
0013 #define __REALTEK_RTSX_H
0014 
0015 #include <linux/io.h>
0016 #include <linux/bitops.h>
0017 #include <linux/delay.h>
0018 #include <linux/interrupt.h>
0019 #include <linux/kernel.h>
0020 #include <linux/module.h>
0021 #include <linux/moduleparam.h>
0022 #include <linux/slab.h>
0023 #include <linux/pci.h>
0024 #include <linux/mutex.h>
0025 #include <linux/cdrom.h>
0026 #include <linux/workqueue.h>
0027 #include <linux/timer.h>
0028 #include <linux/time64.h>
0029 
0030 #include <scsi/scsi.h>
0031 #include <scsi/scsi_cmnd.h>
0032 #include <scsi/scsi_device.h>
0033 #include <scsi/scsi_devinfo.h>
0034 #include <scsi/scsi_eh.h>
0035 #include <scsi/scsi_host.h>
0036 
0037 #define CR_DRIVER_NAME      "rts5208"
0038 
0039 /*
0040  * macros for easy use
0041  */
0042 #define rtsx_writel(chip, reg, value) \
0043     iowrite32(value, (chip)->rtsx->remap_addr + reg)
0044 #define rtsx_readl(chip, reg) \
0045     ioread32((chip)->rtsx->remap_addr + reg)
0046 #define rtsx_writew(chip, reg, value) \
0047     iowrite16(value, (chip)->rtsx->remap_addr + reg)
0048 #define rtsx_readw(chip, reg) \
0049     ioread16((chip)->rtsx->remap_addr + reg)
0050 #define rtsx_writeb(chip, reg, value) \
0051     iowrite8(value, (chip)->rtsx->remap_addr + reg)
0052 #define rtsx_readb(chip, reg) \
0053     ioread8((chip)->rtsx->remap_addr + reg)
0054 
0055 #define rtsx_read_config_byte(chip, where, val) \
0056     pci_read_config_byte((chip)->rtsx->pci, where, val)
0057 
0058 #define rtsx_write_config_byte(chip, where, val) \
0059     pci_write_config_byte((chip)->rtsx->pci, where, val)
0060 
0061 #define wait_timeout_x(task_state, msecs)   \
0062 do {                        \
0063     set_current_state((task_state));    \
0064     schedule_timeout((msecs) * HZ / 1000);  \
0065 } while (0)
0066 #define wait_timeout(msecs) wait_timeout_x(TASK_INTERRUPTIBLE, (msecs))
0067 
0068 #define STATE_TRANS_NONE    0
0069 #define STATE_TRANS_CMD     1
0070 #define STATE_TRANS_BUF     2
0071 #define STATE_TRANS_SG      3
0072 
0073 #define TRANS_NOT_READY     0
0074 #define TRANS_RESULT_OK     1
0075 #define TRANS_RESULT_FAIL   2
0076 
0077 #define SCSI_LUN(srb)       ((srb)->device->lun)
0078 
0079 struct rtsx_chip;
0080 
0081 struct rtsx_dev {
0082     struct pci_dev *pci;
0083 
0084     /* pci resources */
0085     unsigned long       addr;
0086     void __iomem        *remap_addr;
0087     int irq;
0088 
0089     /* locks */
0090     spinlock_t      reg_lock;
0091 
0092     struct task_struct  *ctl_thread;     /* the control thread   */
0093     struct task_struct  *polling_thread; /* the polling thread   */
0094 
0095     /* mutual exclusion and synchronization structures */
0096     struct completion   cmnd_ready;  /* to sleep thread on      */
0097     struct completion   control_exit;    /* control thread exit     */
0098     struct completion   polling_exit;    /* polling thread exit     */
0099     struct completion   notify;      /* thread begin/end        */
0100     struct completion   scanning_done;   /* wait for scan thread    */
0101 
0102     wait_queue_head_t   delay_wait;  /* wait during scan, reset */
0103     struct mutex        dev_mutex;
0104 
0105     /* host reserved buffer */
0106     void            *rtsx_resv_buf;
0107     dma_addr_t      rtsx_resv_buf_addr;
0108 
0109     char            trans_result;
0110     char            trans_state;
0111 
0112     struct completion   *done;
0113     /* Whether interrupt handler should care card cd info */
0114     u32         check_card_cd;
0115 
0116     struct rtsx_chip    *chip;
0117 };
0118 
0119 /* Convert between rtsx_dev and the corresponding Scsi_Host */
0120 static inline struct Scsi_Host *rtsx_to_host(struct rtsx_dev *dev)
0121 {
0122     return container_of((void *)dev, struct Scsi_Host, hostdata);
0123 }
0124 
0125 static inline struct rtsx_dev *host_to_rtsx(struct Scsi_Host *host)
0126 {
0127     return (struct rtsx_dev *)host->hostdata;
0128 }
0129 
0130 /*
0131  * The scsi_lock() and scsi_unlock() macros protect the sm_state and the
0132  * single queue element srb for write access
0133  */
0134 #define scsi_unlock(host)   spin_unlock_irq(host->host_lock)
0135 #define scsi_lock(host)     spin_lock_irq(host->host_lock)
0136 
0137 #define lock_state(chip)    spin_lock_irq(&((chip)->rtsx->reg_lock))
0138 #define unlock_state(chip)  spin_unlock_irq(&((chip)->rtsx->reg_lock))
0139 
0140 /* struct scsi_cmnd transfer buffer access utilities */
0141 enum xfer_buf_dir   {TO_XFER_BUF, FROM_XFER_BUF};
0142 
0143 #include "rtsx_chip.h"
0144 #include "rtsx_transport.h"
0145 #include "rtsx_scsi.h"
0146 #include "rtsx_card.h"
0147 #include "rtsx_sys.h"
0148 #include "general.h"
0149 
0150 #endif  /* __REALTEK_RTSX_H */