dma.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. /*
  2. * Intel I/OAT DMA Linux driver
  3. * Copyright(c) 2004 - 2009 Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. */
  22. /*
  23. * This driver supports an Intel I/OAT DMA engine, which does asynchronous
  24. * copy operations.
  25. */
  26. #include <linux/init.h>
  27. #include <linux/module.h>
  28. #include <linux/slab.h>
  29. #include <linux/pci.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/dmaengine.h>
  32. #include <linux/delay.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/prefetch.h>
  36. #include <linux/i7300_idle.h>
  37. #include "dma.h"
  38. #include "registers.h"
  39. #include "hw.h"
  40. #include "../dmaengine.h"
  41. int ioat_pending_level = 4;
  42. module_param(ioat_pending_level, int, 0644);
  43. MODULE_PARM_DESC(ioat_pending_level,
  44. "high-water mark for pushing ioat descriptors (default: 4)");
  45. /* internal functions */
  46. static void ioat1_cleanup(struct ioat_dma_chan *ioat);
  47. static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat);
  48. /**
  49. * ioat_dma_do_interrupt - handler used for single vector interrupt mode
  50. * @irq: interrupt id
  51. * @data: interrupt data
  52. */
  53. static irqreturn_t ioat_dma_do_interrupt(int irq, void *data)
  54. {
  55. struct ioatdma_device *instance = data;
  56. struct ioat_chan_common *chan;
  57. unsigned long attnstatus;
  58. int bit;
  59. u8 intrctrl;
  60. intrctrl = readb(instance->reg_base + IOAT_INTRCTRL_OFFSET);
  61. if (!(intrctrl & IOAT_INTRCTRL_MASTER_INT_EN))
  62. return IRQ_NONE;
  63. if (!(intrctrl & IOAT_INTRCTRL_INT_STATUS)) {
  64. writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
  65. return IRQ_NONE;
  66. }
  67. attnstatus = readl(instance->reg_base + IOAT_ATTNSTATUS_OFFSET);
  68. for_each_set_bit(bit, &attnstatus, BITS_PER_LONG) {
  69. chan = ioat_chan_by_index(instance, bit);
  70. tasklet_schedule(&chan->cleanup_task);
  71. }
  72. writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
  73. return IRQ_HANDLED;
  74. }
  75. /**
  76. * ioat_dma_do_interrupt_msix - handler used for vector-per-channel interrupt mode
  77. * @irq: interrupt id
  78. * @data: interrupt data
  79. */
  80. static irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)
  81. {
  82. struct ioat_chan_common *chan = data;
  83. tasklet_schedule(&chan->cleanup_task);
  84. return IRQ_HANDLED;
  85. }
  86. /* common channel initialization */
  87. void ioat_init_channel(struct ioatdma_device *device, struct ioat_chan_common *chan, int idx)
  88. {
  89. struct dma_device *dma = &device->common;
  90. struct dma_chan *c = &chan->common;
  91. unsigned long data = (unsigned long) c;
  92. chan->device = device;
  93. chan->reg_base = device->reg_base + (0x80 * (idx + 1));
  94. spin_lock_init(&chan->cleanup_lock);
  95. chan->common.device = dma;
  96. dma_cookie_init(&chan->common);
  97. list_add_tail(&chan->common.device_node, &dma->channels);
  98. device->idx[idx] = chan;
  99. init_timer(&chan->timer);
  100. chan->timer.function = device->timer_fn;
  101. chan->timer.data = data;
  102. tasklet_init(&chan->cleanup_task, device->cleanup_fn, data);
  103. tasklet_disable(&chan->cleanup_task);
  104. }
  105. /**
  106. * ioat1_dma_enumerate_channels - find and initialize the device's channels
  107. * @device: the device to be enumerated
  108. */
  109. static int ioat1_enumerate_channels(struct ioatdma_device *device)
  110. {
  111. u8 xfercap_scale;
  112. u32 xfercap;
  113. int i;
  114. struct ioat_dma_chan *ioat;
  115. struct device *dev = &device->pdev->dev;
  116. struct dma_device *dma = &device->common;
  117. INIT_LIST_HEAD(&dma->channels);
  118. dma->chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET);
  119. dma->chancnt &= 0x1f; /* bits [4:0] valid */
  120. if (dma->chancnt > ARRAY_SIZE(device->idx)) {
  121. dev_warn(dev, "(%d) exceeds max supported channels (%zu)\n",
  122. dma->chancnt, ARRAY_SIZE(device->idx));
  123. dma->chancnt = ARRAY_SIZE(device->idx);
  124. }
  125. xfercap_scale = readb(device->reg_base + IOAT_XFERCAP_OFFSET);
  126. xfercap_scale &= 0x1f; /* bits [4:0] valid */
  127. xfercap = (xfercap_scale == 0 ? -1 : (1UL << xfercap_scale));
  128. dev_dbg(dev, "%s: xfercap = %d\n", __func__, xfercap);
  129. #ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL
  130. if (i7300_idle_platform_probe(NULL, NULL, 1) == 0)
  131. dma->chancnt--;
  132. #endif
  133. for (i = 0; i < dma->chancnt; i++) {
  134. ioat = devm_kzalloc(dev, sizeof(*ioat), GFP_KERNEL);
  135. if (!ioat)
  136. break;
  137. ioat_init_channel(device, &ioat->base, i);
  138. ioat->xfercap = xfercap;
  139. spin_lock_init(&ioat->desc_lock);
  140. INIT_LIST_HEAD(&ioat->free_desc);
  141. INIT_LIST_HEAD(&ioat->used_desc);
  142. }
  143. dma->chancnt = i;
  144. return i;
  145. }
  146. /**
  147. * ioat_dma_memcpy_issue_pending - push potentially unrecognized appended
  148. * descriptors to hw
  149. * @chan: DMA channel handle
  150. */
  151. static inline void
  152. __ioat1_dma_memcpy_issue_pending(struct ioat_dma_chan *ioat)
  153. {
  154. void __iomem *reg_base = ioat->base.reg_base;
  155. dev_dbg(to_dev(&ioat->base), "%s: pending: %d\n",
  156. __func__, ioat->pending);
  157. ioat->pending = 0;
  158. writeb(IOAT_CHANCMD_APPEND, reg_base + IOAT1_CHANCMD_OFFSET);
  159. }
  160. static void ioat1_dma_memcpy_issue_pending(struct dma_chan *chan)
  161. {
  162. struct ioat_dma_chan *ioat = to_ioat_chan(chan);
  163. if (ioat->pending > 0) {
  164. spin_lock_bh(&ioat->desc_lock);
  165. __ioat1_dma_memcpy_issue_pending(ioat);
  166. spin_unlock_bh(&ioat->desc_lock);
  167. }
  168. }
  169. /**
  170. * ioat1_reset_channel - restart a channel
  171. * @ioat: IOAT DMA channel handle
  172. */
  173. static void ioat1_reset_channel(struct ioat_dma_chan *ioat)
  174. {
  175. struct ioat_chan_common *chan = &ioat->base;
  176. void __iomem *reg_base = chan->reg_base;
  177. u32 chansts, chanerr;
  178. dev_warn(to_dev(chan), "reset\n");
  179. chanerr = readl(reg_base + IOAT_CHANERR_OFFSET);
  180. chansts = *chan->completion & IOAT_CHANSTS_STATUS;
  181. if (chanerr) {
  182. dev_err(to_dev(chan),
  183. "chan%d, CHANSTS = 0x%08x CHANERR = 0x%04x, clearing\n",
  184. chan_num(chan), chansts, chanerr);
  185. writel(chanerr, reg_base + IOAT_CHANERR_OFFSET);
  186. }
  187. /*
  188. * whack it upside the head with a reset
  189. * and wait for things to settle out.
  190. * force the pending count to a really big negative
  191. * to make sure no one forces an issue_pending
  192. * while we're waiting.
  193. */
  194. ioat->pending = INT_MIN;
  195. writeb(IOAT_CHANCMD_RESET,
  196. reg_base + IOAT_CHANCMD_OFFSET(chan->device->version));
  197. set_bit(IOAT_RESET_PENDING, &chan->state);
  198. mod_timer(&chan->timer, jiffies + RESET_DELAY);
  199. }
  200. static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx)
  201. {
  202. struct dma_chan *c = tx->chan;
  203. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  204. struct ioat_desc_sw *desc = tx_to_ioat_desc(tx);
  205. struct ioat_chan_common *chan = &ioat->base;
  206. struct ioat_desc_sw *first;
  207. struct ioat_desc_sw *chain_tail;
  208. dma_cookie_t cookie;
  209. spin_lock_bh(&ioat->desc_lock);
  210. /* cookie incr and addition to used_list must be atomic */
  211. cookie = dma_cookie_assign(tx);
  212. dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie);
  213. /* write address into NextDescriptor field of last desc in chain */
  214. first = to_ioat_desc(desc->tx_list.next);
  215. chain_tail = to_ioat_desc(ioat->used_desc.prev);
  216. /* make descriptor updates globally visible before chaining */
  217. wmb();
  218. chain_tail->hw->next = first->txd.phys;
  219. list_splice_tail_init(&desc->tx_list, &ioat->used_desc);
  220. dump_desc_dbg(ioat, chain_tail);
  221. dump_desc_dbg(ioat, first);
  222. if (!test_and_set_bit(IOAT_COMPLETION_PENDING, &chan->state))
  223. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  224. ioat->active += desc->hw->tx_cnt;
  225. ioat->pending += desc->hw->tx_cnt;
  226. if (ioat->pending >= ioat_pending_level)
  227. __ioat1_dma_memcpy_issue_pending(ioat);
  228. spin_unlock_bh(&ioat->desc_lock);
  229. return cookie;
  230. }
  231. /**
  232. * ioat_dma_alloc_descriptor - allocate and return a sw and hw descriptor pair
  233. * @ioat: the channel supplying the memory pool for the descriptors
  234. * @flags: allocation flags
  235. */
  236. static struct ioat_desc_sw *
  237. ioat_dma_alloc_descriptor(struct ioat_dma_chan *ioat, gfp_t flags)
  238. {
  239. struct ioat_dma_descriptor *desc;
  240. struct ioat_desc_sw *desc_sw;
  241. struct ioatdma_device *ioatdma_device;
  242. dma_addr_t phys;
  243. ioatdma_device = ioat->base.device;
  244. desc = pci_pool_alloc(ioatdma_device->dma_pool, flags, &phys);
  245. if (unlikely(!desc))
  246. return NULL;
  247. desc_sw = kzalloc(sizeof(*desc_sw), flags);
  248. if (unlikely(!desc_sw)) {
  249. pci_pool_free(ioatdma_device->dma_pool, desc, phys);
  250. return NULL;
  251. }
  252. memset(desc, 0, sizeof(*desc));
  253. INIT_LIST_HEAD(&desc_sw->tx_list);
  254. dma_async_tx_descriptor_init(&desc_sw->txd, &ioat->base.common);
  255. desc_sw->txd.tx_submit = ioat1_tx_submit;
  256. desc_sw->hw = desc;
  257. desc_sw->txd.phys = phys;
  258. set_desc_id(desc_sw, -1);
  259. return desc_sw;
  260. }
  261. static int ioat_initial_desc_count = 256;
  262. module_param(ioat_initial_desc_count, int, 0644);
  263. MODULE_PARM_DESC(ioat_initial_desc_count,
  264. "ioat1: initial descriptors per channel (default: 256)");
  265. /**
  266. * ioat1_dma_alloc_chan_resources - returns the number of allocated descriptors
  267. * @chan: the channel to be filled out
  268. */
  269. static int ioat1_dma_alloc_chan_resources(struct dma_chan *c)
  270. {
  271. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  272. struct ioat_chan_common *chan = &ioat->base;
  273. struct ioat_desc_sw *desc;
  274. u32 chanerr;
  275. int i;
  276. LIST_HEAD(tmp_list);
  277. /* have we already been set up? */
  278. if (!list_empty(&ioat->free_desc))
  279. return ioat->desccount;
  280. /* Setup register to interrupt and write completion status on error */
  281. writew(IOAT_CHANCTRL_RUN, chan->reg_base + IOAT_CHANCTRL_OFFSET);
  282. chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  283. if (chanerr) {
  284. dev_err(to_dev(chan), "CHANERR = %x, clearing\n", chanerr);
  285. writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
  286. }
  287. /* Allocate descriptors */
  288. for (i = 0; i < ioat_initial_desc_count; i++) {
  289. desc = ioat_dma_alloc_descriptor(ioat, GFP_KERNEL);
  290. if (!desc) {
  291. dev_err(to_dev(chan), "Only %d initial descriptors\n", i);
  292. break;
  293. }
  294. set_desc_id(desc, i);
  295. list_add_tail(&desc->node, &tmp_list);
  296. }
  297. spin_lock_bh(&ioat->desc_lock);
  298. ioat->desccount = i;
  299. list_splice(&tmp_list, &ioat->free_desc);
  300. spin_unlock_bh(&ioat->desc_lock);
  301. /* allocate a completion writeback area */
  302. /* doing 2 32bit writes to mmio since 1 64b write doesn't work */
  303. chan->completion = pci_pool_alloc(chan->device->completion_pool,
  304. GFP_KERNEL, &chan->completion_dma);
  305. memset(chan->completion, 0, sizeof(*chan->completion));
  306. writel(((u64) chan->completion_dma) & 0x00000000FFFFFFFF,
  307. chan->reg_base + IOAT_CHANCMP_OFFSET_LOW);
  308. writel(((u64) chan->completion_dma) >> 32,
  309. chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
  310. tasklet_enable(&chan->cleanup_task);
  311. ioat1_dma_start_null_desc(ioat); /* give chain to dma device */
  312. dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n",
  313. __func__, ioat->desccount);
  314. return ioat->desccount;
  315. }
  316. /**
  317. * ioat1_dma_free_chan_resources - release all the descriptors
  318. * @chan: the channel to be cleaned
  319. */
  320. static void ioat1_dma_free_chan_resources(struct dma_chan *c)
  321. {
  322. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  323. struct ioat_chan_common *chan = &ioat->base;
  324. struct ioatdma_device *ioatdma_device = chan->device;
  325. struct ioat_desc_sw *desc, *_desc;
  326. int in_use_descs = 0;
  327. /* Before freeing channel resources first check
  328. * if they have been previously allocated for this channel.
  329. */
  330. if (ioat->desccount == 0)
  331. return;
  332. tasklet_disable(&chan->cleanup_task);
  333. del_timer_sync(&chan->timer);
  334. ioat1_cleanup(ioat);
  335. /* Delay 100ms after reset to allow internal DMA logic to quiesce
  336. * before removing DMA descriptor resources.
  337. */
  338. writeb(IOAT_CHANCMD_RESET,
  339. chan->reg_base + IOAT_CHANCMD_OFFSET(chan->device->version));
  340. mdelay(100);
  341. spin_lock_bh(&ioat->desc_lock);
  342. list_for_each_entry_safe(desc, _desc, &ioat->used_desc, node) {
  343. dev_dbg(to_dev(chan), "%s: freeing %d from used list\n",
  344. __func__, desc_id(desc));
  345. dump_desc_dbg(ioat, desc);
  346. in_use_descs++;
  347. list_del(&desc->node);
  348. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  349. desc->txd.phys);
  350. kfree(desc);
  351. }
  352. list_for_each_entry_safe(desc, _desc,
  353. &ioat->free_desc, node) {
  354. list_del(&desc->node);
  355. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  356. desc->txd.phys);
  357. kfree(desc);
  358. }
  359. spin_unlock_bh(&ioat->desc_lock);
  360. pci_pool_free(ioatdma_device->completion_pool,
  361. chan->completion,
  362. chan->completion_dma);
  363. /* one is ok since we left it on there on purpose */
  364. if (in_use_descs > 1)
  365. dev_err(to_dev(chan), "Freeing %d in use descriptors!\n",
  366. in_use_descs - 1);
  367. chan->last_completion = 0;
  368. chan->completion_dma = 0;
  369. ioat->pending = 0;
  370. ioat->desccount = 0;
  371. }
  372. /**
  373. * ioat1_dma_get_next_descriptor - return the next available descriptor
  374. * @ioat: IOAT DMA channel handle
  375. *
  376. * Gets the next descriptor from the chain, and must be called with the
  377. * channel's desc_lock held. Allocates more descriptors if the channel
  378. * has run out.
  379. */
  380. static struct ioat_desc_sw *
  381. ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat)
  382. {
  383. struct ioat_desc_sw *new;
  384. if (!list_empty(&ioat->free_desc)) {
  385. new = to_ioat_desc(ioat->free_desc.next);
  386. list_del(&new->node);
  387. } else {
  388. /* try to get another desc */
  389. new = ioat_dma_alloc_descriptor(ioat, GFP_ATOMIC);
  390. if (!new) {
  391. dev_err(to_dev(&ioat->base), "alloc failed\n");
  392. return NULL;
  393. }
  394. }
  395. dev_dbg(to_dev(&ioat->base), "%s: allocated: %d\n",
  396. __func__, desc_id(new));
  397. prefetch(new->hw);
  398. return new;
  399. }
  400. static struct dma_async_tx_descriptor *
  401. ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
  402. dma_addr_t dma_src, size_t len, unsigned long flags)
  403. {
  404. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  405. struct ioat_desc_sw *desc;
  406. size_t copy;
  407. LIST_HEAD(chain);
  408. dma_addr_t src = dma_src;
  409. dma_addr_t dest = dma_dest;
  410. size_t total_len = len;
  411. struct ioat_dma_descriptor *hw = NULL;
  412. int tx_cnt = 0;
  413. spin_lock_bh(&ioat->desc_lock);
  414. desc = ioat1_dma_get_next_descriptor(ioat);
  415. do {
  416. if (!desc)
  417. break;
  418. tx_cnt++;
  419. copy = min_t(size_t, len, ioat->xfercap);
  420. hw = desc->hw;
  421. hw->size = copy;
  422. hw->ctl = 0;
  423. hw->src_addr = src;
  424. hw->dst_addr = dest;
  425. list_add_tail(&desc->node, &chain);
  426. len -= copy;
  427. dest += copy;
  428. src += copy;
  429. if (len) {
  430. struct ioat_desc_sw *next;
  431. async_tx_ack(&desc->txd);
  432. next = ioat1_dma_get_next_descriptor(ioat);
  433. hw->next = next ? next->txd.phys : 0;
  434. dump_desc_dbg(ioat, desc);
  435. desc = next;
  436. } else
  437. hw->next = 0;
  438. } while (len);
  439. if (!desc) {
  440. struct ioat_chan_common *chan = &ioat->base;
  441. dev_err(to_dev(chan),
  442. "chan%d - get_next_desc failed\n", chan_num(chan));
  443. list_splice(&chain, &ioat->free_desc);
  444. spin_unlock_bh(&ioat->desc_lock);
  445. return NULL;
  446. }
  447. spin_unlock_bh(&ioat->desc_lock);
  448. desc->txd.flags = flags;
  449. desc->len = total_len;
  450. list_splice(&chain, &desc->tx_list);
  451. hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  452. hw->ctl_f.compl_write = 1;
  453. hw->tx_cnt = tx_cnt;
  454. dump_desc_dbg(ioat, desc);
  455. return &desc->txd;
  456. }
  457. static void ioat1_cleanup_event(unsigned long data)
  458. {
  459. struct ioat_dma_chan *ioat = to_ioat_chan((void *) data);
  460. ioat1_cleanup(ioat);
  461. writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
  462. }
  463. dma_addr_t ioat_get_current_completion(struct ioat_chan_common *chan)
  464. {
  465. dma_addr_t phys_complete;
  466. u64 completion;
  467. completion = *chan->completion;
  468. phys_complete = ioat_chansts_to_addr(completion);
  469. dev_dbg(to_dev(chan), "%s: phys_complete: %#llx\n", __func__,
  470. (unsigned long long) phys_complete);
  471. if (is_ioat_halted(completion)) {
  472. u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  473. dev_err(to_dev(chan), "Channel halted, chanerr = %x\n",
  474. chanerr);
  475. /* TODO do something to salvage the situation */
  476. }
  477. return phys_complete;
  478. }
  479. bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
  480. dma_addr_t *phys_complete)
  481. {
  482. *phys_complete = ioat_get_current_completion(chan);
  483. if (*phys_complete == chan->last_completion)
  484. return false;
  485. clear_bit(IOAT_COMPLETION_ACK, &chan->state);
  486. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  487. return true;
  488. }
  489. static void __cleanup(struct ioat_dma_chan *ioat, dma_addr_t phys_complete)
  490. {
  491. struct ioat_chan_common *chan = &ioat->base;
  492. struct list_head *_desc, *n;
  493. struct dma_async_tx_descriptor *tx;
  494. dev_dbg(to_dev(chan), "%s: phys_complete: %llx\n",
  495. __func__, (unsigned long long) phys_complete);
  496. list_for_each_safe(_desc, n, &ioat->used_desc) {
  497. struct ioat_desc_sw *desc;
  498. prefetch(n);
  499. desc = list_entry(_desc, typeof(*desc), node);
  500. tx = &desc->txd;
  501. /*
  502. * Incoming DMA requests may use multiple descriptors,
  503. * due to exceeding xfercap, perhaps. If so, only the
  504. * last one will have a cookie, and require unmapping.
  505. */
  506. dump_desc_dbg(ioat, desc);
  507. if (tx->cookie) {
  508. dma_cookie_complete(tx);
  509. dma_descriptor_unmap(tx);
  510. ioat->active -= desc->hw->tx_cnt;
  511. if (tx->callback) {
  512. tx->callback(tx->callback_param);
  513. tx->callback = NULL;
  514. }
  515. }
  516. if (tx->phys != phys_complete) {
  517. /*
  518. * a completed entry, but not the last, so clean
  519. * up if the client is done with the descriptor
  520. */
  521. if (async_tx_test_ack(tx))
  522. list_move_tail(&desc->node, &ioat->free_desc);
  523. } else {
  524. /*
  525. * last used desc. Do not remove, so we can
  526. * append from it.
  527. */
  528. /* if nothing else is pending, cancel the
  529. * completion timeout
  530. */
  531. if (n == &ioat->used_desc) {
  532. dev_dbg(to_dev(chan),
  533. "%s cancel completion timeout\n",
  534. __func__);
  535. clear_bit(IOAT_COMPLETION_PENDING, &chan->state);
  536. }
  537. /* TODO check status bits? */
  538. break;
  539. }
  540. }
  541. chan->last_completion = phys_complete;
  542. }
  543. /**
  544. * ioat1_cleanup - cleanup up finished descriptors
  545. * @chan: ioat channel to be cleaned up
  546. *
  547. * To prevent lock contention we defer cleanup when the locks are
  548. * contended with a terminal timeout that forces cleanup and catches
  549. * completion notification errors.
  550. */
  551. static void ioat1_cleanup(struct ioat_dma_chan *ioat)
  552. {
  553. struct ioat_chan_common *chan = &ioat->base;
  554. dma_addr_t phys_complete;
  555. prefetch(chan->completion);
  556. if (!spin_trylock_bh(&chan->cleanup_lock))
  557. return;
  558. if (!ioat_cleanup_preamble(chan, &phys_complete)) {
  559. spin_unlock_bh(&chan->cleanup_lock);
  560. return;
  561. }
  562. if (!spin_trylock_bh(&ioat->desc_lock)) {
  563. spin_unlock_bh(&chan->cleanup_lock);
  564. return;
  565. }
  566. __cleanup(ioat, phys_complete);
  567. spin_unlock_bh(&ioat->desc_lock);
  568. spin_unlock_bh(&chan->cleanup_lock);
  569. }
  570. static void ioat1_timer_event(unsigned long data)
  571. {
  572. struct ioat_dma_chan *ioat = to_ioat_chan((void *) data);
  573. struct ioat_chan_common *chan = &ioat->base;
  574. dev_dbg(to_dev(chan), "%s: state: %lx\n", __func__, chan->state);
  575. spin_lock_bh(&chan->cleanup_lock);
  576. if (test_and_clear_bit(IOAT_RESET_PENDING, &chan->state)) {
  577. struct ioat_desc_sw *desc;
  578. spin_lock_bh(&ioat->desc_lock);
  579. /* restart active descriptors */
  580. desc = to_ioat_desc(ioat->used_desc.prev);
  581. ioat_set_chainaddr(ioat, desc->txd.phys);
  582. ioat_start(chan);
  583. ioat->pending = 0;
  584. set_bit(IOAT_COMPLETION_PENDING, &chan->state);
  585. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  586. spin_unlock_bh(&ioat->desc_lock);
  587. } else if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
  588. dma_addr_t phys_complete;
  589. spin_lock_bh(&ioat->desc_lock);
  590. /* if we haven't made progress and we have already
  591. * acknowledged a pending completion once, then be more
  592. * forceful with a restart
  593. */
  594. if (ioat_cleanup_preamble(chan, &phys_complete))
  595. __cleanup(ioat, phys_complete);
  596. else if (test_bit(IOAT_COMPLETION_ACK, &chan->state))
  597. ioat1_reset_channel(ioat);
  598. else {
  599. u64 status = ioat_chansts(chan);
  600. /* manually update the last completion address */
  601. if (ioat_chansts_to_addr(status) != 0)
  602. *chan->completion = status;
  603. set_bit(IOAT_COMPLETION_ACK, &chan->state);
  604. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  605. }
  606. spin_unlock_bh(&ioat->desc_lock);
  607. }
  608. spin_unlock_bh(&chan->cleanup_lock);
  609. }
  610. enum dma_status
  611. ioat_dma_tx_status(struct dma_chan *c, dma_cookie_t cookie,
  612. struct dma_tx_state *txstate)
  613. {
  614. struct ioat_chan_common *chan = to_chan_common(c);
  615. struct ioatdma_device *device = chan->device;
  616. enum dma_status ret;
  617. ret = dma_cookie_status(c, cookie, txstate);
  618. if (ret == DMA_SUCCESS)
  619. return ret;
  620. device->cleanup_fn((unsigned long) c);
  621. return dma_cookie_status(c, cookie, txstate);
  622. }
  623. static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat)
  624. {
  625. struct ioat_chan_common *chan = &ioat->base;
  626. struct ioat_desc_sw *desc;
  627. struct ioat_dma_descriptor *hw;
  628. spin_lock_bh(&ioat->desc_lock);
  629. desc = ioat1_dma_get_next_descriptor(ioat);
  630. if (!desc) {
  631. dev_err(to_dev(chan),
  632. "Unable to start null desc - get next desc failed\n");
  633. spin_unlock_bh(&ioat->desc_lock);
  634. return;
  635. }
  636. hw = desc->hw;
  637. hw->ctl = 0;
  638. hw->ctl_f.null = 1;
  639. hw->ctl_f.int_en = 1;
  640. hw->ctl_f.compl_write = 1;
  641. /* set size to non-zero value (channel returns error when size is 0) */
  642. hw->size = NULL_DESC_BUFFER_SIZE;
  643. hw->src_addr = 0;
  644. hw->dst_addr = 0;
  645. async_tx_ack(&desc->txd);
  646. hw->next = 0;
  647. list_add_tail(&desc->node, &ioat->used_desc);
  648. dump_desc_dbg(ioat, desc);
  649. ioat_set_chainaddr(ioat, desc->txd.phys);
  650. ioat_start(chan);
  651. spin_unlock_bh(&ioat->desc_lock);
  652. }
  653. /*
  654. * Perform a IOAT transaction to verify the HW works.
  655. */
  656. #define IOAT_TEST_SIZE 2000
  657. static void ioat_dma_test_callback(void *dma_async_param)
  658. {
  659. struct completion *cmp = dma_async_param;
  660. complete(cmp);
  661. }
  662. /**
  663. * ioat_dma_self_test - Perform a IOAT transaction to verify the HW works.
  664. * @device: device to be tested
  665. */
  666. int ioat_dma_self_test(struct ioatdma_device *device)
  667. {
  668. int i;
  669. u8 *src;
  670. u8 *dest;
  671. struct dma_device *dma = &device->common;
  672. struct device *dev = &device->pdev->dev;
  673. struct dma_chan *dma_chan;
  674. struct dma_async_tx_descriptor *tx;
  675. dma_addr_t dma_dest, dma_src;
  676. dma_cookie_t cookie;
  677. int err = 0;
  678. struct completion cmp;
  679. unsigned long tmo;
  680. unsigned long flags;
  681. src = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
  682. if (!src)
  683. return -ENOMEM;
  684. dest = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
  685. if (!dest) {
  686. kfree(src);
  687. return -ENOMEM;
  688. }
  689. /* Fill in src buffer */
  690. for (i = 0; i < IOAT_TEST_SIZE; i++)
  691. src[i] = (u8)i;
  692. /* Start copy, using first DMA channel */
  693. dma_chan = container_of(dma->channels.next, struct dma_chan,
  694. device_node);
  695. if (dma->device_alloc_chan_resources(dma_chan) < 1) {
  696. dev_err(dev, "selftest cannot allocate chan resource\n");
  697. err = -ENODEV;
  698. goto out;
  699. }
  700. dma_src = dma_map_single(dev, src, IOAT_TEST_SIZE, DMA_TO_DEVICE);
  701. dma_dest = dma_map_single(dev, dest, IOAT_TEST_SIZE, DMA_FROM_DEVICE);
  702. flags = DMA_PREP_INTERRUPT;
  703. tx = device->common.device_prep_dma_memcpy(dma_chan, dma_dest, dma_src,
  704. IOAT_TEST_SIZE, flags);
  705. if (!tx) {
  706. dev_err(dev, "Self-test prep failed, disabling\n");
  707. err = -ENODEV;
  708. goto unmap_dma;
  709. }
  710. async_tx_ack(tx);
  711. init_completion(&cmp);
  712. tx->callback = ioat_dma_test_callback;
  713. tx->callback_param = &cmp;
  714. cookie = tx->tx_submit(tx);
  715. if (cookie < 0) {
  716. dev_err(dev, "Self-test setup failed, disabling\n");
  717. err = -ENODEV;
  718. goto unmap_dma;
  719. }
  720. dma->device_issue_pending(dma_chan);
  721. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  722. if (tmo == 0 ||
  723. dma->device_tx_status(dma_chan, cookie, NULL)
  724. != DMA_SUCCESS) {
  725. dev_err(dev, "Self-test copy timed out, disabling\n");
  726. err = -ENODEV;
  727. goto unmap_dma;
  728. }
  729. if (memcmp(src, dest, IOAT_TEST_SIZE)) {
  730. dev_err(dev, "Self-test copy failed compare, disabling\n");
  731. err = -ENODEV;
  732. goto free_resources;
  733. }
  734. unmap_dma:
  735. dma_unmap_single(dev, dma_src, IOAT_TEST_SIZE, DMA_TO_DEVICE);
  736. dma_unmap_single(dev, dma_dest, IOAT_TEST_SIZE, DMA_FROM_DEVICE);
  737. free_resources:
  738. dma->device_free_chan_resources(dma_chan);
  739. out:
  740. kfree(src);
  741. kfree(dest);
  742. return err;
  743. }
  744. static char ioat_interrupt_style[32] = "msix";
  745. module_param_string(ioat_interrupt_style, ioat_interrupt_style,
  746. sizeof(ioat_interrupt_style), 0644);
  747. MODULE_PARM_DESC(ioat_interrupt_style,
  748. "set ioat interrupt style: msix (default), msi, intx");
  749. /**
  750. * ioat_dma_setup_interrupts - setup interrupt handler
  751. * @device: ioat device
  752. */
  753. int ioat_dma_setup_interrupts(struct ioatdma_device *device)
  754. {
  755. struct ioat_chan_common *chan;
  756. struct pci_dev *pdev = device->pdev;
  757. struct device *dev = &pdev->dev;
  758. struct msix_entry *msix;
  759. int i, j, msixcnt;
  760. int err = -EINVAL;
  761. u8 intrctrl = 0;
  762. if (!strcmp(ioat_interrupt_style, "msix"))
  763. goto msix;
  764. if (!strcmp(ioat_interrupt_style, "msi"))
  765. goto msi;
  766. if (!strcmp(ioat_interrupt_style, "intx"))
  767. goto intx;
  768. dev_err(dev, "invalid ioat_interrupt_style %s\n", ioat_interrupt_style);
  769. goto err_no_irq;
  770. msix:
  771. /* The number of MSI-X vectors should equal the number of channels */
  772. msixcnt = device->common.chancnt;
  773. for (i = 0; i < msixcnt; i++)
  774. device->msix_entries[i].entry = i;
  775. err = pci_enable_msix(pdev, device->msix_entries, msixcnt);
  776. if (err)
  777. goto msi;
  778. for (i = 0; i < msixcnt; i++) {
  779. msix = &device->msix_entries[i];
  780. chan = ioat_chan_by_index(device, i);
  781. err = devm_request_irq(dev, msix->vector,
  782. ioat_dma_do_interrupt_msix, 0,
  783. "ioat-msix", chan);
  784. if (err) {
  785. for (j = 0; j < i; j++) {
  786. msix = &device->msix_entries[j];
  787. chan = ioat_chan_by_index(device, j);
  788. devm_free_irq(dev, msix->vector, chan);
  789. }
  790. goto msi;
  791. }
  792. }
  793. intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL;
  794. device->irq_mode = IOAT_MSIX;
  795. goto done;
  796. msi:
  797. err = pci_enable_msi(pdev);
  798. if (err)
  799. goto intx;
  800. err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt, 0,
  801. "ioat-msi", device);
  802. if (err) {
  803. pci_disable_msi(pdev);
  804. goto intx;
  805. }
  806. device->irq_mode = IOAT_MSI;
  807. goto done;
  808. intx:
  809. err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt,
  810. IRQF_SHARED, "ioat-intx", device);
  811. if (err)
  812. goto err_no_irq;
  813. device->irq_mode = IOAT_INTX;
  814. done:
  815. if (device->intr_quirk)
  816. device->intr_quirk(device);
  817. intrctrl |= IOAT_INTRCTRL_MASTER_INT_EN;
  818. writeb(intrctrl, device->reg_base + IOAT_INTRCTRL_OFFSET);
  819. return 0;
  820. err_no_irq:
  821. /* Disable all interrupt generation */
  822. writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
  823. device->irq_mode = IOAT_NOIRQ;
  824. dev_err(dev, "no usable interrupts\n");
  825. return err;
  826. }
  827. EXPORT_SYMBOL(ioat_dma_setup_interrupts);
  828. static void ioat_disable_interrupts(struct ioatdma_device *device)
  829. {
  830. /* Disable all interrupt generation */
  831. writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
  832. }
  833. int ioat_probe(struct ioatdma_device *device)
  834. {
  835. int err = -ENODEV;
  836. struct dma_device *dma = &device->common;
  837. struct pci_dev *pdev = device->pdev;
  838. struct device *dev = &pdev->dev;
  839. /* DMA coherent memory pool for DMA descriptor allocations */
  840. device->dma_pool = pci_pool_create("dma_desc_pool", pdev,
  841. sizeof(struct ioat_dma_descriptor),
  842. 64, 0);
  843. if (!device->dma_pool) {
  844. err = -ENOMEM;
  845. goto err_dma_pool;
  846. }
  847. device->completion_pool = pci_pool_create("completion_pool", pdev,
  848. sizeof(u64), SMP_CACHE_BYTES,
  849. SMP_CACHE_BYTES);
  850. if (!device->completion_pool) {
  851. err = -ENOMEM;
  852. goto err_completion_pool;
  853. }
  854. device->enumerate_channels(device);
  855. dma_cap_set(DMA_MEMCPY, dma->cap_mask);
  856. dma->dev = &pdev->dev;
  857. if (!dma->chancnt) {
  858. dev_err(dev, "channel enumeration error\n");
  859. goto err_setup_interrupts;
  860. }
  861. err = ioat_dma_setup_interrupts(device);
  862. if (err)
  863. goto err_setup_interrupts;
  864. err = device->self_test(device);
  865. if (err)
  866. goto err_self_test;
  867. return 0;
  868. err_self_test:
  869. ioat_disable_interrupts(device);
  870. err_setup_interrupts:
  871. pci_pool_destroy(device->completion_pool);
  872. err_completion_pool:
  873. pci_pool_destroy(device->dma_pool);
  874. err_dma_pool:
  875. return err;
  876. }
  877. int ioat_register(struct ioatdma_device *device)
  878. {
  879. int err = dma_async_device_register(&device->common);
  880. if (err) {
  881. ioat_disable_interrupts(device);
  882. pci_pool_destroy(device->completion_pool);
  883. pci_pool_destroy(device->dma_pool);
  884. }
  885. return err;
  886. }
  887. /* ioat1_intr_quirk - fix up dma ctrl register to enable / disable msi */
  888. static void ioat1_intr_quirk(struct ioatdma_device *device)
  889. {
  890. struct pci_dev *pdev = device->pdev;
  891. u32 dmactrl;
  892. pci_read_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, &dmactrl);
  893. if (pdev->msi_enabled)
  894. dmactrl |= IOAT_PCI_DMACTRL_MSI_EN;
  895. else
  896. dmactrl &= ~IOAT_PCI_DMACTRL_MSI_EN;
  897. pci_write_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, dmactrl);
  898. }
  899. static ssize_t ring_size_show(struct dma_chan *c, char *page)
  900. {
  901. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  902. return sprintf(page, "%d\n", ioat->desccount);
  903. }
  904. static struct ioat_sysfs_entry ring_size_attr = __ATTR_RO(ring_size);
  905. static ssize_t ring_active_show(struct dma_chan *c, char *page)
  906. {
  907. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  908. return sprintf(page, "%d\n", ioat->active);
  909. }
  910. static struct ioat_sysfs_entry ring_active_attr = __ATTR_RO(ring_active);
  911. static ssize_t cap_show(struct dma_chan *c, char *page)
  912. {
  913. struct dma_device *dma = c->device;
  914. return sprintf(page, "copy%s%s%s%s%s\n",
  915. dma_has_cap(DMA_PQ, dma->cap_mask) ? " pq" : "",
  916. dma_has_cap(DMA_PQ_VAL, dma->cap_mask) ? " pq_val" : "",
  917. dma_has_cap(DMA_XOR, dma->cap_mask) ? " xor" : "",
  918. dma_has_cap(DMA_XOR_VAL, dma->cap_mask) ? " xor_val" : "",
  919. dma_has_cap(DMA_INTERRUPT, dma->cap_mask) ? " intr" : "");
  920. }
  921. struct ioat_sysfs_entry ioat_cap_attr = __ATTR_RO(cap);
  922. static ssize_t version_show(struct dma_chan *c, char *page)
  923. {
  924. struct dma_device *dma = c->device;
  925. struct ioatdma_device *device = to_ioatdma_device(dma);
  926. return sprintf(page, "%d.%d\n",
  927. device->version >> 4, device->version & 0xf);
  928. }
  929. struct ioat_sysfs_entry ioat_version_attr = __ATTR_RO(version);
  930. static struct attribute *ioat1_attrs[] = {
  931. &ring_size_attr.attr,
  932. &ring_active_attr.attr,
  933. &ioat_cap_attr.attr,
  934. &ioat_version_attr.attr,
  935. NULL,
  936. };
  937. static ssize_t
  938. ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
  939. {
  940. struct ioat_sysfs_entry *entry;
  941. struct ioat_chan_common *chan;
  942. entry = container_of(attr, struct ioat_sysfs_entry, attr);
  943. chan = container_of(kobj, struct ioat_chan_common, kobj);
  944. if (!entry->show)
  945. return -EIO;
  946. return entry->show(&chan->common, page);
  947. }
  948. const struct sysfs_ops ioat_sysfs_ops = {
  949. .show = ioat_attr_show,
  950. };
  951. static struct kobj_type ioat1_ktype = {
  952. .sysfs_ops = &ioat_sysfs_ops,
  953. .default_attrs = ioat1_attrs,
  954. };
  955. void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type)
  956. {
  957. struct dma_device *dma = &device->common;
  958. struct dma_chan *c;
  959. list_for_each_entry(c, &dma->channels, device_node) {
  960. struct ioat_chan_common *chan = to_chan_common(c);
  961. struct kobject *parent = &c->dev->device.kobj;
  962. int err;
  963. err = kobject_init_and_add(&chan->kobj, type, parent, "quickdata");
  964. if (err) {
  965. dev_warn(to_dev(chan),
  966. "sysfs init error (%d), continuing...\n", err);
  967. kobject_put(&chan->kobj);
  968. set_bit(IOAT_KOBJ_INIT_FAIL, &chan->state);
  969. }
  970. }
  971. }
  972. void ioat_kobject_del(struct ioatdma_device *device)
  973. {
  974. struct dma_device *dma = &device->common;
  975. struct dma_chan *c;
  976. list_for_each_entry(c, &dma->channels, device_node) {
  977. struct ioat_chan_common *chan = to_chan_common(c);
  978. if (!test_bit(IOAT_KOBJ_INIT_FAIL, &chan->state)) {
  979. kobject_del(&chan->kobj);
  980. kobject_put(&chan->kobj);
  981. }
  982. }
  983. }
  984. int ioat1_dma_probe(struct ioatdma_device *device, int dca)
  985. {
  986. struct pci_dev *pdev = device->pdev;
  987. struct dma_device *dma;
  988. int err;
  989. device->intr_quirk = ioat1_intr_quirk;
  990. device->enumerate_channels = ioat1_enumerate_channels;
  991. device->self_test = ioat_dma_self_test;
  992. device->timer_fn = ioat1_timer_event;
  993. device->cleanup_fn = ioat1_cleanup_event;
  994. dma = &device->common;
  995. dma->device_prep_dma_memcpy = ioat1_dma_prep_memcpy;
  996. dma->device_issue_pending = ioat1_dma_memcpy_issue_pending;
  997. dma->device_alloc_chan_resources = ioat1_dma_alloc_chan_resources;
  998. dma->device_free_chan_resources = ioat1_dma_free_chan_resources;
  999. dma->device_tx_status = ioat_dma_tx_status;
  1000. err = ioat_probe(device);
  1001. if (err)
  1002. return err;
  1003. ioat_set_tcp_copy_break(4096);
  1004. err = ioat_register(device);
  1005. if (err)
  1006. return err;
  1007. ioat_kobject_add(device, &ioat1_ktype);
  1008. if (dca)
  1009. device->dca = ioat_dca_init(pdev, device->reg_base);
  1010. return err;
  1011. }
  1012. void ioat_dma_remove(struct ioatdma_device *device)
  1013. {
  1014. struct dma_device *dma = &device->common;
  1015. ioat_disable_interrupts(device);
  1016. ioat_kobject_del(device);
  1017. dma_async_device_unregister(dma);
  1018. pci_pool_destroy(device->dma_pool);
  1019. pci_pool_destroy(device->completion_pool);
  1020. INIT_LIST_HEAD(&dma->channels);
  1021. }