dma.c 33 KB

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