dma.c 47 KB

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