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. #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. void ioat_dma_unmap(struct ioat_chan_common *chan, enum dma_ctrl_flags flags,
  464. size_t len, struct ioat_dma_descriptor *hw)
  465. {
  466. struct pci_dev *pdev = chan->device->pdev;
  467. size_t offset = len - hw->size;
  468. if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
  469. ioat_unmap(pdev, hw->dst_addr - offset, len,
  470. PCI_DMA_FROMDEVICE, flags, 1);
  471. if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP))
  472. ioat_unmap(pdev, hw->src_addr - offset, len,
  473. PCI_DMA_TODEVICE, flags, 0);
  474. }
  475. dma_addr_t ioat_get_current_completion(struct ioat_chan_common *chan)
  476. {
  477. dma_addr_t phys_complete;
  478. u64 completion;
  479. completion = *chan->completion;
  480. phys_complete = ioat_chansts_to_addr(completion);
  481. dev_dbg(to_dev(chan), "%s: phys_complete: %#llx\n", __func__,
  482. (unsigned long long) phys_complete);
  483. if (is_ioat_halted(completion)) {
  484. u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  485. dev_err(to_dev(chan), "Channel halted, chanerr = %x\n",
  486. chanerr);
  487. /* TODO do something to salvage the situation */
  488. }
  489. return phys_complete;
  490. }
  491. bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
  492. dma_addr_t *phys_complete)
  493. {
  494. *phys_complete = ioat_get_current_completion(chan);
  495. if (*phys_complete == chan->last_completion)
  496. return false;
  497. clear_bit(IOAT_COMPLETION_ACK, &chan->state);
  498. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  499. return true;
  500. }
  501. static void __cleanup(struct ioat_dma_chan *ioat, dma_addr_t phys_complete)
  502. {
  503. struct ioat_chan_common *chan = &ioat->base;
  504. struct list_head *_desc, *n;
  505. struct dma_async_tx_descriptor *tx;
  506. dev_dbg(to_dev(chan), "%s: phys_complete: %llx\n",
  507. __func__, (unsigned long long) phys_complete);
  508. list_for_each_safe(_desc, n, &ioat->used_desc) {
  509. struct ioat_desc_sw *desc;
  510. prefetch(n);
  511. desc = list_entry(_desc, typeof(*desc), node);
  512. tx = &desc->txd;
  513. /*
  514. * Incoming DMA requests may use multiple descriptors,
  515. * due to exceeding xfercap, perhaps. If so, only the
  516. * last one will have a cookie, and require unmapping.
  517. */
  518. dump_desc_dbg(ioat, desc);
  519. if (tx->cookie) {
  520. dma_cookie_complete(tx);
  521. ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
  522. ioat->active -= desc->hw->tx_cnt;
  523. if (tx->callback) {
  524. tx->callback(tx->callback_param);
  525. tx->callback = NULL;
  526. }
  527. }
  528. if (tx->phys != phys_complete) {
  529. /*
  530. * a completed entry, but not the last, so clean
  531. * up if the client is done with the descriptor
  532. */
  533. if (async_tx_test_ack(tx))
  534. list_move_tail(&desc->node, &ioat->free_desc);
  535. } else {
  536. /*
  537. * last used desc. Do not remove, so we can
  538. * append from it.
  539. */
  540. /* if nothing else is pending, cancel the
  541. * completion timeout
  542. */
  543. if (n == &ioat->used_desc) {
  544. dev_dbg(to_dev(chan),
  545. "%s cancel completion timeout\n",
  546. __func__);
  547. clear_bit(IOAT_COMPLETION_PENDING, &chan->state);
  548. }
  549. /* TODO check status bits? */
  550. break;
  551. }
  552. }
  553. chan->last_completion = phys_complete;
  554. }
  555. /**
  556. * ioat1_cleanup - cleanup up finished descriptors
  557. * @chan: ioat channel to be cleaned up
  558. *
  559. * To prevent lock contention we defer cleanup when the locks are
  560. * contended with a terminal timeout that forces cleanup and catches
  561. * completion notification errors.
  562. */
  563. static void ioat1_cleanup(struct ioat_dma_chan *ioat)
  564. {
  565. struct ioat_chan_common *chan = &ioat->base;
  566. dma_addr_t phys_complete;
  567. prefetch(chan->completion);
  568. if (!spin_trylock_bh(&chan->cleanup_lock))
  569. return;
  570. if (!ioat_cleanup_preamble(chan, &phys_complete)) {
  571. spin_unlock_bh(&chan->cleanup_lock);
  572. return;
  573. }
  574. if (!spin_trylock_bh(&ioat->desc_lock)) {
  575. spin_unlock_bh(&chan->cleanup_lock);
  576. return;
  577. }
  578. __cleanup(ioat, phys_complete);
  579. spin_unlock_bh(&ioat->desc_lock);
  580. spin_unlock_bh(&chan->cleanup_lock);
  581. }
  582. static void ioat1_timer_event(unsigned long data)
  583. {
  584. struct ioat_dma_chan *ioat = to_ioat_chan((void *) data);
  585. struct ioat_chan_common *chan = &ioat->base;
  586. dev_dbg(to_dev(chan), "%s: state: %lx\n", __func__, chan->state);
  587. spin_lock_bh(&chan->cleanup_lock);
  588. if (test_and_clear_bit(IOAT_RESET_PENDING, &chan->state)) {
  589. struct ioat_desc_sw *desc;
  590. spin_lock_bh(&ioat->desc_lock);
  591. /* restart active descriptors */
  592. desc = to_ioat_desc(ioat->used_desc.prev);
  593. ioat_set_chainaddr(ioat, desc->txd.phys);
  594. ioat_start(chan);
  595. ioat->pending = 0;
  596. set_bit(IOAT_COMPLETION_PENDING, &chan->state);
  597. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  598. spin_unlock_bh(&ioat->desc_lock);
  599. } else if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
  600. dma_addr_t phys_complete;
  601. spin_lock_bh(&ioat->desc_lock);
  602. /* if we haven't made progress and we have already
  603. * acknowledged a pending completion once, then be more
  604. * forceful with a restart
  605. */
  606. if (ioat_cleanup_preamble(chan, &phys_complete))
  607. __cleanup(ioat, phys_complete);
  608. else if (test_bit(IOAT_COMPLETION_ACK, &chan->state))
  609. ioat1_reset_channel(ioat);
  610. else {
  611. u64 status = ioat_chansts(chan);
  612. /* manually update the last completion address */
  613. if (ioat_chansts_to_addr(status) != 0)
  614. *chan->completion = status;
  615. set_bit(IOAT_COMPLETION_ACK, &chan->state);
  616. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  617. }
  618. spin_unlock_bh(&ioat->desc_lock);
  619. }
  620. spin_unlock_bh(&chan->cleanup_lock);
  621. }
  622. enum dma_status
  623. ioat_dma_tx_status(struct dma_chan *c, dma_cookie_t cookie,
  624. struct dma_tx_state *txstate)
  625. {
  626. struct ioat_chan_common *chan = to_chan_common(c);
  627. struct ioatdma_device *device = chan->device;
  628. enum dma_status ret;
  629. ret = dma_cookie_status(c, cookie, txstate);
  630. if (ret == DMA_SUCCESS)
  631. return ret;
  632. device->cleanup_fn((unsigned long) c);
  633. return dma_cookie_status(c, cookie, txstate);
  634. }
  635. static void ioat1_dma_start_null_desc(struct ioat_dma_chan *ioat)
  636. {
  637. struct ioat_chan_common *chan = &ioat->base;
  638. struct ioat_desc_sw *desc;
  639. struct ioat_dma_descriptor *hw;
  640. spin_lock_bh(&ioat->desc_lock);
  641. desc = ioat1_dma_get_next_descriptor(ioat);
  642. if (!desc) {
  643. dev_err(to_dev(chan),
  644. "Unable to start null desc - get next desc failed\n");
  645. spin_unlock_bh(&ioat->desc_lock);
  646. return;
  647. }
  648. hw = desc->hw;
  649. hw->ctl = 0;
  650. hw->ctl_f.null = 1;
  651. hw->ctl_f.int_en = 1;
  652. hw->ctl_f.compl_write = 1;
  653. /* set size to non-zero value (channel returns error when size is 0) */
  654. hw->size = NULL_DESC_BUFFER_SIZE;
  655. hw->src_addr = 0;
  656. hw->dst_addr = 0;
  657. async_tx_ack(&desc->txd);
  658. hw->next = 0;
  659. list_add_tail(&desc->node, &ioat->used_desc);
  660. dump_desc_dbg(ioat, desc);
  661. ioat_set_chainaddr(ioat, desc->txd.phys);
  662. ioat_start(chan);
  663. spin_unlock_bh(&ioat->desc_lock);
  664. }
  665. /*
  666. * Perform a IOAT transaction to verify the HW works.
  667. */
  668. #define IOAT_TEST_SIZE 2000
  669. static void __devinit ioat_dma_test_callback(void *dma_async_param)
  670. {
  671. struct completion *cmp = dma_async_param;
  672. complete(cmp);
  673. }
  674. /**
  675. * ioat_dma_self_test - Perform a IOAT transaction to verify the HW works.
  676. * @device: device to be tested
  677. */
  678. int __devinit ioat_dma_self_test(struct ioatdma_device *device)
  679. {
  680. int i;
  681. u8 *src;
  682. u8 *dest;
  683. struct dma_device *dma = &device->common;
  684. struct device *dev = &device->pdev->dev;
  685. struct dma_chan *dma_chan;
  686. struct dma_async_tx_descriptor *tx;
  687. dma_addr_t dma_dest, dma_src;
  688. dma_cookie_t cookie;
  689. int err = 0;
  690. struct completion cmp;
  691. unsigned long tmo;
  692. unsigned long flags;
  693. src = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
  694. if (!src)
  695. return -ENOMEM;
  696. dest = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
  697. if (!dest) {
  698. kfree(src);
  699. return -ENOMEM;
  700. }
  701. /* Fill in src buffer */
  702. for (i = 0; i < IOAT_TEST_SIZE; i++)
  703. src[i] = (u8)i;
  704. /* Start copy, using first DMA channel */
  705. dma_chan = container_of(dma->channels.next, struct dma_chan,
  706. device_node);
  707. if (dma->device_alloc_chan_resources(dma_chan) < 1) {
  708. dev_err(dev, "selftest cannot allocate chan resource\n");
  709. err = -ENODEV;
  710. goto out;
  711. }
  712. dma_src = dma_map_single(dev, src, IOAT_TEST_SIZE, DMA_TO_DEVICE);
  713. dma_dest = dma_map_single(dev, dest, IOAT_TEST_SIZE, DMA_FROM_DEVICE);
  714. flags = DMA_COMPL_SRC_UNMAP_SINGLE | DMA_COMPL_DEST_UNMAP_SINGLE |
  715. DMA_PREP_INTERRUPT;
  716. tx = device->common.device_prep_dma_memcpy(dma_chan, dma_dest, dma_src,
  717. IOAT_TEST_SIZE, flags);
  718. if (!tx) {
  719. dev_err(dev, "Self-test prep failed, disabling\n");
  720. err = -ENODEV;
  721. goto free_resources;
  722. }
  723. async_tx_ack(tx);
  724. init_completion(&cmp);
  725. tx->callback = ioat_dma_test_callback;
  726. tx->callback_param = &cmp;
  727. cookie = tx->tx_submit(tx);
  728. if (cookie < 0) {
  729. dev_err(dev, "Self-test setup failed, disabling\n");
  730. err = -ENODEV;
  731. goto free_resources;
  732. }
  733. dma->device_issue_pending(dma_chan);
  734. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  735. if (tmo == 0 ||
  736. dma->device_tx_status(dma_chan, cookie, NULL)
  737. != DMA_SUCCESS) {
  738. dev_err(dev, "Self-test copy timed out, disabling\n");
  739. err = -ENODEV;
  740. goto free_resources;
  741. }
  742. if (memcmp(src, dest, IOAT_TEST_SIZE)) {
  743. dev_err(dev, "Self-test copy failed compare, disabling\n");
  744. err = -ENODEV;
  745. goto free_resources;
  746. }
  747. free_resources:
  748. dma->device_free_chan_resources(dma_chan);
  749. out:
  750. kfree(src);
  751. kfree(dest);
  752. return err;
  753. }
  754. static char ioat_interrupt_style[32] = "msix";
  755. module_param_string(ioat_interrupt_style, ioat_interrupt_style,
  756. sizeof(ioat_interrupt_style), 0644);
  757. MODULE_PARM_DESC(ioat_interrupt_style,
  758. "set ioat interrupt style: msix (default), "
  759. "msix-single-vector, msi, intx)");
  760. /**
  761. * ioat_dma_setup_interrupts - setup interrupt handler
  762. * @device: ioat device
  763. */
  764. static int ioat_dma_setup_interrupts(struct ioatdma_device *device)
  765. {
  766. struct ioat_chan_common *chan;
  767. struct pci_dev *pdev = device->pdev;
  768. struct device *dev = &pdev->dev;
  769. struct msix_entry *msix;
  770. int i, j, msixcnt;
  771. int err = -EINVAL;
  772. u8 intrctrl = 0;
  773. if (!strcmp(ioat_interrupt_style, "msix"))
  774. goto msix;
  775. if (!strcmp(ioat_interrupt_style, "msix-single-vector"))
  776. goto msix_single_vector;
  777. if (!strcmp(ioat_interrupt_style, "msi"))
  778. goto msi;
  779. if (!strcmp(ioat_interrupt_style, "intx"))
  780. goto intx;
  781. dev_err(dev, "invalid ioat_interrupt_style %s\n", ioat_interrupt_style);
  782. goto err_no_irq;
  783. msix:
  784. /* The number of MSI-X vectors should equal the number of channels */
  785. msixcnt = device->common.chancnt;
  786. for (i = 0; i < msixcnt; i++)
  787. device->msix_entries[i].entry = i;
  788. err = pci_enable_msix(pdev, device->msix_entries, msixcnt);
  789. if (err < 0)
  790. goto msi;
  791. if (err > 0)
  792. goto msix_single_vector;
  793. for (i = 0; i < msixcnt; i++) {
  794. msix = &device->msix_entries[i];
  795. chan = ioat_chan_by_index(device, i);
  796. err = devm_request_irq(dev, msix->vector,
  797. ioat_dma_do_interrupt_msix, 0,
  798. "ioat-msix", chan);
  799. if (err) {
  800. for (j = 0; j < i; j++) {
  801. msix = &device->msix_entries[j];
  802. chan = ioat_chan_by_index(device, j);
  803. devm_free_irq(dev, msix->vector, chan);
  804. }
  805. goto msix_single_vector;
  806. }
  807. }
  808. intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL;
  809. goto done;
  810. msix_single_vector:
  811. msix = &device->msix_entries[0];
  812. msix->entry = 0;
  813. err = pci_enable_msix(pdev, device->msix_entries, 1);
  814. if (err)
  815. goto msi;
  816. err = devm_request_irq(dev, msix->vector, ioat_dma_do_interrupt, 0,
  817. "ioat-msix", device);
  818. if (err) {
  819. pci_disable_msix(pdev);
  820. goto msi;
  821. }
  822. goto done;
  823. msi:
  824. err = pci_enable_msi(pdev);
  825. if (err)
  826. goto intx;
  827. err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt, 0,
  828. "ioat-msi", device);
  829. if (err) {
  830. pci_disable_msi(pdev);
  831. goto intx;
  832. }
  833. goto done;
  834. intx:
  835. err = devm_request_irq(dev, pdev->irq, ioat_dma_do_interrupt,
  836. IRQF_SHARED, "ioat-intx", device);
  837. if (err)
  838. goto err_no_irq;
  839. done:
  840. if (device->intr_quirk)
  841. device->intr_quirk(device);
  842. intrctrl |= IOAT_INTRCTRL_MASTER_INT_EN;
  843. writeb(intrctrl, device->reg_base + IOAT_INTRCTRL_OFFSET);
  844. return 0;
  845. err_no_irq:
  846. /* Disable all interrupt generation */
  847. writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
  848. dev_err(dev, "no usable interrupts\n");
  849. return err;
  850. }
  851. static void ioat_disable_interrupts(struct ioatdma_device *device)
  852. {
  853. /* Disable all interrupt generation */
  854. writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
  855. }
  856. int __devinit ioat_probe(struct ioatdma_device *device)
  857. {
  858. int err = -ENODEV;
  859. struct dma_device *dma = &device->common;
  860. struct pci_dev *pdev = device->pdev;
  861. struct device *dev = &pdev->dev;
  862. /* DMA coherent memory pool for DMA descriptor allocations */
  863. device->dma_pool = pci_pool_create("dma_desc_pool", pdev,
  864. sizeof(struct ioat_dma_descriptor),
  865. 64, 0);
  866. if (!device->dma_pool) {
  867. err = -ENOMEM;
  868. goto err_dma_pool;
  869. }
  870. device->completion_pool = pci_pool_create("completion_pool", pdev,
  871. sizeof(u64), SMP_CACHE_BYTES,
  872. SMP_CACHE_BYTES);
  873. if (!device->completion_pool) {
  874. err = -ENOMEM;
  875. goto err_completion_pool;
  876. }
  877. device->enumerate_channels(device);
  878. dma_cap_set(DMA_MEMCPY, dma->cap_mask);
  879. dma->dev = &pdev->dev;
  880. if (!dma->chancnt) {
  881. dev_err(dev, "channel enumeration error\n");
  882. goto err_setup_interrupts;
  883. }
  884. err = ioat_dma_setup_interrupts(device);
  885. if (err)
  886. goto err_setup_interrupts;
  887. err = device->self_test(device);
  888. if (err)
  889. goto err_self_test;
  890. return 0;
  891. err_self_test:
  892. ioat_disable_interrupts(device);
  893. err_setup_interrupts:
  894. pci_pool_destroy(device->completion_pool);
  895. err_completion_pool:
  896. pci_pool_destroy(device->dma_pool);
  897. err_dma_pool:
  898. return err;
  899. }
  900. int __devinit ioat_register(struct ioatdma_device *device)
  901. {
  902. int err = dma_async_device_register(&device->common);
  903. if (err) {
  904. ioat_disable_interrupts(device);
  905. pci_pool_destroy(device->completion_pool);
  906. pci_pool_destroy(device->dma_pool);
  907. }
  908. return err;
  909. }
  910. /* ioat1_intr_quirk - fix up dma ctrl register to enable / disable msi */
  911. static void ioat1_intr_quirk(struct ioatdma_device *device)
  912. {
  913. struct pci_dev *pdev = device->pdev;
  914. u32 dmactrl;
  915. pci_read_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, &dmactrl);
  916. if (pdev->msi_enabled)
  917. dmactrl |= IOAT_PCI_DMACTRL_MSI_EN;
  918. else
  919. dmactrl &= ~IOAT_PCI_DMACTRL_MSI_EN;
  920. pci_write_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, dmactrl);
  921. }
  922. static ssize_t ring_size_show(struct dma_chan *c, char *page)
  923. {
  924. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  925. return sprintf(page, "%d\n", ioat->desccount);
  926. }
  927. static struct ioat_sysfs_entry ring_size_attr = __ATTR_RO(ring_size);
  928. static ssize_t ring_active_show(struct dma_chan *c, char *page)
  929. {
  930. struct ioat_dma_chan *ioat = to_ioat_chan(c);
  931. return sprintf(page, "%d\n", ioat->active);
  932. }
  933. static struct ioat_sysfs_entry ring_active_attr = __ATTR_RO(ring_active);
  934. static ssize_t cap_show(struct dma_chan *c, char *page)
  935. {
  936. struct dma_device *dma = c->device;
  937. return sprintf(page, "copy%s%s%s%s%s%s\n",
  938. dma_has_cap(DMA_PQ, dma->cap_mask) ? " pq" : "",
  939. dma_has_cap(DMA_PQ_VAL, dma->cap_mask) ? " pq_val" : "",
  940. dma_has_cap(DMA_XOR, dma->cap_mask) ? " xor" : "",
  941. dma_has_cap(DMA_XOR_VAL, dma->cap_mask) ? " xor_val" : "",
  942. dma_has_cap(DMA_MEMSET, dma->cap_mask) ? " fill" : "",
  943. dma_has_cap(DMA_INTERRUPT, dma->cap_mask) ? " intr" : "");
  944. }
  945. struct ioat_sysfs_entry ioat_cap_attr = __ATTR_RO(cap);
  946. static ssize_t version_show(struct dma_chan *c, char *page)
  947. {
  948. struct dma_device *dma = c->device;
  949. struct ioatdma_device *device = to_ioatdma_device(dma);
  950. return sprintf(page, "%d.%d\n",
  951. device->version >> 4, device->version & 0xf);
  952. }
  953. struct ioat_sysfs_entry ioat_version_attr = __ATTR_RO(version);
  954. static struct attribute *ioat1_attrs[] = {
  955. &ring_size_attr.attr,
  956. &ring_active_attr.attr,
  957. &ioat_cap_attr.attr,
  958. &ioat_version_attr.attr,
  959. NULL,
  960. };
  961. static ssize_t
  962. ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
  963. {
  964. struct ioat_sysfs_entry *entry;
  965. struct ioat_chan_common *chan;
  966. entry = container_of(attr, struct ioat_sysfs_entry, attr);
  967. chan = container_of(kobj, struct ioat_chan_common, kobj);
  968. if (!entry->show)
  969. return -EIO;
  970. return entry->show(&chan->common, page);
  971. }
  972. const struct sysfs_ops ioat_sysfs_ops = {
  973. .show = ioat_attr_show,
  974. };
  975. static struct kobj_type ioat1_ktype = {
  976. .sysfs_ops = &ioat_sysfs_ops,
  977. .default_attrs = ioat1_attrs,
  978. };
  979. void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type)
  980. {
  981. struct dma_device *dma = &device->common;
  982. struct dma_chan *c;
  983. list_for_each_entry(c, &dma->channels, device_node) {
  984. struct ioat_chan_common *chan = to_chan_common(c);
  985. struct kobject *parent = &c->dev->device.kobj;
  986. int err;
  987. err = kobject_init_and_add(&chan->kobj, type, parent, "quickdata");
  988. if (err) {
  989. dev_warn(to_dev(chan),
  990. "sysfs init error (%d), continuing...\n", err);
  991. kobject_put(&chan->kobj);
  992. set_bit(IOAT_KOBJ_INIT_FAIL, &chan->state);
  993. }
  994. }
  995. }
  996. void ioat_kobject_del(struct ioatdma_device *device)
  997. {
  998. struct dma_device *dma = &device->common;
  999. struct dma_chan *c;
  1000. list_for_each_entry(c, &dma->channels, device_node) {
  1001. struct ioat_chan_common *chan = to_chan_common(c);
  1002. if (!test_bit(IOAT_KOBJ_INIT_FAIL, &chan->state)) {
  1003. kobject_del(&chan->kobj);
  1004. kobject_put(&chan->kobj);
  1005. }
  1006. }
  1007. }
  1008. int __devinit ioat1_dma_probe(struct ioatdma_device *device, int dca)
  1009. {
  1010. struct pci_dev *pdev = device->pdev;
  1011. struct dma_device *dma;
  1012. int err;
  1013. device->intr_quirk = ioat1_intr_quirk;
  1014. device->enumerate_channels = ioat1_enumerate_channels;
  1015. device->self_test = ioat_dma_self_test;
  1016. device->timer_fn = ioat1_timer_event;
  1017. device->cleanup_fn = ioat1_cleanup_event;
  1018. dma = &device->common;
  1019. dma->device_prep_dma_memcpy = ioat1_dma_prep_memcpy;
  1020. dma->device_issue_pending = ioat1_dma_memcpy_issue_pending;
  1021. dma->device_alloc_chan_resources = ioat1_dma_alloc_chan_resources;
  1022. dma->device_free_chan_resources = ioat1_dma_free_chan_resources;
  1023. dma->device_tx_status = ioat_dma_tx_status;
  1024. err = ioat_probe(device);
  1025. if (err)
  1026. return err;
  1027. ioat_set_tcp_copy_break(4096);
  1028. err = ioat_register(device);
  1029. if (err)
  1030. return err;
  1031. ioat_kobject_add(device, &ioat1_ktype);
  1032. if (dca)
  1033. device->dca = ioat_dca_init(pdev, device->reg_base);
  1034. return err;
  1035. }
  1036. void __devexit ioat_dma_remove(struct ioatdma_device *device)
  1037. {
  1038. struct dma_device *dma = &device->common;
  1039. ioat_disable_interrupts(device);
  1040. ioat_kobject_del(device);
  1041. dma_async_device_unregister(dma);
  1042. pci_pool_destroy(device->dma_pool);
  1043. pci_pool_destroy(device->completion_pool);
  1044. INIT_LIST_HEAD(&dma->channels);
  1045. }