dma.c 33 KB

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