dma.c 33 KB

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