nhi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /*
  2. * Thunderbolt Cactus Ridge driver - NHI driver
  3. *
  4. * The NHI (native host interface) is the pci device that allows us to send and
  5. * receive frames from the thunderbolt bus.
  6. *
  7. * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
  8. */
  9. #include <linux/pm_runtime.h>
  10. #include <linux/slab.h>
  11. #include <linux/errno.h>
  12. #include <linux/pci.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/module.h>
  15. #include <linux/dmi.h>
  16. #include "nhi.h"
  17. #include "nhi_regs.h"
  18. #include "tb.h"
  19. #define RING_TYPE(ring) ((ring)->is_tx ? "TX ring" : "RX ring")
  20. static int ring_interrupt_index(struct tb_ring *ring)
  21. {
  22. int bit = ring->hop;
  23. if (!ring->is_tx)
  24. bit += ring->nhi->hop_count;
  25. return bit;
  26. }
  27. /**
  28. * ring_interrupt_active() - activate/deactivate interrupts for a single ring
  29. *
  30. * ring->nhi->lock must be held.
  31. */
  32. static void ring_interrupt_active(struct tb_ring *ring, bool active)
  33. {
  34. int reg = REG_RING_INTERRUPT_BASE + ring_interrupt_index(ring) / 32;
  35. int bit = ring_interrupt_index(ring) & 31;
  36. int mask = 1 << bit;
  37. u32 old, new;
  38. old = ioread32(ring->nhi->iobase + reg);
  39. if (active)
  40. new = old | mask;
  41. else
  42. new = old & ~mask;
  43. dev_info(&ring->nhi->pdev->dev,
  44. "%s interrupt at register %#x bit %d (%#x -> %#x)\n",
  45. active ? "enabling" : "disabling", reg, bit, old, new);
  46. if (new == old)
  47. dev_WARN(&ring->nhi->pdev->dev,
  48. "interrupt for %s %d is already %s\n",
  49. RING_TYPE(ring), ring->hop,
  50. active ? "enabled" : "disabled");
  51. iowrite32(new, ring->nhi->iobase + reg);
  52. }
  53. /**
  54. * nhi_disable_interrupts() - disable interrupts for all rings
  55. *
  56. * Use only during init and shutdown.
  57. */
  58. static void nhi_disable_interrupts(struct tb_nhi *nhi)
  59. {
  60. int i = 0;
  61. /* disable interrupts */
  62. for (i = 0; i < RING_INTERRUPT_REG_COUNT(nhi); i++)
  63. iowrite32(0, nhi->iobase + REG_RING_INTERRUPT_BASE + 4 * i);
  64. /* clear interrupt status bits */
  65. for (i = 0; i < RING_NOTIFY_REG_COUNT(nhi); i++)
  66. ioread32(nhi->iobase + REG_RING_NOTIFY_BASE + 4 * i);
  67. }
  68. /* ring helper methods */
  69. static void __iomem *ring_desc_base(struct tb_ring *ring)
  70. {
  71. void __iomem *io = ring->nhi->iobase;
  72. io += ring->is_tx ? REG_TX_RING_BASE : REG_RX_RING_BASE;
  73. io += ring->hop * 16;
  74. return io;
  75. }
  76. static void __iomem *ring_options_base(struct tb_ring *ring)
  77. {
  78. void __iomem *io = ring->nhi->iobase;
  79. io += ring->is_tx ? REG_TX_OPTIONS_BASE : REG_RX_OPTIONS_BASE;
  80. io += ring->hop * 32;
  81. return io;
  82. }
  83. static void ring_iowrite16desc(struct tb_ring *ring, u32 value, u32 offset)
  84. {
  85. iowrite16(value, ring_desc_base(ring) + offset);
  86. }
  87. static void ring_iowrite32desc(struct tb_ring *ring, u32 value, u32 offset)
  88. {
  89. iowrite32(value, ring_desc_base(ring) + offset);
  90. }
  91. static void ring_iowrite64desc(struct tb_ring *ring, u64 value, u32 offset)
  92. {
  93. iowrite32(value, ring_desc_base(ring) + offset);
  94. iowrite32(value >> 32, ring_desc_base(ring) + offset + 4);
  95. }
  96. static void ring_iowrite32options(struct tb_ring *ring, u32 value, u32 offset)
  97. {
  98. iowrite32(value, ring_options_base(ring) + offset);
  99. }
  100. static bool ring_full(struct tb_ring *ring)
  101. {
  102. return ((ring->head + 1) % ring->size) == ring->tail;
  103. }
  104. static bool ring_empty(struct tb_ring *ring)
  105. {
  106. return ring->head == ring->tail;
  107. }
  108. /**
  109. * ring_write_descriptors() - post frames from ring->queue to the controller
  110. *
  111. * ring->lock is held.
  112. */
  113. static void ring_write_descriptors(struct tb_ring *ring)
  114. {
  115. struct ring_frame *frame, *n;
  116. struct ring_desc *descriptor;
  117. list_for_each_entry_safe(frame, n, &ring->queue, list) {
  118. if (ring_full(ring))
  119. break;
  120. list_move_tail(&frame->list, &ring->in_flight);
  121. descriptor = &ring->descriptors[ring->head];
  122. descriptor->phys = frame->buffer_phy;
  123. descriptor->time = 0;
  124. descriptor->flags = RING_DESC_POSTED | RING_DESC_INTERRUPT;
  125. if (ring->is_tx) {
  126. descriptor->length = frame->size;
  127. descriptor->eof = frame->eof;
  128. descriptor->sof = frame->sof;
  129. }
  130. ring->head = (ring->head + 1) % ring->size;
  131. ring_iowrite16desc(ring, ring->head, ring->is_tx ? 10 : 8);
  132. }
  133. }
  134. /**
  135. * ring_work() - progress completed frames
  136. *
  137. * If the ring is shutting down then all frames are marked as canceled and
  138. * their callbacks are invoked.
  139. *
  140. * Otherwise we collect all completed frame from the ring buffer, write new
  141. * frame to the ring buffer and invoke the callbacks for the completed frames.
  142. */
  143. static void ring_work(struct work_struct *work)
  144. {
  145. struct tb_ring *ring = container_of(work, typeof(*ring), work);
  146. struct ring_frame *frame;
  147. bool canceled = false;
  148. LIST_HEAD(done);
  149. mutex_lock(&ring->lock);
  150. if (!ring->running) {
  151. /* Move all frames to done and mark them as canceled. */
  152. list_splice_tail_init(&ring->in_flight, &done);
  153. list_splice_tail_init(&ring->queue, &done);
  154. canceled = true;
  155. goto invoke_callback;
  156. }
  157. while (!ring_empty(ring)) {
  158. if (!(ring->descriptors[ring->tail].flags
  159. & RING_DESC_COMPLETED))
  160. break;
  161. frame = list_first_entry(&ring->in_flight, typeof(*frame),
  162. list);
  163. list_move_tail(&frame->list, &done);
  164. if (!ring->is_tx) {
  165. frame->size = ring->descriptors[ring->tail].length;
  166. frame->eof = ring->descriptors[ring->tail].eof;
  167. frame->sof = ring->descriptors[ring->tail].sof;
  168. frame->flags = ring->descriptors[ring->tail].flags;
  169. if (frame->sof != 0)
  170. dev_WARN(&ring->nhi->pdev->dev,
  171. "%s %d got unexpected SOF: %#x\n",
  172. RING_TYPE(ring), ring->hop,
  173. frame->sof);
  174. /*
  175. * known flags:
  176. * raw not enabled, interupt not set: 0x2=0010
  177. * raw enabled: 0xa=1010
  178. * raw not enabled: 0xb=1011
  179. * partial frame (>MAX_FRAME_SIZE): 0xe=1110
  180. */
  181. if (frame->flags != 0xa)
  182. dev_WARN(&ring->nhi->pdev->dev,
  183. "%s %d got unexpected flags: %#x\n",
  184. RING_TYPE(ring), ring->hop,
  185. frame->flags);
  186. }
  187. ring->tail = (ring->tail + 1) % ring->size;
  188. }
  189. ring_write_descriptors(ring);
  190. invoke_callback:
  191. mutex_unlock(&ring->lock); /* allow callbacks to schedule new work */
  192. while (!list_empty(&done)) {
  193. frame = list_first_entry(&done, typeof(*frame), list);
  194. /*
  195. * The callback may reenqueue or delete frame.
  196. * Do not hold on to it.
  197. */
  198. list_del_init(&frame->list);
  199. frame->callback(ring, frame, canceled);
  200. }
  201. }
  202. int __ring_enqueue(struct tb_ring *ring, struct ring_frame *frame)
  203. {
  204. int ret = 0;
  205. mutex_lock(&ring->lock);
  206. if (ring->running) {
  207. list_add_tail(&frame->list, &ring->queue);
  208. ring_write_descriptors(ring);
  209. } else {
  210. ret = -ESHUTDOWN;
  211. }
  212. mutex_unlock(&ring->lock);
  213. return ret;
  214. }
  215. static struct tb_ring *ring_alloc(struct tb_nhi *nhi, u32 hop, int size,
  216. bool transmit)
  217. {
  218. struct tb_ring *ring = NULL;
  219. dev_info(&nhi->pdev->dev, "allocating %s ring %d of size %d\n",
  220. transmit ? "TX" : "RX", hop, size);
  221. mutex_lock(&nhi->lock);
  222. if (hop >= nhi->hop_count) {
  223. dev_WARN(&nhi->pdev->dev, "invalid hop: %d\n", hop);
  224. goto err;
  225. }
  226. if (transmit && nhi->tx_rings[hop]) {
  227. dev_WARN(&nhi->pdev->dev, "TX hop %d already allocated\n", hop);
  228. goto err;
  229. } else if (!transmit && nhi->rx_rings[hop]) {
  230. dev_WARN(&nhi->pdev->dev, "RX hop %d already allocated\n", hop);
  231. goto err;
  232. }
  233. ring = kzalloc(sizeof(*ring), GFP_KERNEL);
  234. if (!ring)
  235. goto err;
  236. mutex_init(&ring->lock);
  237. INIT_LIST_HEAD(&ring->queue);
  238. INIT_LIST_HEAD(&ring->in_flight);
  239. INIT_WORK(&ring->work, ring_work);
  240. ring->nhi = nhi;
  241. ring->hop = hop;
  242. ring->is_tx = transmit;
  243. ring->size = size;
  244. ring->head = 0;
  245. ring->tail = 0;
  246. ring->running = false;
  247. ring->descriptors = dma_alloc_coherent(&ring->nhi->pdev->dev,
  248. size * sizeof(*ring->descriptors),
  249. &ring->descriptors_dma, GFP_KERNEL | __GFP_ZERO);
  250. if (!ring->descriptors)
  251. goto err;
  252. if (transmit)
  253. nhi->tx_rings[hop] = ring;
  254. else
  255. nhi->rx_rings[hop] = ring;
  256. mutex_unlock(&nhi->lock);
  257. return ring;
  258. err:
  259. if (ring)
  260. mutex_destroy(&ring->lock);
  261. kfree(ring);
  262. mutex_unlock(&nhi->lock);
  263. return NULL;
  264. }
  265. struct tb_ring *ring_alloc_tx(struct tb_nhi *nhi, int hop, int size)
  266. {
  267. return ring_alloc(nhi, hop, size, true);
  268. }
  269. struct tb_ring *ring_alloc_rx(struct tb_nhi *nhi, int hop, int size)
  270. {
  271. return ring_alloc(nhi, hop, size, false);
  272. }
  273. /**
  274. * ring_start() - enable a ring
  275. *
  276. * Must not be invoked in parallel with ring_stop().
  277. */
  278. void ring_start(struct tb_ring *ring)
  279. {
  280. mutex_lock(&ring->nhi->lock);
  281. mutex_lock(&ring->lock);
  282. if (ring->running) {
  283. dev_WARN(&ring->nhi->pdev->dev, "ring already started\n");
  284. goto err;
  285. }
  286. dev_info(&ring->nhi->pdev->dev, "starting %s %d\n",
  287. RING_TYPE(ring), ring->hop);
  288. ring_iowrite64desc(ring, ring->descriptors_dma, 0);
  289. if (ring->is_tx) {
  290. ring_iowrite32desc(ring, ring->size, 12);
  291. ring_iowrite32options(ring, 0, 4); /* time releated ? */
  292. ring_iowrite32options(ring,
  293. RING_FLAG_ENABLE | RING_FLAG_RAW, 0);
  294. } else {
  295. ring_iowrite32desc(ring,
  296. (TB_FRAME_SIZE << 16) | ring->size, 12);
  297. ring_iowrite32options(ring, 0xffffffff, 4); /* SOF EOF mask */
  298. ring_iowrite32options(ring,
  299. RING_FLAG_ENABLE | RING_FLAG_RAW, 0);
  300. }
  301. ring_interrupt_active(ring, true);
  302. ring->running = true;
  303. err:
  304. mutex_unlock(&ring->lock);
  305. mutex_unlock(&ring->nhi->lock);
  306. }
  307. /**
  308. * ring_stop() - shutdown a ring
  309. *
  310. * Must not be invoked from a callback.
  311. *
  312. * This method will disable the ring. Further calls to ring_tx/ring_rx will
  313. * return -ESHUTDOWN until ring_stop has been called.
  314. *
  315. * All enqueued frames will be canceled and their callbacks will be executed
  316. * with frame->canceled set to true (on the callback thread). This method
  317. * returns only after all callback invocations have finished.
  318. */
  319. void ring_stop(struct tb_ring *ring)
  320. {
  321. mutex_lock(&ring->nhi->lock);
  322. mutex_lock(&ring->lock);
  323. dev_info(&ring->nhi->pdev->dev, "stopping %s %d\n",
  324. RING_TYPE(ring), ring->hop);
  325. if (!ring->running) {
  326. dev_WARN(&ring->nhi->pdev->dev, "%s %d already stopped\n",
  327. RING_TYPE(ring), ring->hop);
  328. goto err;
  329. }
  330. ring_interrupt_active(ring, false);
  331. ring_iowrite32options(ring, 0, 0);
  332. ring_iowrite64desc(ring, 0, 0);
  333. ring_iowrite16desc(ring, 0, ring->is_tx ? 10 : 8);
  334. ring_iowrite32desc(ring, 0, 12);
  335. ring->head = 0;
  336. ring->tail = 0;
  337. ring->running = false;
  338. err:
  339. mutex_unlock(&ring->lock);
  340. mutex_unlock(&ring->nhi->lock);
  341. /*
  342. * schedule ring->work to invoke callbacks on all remaining frames.
  343. */
  344. schedule_work(&ring->work);
  345. flush_work(&ring->work);
  346. }
  347. /*
  348. * ring_free() - free ring
  349. *
  350. * When this method returns all invocations of ring->callback will have
  351. * finished.
  352. *
  353. * Ring must be stopped.
  354. *
  355. * Must NOT be called from ring_frame->callback!
  356. */
  357. void ring_free(struct tb_ring *ring)
  358. {
  359. mutex_lock(&ring->nhi->lock);
  360. /*
  361. * Dissociate the ring from the NHI. This also ensures that
  362. * nhi_interrupt_work cannot reschedule ring->work.
  363. */
  364. if (ring->is_tx)
  365. ring->nhi->tx_rings[ring->hop] = NULL;
  366. else
  367. ring->nhi->rx_rings[ring->hop] = NULL;
  368. if (ring->running) {
  369. dev_WARN(&ring->nhi->pdev->dev, "%s %d still running\n",
  370. RING_TYPE(ring), ring->hop);
  371. }
  372. dma_free_coherent(&ring->nhi->pdev->dev,
  373. ring->size * sizeof(*ring->descriptors),
  374. ring->descriptors, ring->descriptors_dma);
  375. ring->descriptors = NULL;
  376. ring->descriptors_dma = 0;
  377. dev_info(&ring->nhi->pdev->dev,
  378. "freeing %s %d\n",
  379. RING_TYPE(ring),
  380. ring->hop);
  381. mutex_unlock(&ring->nhi->lock);
  382. /**
  383. * ring->work can no longer be scheduled (it is scheduled only by
  384. * nhi_interrupt_work and ring_stop). Wait for it to finish before
  385. * freeing the ring.
  386. */
  387. flush_work(&ring->work);
  388. mutex_destroy(&ring->lock);
  389. kfree(ring);
  390. }
  391. static void nhi_interrupt_work(struct work_struct *work)
  392. {
  393. struct tb_nhi *nhi = container_of(work, typeof(*nhi), interrupt_work);
  394. int value = 0; /* Suppress uninitialized usage warning. */
  395. int bit;
  396. int hop = -1;
  397. int type = 0; /* current interrupt type 0: TX, 1: RX, 2: RX overflow */
  398. struct tb_ring *ring;
  399. mutex_lock(&nhi->lock);
  400. /*
  401. * Starting at REG_RING_NOTIFY_BASE there are three status bitfields
  402. * (TX, RX, RX overflow). We iterate over the bits and read a new
  403. * dwords as required. The registers are cleared on read.
  404. */
  405. for (bit = 0; bit < 3 * nhi->hop_count; bit++) {
  406. if (bit % 32 == 0)
  407. value = ioread32(nhi->iobase
  408. + REG_RING_NOTIFY_BASE
  409. + 4 * (bit / 32));
  410. if (++hop == nhi->hop_count) {
  411. hop = 0;
  412. type++;
  413. }
  414. if ((value & (1 << (bit % 32))) == 0)
  415. continue;
  416. if (type == 2) {
  417. dev_warn(&nhi->pdev->dev,
  418. "RX overflow for ring %d\n",
  419. hop);
  420. continue;
  421. }
  422. if (type == 0)
  423. ring = nhi->tx_rings[hop];
  424. else
  425. ring = nhi->rx_rings[hop];
  426. if (ring == NULL) {
  427. dev_warn(&nhi->pdev->dev,
  428. "got interrupt for inactive %s ring %d\n",
  429. type ? "RX" : "TX",
  430. hop);
  431. continue;
  432. }
  433. /* we do not check ring->running, this is done in ring->work */
  434. schedule_work(&ring->work);
  435. }
  436. mutex_unlock(&nhi->lock);
  437. }
  438. static irqreturn_t nhi_msi(int irq, void *data)
  439. {
  440. struct tb_nhi *nhi = data;
  441. schedule_work(&nhi->interrupt_work);
  442. return IRQ_HANDLED;
  443. }
  444. static int nhi_suspend_noirq(struct device *dev)
  445. {
  446. struct pci_dev *pdev = to_pci_dev(dev);
  447. struct tb *tb = pci_get_drvdata(pdev);
  448. thunderbolt_suspend(tb);
  449. return 0;
  450. }
  451. static int nhi_resume_noirq(struct device *dev)
  452. {
  453. struct pci_dev *pdev = to_pci_dev(dev);
  454. struct tb *tb = pci_get_drvdata(pdev);
  455. thunderbolt_resume(tb);
  456. return 0;
  457. }
  458. static void nhi_shutdown(struct tb_nhi *nhi)
  459. {
  460. int i;
  461. dev_info(&nhi->pdev->dev, "shutdown\n");
  462. for (i = 0; i < nhi->hop_count; i++) {
  463. if (nhi->tx_rings[i])
  464. dev_WARN(&nhi->pdev->dev,
  465. "TX ring %d is still active\n", i);
  466. if (nhi->rx_rings[i])
  467. dev_WARN(&nhi->pdev->dev,
  468. "RX ring %d is still active\n", i);
  469. }
  470. nhi_disable_interrupts(nhi);
  471. /*
  472. * We have to release the irq before calling flush_work. Otherwise an
  473. * already executing IRQ handler could call schedule_work again.
  474. */
  475. devm_free_irq(&nhi->pdev->dev, nhi->pdev->irq, nhi);
  476. flush_work(&nhi->interrupt_work);
  477. mutex_destroy(&nhi->lock);
  478. }
  479. static int nhi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  480. {
  481. struct tb_nhi *nhi;
  482. struct tb *tb;
  483. int res;
  484. res = pcim_enable_device(pdev);
  485. if (res) {
  486. dev_err(&pdev->dev, "cannot enable PCI device, aborting\n");
  487. return res;
  488. }
  489. res = pci_enable_msi(pdev);
  490. if (res) {
  491. dev_err(&pdev->dev, "cannot enable MSI, aborting\n");
  492. return res;
  493. }
  494. res = pcim_iomap_regions(pdev, 1 << 0, "thunderbolt");
  495. if (res) {
  496. dev_err(&pdev->dev, "cannot obtain PCI resources, aborting\n");
  497. return res;
  498. }
  499. nhi = devm_kzalloc(&pdev->dev, sizeof(*nhi), GFP_KERNEL);
  500. if (!nhi)
  501. return -ENOMEM;
  502. nhi->pdev = pdev;
  503. /* cannot fail - table is allocated bin pcim_iomap_regions */
  504. nhi->iobase = pcim_iomap_table(pdev)[0];
  505. nhi->hop_count = ioread32(nhi->iobase + REG_HOP_COUNT) & 0x3ff;
  506. if (nhi->hop_count != 12)
  507. dev_warn(&pdev->dev, "unexpected hop count: %d\n",
  508. nhi->hop_count);
  509. INIT_WORK(&nhi->interrupt_work, nhi_interrupt_work);
  510. nhi->tx_rings = devm_kcalloc(&pdev->dev, nhi->hop_count,
  511. sizeof(*nhi->tx_rings), GFP_KERNEL);
  512. nhi->rx_rings = devm_kcalloc(&pdev->dev, nhi->hop_count,
  513. sizeof(*nhi->rx_rings), GFP_KERNEL);
  514. if (!nhi->tx_rings || !nhi->rx_rings)
  515. return -ENOMEM;
  516. nhi_disable_interrupts(nhi); /* In case someone left them on. */
  517. res = devm_request_irq(&pdev->dev, pdev->irq, nhi_msi,
  518. IRQF_NO_SUSPEND, /* must work during _noirq */
  519. "thunderbolt", nhi);
  520. if (res) {
  521. dev_err(&pdev->dev, "request_irq failed, aborting\n");
  522. return res;
  523. }
  524. mutex_init(&nhi->lock);
  525. pci_set_master(pdev);
  526. /* magic value - clock related? */
  527. iowrite32(3906250 / 10000, nhi->iobase + 0x38c00);
  528. dev_info(&nhi->pdev->dev, "NHI initialized, starting thunderbolt\n");
  529. tb = thunderbolt_alloc_and_start(nhi);
  530. if (!tb) {
  531. /*
  532. * At this point the RX/TX rings might already have been
  533. * activated. Do a proper shutdown.
  534. */
  535. nhi_shutdown(nhi);
  536. return -EIO;
  537. }
  538. pci_set_drvdata(pdev, tb);
  539. return 0;
  540. }
  541. static void nhi_remove(struct pci_dev *pdev)
  542. {
  543. struct tb *tb = pci_get_drvdata(pdev);
  544. struct tb_nhi *nhi = tb->nhi;
  545. thunderbolt_shutdown_and_free(tb);
  546. nhi_shutdown(nhi);
  547. }
  548. /*
  549. * The tunneled pci bridges are siblings of us. Use resume_noirq to reenable
  550. * the tunnels asap. A corresponding pci quirk blocks the downstream bridges
  551. * resume_noirq until we are done.
  552. */
  553. static const struct dev_pm_ops nhi_pm_ops = {
  554. .suspend_noirq = nhi_suspend_noirq,
  555. .resume_noirq = nhi_resume_noirq,
  556. .freeze_noirq = nhi_suspend_noirq, /*
  557. * we just disable hotplug, the
  558. * pci-tunnels stay alive.
  559. */
  560. .thaw_noirq = nhi_resume_noirq,
  561. .restore_noirq = nhi_resume_noirq,
  562. };
  563. static struct pci_device_id nhi_ids[] = {
  564. /*
  565. * We have to specify class, the TB bridges use the same device and
  566. * vendor (sub)id.
  567. */
  568. {
  569. .class = PCI_CLASS_SYSTEM_OTHER << 8, .class_mask = ~0,
  570. .vendor = PCI_VENDOR_ID_INTEL, .device = 0x1547,
  571. .subvendor = 0x2222, .subdevice = 0x1111,
  572. },
  573. {
  574. .class = PCI_CLASS_SYSTEM_OTHER << 8, .class_mask = ~0,
  575. .vendor = PCI_VENDOR_ID_INTEL, .device = 0x156c,
  576. .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID,
  577. },
  578. { 0,}
  579. };
  580. MODULE_DEVICE_TABLE(pci, nhi_ids);
  581. MODULE_LICENSE("GPL");
  582. static struct pci_driver nhi_driver = {
  583. .name = "thunderbolt",
  584. .id_table = nhi_ids,
  585. .probe = nhi_probe,
  586. .remove = nhi_remove,
  587. .driver.pm = &nhi_pm_ops,
  588. };
  589. static int __init nhi_init(void)
  590. {
  591. if (!dmi_match(DMI_BOARD_VENDOR, "Apple Inc."))
  592. return -ENOSYS;
  593. return pci_register_driver(&nhi_driver);
  594. }
  595. static void __exit nhi_unload(void)
  596. {
  597. pci_unregister_driver(&nhi_driver);
  598. }
  599. module_init(nhi_init);
  600. module_exit(nhi_unload);