dma.c 33 KB

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