dma.c 33 KB

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