pci_endpoint_test.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /**
  2. * Host side test driver to test endpoint functionality
  3. *
  4. * Copyright (C) 2017 Texas Instruments
  5. * Author: Kishon Vijay Abraham I <kishon@ti.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 of
  9. * the License as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/crc32.h>
  20. #include <linux/delay.h>
  21. #include <linux/fs.h>
  22. #include <linux/io.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/miscdevice.h>
  26. #include <linux/module.h>
  27. #include <linux/mutex.h>
  28. #include <linux/random.h>
  29. #include <linux/sizes.h>
  30. #include <linux/slab.h>
  31. #include <linux/pci.h>
  32. #include <linux/pci_ids.h>
  33. #include <linux/pci_regs.h>
  34. #include <uapi/linux/pcitest.h>
  35. #define DRV_MODULE_NAME "pci-endpoint-test"
  36. #define PCI_ENDPOINT_TEST_MAGIC 0x0
  37. #define PCI_ENDPOINT_TEST_COMMAND 0x4
  38. #define COMMAND_RAISE_LEGACY_IRQ BIT(0)
  39. #define COMMAND_RAISE_MSI_IRQ BIT(1)
  40. #define MSI_NUMBER_SHIFT 2
  41. /* 6 bits for MSI number */
  42. #define COMMAND_READ BIT(8)
  43. #define COMMAND_WRITE BIT(9)
  44. #define COMMAND_COPY BIT(10)
  45. #define PCI_ENDPOINT_TEST_STATUS 0x8
  46. #define STATUS_READ_SUCCESS BIT(0)
  47. #define STATUS_READ_FAIL BIT(1)
  48. #define STATUS_WRITE_SUCCESS BIT(2)
  49. #define STATUS_WRITE_FAIL BIT(3)
  50. #define STATUS_COPY_SUCCESS BIT(4)
  51. #define STATUS_COPY_FAIL BIT(5)
  52. #define STATUS_IRQ_RAISED BIT(6)
  53. #define STATUS_SRC_ADDR_INVALID BIT(7)
  54. #define STATUS_DST_ADDR_INVALID BIT(8)
  55. #define PCI_ENDPOINT_TEST_LOWER_SRC_ADDR 0xc
  56. #define PCI_ENDPOINT_TEST_UPPER_SRC_ADDR 0x10
  57. #define PCI_ENDPOINT_TEST_LOWER_DST_ADDR 0x14
  58. #define PCI_ENDPOINT_TEST_UPPER_DST_ADDR 0x18
  59. #define PCI_ENDPOINT_TEST_SIZE 0x1c
  60. #define PCI_ENDPOINT_TEST_CHECKSUM 0x20
  61. #define K2G_IB_START_L0(n) (0x304 + (0x10 * (n)))
  62. #define K2G_IB_START_HI(n) (0x308 + (0x10 * (n)))
  63. #define is_k2g_pci_dev(pdev) ((pdev)->device == PCI_DEVICE_ID_TI_K2G)
  64. static DEFINE_IDA(pci_endpoint_test_ida);
  65. #define to_endpoint_test(priv) container_of((priv), struct pci_endpoint_test, \
  66. miscdev)
  67. static bool no_msi;
  68. module_param(no_msi, bool, 0444);
  69. MODULE_PARM_DESC(no_msi, "Disable MSI interrupt in pci_endpoint_test");
  70. enum pci_barno {
  71. BAR_0,
  72. BAR_1,
  73. BAR_2,
  74. BAR_3,
  75. BAR_4,
  76. BAR_5,
  77. };
  78. struct pci_endpoint_test {
  79. struct pci_dev *pdev;
  80. void __iomem *base;
  81. void __iomem *bar[6];
  82. struct completion irq_raised;
  83. int last_irq;
  84. int num_irqs;
  85. /* mutex to protect the ioctls */
  86. struct mutex mutex;
  87. struct miscdevice miscdev;
  88. enum pci_barno test_reg_bar;
  89. size_t alignment;
  90. };
  91. struct pci_endpoint_test_data {
  92. enum pci_barno test_reg_bar;
  93. size_t alignment;
  94. bool no_msi;
  95. };
  96. static inline u32 pci_endpoint_test_readl(struct pci_endpoint_test *test,
  97. u32 offset)
  98. {
  99. return readl(test->base + offset);
  100. }
  101. static inline void pci_endpoint_test_writel(struct pci_endpoint_test *test,
  102. u32 offset, u32 value)
  103. {
  104. writel(value, test->base + offset);
  105. }
  106. static inline u32 pci_endpoint_test_bar_readl(struct pci_endpoint_test *test,
  107. int bar, int offset)
  108. {
  109. return readl(test->bar[bar] + offset);
  110. }
  111. static inline void pci_endpoint_test_bar_writel(struct pci_endpoint_test *test,
  112. int bar, u32 offset, u32 value)
  113. {
  114. writel(value, test->bar[bar] + offset);
  115. }
  116. static irqreturn_t pci_endpoint_test_irqhandler(int irq, void *dev_id)
  117. {
  118. struct pci_endpoint_test *test = dev_id;
  119. u32 reg;
  120. reg = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS);
  121. if (reg & STATUS_IRQ_RAISED) {
  122. test->last_irq = irq;
  123. complete(&test->irq_raised);
  124. reg &= ~STATUS_IRQ_RAISED;
  125. }
  126. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS,
  127. reg);
  128. return IRQ_HANDLED;
  129. }
  130. static bool pci_endpoint_test_bar(struct pci_endpoint_test *test,
  131. enum pci_barno barno)
  132. {
  133. int j;
  134. u32 val;
  135. int size;
  136. struct pci_dev *pdev = test->pdev;
  137. if (!test->bar[barno])
  138. return false;
  139. size = pci_resource_len(pdev, barno);
  140. if (barno == test->test_reg_bar)
  141. size = 0x4;
  142. for (j = 0; j < size; j += 4)
  143. pci_endpoint_test_bar_writel(test, barno, j, 0xA0A0A0A0);
  144. for (j = 0; j < size; j += 4) {
  145. val = pci_endpoint_test_bar_readl(test, barno, j);
  146. if (val != 0xA0A0A0A0)
  147. return false;
  148. }
  149. return true;
  150. }
  151. static bool pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test)
  152. {
  153. u32 val;
  154. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
  155. COMMAND_RAISE_LEGACY_IRQ);
  156. val = wait_for_completion_timeout(&test->irq_raised,
  157. msecs_to_jiffies(1000));
  158. if (!val)
  159. return false;
  160. return true;
  161. }
  162. static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test,
  163. u8 msi_num)
  164. {
  165. u32 val;
  166. struct pci_dev *pdev = test->pdev;
  167. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
  168. msi_num << MSI_NUMBER_SHIFT |
  169. COMMAND_RAISE_MSI_IRQ);
  170. val = wait_for_completion_timeout(&test->irq_raised,
  171. msecs_to_jiffies(1000));
  172. if (!val)
  173. return false;
  174. if (test->last_irq - pdev->irq == msi_num - 1)
  175. return true;
  176. return false;
  177. }
  178. static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, size_t size)
  179. {
  180. bool ret = false;
  181. void *src_addr;
  182. void *dst_addr;
  183. dma_addr_t src_phys_addr;
  184. dma_addr_t dst_phys_addr;
  185. struct pci_dev *pdev = test->pdev;
  186. struct device *dev = &pdev->dev;
  187. void *orig_src_addr;
  188. dma_addr_t orig_src_phys_addr;
  189. void *orig_dst_addr;
  190. dma_addr_t orig_dst_phys_addr;
  191. size_t offset;
  192. size_t alignment = test->alignment;
  193. u32 src_crc32;
  194. u32 dst_crc32;
  195. orig_src_addr = dma_alloc_coherent(dev, size + alignment,
  196. &orig_src_phys_addr, GFP_KERNEL);
  197. if (!orig_src_addr) {
  198. dev_err(dev, "failed to allocate source buffer\n");
  199. ret = false;
  200. goto err;
  201. }
  202. if (alignment && !IS_ALIGNED(orig_src_phys_addr, alignment)) {
  203. src_phys_addr = PTR_ALIGN(orig_src_phys_addr, alignment);
  204. offset = src_phys_addr - orig_src_phys_addr;
  205. src_addr = orig_src_addr + offset;
  206. } else {
  207. src_phys_addr = orig_src_phys_addr;
  208. src_addr = orig_src_addr;
  209. }
  210. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_SRC_ADDR,
  211. lower_32_bits(src_phys_addr));
  212. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_SRC_ADDR,
  213. upper_32_bits(src_phys_addr));
  214. get_random_bytes(src_addr, size);
  215. src_crc32 = crc32_le(~0, src_addr, size);
  216. orig_dst_addr = dma_alloc_coherent(dev, size + alignment,
  217. &orig_dst_phys_addr, GFP_KERNEL);
  218. if (!orig_dst_addr) {
  219. dev_err(dev, "failed to allocate destination address\n");
  220. ret = false;
  221. goto err_orig_src_addr;
  222. }
  223. if (alignment && !IS_ALIGNED(orig_dst_phys_addr, alignment)) {
  224. dst_phys_addr = PTR_ALIGN(orig_dst_phys_addr, alignment);
  225. offset = dst_phys_addr - orig_dst_phys_addr;
  226. dst_addr = orig_dst_addr + offset;
  227. } else {
  228. dst_phys_addr = orig_dst_phys_addr;
  229. dst_addr = orig_dst_addr;
  230. }
  231. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR,
  232. lower_32_bits(dst_phys_addr));
  233. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR,
  234. upper_32_bits(dst_phys_addr));
  235. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE,
  236. size);
  237. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
  238. 1 << MSI_NUMBER_SHIFT | COMMAND_COPY);
  239. wait_for_completion(&test->irq_raised);
  240. dst_crc32 = crc32_le(~0, dst_addr, size);
  241. if (dst_crc32 == src_crc32)
  242. ret = true;
  243. dma_free_coherent(dev, size + alignment, orig_dst_addr,
  244. orig_dst_phys_addr);
  245. err_orig_src_addr:
  246. dma_free_coherent(dev, size + alignment, orig_src_addr,
  247. orig_src_phys_addr);
  248. err:
  249. return ret;
  250. }
  251. static bool pci_endpoint_test_write(struct pci_endpoint_test *test, size_t size)
  252. {
  253. bool ret = false;
  254. u32 reg;
  255. void *addr;
  256. dma_addr_t phys_addr;
  257. struct pci_dev *pdev = test->pdev;
  258. struct device *dev = &pdev->dev;
  259. void *orig_addr;
  260. dma_addr_t orig_phys_addr;
  261. size_t offset;
  262. size_t alignment = test->alignment;
  263. u32 crc32;
  264. orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr,
  265. GFP_KERNEL);
  266. if (!orig_addr) {
  267. dev_err(dev, "failed to allocate address\n");
  268. ret = false;
  269. goto err;
  270. }
  271. if (alignment && !IS_ALIGNED(orig_phys_addr, alignment)) {
  272. phys_addr = PTR_ALIGN(orig_phys_addr, alignment);
  273. offset = phys_addr - orig_phys_addr;
  274. addr = orig_addr + offset;
  275. } else {
  276. phys_addr = orig_phys_addr;
  277. addr = orig_addr;
  278. }
  279. get_random_bytes(addr, size);
  280. crc32 = crc32_le(~0, addr, size);
  281. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_CHECKSUM,
  282. crc32);
  283. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_SRC_ADDR,
  284. lower_32_bits(phys_addr));
  285. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_SRC_ADDR,
  286. upper_32_bits(phys_addr));
  287. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size);
  288. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
  289. 1 << MSI_NUMBER_SHIFT | COMMAND_READ);
  290. wait_for_completion(&test->irq_raised);
  291. reg = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS);
  292. if (reg & STATUS_READ_SUCCESS)
  293. ret = true;
  294. dma_free_coherent(dev, size + alignment, orig_addr, orig_phys_addr);
  295. err:
  296. return ret;
  297. }
  298. static bool pci_endpoint_test_read(struct pci_endpoint_test *test, size_t size)
  299. {
  300. bool ret = false;
  301. void *addr;
  302. dma_addr_t phys_addr;
  303. struct pci_dev *pdev = test->pdev;
  304. struct device *dev = &pdev->dev;
  305. void *orig_addr;
  306. dma_addr_t orig_phys_addr;
  307. size_t offset;
  308. size_t alignment = test->alignment;
  309. u32 crc32;
  310. orig_addr = dma_alloc_coherent(dev, size + alignment, &orig_phys_addr,
  311. GFP_KERNEL);
  312. if (!orig_addr) {
  313. dev_err(dev, "failed to allocate destination address\n");
  314. ret = false;
  315. goto err;
  316. }
  317. if (alignment && !IS_ALIGNED(orig_phys_addr, alignment)) {
  318. phys_addr = PTR_ALIGN(orig_phys_addr, alignment);
  319. offset = phys_addr - orig_phys_addr;
  320. addr = orig_addr + offset;
  321. } else {
  322. phys_addr = orig_phys_addr;
  323. addr = orig_addr;
  324. }
  325. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR,
  326. lower_32_bits(phys_addr));
  327. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR,
  328. upper_32_bits(phys_addr));
  329. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size);
  330. pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
  331. 1 << MSI_NUMBER_SHIFT | COMMAND_WRITE);
  332. wait_for_completion(&test->irq_raised);
  333. crc32 = crc32_le(~0, addr, size);
  334. if (crc32 == pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM))
  335. ret = true;
  336. dma_free_coherent(dev, size + alignment, orig_addr, orig_phys_addr);
  337. err:
  338. return ret;
  339. }
  340. static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,
  341. unsigned long arg)
  342. {
  343. int ret = -EINVAL;
  344. enum pci_barno bar;
  345. struct pci_endpoint_test *test = to_endpoint_test(file->private_data);
  346. struct pci_dev *pdev = test->pdev;
  347. mutex_lock(&test->mutex);
  348. switch (cmd) {
  349. case PCITEST_BAR:
  350. bar = arg;
  351. if (bar < 0 || bar > 5)
  352. goto ret;
  353. if (is_k2g_pci_dev(pdev) && bar == BAR_0)
  354. goto ret;
  355. ret = pci_endpoint_test_bar(test, bar);
  356. break;
  357. case PCITEST_LEGACY_IRQ:
  358. ret = pci_endpoint_test_legacy_irq(test);
  359. break;
  360. case PCITEST_MSI:
  361. ret = pci_endpoint_test_msi_irq(test, arg);
  362. break;
  363. case PCITEST_WRITE:
  364. ret = pci_endpoint_test_write(test, arg);
  365. break;
  366. case PCITEST_READ:
  367. ret = pci_endpoint_test_read(test, arg);
  368. break;
  369. case PCITEST_COPY:
  370. ret = pci_endpoint_test_copy(test, arg);
  371. break;
  372. }
  373. ret:
  374. mutex_unlock(&test->mutex);
  375. return ret;
  376. }
  377. static const struct file_operations pci_endpoint_test_fops = {
  378. .owner = THIS_MODULE,
  379. .unlocked_ioctl = pci_endpoint_test_ioctl,
  380. };
  381. static int pci_endpoint_test_k2g_init(struct pci_endpoint_test *test)
  382. {
  383. struct pci_dev *pdev = test->pdev;
  384. enum pci_barno bar;
  385. resource_size_t start;
  386. if (!test->bar[0])
  387. return -EINVAL;
  388. for (bar = BAR_1; bar <= BAR_5; bar++) {
  389. start = pci_resource_start(pdev, bar);
  390. pci_endpoint_test_bar_writel(test, BAR_0,
  391. K2G_IB_START_L0(bar - 1),
  392. lower_32_bits(start));
  393. pci_endpoint_test_bar_writel(test, BAR_0,
  394. K2G_IB_START_HI(bar - 1),
  395. upper_32_bits(start));
  396. }
  397. return 0;
  398. }
  399. static int pci_endpoint_test_probe(struct pci_dev *pdev,
  400. const struct pci_device_id *ent)
  401. {
  402. int i;
  403. int err;
  404. int irq = 0;
  405. int id;
  406. char name[20];
  407. enum pci_barno bar;
  408. void __iomem *base;
  409. struct device *dev = &pdev->dev;
  410. struct pci_endpoint_test *test;
  411. struct pci_endpoint_test_data *data;
  412. enum pci_barno test_reg_bar = BAR_0;
  413. struct miscdevice *misc_device;
  414. if (pci_is_bridge(pdev))
  415. return -ENODEV;
  416. test = devm_kzalloc(dev, sizeof(*test), GFP_KERNEL);
  417. if (!test)
  418. return -ENOMEM;
  419. test->test_reg_bar = 0;
  420. test->alignment = 0;
  421. test->pdev = pdev;
  422. data = (struct pci_endpoint_test_data *)ent->driver_data;
  423. if (data) {
  424. test_reg_bar = data->test_reg_bar;
  425. test->alignment = data->alignment;
  426. no_msi = data->no_msi;
  427. }
  428. init_completion(&test->irq_raised);
  429. mutex_init(&test->mutex);
  430. err = pci_enable_device(pdev);
  431. if (err) {
  432. dev_err(dev, "Cannot enable PCI device\n");
  433. return err;
  434. }
  435. err = pci_request_regions(pdev, DRV_MODULE_NAME);
  436. if (err) {
  437. dev_err(dev, "Cannot obtain PCI resources\n");
  438. goto err_disable_pdev;
  439. }
  440. pci_set_master(pdev);
  441. if (!no_msi) {
  442. irq = pci_enable_msi_range(pdev, 1, 32);
  443. if (irq < 0)
  444. dev_err(dev, "failed to get MSI interrupts\n");
  445. test->num_irqs = irq;
  446. }
  447. err = devm_request_irq(dev, pdev->irq, pci_endpoint_test_irqhandler,
  448. IRQF_SHARED, DRV_MODULE_NAME, test);
  449. if (err) {
  450. dev_err(dev, "failed to request irq\n");
  451. goto err_disable_msi;
  452. }
  453. for (i = 1; i < irq; i++) {
  454. err = devm_request_irq(dev, pdev->irq + i,
  455. pci_endpoint_test_irqhandler,
  456. IRQF_SHARED, DRV_MODULE_NAME, test);
  457. if (err)
  458. dev_err(dev, "failed to request irq for MSI %d\n",
  459. i + 1);
  460. }
  461. for (bar = BAR_0; bar <= BAR_5; bar++) {
  462. base = pci_ioremap_bar(pdev, bar);
  463. if (!base) {
  464. dev_err(dev, "failed to read BAR%d\n", bar);
  465. WARN_ON(bar == test_reg_bar);
  466. }
  467. test->bar[bar] = base;
  468. }
  469. test->base = test->bar[test_reg_bar];
  470. if (!test->base) {
  471. err = -ENOMEM;
  472. dev_err(dev, "Cannot perform PCI test without BAR%d\n",
  473. test_reg_bar);
  474. goto err_iounmap;
  475. }
  476. if (is_k2g_pci_dev(pdev)) {
  477. err = pci_endpoint_test_k2g_init(test);
  478. if (err)
  479. goto err_iounmap;
  480. }
  481. pci_set_drvdata(pdev, test);
  482. id = ida_simple_get(&pci_endpoint_test_ida, 0, 0, GFP_KERNEL);
  483. if (id < 0) {
  484. err = id;
  485. dev_err(dev, "unable to get id\n");
  486. goto err_iounmap;
  487. }
  488. snprintf(name, sizeof(name), DRV_MODULE_NAME ".%d", id);
  489. misc_device = &test->miscdev;
  490. misc_device->minor = MISC_DYNAMIC_MINOR;
  491. misc_device->name = kstrdup(name, GFP_KERNEL);
  492. if (!misc_device->name) {
  493. err = -ENOMEM;
  494. goto err_ida_remove;
  495. }
  496. misc_device->fops = &pci_endpoint_test_fops,
  497. err = misc_register(misc_device);
  498. if (err) {
  499. dev_err(dev, "failed to register device\n");
  500. goto err_kfree_name;
  501. }
  502. return 0;
  503. err_kfree_name:
  504. kfree(misc_device->name);
  505. err_ida_remove:
  506. ida_simple_remove(&pci_endpoint_test_ida, id);
  507. err_iounmap:
  508. for (bar = BAR_0; bar <= BAR_5; bar++) {
  509. if (test->bar[bar])
  510. pci_iounmap(pdev, test->bar[bar]);
  511. }
  512. for (i = 0; i < irq; i++)
  513. devm_free_irq(dev, pdev->irq + i, test);
  514. err_disable_msi:
  515. pci_disable_msi(pdev);
  516. pci_release_regions(pdev);
  517. err_disable_pdev:
  518. pci_disable_device(pdev);
  519. return err;
  520. }
  521. static void pci_endpoint_test_remove(struct pci_dev *pdev)
  522. {
  523. int id;
  524. int i;
  525. enum pci_barno bar;
  526. struct pci_endpoint_test *test = pci_get_drvdata(pdev);
  527. struct miscdevice *misc_device = &test->miscdev;
  528. if (sscanf(misc_device->name, DRV_MODULE_NAME ".%d", &id) != 1)
  529. return;
  530. misc_deregister(&test->miscdev);
  531. kfree(misc_device->name);
  532. ida_simple_remove(&pci_endpoint_test_ida, id);
  533. for (bar = BAR_0; bar <= BAR_5; bar++) {
  534. if (test->bar[bar])
  535. pci_iounmap(pdev, test->bar[bar]);
  536. }
  537. for (i = 0; i < test->num_irqs; i++)
  538. devm_free_irq(&pdev->dev, pdev->irq + i, test);
  539. pci_disable_msi(pdev);
  540. pci_release_regions(pdev);
  541. pci_disable_device(pdev);
  542. }
  543. static const struct pci_endpoint_test_data k2g_data = {
  544. .test_reg_bar = BAR_1,
  545. .alignment = SZ_1M,
  546. .no_msi = true,
  547. };
  548. static const struct pci_device_id pci_endpoint_test_tbl[] = {
  549. { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA74x) },
  550. { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA72x) },
  551. { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_K2G),
  552. .driver_data = (kernel_ulong_t)&k2g_data
  553. },
  554. { }
  555. };
  556. MODULE_DEVICE_TABLE(pci, pci_endpoint_test_tbl);
  557. static struct pci_driver pci_endpoint_test_driver = {
  558. .name = DRV_MODULE_NAME,
  559. .id_table = pci_endpoint_test_tbl,
  560. .probe = pci_endpoint_test_probe,
  561. .remove = pci_endpoint_test_remove,
  562. };
  563. module_pci_driver(pci_endpoint_test_driver);
  564. MODULE_DESCRIPTION("PCI ENDPOINT TEST DRIVER");
  565. MODULE_AUTHOR("Kishon Vijay Abraham I <kishon@ti.com>");
  566. MODULE_LICENSE("GPL v2");