dma_v3.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright(c) 2004 - 2009 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms and conditions of the GNU General Public License,
  11. * version 2, as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * The full GNU General Public License is included in this distribution in
  23. * the file called "COPYING".
  24. *
  25. * BSD LICENSE
  26. *
  27. * Copyright(c) 2004-2009 Intel Corporation. All rights reserved.
  28. *
  29. * Redistribution and use in source and binary forms, with or without
  30. * modification, are permitted provided that the following conditions are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. * * Redistributions in binary form must reproduce the above copyright
  35. * notice, this list of conditions and the following disclaimer in
  36. * the documentation and/or other materials provided with the
  37. * distribution.
  38. * * Neither the name of Intel Corporation nor the names of its
  39. * contributors may be used to endorse or promote products derived
  40. * from this software without specific prior written permission.
  41. *
  42. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  43. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  45. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  46. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  47. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  48. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  49. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  50. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  51. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  52. * POSSIBILITY OF SUCH DAMAGE.
  53. */
  54. /*
  55. * Support routines for v3+ hardware
  56. */
  57. #include <linux/pci.h>
  58. #include <linux/dmaengine.h>
  59. #include <linux/dma-mapping.h>
  60. #include "registers.h"
  61. #include "hw.h"
  62. #include "dma.h"
  63. #include "dma_v2.h"
  64. /* ioat hardware assumes at least two sources for raid operations */
  65. #define src_cnt_to_sw(x) ((x) + 2)
  66. #define src_cnt_to_hw(x) ((x) - 2)
  67. /* provide a lookup table for setting the source address in the base or
  68. * extended descriptor of an xor or pq descriptor
  69. */
  70. static const u8 xor_idx_to_desc __read_mostly = 0xd0;
  71. static const u8 xor_idx_to_field[] __read_mostly = { 1, 4, 5, 6, 7, 0, 1, 2 };
  72. static const u8 pq_idx_to_desc __read_mostly = 0xf8;
  73. static const u8 pq_idx_to_field[] __read_mostly = { 1, 4, 5, 0, 1, 2, 4, 5 };
  74. static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx)
  75. {
  76. struct ioat_raw_descriptor *raw = descs[xor_idx_to_desc >> idx & 1];
  77. return raw->field[xor_idx_to_field[idx]];
  78. }
  79. static void xor_set_src(struct ioat_raw_descriptor *descs[2],
  80. dma_addr_t addr, u32 offset, int idx)
  81. {
  82. struct ioat_raw_descriptor *raw = descs[xor_idx_to_desc >> idx & 1];
  83. raw->field[xor_idx_to_field[idx]] = addr + offset;
  84. }
  85. static dma_addr_t pq_get_src(struct ioat_raw_descriptor *descs[2], int idx)
  86. {
  87. struct ioat_raw_descriptor *raw = descs[pq_idx_to_desc >> idx & 1];
  88. return raw->field[pq_idx_to_field[idx]];
  89. }
  90. static void pq_set_src(struct ioat_raw_descriptor *descs[2],
  91. dma_addr_t addr, u32 offset, u8 coef, int idx)
  92. {
  93. struct ioat_pq_descriptor *pq = (struct ioat_pq_descriptor *) descs[0];
  94. struct ioat_raw_descriptor *raw = descs[pq_idx_to_desc >> idx & 1];
  95. raw->field[pq_idx_to_field[idx]] = addr + offset;
  96. pq->coef[idx] = coef;
  97. }
  98. static void ioat3_dma_unmap(struct ioat2_dma_chan *ioat,
  99. struct ioat_ring_ent *desc, int idx)
  100. {
  101. struct ioat_chan_common *chan = &ioat->base;
  102. struct pci_dev *pdev = chan->device->pdev;
  103. size_t len = desc->len;
  104. size_t offset = len - desc->hw->size;
  105. struct dma_async_tx_descriptor *tx = &desc->txd;
  106. enum dma_ctrl_flags flags = tx->flags;
  107. switch (desc->hw->ctl_f.op) {
  108. case IOAT_OP_COPY:
  109. ioat_dma_unmap(chan, flags, len, desc->hw);
  110. break;
  111. case IOAT_OP_FILL: {
  112. struct ioat_fill_descriptor *hw = desc->fill;
  113. if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
  114. ioat_unmap(pdev, hw->dst_addr - offset, len,
  115. PCI_DMA_FROMDEVICE, flags, 1);
  116. break;
  117. }
  118. case IOAT_OP_XOR_VAL:
  119. case IOAT_OP_XOR: {
  120. struct ioat_xor_descriptor *xor = desc->xor;
  121. struct ioat_ring_ent *ext;
  122. struct ioat_xor_ext_descriptor *xor_ex = NULL;
  123. int src_cnt = src_cnt_to_sw(xor->ctl_f.src_cnt);
  124. struct ioat_raw_descriptor *descs[2];
  125. int i;
  126. if (src_cnt > 5) {
  127. ext = ioat2_get_ring_ent(ioat, idx + 1);
  128. xor_ex = ext->xor_ex;
  129. }
  130. if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
  131. descs[0] = (struct ioat_raw_descriptor *) xor;
  132. descs[1] = (struct ioat_raw_descriptor *) xor_ex;
  133. for (i = 0; i < src_cnt; i++) {
  134. dma_addr_t src = xor_get_src(descs, i);
  135. ioat_unmap(pdev, src - offset, len,
  136. PCI_DMA_TODEVICE, flags, 0);
  137. }
  138. /* dest is a source in xor validate operations */
  139. if (xor->ctl_f.op == IOAT_OP_XOR_VAL) {
  140. ioat_unmap(pdev, xor->dst_addr - offset, len,
  141. PCI_DMA_TODEVICE, flags, 1);
  142. break;
  143. }
  144. }
  145. if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
  146. ioat_unmap(pdev, xor->dst_addr - offset, len,
  147. PCI_DMA_FROMDEVICE, flags, 1);
  148. break;
  149. }
  150. case IOAT_OP_PQ_VAL:
  151. case IOAT_OP_PQ: {
  152. struct ioat_pq_descriptor *pq = desc->pq;
  153. struct ioat_ring_ent *ext;
  154. struct ioat_pq_ext_descriptor *pq_ex = NULL;
  155. int src_cnt = src_cnt_to_sw(pq->ctl_f.src_cnt);
  156. struct ioat_raw_descriptor *descs[2];
  157. int i;
  158. if (src_cnt > 3) {
  159. ext = ioat2_get_ring_ent(ioat, idx + 1);
  160. pq_ex = ext->pq_ex;
  161. }
  162. /* in the 'continue' case don't unmap the dests as sources */
  163. if (dmaf_p_disabled_continue(flags))
  164. src_cnt--;
  165. else if (dmaf_continue(flags))
  166. src_cnt -= 3;
  167. if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
  168. descs[0] = (struct ioat_raw_descriptor *) pq;
  169. descs[1] = (struct ioat_raw_descriptor *) pq_ex;
  170. for (i = 0; i < src_cnt; i++) {
  171. dma_addr_t src = pq_get_src(descs, i);
  172. ioat_unmap(pdev, src - offset, len,
  173. PCI_DMA_TODEVICE, flags, 0);
  174. }
  175. /* the dests are sources in pq validate operations */
  176. if (pq->ctl_f.op == IOAT_OP_XOR_VAL) {
  177. if (!(flags & DMA_PREP_PQ_DISABLE_P))
  178. ioat_unmap(pdev, pq->p_addr - offset,
  179. len, PCI_DMA_TODEVICE, flags, 0);
  180. if (!(flags & DMA_PREP_PQ_DISABLE_Q))
  181. ioat_unmap(pdev, pq->q_addr - offset,
  182. len, PCI_DMA_TODEVICE, flags, 0);
  183. break;
  184. }
  185. }
  186. if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
  187. if (!(flags & DMA_PREP_PQ_DISABLE_P))
  188. ioat_unmap(pdev, pq->p_addr - offset, len,
  189. PCI_DMA_BIDIRECTIONAL, flags, 1);
  190. if (!(flags & DMA_PREP_PQ_DISABLE_Q))
  191. ioat_unmap(pdev, pq->q_addr - offset, len,
  192. PCI_DMA_BIDIRECTIONAL, flags, 1);
  193. }
  194. break;
  195. }
  196. default:
  197. dev_err(&pdev->dev, "%s: unknown op type: %#x\n",
  198. __func__, desc->hw->ctl_f.op);
  199. }
  200. }
  201. static bool desc_has_ext(struct ioat_ring_ent *desc)
  202. {
  203. struct ioat_dma_descriptor *hw = desc->hw;
  204. if (hw->ctl_f.op == IOAT_OP_XOR ||
  205. hw->ctl_f.op == IOAT_OP_XOR_VAL) {
  206. struct ioat_xor_descriptor *xor = desc->xor;
  207. if (src_cnt_to_sw(xor->ctl_f.src_cnt) > 5)
  208. return true;
  209. } else if (hw->ctl_f.op == IOAT_OP_PQ ||
  210. hw->ctl_f.op == IOAT_OP_PQ_VAL) {
  211. struct ioat_pq_descriptor *pq = desc->pq;
  212. if (src_cnt_to_sw(pq->ctl_f.src_cnt) > 3)
  213. return true;
  214. }
  215. return false;
  216. }
  217. /**
  218. * __cleanup - reclaim used descriptors
  219. * @ioat: channel (ring) to clean
  220. *
  221. * The difference from the dma_v2.c __cleanup() is that this routine
  222. * handles extended descriptors and dma-unmapping raid operations.
  223. */
  224. static void __cleanup(struct ioat2_dma_chan *ioat, unsigned long phys_complete)
  225. {
  226. struct ioat_chan_common *chan = &ioat->base;
  227. struct ioat_ring_ent *desc;
  228. bool seen_current = false;
  229. u16 active;
  230. int i;
  231. dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n",
  232. __func__, ioat->head, ioat->tail, ioat->issued);
  233. active = ioat2_ring_active(ioat);
  234. for (i = 0; i < active && !seen_current; i++) {
  235. struct dma_async_tx_descriptor *tx;
  236. prefetch(ioat2_get_ring_ent(ioat, ioat->tail + i + 1));
  237. desc = ioat2_get_ring_ent(ioat, ioat->tail + i);
  238. dump_desc_dbg(ioat, desc);
  239. tx = &desc->txd;
  240. if (tx->cookie) {
  241. chan->completed_cookie = tx->cookie;
  242. ioat3_dma_unmap(ioat, desc, ioat->tail + i);
  243. tx->cookie = 0;
  244. if (tx->callback) {
  245. tx->callback(tx->callback_param);
  246. tx->callback = NULL;
  247. }
  248. }
  249. if (tx->phys == phys_complete)
  250. seen_current = true;
  251. /* skip extended descriptors */
  252. if (desc_has_ext(desc)) {
  253. BUG_ON(i + 1 >= active);
  254. i++;
  255. }
  256. }
  257. ioat->tail += i;
  258. BUG_ON(!seen_current); /* no active descs have written a completion? */
  259. chan->last_completion = phys_complete;
  260. if (ioat->head == ioat->tail) {
  261. dev_dbg(to_dev(chan), "%s: cancel completion timeout\n",
  262. __func__);
  263. clear_bit(IOAT_COMPLETION_PENDING, &chan->state);
  264. mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
  265. }
  266. }
  267. static void ioat3_cleanup(struct ioat2_dma_chan *ioat)
  268. {
  269. struct ioat_chan_common *chan = &ioat->base;
  270. unsigned long phys_complete;
  271. prefetch(chan->completion);
  272. if (!spin_trylock_bh(&chan->cleanup_lock))
  273. return;
  274. if (!ioat_cleanup_preamble(chan, &phys_complete)) {
  275. spin_unlock_bh(&chan->cleanup_lock);
  276. return;
  277. }
  278. if (!spin_trylock_bh(&ioat->ring_lock)) {
  279. spin_unlock_bh(&chan->cleanup_lock);
  280. return;
  281. }
  282. __cleanup(ioat, phys_complete);
  283. spin_unlock_bh(&ioat->ring_lock);
  284. spin_unlock_bh(&chan->cleanup_lock);
  285. }
  286. static void ioat3_cleanup_tasklet(unsigned long data)
  287. {
  288. struct ioat2_dma_chan *ioat = (void *) data;
  289. ioat3_cleanup(ioat);
  290. writew(IOAT_CHANCTRL_RUN | IOAT3_CHANCTRL_COMPL_DCA_EN,
  291. ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
  292. }
  293. static void ioat3_restart_channel(struct ioat2_dma_chan *ioat)
  294. {
  295. struct ioat_chan_common *chan = &ioat->base;
  296. unsigned long phys_complete;
  297. u32 status;
  298. status = ioat_chansts(chan);
  299. if (is_ioat_active(status) || is_ioat_idle(status))
  300. ioat_suspend(chan);
  301. while (is_ioat_active(status) || is_ioat_idle(status)) {
  302. status = ioat_chansts(chan);
  303. cpu_relax();
  304. }
  305. if (ioat_cleanup_preamble(chan, &phys_complete))
  306. __cleanup(ioat, phys_complete);
  307. __ioat2_restart_chan(ioat);
  308. }
  309. static void ioat3_timer_event(unsigned long data)
  310. {
  311. struct ioat2_dma_chan *ioat = (void *) data;
  312. struct ioat_chan_common *chan = &ioat->base;
  313. spin_lock_bh(&chan->cleanup_lock);
  314. if (test_bit(IOAT_COMPLETION_PENDING, &chan->state)) {
  315. unsigned long phys_complete;
  316. u64 status;
  317. spin_lock_bh(&ioat->ring_lock);
  318. status = ioat_chansts(chan);
  319. /* when halted due to errors check for channel
  320. * programming errors before advancing the completion state
  321. */
  322. if (is_ioat_halted(status)) {
  323. u32 chanerr;
  324. chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  325. BUG_ON(is_ioat_bug(chanerr));
  326. }
  327. /* if we haven't made progress and we have already
  328. * acknowledged a pending completion once, then be more
  329. * forceful with a restart
  330. */
  331. if (ioat_cleanup_preamble(chan, &phys_complete))
  332. __cleanup(ioat, phys_complete);
  333. else if (test_bit(IOAT_COMPLETION_ACK, &chan->state))
  334. ioat3_restart_channel(ioat);
  335. else {
  336. set_bit(IOAT_COMPLETION_ACK, &chan->state);
  337. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  338. }
  339. spin_unlock_bh(&ioat->ring_lock);
  340. } else {
  341. u16 active;
  342. /* if the ring is idle, empty, and oversized try to step
  343. * down the size
  344. */
  345. spin_lock_bh(&ioat->ring_lock);
  346. active = ioat2_ring_active(ioat);
  347. if (active == 0 && ioat->alloc_order > ioat_get_alloc_order())
  348. reshape_ring(ioat, ioat->alloc_order-1);
  349. spin_unlock_bh(&ioat->ring_lock);
  350. /* keep shrinking until we get back to our minimum
  351. * default size
  352. */
  353. if (ioat->alloc_order > ioat_get_alloc_order())
  354. mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
  355. }
  356. spin_unlock_bh(&chan->cleanup_lock);
  357. }
  358. static enum dma_status
  359. ioat3_is_complete(struct dma_chan *c, dma_cookie_t cookie,
  360. dma_cookie_t *done, dma_cookie_t *used)
  361. {
  362. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  363. if (ioat_is_complete(c, cookie, done, used) == DMA_SUCCESS)
  364. return DMA_SUCCESS;
  365. ioat3_cleanup(ioat);
  366. return ioat_is_complete(c, cookie, done, used);
  367. }
  368. static struct dma_async_tx_descriptor *
  369. ioat3_prep_memset_lock(struct dma_chan *c, dma_addr_t dest, int value,
  370. size_t len, unsigned long flags)
  371. {
  372. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  373. struct ioat_ring_ent *desc;
  374. size_t total_len = len;
  375. struct ioat_fill_descriptor *fill;
  376. int num_descs;
  377. u64 src_data = (0x0101010101010101ULL) * (value & 0xff);
  378. u16 idx;
  379. int i;
  380. num_descs = ioat2_xferlen_to_descs(ioat, len);
  381. if (likely(num_descs) &&
  382. ioat2_alloc_and_lock(&idx, ioat, num_descs) == 0)
  383. /* pass */;
  384. else
  385. return NULL;
  386. for (i = 0; i < num_descs; i++) {
  387. size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
  388. desc = ioat2_get_ring_ent(ioat, idx + i);
  389. fill = desc->fill;
  390. fill->size = xfer_size;
  391. fill->src_data = src_data;
  392. fill->dst_addr = dest;
  393. fill->ctl = 0;
  394. fill->ctl_f.op = IOAT_OP_FILL;
  395. len -= xfer_size;
  396. dest += xfer_size;
  397. dump_desc_dbg(ioat, desc);
  398. }
  399. desc->txd.flags = flags;
  400. desc->len = total_len;
  401. fill->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  402. fill->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  403. fill->ctl_f.compl_write = 1;
  404. dump_desc_dbg(ioat, desc);
  405. /* we leave the channel locked to ensure in order submission */
  406. return &desc->txd;
  407. }
  408. static struct dma_async_tx_descriptor *
  409. __ioat3_prep_xor_lock(struct dma_chan *c, enum sum_check_flags *result,
  410. dma_addr_t dest, dma_addr_t *src, unsigned int src_cnt,
  411. size_t len, unsigned long flags)
  412. {
  413. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  414. struct ioat_ring_ent *compl_desc;
  415. struct ioat_ring_ent *desc;
  416. struct ioat_ring_ent *ext;
  417. size_t total_len = len;
  418. struct ioat_xor_descriptor *xor;
  419. struct ioat_xor_ext_descriptor *xor_ex = NULL;
  420. struct ioat_dma_descriptor *hw;
  421. u32 offset = 0;
  422. int num_descs;
  423. int with_ext;
  424. int i;
  425. u16 idx;
  426. u8 op = result ? IOAT_OP_XOR_VAL : IOAT_OP_XOR;
  427. BUG_ON(src_cnt < 2);
  428. num_descs = ioat2_xferlen_to_descs(ioat, len);
  429. /* we need 2x the number of descriptors to cover greater than 5
  430. * sources
  431. */
  432. if (src_cnt > 5) {
  433. with_ext = 1;
  434. num_descs *= 2;
  435. } else
  436. with_ext = 0;
  437. /* completion writes from the raid engine may pass completion
  438. * writes from the legacy engine, so we need one extra null
  439. * (legacy) descriptor to ensure all completion writes arrive in
  440. * order.
  441. */
  442. if (likely(num_descs) &&
  443. ioat2_alloc_and_lock(&idx, ioat, num_descs+1) == 0)
  444. /* pass */;
  445. else
  446. return NULL;
  447. for (i = 0; i < num_descs; i += 1 + with_ext) {
  448. struct ioat_raw_descriptor *descs[2];
  449. size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
  450. int s;
  451. desc = ioat2_get_ring_ent(ioat, idx + i);
  452. xor = desc->xor;
  453. /* save a branch by unconditionally retrieving the
  454. * extended descriptor xor_set_src() knows to not write
  455. * to it in the single descriptor case
  456. */
  457. ext = ioat2_get_ring_ent(ioat, idx + i + 1);
  458. xor_ex = ext->xor_ex;
  459. descs[0] = (struct ioat_raw_descriptor *) xor;
  460. descs[1] = (struct ioat_raw_descriptor *) xor_ex;
  461. for (s = 0; s < src_cnt; s++)
  462. xor_set_src(descs, src[s], offset, s);
  463. xor->size = xfer_size;
  464. xor->dst_addr = dest + offset;
  465. xor->ctl = 0;
  466. xor->ctl_f.op = op;
  467. xor->ctl_f.src_cnt = src_cnt_to_hw(src_cnt);
  468. len -= xfer_size;
  469. offset += xfer_size;
  470. dump_desc_dbg(ioat, desc);
  471. }
  472. /* last xor descriptor carries the unmap parameters and fence bit */
  473. desc->txd.flags = flags;
  474. desc->len = total_len;
  475. if (result)
  476. desc->result = result;
  477. xor->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  478. /* completion descriptor carries interrupt bit */
  479. compl_desc = ioat2_get_ring_ent(ioat, idx + i);
  480. compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
  481. hw = compl_desc->hw;
  482. hw->ctl = 0;
  483. hw->ctl_f.null = 1;
  484. hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  485. hw->ctl_f.compl_write = 1;
  486. hw->size = NULL_DESC_BUFFER_SIZE;
  487. dump_desc_dbg(ioat, compl_desc);
  488. /* we leave the channel locked to ensure in order submission */
  489. return &desc->txd;
  490. }
  491. static struct dma_async_tx_descriptor *
  492. ioat3_prep_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
  493. unsigned int src_cnt, size_t len, unsigned long flags)
  494. {
  495. return __ioat3_prep_xor_lock(chan, NULL, dest, src, src_cnt, len, flags);
  496. }
  497. struct dma_async_tx_descriptor *
  498. ioat3_prep_xor_val(struct dma_chan *chan, dma_addr_t *src,
  499. unsigned int src_cnt, size_t len,
  500. enum sum_check_flags *result, unsigned long flags)
  501. {
  502. /* the cleanup routine only sets bits on validate failure, it
  503. * does not clear bits on validate success... so clear it here
  504. */
  505. *result = 0;
  506. return __ioat3_prep_xor_lock(chan, result, src[0], &src[1],
  507. src_cnt - 1, len, flags);
  508. }
  509. static void
  510. dump_pq_desc_dbg(struct ioat2_dma_chan *ioat, struct ioat_ring_ent *desc, struct ioat_ring_ent *ext)
  511. {
  512. struct device *dev = to_dev(&ioat->base);
  513. struct ioat_pq_descriptor *pq = desc->pq;
  514. struct ioat_pq_ext_descriptor *pq_ex = ext ? ext->pq_ex : NULL;
  515. struct ioat_raw_descriptor *descs[] = { (void *) pq, (void *) pq_ex };
  516. int src_cnt = src_cnt_to_sw(pq->ctl_f.src_cnt);
  517. int i;
  518. dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x"
  519. " sz: %#x ctl: %#x (op: %d int: %d compl: %d pq: '%s%s' src_cnt: %d)\n",
  520. desc_id(desc), (unsigned long long) desc->txd.phys,
  521. (unsigned long long) (pq_ex ? pq_ex->next : pq->next),
  522. desc->txd.flags, pq->size, pq->ctl, pq->ctl_f.op, pq->ctl_f.int_en,
  523. pq->ctl_f.compl_write,
  524. pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q",
  525. pq->ctl_f.src_cnt);
  526. for (i = 0; i < src_cnt; i++)
  527. dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i,
  528. (unsigned long long) pq_get_src(descs, i), pq->coef[i]);
  529. dev_dbg(dev, "\tP: %#llx\n", pq->p_addr);
  530. dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr);
  531. }
  532. static struct dma_async_tx_descriptor *
  533. __ioat3_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result,
  534. const dma_addr_t *dst, const dma_addr_t *src,
  535. unsigned int src_cnt, const unsigned char *scf,
  536. size_t len, unsigned long flags)
  537. {
  538. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  539. struct ioat_chan_common *chan = &ioat->base;
  540. struct ioat_ring_ent *compl_desc;
  541. struct ioat_ring_ent *desc;
  542. struct ioat_ring_ent *ext;
  543. size_t total_len = len;
  544. struct ioat_pq_descriptor *pq;
  545. struct ioat_pq_ext_descriptor *pq_ex = NULL;
  546. struct ioat_dma_descriptor *hw;
  547. u32 offset = 0;
  548. int num_descs;
  549. int with_ext;
  550. int i, s;
  551. u16 idx;
  552. u8 op = result ? IOAT_OP_PQ_VAL : IOAT_OP_PQ;
  553. dev_dbg(to_dev(chan), "%s\n", __func__);
  554. /* the engine requires at least two sources (we provide
  555. * at least 1 implied source in the DMA_PREP_CONTINUE case)
  556. */
  557. BUG_ON(src_cnt + dmaf_continue(flags) < 2);
  558. num_descs = ioat2_xferlen_to_descs(ioat, len);
  559. /* we need 2x the number of descriptors to cover greater than 3
  560. * sources
  561. */
  562. if (src_cnt > 3 || flags & DMA_PREP_CONTINUE) {
  563. with_ext = 1;
  564. num_descs *= 2;
  565. } else
  566. with_ext = 0;
  567. /* completion writes from the raid engine may pass completion
  568. * writes from the legacy engine, so we need one extra null
  569. * (legacy) descriptor to ensure all completion writes arrive in
  570. * order.
  571. */
  572. if (likely(num_descs) &&
  573. ioat2_alloc_and_lock(&idx, ioat, num_descs+1) == 0)
  574. /* pass */;
  575. else
  576. return NULL;
  577. for (i = 0; i < num_descs; i += 1 + with_ext) {
  578. struct ioat_raw_descriptor *descs[2];
  579. size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
  580. desc = ioat2_get_ring_ent(ioat, idx + i);
  581. pq = desc->pq;
  582. /* save a branch by unconditionally retrieving the
  583. * extended descriptor pq_set_src() knows to not write
  584. * to it in the single descriptor case
  585. */
  586. ext = ioat2_get_ring_ent(ioat, idx + i + with_ext);
  587. pq_ex = ext->pq_ex;
  588. descs[0] = (struct ioat_raw_descriptor *) pq;
  589. descs[1] = (struct ioat_raw_descriptor *) pq_ex;
  590. for (s = 0; s < src_cnt; s++)
  591. pq_set_src(descs, src[s], offset, scf[s], s);
  592. /* see the comment for dma_maxpq in include/linux/dmaengine.h */
  593. if (dmaf_p_disabled_continue(flags))
  594. pq_set_src(descs, dst[1], offset, 1, s++);
  595. else if (dmaf_continue(flags)) {
  596. pq_set_src(descs, dst[0], offset, 0, s++);
  597. pq_set_src(descs, dst[1], offset, 1, s++);
  598. pq_set_src(descs, dst[1], offset, 0, s++);
  599. }
  600. pq->size = xfer_size;
  601. pq->p_addr = dst[0] + offset;
  602. pq->q_addr = dst[1] + offset;
  603. pq->ctl = 0;
  604. pq->ctl_f.op = op;
  605. pq->ctl_f.src_cnt = src_cnt_to_hw(s);
  606. pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
  607. pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
  608. len -= xfer_size;
  609. offset += xfer_size;
  610. }
  611. /* last pq descriptor carries the unmap parameters and fence bit */
  612. desc->txd.flags = flags;
  613. desc->len = total_len;
  614. if (result)
  615. desc->result = result;
  616. pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  617. dump_pq_desc_dbg(ioat, desc, ext);
  618. /* completion descriptor carries interrupt bit */
  619. compl_desc = ioat2_get_ring_ent(ioat, idx + i);
  620. compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
  621. hw = compl_desc->hw;
  622. hw->ctl = 0;
  623. hw->ctl_f.null = 1;
  624. hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  625. hw->ctl_f.compl_write = 1;
  626. hw->size = NULL_DESC_BUFFER_SIZE;
  627. dump_desc_dbg(ioat, compl_desc);
  628. /* we leave the channel locked to ensure in order submission */
  629. return &desc->txd;
  630. }
  631. static struct dma_async_tx_descriptor *
  632. ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
  633. unsigned int src_cnt, const unsigned char *scf, size_t len,
  634. unsigned long flags)
  635. {
  636. /* handle the single source multiply case from the raid6
  637. * recovery path
  638. */
  639. if (unlikely((flags & DMA_PREP_PQ_DISABLE_P) && src_cnt == 1)) {
  640. dma_addr_t single_source[2];
  641. unsigned char single_source_coef[2];
  642. BUG_ON(flags & DMA_PREP_PQ_DISABLE_Q);
  643. single_source[0] = src[0];
  644. single_source[1] = src[0];
  645. single_source_coef[0] = scf[0];
  646. single_source_coef[1] = 0;
  647. return __ioat3_prep_pq_lock(chan, NULL, dst, single_source, 2,
  648. single_source_coef, len, flags);
  649. } else
  650. return __ioat3_prep_pq_lock(chan, NULL, dst, src, src_cnt, scf,
  651. len, flags);
  652. }
  653. struct dma_async_tx_descriptor *
  654. ioat3_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
  655. unsigned int src_cnt, const unsigned char *scf, size_t len,
  656. enum sum_check_flags *pqres, unsigned long flags)
  657. {
  658. /* the cleanup routine only sets bits on validate failure, it
  659. * does not clear bits on validate success... so clear it here
  660. */
  661. *pqres = 0;
  662. return __ioat3_prep_pq_lock(chan, pqres, pq, src, src_cnt, scf, len,
  663. flags);
  664. }
  665. static struct dma_async_tx_descriptor *
  666. ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
  667. unsigned int src_cnt, size_t len, unsigned long flags)
  668. {
  669. unsigned char scf[src_cnt];
  670. dma_addr_t pq[2];
  671. memset(scf, 0, src_cnt);
  672. flags |= DMA_PREP_PQ_DISABLE_Q;
  673. pq[0] = dst;
  674. pq[1] = ~0;
  675. return __ioat3_prep_pq_lock(chan, NULL, pq, src, src_cnt, scf, len,
  676. flags);
  677. }
  678. struct dma_async_tx_descriptor *
  679. ioat3_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
  680. unsigned int src_cnt, size_t len,
  681. enum sum_check_flags *result, unsigned long flags)
  682. {
  683. unsigned char scf[src_cnt];
  684. dma_addr_t pq[2];
  685. /* the cleanup routine only sets bits on validate failure, it
  686. * does not clear bits on validate success... so clear it here
  687. */
  688. *result = 0;
  689. memset(scf, 0, src_cnt);
  690. flags |= DMA_PREP_PQ_DISABLE_Q;
  691. pq[0] = src[0];
  692. pq[1] = ~0;
  693. return __ioat3_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1, scf,
  694. len, flags);
  695. }
  696. static void __devinit ioat3_dma_test_callback(void *dma_async_param)
  697. {
  698. struct completion *cmp = dma_async_param;
  699. complete(cmp);
  700. }
  701. #define IOAT_NUM_SRC_TEST 6 /* must be <= 8 */
  702. static int __devinit ioat_xor_val_self_test(struct ioatdma_device *device)
  703. {
  704. int i, src_idx;
  705. struct page *dest;
  706. struct page *xor_srcs[IOAT_NUM_SRC_TEST];
  707. struct page *xor_val_srcs[IOAT_NUM_SRC_TEST + 1];
  708. dma_addr_t dma_srcs[IOAT_NUM_SRC_TEST + 1];
  709. dma_addr_t dma_addr, dest_dma;
  710. struct dma_async_tx_descriptor *tx;
  711. struct dma_chan *dma_chan;
  712. dma_cookie_t cookie;
  713. u8 cmp_byte = 0;
  714. u32 cmp_word;
  715. u32 xor_val_result;
  716. int err = 0;
  717. struct completion cmp;
  718. unsigned long tmo;
  719. struct device *dev = &device->pdev->dev;
  720. struct dma_device *dma = &device->common;
  721. dev_dbg(dev, "%s\n", __func__);
  722. if (!dma_has_cap(DMA_XOR, dma->cap_mask))
  723. return 0;
  724. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) {
  725. xor_srcs[src_idx] = alloc_page(GFP_KERNEL);
  726. if (!xor_srcs[src_idx]) {
  727. while (src_idx--)
  728. __free_page(xor_srcs[src_idx]);
  729. return -ENOMEM;
  730. }
  731. }
  732. dest = alloc_page(GFP_KERNEL);
  733. if (!dest) {
  734. while (src_idx--)
  735. __free_page(xor_srcs[src_idx]);
  736. return -ENOMEM;
  737. }
  738. /* Fill in src buffers */
  739. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) {
  740. u8 *ptr = page_address(xor_srcs[src_idx]);
  741. for (i = 0; i < PAGE_SIZE; i++)
  742. ptr[i] = (1 << src_idx);
  743. }
  744. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++)
  745. cmp_byte ^= (u8) (1 << src_idx);
  746. cmp_word = (cmp_byte << 24) | (cmp_byte << 16) |
  747. (cmp_byte << 8) | cmp_byte;
  748. memset(page_address(dest), 0, PAGE_SIZE);
  749. dma_chan = container_of(dma->channels.next, struct dma_chan,
  750. device_node);
  751. if (dma->device_alloc_chan_resources(dma_chan) < 1) {
  752. err = -ENODEV;
  753. goto out;
  754. }
  755. /* test xor */
  756. dest_dma = dma_map_page(dev, dest, 0, PAGE_SIZE, DMA_FROM_DEVICE);
  757. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  758. dma_srcs[i] = dma_map_page(dev, xor_srcs[i], 0, PAGE_SIZE,
  759. DMA_TO_DEVICE);
  760. tx = dma->device_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
  761. IOAT_NUM_SRC_TEST, PAGE_SIZE,
  762. DMA_PREP_INTERRUPT);
  763. if (!tx) {
  764. dev_err(dev, "Self-test xor prep failed\n");
  765. err = -ENODEV;
  766. goto free_resources;
  767. }
  768. async_tx_ack(tx);
  769. init_completion(&cmp);
  770. tx->callback = ioat3_dma_test_callback;
  771. tx->callback_param = &cmp;
  772. cookie = tx->tx_submit(tx);
  773. if (cookie < 0) {
  774. dev_err(dev, "Self-test xor setup failed\n");
  775. err = -ENODEV;
  776. goto free_resources;
  777. }
  778. dma->device_issue_pending(dma_chan);
  779. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  780. if (dma->device_is_tx_complete(dma_chan, cookie, NULL, NULL) != DMA_SUCCESS) {
  781. dev_err(dev, "Self-test xor timed out\n");
  782. err = -ENODEV;
  783. goto free_resources;
  784. }
  785. dma_sync_single_for_cpu(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  786. for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) {
  787. u32 *ptr = page_address(dest);
  788. if (ptr[i] != cmp_word) {
  789. dev_err(dev, "Self-test xor failed compare\n");
  790. err = -ENODEV;
  791. goto free_resources;
  792. }
  793. }
  794. dma_sync_single_for_device(dev, dest_dma, PAGE_SIZE, DMA_TO_DEVICE);
  795. /* skip validate if the capability is not present */
  796. if (!dma_has_cap(DMA_XOR_VAL, dma_chan->device->cap_mask))
  797. goto free_resources;
  798. /* validate the sources with the destintation page */
  799. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  800. xor_val_srcs[i] = xor_srcs[i];
  801. xor_val_srcs[i] = dest;
  802. xor_val_result = 1;
  803. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  804. dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE,
  805. DMA_TO_DEVICE);
  806. tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
  807. IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
  808. &xor_val_result, DMA_PREP_INTERRUPT);
  809. if (!tx) {
  810. dev_err(dev, "Self-test zero prep failed\n");
  811. err = -ENODEV;
  812. goto free_resources;
  813. }
  814. async_tx_ack(tx);
  815. init_completion(&cmp);
  816. tx->callback = ioat3_dma_test_callback;
  817. tx->callback_param = &cmp;
  818. cookie = tx->tx_submit(tx);
  819. if (cookie < 0) {
  820. dev_err(dev, "Self-test zero setup failed\n");
  821. err = -ENODEV;
  822. goto free_resources;
  823. }
  824. dma->device_issue_pending(dma_chan);
  825. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  826. if (dma->device_is_tx_complete(dma_chan, cookie, NULL, NULL) != DMA_SUCCESS) {
  827. dev_err(dev, "Self-test validate timed out\n");
  828. err = -ENODEV;
  829. goto free_resources;
  830. }
  831. if (xor_val_result != 0) {
  832. dev_err(dev, "Self-test validate failed compare\n");
  833. err = -ENODEV;
  834. goto free_resources;
  835. }
  836. /* skip memset if the capability is not present */
  837. if (!dma_has_cap(DMA_MEMSET, dma_chan->device->cap_mask))
  838. goto free_resources;
  839. /* test memset */
  840. dma_addr = dma_map_page(dev, dest, 0,
  841. PAGE_SIZE, DMA_FROM_DEVICE);
  842. tx = dma->device_prep_dma_memset(dma_chan, dma_addr, 0, PAGE_SIZE,
  843. DMA_PREP_INTERRUPT);
  844. if (!tx) {
  845. dev_err(dev, "Self-test memset prep failed\n");
  846. err = -ENODEV;
  847. goto free_resources;
  848. }
  849. async_tx_ack(tx);
  850. init_completion(&cmp);
  851. tx->callback = ioat3_dma_test_callback;
  852. tx->callback_param = &cmp;
  853. cookie = tx->tx_submit(tx);
  854. if (cookie < 0) {
  855. dev_err(dev, "Self-test memset setup failed\n");
  856. err = -ENODEV;
  857. goto free_resources;
  858. }
  859. dma->device_issue_pending(dma_chan);
  860. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  861. if (dma->device_is_tx_complete(dma_chan, cookie, NULL, NULL) != DMA_SUCCESS) {
  862. dev_err(dev, "Self-test memset timed out\n");
  863. err = -ENODEV;
  864. goto free_resources;
  865. }
  866. for (i = 0; i < PAGE_SIZE/sizeof(u32); i++) {
  867. u32 *ptr = page_address(dest);
  868. if (ptr[i]) {
  869. dev_err(dev, "Self-test memset failed compare\n");
  870. err = -ENODEV;
  871. goto free_resources;
  872. }
  873. }
  874. /* test for non-zero parity sum */
  875. xor_val_result = 0;
  876. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  877. dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE,
  878. DMA_TO_DEVICE);
  879. tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
  880. IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
  881. &xor_val_result, DMA_PREP_INTERRUPT);
  882. if (!tx) {
  883. dev_err(dev, "Self-test 2nd zero prep failed\n");
  884. err = -ENODEV;
  885. goto free_resources;
  886. }
  887. async_tx_ack(tx);
  888. init_completion(&cmp);
  889. tx->callback = ioat3_dma_test_callback;
  890. tx->callback_param = &cmp;
  891. cookie = tx->tx_submit(tx);
  892. if (cookie < 0) {
  893. dev_err(dev, "Self-test 2nd zero setup failed\n");
  894. err = -ENODEV;
  895. goto free_resources;
  896. }
  897. dma->device_issue_pending(dma_chan);
  898. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  899. if (dma->device_is_tx_complete(dma_chan, cookie, NULL, NULL) != DMA_SUCCESS) {
  900. dev_err(dev, "Self-test 2nd validate timed out\n");
  901. err = -ENODEV;
  902. goto free_resources;
  903. }
  904. if (xor_val_result != SUM_CHECK_P_RESULT) {
  905. dev_err(dev, "Self-test validate failed compare\n");
  906. err = -ENODEV;
  907. goto free_resources;
  908. }
  909. free_resources:
  910. dma->device_free_chan_resources(dma_chan);
  911. out:
  912. src_idx = IOAT_NUM_SRC_TEST;
  913. while (src_idx--)
  914. __free_page(xor_srcs[src_idx]);
  915. __free_page(dest);
  916. return err;
  917. }
  918. static int __devinit ioat3_dma_self_test(struct ioatdma_device *device)
  919. {
  920. int rc = ioat_dma_self_test(device);
  921. if (rc)
  922. return rc;
  923. rc = ioat_xor_val_self_test(device);
  924. if (rc)
  925. return rc;
  926. return 0;
  927. }
  928. int __devinit ioat3_dma_probe(struct ioatdma_device *device, int dca)
  929. {
  930. struct pci_dev *pdev = device->pdev;
  931. struct dma_device *dma;
  932. struct dma_chan *c;
  933. struct ioat_chan_common *chan;
  934. int err;
  935. u16 dev_id;
  936. u32 cap;
  937. device->enumerate_channels = ioat2_enumerate_channels;
  938. device->cleanup_tasklet = ioat3_cleanup_tasklet;
  939. device->timer_fn = ioat3_timer_event;
  940. device->self_test = ioat3_dma_self_test;
  941. dma = &device->common;
  942. dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock;
  943. dma->device_issue_pending = ioat2_issue_pending;
  944. dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
  945. dma->device_free_chan_resources = ioat2_free_chan_resources;
  946. dma->device_is_tx_complete = ioat3_is_complete;
  947. cap = readl(device->reg_base + IOAT_DMA_CAP_OFFSET);
  948. if (cap & IOAT_CAP_FILL_BLOCK) {
  949. dma_cap_set(DMA_MEMSET, dma->cap_mask);
  950. dma->device_prep_dma_memset = ioat3_prep_memset_lock;
  951. }
  952. if (cap & IOAT_CAP_XOR) {
  953. dma->max_xor = 8;
  954. dma->xor_align = 2;
  955. dma_cap_set(DMA_XOR, dma->cap_mask);
  956. dma->device_prep_dma_xor = ioat3_prep_xor;
  957. dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
  958. dma->device_prep_dma_xor_val = ioat3_prep_xor_val;
  959. }
  960. if (cap & IOAT_CAP_PQ) {
  961. dma_set_maxpq(dma, 8, 0);
  962. dma->pq_align = 2;
  963. dma_cap_set(DMA_PQ, dma->cap_mask);
  964. dma->device_prep_dma_pq = ioat3_prep_pq;
  965. dma_cap_set(DMA_PQ_VAL, dma->cap_mask);
  966. dma->device_prep_dma_pq_val = ioat3_prep_pq_val;
  967. if (!(cap & IOAT_CAP_XOR)) {
  968. dma->max_xor = 8;
  969. dma->xor_align = 2;
  970. dma_cap_set(DMA_XOR, dma->cap_mask);
  971. dma->device_prep_dma_xor = ioat3_prep_pqxor;
  972. dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
  973. dma->device_prep_dma_xor_val = ioat3_prep_pqxor_val;
  974. }
  975. }
  976. /* -= IOAT ver.3 workarounds =- */
  977. /* Write CHANERRMSK_INT with 3E07h to mask out the errors
  978. * that can cause stability issues for IOAT ver.3
  979. */
  980. pci_write_config_dword(pdev, IOAT_PCI_CHANERRMASK_INT_OFFSET, 0x3e07);
  981. /* Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit
  982. * (workaround for spurious config parity error after restart)
  983. */
  984. pci_read_config_word(pdev, IOAT_PCI_DEVICE_ID_OFFSET, &dev_id);
  985. if (dev_id == PCI_DEVICE_ID_INTEL_IOAT_TBG0)
  986. pci_write_config_dword(pdev, IOAT_PCI_DMAUNCERRSTS_OFFSET, 0x10);
  987. err = ioat_probe(device);
  988. if (err)
  989. return err;
  990. ioat_set_tcp_copy_break(262144);
  991. list_for_each_entry(c, &dma->channels, device_node) {
  992. chan = to_chan_common(c);
  993. writel(IOAT_DMA_DCA_ANY_CPU,
  994. chan->reg_base + IOAT_DCACTRL_OFFSET);
  995. }
  996. err = ioat_register(device);
  997. if (err)
  998. return err;
  999. ioat_kobject_add(device, &ioat2_ktype);
  1000. if (dca)
  1001. device->dca = ioat3_dca_init(pdev, device->reg_base);
  1002. return 0;
  1003. }