dma_v3.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  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/module.h>
  58. #include <linux/pci.h>
  59. #include <linux/gfp.h>
  60. #include <linux/dmaengine.h>
  61. #include <linux/dma-mapping.h>
  62. #include <linux/prefetch.h>
  63. #include "../dmaengine.h"
  64. #include "registers.h"
  65. #include "hw.h"
  66. #include "dma.h"
  67. #include "dma_v2.h"
  68. extern struct kmem_cache *ioat3_sed_cache;
  69. /* ioat hardware assumes at least two sources for raid operations */
  70. #define src_cnt_to_sw(x) ((x) + 2)
  71. #define src_cnt_to_hw(x) ((x) - 2)
  72. #define ndest_to_sw(x) ((x) + 1)
  73. #define ndest_to_hw(x) ((x) - 1)
  74. #define src16_cnt_to_sw(x) ((x) + 9)
  75. #define src16_cnt_to_hw(x) ((x) - 9)
  76. /* provide a lookup table for setting the source address in the base or
  77. * extended descriptor of an xor or pq descriptor
  78. */
  79. static const u8 xor_idx_to_desc = 0xe0;
  80. static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 };
  81. static const u8 pq_idx_to_desc = 0xf8;
  82. static const u8 pq16_idx_to_desc[] = { 0, 0, 1, 1, 1, 1, 1, 1, 1,
  83. 2, 2, 2, 2, 2, 2, 2 };
  84. static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 };
  85. static const u8 pq16_idx_to_field[] = { 1, 4, 1, 2, 3, 4, 5, 6, 7,
  86. 0, 1, 2, 3, 4, 5, 6 };
  87. static void ioat3_eh(struct ioat2_dma_chan *ioat);
  88. static void xor_set_src(struct ioat_raw_descriptor *descs[2],
  89. dma_addr_t addr, u32 offset, int idx)
  90. {
  91. struct ioat_raw_descriptor *raw = descs[xor_idx_to_desc >> idx & 1];
  92. raw->field[xor_idx_to_field[idx]] = addr + offset;
  93. }
  94. static dma_addr_t pq_get_src(struct ioat_raw_descriptor *descs[2], int idx)
  95. {
  96. struct ioat_raw_descriptor *raw = descs[pq_idx_to_desc >> idx & 1];
  97. return raw->field[pq_idx_to_field[idx]];
  98. }
  99. static dma_addr_t pq16_get_src(struct ioat_raw_descriptor *desc[3], int idx)
  100. {
  101. struct ioat_raw_descriptor *raw = desc[pq16_idx_to_desc[idx]];
  102. return raw->field[pq16_idx_to_field[idx]];
  103. }
  104. static void pq_set_src(struct ioat_raw_descriptor *descs[2],
  105. dma_addr_t addr, u32 offset, u8 coef, int idx)
  106. {
  107. struct ioat_pq_descriptor *pq = (struct ioat_pq_descriptor *) descs[0];
  108. struct ioat_raw_descriptor *raw = descs[pq_idx_to_desc >> idx & 1];
  109. raw->field[pq_idx_to_field[idx]] = addr + offset;
  110. pq->coef[idx] = coef;
  111. }
  112. static bool is_jf_ioat(struct pci_dev *pdev)
  113. {
  114. switch (pdev->device) {
  115. case PCI_DEVICE_ID_INTEL_IOAT_JSF0:
  116. case PCI_DEVICE_ID_INTEL_IOAT_JSF1:
  117. case PCI_DEVICE_ID_INTEL_IOAT_JSF2:
  118. case PCI_DEVICE_ID_INTEL_IOAT_JSF3:
  119. case PCI_DEVICE_ID_INTEL_IOAT_JSF4:
  120. case PCI_DEVICE_ID_INTEL_IOAT_JSF5:
  121. case PCI_DEVICE_ID_INTEL_IOAT_JSF6:
  122. case PCI_DEVICE_ID_INTEL_IOAT_JSF7:
  123. case PCI_DEVICE_ID_INTEL_IOAT_JSF8:
  124. case PCI_DEVICE_ID_INTEL_IOAT_JSF9:
  125. return true;
  126. default:
  127. return false;
  128. }
  129. }
  130. static bool is_snb_ioat(struct pci_dev *pdev)
  131. {
  132. switch (pdev->device) {
  133. case PCI_DEVICE_ID_INTEL_IOAT_SNB0:
  134. case PCI_DEVICE_ID_INTEL_IOAT_SNB1:
  135. case PCI_DEVICE_ID_INTEL_IOAT_SNB2:
  136. case PCI_DEVICE_ID_INTEL_IOAT_SNB3:
  137. case PCI_DEVICE_ID_INTEL_IOAT_SNB4:
  138. case PCI_DEVICE_ID_INTEL_IOAT_SNB5:
  139. case PCI_DEVICE_ID_INTEL_IOAT_SNB6:
  140. case PCI_DEVICE_ID_INTEL_IOAT_SNB7:
  141. case PCI_DEVICE_ID_INTEL_IOAT_SNB8:
  142. case PCI_DEVICE_ID_INTEL_IOAT_SNB9:
  143. return true;
  144. default:
  145. return false;
  146. }
  147. }
  148. static bool is_ivb_ioat(struct pci_dev *pdev)
  149. {
  150. switch (pdev->device) {
  151. case PCI_DEVICE_ID_INTEL_IOAT_IVB0:
  152. case PCI_DEVICE_ID_INTEL_IOAT_IVB1:
  153. case PCI_DEVICE_ID_INTEL_IOAT_IVB2:
  154. case PCI_DEVICE_ID_INTEL_IOAT_IVB3:
  155. case PCI_DEVICE_ID_INTEL_IOAT_IVB4:
  156. case PCI_DEVICE_ID_INTEL_IOAT_IVB5:
  157. case PCI_DEVICE_ID_INTEL_IOAT_IVB6:
  158. case PCI_DEVICE_ID_INTEL_IOAT_IVB7:
  159. case PCI_DEVICE_ID_INTEL_IOAT_IVB8:
  160. case PCI_DEVICE_ID_INTEL_IOAT_IVB9:
  161. return true;
  162. default:
  163. return false;
  164. }
  165. }
  166. static bool is_hsw_ioat(struct pci_dev *pdev)
  167. {
  168. switch (pdev->device) {
  169. case PCI_DEVICE_ID_INTEL_IOAT_HSW0:
  170. case PCI_DEVICE_ID_INTEL_IOAT_HSW1:
  171. case PCI_DEVICE_ID_INTEL_IOAT_HSW2:
  172. case PCI_DEVICE_ID_INTEL_IOAT_HSW3:
  173. case PCI_DEVICE_ID_INTEL_IOAT_HSW4:
  174. case PCI_DEVICE_ID_INTEL_IOAT_HSW5:
  175. case PCI_DEVICE_ID_INTEL_IOAT_HSW6:
  176. case PCI_DEVICE_ID_INTEL_IOAT_HSW7:
  177. case PCI_DEVICE_ID_INTEL_IOAT_HSW8:
  178. case PCI_DEVICE_ID_INTEL_IOAT_HSW9:
  179. return true;
  180. default:
  181. return false;
  182. }
  183. }
  184. static bool is_xeon_cb32(struct pci_dev *pdev)
  185. {
  186. return is_jf_ioat(pdev) || is_snb_ioat(pdev) || is_ivb_ioat(pdev) ||
  187. is_hsw_ioat(pdev);
  188. }
  189. static bool is_bwd_ioat(struct pci_dev *pdev)
  190. {
  191. switch (pdev->device) {
  192. case PCI_DEVICE_ID_INTEL_IOAT_BWD0:
  193. case PCI_DEVICE_ID_INTEL_IOAT_BWD1:
  194. case PCI_DEVICE_ID_INTEL_IOAT_BWD2:
  195. case PCI_DEVICE_ID_INTEL_IOAT_BWD3:
  196. return true;
  197. default:
  198. return false;
  199. }
  200. }
  201. static bool is_bwd_noraid(struct pci_dev *pdev)
  202. {
  203. switch (pdev->device) {
  204. case PCI_DEVICE_ID_INTEL_IOAT_BWD2:
  205. case PCI_DEVICE_ID_INTEL_IOAT_BWD3:
  206. return true;
  207. default:
  208. return false;
  209. }
  210. }
  211. static void pq16_set_src(struct ioat_raw_descriptor *desc[3],
  212. dma_addr_t addr, u32 offset, u8 coef, unsigned idx)
  213. {
  214. struct ioat_pq_descriptor *pq = (struct ioat_pq_descriptor *)desc[0];
  215. struct ioat_pq16a_descriptor *pq16 =
  216. (struct ioat_pq16a_descriptor *)desc[1];
  217. struct ioat_raw_descriptor *raw = desc[pq16_idx_to_desc[idx]];
  218. raw->field[pq16_idx_to_field[idx]] = addr + offset;
  219. if (idx < 8)
  220. pq->coef[idx] = coef;
  221. else
  222. pq16->coef[idx - 8] = coef;
  223. }
  224. static struct ioat_sed_ent *
  225. ioat3_alloc_sed(struct ioatdma_device *device, unsigned int hw_pool)
  226. {
  227. struct ioat_sed_ent *sed;
  228. gfp_t flags = __GFP_ZERO | GFP_ATOMIC;
  229. sed = kmem_cache_alloc(ioat3_sed_cache, flags);
  230. if (!sed)
  231. return NULL;
  232. sed->hw_pool = hw_pool;
  233. sed->hw = dma_pool_alloc(device->sed_hw_pool[hw_pool],
  234. flags, &sed->dma);
  235. if (!sed->hw) {
  236. kmem_cache_free(ioat3_sed_cache, sed);
  237. return NULL;
  238. }
  239. return sed;
  240. }
  241. static void ioat3_free_sed(struct ioatdma_device *device, struct ioat_sed_ent *sed)
  242. {
  243. if (!sed)
  244. return;
  245. dma_pool_free(device->sed_hw_pool[sed->hw_pool], sed->hw, sed->dma);
  246. kmem_cache_free(ioat3_sed_cache, sed);
  247. }
  248. static bool desc_has_ext(struct ioat_ring_ent *desc)
  249. {
  250. struct ioat_dma_descriptor *hw = desc->hw;
  251. if (hw->ctl_f.op == IOAT_OP_XOR ||
  252. hw->ctl_f.op == IOAT_OP_XOR_VAL) {
  253. struct ioat_xor_descriptor *xor = desc->xor;
  254. if (src_cnt_to_sw(xor->ctl_f.src_cnt) > 5)
  255. return true;
  256. } else if (hw->ctl_f.op == IOAT_OP_PQ ||
  257. hw->ctl_f.op == IOAT_OP_PQ_VAL) {
  258. struct ioat_pq_descriptor *pq = desc->pq;
  259. if (src_cnt_to_sw(pq->ctl_f.src_cnt) > 3)
  260. return true;
  261. }
  262. return false;
  263. }
  264. static u64 ioat3_get_current_completion(struct ioat_chan_common *chan)
  265. {
  266. u64 phys_complete;
  267. u64 completion;
  268. completion = *chan->completion;
  269. phys_complete = ioat_chansts_to_addr(completion);
  270. dev_dbg(to_dev(chan), "%s: phys_complete: %#llx\n", __func__,
  271. (unsigned long long) phys_complete);
  272. return phys_complete;
  273. }
  274. static bool ioat3_cleanup_preamble(struct ioat_chan_common *chan,
  275. u64 *phys_complete)
  276. {
  277. *phys_complete = ioat3_get_current_completion(chan);
  278. if (*phys_complete == chan->last_completion)
  279. return false;
  280. clear_bit(IOAT_COMPLETION_ACK, &chan->state);
  281. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  282. return true;
  283. }
  284. static void
  285. desc_get_errstat(struct ioat2_dma_chan *ioat, struct ioat_ring_ent *desc)
  286. {
  287. struct ioat_dma_descriptor *hw = desc->hw;
  288. switch (hw->ctl_f.op) {
  289. case IOAT_OP_PQ_VAL:
  290. case IOAT_OP_PQ_VAL_16S:
  291. {
  292. struct ioat_pq_descriptor *pq = desc->pq;
  293. /* check if there's error written */
  294. if (!pq->dwbes_f.wbes)
  295. return;
  296. /* need to set a chanerr var for checking to clear later */
  297. if (pq->dwbes_f.p_val_err)
  298. *desc->result |= SUM_CHECK_P_RESULT;
  299. if (pq->dwbes_f.q_val_err)
  300. *desc->result |= SUM_CHECK_Q_RESULT;
  301. return;
  302. }
  303. default:
  304. return;
  305. }
  306. }
  307. /**
  308. * __cleanup - reclaim used descriptors
  309. * @ioat: channel (ring) to clean
  310. *
  311. * The difference from the dma_v2.c __cleanup() is that this routine
  312. * handles extended descriptors and dma-unmapping raid operations.
  313. */
  314. static void __cleanup(struct ioat2_dma_chan *ioat, dma_addr_t phys_complete)
  315. {
  316. struct ioat_chan_common *chan = &ioat->base;
  317. struct ioatdma_device *device = chan->device;
  318. struct ioat_ring_ent *desc;
  319. bool seen_current = false;
  320. int idx = ioat->tail, i;
  321. u16 active;
  322. dev_dbg(to_dev(chan), "%s: head: %#x tail: %#x issued: %#x\n",
  323. __func__, ioat->head, ioat->tail, ioat->issued);
  324. /*
  325. * At restart of the channel, the completion address and the
  326. * channel status will be 0 due to starting a new chain. Since
  327. * it's new chain and the first descriptor "fails", there is
  328. * nothing to clean up. We do not want to reap the entire submitted
  329. * chain due to this 0 address value and then BUG.
  330. */
  331. if (!phys_complete)
  332. return;
  333. active = ioat2_ring_active(ioat);
  334. for (i = 0; i < active && !seen_current; i++) {
  335. struct dma_async_tx_descriptor *tx;
  336. smp_read_barrier_depends();
  337. prefetch(ioat2_get_ring_ent(ioat, idx + i + 1));
  338. desc = ioat2_get_ring_ent(ioat, idx + i);
  339. dump_desc_dbg(ioat, desc);
  340. /* set err stat if we are using dwbes */
  341. if (device->cap & IOAT_CAP_DWBES)
  342. desc_get_errstat(ioat, desc);
  343. tx = &desc->txd;
  344. if (tx->cookie) {
  345. dma_cookie_complete(tx);
  346. dma_descriptor_unmap(tx);
  347. if (tx->callback) {
  348. tx->callback(tx->callback_param);
  349. tx->callback = NULL;
  350. }
  351. }
  352. if (tx->phys == phys_complete)
  353. seen_current = true;
  354. /* skip extended descriptors */
  355. if (desc_has_ext(desc)) {
  356. BUG_ON(i + 1 >= active);
  357. i++;
  358. }
  359. /* cleanup super extended descriptors */
  360. if (desc->sed) {
  361. ioat3_free_sed(device, desc->sed);
  362. desc->sed = NULL;
  363. }
  364. }
  365. smp_mb(); /* finish all descriptor reads before incrementing tail */
  366. ioat->tail = idx + i;
  367. BUG_ON(active && !seen_current); /* no active descs have written a completion? */
  368. chan->last_completion = phys_complete;
  369. if (active - i == 0) {
  370. dev_dbg(to_dev(chan), "%s: cancel completion timeout\n",
  371. __func__);
  372. clear_bit(IOAT_COMPLETION_PENDING, &chan->state);
  373. mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
  374. }
  375. /* 5 microsecond delay per pending descriptor */
  376. writew(min((5 * (active - i)), IOAT_INTRDELAY_MASK),
  377. chan->device->reg_base + IOAT_INTRDELAY_OFFSET);
  378. }
  379. static void ioat3_cleanup(struct ioat2_dma_chan *ioat)
  380. {
  381. struct ioat_chan_common *chan = &ioat->base;
  382. u64 phys_complete;
  383. spin_lock_bh(&chan->cleanup_lock);
  384. if (ioat3_cleanup_preamble(chan, &phys_complete))
  385. __cleanup(ioat, phys_complete);
  386. if (is_ioat_halted(*chan->completion)) {
  387. u32 chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  388. if (chanerr & IOAT_CHANERR_HANDLE_MASK) {
  389. mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
  390. ioat3_eh(ioat);
  391. }
  392. }
  393. spin_unlock_bh(&chan->cleanup_lock);
  394. }
  395. static void ioat3_cleanup_event(unsigned long data)
  396. {
  397. struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
  398. ioat3_cleanup(ioat);
  399. writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
  400. }
  401. static void ioat3_restart_channel(struct ioat2_dma_chan *ioat)
  402. {
  403. struct ioat_chan_common *chan = &ioat->base;
  404. u64 phys_complete;
  405. ioat2_quiesce(chan, 0);
  406. if (ioat3_cleanup_preamble(chan, &phys_complete))
  407. __cleanup(ioat, phys_complete);
  408. __ioat2_restart_chan(ioat);
  409. }
  410. static void ioat3_eh(struct ioat2_dma_chan *ioat)
  411. {
  412. struct ioat_chan_common *chan = &ioat->base;
  413. struct pci_dev *pdev = to_pdev(chan);
  414. struct ioat_dma_descriptor *hw;
  415. u64 phys_complete;
  416. struct ioat_ring_ent *desc;
  417. u32 err_handled = 0;
  418. u32 chanerr_int;
  419. u32 chanerr;
  420. /* cleanup so tail points to descriptor that caused the error */
  421. if (ioat3_cleanup_preamble(chan, &phys_complete))
  422. __cleanup(ioat, phys_complete);
  423. chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  424. pci_read_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, &chanerr_int);
  425. dev_dbg(to_dev(chan), "%s: error = %x:%x\n",
  426. __func__, chanerr, chanerr_int);
  427. desc = ioat2_get_ring_ent(ioat, ioat->tail);
  428. hw = desc->hw;
  429. dump_desc_dbg(ioat, desc);
  430. switch (hw->ctl_f.op) {
  431. case IOAT_OP_XOR_VAL:
  432. if (chanerr & IOAT_CHANERR_XOR_P_OR_CRC_ERR) {
  433. *desc->result |= SUM_CHECK_P_RESULT;
  434. err_handled |= IOAT_CHANERR_XOR_P_OR_CRC_ERR;
  435. }
  436. break;
  437. case IOAT_OP_PQ_VAL:
  438. case IOAT_OP_PQ_VAL_16S:
  439. if (chanerr & IOAT_CHANERR_XOR_P_OR_CRC_ERR) {
  440. *desc->result |= SUM_CHECK_P_RESULT;
  441. err_handled |= IOAT_CHANERR_XOR_P_OR_CRC_ERR;
  442. }
  443. if (chanerr & IOAT_CHANERR_XOR_Q_ERR) {
  444. *desc->result |= SUM_CHECK_Q_RESULT;
  445. err_handled |= IOAT_CHANERR_XOR_Q_ERR;
  446. }
  447. break;
  448. }
  449. /* fault on unhandled error or spurious halt */
  450. if (chanerr ^ err_handled || chanerr == 0) {
  451. dev_err(to_dev(chan), "%s: fatal error (%x:%x)\n",
  452. __func__, chanerr, err_handled);
  453. BUG();
  454. }
  455. writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
  456. pci_write_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, chanerr_int);
  457. /* mark faulting descriptor as complete */
  458. *chan->completion = desc->txd.phys;
  459. spin_lock_bh(&ioat->prep_lock);
  460. ioat3_restart_channel(ioat);
  461. spin_unlock_bh(&ioat->prep_lock);
  462. }
  463. static void check_active(struct ioat2_dma_chan *ioat)
  464. {
  465. struct ioat_chan_common *chan = &ioat->base;
  466. if (ioat2_ring_active(ioat)) {
  467. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  468. return;
  469. }
  470. if (test_and_clear_bit(IOAT_CHAN_ACTIVE, &chan->state))
  471. mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
  472. else if (ioat->alloc_order > ioat_get_alloc_order()) {
  473. /* if the ring is idle, empty, and oversized try to step
  474. * down the size
  475. */
  476. reshape_ring(ioat, ioat->alloc_order - 1);
  477. /* keep shrinking until we get back to our minimum
  478. * default size
  479. */
  480. if (ioat->alloc_order > ioat_get_alloc_order())
  481. mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
  482. }
  483. }
  484. static void ioat3_timer_event(unsigned long data)
  485. {
  486. struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
  487. struct ioat_chan_common *chan = &ioat->base;
  488. dma_addr_t phys_complete;
  489. u64 status;
  490. status = ioat_chansts(chan);
  491. /* when halted due to errors check for channel
  492. * programming errors before advancing the completion state
  493. */
  494. if (is_ioat_halted(status)) {
  495. u32 chanerr;
  496. chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  497. dev_err(to_dev(chan), "%s: Channel halted (%x)\n",
  498. __func__, chanerr);
  499. if (test_bit(IOAT_RUN, &chan->state))
  500. BUG_ON(is_ioat_bug(chanerr));
  501. else /* we never got off the ground */
  502. return;
  503. }
  504. /* if we haven't made progress and we have already
  505. * acknowledged a pending completion once, then be more
  506. * forceful with a restart
  507. */
  508. spin_lock_bh(&chan->cleanup_lock);
  509. if (ioat_cleanup_preamble(chan, &phys_complete))
  510. __cleanup(ioat, phys_complete);
  511. else if (test_bit(IOAT_COMPLETION_ACK, &chan->state)) {
  512. spin_lock_bh(&ioat->prep_lock);
  513. ioat3_restart_channel(ioat);
  514. spin_unlock_bh(&ioat->prep_lock);
  515. spin_unlock_bh(&chan->cleanup_lock);
  516. return;
  517. } else {
  518. set_bit(IOAT_COMPLETION_ACK, &chan->state);
  519. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  520. }
  521. if (ioat2_ring_active(ioat))
  522. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  523. else {
  524. spin_lock_bh(&ioat->prep_lock);
  525. check_active(ioat);
  526. spin_unlock_bh(&ioat->prep_lock);
  527. }
  528. spin_unlock_bh(&chan->cleanup_lock);
  529. }
  530. static enum dma_status
  531. ioat3_tx_status(struct dma_chan *c, dma_cookie_t cookie,
  532. struct dma_tx_state *txstate)
  533. {
  534. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  535. enum dma_status ret;
  536. ret = dma_cookie_status(c, cookie, txstate);
  537. if (ret == DMA_SUCCESS)
  538. return ret;
  539. ioat3_cleanup(ioat);
  540. return dma_cookie_status(c, cookie, txstate);
  541. }
  542. static struct dma_async_tx_descriptor *
  543. __ioat3_prep_xor_lock(struct dma_chan *c, enum sum_check_flags *result,
  544. dma_addr_t dest, dma_addr_t *src, unsigned int src_cnt,
  545. size_t len, unsigned long flags)
  546. {
  547. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  548. struct ioat_ring_ent *compl_desc;
  549. struct ioat_ring_ent *desc;
  550. struct ioat_ring_ent *ext;
  551. size_t total_len = len;
  552. struct ioat_xor_descriptor *xor;
  553. struct ioat_xor_ext_descriptor *xor_ex = NULL;
  554. struct ioat_dma_descriptor *hw;
  555. int num_descs, with_ext, idx, i;
  556. u32 offset = 0;
  557. u8 op = result ? IOAT_OP_XOR_VAL : IOAT_OP_XOR;
  558. BUG_ON(src_cnt < 2);
  559. num_descs = ioat2_xferlen_to_descs(ioat, len);
  560. /* we need 2x the number of descriptors to cover greater than 5
  561. * sources
  562. */
  563. if (src_cnt > 5) {
  564. with_ext = 1;
  565. num_descs *= 2;
  566. } else
  567. with_ext = 0;
  568. /* completion writes from the raid engine may pass completion
  569. * writes from the legacy engine, so we need one extra null
  570. * (legacy) descriptor to ensure all completion writes arrive in
  571. * order.
  572. */
  573. if (likely(num_descs) && ioat2_check_space_lock(ioat, num_descs+1) == 0)
  574. idx = ioat->head;
  575. else
  576. return NULL;
  577. i = 0;
  578. do {
  579. struct ioat_raw_descriptor *descs[2];
  580. size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
  581. int s;
  582. desc = ioat2_get_ring_ent(ioat, idx + i);
  583. xor = desc->xor;
  584. /* save a branch by unconditionally retrieving the
  585. * extended descriptor xor_set_src() knows to not write
  586. * to it in the single descriptor case
  587. */
  588. ext = ioat2_get_ring_ent(ioat, idx + i + 1);
  589. xor_ex = ext->xor_ex;
  590. descs[0] = (struct ioat_raw_descriptor *) xor;
  591. descs[1] = (struct ioat_raw_descriptor *) xor_ex;
  592. for (s = 0; s < src_cnt; s++)
  593. xor_set_src(descs, src[s], offset, s);
  594. xor->size = xfer_size;
  595. xor->dst_addr = dest + offset;
  596. xor->ctl = 0;
  597. xor->ctl_f.op = op;
  598. xor->ctl_f.src_cnt = src_cnt_to_hw(src_cnt);
  599. len -= xfer_size;
  600. offset += xfer_size;
  601. dump_desc_dbg(ioat, desc);
  602. } while ((i += 1 + with_ext) < num_descs);
  603. /* last xor descriptor carries the unmap parameters and fence bit */
  604. desc->txd.flags = flags;
  605. desc->len = total_len;
  606. if (result)
  607. desc->result = result;
  608. xor->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  609. /* completion descriptor carries interrupt bit */
  610. compl_desc = ioat2_get_ring_ent(ioat, idx + i);
  611. compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
  612. hw = compl_desc->hw;
  613. hw->ctl = 0;
  614. hw->ctl_f.null = 1;
  615. hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  616. hw->ctl_f.compl_write = 1;
  617. hw->size = NULL_DESC_BUFFER_SIZE;
  618. dump_desc_dbg(ioat, compl_desc);
  619. /* we leave the channel locked to ensure in order submission */
  620. return &compl_desc->txd;
  621. }
  622. static struct dma_async_tx_descriptor *
  623. ioat3_prep_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
  624. unsigned int src_cnt, size_t len, unsigned long flags)
  625. {
  626. return __ioat3_prep_xor_lock(chan, NULL, dest, src, src_cnt, len, flags);
  627. }
  628. struct dma_async_tx_descriptor *
  629. ioat3_prep_xor_val(struct dma_chan *chan, dma_addr_t *src,
  630. unsigned int src_cnt, size_t len,
  631. enum sum_check_flags *result, unsigned long flags)
  632. {
  633. /* the cleanup routine only sets bits on validate failure, it
  634. * does not clear bits on validate success... so clear it here
  635. */
  636. *result = 0;
  637. return __ioat3_prep_xor_lock(chan, result, src[0], &src[1],
  638. src_cnt - 1, len, flags);
  639. }
  640. static void
  641. dump_pq_desc_dbg(struct ioat2_dma_chan *ioat, struct ioat_ring_ent *desc, struct ioat_ring_ent *ext)
  642. {
  643. struct device *dev = to_dev(&ioat->base);
  644. struct ioat_pq_descriptor *pq = desc->pq;
  645. struct ioat_pq_ext_descriptor *pq_ex = ext ? ext->pq_ex : NULL;
  646. struct ioat_raw_descriptor *descs[] = { (void *) pq, (void *) pq_ex };
  647. int src_cnt = src_cnt_to_sw(pq->ctl_f.src_cnt);
  648. int i;
  649. dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x"
  650. " sz: %#10.8x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s'"
  651. " src_cnt: %d)\n",
  652. desc_id(desc), (unsigned long long) desc->txd.phys,
  653. (unsigned long long) (pq_ex ? pq_ex->next : pq->next),
  654. desc->txd.flags, pq->size, pq->ctl, pq->ctl_f.op, pq->ctl_f.int_en,
  655. pq->ctl_f.compl_write,
  656. pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q",
  657. pq->ctl_f.src_cnt);
  658. for (i = 0; i < src_cnt; i++)
  659. dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i,
  660. (unsigned long long) pq_get_src(descs, i), pq->coef[i]);
  661. dev_dbg(dev, "\tP: %#llx\n", pq->p_addr);
  662. dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr);
  663. dev_dbg(dev, "\tNEXT: %#llx\n", pq->next);
  664. }
  665. static void dump_pq16_desc_dbg(struct ioat2_dma_chan *ioat,
  666. struct ioat_ring_ent *desc)
  667. {
  668. struct device *dev = to_dev(&ioat->base);
  669. struct ioat_pq_descriptor *pq = desc->pq;
  670. struct ioat_raw_descriptor *descs[] = { (void *)pq,
  671. (void *)pq,
  672. (void *)pq };
  673. int src_cnt = src16_cnt_to_sw(pq->ctl_f.src_cnt);
  674. int i;
  675. if (desc->sed) {
  676. descs[1] = (void *)desc->sed->hw;
  677. descs[2] = (void *)desc->sed->hw + 64;
  678. }
  679. dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x"
  680. " sz: %#x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s'"
  681. " src_cnt: %d)\n",
  682. desc_id(desc), (unsigned long long) desc->txd.phys,
  683. (unsigned long long) pq->next,
  684. desc->txd.flags, pq->size, pq->ctl,
  685. pq->ctl_f.op, pq->ctl_f.int_en,
  686. pq->ctl_f.compl_write,
  687. pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q",
  688. pq->ctl_f.src_cnt);
  689. for (i = 0; i < src_cnt; i++) {
  690. dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i,
  691. (unsigned long long) pq16_get_src(descs, i),
  692. pq->coef[i]);
  693. }
  694. dev_dbg(dev, "\tP: %#llx\n", pq->p_addr);
  695. dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr);
  696. }
  697. static struct dma_async_tx_descriptor *
  698. __ioat3_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result,
  699. const dma_addr_t *dst, const dma_addr_t *src,
  700. unsigned int src_cnt, const unsigned char *scf,
  701. size_t len, unsigned long flags)
  702. {
  703. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  704. struct ioat_chan_common *chan = &ioat->base;
  705. struct ioatdma_device *device = chan->device;
  706. struct ioat_ring_ent *compl_desc;
  707. struct ioat_ring_ent *desc;
  708. struct ioat_ring_ent *ext;
  709. size_t total_len = len;
  710. struct ioat_pq_descriptor *pq;
  711. struct ioat_pq_ext_descriptor *pq_ex = NULL;
  712. struct ioat_dma_descriptor *hw;
  713. u32 offset = 0;
  714. u8 op = result ? IOAT_OP_PQ_VAL : IOAT_OP_PQ;
  715. int i, s, idx, with_ext, num_descs;
  716. int cb32 = (device->version < IOAT_VER_3_3) ? 1 : 0;
  717. dev_dbg(to_dev(chan), "%s\n", __func__);
  718. /* the engine requires at least two sources (we provide
  719. * at least 1 implied source in the DMA_PREP_CONTINUE case)
  720. */
  721. BUG_ON(src_cnt + dmaf_continue(flags) < 2);
  722. num_descs = ioat2_xferlen_to_descs(ioat, len);
  723. /* we need 2x the number of descriptors to cover greater than 3
  724. * sources (we need 1 extra source in the q-only continuation
  725. * case and 3 extra sources in the p+q continuation case.
  726. */
  727. if (src_cnt + dmaf_p_disabled_continue(flags) > 3 ||
  728. (dmaf_continue(flags) && !dmaf_p_disabled_continue(flags))) {
  729. with_ext = 1;
  730. num_descs *= 2;
  731. } else
  732. with_ext = 0;
  733. /* completion writes from the raid engine may pass completion
  734. * writes from the legacy engine, so we need one extra null
  735. * (legacy) descriptor to ensure all completion writes arrive in
  736. * order.
  737. */
  738. if (likely(num_descs) &&
  739. ioat2_check_space_lock(ioat, num_descs + cb32) == 0)
  740. idx = ioat->head;
  741. else
  742. return NULL;
  743. i = 0;
  744. do {
  745. struct ioat_raw_descriptor *descs[2];
  746. size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
  747. desc = ioat2_get_ring_ent(ioat, idx + i);
  748. pq = desc->pq;
  749. /* save a branch by unconditionally retrieving the
  750. * extended descriptor pq_set_src() knows to not write
  751. * to it in the single descriptor case
  752. */
  753. ext = ioat2_get_ring_ent(ioat, idx + i + with_ext);
  754. pq_ex = ext->pq_ex;
  755. descs[0] = (struct ioat_raw_descriptor *) pq;
  756. descs[1] = (struct ioat_raw_descriptor *) pq_ex;
  757. for (s = 0; s < src_cnt; s++)
  758. pq_set_src(descs, src[s], offset, scf[s], s);
  759. /* see the comment for dma_maxpq in include/linux/dmaengine.h */
  760. if (dmaf_p_disabled_continue(flags))
  761. pq_set_src(descs, dst[1], offset, 1, s++);
  762. else if (dmaf_continue(flags)) {
  763. pq_set_src(descs, dst[0], offset, 0, s++);
  764. pq_set_src(descs, dst[1], offset, 1, s++);
  765. pq_set_src(descs, dst[1], offset, 0, s++);
  766. }
  767. pq->size = xfer_size;
  768. pq->p_addr = dst[0] + offset;
  769. pq->q_addr = dst[1] + offset;
  770. pq->ctl = 0;
  771. pq->ctl_f.op = op;
  772. /* we turn on descriptor write back error status */
  773. if (device->cap & IOAT_CAP_DWBES)
  774. pq->ctl_f.wb_en = result ? 1 : 0;
  775. pq->ctl_f.src_cnt = src_cnt_to_hw(s);
  776. pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
  777. pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
  778. len -= xfer_size;
  779. offset += xfer_size;
  780. } while ((i += 1 + with_ext) < num_descs);
  781. /* last pq descriptor carries the unmap parameters and fence bit */
  782. desc->txd.flags = flags;
  783. desc->len = total_len;
  784. if (result)
  785. desc->result = result;
  786. pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  787. dump_pq_desc_dbg(ioat, desc, ext);
  788. if (!cb32) {
  789. pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  790. pq->ctl_f.compl_write = 1;
  791. compl_desc = desc;
  792. } else {
  793. /* completion descriptor carries interrupt bit */
  794. compl_desc = ioat2_get_ring_ent(ioat, idx + i);
  795. compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
  796. hw = compl_desc->hw;
  797. hw->ctl = 0;
  798. hw->ctl_f.null = 1;
  799. hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  800. hw->ctl_f.compl_write = 1;
  801. hw->size = NULL_DESC_BUFFER_SIZE;
  802. dump_desc_dbg(ioat, compl_desc);
  803. }
  804. /* we leave the channel locked to ensure in order submission */
  805. return &compl_desc->txd;
  806. }
  807. static struct dma_async_tx_descriptor *
  808. __ioat3_prep_pq16_lock(struct dma_chan *c, enum sum_check_flags *result,
  809. const dma_addr_t *dst, const dma_addr_t *src,
  810. unsigned int src_cnt, const unsigned char *scf,
  811. size_t len, unsigned long flags)
  812. {
  813. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  814. struct ioat_chan_common *chan = &ioat->base;
  815. struct ioatdma_device *device = chan->device;
  816. struct ioat_ring_ent *desc;
  817. size_t total_len = len;
  818. struct ioat_pq_descriptor *pq;
  819. u32 offset = 0;
  820. u8 op;
  821. int i, s, idx, num_descs;
  822. /* this function is only called with 9-16 sources */
  823. op = result ? IOAT_OP_PQ_VAL_16S : IOAT_OP_PQ_16S;
  824. dev_dbg(to_dev(chan), "%s\n", __func__);
  825. num_descs = ioat2_xferlen_to_descs(ioat, len);
  826. /*
  827. * 16 source pq is only available on cb3.3 and has no completion
  828. * write hw bug.
  829. */
  830. if (num_descs && ioat2_check_space_lock(ioat, num_descs) == 0)
  831. idx = ioat->head;
  832. else
  833. return NULL;
  834. i = 0;
  835. do {
  836. struct ioat_raw_descriptor *descs[4];
  837. size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
  838. desc = ioat2_get_ring_ent(ioat, idx + i);
  839. pq = desc->pq;
  840. descs[0] = (struct ioat_raw_descriptor *) pq;
  841. desc->sed = ioat3_alloc_sed(device, (src_cnt-2) >> 3);
  842. if (!desc->sed) {
  843. dev_err(to_dev(chan),
  844. "%s: no free sed entries\n", __func__);
  845. return NULL;
  846. }
  847. pq->sed_addr = desc->sed->dma;
  848. desc->sed->parent = desc;
  849. descs[1] = (struct ioat_raw_descriptor *)desc->sed->hw;
  850. descs[2] = (void *)descs[1] + 64;
  851. for (s = 0; s < src_cnt; s++)
  852. pq16_set_src(descs, src[s], offset, scf[s], s);
  853. /* see the comment for dma_maxpq in include/linux/dmaengine.h */
  854. if (dmaf_p_disabled_continue(flags))
  855. pq16_set_src(descs, dst[1], offset, 1, s++);
  856. else if (dmaf_continue(flags)) {
  857. pq16_set_src(descs, dst[0], offset, 0, s++);
  858. pq16_set_src(descs, dst[1], offset, 1, s++);
  859. pq16_set_src(descs, dst[1], offset, 0, s++);
  860. }
  861. pq->size = xfer_size;
  862. pq->p_addr = dst[0] + offset;
  863. pq->q_addr = dst[1] + offset;
  864. pq->ctl = 0;
  865. pq->ctl_f.op = op;
  866. pq->ctl_f.src_cnt = src16_cnt_to_hw(s);
  867. /* we turn on descriptor write back error status */
  868. if (device->cap & IOAT_CAP_DWBES)
  869. pq->ctl_f.wb_en = result ? 1 : 0;
  870. pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
  871. pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
  872. len -= xfer_size;
  873. offset += xfer_size;
  874. } while (++i < num_descs);
  875. /* last pq descriptor carries the unmap parameters and fence bit */
  876. desc->txd.flags = flags;
  877. desc->len = total_len;
  878. if (result)
  879. desc->result = result;
  880. pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  881. /* with cb3.3 we should be able to do completion w/o a null desc */
  882. pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  883. pq->ctl_f.compl_write = 1;
  884. dump_pq16_desc_dbg(ioat, desc);
  885. /* we leave the channel locked to ensure in order submission */
  886. return &desc->txd;
  887. }
  888. static int src_cnt_flags(unsigned int src_cnt, unsigned long flags)
  889. {
  890. if (dmaf_p_disabled_continue(flags))
  891. return src_cnt + 1;
  892. else if (dmaf_continue(flags))
  893. return src_cnt + 3;
  894. else
  895. return src_cnt;
  896. }
  897. static struct dma_async_tx_descriptor *
  898. ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
  899. unsigned int src_cnt, const unsigned char *scf, size_t len,
  900. unsigned long flags)
  901. {
  902. /* specify valid address for disabled result */
  903. if (flags & DMA_PREP_PQ_DISABLE_P)
  904. dst[0] = dst[1];
  905. if (flags & DMA_PREP_PQ_DISABLE_Q)
  906. dst[1] = dst[0];
  907. /* handle the single source multiply case from the raid6
  908. * recovery path
  909. */
  910. if ((flags & DMA_PREP_PQ_DISABLE_P) && src_cnt == 1) {
  911. dma_addr_t single_source[2];
  912. unsigned char single_source_coef[2];
  913. BUG_ON(flags & DMA_PREP_PQ_DISABLE_Q);
  914. single_source[0] = src[0];
  915. single_source[1] = src[0];
  916. single_source_coef[0] = scf[0];
  917. single_source_coef[1] = 0;
  918. return src_cnt_flags(src_cnt, flags) > 8 ?
  919. __ioat3_prep_pq16_lock(chan, NULL, dst, single_source,
  920. 2, single_source_coef, len,
  921. flags) :
  922. __ioat3_prep_pq_lock(chan, NULL, dst, single_source, 2,
  923. single_source_coef, len, flags);
  924. } else {
  925. return src_cnt_flags(src_cnt, flags) > 8 ?
  926. __ioat3_prep_pq16_lock(chan, NULL, dst, src, src_cnt,
  927. scf, len, flags) :
  928. __ioat3_prep_pq_lock(chan, NULL, dst, src, src_cnt,
  929. scf, len, flags);
  930. }
  931. }
  932. struct dma_async_tx_descriptor *
  933. ioat3_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
  934. unsigned int src_cnt, const unsigned char *scf, size_t len,
  935. enum sum_check_flags *pqres, unsigned long flags)
  936. {
  937. /* specify valid address for disabled result */
  938. if (flags & DMA_PREP_PQ_DISABLE_P)
  939. pq[0] = pq[1];
  940. if (flags & DMA_PREP_PQ_DISABLE_Q)
  941. pq[1] = pq[0];
  942. /* the cleanup routine only sets bits on validate failure, it
  943. * does not clear bits on validate success... so clear it here
  944. */
  945. *pqres = 0;
  946. return src_cnt_flags(src_cnt, flags) > 8 ?
  947. __ioat3_prep_pq16_lock(chan, pqres, pq, src, src_cnt, scf, len,
  948. flags) :
  949. __ioat3_prep_pq_lock(chan, pqres, pq, src, src_cnt, scf, len,
  950. flags);
  951. }
  952. static struct dma_async_tx_descriptor *
  953. ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
  954. unsigned int src_cnt, size_t len, unsigned long flags)
  955. {
  956. unsigned char scf[src_cnt];
  957. dma_addr_t pq[2];
  958. memset(scf, 0, src_cnt);
  959. pq[0] = dst;
  960. flags |= DMA_PREP_PQ_DISABLE_Q;
  961. pq[1] = dst; /* specify valid address for disabled result */
  962. return src_cnt_flags(src_cnt, flags) > 8 ?
  963. __ioat3_prep_pq16_lock(chan, NULL, pq, src, src_cnt, scf, len,
  964. flags) :
  965. __ioat3_prep_pq_lock(chan, NULL, pq, src, src_cnt, scf, len,
  966. flags);
  967. }
  968. struct dma_async_tx_descriptor *
  969. ioat3_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
  970. unsigned int src_cnt, size_t len,
  971. enum sum_check_flags *result, unsigned long flags)
  972. {
  973. unsigned char scf[src_cnt];
  974. dma_addr_t pq[2];
  975. /* the cleanup routine only sets bits on validate failure, it
  976. * does not clear bits on validate success... so clear it here
  977. */
  978. *result = 0;
  979. memset(scf, 0, src_cnt);
  980. pq[0] = src[0];
  981. flags |= DMA_PREP_PQ_DISABLE_Q;
  982. pq[1] = pq[0]; /* specify valid address for disabled result */
  983. return src_cnt_flags(src_cnt, flags) > 8 ?
  984. __ioat3_prep_pq16_lock(chan, result, pq, &src[1], src_cnt - 1,
  985. scf, len, flags) :
  986. __ioat3_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1,
  987. scf, len, flags);
  988. }
  989. static struct dma_async_tx_descriptor *
  990. ioat3_prep_interrupt_lock(struct dma_chan *c, unsigned long flags)
  991. {
  992. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  993. struct ioat_ring_ent *desc;
  994. struct ioat_dma_descriptor *hw;
  995. if (ioat2_check_space_lock(ioat, 1) == 0)
  996. desc = ioat2_get_ring_ent(ioat, ioat->head);
  997. else
  998. return NULL;
  999. hw = desc->hw;
  1000. hw->ctl = 0;
  1001. hw->ctl_f.null = 1;
  1002. hw->ctl_f.int_en = 1;
  1003. hw->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  1004. hw->ctl_f.compl_write = 1;
  1005. hw->size = NULL_DESC_BUFFER_SIZE;
  1006. hw->src_addr = 0;
  1007. hw->dst_addr = 0;
  1008. desc->txd.flags = flags;
  1009. desc->len = 1;
  1010. dump_desc_dbg(ioat, desc);
  1011. /* we leave the channel locked to ensure in order submission */
  1012. return &desc->txd;
  1013. }
  1014. static void ioat3_dma_test_callback(void *dma_async_param)
  1015. {
  1016. struct completion *cmp = dma_async_param;
  1017. complete(cmp);
  1018. }
  1019. #define IOAT_NUM_SRC_TEST 6 /* must be <= 8 */
  1020. static int ioat_xor_val_self_test(struct ioatdma_device *device)
  1021. {
  1022. int i, src_idx;
  1023. struct page *dest;
  1024. struct page *xor_srcs[IOAT_NUM_SRC_TEST];
  1025. struct page *xor_val_srcs[IOAT_NUM_SRC_TEST + 1];
  1026. dma_addr_t dma_srcs[IOAT_NUM_SRC_TEST + 1];
  1027. dma_addr_t dest_dma;
  1028. struct dma_async_tx_descriptor *tx;
  1029. struct dma_chan *dma_chan;
  1030. dma_cookie_t cookie;
  1031. u8 cmp_byte = 0;
  1032. u32 cmp_word;
  1033. u32 xor_val_result;
  1034. int err = 0;
  1035. struct completion cmp;
  1036. unsigned long tmo;
  1037. struct device *dev = &device->pdev->dev;
  1038. struct dma_device *dma = &device->common;
  1039. u8 op = 0;
  1040. dev_dbg(dev, "%s\n", __func__);
  1041. if (!dma_has_cap(DMA_XOR, dma->cap_mask))
  1042. return 0;
  1043. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) {
  1044. xor_srcs[src_idx] = alloc_page(GFP_KERNEL);
  1045. if (!xor_srcs[src_idx]) {
  1046. while (src_idx--)
  1047. __free_page(xor_srcs[src_idx]);
  1048. return -ENOMEM;
  1049. }
  1050. }
  1051. dest = alloc_page(GFP_KERNEL);
  1052. if (!dest) {
  1053. while (src_idx--)
  1054. __free_page(xor_srcs[src_idx]);
  1055. return -ENOMEM;
  1056. }
  1057. /* Fill in src buffers */
  1058. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) {
  1059. u8 *ptr = page_address(xor_srcs[src_idx]);
  1060. for (i = 0; i < PAGE_SIZE; i++)
  1061. ptr[i] = (1 << src_idx);
  1062. }
  1063. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++)
  1064. cmp_byte ^= (u8) (1 << src_idx);
  1065. cmp_word = (cmp_byte << 24) | (cmp_byte << 16) |
  1066. (cmp_byte << 8) | cmp_byte;
  1067. memset(page_address(dest), 0, PAGE_SIZE);
  1068. dma_chan = container_of(dma->channels.next, struct dma_chan,
  1069. device_node);
  1070. if (dma->device_alloc_chan_resources(dma_chan) < 1) {
  1071. err = -ENODEV;
  1072. goto out;
  1073. }
  1074. /* test xor */
  1075. op = IOAT_OP_XOR;
  1076. dest_dma = dma_map_page(dev, dest, 0, PAGE_SIZE, DMA_FROM_DEVICE);
  1077. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1078. dma_srcs[i] = dma_map_page(dev, xor_srcs[i], 0, PAGE_SIZE,
  1079. DMA_TO_DEVICE);
  1080. tx = dma->device_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
  1081. IOAT_NUM_SRC_TEST, PAGE_SIZE,
  1082. DMA_PREP_INTERRUPT);
  1083. if (!tx) {
  1084. dev_err(dev, "Self-test xor prep failed\n");
  1085. err = -ENODEV;
  1086. goto dma_unmap;
  1087. }
  1088. async_tx_ack(tx);
  1089. init_completion(&cmp);
  1090. tx->callback = ioat3_dma_test_callback;
  1091. tx->callback_param = &cmp;
  1092. cookie = tx->tx_submit(tx);
  1093. if (cookie < 0) {
  1094. dev_err(dev, "Self-test xor setup failed\n");
  1095. err = -ENODEV;
  1096. goto dma_unmap;
  1097. }
  1098. dma->device_issue_pending(dma_chan);
  1099. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1100. if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  1101. dev_err(dev, "Self-test xor timed out\n");
  1102. err = -ENODEV;
  1103. goto dma_unmap;
  1104. }
  1105. dma_unmap_page(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1106. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1107. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
  1108. dma_sync_single_for_cpu(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1109. for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) {
  1110. u32 *ptr = page_address(dest);
  1111. if (ptr[i] != cmp_word) {
  1112. dev_err(dev, "Self-test xor failed compare\n");
  1113. err = -ENODEV;
  1114. goto free_resources;
  1115. }
  1116. }
  1117. dma_sync_single_for_device(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1118. /* skip validate if the capability is not present */
  1119. if (!dma_has_cap(DMA_XOR_VAL, dma_chan->device->cap_mask))
  1120. goto free_resources;
  1121. op = IOAT_OP_XOR_VAL;
  1122. /* validate the sources with the destintation page */
  1123. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1124. xor_val_srcs[i] = xor_srcs[i];
  1125. xor_val_srcs[i] = dest;
  1126. xor_val_result = 1;
  1127. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1128. dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE,
  1129. DMA_TO_DEVICE);
  1130. tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
  1131. IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
  1132. &xor_val_result, DMA_PREP_INTERRUPT);
  1133. if (!tx) {
  1134. dev_err(dev, "Self-test zero prep failed\n");
  1135. err = -ENODEV;
  1136. goto dma_unmap;
  1137. }
  1138. async_tx_ack(tx);
  1139. init_completion(&cmp);
  1140. tx->callback = ioat3_dma_test_callback;
  1141. tx->callback_param = &cmp;
  1142. cookie = tx->tx_submit(tx);
  1143. if (cookie < 0) {
  1144. dev_err(dev, "Self-test zero setup failed\n");
  1145. err = -ENODEV;
  1146. goto dma_unmap;
  1147. }
  1148. dma->device_issue_pending(dma_chan);
  1149. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1150. if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  1151. dev_err(dev, "Self-test validate timed out\n");
  1152. err = -ENODEV;
  1153. goto dma_unmap;
  1154. }
  1155. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1156. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
  1157. if (xor_val_result != 0) {
  1158. dev_err(dev, "Self-test validate failed compare\n");
  1159. err = -ENODEV;
  1160. goto free_resources;
  1161. }
  1162. memset(page_address(dest), 0, PAGE_SIZE);
  1163. /* test for non-zero parity sum */
  1164. op = IOAT_OP_XOR_VAL;
  1165. xor_val_result = 0;
  1166. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1167. dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE,
  1168. DMA_TO_DEVICE);
  1169. tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
  1170. IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
  1171. &xor_val_result, DMA_PREP_INTERRUPT);
  1172. if (!tx) {
  1173. dev_err(dev, "Self-test 2nd zero prep failed\n");
  1174. err = -ENODEV;
  1175. goto dma_unmap;
  1176. }
  1177. async_tx_ack(tx);
  1178. init_completion(&cmp);
  1179. tx->callback = ioat3_dma_test_callback;
  1180. tx->callback_param = &cmp;
  1181. cookie = tx->tx_submit(tx);
  1182. if (cookie < 0) {
  1183. dev_err(dev, "Self-test 2nd zero setup failed\n");
  1184. err = -ENODEV;
  1185. goto dma_unmap;
  1186. }
  1187. dma->device_issue_pending(dma_chan);
  1188. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1189. if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  1190. dev_err(dev, "Self-test 2nd validate timed out\n");
  1191. err = -ENODEV;
  1192. goto dma_unmap;
  1193. }
  1194. if (xor_val_result != SUM_CHECK_P_RESULT) {
  1195. dev_err(dev, "Self-test validate failed compare\n");
  1196. err = -ENODEV;
  1197. goto dma_unmap;
  1198. }
  1199. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1200. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
  1201. goto free_resources;
  1202. dma_unmap:
  1203. if (op == IOAT_OP_XOR) {
  1204. dma_unmap_page(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1205. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1206. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE,
  1207. DMA_TO_DEVICE);
  1208. } else if (op == IOAT_OP_XOR_VAL) {
  1209. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1210. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE,
  1211. DMA_TO_DEVICE);
  1212. }
  1213. free_resources:
  1214. dma->device_free_chan_resources(dma_chan);
  1215. out:
  1216. src_idx = IOAT_NUM_SRC_TEST;
  1217. while (src_idx--)
  1218. __free_page(xor_srcs[src_idx]);
  1219. __free_page(dest);
  1220. return err;
  1221. }
  1222. static int ioat3_dma_self_test(struct ioatdma_device *device)
  1223. {
  1224. int rc = ioat_dma_self_test(device);
  1225. if (rc)
  1226. return rc;
  1227. rc = ioat_xor_val_self_test(device);
  1228. if (rc)
  1229. return rc;
  1230. return 0;
  1231. }
  1232. static int ioat3_irq_reinit(struct ioatdma_device *device)
  1233. {
  1234. int msixcnt = device->common.chancnt;
  1235. struct pci_dev *pdev = device->pdev;
  1236. int i;
  1237. struct msix_entry *msix;
  1238. struct ioat_chan_common *chan;
  1239. int err = 0;
  1240. switch (device->irq_mode) {
  1241. case IOAT_MSIX:
  1242. for (i = 0; i < msixcnt; i++) {
  1243. msix = &device->msix_entries[i];
  1244. chan = ioat_chan_by_index(device, i);
  1245. devm_free_irq(&pdev->dev, msix->vector, chan);
  1246. }
  1247. pci_disable_msix(pdev);
  1248. break;
  1249. case IOAT_MSIX_SINGLE:
  1250. msix = &device->msix_entries[0];
  1251. chan = ioat_chan_by_index(device, 0);
  1252. devm_free_irq(&pdev->dev, msix->vector, chan);
  1253. pci_disable_msix(pdev);
  1254. break;
  1255. case IOAT_MSI:
  1256. chan = ioat_chan_by_index(device, 0);
  1257. devm_free_irq(&pdev->dev, pdev->irq, chan);
  1258. pci_disable_msi(pdev);
  1259. break;
  1260. case IOAT_INTX:
  1261. chan = ioat_chan_by_index(device, 0);
  1262. devm_free_irq(&pdev->dev, pdev->irq, chan);
  1263. break;
  1264. default:
  1265. return 0;
  1266. }
  1267. device->irq_mode = IOAT_NOIRQ;
  1268. err = ioat_dma_setup_interrupts(device);
  1269. return err;
  1270. }
  1271. static int ioat3_reset_hw(struct ioat_chan_common *chan)
  1272. {
  1273. /* throw away whatever the channel was doing and get it
  1274. * initialized, with ioat3 specific workarounds
  1275. */
  1276. struct ioatdma_device *device = chan->device;
  1277. struct pci_dev *pdev = device->pdev;
  1278. u32 chanerr;
  1279. u16 dev_id;
  1280. int err;
  1281. ioat2_quiesce(chan, msecs_to_jiffies(100));
  1282. chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  1283. writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
  1284. if (device->version < IOAT_VER_3_3) {
  1285. /* clear any pending errors */
  1286. err = pci_read_config_dword(pdev,
  1287. IOAT_PCI_CHANERR_INT_OFFSET, &chanerr);
  1288. if (err) {
  1289. dev_err(&pdev->dev,
  1290. "channel error register unreachable\n");
  1291. return err;
  1292. }
  1293. pci_write_config_dword(pdev,
  1294. IOAT_PCI_CHANERR_INT_OFFSET, chanerr);
  1295. /* Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit
  1296. * (workaround for spurious config parity error after restart)
  1297. */
  1298. pci_read_config_word(pdev, IOAT_PCI_DEVICE_ID_OFFSET, &dev_id);
  1299. if (dev_id == PCI_DEVICE_ID_INTEL_IOAT_TBG0) {
  1300. pci_write_config_dword(pdev,
  1301. IOAT_PCI_DMAUNCERRSTS_OFFSET,
  1302. 0x10);
  1303. }
  1304. }
  1305. err = ioat2_reset_sync(chan, msecs_to_jiffies(200));
  1306. if (err) {
  1307. dev_err(&pdev->dev, "Failed to reset!\n");
  1308. return err;
  1309. }
  1310. if (device->irq_mode != IOAT_NOIRQ && is_bwd_ioat(pdev))
  1311. err = ioat3_irq_reinit(device);
  1312. return err;
  1313. }
  1314. static void ioat3_intr_quirk(struct ioatdma_device *device)
  1315. {
  1316. struct dma_device *dma;
  1317. struct dma_chan *c;
  1318. struct ioat_chan_common *chan;
  1319. u32 errmask;
  1320. dma = &device->common;
  1321. /*
  1322. * if we have descriptor write back error status, we mask the
  1323. * error interrupts
  1324. */
  1325. if (device->cap & IOAT_CAP_DWBES) {
  1326. list_for_each_entry(c, &dma->channels, device_node) {
  1327. chan = to_chan_common(c);
  1328. errmask = readl(chan->reg_base +
  1329. IOAT_CHANERR_MASK_OFFSET);
  1330. errmask |= IOAT_CHANERR_XOR_P_OR_CRC_ERR |
  1331. IOAT_CHANERR_XOR_Q_ERR;
  1332. writel(errmask, chan->reg_base +
  1333. IOAT_CHANERR_MASK_OFFSET);
  1334. }
  1335. }
  1336. }
  1337. int ioat3_dma_probe(struct ioatdma_device *device, int dca)
  1338. {
  1339. struct pci_dev *pdev = device->pdev;
  1340. int dca_en = system_has_dca_enabled(pdev);
  1341. struct dma_device *dma;
  1342. struct dma_chan *c;
  1343. struct ioat_chan_common *chan;
  1344. bool is_raid_device = false;
  1345. int err;
  1346. device->enumerate_channels = ioat2_enumerate_channels;
  1347. device->reset_hw = ioat3_reset_hw;
  1348. device->self_test = ioat3_dma_self_test;
  1349. device->intr_quirk = ioat3_intr_quirk;
  1350. dma = &device->common;
  1351. dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock;
  1352. dma->device_issue_pending = ioat2_issue_pending;
  1353. dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
  1354. dma->device_free_chan_resources = ioat2_free_chan_resources;
  1355. dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
  1356. dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;
  1357. device->cap = readl(device->reg_base + IOAT_DMA_CAP_OFFSET);
  1358. if (is_xeon_cb32(pdev) || is_bwd_noraid(pdev))
  1359. device->cap &= ~(IOAT_CAP_XOR | IOAT_CAP_PQ | IOAT_CAP_RAID16SS);
  1360. /* dca is incompatible with raid operations */
  1361. if (dca_en && (device->cap & (IOAT_CAP_XOR|IOAT_CAP_PQ)))
  1362. device->cap &= ~(IOAT_CAP_XOR|IOAT_CAP_PQ);
  1363. if (device->cap & IOAT_CAP_XOR) {
  1364. is_raid_device = true;
  1365. dma->max_xor = 8;
  1366. dma_cap_set(DMA_XOR, dma->cap_mask);
  1367. dma->device_prep_dma_xor = ioat3_prep_xor;
  1368. dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
  1369. dma->device_prep_dma_xor_val = ioat3_prep_xor_val;
  1370. }
  1371. if (device->cap & IOAT_CAP_PQ) {
  1372. is_raid_device = true;
  1373. dma->device_prep_dma_pq = ioat3_prep_pq;
  1374. dma->device_prep_dma_pq_val = ioat3_prep_pq_val;
  1375. dma_cap_set(DMA_PQ, dma->cap_mask);
  1376. dma_cap_set(DMA_PQ_VAL, dma->cap_mask);
  1377. if (device->cap & IOAT_CAP_RAID16SS) {
  1378. dma_set_maxpq(dma, 16, 0);
  1379. } else {
  1380. dma_set_maxpq(dma, 8, 0);
  1381. }
  1382. if (!(device->cap & IOAT_CAP_XOR)) {
  1383. dma->device_prep_dma_xor = ioat3_prep_pqxor;
  1384. dma->device_prep_dma_xor_val = ioat3_prep_pqxor_val;
  1385. dma_cap_set(DMA_XOR, dma->cap_mask);
  1386. dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
  1387. if (device->cap & IOAT_CAP_RAID16SS) {
  1388. dma->max_xor = 16;
  1389. } else {
  1390. dma->max_xor = 8;
  1391. }
  1392. }
  1393. }
  1394. dma->device_tx_status = ioat3_tx_status;
  1395. device->cleanup_fn = ioat3_cleanup_event;
  1396. device->timer_fn = ioat3_timer_event;
  1397. /* starting with CB3.3 super extended descriptors are supported */
  1398. if (device->cap & IOAT_CAP_RAID16SS) {
  1399. char pool_name[14];
  1400. int i;
  1401. for (i = 0; i < MAX_SED_POOLS; i++) {
  1402. snprintf(pool_name, 14, "ioat_hw%d_sed", i);
  1403. /* allocate SED DMA pool */
  1404. device->sed_hw_pool[i] = dmam_pool_create(pool_name,
  1405. &pdev->dev,
  1406. SED_SIZE * (i + 1), 64, 0);
  1407. if (!device->sed_hw_pool[i])
  1408. return -ENOMEM;
  1409. }
  1410. }
  1411. err = ioat_probe(device);
  1412. if (err)
  1413. return err;
  1414. ioat_set_tcp_copy_break(262144);
  1415. list_for_each_entry(c, &dma->channels, device_node) {
  1416. chan = to_chan_common(c);
  1417. writel(IOAT_DMA_DCA_ANY_CPU,
  1418. chan->reg_base + IOAT_DCACTRL_OFFSET);
  1419. }
  1420. err = ioat_register(device);
  1421. if (err)
  1422. return err;
  1423. ioat_kobject_add(device, &ioat2_ktype);
  1424. if (dca)
  1425. device->dca = ioat3_dca_init(pdev, device->reg_base);
  1426. return 0;
  1427. }