dma.c 33 KB

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