dma.c 33 KB

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