ioat_dma.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731
  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) == 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. INIT_LIST_HEAD(&desc_sw->async_tx.tx_list);
  605. desc_sw->hw = desc;
  606. desc_sw->async_tx.phys = phys;
  607. return desc_sw;
  608. }
  609. static int ioat_initial_desc_count = 256;
  610. module_param(ioat_initial_desc_count, int, 0644);
  611. MODULE_PARM_DESC(ioat_initial_desc_count,
  612. "initial descriptors per channel (default: 256)");
  613. /**
  614. * ioat2_dma_massage_chan_desc - link the descriptors into a circle
  615. * @ioat_chan: the channel to be massaged
  616. */
  617. static void ioat2_dma_massage_chan_desc(struct ioat_dma_chan *ioat_chan)
  618. {
  619. struct ioat_desc_sw *desc, *_desc;
  620. /* setup used_desc */
  621. ioat_chan->used_desc.next = ioat_chan->free_desc.next;
  622. ioat_chan->used_desc.prev = NULL;
  623. /* pull free_desc out of the circle so that every node is a hw
  624. * descriptor, but leave it pointing to the list
  625. */
  626. ioat_chan->free_desc.prev->next = ioat_chan->free_desc.next;
  627. ioat_chan->free_desc.next->prev = ioat_chan->free_desc.prev;
  628. /* circle link the hw descriptors */
  629. desc = to_ioat_desc(ioat_chan->free_desc.next);
  630. desc->hw->next = to_ioat_desc(desc->node.next)->async_tx.phys;
  631. list_for_each_entry_safe(desc, _desc, ioat_chan->free_desc.next, node) {
  632. desc->hw->next = to_ioat_desc(desc->node.next)->async_tx.phys;
  633. }
  634. }
  635. /**
  636. * ioat_dma_alloc_chan_resources - returns the number of allocated descriptors
  637. * @chan: the channel to be filled out
  638. */
  639. static int ioat_dma_alloc_chan_resources(struct dma_chan *chan)
  640. {
  641. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  642. struct ioat_desc_sw *desc;
  643. u16 chanctrl;
  644. u32 chanerr;
  645. int i;
  646. LIST_HEAD(tmp_list);
  647. /* have we already been set up? */
  648. if (!list_empty(&ioat_chan->free_desc))
  649. return ioat_chan->desccount;
  650. /* Setup register to interrupt and write completion status on error */
  651. chanctrl = IOAT_CHANCTRL_ERR_INT_EN |
  652. IOAT_CHANCTRL_ANY_ERR_ABORT_EN |
  653. IOAT_CHANCTRL_ERR_COMPLETION_EN;
  654. writew(chanctrl, ioat_chan->reg_base + IOAT_CHANCTRL_OFFSET);
  655. chanerr = readl(ioat_chan->reg_base + IOAT_CHANERR_OFFSET);
  656. if (chanerr) {
  657. dev_err(&ioat_chan->device->pdev->dev,
  658. "CHANERR = %x, clearing\n", chanerr);
  659. writel(chanerr, ioat_chan->reg_base + IOAT_CHANERR_OFFSET);
  660. }
  661. /* Allocate descriptors */
  662. for (i = 0; i < ioat_initial_desc_count; i++) {
  663. desc = ioat_dma_alloc_descriptor(ioat_chan, GFP_KERNEL);
  664. if (!desc) {
  665. dev_err(&ioat_chan->device->pdev->dev,
  666. "Only %d initial descriptors\n", i);
  667. break;
  668. }
  669. list_add_tail(&desc->node, &tmp_list);
  670. }
  671. spin_lock_bh(&ioat_chan->desc_lock);
  672. ioat_chan->desccount = i;
  673. list_splice(&tmp_list, &ioat_chan->free_desc);
  674. if (ioat_chan->device->version != IOAT_VER_1_2)
  675. ioat2_dma_massage_chan_desc(ioat_chan);
  676. spin_unlock_bh(&ioat_chan->desc_lock);
  677. /* allocate a completion writeback area */
  678. /* doing 2 32bit writes to mmio since 1 64b write doesn't work */
  679. ioat_chan->completion_virt =
  680. pci_pool_alloc(ioat_chan->device->completion_pool,
  681. GFP_KERNEL,
  682. &ioat_chan->completion_addr);
  683. memset(ioat_chan->completion_virt, 0,
  684. sizeof(*ioat_chan->completion_virt));
  685. writel(((u64) ioat_chan->completion_addr) & 0x00000000FFFFFFFF,
  686. ioat_chan->reg_base + IOAT_CHANCMP_OFFSET_LOW);
  687. writel(((u64) ioat_chan->completion_addr) >> 32,
  688. ioat_chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
  689. tasklet_enable(&ioat_chan->cleanup_task);
  690. ioat_dma_start_null_desc(ioat_chan); /* give chain to dma device */
  691. return ioat_chan->desccount;
  692. }
  693. /**
  694. * ioat_dma_free_chan_resources - release all the descriptors
  695. * @chan: the channel to be cleaned
  696. */
  697. static void ioat_dma_free_chan_resources(struct dma_chan *chan)
  698. {
  699. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  700. struct ioatdma_device *ioatdma_device = to_ioatdma_device(chan->device);
  701. struct ioat_desc_sw *desc, *_desc;
  702. int in_use_descs = 0;
  703. /* Before freeing channel resources first check
  704. * if they have been previously allocated for this channel.
  705. */
  706. if (ioat_chan->desccount == 0)
  707. return;
  708. tasklet_disable(&ioat_chan->cleanup_task);
  709. ioat_dma_memcpy_cleanup(ioat_chan);
  710. /* Delay 100ms after reset to allow internal DMA logic to quiesce
  711. * before removing DMA descriptor resources.
  712. */
  713. writeb(IOAT_CHANCMD_RESET,
  714. ioat_chan->reg_base
  715. + IOAT_CHANCMD_OFFSET(ioat_chan->device->version));
  716. mdelay(100);
  717. spin_lock_bh(&ioat_chan->desc_lock);
  718. switch (ioat_chan->device->version) {
  719. case IOAT_VER_1_2:
  720. list_for_each_entry_safe(desc, _desc,
  721. &ioat_chan->used_desc, node) {
  722. in_use_descs++;
  723. list_del(&desc->node);
  724. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  725. desc->async_tx.phys);
  726. kfree(desc);
  727. }
  728. list_for_each_entry_safe(desc, _desc,
  729. &ioat_chan->free_desc, node) {
  730. list_del(&desc->node);
  731. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  732. desc->async_tx.phys);
  733. kfree(desc);
  734. }
  735. break;
  736. case IOAT_VER_2_0:
  737. case IOAT_VER_3_0:
  738. list_for_each_entry_safe(desc, _desc,
  739. ioat_chan->free_desc.next, node) {
  740. list_del(&desc->node);
  741. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  742. desc->async_tx.phys);
  743. kfree(desc);
  744. }
  745. desc = to_ioat_desc(ioat_chan->free_desc.next);
  746. pci_pool_free(ioatdma_device->dma_pool, desc->hw,
  747. desc->async_tx.phys);
  748. kfree(desc);
  749. INIT_LIST_HEAD(&ioat_chan->free_desc);
  750. INIT_LIST_HEAD(&ioat_chan->used_desc);
  751. break;
  752. }
  753. spin_unlock_bh(&ioat_chan->desc_lock);
  754. pci_pool_free(ioatdma_device->completion_pool,
  755. ioat_chan->completion_virt,
  756. ioat_chan->completion_addr);
  757. /* one is ok since we left it on there on purpose */
  758. if (in_use_descs > 1)
  759. dev_err(&ioat_chan->device->pdev->dev,
  760. "Freeing %d in use descriptors!\n",
  761. in_use_descs - 1);
  762. ioat_chan->last_completion = ioat_chan->completion_addr = 0;
  763. ioat_chan->pending = 0;
  764. ioat_chan->dmacount = 0;
  765. ioat_chan->desccount = 0;
  766. ioat_chan->watchdog_completion = 0;
  767. ioat_chan->last_compl_desc_addr_hw = 0;
  768. ioat_chan->watchdog_tcp_cookie =
  769. ioat_chan->watchdog_last_tcp_cookie = 0;
  770. }
  771. /**
  772. * ioat_dma_get_next_descriptor - return the next available descriptor
  773. * @ioat_chan: IOAT DMA channel handle
  774. *
  775. * Gets the next descriptor from the chain, and must be called with the
  776. * channel's desc_lock held. Allocates more descriptors if the channel
  777. * has run out.
  778. */
  779. static struct ioat_desc_sw *
  780. ioat1_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan)
  781. {
  782. struct ioat_desc_sw *new;
  783. if (!list_empty(&ioat_chan->free_desc)) {
  784. new = to_ioat_desc(ioat_chan->free_desc.next);
  785. list_del(&new->node);
  786. } else {
  787. /* try to get another desc */
  788. new = ioat_dma_alloc_descriptor(ioat_chan, GFP_ATOMIC);
  789. if (!new) {
  790. dev_err(&ioat_chan->device->pdev->dev,
  791. "alloc failed\n");
  792. return NULL;
  793. }
  794. }
  795. prefetch(new->hw);
  796. return new;
  797. }
  798. static struct ioat_desc_sw *
  799. ioat2_dma_get_next_descriptor(struct ioat_dma_chan *ioat_chan)
  800. {
  801. struct ioat_desc_sw *new;
  802. /*
  803. * used.prev points to where to start processing
  804. * used.next points to next free descriptor
  805. * if used.prev == NULL, there are none waiting to be processed
  806. * if used.next == used.prev.prev, there is only one free descriptor,
  807. * and we need to use it to as a noop descriptor before
  808. * linking in a new set of descriptors, since the device
  809. * has probably already read the pointer to it
  810. */
  811. if (ioat_chan->used_desc.prev &&
  812. ioat_chan->used_desc.next == ioat_chan->used_desc.prev->prev) {
  813. struct ioat_desc_sw *desc;
  814. struct ioat_desc_sw *noop_desc;
  815. int i;
  816. /* set up the noop descriptor */
  817. noop_desc = to_ioat_desc(ioat_chan->used_desc.next);
  818. /* set size to non-zero value (channel returns error when size is 0) */
  819. noop_desc->hw->size = NULL_DESC_BUFFER_SIZE;
  820. noop_desc->hw->ctl = IOAT_DMA_DESCRIPTOR_NUL;
  821. noop_desc->hw->src_addr = 0;
  822. noop_desc->hw->dst_addr = 0;
  823. ioat_chan->used_desc.next = ioat_chan->used_desc.next->next;
  824. ioat_chan->pending++;
  825. ioat_chan->dmacount++;
  826. /* try to get a few more descriptors */
  827. for (i = 16; i; i--) {
  828. desc = ioat_dma_alloc_descriptor(ioat_chan, GFP_ATOMIC);
  829. if (!desc) {
  830. dev_err(&ioat_chan->device->pdev->dev,
  831. "alloc failed\n");
  832. break;
  833. }
  834. list_add_tail(&desc->node, ioat_chan->used_desc.next);
  835. desc->hw->next
  836. = to_ioat_desc(desc->node.next)->async_tx.phys;
  837. to_ioat_desc(desc->node.prev)->hw->next
  838. = desc->async_tx.phys;
  839. ioat_chan->desccount++;
  840. }
  841. ioat_chan->used_desc.next = noop_desc->node.next;
  842. }
  843. new = to_ioat_desc(ioat_chan->used_desc.next);
  844. prefetch(new);
  845. ioat_chan->used_desc.next = new->node.next;
  846. if (ioat_chan->used_desc.prev == NULL)
  847. ioat_chan->used_desc.prev = &new->node;
  848. prefetch(new->hw);
  849. return new;
  850. }
  851. static struct ioat_desc_sw *ioat_dma_get_next_descriptor(
  852. struct ioat_dma_chan *ioat_chan)
  853. {
  854. if (!ioat_chan)
  855. return NULL;
  856. switch (ioat_chan->device->version) {
  857. case IOAT_VER_1_2:
  858. return ioat1_dma_get_next_descriptor(ioat_chan);
  859. case IOAT_VER_2_0:
  860. case IOAT_VER_3_0:
  861. return ioat2_dma_get_next_descriptor(ioat_chan);
  862. }
  863. return NULL;
  864. }
  865. static struct dma_async_tx_descriptor *ioat1_dma_prep_memcpy(
  866. struct dma_chan *chan,
  867. dma_addr_t dma_dest,
  868. dma_addr_t dma_src,
  869. size_t len,
  870. unsigned long flags)
  871. {
  872. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  873. struct ioat_desc_sw *new;
  874. spin_lock_bh(&ioat_chan->desc_lock);
  875. new = ioat_dma_get_next_descriptor(ioat_chan);
  876. spin_unlock_bh(&ioat_chan->desc_lock);
  877. if (new) {
  878. new->len = len;
  879. new->dst = dma_dest;
  880. new->src = dma_src;
  881. new->async_tx.flags = flags;
  882. return &new->async_tx;
  883. } else {
  884. dev_err(&ioat_chan->device->pdev->dev,
  885. "chan%d - get_next_desc failed: %d descs waiting, %d total desc\n",
  886. chan_num(ioat_chan), ioat_chan->dmacount, ioat_chan->desccount);
  887. return NULL;
  888. }
  889. }
  890. static struct dma_async_tx_descriptor *ioat2_dma_prep_memcpy(
  891. struct dma_chan *chan,
  892. dma_addr_t dma_dest,
  893. dma_addr_t dma_src,
  894. size_t len,
  895. unsigned long flags)
  896. {
  897. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  898. struct ioat_desc_sw *new;
  899. spin_lock_bh(&ioat_chan->desc_lock);
  900. new = ioat2_dma_get_next_descriptor(ioat_chan);
  901. /*
  902. * leave ioat_chan->desc_lock set in ioat 2 path
  903. * it will get unlocked at end of tx_submit
  904. */
  905. if (new) {
  906. new->len = len;
  907. new->dst = dma_dest;
  908. new->src = dma_src;
  909. new->async_tx.flags = flags;
  910. return &new->async_tx;
  911. } else {
  912. spin_unlock_bh(&ioat_chan->desc_lock);
  913. dev_err(&ioat_chan->device->pdev->dev,
  914. "chan%d - get_next_desc failed: %d descs waiting, %d total desc\n",
  915. chan_num(ioat_chan), ioat_chan->dmacount, ioat_chan->desccount);
  916. return NULL;
  917. }
  918. }
  919. static void ioat_dma_cleanup_tasklet(unsigned long data)
  920. {
  921. struct ioat_dma_chan *chan = (void *)data;
  922. ioat_dma_memcpy_cleanup(chan);
  923. writew(IOAT_CHANCTRL_INT_DISABLE,
  924. chan->reg_base + IOAT_CHANCTRL_OFFSET);
  925. }
  926. static void
  927. ioat_dma_unmap(struct ioat_dma_chan *ioat_chan, struct ioat_desc_sw *desc)
  928. {
  929. /*
  930. * yes we are unmapping both _page and _single
  931. * alloc'd regions with unmap_page. Is this
  932. * *really* that bad?
  933. */
  934. if (!(desc->async_tx.flags & DMA_COMPL_SKIP_DEST_UNMAP))
  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. if (!(desc->async_tx.flags & DMA_COMPL_SKIP_SRC_UNMAP))
  940. pci_unmap_page(ioat_chan->device->pdev,
  941. pci_unmap_addr(desc, src),
  942. pci_unmap_len(desc, len),
  943. PCI_DMA_TODEVICE);
  944. }
  945. /**
  946. * ioat_dma_memcpy_cleanup - cleanup up finished descriptors
  947. * @chan: ioat channel to be cleaned up
  948. */
  949. static void ioat_dma_memcpy_cleanup(struct ioat_dma_chan *ioat_chan)
  950. {
  951. unsigned long phys_complete;
  952. struct ioat_desc_sw *desc, *_desc;
  953. dma_cookie_t cookie = 0;
  954. unsigned long desc_phys;
  955. struct ioat_desc_sw *latest_desc;
  956. prefetch(ioat_chan->completion_virt);
  957. if (!spin_trylock_bh(&ioat_chan->cleanup_lock))
  958. return;
  959. /* The completion writeback can happen at any time,
  960. so reads by the driver need to be atomic operations
  961. The descriptor physical addresses are limited to 32-bits
  962. when the CPU can only do a 32-bit mov */
  963. #if (BITS_PER_LONG == 64)
  964. phys_complete =
  965. ioat_chan->completion_virt->full
  966. & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR;
  967. #else
  968. phys_complete =
  969. ioat_chan->completion_virt->low & IOAT_LOW_COMPLETION_MASK;
  970. #endif
  971. if ((ioat_chan->completion_virt->full
  972. & IOAT_CHANSTS_DMA_TRANSFER_STATUS) ==
  973. IOAT_CHANSTS_DMA_TRANSFER_STATUS_HALTED) {
  974. dev_err(&ioat_chan->device->pdev->dev,
  975. "Channel halted, chanerr = %x\n",
  976. readl(ioat_chan->reg_base + IOAT_CHANERR_OFFSET));
  977. /* TODO do something to salvage the situation */
  978. }
  979. if (phys_complete == ioat_chan->last_completion) {
  980. spin_unlock_bh(&ioat_chan->cleanup_lock);
  981. /*
  982. * perhaps we're stuck so hard that the watchdog can't go off?
  983. * try to catch it after 2 seconds
  984. */
  985. if (ioat_chan->device->version != IOAT_VER_3_0) {
  986. if (time_after(jiffies,
  987. ioat_chan->last_completion_time + HZ*WATCHDOG_DELAY)) {
  988. ioat_dma_chan_watchdog(&(ioat_chan->device->work.work));
  989. ioat_chan->last_completion_time = jiffies;
  990. }
  991. }
  992. return;
  993. }
  994. ioat_chan->last_completion_time = jiffies;
  995. cookie = 0;
  996. if (!spin_trylock_bh(&ioat_chan->desc_lock)) {
  997. spin_unlock_bh(&ioat_chan->cleanup_lock);
  998. return;
  999. }
  1000. switch (ioat_chan->device->version) {
  1001. case IOAT_VER_1_2:
  1002. list_for_each_entry_safe(desc, _desc,
  1003. &ioat_chan->used_desc, node) {
  1004. /*
  1005. * Incoming DMA requests may use multiple descriptors,
  1006. * due to exceeding xfercap, perhaps. If so, only the
  1007. * last one will have a cookie, and require unmapping.
  1008. */
  1009. if (desc->async_tx.cookie) {
  1010. cookie = desc->async_tx.cookie;
  1011. ioat_dma_unmap(ioat_chan, desc);
  1012. if (desc->async_tx.callback) {
  1013. desc->async_tx.callback(desc->async_tx.callback_param);
  1014. desc->async_tx.callback = NULL;
  1015. }
  1016. }
  1017. if (desc->async_tx.phys != phys_complete) {
  1018. /*
  1019. * a completed entry, but not the last, so clean
  1020. * up if the client is done with the descriptor
  1021. */
  1022. if (async_tx_test_ack(&desc->async_tx)) {
  1023. list_move_tail(&desc->node,
  1024. &ioat_chan->free_desc);
  1025. } else
  1026. desc->async_tx.cookie = 0;
  1027. } else {
  1028. /*
  1029. * last used desc. Do not remove, so we can
  1030. * append from it, but don't look at it next
  1031. * time, either
  1032. */
  1033. desc->async_tx.cookie = 0;
  1034. /* TODO check status bits? */
  1035. break;
  1036. }
  1037. }
  1038. break;
  1039. case IOAT_VER_2_0:
  1040. case IOAT_VER_3_0:
  1041. /* has some other thread has already cleaned up? */
  1042. if (ioat_chan->used_desc.prev == NULL)
  1043. break;
  1044. /* work backwards to find latest finished desc */
  1045. desc = to_ioat_desc(ioat_chan->used_desc.next);
  1046. latest_desc = NULL;
  1047. do {
  1048. desc = to_ioat_desc(desc->node.prev);
  1049. desc_phys = (unsigned long)desc->async_tx.phys
  1050. & IOAT_CHANSTS_COMPLETED_DESCRIPTOR_ADDR;
  1051. if (desc_phys == phys_complete) {
  1052. latest_desc = desc;
  1053. break;
  1054. }
  1055. } while (&desc->node != ioat_chan->used_desc.prev);
  1056. if (latest_desc != NULL) {
  1057. /* work forwards to clear finished descriptors */
  1058. for (desc = to_ioat_desc(ioat_chan->used_desc.prev);
  1059. &desc->node != latest_desc->node.next &&
  1060. &desc->node != ioat_chan->used_desc.next;
  1061. desc = to_ioat_desc(desc->node.next)) {
  1062. if (desc->async_tx.cookie) {
  1063. cookie = desc->async_tx.cookie;
  1064. desc->async_tx.cookie = 0;
  1065. ioat_dma_unmap(ioat_chan, desc);
  1066. if (desc->async_tx.callback) {
  1067. desc->async_tx.callback(desc->async_tx.callback_param);
  1068. desc->async_tx.callback = NULL;
  1069. }
  1070. }
  1071. }
  1072. /* move used.prev up beyond those that are finished */
  1073. if (&desc->node == ioat_chan->used_desc.next)
  1074. ioat_chan->used_desc.prev = NULL;
  1075. else
  1076. ioat_chan->used_desc.prev = &desc->node;
  1077. }
  1078. break;
  1079. }
  1080. spin_unlock_bh(&ioat_chan->desc_lock);
  1081. ioat_chan->last_completion = phys_complete;
  1082. if (cookie != 0)
  1083. ioat_chan->completed_cookie = cookie;
  1084. spin_unlock_bh(&ioat_chan->cleanup_lock);
  1085. }
  1086. /**
  1087. * ioat_dma_is_complete - poll the status of a IOAT DMA transaction
  1088. * @chan: IOAT DMA channel handle
  1089. * @cookie: DMA transaction identifier
  1090. * @done: if not %NULL, updated with last completed transaction
  1091. * @used: if not %NULL, updated with last used transaction
  1092. */
  1093. static enum dma_status ioat_dma_is_complete(struct dma_chan *chan,
  1094. dma_cookie_t cookie,
  1095. dma_cookie_t *done,
  1096. dma_cookie_t *used)
  1097. {
  1098. struct ioat_dma_chan *ioat_chan = to_ioat_chan(chan);
  1099. dma_cookie_t last_used;
  1100. dma_cookie_t last_complete;
  1101. enum dma_status ret;
  1102. last_used = chan->cookie;
  1103. last_complete = ioat_chan->completed_cookie;
  1104. ioat_chan->watchdog_tcp_cookie = cookie;
  1105. if (done)
  1106. *done = last_complete;
  1107. if (used)
  1108. *used = last_used;
  1109. ret = dma_async_is_complete(cookie, last_complete, last_used);
  1110. if (ret == DMA_SUCCESS)
  1111. return ret;
  1112. ioat_dma_memcpy_cleanup(ioat_chan);
  1113. last_used = chan->cookie;
  1114. last_complete = ioat_chan->completed_cookie;
  1115. if (done)
  1116. *done = last_complete;
  1117. if (used)
  1118. *used = last_used;
  1119. return dma_async_is_complete(cookie, last_complete, last_used);
  1120. }
  1121. static void ioat_dma_start_null_desc(struct ioat_dma_chan *ioat_chan)
  1122. {
  1123. struct ioat_desc_sw *desc;
  1124. spin_lock_bh(&ioat_chan->desc_lock);
  1125. desc = ioat_dma_get_next_descriptor(ioat_chan);
  1126. if (!desc) {
  1127. dev_err(&ioat_chan->device->pdev->dev,
  1128. "Unable to start null desc - get next desc failed\n");
  1129. spin_unlock_bh(&ioat_chan->desc_lock);
  1130. return;
  1131. }
  1132. desc->hw->ctl = IOAT_DMA_DESCRIPTOR_NUL
  1133. | IOAT_DMA_DESCRIPTOR_CTL_INT_GN
  1134. | IOAT_DMA_DESCRIPTOR_CTL_CP_STS;
  1135. /* set size to non-zero value (channel returns error when size is 0) */
  1136. desc->hw->size = NULL_DESC_BUFFER_SIZE;
  1137. desc->hw->src_addr = 0;
  1138. desc->hw->dst_addr = 0;
  1139. async_tx_ack(&desc->async_tx);
  1140. switch (ioat_chan->device->version) {
  1141. case IOAT_VER_1_2:
  1142. desc->hw->next = 0;
  1143. list_add_tail(&desc->node, &ioat_chan->used_desc);
  1144. writel(((u64) desc->async_tx.phys) & 0x00000000FFFFFFFF,
  1145. ioat_chan->reg_base + IOAT1_CHAINADDR_OFFSET_LOW);
  1146. writel(((u64) desc->async_tx.phys) >> 32,
  1147. ioat_chan->reg_base + IOAT1_CHAINADDR_OFFSET_HIGH);
  1148. writeb(IOAT_CHANCMD_START, ioat_chan->reg_base
  1149. + IOAT_CHANCMD_OFFSET(ioat_chan->device->version));
  1150. break;
  1151. case IOAT_VER_2_0:
  1152. case IOAT_VER_3_0:
  1153. writel(((u64) desc->async_tx.phys) & 0x00000000FFFFFFFF,
  1154. ioat_chan->reg_base + IOAT2_CHAINADDR_OFFSET_LOW);
  1155. writel(((u64) desc->async_tx.phys) >> 32,
  1156. ioat_chan->reg_base + IOAT2_CHAINADDR_OFFSET_HIGH);
  1157. ioat_chan->dmacount++;
  1158. __ioat2_dma_memcpy_issue_pending(ioat_chan);
  1159. break;
  1160. }
  1161. spin_unlock_bh(&ioat_chan->desc_lock);
  1162. }
  1163. /*
  1164. * Perform a IOAT transaction to verify the HW works.
  1165. */
  1166. #define IOAT_TEST_SIZE 2000
  1167. static void ioat_dma_test_callback(void *dma_async_param)
  1168. {
  1169. struct completion *cmp = dma_async_param;
  1170. complete(cmp);
  1171. }
  1172. /**
  1173. * ioat_dma_self_test - Perform a IOAT transaction to verify the HW works.
  1174. * @device: device to be tested
  1175. */
  1176. static int ioat_dma_self_test(struct ioatdma_device *device)
  1177. {
  1178. int i;
  1179. u8 *src;
  1180. u8 *dest;
  1181. struct dma_chan *dma_chan;
  1182. struct dma_async_tx_descriptor *tx;
  1183. dma_addr_t dma_dest, dma_src;
  1184. dma_cookie_t cookie;
  1185. int err = 0;
  1186. struct completion cmp;
  1187. unsigned long tmo;
  1188. src = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
  1189. if (!src)
  1190. return -ENOMEM;
  1191. dest = kzalloc(sizeof(u8) * IOAT_TEST_SIZE, GFP_KERNEL);
  1192. if (!dest) {
  1193. kfree(src);
  1194. return -ENOMEM;
  1195. }
  1196. /* Fill in src buffer */
  1197. for (i = 0; i < IOAT_TEST_SIZE; i++)
  1198. src[i] = (u8)i;
  1199. /* Start copy, using first DMA channel */
  1200. dma_chan = container_of(device->common.channels.next,
  1201. struct dma_chan,
  1202. device_node);
  1203. if (device->common.device_alloc_chan_resources(dma_chan) < 1) {
  1204. dev_err(&device->pdev->dev,
  1205. "selftest cannot allocate chan resource\n");
  1206. err = -ENODEV;
  1207. goto out;
  1208. }
  1209. dma_src = dma_map_single(dma_chan->device->dev, src, IOAT_TEST_SIZE,
  1210. DMA_TO_DEVICE);
  1211. dma_dest = dma_map_single(dma_chan->device->dev, dest, IOAT_TEST_SIZE,
  1212. DMA_FROM_DEVICE);
  1213. tx = device->common.device_prep_dma_memcpy(dma_chan, dma_dest, dma_src,
  1214. IOAT_TEST_SIZE, 0);
  1215. if (!tx) {
  1216. dev_err(&device->pdev->dev,
  1217. "Self-test prep failed, disabling\n");
  1218. err = -ENODEV;
  1219. goto free_resources;
  1220. }
  1221. async_tx_ack(tx);
  1222. init_completion(&cmp);
  1223. tx->callback = ioat_dma_test_callback;
  1224. tx->callback_param = &cmp;
  1225. cookie = tx->tx_submit(tx);
  1226. if (cookie < 0) {
  1227. dev_err(&device->pdev->dev,
  1228. "Self-test setup failed, disabling\n");
  1229. err = -ENODEV;
  1230. goto free_resources;
  1231. }
  1232. device->common.device_issue_pending(dma_chan);
  1233. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1234. if (tmo == 0 ||
  1235. device->common.device_is_tx_complete(dma_chan, cookie, NULL, NULL)
  1236. != DMA_SUCCESS) {
  1237. dev_err(&device->pdev->dev,
  1238. "Self-test copy timed out, disabling\n");
  1239. err = -ENODEV;
  1240. goto free_resources;
  1241. }
  1242. if (memcmp(src, dest, IOAT_TEST_SIZE)) {
  1243. dev_err(&device->pdev->dev,
  1244. "Self-test copy failed compare, disabling\n");
  1245. err = -ENODEV;
  1246. goto free_resources;
  1247. }
  1248. free_resources:
  1249. device->common.device_free_chan_resources(dma_chan);
  1250. out:
  1251. kfree(src);
  1252. kfree(dest);
  1253. return err;
  1254. }
  1255. static char ioat_interrupt_style[32] = "msix";
  1256. module_param_string(ioat_interrupt_style, ioat_interrupt_style,
  1257. sizeof(ioat_interrupt_style), 0644);
  1258. MODULE_PARM_DESC(ioat_interrupt_style,
  1259. "set ioat interrupt style: msix (default), "
  1260. "msix-single-vector, msi, intx)");
  1261. /**
  1262. * ioat_dma_setup_interrupts - setup interrupt handler
  1263. * @device: ioat device
  1264. */
  1265. static int ioat_dma_setup_interrupts(struct ioatdma_device *device)
  1266. {
  1267. struct ioat_dma_chan *ioat_chan;
  1268. int err, i, j, msixcnt;
  1269. u8 intrctrl = 0;
  1270. if (!strcmp(ioat_interrupt_style, "msix"))
  1271. goto msix;
  1272. if (!strcmp(ioat_interrupt_style, "msix-single-vector"))
  1273. goto msix_single_vector;
  1274. if (!strcmp(ioat_interrupt_style, "msi"))
  1275. goto msi;
  1276. if (!strcmp(ioat_interrupt_style, "intx"))
  1277. goto intx;
  1278. dev_err(&device->pdev->dev, "invalid ioat_interrupt_style %s\n",
  1279. ioat_interrupt_style);
  1280. goto err_no_irq;
  1281. msix:
  1282. /* The number of MSI-X vectors should equal the number of channels */
  1283. msixcnt = device->common.chancnt;
  1284. for (i = 0; i < msixcnt; i++)
  1285. device->msix_entries[i].entry = i;
  1286. err = pci_enable_msix(device->pdev, device->msix_entries, msixcnt);
  1287. if (err < 0)
  1288. goto msi;
  1289. if (err > 0)
  1290. goto msix_single_vector;
  1291. for (i = 0; i < msixcnt; i++) {
  1292. ioat_chan = ioat_lookup_chan_by_index(device, i);
  1293. err = request_irq(device->msix_entries[i].vector,
  1294. ioat_dma_do_interrupt_msix,
  1295. 0, "ioat-msix", ioat_chan);
  1296. if (err) {
  1297. for (j = 0; j < i; j++) {
  1298. ioat_chan =
  1299. ioat_lookup_chan_by_index(device, j);
  1300. free_irq(device->msix_entries[j].vector,
  1301. ioat_chan);
  1302. }
  1303. goto msix_single_vector;
  1304. }
  1305. }
  1306. intrctrl |= IOAT_INTRCTRL_MSIX_VECTOR_CONTROL;
  1307. device->irq_mode = msix_multi_vector;
  1308. goto done;
  1309. msix_single_vector:
  1310. device->msix_entries[0].entry = 0;
  1311. err = pci_enable_msix(device->pdev, device->msix_entries, 1);
  1312. if (err)
  1313. goto msi;
  1314. err = request_irq(device->msix_entries[0].vector, ioat_dma_do_interrupt,
  1315. 0, "ioat-msix", device);
  1316. if (err) {
  1317. pci_disable_msix(device->pdev);
  1318. goto msi;
  1319. }
  1320. device->irq_mode = msix_single_vector;
  1321. goto done;
  1322. msi:
  1323. err = pci_enable_msi(device->pdev);
  1324. if (err)
  1325. goto intx;
  1326. err = request_irq(device->pdev->irq, ioat_dma_do_interrupt,
  1327. 0, "ioat-msi", device);
  1328. if (err) {
  1329. pci_disable_msi(device->pdev);
  1330. goto intx;
  1331. }
  1332. /*
  1333. * CB 1.2 devices need a bit set in configuration space to enable MSI
  1334. */
  1335. if (device->version == IOAT_VER_1_2) {
  1336. u32 dmactrl;
  1337. pci_read_config_dword(device->pdev,
  1338. IOAT_PCI_DMACTRL_OFFSET, &dmactrl);
  1339. dmactrl |= IOAT_PCI_DMACTRL_MSI_EN;
  1340. pci_write_config_dword(device->pdev,
  1341. IOAT_PCI_DMACTRL_OFFSET, dmactrl);
  1342. }
  1343. device->irq_mode = msi;
  1344. goto done;
  1345. intx:
  1346. err = request_irq(device->pdev->irq, ioat_dma_do_interrupt,
  1347. IRQF_SHARED, "ioat-intx", device);
  1348. if (err)
  1349. goto err_no_irq;
  1350. device->irq_mode = intx;
  1351. done:
  1352. intrctrl |= IOAT_INTRCTRL_MASTER_INT_EN;
  1353. writeb(intrctrl, device->reg_base + IOAT_INTRCTRL_OFFSET);
  1354. return 0;
  1355. err_no_irq:
  1356. /* Disable all interrupt generation */
  1357. writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
  1358. dev_err(&device->pdev->dev, "no usable interrupts\n");
  1359. device->irq_mode = none;
  1360. return -1;
  1361. }
  1362. /**
  1363. * ioat_dma_remove_interrupts - remove whatever interrupts were set
  1364. * @device: ioat device
  1365. */
  1366. static void ioat_dma_remove_interrupts(struct ioatdma_device *device)
  1367. {
  1368. struct ioat_dma_chan *ioat_chan;
  1369. int i;
  1370. /* Disable all interrupt generation */
  1371. writeb(0, device->reg_base + IOAT_INTRCTRL_OFFSET);
  1372. switch (device->irq_mode) {
  1373. case msix_multi_vector:
  1374. for (i = 0; i < device->common.chancnt; i++) {
  1375. ioat_chan = ioat_lookup_chan_by_index(device, i);
  1376. free_irq(device->msix_entries[i].vector, ioat_chan);
  1377. }
  1378. pci_disable_msix(device->pdev);
  1379. break;
  1380. case msix_single_vector:
  1381. free_irq(device->msix_entries[0].vector, device);
  1382. pci_disable_msix(device->pdev);
  1383. break;
  1384. case msi:
  1385. free_irq(device->pdev->irq, device);
  1386. pci_disable_msi(device->pdev);
  1387. break;
  1388. case intx:
  1389. free_irq(device->pdev->irq, device);
  1390. break;
  1391. case none:
  1392. dev_warn(&device->pdev->dev,
  1393. "call to %s without interrupts setup\n", __func__);
  1394. }
  1395. device->irq_mode = none;
  1396. }
  1397. struct ioatdma_device *ioat_dma_probe(struct pci_dev *pdev,
  1398. void __iomem *iobase)
  1399. {
  1400. int err;
  1401. struct ioatdma_device *device;
  1402. device = kzalloc(sizeof(*device), GFP_KERNEL);
  1403. if (!device) {
  1404. err = -ENOMEM;
  1405. goto err_kzalloc;
  1406. }
  1407. device->pdev = pdev;
  1408. device->reg_base = iobase;
  1409. device->version = readb(device->reg_base + IOAT_VER_OFFSET);
  1410. /* DMA coherent memory pool for DMA descriptor allocations */
  1411. device->dma_pool = pci_pool_create("dma_desc_pool", pdev,
  1412. sizeof(struct ioat_dma_descriptor),
  1413. 64, 0);
  1414. if (!device->dma_pool) {
  1415. err = -ENOMEM;
  1416. goto err_dma_pool;
  1417. }
  1418. device->completion_pool = pci_pool_create("completion_pool", pdev,
  1419. sizeof(u64), SMP_CACHE_BYTES,
  1420. SMP_CACHE_BYTES);
  1421. if (!device->completion_pool) {
  1422. err = -ENOMEM;
  1423. goto err_completion_pool;
  1424. }
  1425. INIT_LIST_HEAD(&device->common.channels);
  1426. ioat_dma_enumerate_channels(device);
  1427. device->common.device_alloc_chan_resources =
  1428. ioat_dma_alloc_chan_resources;
  1429. device->common.device_free_chan_resources =
  1430. ioat_dma_free_chan_resources;
  1431. device->common.dev = &pdev->dev;
  1432. dma_cap_set(DMA_MEMCPY, device->common.cap_mask);
  1433. device->common.device_is_tx_complete = ioat_dma_is_complete;
  1434. switch (device->version) {
  1435. case IOAT_VER_1_2:
  1436. device->common.device_prep_dma_memcpy = ioat1_dma_prep_memcpy;
  1437. device->common.device_issue_pending =
  1438. ioat1_dma_memcpy_issue_pending;
  1439. break;
  1440. case IOAT_VER_2_0:
  1441. case IOAT_VER_3_0:
  1442. device->common.device_prep_dma_memcpy = ioat2_dma_prep_memcpy;
  1443. device->common.device_issue_pending =
  1444. ioat2_dma_memcpy_issue_pending;
  1445. break;
  1446. }
  1447. dev_err(&device->pdev->dev,
  1448. "Intel(R) I/OAT DMA Engine found,"
  1449. " %d channels, device version 0x%02x, driver version %s\n",
  1450. device->common.chancnt, device->version, IOAT_DMA_VERSION);
  1451. if (!device->common.chancnt) {
  1452. dev_err(&device->pdev->dev,
  1453. "Intel(R) I/OAT DMA Engine problem found: "
  1454. "zero channels detected\n");
  1455. goto err_setup_interrupts;
  1456. }
  1457. err = ioat_dma_setup_interrupts(device);
  1458. if (err)
  1459. goto err_setup_interrupts;
  1460. err = ioat_dma_self_test(device);
  1461. if (err)
  1462. goto err_self_test;
  1463. ioat_set_tcp_copy_break(device);
  1464. dma_async_device_register(&device->common);
  1465. if (device->version != IOAT_VER_3_0) {
  1466. INIT_DELAYED_WORK(&device->work, ioat_dma_chan_watchdog);
  1467. schedule_delayed_work(&device->work,
  1468. WATCHDOG_DELAY);
  1469. }
  1470. return device;
  1471. err_self_test:
  1472. ioat_dma_remove_interrupts(device);
  1473. err_setup_interrupts:
  1474. pci_pool_destroy(device->completion_pool);
  1475. err_completion_pool:
  1476. pci_pool_destroy(device->dma_pool);
  1477. err_dma_pool:
  1478. kfree(device);
  1479. err_kzalloc:
  1480. dev_err(&pdev->dev,
  1481. "Intel(R) I/OAT DMA Engine initialization failed\n");
  1482. return NULL;
  1483. }
  1484. void ioat_dma_remove(struct ioatdma_device *device)
  1485. {
  1486. struct dma_chan *chan, *_chan;
  1487. struct ioat_dma_chan *ioat_chan;
  1488. if (device->version != IOAT_VER_3_0)
  1489. cancel_delayed_work(&device->work);
  1490. ioat_dma_remove_interrupts(device);
  1491. dma_async_device_unregister(&device->common);
  1492. pci_pool_destroy(device->dma_pool);
  1493. pci_pool_destroy(device->completion_pool);
  1494. iounmap(device->reg_base);
  1495. pci_release_regions(device->pdev);
  1496. pci_disable_device(device->pdev);
  1497. list_for_each_entry_safe(chan, _chan,
  1498. &device->common.channels, device_node) {
  1499. ioat_chan = to_ioat_chan(chan);
  1500. list_del(&chan->device_node);
  1501. kfree(ioat_chan);
  1502. }
  1503. kfree(device);
  1504. }