23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/sched.h>
41 #define DRIVER_VERSION "v1.10"
47 static unsigned int delay_use = 1;
55 static int ss_interval = 50;
59 static int auto_delink_en;
63 static unsigned char aspm_l0s_l1_en;
79 return "SCSI emulation for PCI-Express Mass Storage devices";
132 #define SPRINTF(args...) \
133 do { if (pos < buffer+length) pos += sprintf(pos, ## args); } while (0)
148 SPRINTF(
" Vendor: Realtek Corp.\n");
149 SPRINTF(
" Product: PCIE Card Reader\n");
157 if ((pos - buffer) < offset)
159 else if ((pos - buffer - offset) < length)
160 return pos - buffer -
offset;
175 dev_err(&dev->
pci->dev,
"Error in %s: chip->srb = %p\n",
176 __func__, chip->
srb);
182 dev_info(&dev->
pci->dev,
"Fail command during disconnect\n");
206 struct rtsx_dev *dev = host_to_rtsx(host);
214 if (chip->
srb != srb) {
299 .skip_settle_delay = 1,
306 static int rtsx_acquire_irq(
struct rtsx_dev *dev)
310 dev_info(&dev->
pci->dev,
"%s: chip->msi_en = %d, pci->irq = %d\n",
317 "rtsx: unable to grab IRQ %d, disabling device\n",
339 pci_read_config_byte(pdev, offset, &data);
385 static int rtsx_resume(
struct pci_dev *pci)
402 "%s: pci_enable_device failed, disabling device\n",
411 if (pci_enable_msi(pci) < 0)
415 if (rtsx_acquire_irq(dev) < 0) {
431 static void rtsx_shutdown(
struct pci_dev *pci)
457 static int rtsx_control_thread(
void *__dev)
461 struct Scsi_Host *host = rtsx_to_host(dev);
472 dev_info(&dev->
pci->dev,
"-- rtsx-control exiting\n");
492 dev_err(&dev->
pci->dev,
"UNKNOWN data direction\n");
499 else if (chip->
srb->device->id) {
500 dev_err(&dev->
pci->dev,
"Bad target number (%d:%d)\n",
501 chip->
srb->device->id,
502 chip->
srb->device->lun);
506 else if (chip->
srb->device->lun > chip->
max_lun) {
508 chip->
srb->device->id,
509 chip->
srb->device->lun);
528 chip->
srb->scsi_done(chip->
srb);
531 dev_err(&dev->
pci->dev,
"scsi command aborted\n");
566 static int rtsx_polling_thread(
void *__dev)
591 dev_info(&dev->
pci->dev,
"-- rtsx-polling exiting\n");
635 if (chip->
int_reg == 0xFFFFFFFF)
678 static void rtsx_release_resources(
struct rtsx_dev *dev)
686 dev_info(&dev->
pci->dev,
"-- sending exit command to thread\n");
704 if (dev->
chip->msi_en)
718 static void quiesce_and_remove_host(
struct rtsx_dev *dev)
720 struct Scsi_Host *host = rtsx_to_host(dev);
743 chip->
srb->scsi_done(dev->
chip->srb);
754 static void release_everything(
struct rtsx_dev *dev)
756 rtsx_release_resources(dev);
764 static int rtsx_scan_thread(
void *__dev)
772 "%s: waiting for device to settle before scanning\n",
782 dev_info(&dev->
pci->dev,
"%s: device scan complete\n",
791 static void rtsx_init_options(
struct rtsx_chip *chip)
798 #ifdef HW_AUTO_SWITCH_SD_BUS
901 RTSX_DEBUGP(
"Realtek PCI-E card reader detected\n");
905 dev_err(&pci->
dev,
"PCI enable device failed!\n");
911 dev_err(&pci->
dev,
"PCI request regions for %s failed!\n",
923 dev_err(&pci->
dev,
"Unable to allocate the scsi host\n");
929 dev = host_to_rtsx(host);
941 init_completion(&(dev->
notify));
962 dev_info(&pci->
dev,
"Original address: 0x%lx, remapped address: 0x%lx\n",
968 dev_err(&pci->
dev,
"alloc dma buffer fail\n");
980 rtsx_init_options(dev->
chip);
984 if (dev->
chip->msi_en) {
985 if (pci_enable_msi(pci) < 0)
986 dev->
chip->msi_en = 0;
989 if (rtsx_acquire_irq(dev) < 0) {
1007 dev_err(&pci->
dev,
"Unable to start control thread\n");
1013 err = scsi_add_host(host, &pci->
dev);
1015 dev_err(&pci->
dev,
"Unable to add the scsi host\n");
1020 th =
kthread_run(rtsx_scan_thread, dev,
"rtsx-scan");
1022 dev_err(&pci->
dev,
"Unable to start the device-scanning thread\n");
1024 quiesce_and_remove_host(dev);
1030 th =
kthread_run(rtsx_polling_thread, dev,
"rtsx-polling");
1032 dev_err(&pci->
dev,
"Unable to start the device-polling thread\n");
1033 quiesce_and_remove_host(dev);
1039 pci_set_drvdata(pci, dev);
1046 release_everything(dev);
1058 quiesce_and_remove_host(dev);
1059 release_everything(dev);
1061 pci_set_drvdata(pci,
NULL);
1077 .id_table = rtsx_ids,
1078 .probe = rtsx_probe,
1081 .suspend = rtsx_suspend,
1082 .resume = rtsx_resume,
1084 .shutdown = rtsx_shutdown,
1087 static int __init rtsx_init(
void)
1089 pr_info(
"Initializing Realtek PCIE storage driver...\n");
1091 return pci_register_driver(&driver);
1094 static void __exit rtsx_exit(
void)
1096 pr_info(
"rtsx_exit() called\n");