ioat_dma.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741
  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 "ioatdma.h"
  36. #include "ioatdma_registers.h"
  37. #include "ioatdma_hw.h"
  38. #define to_ioat_chan(chan) container_of(chan, struct ioat_dma_chan, common)
  39. #define to_ioatdma_device(dev) container_of(dev, struct ioatdma_device, common)
  40. #define to_ioat_desc(lh) container_of(lh, struct ioat_desc_sw, node)
  41. #define tx_to_ioat_desc(tx) container_of(tx, struct ioat_desc_sw, async_tx)
  42. #define chan_num(ch) ((int)((ch)->reg_base - (ch)->device->reg_base) / 0x80)
  43. static int ioat_pending_level = 4;
  44. module_param(ioat_pending_level, int, 0644);
  45. MODULE_PARM_DESC(ioat_pending_level,
  46. "high-water mark for pushing ioat descriptors (default: 4)");
  47. #define RESET_DELAY msecs_to_jiffies(100)
  48. #define WATCHDOG_DELAY round_jiffies(msecs_to_jiffies(2000))
  49. static void ioat_dma_chan_reset_part2(struct work_struct *work);
  50. static void ioat_dma_chan_watchdog(struct work_struct *work);
  51. /*
  52. * workaround for IOAT ver.3.0 null descriptor issue
  53. * (channel returns error when size is 0)
  54. */
  55. #define NULL_DESC_BUFFER_SIZE 1
  56. /* internal functions */
  57. static void ioat_dma_start_null_desc(struct ioat_dma_chan *ioat_chan);
  58. static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *ioat_chan);
  59. static struct ioat_desc_sw *
  60. ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan);
  61. static struct ioat_desc_sw *
  62. ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan);
  63. static inline struct ioat_dma_chan *ioat_lookup_chan_by_index(
  64. struct ioatdma_device *device,
  65. int index)
  66. {
  67. return device->idx[index];
  68. }
  69. /**
  70. * ioat_dma_do_interrupt - handler used for single vector interrupt mode
  71. * @irq: interrupt id
  72. * @data: interrupt data
  73. */
  74. static irqreturn_t ioat_dma_do_interrupt(int irq, void *data)
  75. {
  76. struct ioatdma_device *instance = data;
  77. struct ioat_dma_chan *ioat_chan;
  78. unsigned long attnstatus;
  79. int bit;
  80. u8 intrctrl;
  81. intrctrl = readb(instance->reg_base + IOAT_INTRCTRL_OFFSET);
  82. if (!(intrctrl & IOAT_INTRCTRL_MASTER_INT_EN))
  83. return IRQ_NONE;
  84. if (!(intrctrl & IOAT_INTRCTRL_INT_STATUS)) {
  85. writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
  86. return IRQ_NONE;
  87. }
  88. attnstatus = readl(instance->reg_base + IOAT_ATTNSTATUS_OFFSET);
  89. for_each_bit(bit, &attnstatus, BITS_PER_LONG) {
  90. ioat_chan = ioat_lookup_chan_by_index(instance, bit);
  91. tasklet_schedule(&ioat_chan->cleanup_task);
  92. }
  93. writeb(intrctrl, instance->reg_base + IOAT_INTRCTRL_OFFSET);
  94. return IRQ_HANDLED;
  95. }
  96. /**
  97. * ioat_dma_do_interrupt_msix - handler used for vector-per-channel interrupt mode
  98. * @irq: interrupt id
  99. * @data: interrupt data
  100. */
  101. static irqreturn_t ioat_dma_do_interrupt_msix(int irq, void *data)
  102. {
  103. struct ioat_dma_chan *ioat_chan = data;
  104. tasklet_schedule(&ioat_chan->cleanup_task);
  105. return IRQ_HANDLED;
  106. }
  107. static void ioat_dma_cleanup_tasklet(unsigned long data);
  108. /**
  109. * ioat_dma_enumerate_channels - find and initialize the device's channels
  110. * @device: the device to be enumerated
  111. */
  112. static int ioat_dma_enumerate_channels(struct ioatdma_device *device)
  113. {
  114. u8 xfercap_scale;
  115. u32 xfercap;
  116. int i;
  117. struct ioat_dma_chan *ioat_chan;
  118. /*
  119. * IOAT ver.3 workarounds
  120. */
  121. if (device->version == IOAT_VER_3_0) {
  122. u32 chan_err_mask;
  123. u16 dev_id;
  124. u32 dmauncerrsts;
  125. /*
  126. * Write CHANERRMSK_INT with 3E07h to mask out the errors
  127. * that can cause stability issues for IOAT ver.3
  128. */
  129. chan_err_mask = 0x3E07;
  130. pci_write_config_dword(device->pdev,
  131. IOAT_PCI_CHANERRMASK_INT_OFFSET,
  132. chan_err_mask);
  133. /*
  134. * Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit
  135. * (workaround for spurious config parity error after restart)
  136. */
  137. pci_read_config_word(device->pdev,
  138. IOAT_PCI_DEVICE_ID_OFFSET,
  139. &dev_id);
  140. if (dev_id == PCI_DEVICE_ID_INTEL_IOAT_TBG0) {
  141. dmauncerrsts = 0x10;
  142. pci_write_config_dword(device->pdev,
  143. IOAT_PCI_DMAUNCERRSTS_OFFSET,
  144. dmauncerrsts);
  145. }
  146. }
  147. device->common.chancnt = readb(device->reg_base + IOAT_CHANCNT_OFFSET);
  148. xfercap_scale = readb(device->reg_base + IOAT_XFERCAP_OFFSET);
  149. xfercap = (xfercap_scale == 0 ? -1 : (1UL << xfercap_scale));
  150. #ifdef CONFIG_I7300_IDLE_IOAT_CHANNEL
  151. if (i7300_idle_platform_probe(NULL, NULL, 1) == 0) {
  152. device->common.chancnt--;
  153. }
  154. #endif
  155. for (i = 0; i < device->common.chancnt; i++) {
  156. ioat_chan = kzalloc(sizeof(*ioat_chan), GFP_KERNEL);
  157. if (!ioat_chan) {
  158. device->common.chancnt = i;
  159. break;
  160. }
  161. ioat_chan->device = device;
  162. ioat_chan->reg_base = device->reg_base + (0x80 * (i + 1));
  163. ioat_chan->xfercap = xfercap;
  164. ioat_chan->desccount = 0;
  165. INIT_DELAYED_WORK(&ioat_chan->work, ioat_dma_chan_reset_part2);
  166. if (ioat_chan->device->version == IOAT_VER_2_0)
  167. writel(IOAT_DCACTRL_CMPL_WRITE_ENABLE |
  168. IOAT_DMA_DCA_ANY_CPU,
  169. ioat_chan->reg_base + IOAT_DCACTRL_OFFSET);
  170. else if (ioat_chan->device->version == IOAT_VER_3_0)
  171. writel(IOAT_DMA_DCA_ANY_CPU,
  172. ioat_chan->reg_base + IOAT_DCACTRL_OFFSET);
  173. spin_lock_init(&ioat_chan->cleanup_lock);
  174. spin_lock_init(&ioat_chan->desc_lock);
  175. INIT_LIST_HEAD(&ioat_chan->free_desc);
  176. INIT_LIST_HEAD(&ioat_chan->used_desc);
  177. /* This should be made common somewhere in dmaengine.c */
  178. ioat_chan->common.device = &device->common;
  179. list_add_tail(&ioat_chan->common.device_node,
  180. &device->common.channels);
  181. device->idx[i] = ioat_chan;
  182. tasklet_init(&ioat_chan->cleanup_task,
  183. ioat_dma_cleanup_tasklet,
  184. (unsigned long) ioat_chan);
  185. tasklet_disable(&ioat_chan->cleanup_task);
  186. }
  187. return device->common.chancnt;
  188. }
  189. /**
  190. * ioat_dma_memcpy_issue_pending - push potentially unrecognized appended
  191. * descriptors to hw
  192. * @chan: DMA channel handle
  193. */
  194. static inline void __ioat1_dma_memcpy_issue_pending(
  195. struct ioat_dma_chan *ioat_chan)
  196. {
  197. ioat_chan->pending = 0;
  198. writeb(IOAT_CHANCMD_APPEND, ioat_chan->reg_base + IOAT1_CHANCMD_OFFSET);
  199. }
  200. static void ioat1_dma_memcpy_issue_pending(struct dma_chan *chan)
  201. {
  202. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  203. if (ioat_chan->pending > 0) {
  204. spin_lock_bh(&ioat_chan->desc_lock);
  205. __ioat1_dma_memcpy_issue_pending(ioat_chan);
  206. spin_unlock_bh(&ioat_chan->desc_lock);
  207. }
  208. }
  209. static inline void __ioat2_dma_memcpy_issue_pending(
  210. struct ioat_dma_chan *ioat_chan)
  211. {
  212. ioat_chan->pending = 0;
  213. writew(ioat_chan->dmacount,
  214. ioat_chan->reg_base + IOAT_CHAN_DMACOUNT_OFFSET);
  215. }
  216. static void ioat2_dma_memcpy_issue_pending(struct dma_chan *chan)
  217. {
  218. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  219. if (ioat_chan->pending > 0) {
  220. spin_lock_bh(&ioat_chan->desc_lock);
  221. __ioat2_dma_memcpy_issue_pending(ioat_chan);
  222. spin_unlock_bh(&ioat_chan->desc_lock);
  223. }
  224. }
  225. /**
  226. * ioat_dma_chan_reset_part2 - reinit the channel after a reset
  227. */
  228. static void ioat_dma_chan_reset_part2(struct work_struct *work)
  229. {
  230. struct ioat_dma_chan *ioat_chan =
  231. container_of(work, struct ioat_dma_chan, work.work);
  232. struct ioat_desc_sw *desc;
  233. spin_lock_bh(&ioat_chan->cleanup_lock);
  234. spin_lock_bh(&ioat_chan->desc_lock);
  235. ioat_chan->completion_virt->low = 0;
  236. ioat_chan->completion_virt->high = 0;
  237. ioat_chan->pending = 0;
  238. /*
  239. * count the descriptors waiting, and be sure to do it
  240. * right for both the CB1 line and the CB2 ring
  241. */
  242. ioat_chan->dmacount = 0;
  243. if (ioat_chan->used_desc.prev) {
  244. desc = to_ioat_desc(ioat_chan->used_desc.prev);
  245. do {
  246. ioat_chan->dmacount++;
  247. desc = to_ioat_desc(desc->node.next);
  248. } while (&desc->node != ioat_chan->used_desc.next);
  249. }
  250. /*
  251. * write the new starting descriptor address
  252. * this puts channel engine into ARMED state
  253. */
  254. desc = to_ioat_desc(ioat_chan->used_desc.prev);
  255. switch (ioat_chan->device->version) {
  256. case IOAT_VER_1_2:
  257. writel(((u64) desc->async_tx.phys) & 0x00000000FFFFFFFF,
  258. ioat_chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW);
  259. writel(((u64) desc->async_tx.phys) >> 32,
  260. ioat_chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH);
  261. writeb(IOAT_CHANCMD_START, ioat_chan->reg_base
  262. + IOAT_CHANCMD_OFFSET(ioat_chan->device->version));
  263. break;
  264. case IOAT_VER_2_0:
  265. writel(((u64) desc->async_tx.phys) & 0x00000000FFFFFFFF,
  266. ioat_chan->reg_base + IOAT2_CHAINADDR_OFFSET_LOW);
  267. writel(((u64) desc->async_tx.phys) >> 32,
  268. ioat_chan->reg_base + IOAT2_CHAINADDR_OFFSET_HIGH);
  269. /* tell the engine to go with what's left to be done */
  270. writew(ioat_chan->dmacount,
  271. ioat_chan->reg_base + IOAT_CHAN_DMACOUNT_OFFSET);
  272. break;
  273. }
  274. dev_err(&ioat_chan->device->pdev->dev,
  275. "chan%d reset - %d descs waiting, %d total desc\n",
  276. chan_num(ioat_chan), ioat_chan->dmacount, ioat_chan->desccount);
  277. spin_unlock_bh(&ioat_chan->desc_lock);
  278. spin_unlock_bh(&ioat_chan->cleanup_lock);
  279. }
  280. /**
  281. * ioat_dma_reset_channel - restart a channel
  282. * @ioat_chan: IOAT DMA channel handle
  283. */
  284. static void ioat_dma_reset_channel(struct ioat_dma_chan *ioat_chan)
  285. {
  286. u32 chansts, chanerr;
  287. if (!ioat_chan->used_desc.prev)
  288. return;
  289. chanerr = readl(ioat_chan->reg_base + IOAT_CHANERR_OFFSET);
  290. chansts = (ioat_chan->completion_virt->low
  291. & IOAT_CHANSTS_DMA_TRANSFER_STATUS);
  292. if (chanerr) {
  293. dev_err(&ioat_chan->device->pdev->dev,
  294. "chan%d, CHANSTS = 0x%08x CHANERR = 0x%04x, clearing\n",
  295. chan_num(ioat_chan), chansts, chanerr);
  296. writel(chanerr, ioat_chan->reg_base + IOAT_CHANERR_OFFSET);
  297. }
  298. /*
  299. * whack it upside the head with a reset
  300. * and wait for things to settle out.
  301. * force the pending count to a really big negative
  302. * to make sure no one forces an issue_pending
  303. * while we're waiting.
  304. */
  305. spin_lock_bh(&ioat_chan->desc_lock);
  306. ioat_chan->pending = INT_MIN;
  307. writeb(IOAT_CHANCMD_RESET,
  308. ioat_chan->reg_base
  309. + IOAT_CHANCMD_OFFSET(ioat_chan->device->version));
  310. spin_unlock_bh(&ioat_chan->desc_lock);
  311. /* schedule the 2nd half instead of sleeping a long time */
  312. schedule_delayed_work(&ioat_chan->work, RESET_DELAY);
  313. }
  314. /**
  315. * ioat_dma_chan_watchdog - watch for stuck channels
  316. */
  317. static void ioat_dma_chan_watchdog(struct work_struct *work)
  318. {
  319. struct ioatdma_device *device =
  320. container_of(work, struct ioatdma_device, work.work);
  321. struct ioat_dma_chan *ioat_chan;
  322. int i;
  323. union {
  324. u64 full;
  325. struct {
  326. u32 low;
  327. u32 high;
  328. };
  329. } completion_hw;
  330. unsigned long compl_desc_addr_hw;
  331. for (i = 0; i < device->common.chancnt; i++) {
  332. ioat_chan = ioat_lookup_chan_by_index(device, i);
  333. if (ioat_chan->device->version == IOAT_VER_1_2
  334. /* have we started processing anything yet */
  335. && ioat_chan->last_completion
  336. /* have we completed any since last watchdog cycle? */
  337. && (ioat_chan->last_completion ==
  338. ioat_chan->watchdog_completion)
  339. /* has TCP stuck on one cookie since last watchdog? */
  340. && (ioat_chan->watchdog_tcp_cookie ==
  341. ioat_chan->watchdog_last_tcp_cookie)
  342. && (ioat_chan->watchdog_tcp_cookie !=
  343. ioat_chan->completed_cookie)
  344. /* is there something in the chain to be processed? */
  345. /* CB1 chain always has at least the last one processed */
  346. && (ioat_chan->used_desc.prev != ioat_chan->used_desc.next)
  347. && ioat_chan->pending == 0) {
  348. /*
  349. * check CHANSTS register for completed
  350. * descriptor address.
  351. * if it is different than completion writeback,
  352. * it is not zero
  353. * and it has changed since the last watchdog
  354. * we can assume that channel
  355. * is still working correctly
  356. * and the problem is in completion writeback.
  357. * update completion writeback
  358. * with actual CHANSTS value
  359. * else
  360. * try resetting the channel
  361. */
  362. completion_hw.low = readl(ioat_chan->reg_base +
  363. IOAT_CHANSTS_OFFSET_LOW(ioat_chan->device->version));
  364. completion_hw.high = readl(ioat_chan->reg_base +
  365. IOAT_CHANSTS_OFFSET_HIGH(ioat_chan->device->version));
  366. #if (BITS_PER_LONG == 64)
  367. compl_desc_addr_hw =
  368. completion_hw.full
  369. & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR;
  370. #else
  371. compl_desc_addr_hw =
  372. completion_hw.low & IOAT_LOW_COMPLETION_MASK;
  373. #endif
  374. if ((compl_desc_addr_hw != 0)
  375. && (compl_desc_addr_hw != ioat_chan->watchdog_completion)
  376. && (compl_desc_addr_hw != ioat_chan->last_compl_desc_addr_hw)) {
  377. ioat_chan->last_compl_desc_addr_hw = compl_desc_addr_hw;
  378. ioat_chan->completion_virt->low = completion_hw.low;
  379. ioat_chan->completion_virt->high = completion_hw.high;
  380. } else {
  381. ioat_dma_reset_channel(ioat_chan);
  382. ioat_chan->watchdog_completion = 0;
  383. ioat_chan->last_compl_desc_addr_hw = 0;
  384. }
  385. /*
  386. * for version 2.0 if there are descriptors yet to be processed
  387. * and the last completed hasn't changed since the last watchdog
  388. * if they haven't hit the pending level
  389. * issue the pending to push them through
  390. * else
  391. * try resetting the channel
  392. */
  393. } else if (ioat_chan->device->version == IOAT_VER_2_0
  394. && ioat_chan->used_desc.prev
  395. && ioat_chan->last_completion
  396. && ioat_chan->last_completion == ioat_chan->watchdog_completion) {
  397. if (ioat_chan->pending < ioat_pending_level)
  398. ioat2_dma_memcpy_issue_pending(&ioat_chan->common);
  399. else {
  400. ioat_dma_reset_channel(ioat_chan);
  401. ioat_chan->watchdog_completion = 0;
  402. }
  403. } else {
  404. ioat_chan->last_compl_desc_addr_hw = 0;
  405. ioat_chan->watchdog_completion
  406. = ioat_chan->last_completion;
  407. }
  408. ioat_chan->watchdog_last_tcp_cookie =
  409. ioat_chan->watchdog_tcp_cookie;
  410. }
  411. schedule_delayed_work(&device->work, WATCHDOG_DELAY);
  412. }
  413. static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx)
  414. {
  415. struct ioat_dma_chan *ioat_chan = to_ioat_chan(tx->chan);
  416. struct ioat_desc_sw *first = tx_to_ioat_desc(tx);
  417. struct ioat_desc_sw *prev, *new;
  418. struct ioat_dma_descriptor *hw;
  419. dma_cookie_t cookie;
  420. LIST_HEAD(new_chain);
  421. u32 copy;
  422. size_t len;
  423. dma_addr_t src, dst;
  424. unsigned long orig_flags;
  425. unsigned int desc_count = 0;
  426. /* src and dest and len are stored in the initial descriptor */
  427. len = first->len;
  428. src = first->src;
  429. dst = first->dst;
  430. orig_flags = first->async_tx.flags;
  431. new = first;
  432. spin_lock_bh(&ioat_chan->desc_lock);
  433. prev = to_ioat_desc(ioat_chan->used_desc.prev);
  434. prefetch(prev->hw);
  435. do {
  436. copy = min_t(size_t, len, ioat_chan->xfercap);
  437. async_tx_ack(&new->async_tx);
  438. hw = new->hw;
  439. hw->size = copy;
  440. hw->ctl = 0;
  441. hw->src_addr = src;
  442. hw->dst_addr = dst;
  443. hw->next = 0;
  444. /* chain together the physical address list for the HW */
  445. wmb();
  446. prev->hw->next = (u64) new->async_tx.phys;
  447. len -= copy;
  448. dst += copy;
  449. src += copy;
  450. list_add_tail(&new->node, &new_chain);
  451. desc_count++;
  452. prev = new;
  453. } while (len && (new = ioat1_dma_get_next_descriptor(ioat_chan)));
  454. if (!new) {
  455. dev_err(&ioat_chan->device->pdev->dev,
  456. "tx submit failed\n");
  457. spin_unlock_bh(&ioat_chan->desc_lock);
  458. return -ENOMEM;
  459. }
  460. hw->ctl = IOAT_DMA_DESCRIPTOR_CTL_CP_STS;
  461. if (first->async_tx.callback) {
  462. hw->ctl |= IOAT_DMA_DESCRIPTOR_CTL_INT_GN;
  463. if (first != new) {
  464. /* move callback into to last desc */
  465. new->async_tx.callback = first->async_tx.callback;
  466. new->async_tx.callback_param
  467. = first->async_tx.callback_param;
  468. first->async_tx.callback = NULL;
  469. first->async_tx.callback_param = NULL;
  470. }
  471. }
  472. new->tx_cnt = desc_count;
  473. new->async_tx.flags = orig_flags; /* client is in control of this ack */
  474. /* store the original values for use in later cleanup */
  475. if (new != first) {
  476. new->src = first->src;
  477. new->dst = first->dst;
  478. new->len = first->len;
  479. }
  480. /* cookie incr and addition to used_list must be atomic */
  481. cookie = ioat_chan->common.cookie;
  482. cookie++;
  483. if (cookie < 0)
  484. cookie = 1;
  485. ioat_chan->common.cookie = new->async_tx.cookie = cookie;
  486. /* write address into NextDescriptor field of last desc in chain */
  487. to_ioat_desc(ioat_chan->used_desc.prev)->hw->next =
  488. first->async_tx.phys;
  489. list_splice_tail(&new_chain, &ioat_chan->used_desc);
  490. ioat_chan->dmacount += desc_count;
  491. ioat_chan->pending += desc_count;
  492. if (ioat_chan->pending >= ioat_pending_level)
  493. __ioat1_dma_memcpy_issue_pending(ioat_chan);
  494. spin_unlock_bh(&ioat_chan->desc_lock);
  495. return cookie;
  496. }
  497. static dma_cookie_t ioat2_tx_submit(struct dma_async_tx_descriptor *tx)
  498. {
  499. struct ioat_dma_chan *ioat_chan = to_ioat_chan(tx->chan);
  500. struct ioat_desc_sw *first = tx_to_ioat_desc(tx);
  501. struct ioat_desc_sw *new;
  502. struct ioat_dma_descriptor *hw;
  503. dma_cookie_t cookie;
  504. u32 copy;
  505. size_t len;
  506. dma_addr_t src, dst;
  507. unsigned long orig_flags;
  508. unsigned int desc_count = 0;
  509. /* src and dest and len are stored in the initial descriptor */
  510. len = first->len;
  511. src = first->src;
  512. dst = first->dst;
  513. orig_flags = first->async_tx.flags;
  514. new = first;
  515. /*
  516. * ioat_chan->desc_lock is still in force in version 2 path
  517. * it gets unlocked at end of this function
  518. */
  519. do {
  520. copy = min_t(size_t, len, ioat_chan->xfercap);
  521. async_tx_ack(&new->async_tx);
  522. hw = new->hw;
  523. hw->size = copy;
  524. hw->ctl = 0;
  525. hw->src_addr = src;
  526. hw->dst_addr = dst;
  527. len -= copy;
  528. dst += copy;
  529. src += copy;
  530. desc_count++;
  531. } while (len && (new = ioat2_dma_get_next_descriptor(ioat_chan)));
  532. if (!new) {
  533. dev_err(&ioat_chan->device->pdev->dev,
  534. "tx submit failed\n");
  535. spin_unlock_bh(&ioat_chan->desc_lock);
  536. return -ENOMEM;
  537. }
  538. hw->ctl |= IOAT_DMA_DESCRIPTOR_CTL_CP_STS;
  539. if (first->async_tx.callback) {
  540. hw->ctl |= IOAT_DMA_DESCRIPTOR_CTL_INT_GN;
  541. if (first != new) {
  542. /* move callback into to last desc */
  543. new->async_tx.callback = first->async_tx.callback;
  544. new->async_tx.callback_param
  545. = first->async_tx.callback_param;
  546. first->async_tx.callback = NULL;
  547. first->async_tx.callback_param = NULL;
  548. }
  549. }
  550. new->tx_cnt = desc_count;
  551. new->async_tx.flags = orig_flags; /* client is in control of this ack */
  552. /* store the original values for use in later cleanup */
  553. if (new != first) {
  554. new->src = first->src;
  555. new->dst = first->dst;
  556. new->len = first->len;
  557. }
  558. /* cookie incr and addition to used_list must be atomic */
  559. cookie = ioat_chan->common.cookie;
  560. cookie++;
  561. if (cookie < 0)
  562. cookie = 1;
  563. ioat_chan->common.cookie = new->async_tx.cookie = cookie;
  564. ioat_chan->dmacount += desc_count;
  565. ioat_chan->pending += desc_count;
  566. if (ioat_chan->pending >= ioat_pending_level)
  567. __ioat2_dma_memcpy_issue_pending(ioat_chan);
  568. spin_unlock_bh(&ioat_chan->desc_lock);
  569. return cookie;
  570. }
  571. /**
  572. * ioat_dma_alloc_descriptor - allocate and return a sw and hw descriptor pair
  573. * @ioat_chan: the channel supplying the memory pool for the descriptors
  574. * @flags: allocation flags
  575. */
  576. static struct ioat_desc_sw *ioat_dma_alloc_descriptor(
  577. struct ioat_dma_chan *ioat_chan,
  578. gfp_t flags)
  579. {
  580. struct ioat_dma_descriptor *desc;
  581. struct ioat_desc_sw *desc_sw;
  582. struct ioatdma_device *ioatdma_device;
  583. dma_addr_t phys;
  584. ioatdma_device = to_ioatdma_device(ioat_chan->common.device);
  585. desc = pci_pool_alloc(ioatdma_device->dma_pool, flags, &phys);
  586. if (unlikely(!desc))
  587. return NULL;
  588. desc_sw = kzalloc(sizeof(*desc_sw), flags);
  589. if (unlikely(!desc_sw)) {
  590. pci_pool_free(ioatdma_device->dma_pool, desc, phys);
  591. return NULL;
  592. }
  593. memset(desc, 0, sizeof(*desc));
  594. dma_async_tx_descriptor_init(&desc_sw->async_tx, &ioat_chan->common);
  595. switch (ioat_chan->device->version) {
  596. case IOAT_VER_1_2:
  597. desc_sw->async_tx.tx_submit = ioat1_tx_submit;
  598. break;
  599. case IOAT_VER_2_0:
  600. case IOAT_VER_3_0:
  601. desc_sw->async_tx.tx_submit = ioat2_tx_submit;
  602. break;
  603. }
  604. desc_sw->hw = desc;
  605. desc_sw->async_tx.phys = phys;
  606. return desc_sw;
  607. }
  608. static int ioat_initial_desc_count = 256;
  609. module_param(ioat_initial_desc_count, int, 0644);
  610. MODULE_PARM_DESC(ioat_initial_desc_count,
  611. "initial descriptors per channel (default: 256)");
  612. /**
  613. * ioat2_dma_massage_chan_desc - link the descriptors into a circle
  614. * @ioat_chan: the channel to be massaged
  615. */
  616. static void ioat2_dma_massage_chan_desc(struct ioat_dma_chan *ioat_chan)
  617. {
  618. struct ioat_desc_sw *desc, *_desc;
  619. /* setup used_desc */
  620. ioat_chan->used_desc.next = ioat_chan->free_desc.next;
  621. ioat_chan->used_desc.prev = NULL;
  622. /* pull free_desc out of the circle so that every node is a hw
  623. * descriptor, but leave it pointing to the list
  624. */
  625. ioat_chan->free_desc.prev->next = ioat_chan->free_desc.next;
  626. ioat_chan->free_desc.next->prev = ioat_chan->free_desc.prev;
  627. /* circle link the hw descriptors */
  628. desc = to_ioat_desc(ioat_chan->free_desc.next);
  629. desc->hw->next = to_ioat_desc(desc->node.next)->async_tx.phys;
  630. list_for_each_entry_safe(desc, _desc, ioat_chan->free_desc.next, node) {
  631. desc->hw->next = to_ioat_desc(desc->node.next)->async_tx.phys;
  632. }
  633. }
  634. /**
  635. * ioat_dma_alloc_chan_resources - returns the number of allocated descriptors
  636. * @chan: the channel to be filled out
  637. */
  638. static int ioat_dma_alloc_chan_resources(struct dma_chan *chan)
  639. {
  640. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  641. struct ioat_desc_sw *desc;
  642. u16 chanctrl;
  643. u32 chanerr;
  644. int i;
  645. LIST_HEAD(tmp_list);
  646. /* have we already been set up? */
  647. if (!list_empty(&ioat_chan->free_desc))
  648. return ioat_chan->desccount;
  649. /* Setup register to interrupt and write completion status on error */
  650. chanctrl = IOAT_CHANCTRL_ERR_INT_EN |
  651. IOAT_CHANCTRL_ANY_ERR_ABORT_EN |
  652. IOAT_CHANCTRL_ERR_COMPLETION_EN;
  653. writew(chanctrl, ioat_chan->reg_base + IOAT_CHANCTRL_OFFSET);
  654. chanerr = readl(ioat_chan->reg_base + IOAT_CHANERR_OFFSET);
  655. if (chanerr) {
  656. dev_err(&ioat_chan->device->pdev->dev,
  657. "CHANERR = %x, clearing\n", chanerr);
  658. writel(chanerr, ioat_chan->reg_base + IOAT_CHANERR_OFFSET);
  659. }
  660. /* Allocate descriptors */
  661. for (i = 0; i < ioat_initial_desc_count; i++) {
  662. desc = ioat_dma_alloc_descriptor(ioat_chan, GFP_KERNEL);
  663. if (!desc) {
  664. dev_err(&ioat_chan->device->pdev->dev,
  665. "Only %d initial descriptors\n", i);
  666. break;
  667. }
  668. list_add_tail(&desc->node, &tmp_list);
  669. }
  670. spin_lock_bh(&ioat_chan->desc_lock);
  671. ioat_chan->desccount = i;
  672. list_splice(&tmp_list, &ioat_chan->free_desc);
  673. if (ioat_chan->device->version != IOAT_VER_1_2)
  674. ioat2_dma_massage_chan_desc(ioat_chan);
  675. spin_unlock_bh(&ioat_chan->desc_lock);
  676. /* allocate a completion writeback area */
  677. /* doing 2 32bit writes to mmio since 1 64b write doesn't work */
  678. ioat_chan->completion_virt =
  679. pci_pool_alloc(ioat_chan->device->completion_pool,
  680. GFP_KERNEL,
  681. &ioat_chan->completion_addr);
  682. memset(ioat_chan->completion_virt, 0,
  683. sizeof(*ioat_chan->completion_virt));
  684. writel(((u64) ioat_chan->completion_addr) & 0x00000000FFFFFFFF,
  685. ioat_chan->reg_base + IOAT_CHANCMP_OFFSET_LOW);
  686. writel(((u64) ioat_chan->completion_addr) >> 32,
  687. ioat_chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
  688. tasklet_enable(&ioat_chan->cleanup_task);
  689. ioat_dma_start_null_desc(ioat_chan); /* give chain to dma device */
  690. return ioat_chan->desccount;
  691. }
  692. /**
  693. * ioat_dma_free_chan_resources - release all the descriptors
  694. * @chan: the channel to be cleaned
  695. */
  696. static void ioat_dma_free_chan_resources(struct dma_chan *chan)
  697. {
  698. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  699. struct ioatdma_device *ioatdma_device = to_ioatdma_device(chan->device);
  700. struct ioat_desc_sw *desc, *_desc;
  701. int in_use_descs = 0;
  702. /* Before freeing channel resources first check
  703. * if they have been previously allocated for this channel.
  704. */
  705. if (ioat_chan->desccount == 0)
  706. return;
  707. tasklet_disable(&ioat_chan->cleanup_task);
  708. ioat_dma_memcpy_cleanup(ioat_chan);
  709. /* Delay 100ms after reset to allow internal DMA logic to quiesce
  710. * before removing DMA descriptor resources.
  711. */
  712. writeb(IOAT_CHANCMD_RESET,
  713. ioat_chan->reg_base
  714. + IOAT_CHANCMD_OFFSET(ioat_chan->device->version));
  715. mdelay(100);
  716. spin_lock_bh(&ioat_chan->desc_lock);
  717. switch (ioat_chan->device->version) {
  718. case IOAT_VER_1_2:
  719. list_for_each_entry_safe(desc, _desc,
  720. &ioat_chan->used_desc, node) {
  721. in_use_descs++;
  722. list_del(&desc->node);
  723. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  724. desc->async_tx.phys);
  725. kfree(desc);
  726. }
  727. list_for_each_entry_safe(desc, _desc,
  728. &ioat_chan->free_desc, node) {
  729. list_del(&desc->node);
  730. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  731. desc->async_tx.phys);
  732. kfree(desc);
  733. }
  734. break;
  735. case IOAT_VER_2_0:
  736. case IOAT_VER_3_0:
  737. list_for_each_entry_safe(desc, _desc,
  738. ioat_chan->free_desc.next, node) {
  739. list_del(&desc->node);
  740. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  741. desc->async_tx.phys);
  742. kfree(desc);
  743. }
  744. desc = to_ioat_desc(ioat_chan->free_desc.next);
  745. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  746. desc->async_tx.phys);
  747. kfree(desc);
  748. INIT_LIST_HEAD(&ioat_chan->free_desc);
  749. INIT_LIST_HEAD(&ioat_chan->used_desc);
  750. break;
  751. }
  752. spin_unlock_bh(&ioat_chan->desc_lock);
  753. pci_pool_free(ioatdma_device->completion_pool,
  754. ioat_chan->completion_virt,
  755. ioat_chan->completion_addr);
  756. /* one is ok since we left it on there on purpose */
  757. if (in_use_descs > 1)
  758. dev_err(&ioat_chan->device->pdev->dev,
  759. "Freeing %d in use descriptors!\n",
  760. in_use_descs - 1);
  761. ioat_chan->last_completion = ioat_chan->completion_addr = 0;
  762. ioat_chan->pending = 0;
  763. ioat_chan->dmacount = 0;
  764. ioat_chan->desccount = 0;
  765. ioat_chan->watchdog_completion = 0;
  766. ioat_chan->last_compl_desc_addr_hw = 0;
  767. ioat_chan->watchdog_tcp_cookie =
  768. ioat_chan->watchdog_last_tcp_cookie = 0;
  769. }
  770. /**
  771. * ioat_dma_get_next_descriptor - return the next available descriptor
  772. * @ioat_chan: IOAT DMA channel handle
  773. *
  774. * Gets the next descriptor from the chain, and must be called with the
  775. * channel's desc_lock held. Allocates more descriptors if the channel
  776. * has run out.
  777. */
  778. static struct ioat_desc_sw *
  779. ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan)
  780. {
  781. struct ioat_desc_sw *new;
  782. if (!list_empty(&ioat_chan->free_desc)) {
  783. new = to_ioat_desc(ioat_chan->free_desc.next);
  784. list_del(&new->node);
  785. } else {
  786. /* try to get another desc */
  787. new = ioat_dma_alloc_descriptor(ioat_chan, GFP_ATOMIC);
  788. if (!new) {
  789. dev_err(&ioat_chan->device->pdev->dev,
  790. "alloc failed\n");
  791. return NULL;
  792. }
  793. }
  794. prefetch(new->hw);
  795. return new;
  796. }
  797. static struct ioat_desc_sw *
  798. ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan)
  799. {
  800. struct ioat_desc_sw *new;
  801. /*
  802. * used.prev points to where to start processing
  803. * used.next points to next free descriptor
  804. * if used.prev == NULL, there are none waiting to be processed
  805. * if used.next == used.prev.prev, there is only one free descriptor,
  806. * and we need to use it to as a noop descriptor before
  807. * linking in a new set of descriptors, since the device
  808. * has probably already read the pointer to it
  809. */
  810. if (ioat_chan->used_desc.prev &&
  811. ioat_chan->used_desc.next == ioat_chan->used_desc.prev->prev) {
  812. struct ioat_desc_sw *desc;
  813. struct ioat_desc_sw *noop_desc;
  814. int i;
  815. /* set up the noop descriptor */
  816. noop_desc = to_ioat_desc(ioat_chan->used_desc.next);
  817. /* set size to non-zero value (channel returns error when size is 0) */
  818. noop_desc->hw->size = NULL_DESC_BUFFER_SIZE;
  819. noop_desc->hw->ctl = IOAT_DMA_DESCRIPTOR_NUL;
  820. noop_desc->hw->src_addr = 0;
  821. noop_desc->hw->dst_addr = 0;
  822. ioat_chan->used_desc.next = ioat_chan->used_desc.next->next;
  823. ioat_chan->pending++;
  824. ioat_chan->dmacount++;
  825. /* try to get a few more descriptors */
  826. for (i = 16; i; i--) {
  827. desc = ioat_dma_alloc_descriptor(ioat_chan, GFP_ATOMIC);
  828. if (!desc) {
  829. dev_err(&ioat_chan->device->pdev->dev,
  830. "alloc failed\n");
  831. break;
  832. }
  833. list_add_tail(&desc->node, ioat_chan->used_desc.next);
  834. desc->hw->next
  835. = to_ioat_desc(desc->node.next)->async_tx.phys;
  836. to_ioat_desc(desc->node.prev)->hw->next
  837. = desc->async_tx.phys;
  838. ioat_chan->desccount++;
  839. }
  840. ioat_chan->used_desc.next = noop_desc->node.next;
  841. }
  842. new = to_ioat_desc(ioat_chan->used_desc.next);
  843. prefetch(new);
  844. ioat_chan->used_desc.next = new->node.next;
  845. if (ioat_chan->used_desc.prev == NULL)
  846. ioat_chan->used_desc.prev = &new->node;
  847. prefetch(new->hw);
  848. return new;
  849. }
  850. static struct ioat_desc_sw *ioat_dma_get_next_descriptor(
  851. struct ioat_dma_chan *ioat_chan)
  852. {
  853. if (!ioat_chan)
  854. return NULL;
  855. switch (ioat_chan->device->version) {
  856. case IOAT_VER_1_2:
  857. return ioat1_dma_get_next_descriptor(ioat_chan);
  858. case IOAT_VER_2_0:
  859. case IOAT_VER_3_0:
  860. return ioat2_dma_get_next_descriptor(ioat_chan);
  861. }
  862. return NULL;
  863. }
  864. static struct dma_async_tx_descriptor *ioat1_dma_prep_memcpy(
  865. struct dma_chan *chan,
  866. dma_addr_t dma_dest,
  867. dma_addr_t dma_src,
  868. size_t len,
  869. unsigned long flags)
  870. {
  871. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  872. struct ioat_desc_sw *new;
  873. spin_lock_bh(&ioat_chan->desc_lock);
  874. new = ioat_dma_get_next_descriptor(ioat_chan);
  875. spin_unlock_bh(&ioat_chan->desc_lock);
  876. if (new) {
  877. new->len = len;
  878. new->dst = dma_dest;
  879. new->src = dma_src;
  880. new->async_tx.flags = flags;
  881. return &new->async_tx;
  882. } else {
  883. dev_err(&ioat_chan->device->pdev->dev,
  884. "chan%d - get_next_desc failed: %d descs waiting, %d total desc\n",
  885. chan_num(ioat_chan), ioat_chan->dmacount, ioat_chan->desccount);
  886. return NULL;
  887. }
  888. }
  889. static struct dma_async_tx_descriptor *ioat2_dma_prep_memcpy(
  890. struct dma_chan *chan,
  891. dma_addr_t dma_dest,
  892. dma_addr_t dma_src,
  893. size_t len,
  894. unsigned long flags)
  895. {
  896. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  897. struct ioat_desc_sw *new;
  898. spin_lock_bh(&ioat_chan->desc_lock);
  899. new = ioat2_dma_get_next_descriptor(ioat_chan);
  900. /*
  901. * leave ioat_chan->desc_lock set in ioat 2 path
  902. * it will get unlocked at end of tx_submit
  903. */
  904. if (new) {
  905. new->len = len;
  906. new->dst = dma_dest;
  907. new->src = dma_src;
  908. new->async_tx.flags = flags;
  909. return &new->async_tx;
  910. } else {
  911. spin_unlock_bh(&ioat_chan->desc_lock);
  912. dev_err(&ioat_chan->device->pdev->dev,
  913. "chan%d - get_next_desc failed: %d descs waiting, %d total desc\n",
  914. chan_num(ioat_chan), ioat_chan->dmacount, ioat_chan->desccount);
  915. return NULL;
  916. }
  917. }
  918. static void ioat_dma_cleanup_tasklet(unsigned long data)
  919. {
  920. struct ioat_dma_chan *chan = (void *)data;
  921. ioat_dma_memcpy_cleanup(chan);
  922. writew(IOAT_CHANCTRL_INT_DISABLE,
  923. chan->reg_base + IOAT_CHANCTRL_OFFSET);
  924. }
  925. static void
  926. ioat_dma_unmap(struct ioat_dma_chan *ioat_chan, struct ioat_desc_sw *desc)
  927. {
  928. if (!(desc->async_tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
  929. if (desc->async_tx.flags & DMA_COMPL_DEST_UNMAP_SINGLE)
  930. pci_unmap_single(ioat_chan->device->pdev,
  931. pci_unmap_addr(desc, dst),
  932. pci_unmap_len(desc, len),
  933. PCI_DMA_FROMDEVICE);
  934. else
  935. pci_unmap_page(ioat_chan->device->pdev,
  936. pci_unmap_addr(desc, dst),
  937. pci_unmap_len(desc, len),
  938. PCI_DMA_FROMDEVICE);
  939. }
  940. if (!(desc->async_tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
  941. if (desc->async_tx.flags & DMA_COMPL_SRC_UNMAP_SINGLE)
  942. pci_unmap_single(ioat_chan->device->pdev,
  943. pci_unmap_addr(desc, src),
  944. pci_unmap_len(desc, len),
  945. PCI_DMA_TODEVICE);
  946. else
  947. pci_unmap_page(ioat_chan->device->pdev,
  948. pci_unmap_addr(desc, src),
  949. pci_unmap_len(desc, len),
  950. PCI_DMA_TODEVICE);
  951. }
  952. }
  953. /**
  954. * ioat_dma_memcpy_cleanup - cleanup up finished descriptors
  955. * @chan: ioat channel to be cleaned up
  956. */
  957. static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *ioat_chan)
  958. {
  959. unsigned long phys_complete;
  960. struct ioat_desc_sw *desc, *_desc;
  961. dma_cookie_t cookie = 0;
  962. unsigned long desc_phys;
  963. struct ioat_desc_sw *latest_desc;
  964. prefetch(ioat_chan->completion_virt);
  965. if (!spin_trylock_bh(&ioat_chan->cleanup_lock))
  966. return;
  967. /* The completion writeback can happen at any time,
  968. so reads by the driver need to be atomic operations
  969. The descriptor physical addresses are limited to 32-bits
  970. when the CPU can only do a 32-bit mov */
  971. #if (BITS_PER_LONG == 64)
  972. phys_complete =
  973. ioat_chan->completion_virt->full
  974. & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR;
  975. #else
  976. phys_complete =
  977. ioat_chan->completion_virt->low & IOAT_LOW_COMPLETION_MASK;
  978. #endif
  979. if ((ioat_chan->completion_virt->full
  980. & IOAT_CHANSTS_DMA_TRANSFER_STATUS) ==
  981. IOAT_CHANSTS_DMA_TRANSFER_STATUS_HALTED) {
  982. dev_err(&ioat_chan->device->pdev->dev,
  983. "Channel halted, chanerr = %x\n",
  984. readl(ioat_chan->reg_base + IOAT_CHANERR_OFFSET));
  985. /* TODO do something to salvage the situation */
  986. }
  987. if (phys_complete == ioat_chan->last_completion) {
  988. spin_unlock_bh(&ioat_chan->cleanup_lock);
  989. /*
  990. * perhaps we're stuck so hard that the watchdog can't go off?
  991. * try to catch it after 2 seconds
  992. */
  993. if (ioat_chan->device->version != IOAT_VER_3_0) {
  994. if (time_after(jiffies,
  995. ioat_chan->last_completion_time + HZ*WATCHDOG_DELAY)) {
  996. ioat_dma_chan_watchdog(&(ioat_chan->device->work.work));
  997. ioat_chan->last_completion_time = jiffies;
  998. }
  999. }
  1000. return;
  1001. }
  1002. ioat_chan->last_completion_time = jiffies;
  1003. cookie = 0;
  1004. if (!spin_trylock_bh(&ioat_chan->desc_lock)) {
  1005. spin_unlock_bh(&ioat_chan->cleanup_lock);
  1006. return;
  1007. }
  1008. switch (ioat_chan->device->version) {
  1009. case IOAT_VER_1_2:
  1010. list_for_each_entry_safe(desc, _desc,
  1011. &ioat_chan->used_desc, node) {
  1012. /*
  1013. * Incoming DMA requests may use multiple descriptors,
  1014. * due to exceeding xfercap, perhaps. If so, only the
  1015. * last one will have a cookie, and require unmapping.
  1016. */
  1017. if (desc->async_tx.cookie) {
  1018. cookie = desc->async_tx.cookie;
  1019. ioat_dma_unmap(ioat_chan, desc);
  1020. if (desc->async_tx.callback) {
  1021. desc->async_tx.callback(desc->async_tx.callback_param);
  1022. desc->async_tx.callback = NULL;
  1023. }
  1024. }
  1025. if (desc->async_tx.phys != phys_complete) {
  1026. /*
  1027. * a completed entry, but not the last, so clean
  1028. * up if the client is done with the descriptor
  1029. */
  1030. if (async_tx_test_ack(&desc->async_tx)) {
  1031. list_move_tail(&desc->node,
  1032. &ioat_chan->free_desc);
  1033. } else
  1034. desc->async_tx.cookie = 0;
  1035. } else {
  1036. /*
  1037. * last used desc. Do not remove, so we can
  1038. * append from it, but don't look at it next
  1039. * time, either
  1040. */
  1041. desc->async_tx.cookie = 0;
  1042. /* TODO check status bits? */
  1043. break;
  1044. }
  1045. }
  1046. break;
  1047. case IOAT_VER_2_0:
  1048. case IOAT_VER_3_0:
  1049. /* has some other thread has already cleaned up? */
  1050. if (ioat_chan->used_desc.prev == NULL)
  1051. break;
  1052. /* work backwards to find latest finished desc */
  1053. desc = to_ioat_desc(ioat_chan->used_desc.next);
  1054. latest_desc = NULL;
  1055. do {
  1056. desc = to_ioat_desc(desc->node.prev);
  1057. desc_phys = (unsigned long)desc->async_tx.phys
  1058. & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR;
  1059. if (desc_phys == phys_complete) {
  1060. latest_desc = desc;
  1061. break;
  1062. }
  1063. } while (&desc->node != ioat_chan->used_desc.prev);
  1064. if (latest_desc != NULL) {
  1065. /* work forwards to clear finished descriptors */
  1066. for (desc = to_ioat_desc(ioat_chan->used_desc.prev);
  1067. &desc->node != latest_desc->node.next &&
  1068. &desc->node != ioat_chan->used_desc.next;
  1069. desc = to_ioat_desc(desc->node.next)) {
  1070. if (desc->async_tx.cookie) {
  1071. cookie = desc->async_tx.cookie;
  1072. desc->async_tx.cookie = 0;
  1073. ioat_dma_unmap(ioat_chan, desc);
  1074. if (desc->async_tx.callback) {
  1075. desc->async_tx.callback(desc->async_tx.callback_param);
  1076. desc->async_tx.callback = NULL;
  1077. }
  1078. }
  1079. }
  1080. /* move used.prev up beyond those that are finished */
  1081. if (&desc->node == ioat_chan->used_desc.next)
  1082. ioat_chan->used_desc.prev = NULL;
  1083. else
  1084. ioat_chan->used_desc.prev = &desc->node;
  1085. }
  1086. break;
  1087. }
  1088. spin_unlock_bh(&ioat_chan->desc_lock);
  1089. ioat_chan->last_completion = phys_complete;
  1090. if (cookie != 0)
  1091. ioat_chan->completed_cookie = cookie;
  1092. spin_unlock_bh(&ioat_chan->cleanup_lock);
  1093. }
  1094. /**
  1095. * ioat_dma_is_complete - poll the status of a IOAT DMA transaction
  1096. * @chan: IOAT DMA channel handle
  1097. * @cookie: DMA transaction identifier
  1098. * @done: if not %NULL, updated with last completed transaction
  1099. * @used: if not %NULL, updated with last used transaction
  1100. */
  1101. static enum dma_status ioat_dma_is_complete(struct dma_chan *chan,
  1102. dma_cookie_t cookie,
  1103. dma_cookie_t *done,
  1104. dma_cookie_t *used)
  1105. {
  1106. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  1107. dma_cookie_t last_used;
  1108. dma_cookie_t last_complete;
  1109. enum dma_status ret;
  1110. last_used = chan->cookie;
  1111. last_complete = ioat_chan->completed_cookie;
  1112. ioat_chan->watchdog_tcp_cookie = cookie;
  1113. if (done)
  1114. *done = last_complete;
  1115. if (used)
  1116. *used = last_used;
  1117. ret = dma_async_is_complete(cookie, last_complete, last_used);
  1118. if (ret == DMA_SUCCESS)
  1119. return ret;
  1120. ioat_dma_memcpy_cleanup(ioat_chan);
  1121. last_used = chan->cookie;
  1122. last_complete = ioat_chan->completed_cookie;
  1123. if (done)
  1124. *done = last_complete;
  1125. if (used)
  1126. *used = last_used;
  1127. return dma_async_is_complete(cookie, last_complete, last_used);
  1128. }
  1129. static void ioat_dma_start_null_desc(struct ioat_dma_chan *ioat_chan)
  1130. {
  1131. struct ioat_desc_sw *desc;
  1132. spin_lock_bh(&ioat_chan->desc_lock);
  1133. desc = ioat_dma_get_next_descriptor(ioat_chan);
  1134. if (!desc) {
  1135. dev_err(&ioat_chan->device->pdev->dev,
  1136. "Unable to start null desc - get next desc failed\n");
  1137. spin_unlock_bh(&ioat_chan->desc_lock);
  1138. return;
  1139. }
  1140. desc->hw->ctl = IOAT_DMA_DESCRIPTOR_NUL
  1141. | IOAT_DMA_DESCRIPTOR_CTL_INT_GN
  1142. | IOAT_DMA_DESCRIPTOR_CTL_CP_STS;
  1143. /* set size to non-zero value (channel returns error when size is 0) */
  1144. desc->hw->size = NULL_DESC_BUFFER_SIZE;
  1145. desc->hw->src_addr = 0;
  1146. desc->hw->dst_addr = 0;
  1147. async_tx_ack(&desc->async_tx);
  1148. switch (ioat_chan->device->version) {
  1149. case IOAT_VER_1_2:
  1150. desc->hw->next = 0;
  1151. list_add_tail(&desc->node, &ioat_chan->used_desc);
  1152. writel(((u64) desc->async_tx.phys) & 0x00000000FFFFFFFF,
  1153. ioat_chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW);
  1154. writel(((u64) desc->async_tx.phys) >> 32,
  1155. ioat_chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH);
  1156. writeb(IOAT_CHANCMD_START, ioat_chan->reg_base
  1157. + IOAT_CHANCMD_OFFSET(ioat_chan->device->version));
  1158. break;
  1159. case IOAT_VER_2_0:
  1160. case IOAT_VER_3_0:
  1161. writel(((u64) desc->async_tx.phys) & 0x00000000FFFFFFFF,
  1162. ioat_chan->reg_base + IOAT2_CHAINADDR_OFFSET_LOW);
  1163. writel(((u64) desc->async_tx.phys) >> 32,
  1164. ioat_chan->reg_base + IOAT2_CHAINADDR_OFFSET_HIGH);
  1165. ioat_chan->dmacount++;
  1166. __ioat2_dma_memcpy_issue_pending(ioat_chan);
  1167. break;
  1168. }
  1169. spin_unlock_bh(&ioat_chan->desc_lock);
  1170. }
  1171. /*
  1172. * Perform a IOAT transaction to verify the HW works.
  1173. */
  1174. #define IOAT_TEST_SIZE 2000
  1175. static void ioat_dma_test_callback(void *dma_async_param)
  1176. {
  1177. struct completion *cmp = dma_async_param;
  1178. complete(cmp);
  1179. }
  1180. /**
  1181. * ioat_dma_self_test - Perform a IOAT transaction to verify the HW works.
  1182. * @device: device to be tested
  1183. */
  1184. static int ioat_dma_self_test(struct ioatdma_device *device)
  1185. {
  1186. int i;
  1187. u8 *src;
  1188. u8 *dest;
  1189. struct dma_chan *dma_chan;
  1190. struct dma_async_tx_descriptor *tx;
  1191. dma_addr_t dma_dest, dma_src;
  1192. dma_cookie_t cookie;
  1193. int err = 0;
  1194. struct completion cmp;
  1195. unsigned long tmo;
  1196. unsigned long flags;
  1197. src = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
  1198. if (!src)
  1199. return -ENOMEM;
  1200. dest = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
  1201. if (!dest) {
  1202. kfree(src);
  1203. return -ENOMEM;
  1204. }
  1205. /* Fill in src buffer */
  1206. for (i = 0; i < IOAT_TEST_SIZE; i++)
  1207. src[i] = (u8)i;
  1208. /* Start copy, using first DMA channel */
  1209. dma_chan = container_of(device->common.channels.next,
  1210. struct dma_chan,
  1211. device_node);
  1212. if (device->common.device_alloc_chan_resources(dma_chan) < 1) {
  1213. dev_err(&device->pdev->dev,
  1214. "selftest cannot allocate chan resource\n");
  1215. err = -ENODEV;
  1216. goto out;
  1217. }
  1218. dma_src = dma_map_single(dma_chan->device->dev, src, IOAT_TEST_SIZE,
  1219. DMA_TO_DEVICE);
  1220. dma_dest = dma_map_single(dma_chan->device->dev, dest, IOAT_TEST_SIZE,
  1221. DMA_FROM_DEVICE);
  1222. flags = DMA_COMPL_SRC_UNMAP_SINGLE | DMA_COMPL_DEST_UNMAP_SINGLE;
  1223. tx = device->common.device_prep_dma_memcpy(dma_chan, dma_dest, dma_src,
  1224. IOAT_TEST_SIZE, flags);
  1225. if (!tx) {
  1226. dev_err(&device->pdev->dev,
  1227. "Self-test prep failed, disabling\n");
  1228. err = -ENODEV;
  1229. goto free_resources;
  1230. }
  1231. async_tx_ack(tx);
  1232. init_completion(&cmp);
  1233. tx->callback = ioat_dma_test_callback;
  1234. tx->callback_param = &cmp;
  1235. cookie = tx->tx_submit(tx);
  1236. if (cookie < 0) {
  1237. dev_err(&device->pdev->dev,
  1238. "Self-test setup failed, disabling\n");
  1239. err = -ENODEV;
  1240. goto free_resources;
  1241. }
  1242. device->common.device_issue_pending(dma_chan);
  1243. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1244. if (tmo == 0 ||
  1245. device->common.device_is_tx_complete(dma_chan, cookie, NULL, NULL)
  1246. != DMA_SUCCESS) {
  1247. dev_err(&device->pdev->dev,
  1248. "Self-test copy timed out, disabling\n");
  1249. err = -ENODEV;
  1250. goto free_resources;
  1251. }
  1252. if (memcmp(src, dest, IOAT_TEST_SIZE)) {
  1253. dev_err(&device->pdev->dev,
  1254. "Self-test copy failed compare, disabling\n");
  1255. err = -ENODEV;
  1256. goto free_resources;
  1257. }
  1258. free_resources:
  1259. device->common.device_free_chan_resources(dma_chan);
  1260. out:
  1261. kfree(src);
  1262. kfree(dest);
  1263. return err;
  1264. }
  1265. static char ioat_interrupt_style[32] = "msix";
  1266. module_param_string(ioat_interrupt_style, ioat_interrupt_style,
  1267. sizeof(ioat_interrupt_style), 0644);
  1268. MODULE_PARM_DESC(ioat_interrupt_style,
  1269. "set ioat interrupt style: msix (default), "
  1270. "msix-single-vector, msi, intx)");
  1271. /**
  1272. * ioat_dma_setup_interrupts - setup interrupt handler
  1273. * @device: ioat device
  1274. */
  1275. static int ioat_dma_setup_interrupts(struct ioatdma_device *device)
  1276. {
  1277. struct ioat_dma_chan *ioat_chan;
  1278. int err, i, j, msixcnt;
  1279. u8 intrctrl = 0;
  1280. if (!strcmp(ioat_interrupt_style, "msix"))
  1281. goto msix;
  1282. if (!strcmp(ioat_interrupt_style, "msix-single-vector"))
  1283. goto msix_single_vector;
  1284. if (!strcmp(ioat_interrupt_style, "msi"))
  1285. goto msi;
  1286. if (!strcmp(ioat_interrupt_style, "intx"))
  1287. goto intx;
  1288. dev_err(&device->pdev->dev, "invalid ioat_interrupt_style %s\n",
  1289. ioat_interrupt_style);
  1290. goto err_no_irq;
  1291. msix:
  1292. /* The number of MSI-X vectors should equal the number of channels */
  1293. msixcnt = device->common.chancnt;
  1294. for (i = 0; i < msixcnt; i++)
  1295. device->msix_entries[i].entry = i;
  1296. err = pci_enable_msix(device->pdev, device->msix_entries, msixcnt);
  1297. if (err < 0)
  1298. goto msi;
  1299. if (err > 0)
  1300. goto msix_single_vector;
  1301. for (i = 0; i < msixcnt; i++) {
  1302. ioat_chan = ioat_lookup_chan_by_index(device, i);
  1303. err = request_irq(device->msix_entries[i].vector,
  1304. ioat_dma_do_interrupt_msix,
  1305. 0, "ioat-msix", ioat_chan);
  1306. if (err) {
  1307. for (j = 0; j < i; j++) {
  1308. ioat_chan =
  1309. ioat_lookup_chan_by_index(device, j);
  1310. free_irq(device->msix_entries[j].vector,
  1311. ioat_chan);
  1312. }
  1313. goto msix_single_vector;
  1314. }
  1315. }
  1316. intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL;
  1317. device->irq_mode = msix_multi_vector;
  1318. goto done;
  1319. msix_single_vector:
  1320. device->msix_entries[0].entry = 0;
  1321. err = pci_enable_msix(device->pdev, device->msix_entries, 1);
  1322. if (err)
  1323. goto msi;
  1324. err = request_irq(device->msix_entries[0].vector, ioat_dma_do_interrupt,
  1325. 0, "ioat-msix", device);
  1326. if (err) {
  1327. pci_disable_msix(device->pdev);
  1328. goto msi;
  1329. }
  1330. device->irq_mode = msix_single_vector;
  1331. goto done;
  1332. msi:
  1333. err = pci_enable_msi(device->pdev);
  1334. if (err)
  1335. goto intx;
  1336. err = request_irq(device->pdev->irq, ioat_dma_do_interrupt,
  1337. 0, "ioat-msi", device);
  1338. if (err) {
  1339. pci_disable_msi(device->pdev);
  1340. goto intx;
  1341. }
  1342. /*
  1343. * CB 1.2 devices need a bit set in configuration space to enable MSI
  1344. */
  1345. if (device->version == IOAT_VER_1_2) {
  1346. u32 dmactrl;
  1347. pci_read_config_dword(device->pdev,
  1348. IOAT_PCI_DMACTRL_OFFSET, &dmactrl);
  1349. dmactrl |= IOAT_PCI_DMACTRL_MSI_EN;
  1350. pci_write_config_dword(device->pdev,
  1351. IOAT_PCI_DMACTRL_OFFSET, dmactrl);
  1352. }
  1353. device->irq_mode = msi;
  1354. goto done;
  1355. intx:
  1356. err = request_irq(device->pdev->irq, ioat_dma_do_interrupt,
  1357. IRQF_SHARED, "ioat-intx", device);
  1358. if (err)
  1359. goto err_no_irq;
  1360. device->irq_mode = intx;
  1361. done:
  1362. intrctrl |= IOAT_INTRCTRL_MASTER_INT_EN;
  1363. writeb(intrctrl, device->reg_base + IOAT_INTRCTRL_OFFSET);
  1364. return 0;
  1365. err_no_irq:
  1366. /* Disable all interrupt generation */
  1367. writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
  1368. dev_err(&device->pdev->dev, "no usable interrupts\n");
  1369. device->irq_mode = none;
  1370. return -1;
  1371. }
  1372. /**
  1373. * ioat_dma_remove_interrupts - remove whatever interrupts were set
  1374. * @device: ioat device
  1375. */
  1376. static void ioat_dma_remove_interrupts(struct ioatdma_device *device)
  1377. {
  1378. struct ioat_dma_chan *ioat_chan;
  1379. int i;
  1380. /* Disable all interrupt generation */
  1381. writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
  1382. switch (device->irq_mode) {
  1383. case msix_multi_vector:
  1384. for (i = 0; i < device->common.chancnt; i++) {
  1385. ioat_chan = ioat_lookup_chan_by_index(device, i);
  1386. free_irq(device->msix_entries[i].vector, ioat_chan);
  1387. }
  1388. pci_disable_msix(device->pdev);
  1389. break;
  1390. case msix_single_vector:
  1391. free_irq(device->msix_entries[0].vector, device);
  1392. pci_disable_msix(device->pdev);
  1393. break;
  1394. case msi:
  1395. free_irq(device->pdev->irq, device);
  1396. pci_disable_msi(device->pdev);
  1397. break;
  1398. case intx:
  1399. free_irq(device->pdev->irq, device);
  1400. break;
  1401. case none:
  1402. dev_warn(&device->pdev->dev,
  1403. "call to %s without interrupts setup\n", __func__);
  1404. }
  1405. device->irq_mode = none;
  1406. }
  1407. struct ioatdma_device *ioat_dma_probe(struct pci_dev *pdev,
  1408. void __iomem *iobase)
  1409. {
  1410. int err;
  1411. struct ioatdma_device *device;
  1412. device = kzalloc(sizeof(*device), GFP_KERNEL);
  1413. if (!device) {
  1414. err = -ENOMEM;
  1415. goto err_kzalloc;
  1416. }
  1417. device->pdev = pdev;
  1418. device->reg_base = iobase;
  1419. device->version = readb(device->reg_base + IOAT_VER_OFFSET);
  1420. /* DMA coherent memory pool for DMA descriptor allocations */
  1421. device->dma_pool = pci_pool_create("dma_desc_pool", pdev,
  1422. sizeof(struct ioat_dma_descriptor),
  1423. 64, 0);
  1424. if (!device->dma_pool) {
  1425. err = -ENOMEM;
  1426. goto err_dma_pool;
  1427. }
  1428. device->completion_pool = pci_pool_create("completion_pool", pdev,
  1429. sizeof(u64), SMP_CACHE_BYTES,
  1430. SMP_CACHE_BYTES);
  1431. if (!device->completion_pool) {
  1432. err = -ENOMEM;
  1433. goto err_completion_pool;
  1434. }
  1435. INIT_LIST_HEAD(&device->common.channels);
  1436. ioat_dma_enumerate_channels(device);
  1437. device->common.device_alloc_chan_resources =
  1438. ioat_dma_alloc_chan_resources;
  1439. device->common.device_free_chan_resources =
  1440. ioat_dma_free_chan_resources;
  1441. device->common.dev = &pdev->dev;
  1442. dma_cap_set(DMA_MEMCPY, device->common.cap_mask);
  1443. device->common.device_is_tx_complete = ioat_dma_is_complete;
  1444. switch (device->version) {
  1445. case IOAT_VER_1_2:
  1446. device->common.device_prep_dma_memcpy = ioat1_dma_prep_memcpy;
  1447. device->common.device_issue_pending =
  1448. ioat1_dma_memcpy_issue_pending;
  1449. break;
  1450. case IOAT_VER_2_0:
  1451. case IOAT_VER_3_0:
  1452. device->common.device_prep_dma_memcpy = ioat2_dma_prep_memcpy;
  1453. device->common.device_issue_pending =
  1454. ioat2_dma_memcpy_issue_pending;
  1455. break;
  1456. }
  1457. dev_err(&device->pdev->dev,
  1458. "Intel(R) I/OAT DMA Engine found,"
  1459. " %d channels, device version 0x%02x, driver version %s\n",
  1460. device->common.chancnt, device->version, IOAT_DMA_VERSION);
  1461. if (!device->common.chancnt) {
  1462. dev_err(&device->pdev->dev,
  1463. "Intel(R) I/OAT DMA Engine problem found: "
  1464. "zero channels detected\n");
  1465. goto err_setup_interrupts;
  1466. }
  1467. err = ioat_dma_setup_interrupts(device);
  1468. if (err)
  1469. goto err_setup_interrupts;
  1470. err = ioat_dma_self_test(device);
  1471. if (err)
  1472. goto err_self_test;
  1473. ioat_set_tcp_copy_break(device);
  1474. dma_async_device_register(&device->common);
  1475. if (device->version != IOAT_VER_3_0) {
  1476. INIT_DELAYED_WORK(&device->work, ioat_dma_chan_watchdog);
  1477. schedule_delayed_work(&device->work,
  1478. WATCHDOG_DELAY);
  1479. }
  1480. return device;
  1481. err_self_test:
  1482. ioat_dma_remove_interrupts(device);
  1483. err_setup_interrupts:
  1484. pci_pool_destroy(device->completion_pool);
  1485. err_completion_pool:
  1486. pci_pool_destroy(device->dma_pool);
  1487. err_dma_pool:
  1488. kfree(device);
  1489. err_kzalloc:
  1490. dev_err(&pdev->dev,
  1491. "Intel(R) I/OAT DMA Engine initialization failed\n");
  1492. return NULL;
  1493. }
  1494. void ioat_dma_remove(struct ioatdma_device *device)
  1495. {
  1496. struct dma_chan *chan, *_chan;
  1497. struct ioat_dma_chan *ioat_chan;
  1498. if (device->version != IOAT_VER_3_0)
  1499. cancel_delayed_work(&device->work);
  1500. ioat_dma_remove_interrupts(device);
  1501. dma_async_device_unregister(&device->common);
  1502. pci_pool_destroy(device->dma_pool);
  1503. pci_pool_destroy(device->completion_pool);
  1504. iounmap(device->reg_base);
  1505. pci_release_regions(device->pdev);
  1506. pci_disable_device(device->pdev);
  1507. list_for_each_entry_safe(chan, _chan,
  1508. &device->common.channels, device_node) {
  1509. ioat_chan = to_ioat_chan(chan);
  1510. list_del(&chan->device_node);
  1511. kfree(ioat_chan);
  1512. }
  1513. kfree(device);
  1514. }