dma.c 33 KB

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