dma.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  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/pci.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/dmaengine.h>
  31. #include <linux/delay.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/workqueue.h>
  34. #include <linux/i7300_idle.h>
  35. #include "dma.h"
  36. #include "registers.h"
  37. #include "hw.h"
  38. int ioat_pending_level = 4;
  39. module_param(ioat_pending_level, int, 0644);
  40. MODULE_PARM_DESC(ioat_pending_level,
  41. "high-water mark for pushing ioat descriptors (default: 4)");
  42. /* internal functions */
  43. static void ioat1_cleanup(struct ioat_dma_chan *ioat);
  44. static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat);
  45. /**
  46. * ioat_dma_do_interrupt - handler used for single vector interrupt mode
  47. * @irq: interrupt id
  48. * @data: interrupt data
  49. */
  50. static irqreturn_t ioat_dma_do_interrupt(int irq, void *data)
  51. {
  52. struct ioatdma_device *instance = data;
  53. struct ioat_chan_common *chan;
  54. unsigned long attnstatus;
  55. int bit;
  56. u8 intrctrl;
  57. intrctrl = readb(instance->reg_base + IOAT_INTRCTRL_OFFSET);
  58. if (!(intrctrl & IOAT_INTRCTRL_MASTER_INT_EN))
  59. return IRQ_NONE;
  60. if (!(intrctrl & IOAT_INTRCTRL_INT_STATUS)) {
  61. writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
  62. return IRQ_NONE;
  63. }
  64. attnstatus = readl(instance->reg_base + IOAT_ATTNSTATUS_OFFSET);
  65. for_each_bit(bit, &attnstatus, BITS_PER_LONG) {
  66. chan = ioat_chan_by_index(instance, bit);
  67. tasklet_schedule(&chan->cleanup_task);
  68. }
  69. writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
  70. return IRQ_HANDLED;
  71. }
  72. /**
  73. * ioat_dma_do_interrupt_msix - handler used for vector-per-channel interrupt mode
  74. * @irq: interrupt id
  75. * @data: interrupt data
  76. */
  77. static irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)
  78. {
  79. struct ioat_chan_common *chan = data;
  80. tasklet_schedule(&chan->cleanup_task);
  81. return IRQ_HANDLED;
  82. }
  83. static void ioat1_cleanup_tasklet(unsigned long data);
  84. /* common channel initialization */
  85. void ioat_init_channel(struct ioatdma_device *device,
  86. struct ioat_chan_common *chan, int idx,
  87. work_func_t work_fn, void (*tasklet)(unsigned long),
  88. unsigned long tasklet_data)
  89. {
  90. struct dma_device *dma = &device->common;
  91. chan->device = device;
  92. chan->reg_base = device->reg_base + (0x80 * (idx + 1));
  93. INIT_DELAYED_WORK(&chan->work, work_fn);
  94. spin_lock_init(&chan->cleanup_lock);
  95. chan->common.device = dma;
  96. list_add_tail(&chan->common.device_node, &dma->channels);
  97. device->idx[idx] = chan;
  98. tasklet_init(&chan->cleanup_task, tasklet, tasklet_data);
  99. tasklet_disable(&chan->cleanup_task);
  100. }
  101. static void ioat1_reset_part2(struct work_struct *work);
  102. /**
  103. * ioat1_dma_enumerate_channels - find and initialize the device's channels
  104. * @device: the device to be enumerated
  105. */
  106. static int ioat1_enumerate_channels(struct ioatdma_device *device)
  107. {
  108. u8 xfercap_scale;
  109. u32 xfercap;
  110. int i;
  111. struct ioat_dma_chan *ioat;
  112. struct device *dev = &device->pdev->dev;
  113. struct dma_device *dma = &device->common;
  114. INIT_LIST_HEAD(&dma->channels);
  115. dma->chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET);
  116. dma->chancnt &= 0x1f; /* bits [4:0] valid */
  117. if (dma->chancnt > ARRAY_SIZE(device->idx)) {
  118. dev_warn(dev, "(%d) exceeds max supported channels (%zu)\n",
  119. dma->chancnt, ARRAY_SIZE(device->idx));
  120. dma->chancnt = ARRAY_SIZE(device->idx);
  121. }
  122. xfercap_scale = readb(device->reg_base + IOAT_XFERCAP_OFFSET);
  123. xfercap_scale &= 0x1f; /* bits [4:0] valid */
  124. xfercap = (xfercap_scale == 0 ? -1 : (1UL << xfercap_scale));
  125. dev_dbg(dev, "%s: xfercap = %d\n", __func__, xfercap);
  126. #ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL
  127. if (i7300_idle_platform_probe(NULL, NULL, 1) == 0)
  128. dma->chancnt--;
  129. #endif
  130. for (i = 0; i < dma->chancnt; i++) {
  131. ioat = devm_kzalloc(dev, sizeof(*ioat), GFP_KERNEL);
  132. if (!ioat)
  133. break;
  134. ioat_init_channel(device, &ioat->base, i,
  135. ioat1_reset_part2,
  136. ioat1_cleanup_tasklet,
  137. (unsigned long) ioat);
  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_part2 - reinit the channel after a reset
  171. */
  172. static void ioat1_reset_part2(struct work_struct *work)
  173. {
  174. struct ioat_chan_common *chan;
  175. struct ioat_dma_chan *ioat;
  176. struct ioat_desc_sw *desc;
  177. int dmacount;
  178. bool start_null = false;
  179. chan = container_of(work, struct ioat_chan_common, work.work);
  180. ioat = container_of(chan, struct ioat_dma_chan, base);
  181. spin_lock_bh(&chan->cleanup_lock);
  182. spin_lock_bh(&ioat->desc_lock);
  183. *chan->completion = 0;
  184. ioat->pending = 0;
  185. /* count the descriptors waiting */
  186. dmacount = 0;
  187. if (ioat->used_desc.prev) {
  188. desc = to_ioat_desc(ioat->used_desc.prev);
  189. do {
  190. dmacount++;
  191. desc = to_ioat_desc(desc->node.next);
  192. } while (&desc->node != ioat->used_desc.next);
  193. }
  194. if (dmacount) {
  195. /*
  196. * write the new starting descriptor address
  197. * this puts channel engine into ARMED state
  198. */
  199. desc = to_ioat_desc(ioat->used_desc.prev);
  200. writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF,
  201. chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW);
  202. writel(((u64) desc->txd.phys) >> 32,
  203. chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH);
  204. writeb(IOAT_CHANCMD_START, chan->reg_base
  205. + IOAT_CHANCMD_OFFSET(chan->device->version));
  206. } else
  207. start_null = true;
  208. spin_unlock_bh(&ioat->desc_lock);
  209. spin_unlock_bh(&chan->cleanup_lock);
  210. dev_err(to_dev(chan),
  211. "chan%d reset - %d descs waiting, %d total desc\n",
  212. chan_num(chan), dmacount, ioat->desccount);
  213. if (start_null)
  214. ioat1_dma_start_null_desc(ioat);
  215. }
  216. /**
  217. * ioat1_reset_channel - restart a channel
  218. * @ioat: IOAT DMA channel handle
  219. */
  220. static void ioat1_reset_channel(struct ioat_dma_chan *ioat)
  221. {
  222. struct ioat_chan_common *chan = &ioat->base;
  223. void __iomem *reg_base = chan->reg_base;
  224. u32 chansts, chanerr;
  225. if (!ioat->used_desc.prev)
  226. return;
  227. dev_dbg(to_dev(chan), "%s\n", __func__);
  228. chanerr = readl(reg_base + IOAT_CHANERR_OFFSET);
  229. chansts = *chan->completion & IOAT_CHANSTS_DMA_TRANSFER_STATUS;
  230. if (chanerr) {
  231. dev_err(to_dev(chan),
  232. "chan%d, CHANSTS = 0x%08x CHANERR = 0x%04x, clearing\n",
  233. chan_num(chan), chansts, chanerr);
  234. writel(chanerr, reg_base + IOAT_CHANERR_OFFSET);
  235. }
  236. /*
  237. * whack it upside the head with a reset
  238. * and wait for things to settle out.
  239. * force the pending count to a really big negative
  240. * to make sure no one forces an issue_pending
  241. * while we're waiting.
  242. */
  243. spin_lock_bh(&ioat->desc_lock);
  244. ioat->pending = INT_MIN;
  245. writeb(IOAT_CHANCMD_RESET,
  246. reg_base + IOAT_CHANCMD_OFFSET(chan->device->version));
  247. spin_unlock_bh(&ioat->desc_lock);
  248. /* schedule the 2nd half instead of sleeping a long time */
  249. schedule_delayed_work(&chan->work, RESET_DELAY);
  250. }
  251. /**
  252. * ioat1_chan_watchdog - watch for stuck channels
  253. */
  254. static void ioat1_chan_watchdog(struct work_struct *work)
  255. {
  256. struct ioatdma_device *device =
  257. container_of(work, struct ioatdma_device, work.work);
  258. struct ioat_dma_chan *ioat;
  259. struct ioat_chan_common *chan;
  260. int i;
  261. u64 completion;
  262. u32 completion_low;
  263. unsigned long compl_desc_addr_hw;
  264. for (i = 0; i < device->common.chancnt; i++) {
  265. chan = ioat_chan_by_index(device, i);
  266. ioat = container_of(chan, struct ioat_dma_chan, base);
  267. if (/* have we started processing anything yet */
  268. chan->last_completion
  269. /* have we completed any since last watchdog cycle? */
  270. && (chan->last_completion == chan->watchdog_completion)
  271. /* has TCP stuck on one cookie since last watchdog? */
  272. && (chan->watchdog_tcp_cookie == chan->watchdog_last_tcp_cookie)
  273. && (chan->watchdog_tcp_cookie != chan->completed_cookie)
  274. /* is there something in the chain to be processed? */
  275. /* CB1 chain always has at least the last one processed */
  276. && (ioat->used_desc.prev != ioat->used_desc.next)
  277. && ioat->pending == 0) {
  278. /*
  279. * check CHANSTS register for completed
  280. * descriptor address.
  281. * if it is different than completion writeback,
  282. * it is not zero
  283. * and it has changed since the last watchdog
  284. * we can assume that channel
  285. * is still working correctly
  286. * and the problem is in completion writeback.
  287. * update completion writeback
  288. * with actual CHANSTS value
  289. * else
  290. * try resetting the channel
  291. */
  292. /* we need to read the low address first as this
  293. * causes the chipset to latch the upper bits
  294. * for the subsequent read
  295. */
  296. completion_low = readl(chan->reg_base +
  297. IOAT_CHANSTS_OFFSET_LOW(chan->device->version));
  298. completion = readl(chan->reg_base +
  299. IOAT_CHANSTS_OFFSET_HIGH(chan->device->version));
  300. completion <<= 32;
  301. completion |= completion_low;
  302. compl_desc_addr_hw = completion &
  303. IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR;
  304. if ((compl_desc_addr_hw != 0)
  305. && (compl_desc_addr_hw != chan->watchdog_completion)
  306. && (compl_desc_addr_hw != chan->last_compl_desc_addr_hw)) {
  307. chan->last_compl_desc_addr_hw = compl_desc_addr_hw;
  308. *chan->completion = completion;
  309. } else {
  310. ioat1_reset_channel(ioat);
  311. chan->watchdog_completion = 0;
  312. chan->last_compl_desc_addr_hw = 0;
  313. }
  314. } else {
  315. chan->last_compl_desc_addr_hw = 0;
  316. chan->watchdog_completion = chan->last_completion;
  317. }
  318. chan->watchdog_last_tcp_cookie = chan->watchdog_tcp_cookie;
  319. }
  320. schedule_delayed_work(&device->work, WATCHDOG_DELAY);
  321. }
  322. static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx)
  323. {
  324. struct dma_chan *c = tx->chan;
  325. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  326. struct ioat_desc_sw *desc = tx_to_ioat_desc(tx);
  327. struct ioat_desc_sw *first;
  328. struct ioat_desc_sw *chain_tail;
  329. dma_cookie_t cookie;
  330. spin_lock_bh(&ioat->desc_lock);
  331. /* cookie incr and addition to used_list must be atomic */
  332. cookie = c->cookie;
  333. cookie++;
  334. if (cookie < 0)
  335. cookie = 1;
  336. c->cookie = cookie;
  337. tx->cookie = cookie;
  338. dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie);
  339. /* write address into NextDescriptor field of last desc in chain */
  340. first = to_ioat_desc(tx->tx_list.next);
  341. chain_tail = to_ioat_desc(ioat->used_desc.prev);
  342. /* make descriptor updates globally visible before chaining */
  343. wmb();
  344. chain_tail->hw->next = first->txd.phys;
  345. list_splice_tail_init(&tx->tx_list, &ioat->used_desc);
  346. dump_desc_dbg(ioat, chain_tail);
  347. dump_desc_dbg(ioat, first);
  348. ioat->pending += desc->tx_cnt;
  349. if (ioat->pending >= ioat_pending_level)
  350. __ioat1_dma_memcpy_issue_pending(ioat);
  351. spin_unlock_bh(&ioat->desc_lock);
  352. return cookie;
  353. }
  354. /**
  355. * ioat_dma_alloc_descriptor - allocate and return a sw and hw descriptor pair
  356. * @ioat: the channel supplying the memory pool for the descriptors
  357. * @flags: allocation flags
  358. */
  359. static struct ioat_desc_sw *
  360. ioat_dma_alloc_descriptor(struct ioat_dma_chan *ioat, gfp_t flags)
  361. {
  362. struct ioat_dma_descriptor *desc;
  363. struct ioat_desc_sw *desc_sw;
  364. struct ioatdma_device *ioatdma_device;
  365. dma_addr_t phys;
  366. ioatdma_device = ioat->base.device;
  367. desc = pci_pool_alloc(ioatdma_device->dma_pool, flags, &phys);
  368. if (unlikely(!desc))
  369. return NULL;
  370. desc_sw = kzalloc(sizeof(*desc_sw), flags);
  371. if (unlikely(!desc_sw)) {
  372. pci_pool_free(ioatdma_device->dma_pool, desc, phys);
  373. return NULL;
  374. }
  375. memset(desc, 0, sizeof(*desc));
  376. dma_async_tx_descriptor_init(&desc_sw->txd, &ioat->base.common);
  377. desc_sw->txd.tx_submit = ioat1_tx_submit;
  378. desc_sw->hw = desc;
  379. desc_sw->txd.phys = phys;
  380. set_desc_id(desc_sw, -1);
  381. return desc_sw;
  382. }
  383. static int ioat_initial_desc_count = 256;
  384. module_param(ioat_initial_desc_count, int, 0644);
  385. MODULE_PARM_DESC(ioat_initial_desc_count,
  386. "ioat1: initial descriptors per channel (default: 256)");
  387. /**
  388. * ioat1_dma_alloc_chan_resources - returns the number of allocated descriptors
  389. * @chan: the channel to be filled out
  390. */
  391. static int ioat1_dma_alloc_chan_resources(struct dma_chan *c)
  392. {
  393. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  394. struct ioat_chan_common *chan = &ioat->base;
  395. struct ioat_desc_sw *desc;
  396. u16 chanctrl;
  397. u32 chanerr;
  398. int i;
  399. LIST_HEAD(tmp_list);
  400. /* have we already been set up? */
  401. if (!list_empty(&ioat->free_desc))
  402. return ioat->desccount;
  403. /* Setup register to interrupt and write completion status on error */
  404. chanctrl = IOAT_CHANCTRL_ERR_INT_EN |
  405. IOAT_CHANCTRL_ANY_ERR_ABORT_EN |
  406. IOAT_CHANCTRL_ERR_COMPLETION_EN;
  407. writew(chanctrl, chan->reg_base + IOAT_CHANCTRL_OFFSET);
  408. chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  409. if (chanerr) {
  410. dev_err(to_dev(chan), "CHANERR = %x, clearing\n", chanerr);
  411. writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
  412. }
  413. /* Allocate descriptors */
  414. for (i = 0; i < ioat_initial_desc_count; i++) {
  415. desc = ioat_dma_alloc_descriptor(ioat, GFP_KERNEL);
  416. if (!desc) {
  417. dev_err(to_dev(chan), "Only %d initial descriptors\n", i);
  418. break;
  419. }
  420. set_desc_id(desc, i);
  421. list_add_tail(&desc->node, &tmp_list);
  422. }
  423. spin_lock_bh(&ioat->desc_lock);
  424. ioat->desccount = i;
  425. list_splice(&tmp_list, &ioat->free_desc);
  426. spin_unlock_bh(&ioat->desc_lock);
  427. /* allocate a completion writeback area */
  428. /* doing 2 32bit writes to mmio since 1 64b write doesn't work */
  429. chan->completion = pci_pool_alloc(chan->device->completion_pool,
  430. GFP_KERNEL, &chan->completion_dma);
  431. memset(chan->completion, 0, sizeof(*chan->completion));
  432. writel(((u64) chan->completion_dma) & 0x00000000FFFFFFFF,
  433. chan->reg_base + IOAT_CHANCMP_OFFSET_LOW);
  434. writel(((u64) chan->completion_dma) >> 32,
  435. chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
  436. tasklet_enable(&chan->cleanup_task);
  437. ioat1_dma_start_null_desc(ioat); /* give chain to dma device */
  438. dev_dbg(to_dev(chan), "%s: allocated %d descriptors\n",
  439. __func__, ioat->desccount);
  440. return ioat->desccount;
  441. }
  442. /**
  443. * ioat1_dma_free_chan_resources - release all the descriptors
  444. * @chan: the channel to be cleaned
  445. */
  446. static void ioat1_dma_free_chan_resources(struct dma_chan *c)
  447. {
  448. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  449. struct ioat_chan_common *chan = &ioat->base;
  450. struct ioatdma_device *ioatdma_device = chan->device;
  451. struct ioat_desc_sw *desc, *_desc;
  452. int in_use_descs = 0;
  453. /* Before freeing channel resources first check
  454. * if they have been previously allocated for this channel.
  455. */
  456. if (ioat->desccount == 0)
  457. return;
  458. tasklet_disable(&chan->cleanup_task);
  459. ioat1_cleanup(ioat);
  460. /* Delay 100ms after reset to allow internal DMA logic to quiesce
  461. * before removing DMA descriptor resources.
  462. */
  463. writeb(IOAT_CHANCMD_RESET,
  464. chan->reg_base + IOAT_CHANCMD_OFFSET(chan->device->version));
  465. mdelay(100);
  466. spin_lock_bh(&ioat->desc_lock);
  467. list_for_each_entry_safe(desc, _desc, &ioat->used_desc, node) {
  468. dev_dbg(to_dev(chan), "%s: freeing %d from used list\n",
  469. __func__, desc_id(desc));
  470. dump_desc_dbg(ioat, desc);
  471. in_use_descs++;
  472. list_del(&desc->node);
  473. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  474. desc->txd.phys);
  475. kfree(desc);
  476. }
  477. list_for_each_entry_safe(desc, _desc,
  478. &ioat->free_desc, node) {
  479. list_del(&desc->node);
  480. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  481. desc->txd.phys);
  482. kfree(desc);
  483. }
  484. spin_unlock_bh(&ioat->desc_lock);
  485. pci_pool_free(ioatdma_device->completion_pool,
  486. chan->completion,
  487. chan->completion_dma);
  488. /* one is ok since we left it on there on purpose */
  489. if (in_use_descs > 1)
  490. dev_err(to_dev(chan), "Freeing %d in use descriptors!\n",
  491. in_use_descs - 1);
  492. chan->last_completion = 0;
  493. chan->completion_dma = 0;
  494. chan->watchdog_completion = 0;
  495. chan->last_compl_desc_addr_hw = 0;
  496. chan->watchdog_tcp_cookie = chan->watchdog_last_tcp_cookie = 0;
  497. ioat->pending = 0;
  498. ioat->desccount = 0;
  499. }
  500. /**
  501. * ioat1_dma_get_next_descriptor - return the next available descriptor
  502. * @ioat: IOAT DMA channel handle
  503. *
  504. * Gets the next descriptor from the chain, and must be called with the
  505. * channel's desc_lock held. Allocates more descriptors if the channel
  506. * has run out.
  507. */
  508. static struct ioat_desc_sw *
  509. ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat)
  510. {
  511. struct ioat_desc_sw *new;
  512. if (!list_empty(&ioat->free_desc)) {
  513. new = to_ioat_desc(ioat->free_desc.next);
  514. list_del(&new->node);
  515. } else {
  516. /* try to get another desc */
  517. new = ioat_dma_alloc_descriptor(ioat, GFP_ATOMIC);
  518. if (!new) {
  519. dev_err(to_dev(&ioat->base), "alloc failed\n");
  520. return NULL;
  521. }
  522. }
  523. dev_dbg(to_dev(&ioat->base), "%s: allocated: %d\n",
  524. __func__, desc_id(new));
  525. prefetch(new->hw);
  526. return new;
  527. }
  528. static struct dma_async_tx_descriptor *
  529. ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
  530. dma_addr_t dma_src, size_t len, unsigned long flags)
  531. {
  532. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  533. struct ioat_desc_sw *desc;
  534. size_t copy;
  535. LIST_HEAD(chain);
  536. dma_addr_t src = dma_src;
  537. dma_addr_t dest = dma_dest;
  538. size_t total_len = len;
  539. struct ioat_dma_descriptor *hw = NULL;
  540. int tx_cnt = 0;
  541. spin_lock_bh(&ioat->desc_lock);
  542. desc = ioat1_dma_get_next_descriptor(ioat);
  543. do {
  544. if (!desc)
  545. break;
  546. tx_cnt++;
  547. copy = min_t(size_t, len, ioat->xfercap);
  548. hw = desc->hw;
  549. hw->size = copy;
  550. hw->ctl = 0;
  551. hw->src_addr = src;
  552. hw->dst_addr = dest;
  553. list_add_tail(&desc->node, &chain);
  554. len -= copy;
  555. dest += copy;
  556. src += copy;
  557. if (len) {
  558. struct ioat_desc_sw *next;
  559. async_tx_ack(&desc->txd);
  560. next = ioat1_dma_get_next_descriptor(ioat);
  561. hw->next = next ? next->txd.phys : 0;
  562. dump_desc_dbg(ioat, desc);
  563. desc = next;
  564. } else
  565. hw->next = 0;
  566. } while (len);
  567. if (!desc) {
  568. struct ioat_chan_common *chan = &ioat->base;
  569. dev_err(to_dev(chan),
  570. "chan%d - get_next_desc failed\n", chan_num(chan));
  571. list_splice(&chain, &ioat->free_desc);
  572. spin_unlock_bh(&ioat->desc_lock);
  573. return NULL;
  574. }
  575. spin_unlock_bh(&ioat->desc_lock);
  576. desc->txd.flags = flags;
  577. desc->tx_cnt = tx_cnt;
  578. desc->len = total_len;
  579. list_splice(&chain, &desc->txd.tx_list);
  580. hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  581. hw->ctl_f.compl_write = 1;
  582. dump_desc_dbg(ioat, desc);
  583. return &desc->txd;
  584. }
  585. static void ioat1_cleanup_tasklet(unsigned long data)
  586. {
  587. struct ioat_dma_chan *chan = (void *)data;
  588. ioat1_cleanup(chan);
  589. writew(IOAT_CHANCTRL_INT_DISABLE,
  590. chan->base.reg_base + IOAT_CHANCTRL_OFFSET);
  591. }
  592. static void ioat_unmap(struct pci_dev *pdev, dma_addr_t addr, size_t len,
  593. int direction, enum dma_ctrl_flags flags, bool dst)
  594. {
  595. if ((dst && (flags & DMA_COMPL_DEST_UNMAP_SINGLE)) ||
  596. (!dst && (flags & DMA_COMPL_SRC_UNMAP_SINGLE)))
  597. pci_unmap_single(pdev, addr, len, direction);
  598. else
  599. pci_unmap_page(pdev, addr, len, direction);
  600. }
  601. void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags,
  602. size_t len, struct ioat_dma_descriptor *hw)
  603. {
  604. struct pci_dev *pdev = chan->device->pdev;
  605. size_t offset = len - hw->size;
  606. if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
  607. ioat_unmap(pdev, hw->dst_addr - offset, len,
  608. PCI_DMA_FROMDEVICE, flags, 1);
  609. if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP))
  610. ioat_unmap(pdev, hw->src_addr - offset, len,
  611. PCI_DMA_TODEVICE, flags, 0);
  612. }
  613. unsigned long ioat_get_current_completion(struct ioat_chan_common *chan)
  614. {
  615. unsigned long phys_complete;
  616. u64 completion;
  617. completion = *chan->completion;
  618. phys_complete = completion & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR;
  619. dev_dbg(to_dev(chan), "%s: phys_complete: %#llx\n", __func__,
  620. (unsigned long long) phys_complete);
  621. if ((completion & IOAT_CHANSTS_DMA_TRANSFER_STATUS) ==
  622. IOAT_CHANSTS_DMA_TRANSFER_STATUS_HALTED) {
  623. dev_err(to_dev(chan), "Channel halted, chanerr = %x\n",
  624. readl(chan->reg_base + IOAT_CHANERR_OFFSET));
  625. /* TODO do something to salvage the situation */
  626. }
  627. return phys_complete;
  628. }
  629. /**
  630. * ioat1_cleanup - cleanup up finished descriptors
  631. * @chan: ioat channel to be cleaned up
  632. */
  633. static void ioat1_cleanup(struct ioat_dma_chan *ioat)
  634. {
  635. struct ioat_chan_common *chan = &ioat->base;
  636. unsigned long phys_complete;
  637. struct ioat_desc_sw *desc, *_desc;
  638. dma_cookie_t cookie = 0;
  639. struct dma_async_tx_descriptor *tx;
  640. prefetch(chan->completion);
  641. if (!spin_trylock_bh(&chan->cleanup_lock))
  642. return;
  643. phys_complete = ioat_get_current_completion(chan);
  644. if (phys_complete == chan->last_completion) {
  645. spin_unlock_bh(&chan->cleanup_lock);
  646. /*
  647. * perhaps we're stuck so hard that the watchdog can't go off?
  648. * try to catch it after 2 seconds
  649. */
  650. if (time_after(jiffies,
  651. chan->last_completion_time + HZ*WATCHDOG_DELAY)) {
  652. ioat1_chan_watchdog(&(chan->device->work.work));
  653. chan->last_completion_time = jiffies;
  654. }
  655. return;
  656. }
  657. chan->last_completion_time = jiffies;
  658. cookie = 0;
  659. if (!spin_trylock_bh(&ioat->desc_lock)) {
  660. spin_unlock_bh(&chan->cleanup_lock);
  661. return;
  662. }
  663. dev_dbg(to_dev(chan), "%s: phys_complete: %lx\n",
  664. __func__, phys_complete);
  665. list_for_each_entry_safe(desc, _desc, &ioat->used_desc, node) {
  666. tx = &desc->txd;
  667. /*
  668. * Incoming DMA requests may use multiple descriptors,
  669. * due to exceeding xfercap, perhaps. If so, only the
  670. * last one will have a cookie, and require unmapping.
  671. */
  672. dump_desc_dbg(ioat, desc);
  673. if (tx->cookie) {
  674. cookie = tx->cookie;
  675. ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
  676. if (tx->callback) {
  677. tx->callback(tx->callback_param);
  678. tx->callback = NULL;
  679. }
  680. }
  681. if (tx->phys != phys_complete) {
  682. /*
  683. * a completed entry, but not the last, so clean
  684. * up if the client is done with the descriptor
  685. */
  686. if (async_tx_test_ack(tx))
  687. list_move_tail(&desc->node, &ioat->free_desc);
  688. else
  689. tx->cookie = 0;
  690. } else {
  691. /*
  692. * last used desc. Do not remove, so we can
  693. * append from it, but don't look at it next
  694. * time, either
  695. */
  696. tx->cookie = 0;
  697. /* TODO check status bits? */
  698. break;
  699. }
  700. }
  701. spin_unlock_bh(&ioat->desc_lock);
  702. chan->last_completion = phys_complete;
  703. if (cookie != 0)
  704. chan->completed_cookie = cookie;
  705. spin_unlock_bh(&chan->cleanup_lock);
  706. }
  707. static enum dma_status
  708. ioat1_dma_is_complete(struct dma_chan *c, dma_cookie_t cookie,
  709. dma_cookie_t *done, dma_cookie_t *used)
  710. {
  711. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  712. if (ioat_is_complete(c, cookie, done, used) == DMA_SUCCESS)
  713. return DMA_SUCCESS;
  714. ioat1_cleanup(ioat);
  715. return ioat_is_complete(c, cookie, done, used);
  716. }
  717. static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat)
  718. {
  719. struct ioat_chan_common *chan = &ioat->base;
  720. struct ioat_desc_sw *desc;
  721. struct ioat_dma_descriptor *hw;
  722. spin_lock_bh(&ioat->desc_lock);
  723. desc = ioat1_dma_get_next_descriptor(ioat);
  724. if (!desc) {
  725. dev_err(to_dev(chan),
  726. "Unable to start null desc - get next desc failed\n");
  727. spin_unlock_bh(&ioat->desc_lock);
  728. return;
  729. }
  730. hw = desc->hw;
  731. hw->ctl = 0;
  732. hw->ctl_f.null = 1;
  733. hw->ctl_f.int_en = 1;
  734. hw->ctl_f.compl_write = 1;
  735. /* set size to non-zero value (channel returns error when size is 0) */
  736. hw->size = NULL_DESC_BUFFER_SIZE;
  737. hw->src_addr = 0;
  738. hw->dst_addr = 0;
  739. async_tx_ack(&desc->txd);
  740. hw->next = 0;
  741. list_add_tail(&desc->node, &ioat->used_desc);
  742. dump_desc_dbg(ioat, desc);
  743. writel(((u64) desc->txd.phys) & 0x00000000FFFFFFFF,
  744. chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW);
  745. writel(((u64) desc->txd.phys) >> 32,
  746. chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH);
  747. writeb(IOAT_CHANCMD_START, chan->reg_base
  748. + IOAT_CHANCMD_OFFSET(chan->device->version));
  749. spin_unlock_bh(&ioat->desc_lock);
  750. }
  751. /*
  752. * Perform a IOAT transaction to verify the HW works.
  753. */
  754. #define IOAT_TEST_SIZE 2000
  755. static void ioat_dma_test_callback(void *dma_async_param)
  756. {
  757. struct completion *cmp = dma_async_param;
  758. complete(cmp);
  759. }
  760. /**
  761. * ioat_dma_self_test - Perform a IOAT transaction to verify the HW works.
  762. * @device: device to be tested
  763. */
  764. static int ioat_dma_self_test(struct ioatdma_device *device)
  765. {
  766. int i;
  767. u8 *src;
  768. u8 *dest;
  769. struct dma_device *dma = &device->common;
  770. struct device *dev = &device->pdev->dev;
  771. struct dma_chan *dma_chan;
  772. struct dma_async_tx_descriptor *tx;
  773. dma_addr_t dma_dest, dma_src;
  774. dma_cookie_t cookie;
  775. int err = 0;
  776. struct completion cmp;
  777. unsigned long tmo;
  778. unsigned long flags;
  779. src = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
  780. if (!src)
  781. return -ENOMEM;
  782. dest = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
  783. if (!dest) {
  784. kfree(src);
  785. return -ENOMEM;
  786. }
  787. /* Fill in src buffer */
  788. for (i = 0; i < IOAT_TEST_SIZE; i++)
  789. src[i] = (u8)i;
  790. /* Start copy, using first DMA channel */
  791. dma_chan = container_of(dma->channels.next, struct dma_chan,
  792. device_node);
  793. if (dma->device_alloc_chan_resources(dma_chan) < 1) {
  794. dev_err(dev, "selftest cannot allocate chan resource\n");
  795. err = -ENODEV;
  796. goto out;
  797. }
  798. dma_src = dma_map_single(dev, src, IOAT_TEST_SIZE, DMA_TO_DEVICE);
  799. dma_dest = dma_map_single(dev, dest, IOAT_TEST_SIZE, DMA_FROM_DEVICE);
  800. flags = DMA_COMPL_SRC_UNMAP_SINGLE | DMA_COMPL_DEST_UNMAP_SINGLE |
  801. DMA_PREP_INTERRUPT;
  802. tx = device->common.device_prep_dma_memcpy(dma_chan, dma_dest, dma_src,
  803. IOAT_TEST_SIZE, flags);
  804. if (!tx) {
  805. dev_err(dev, "Self-test prep failed, disabling\n");
  806. err = -ENODEV;
  807. goto free_resources;
  808. }
  809. async_tx_ack(tx);
  810. init_completion(&cmp);
  811. tx->callback = ioat_dma_test_callback;
  812. tx->callback_param = &cmp;
  813. cookie = tx->tx_submit(tx);
  814. if (cookie < 0) {
  815. dev_err(dev, "Self-test setup failed, disabling\n");
  816. err = -ENODEV;
  817. goto free_resources;
  818. }
  819. dma->device_issue_pending(dma_chan);
  820. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  821. if (tmo == 0 ||
  822. dma->device_is_tx_complete(dma_chan, cookie, NULL, NULL)
  823. != DMA_SUCCESS) {
  824. dev_err(dev, "Self-test copy timed out, disabling\n");
  825. err = -ENODEV;
  826. goto free_resources;
  827. }
  828. if (memcmp(src, dest, IOAT_TEST_SIZE)) {
  829. dev_err(dev, "Self-test copy failed compare, disabling\n");
  830. err = -ENODEV;
  831. goto free_resources;
  832. }
  833. free_resources:
  834. dma->device_free_chan_resources(dma_chan);
  835. out:
  836. kfree(src);
  837. kfree(dest);
  838. return err;
  839. }
  840. static char ioat_interrupt_style[32] = "msix";
  841. module_param_string(ioat_interrupt_style, ioat_interrupt_style,
  842. sizeof(ioat_interrupt_style), 0644);
  843. MODULE_PARM_DESC(ioat_interrupt_style,
  844. "set ioat interrupt style: msix (default), "
  845. "msix-single-vector, msi, intx)");
  846. /**
  847. * ioat_dma_setup_interrupts - setup interrupt handler
  848. * @device: ioat device
  849. */
  850. static int ioat_dma_setup_interrupts(struct ioatdma_device *device)
  851. {
  852. struct ioat_chan_common *chan;
  853. struct pci_dev *pdev = device->pdev;
  854. struct device *dev = &pdev->dev;
  855. struct msix_entry *msix;
  856. int i, j, msixcnt;
  857. int err = -EINVAL;
  858. u8 intrctrl = 0;
  859. if (!strcmp(ioat_interrupt_style, "msix"))
  860. goto msix;
  861. if (!strcmp(ioat_interrupt_style, "msix-single-vector"))
  862. goto msix_single_vector;
  863. if (!strcmp(ioat_interrupt_style, "msi"))
  864. goto msi;
  865. if (!strcmp(ioat_interrupt_style, "intx"))
  866. goto intx;
  867. dev_err(dev, "invalid ioat_interrupt_style %s\n", ioat_interrupt_style);
  868. goto err_no_irq;
  869. msix:
  870. /* The number of MSI-X vectors should equal the number of channels */
  871. msixcnt = device->common.chancnt;
  872. for (i = 0; i < msixcnt; i++)
  873. device->msix_entries[i].entry = i;
  874. err = pci_enable_msix(pdev, device->msix_entries, msixcnt);
  875. if (err < 0)
  876. goto msi;
  877. if (err > 0)
  878. goto msix_single_vector;
  879. for (i = 0; i < msixcnt; i++) {
  880. msix = &device->msix_entries[i];
  881. chan = ioat_chan_by_index(device, i);
  882. err = devm_request_irq(dev, msix->vector,
  883. ioat_dma_do_interrupt_msix, 0,
  884. "ioat-msix", chan);
  885. if (err) {
  886. for (j = 0; j < i; j++) {
  887. msix = &device->msix_entries[j];
  888. chan = ioat_chan_by_index(device, j);
  889. devm_free_irq(dev, msix->vector, chan);
  890. }
  891. goto msix_single_vector;
  892. }
  893. }
  894. intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL;
  895. goto done;
  896. msix_single_vector:
  897. msix = &device->msix_entries[0];
  898. msix->entry = 0;
  899. err = pci_enable_msix(pdev, device->msix_entries, 1);
  900. if (err)
  901. goto msi;
  902. err = devm_request_irq(dev, msix->vector, ioat_dma_do_interrupt, 0,
  903. "ioat-msix", device);
  904. if (err) {
  905. pci_disable_msix(pdev);
  906. goto msi;
  907. }
  908. goto done;
  909. msi:
  910. err = pci_enable_msi(pdev);
  911. if (err)
  912. goto intx;
  913. err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt, 0,
  914. "ioat-msi", device);
  915. if (err) {
  916. pci_disable_msi(pdev);
  917. goto intx;
  918. }
  919. goto done;
  920. intx:
  921. err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt,
  922. IRQF_SHARED, "ioat-intx", device);
  923. if (err)
  924. goto err_no_irq;
  925. done:
  926. if (device->intr_quirk)
  927. device->intr_quirk(device);
  928. intrctrl |= IOAT_INTRCTRL_MASTER_INT_EN;
  929. writeb(intrctrl, device->reg_base + IOAT_INTRCTRL_OFFSET);
  930. return 0;
  931. err_no_irq:
  932. /* Disable all interrupt generation */
  933. writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
  934. dev_err(dev, "no usable interrupts\n");
  935. return err;
  936. }
  937. static void ioat_disable_interrupts(struct ioatdma_device *device)
  938. {
  939. /* Disable all interrupt generation */
  940. writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
  941. }
  942. int ioat_probe(struct ioatdma_device *device)
  943. {
  944. int err = -ENODEV;
  945. struct dma_device *dma = &device->common;
  946. struct pci_dev *pdev = device->pdev;
  947. struct device *dev = &pdev->dev;
  948. /* DMA coherent memory pool for DMA descriptor allocations */
  949. device->dma_pool = pci_pool_create("dma_desc_pool", pdev,
  950. sizeof(struct ioat_dma_descriptor),
  951. 64, 0);
  952. if (!device->dma_pool) {
  953. err = -ENOMEM;
  954. goto err_dma_pool;
  955. }
  956. device->completion_pool = pci_pool_create("completion_pool", pdev,
  957. sizeof(u64), SMP_CACHE_BYTES,
  958. SMP_CACHE_BYTES);
  959. if (!device->completion_pool) {
  960. err = -ENOMEM;
  961. goto err_completion_pool;
  962. }
  963. device->enumerate_channels(device);
  964. dma_cap_set(DMA_MEMCPY, dma->cap_mask);
  965. dma->dev = &pdev->dev;
  966. dev_err(dev, "Intel(R) I/OAT DMA Engine found,"
  967. " %d channels, device version 0x%02x, driver version %s\n",
  968. dma->chancnt, device->version, IOAT_DMA_VERSION);
  969. if (!dma->chancnt) {
  970. dev_err(dev, "Intel(R) I/OAT DMA Engine problem found: "
  971. "zero channels detected\n");
  972. goto err_setup_interrupts;
  973. }
  974. err = ioat_dma_setup_interrupts(device);
  975. if (err)
  976. goto err_setup_interrupts;
  977. err = ioat_dma_self_test(device);
  978. if (err)
  979. goto err_self_test;
  980. return 0;
  981. err_self_test:
  982. ioat_disable_interrupts(device);
  983. err_setup_interrupts:
  984. pci_pool_destroy(device->completion_pool);
  985. err_completion_pool:
  986. pci_pool_destroy(device->dma_pool);
  987. err_dma_pool:
  988. return err;
  989. }
  990. int ioat_register(struct ioatdma_device *device)
  991. {
  992. int err = dma_async_device_register(&device->common);
  993. if (err) {
  994. ioat_disable_interrupts(device);
  995. pci_pool_destroy(device->completion_pool);
  996. pci_pool_destroy(device->dma_pool);
  997. }
  998. return err;
  999. }
  1000. /* ioat1_intr_quirk - fix up dma ctrl register to enable / disable msi */
  1001. static void ioat1_intr_quirk(struct ioatdma_device *device)
  1002. {
  1003. struct pci_dev *pdev = device->pdev;
  1004. u32 dmactrl;
  1005. pci_read_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, &dmactrl);
  1006. if (pdev->msi_enabled)
  1007. dmactrl |= IOAT_PCI_DMACTRL_MSI_EN;
  1008. else
  1009. dmactrl &= ~IOAT_PCI_DMACTRL_MSI_EN;
  1010. pci_write_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, dmactrl);
  1011. }
  1012. int ioat1_dma_probe(struct ioatdma_device *device, int dca)
  1013. {
  1014. struct pci_dev *pdev = device->pdev;
  1015. struct dma_device *dma;
  1016. int err;
  1017. device->intr_quirk = ioat1_intr_quirk;
  1018. device->enumerate_channels = ioat1_enumerate_channels;
  1019. dma = &device->common;
  1020. dma->device_prep_dma_memcpy = ioat1_dma_prep_memcpy;
  1021. dma->device_issue_pending = ioat1_dma_memcpy_issue_pending;
  1022. dma->device_alloc_chan_resources = ioat1_dma_alloc_chan_resources;
  1023. dma->device_free_chan_resources = ioat1_dma_free_chan_resources;
  1024. dma->device_is_tx_complete = ioat1_dma_is_complete;
  1025. err = ioat_probe(device);
  1026. if (err)
  1027. return err;
  1028. ioat_set_tcp_copy_break(4096);
  1029. err = ioat_register(device);
  1030. if (err)
  1031. return err;
  1032. if (dca)
  1033. device->dca = ioat_dca_init(pdev, device->reg_base);
  1034. INIT_DELAYED_WORK(&device->work, ioat1_chan_watchdog);
  1035. schedule_delayed_work(&device->work, WATCHDOG_DELAY);
  1036. return err;
  1037. }
  1038. void ioat_dma_remove(struct ioatdma_device *device)
  1039. {
  1040. struct dma_device *dma = &device->common;
  1041. if (device->version != IOAT_VER_3_0)
  1042. cancel_delayed_work(&device->work);
  1043. ioat_disable_interrupts(device);
  1044. dma_async_device_unregister(dma);
  1045. pci_pool_destroy(device->dma_pool);
  1046. pci_pool_destroy(device->completion_pool);
  1047. INIT_LIST_HEAD(&dma->channels);
  1048. }