dma.c 33 KB

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