dma_v3.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  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. struct ioat_chan_common *chan = &ioat->base;
  399. ioat3_cleanup(ioat);
  400. if (!test_bit(IOAT_RUN, &chan->state))
  401. return;
  402. writew(IOAT_CHANCTRL_RUN, ioat->base.reg_base + IOAT_CHANCTRL_OFFSET);
  403. }
  404. static void ioat3_restart_channel(struct ioat2_dma_chan *ioat)
  405. {
  406. struct ioat_chan_common *chan = &ioat->base;
  407. u64 phys_complete;
  408. ioat2_quiesce(chan, 0);
  409. if (ioat3_cleanup_preamble(chan, &phys_complete))
  410. __cleanup(ioat, phys_complete);
  411. __ioat2_restart_chan(ioat);
  412. }
  413. static void ioat3_eh(struct ioat2_dma_chan *ioat)
  414. {
  415. struct ioat_chan_common *chan = &ioat->base;
  416. struct pci_dev *pdev = to_pdev(chan);
  417. struct ioat_dma_descriptor *hw;
  418. u64 phys_complete;
  419. struct ioat_ring_ent *desc;
  420. u32 err_handled = 0;
  421. u32 chanerr_int;
  422. u32 chanerr;
  423. /* cleanup so tail points to descriptor that caused the error */
  424. if (ioat3_cleanup_preamble(chan, &phys_complete))
  425. __cleanup(ioat, phys_complete);
  426. chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  427. pci_read_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, &chanerr_int);
  428. dev_dbg(to_dev(chan), "%s: error = %x:%x\n",
  429. __func__, chanerr, chanerr_int);
  430. desc = ioat2_get_ring_ent(ioat, ioat->tail);
  431. hw = desc->hw;
  432. dump_desc_dbg(ioat, desc);
  433. switch (hw->ctl_f.op) {
  434. case IOAT_OP_XOR_VAL:
  435. if (chanerr & IOAT_CHANERR_XOR_P_OR_CRC_ERR) {
  436. *desc->result |= SUM_CHECK_P_RESULT;
  437. err_handled |= IOAT_CHANERR_XOR_P_OR_CRC_ERR;
  438. }
  439. break;
  440. case IOAT_OP_PQ_VAL:
  441. case IOAT_OP_PQ_VAL_16S:
  442. if (chanerr & IOAT_CHANERR_XOR_P_OR_CRC_ERR) {
  443. *desc->result |= SUM_CHECK_P_RESULT;
  444. err_handled |= IOAT_CHANERR_XOR_P_OR_CRC_ERR;
  445. }
  446. if (chanerr & IOAT_CHANERR_XOR_Q_ERR) {
  447. *desc->result |= SUM_CHECK_Q_RESULT;
  448. err_handled |= IOAT_CHANERR_XOR_Q_ERR;
  449. }
  450. break;
  451. }
  452. /* fault on unhandled error or spurious halt */
  453. if (chanerr ^ err_handled || chanerr == 0) {
  454. dev_err(to_dev(chan), "%s: fatal error (%x:%x)\n",
  455. __func__, chanerr, err_handled);
  456. BUG();
  457. }
  458. writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
  459. pci_write_config_dword(pdev, IOAT_PCI_CHANERR_INT_OFFSET, chanerr_int);
  460. /* mark faulting descriptor as complete */
  461. *chan->completion = desc->txd.phys;
  462. spin_lock_bh(&ioat->prep_lock);
  463. ioat3_restart_channel(ioat);
  464. spin_unlock_bh(&ioat->prep_lock);
  465. }
  466. static void check_active(struct ioat2_dma_chan *ioat)
  467. {
  468. struct ioat_chan_common *chan = &ioat->base;
  469. if (ioat2_ring_active(ioat)) {
  470. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  471. return;
  472. }
  473. if (test_and_clear_bit(IOAT_CHAN_ACTIVE, &chan->state))
  474. mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
  475. else if (ioat->alloc_order > ioat_get_alloc_order()) {
  476. /* if the ring is idle, empty, and oversized try to step
  477. * down the size
  478. */
  479. reshape_ring(ioat, ioat->alloc_order - 1);
  480. /* keep shrinking until we get back to our minimum
  481. * default size
  482. */
  483. if (ioat->alloc_order > ioat_get_alloc_order())
  484. mod_timer(&chan->timer, jiffies + IDLE_TIMEOUT);
  485. }
  486. }
  487. static void ioat3_timer_event(unsigned long data)
  488. {
  489. struct ioat2_dma_chan *ioat = to_ioat2_chan((void *) data);
  490. struct ioat_chan_common *chan = &ioat->base;
  491. dma_addr_t phys_complete;
  492. u64 status;
  493. status = ioat_chansts(chan);
  494. /* when halted due to errors check for channel
  495. * programming errors before advancing the completion state
  496. */
  497. if (is_ioat_halted(status)) {
  498. u32 chanerr;
  499. chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  500. dev_err(to_dev(chan), "%s: Channel halted (%x)\n",
  501. __func__, chanerr);
  502. if (test_bit(IOAT_RUN, &chan->state))
  503. BUG_ON(is_ioat_bug(chanerr));
  504. else /* we never got off the ground */
  505. return;
  506. }
  507. /* if we haven't made progress and we have already
  508. * acknowledged a pending completion once, then be more
  509. * forceful with a restart
  510. */
  511. spin_lock_bh(&chan->cleanup_lock);
  512. if (ioat_cleanup_preamble(chan, &phys_complete))
  513. __cleanup(ioat, phys_complete);
  514. else if (test_bit(IOAT_COMPLETION_ACK, &chan->state)) {
  515. spin_lock_bh(&ioat->prep_lock);
  516. ioat3_restart_channel(ioat);
  517. spin_unlock_bh(&ioat->prep_lock);
  518. spin_unlock_bh(&chan->cleanup_lock);
  519. return;
  520. } else {
  521. set_bit(IOAT_COMPLETION_ACK, &chan->state);
  522. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  523. }
  524. if (ioat2_ring_active(ioat))
  525. mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
  526. else {
  527. spin_lock_bh(&ioat->prep_lock);
  528. check_active(ioat);
  529. spin_unlock_bh(&ioat->prep_lock);
  530. }
  531. spin_unlock_bh(&chan->cleanup_lock);
  532. }
  533. static enum dma_status
  534. ioat3_tx_status(struct dma_chan *c, dma_cookie_t cookie,
  535. struct dma_tx_state *txstate)
  536. {
  537. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  538. enum dma_status ret;
  539. ret = dma_cookie_status(c, cookie, txstate);
  540. if (ret == DMA_COMPLETE)
  541. return ret;
  542. ioat3_cleanup(ioat);
  543. return dma_cookie_status(c, cookie, txstate);
  544. }
  545. static struct dma_async_tx_descriptor *
  546. __ioat3_prep_xor_lock(struct dma_chan *c, enum sum_check_flags *result,
  547. dma_addr_t dest, dma_addr_t *src, unsigned int src_cnt,
  548. size_t len, unsigned long flags)
  549. {
  550. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  551. struct ioat_ring_ent *compl_desc;
  552. struct ioat_ring_ent *desc;
  553. struct ioat_ring_ent *ext;
  554. size_t total_len = len;
  555. struct ioat_xor_descriptor *xor;
  556. struct ioat_xor_ext_descriptor *xor_ex = NULL;
  557. struct ioat_dma_descriptor *hw;
  558. int num_descs, with_ext, idx, i;
  559. u32 offset = 0;
  560. u8 op = result ? IOAT_OP_XOR_VAL : IOAT_OP_XOR;
  561. BUG_ON(src_cnt < 2);
  562. num_descs = ioat2_xferlen_to_descs(ioat, len);
  563. /* we need 2x the number of descriptors to cover greater than 5
  564. * sources
  565. */
  566. if (src_cnt > 5) {
  567. with_ext = 1;
  568. num_descs *= 2;
  569. } else
  570. with_ext = 0;
  571. /* completion writes from the raid engine may pass completion
  572. * writes from the legacy engine, so we need one extra null
  573. * (legacy) descriptor to ensure all completion writes arrive in
  574. * order.
  575. */
  576. if (likely(num_descs) && ioat2_check_space_lock(ioat, num_descs+1) == 0)
  577. idx = ioat->head;
  578. else
  579. return NULL;
  580. i = 0;
  581. do {
  582. struct ioat_raw_descriptor *descs[2];
  583. size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
  584. int s;
  585. desc = ioat2_get_ring_ent(ioat, idx + i);
  586. xor = desc->xor;
  587. /* save a branch by unconditionally retrieving the
  588. * extended descriptor xor_set_src() knows to not write
  589. * to it in the single descriptor case
  590. */
  591. ext = ioat2_get_ring_ent(ioat, idx + i + 1);
  592. xor_ex = ext->xor_ex;
  593. descs[0] = (struct ioat_raw_descriptor *) xor;
  594. descs[1] = (struct ioat_raw_descriptor *) xor_ex;
  595. for (s = 0; s < src_cnt; s++)
  596. xor_set_src(descs, src[s], offset, s);
  597. xor->size = xfer_size;
  598. xor->dst_addr = dest + offset;
  599. xor->ctl = 0;
  600. xor->ctl_f.op = op;
  601. xor->ctl_f.src_cnt = src_cnt_to_hw(src_cnt);
  602. len -= xfer_size;
  603. offset += xfer_size;
  604. dump_desc_dbg(ioat, desc);
  605. } while ((i += 1 + with_ext) < num_descs);
  606. /* last xor descriptor carries the unmap parameters and fence bit */
  607. desc->txd.flags = flags;
  608. desc->len = total_len;
  609. if (result)
  610. desc->result = result;
  611. xor->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  612. /* completion descriptor carries interrupt bit */
  613. compl_desc = ioat2_get_ring_ent(ioat, idx + i);
  614. compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
  615. hw = compl_desc->hw;
  616. hw->ctl = 0;
  617. hw->ctl_f.null = 1;
  618. hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  619. hw->ctl_f.compl_write = 1;
  620. hw->size = NULL_DESC_BUFFER_SIZE;
  621. dump_desc_dbg(ioat, compl_desc);
  622. /* we leave the channel locked to ensure in order submission */
  623. return &compl_desc->txd;
  624. }
  625. static struct dma_async_tx_descriptor *
  626. ioat3_prep_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
  627. unsigned int src_cnt, size_t len, unsigned long flags)
  628. {
  629. return __ioat3_prep_xor_lock(chan, NULL, dest, src, src_cnt, len, flags);
  630. }
  631. struct dma_async_tx_descriptor *
  632. ioat3_prep_xor_val(struct dma_chan *chan, dma_addr_t *src,
  633. unsigned int src_cnt, size_t len,
  634. enum sum_check_flags *result, unsigned long flags)
  635. {
  636. /* the cleanup routine only sets bits on validate failure, it
  637. * does not clear bits on validate success... so clear it here
  638. */
  639. *result = 0;
  640. return __ioat3_prep_xor_lock(chan, result, src[0], &src[1],
  641. src_cnt - 1, len, flags);
  642. }
  643. static void
  644. dump_pq_desc_dbg(struct ioat2_dma_chan *ioat, struct ioat_ring_ent *desc, struct ioat_ring_ent *ext)
  645. {
  646. struct device *dev = to_dev(&ioat->base);
  647. struct ioat_pq_descriptor *pq = desc->pq;
  648. struct ioat_pq_ext_descriptor *pq_ex = ext ? ext->pq_ex : NULL;
  649. struct ioat_raw_descriptor *descs[] = { (void *) pq, (void *) pq_ex };
  650. int src_cnt = src_cnt_to_sw(pq->ctl_f.src_cnt);
  651. int i;
  652. dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x"
  653. " sz: %#10.8x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s'"
  654. " src_cnt: %d)\n",
  655. desc_id(desc), (unsigned long long) desc->txd.phys,
  656. (unsigned long long) (pq_ex ? pq_ex->next : pq->next),
  657. desc->txd.flags, pq->size, pq->ctl, pq->ctl_f.op, pq->ctl_f.int_en,
  658. pq->ctl_f.compl_write,
  659. pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q",
  660. pq->ctl_f.src_cnt);
  661. for (i = 0; i < src_cnt; i++)
  662. dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i,
  663. (unsigned long long) pq_get_src(descs, i), pq->coef[i]);
  664. dev_dbg(dev, "\tP: %#llx\n", pq->p_addr);
  665. dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr);
  666. dev_dbg(dev, "\tNEXT: %#llx\n", pq->next);
  667. }
  668. static void dump_pq16_desc_dbg(struct ioat2_dma_chan *ioat,
  669. struct ioat_ring_ent *desc)
  670. {
  671. struct device *dev = to_dev(&ioat->base);
  672. struct ioat_pq_descriptor *pq = desc->pq;
  673. struct ioat_raw_descriptor *descs[] = { (void *)pq,
  674. (void *)pq,
  675. (void *)pq };
  676. int src_cnt = src16_cnt_to_sw(pq->ctl_f.src_cnt);
  677. int i;
  678. if (desc->sed) {
  679. descs[1] = (void *)desc->sed->hw;
  680. descs[2] = (void *)desc->sed->hw + 64;
  681. }
  682. dev_dbg(dev, "desc[%d]: (%#llx->%#llx) flags: %#x"
  683. " sz: %#x ctl: %#x (op: %#x int: %d compl: %d pq: '%s%s'"
  684. " src_cnt: %d)\n",
  685. desc_id(desc), (unsigned long long) desc->txd.phys,
  686. (unsigned long long) pq->next,
  687. desc->txd.flags, pq->size, pq->ctl,
  688. pq->ctl_f.op, pq->ctl_f.int_en,
  689. pq->ctl_f.compl_write,
  690. pq->ctl_f.p_disable ? "" : "p", pq->ctl_f.q_disable ? "" : "q",
  691. pq->ctl_f.src_cnt);
  692. for (i = 0; i < src_cnt; i++) {
  693. dev_dbg(dev, "\tsrc[%d]: %#llx coef: %#x\n", i,
  694. (unsigned long long) pq16_get_src(descs, i),
  695. pq->coef[i]);
  696. }
  697. dev_dbg(dev, "\tP: %#llx\n", pq->p_addr);
  698. dev_dbg(dev, "\tQ: %#llx\n", pq->q_addr);
  699. }
  700. static struct dma_async_tx_descriptor *
  701. __ioat3_prep_pq_lock(struct dma_chan *c, enum sum_check_flags *result,
  702. const dma_addr_t *dst, const dma_addr_t *src,
  703. unsigned int src_cnt, const unsigned char *scf,
  704. size_t len, unsigned long flags)
  705. {
  706. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  707. struct ioat_chan_common *chan = &ioat->base;
  708. struct ioatdma_device *device = chan->device;
  709. struct ioat_ring_ent *compl_desc;
  710. struct ioat_ring_ent *desc;
  711. struct ioat_ring_ent *ext;
  712. size_t total_len = len;
  713. struct ioat_pq_descriptor *pq;
  714. struct ioat_pq_ext_descriptor *pq_ex = NULL;
  715. struct ioat_dma_descriptor *hw;
  716. u32 offset = 0;
  717. u8 op = result ? IOAT_OP_PQ_VAL : IOAT_OP_PQ;
  718. int i, s, idx, with_ext, num_descs;
  719. int cb32 = (device->version < IOAT_VER_3_3) ? 1 : 0;
  720. dev_dbg(to_dev(chan), "%s\n", __func__);
  721. /* the engine requires at least two sources (we provide
  722. * at least 1 implied source in the DMA_PREP_CONTINUE case)
  723. */
  724. BUG_ON(src_cnt + dmaf_continue(flags) < 2);
  725. num_descs = ioat2_xferlen_to_descs(ioat, len);
  726. /* we need 2x the number of descriptors to cover greater than 3
  727. * sources (we need 1 extra source in the q-only continuation
  728. * case and 3 extra sources in the p+q continuation case.
  729. */
  730. if (src_cnt + dmaf_p_disabled_continue(flags) > 3 ||
  731. (dmaf_continue(flags) && !dmaf_p_disabled_continue(flags))) {
  732. with_ext = 1;
  733. num_descs *= 2;
  734. } else
  735. with_ext = 0;
  736. /* completion writes from the raid engine may pass completion
  737. * writes from the legacy engine, so we need one extra null
  738. * (legacy) descriptor to ensure all completion writes arrive in
  739. * order.
  740. */
  741. if (likely(num_descs) &&
  742. ioat2_check_space_lock(ioat, num_descs + cb32) == 0)
  743. idx = ioat->head;
  744. else
  745. return NULL;
  746. i = 0;
  747. do {
  748. struct ioat_raw_descriptor *descs[2];
  749. size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
  750. desc = ioat2_get_ring_ent(ioat, idx + i);
  751. pq = desc->pq;
  752. /* save a branch by unconditionally retrieving the
  753. * extended descriptor pq_set_src() knows to not write
  754. * to it in the single descriptor case
  755. */
  756. ext = ioat2_get_ring_ent(ioat, idx + i + with_ext);
  757. pq_ex = ext->pq_ex;
  758. descs[0] = (struct ioat_raw_descriptor *) pq;
  759. descs[1] = (struct ioat_raw_descriptor *) pq_ex;
  760. for (s = 0; s < src_cnt; s++)
  761. pq_set_src(descs, src[s], offset, scf[s], s);
  762. /* see the comment for dma_maxpq in include/linux/dmaengine.h */
  763. if (dmaf_p_disabled_continue(flags))
  764. pq_set_src(descs, dst[1], offset, 1, s++);
  765. else if (dmaf_continue(flags)) {
  766. pq_set_src(descs, dst[0], offset, 0, s++);
  767. pq_set_src(descs, dst[1], offset, 1, s++);
  768. pq_set_src(descs, dst[1], offset, 0, s++);
  769. }
  770. pq->size = xfer_size;
  771. pq->p_addr = dst[0] + offset;
  772. pq->q_addr = dst[1] + offset;
  773. pq->ctl = 0;
  774. pq->ctl_f.op = op;
  775. /* we turn on descriptor write back error status */
  776. if (device->cap & IOAT_CAP_DWBES)
  777. pq->ctl_f.wb_en = result ? 1 : 0;
  778. pq->ctl_f.src_cnt = src_cnt_to_hw(s);
  779. pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
  780. pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
  781. len -= xfer_size;
  782. offset += xfer_size;
  783. } while ((i += 1 + with_ext) < num_descs);
  784. /* last pq descriptor carries the unmap parameters and fence bit */
  785. desc->txd.flags = flags;
  786. desc->len = total_len;
  787. if (result)
  788. desc->result = result;
  789. pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  790. dump_pq_desc_dbg(ioat, desc, ext);
  791. if (!cb32) {
  792. pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  793. pq->ctl_f.compl_write = 1;
  794. compl_desc = desc;
  795. } else {
  796. /* completion descriptor carries interrupt bit */
  797. compl_desc = ioat2_get_ring_ent(ioat, idx + i);
  798. compl_desc->txd.flags = flags & DMA_PREP_INTERRUPT;
  799. hw = compl_desc->hw;
  800. hw->ctl = 0;
  801. hw->ctl_f.null = 1;
  802. hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  803. hw->ctl_f.compl_write = 1;
  804. hw->size = NULL_DESC_BUFFER_SIZE;
  805. dump_desc_dbg(ioat, compl_desc);
  806. }
  807. /* we leave the channel locked to ensure in order submission */
  808. return &compl_desc->txd;
  809. }
  810. static struct dma_async_tx_descriptor *
  811. __ioat3_prep_pq16_lock(struct dma_chan *c, enum sum_check_flags *result,
  812. const dma_addr_t *dst, const dma_addr_t *src,
  813. unsigned int src_cnt, const unsigned char *scf,
  814. size_t len, unsigned long flags)
  815. {
  816. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  817. struct ioat_chan_common *chan = &ioat->base;
  818. struct ioatdma_device *device = chan->device;
  819. struct ioat_ring_ent *desc;
  820. size_t total_len = len;
  821. struct ioat_pq_descriptor *pq;
  822. u32 offset = 0;
  823. u8 op;
  824. int i, s, idx, num_descs;
  825. /* this function is only called with 9-16 sources */
  826. op = result ? IOAT_OP_PQ_VAL_16S : IOAT_OP_PQ_16S;
  827. dev_dbg(to_dev(chan), "%s\n", __func__);
  828. num_descs = ioat2_xferlen_to_descs(ioat, len);
  829. /*
  830. * 16 source pq is only available on cb3.3 and has no completion
  831. * write hw bug.
  832. */
  833. if (num_descs && ioat2_check_space_lock(ioat, num_descs) == 0)
  834. idx = ioat->head;
  835. else
  836. return NULL;
  837. i = 0;
  838. do {
  839. struct ioat_raw_descriptor *descs[4];
  840. size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
  841. desc = ioat2_get_ring_ent(ioat, idx + i);
  842. pq = desc->pq;
  843. descs[0] = (struct ioat_raw_descriptor *) pq;
  844. desc->sed = ioat3_alloc_sed(device, (src_cnt-2) >> 3);
  845. if (!desc->sed) {
  846. dev_err(to_dev(chan),
  847. "%s: no free sed entries\n", __func__);
  848. return NULL;
  849. }
  850. pq->sed_addr = desc->sed->dma;
  851. desc->sed->parent = desc;
  852. descs[1] = (struct ioat_raw_descriptor *)desc->sed->hw;
  853. descs[2] = (void *)descs[1] + 64;
  854. for (s = 0; s < src_cnt; s++)
  855. pq16_set_src(descs, src[s], offset, scf[s], s);
  856. /* see the comment for dma_maxpq in include/linux/dmaengine.h */
  857. if (dmaf_p_disabled_continue(flags))
  858. pq16_set_src(descs, dst[1], offset, 1, s++);
  859. else if (dmaf_continue(flags)) {
  860. pq16_set_src(descs, dst[0], offset, 0, s++);
  861. pq16_set_src(descs, dst[1], offset, 1, s++);
  862. pq16_set_src(descs, dst[1], offset, 0, s++);
  863. }
  864. pq->size = xfer_size;
  865. pq->p_addr = dst[0] + offset;
  866. pq->q_addr = dst[1] + offset;
  867. pq->ctl = 0;
  868. pq->ctl_f.op = op;
  869. pq->ctl_f.src_cnt = src16_cnt_to_hw(s);
  870. /* we turn on descriptor write back error status */
  871. if (device->cap & IOAT_CAP_DWBES)
  872. pq->ctl_f.wb_en = result ? 1 : 0;
  873. pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
  874. pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
  875. len -= xfer_size;
  876. offset += xfer_size;
  877. } while (++i < num_descs);
  878. /* last pq descriptor carries the unmap parameters and fence bit */
  879. desc->txd.flags = flags;
  880. desc->len = total_len;
  881. if (result)
  882. desc->result = result;
  883. pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  884. /* with cb3.3 we should be able to do completion w/o a null desc */
  885. pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  886. pq->ctl_f.compl_write = 1;
  887. dump_pq16_desc_dbg(ioat, desc);
  888. /* we leave the channel locked to ensure in order submission */
  889. return &desc->txd;
  890. }
  891. static int src_cnt_flags(unsigned int src_cnt, unsigned long flags)
  892. {
  893. if (dmaf_p_disabled_continue(flags))
  894. return src_cnt + 1;
  895. else if (dmaf_continue(flags))
  896. return src_cnt + 3;
  897. else
  898. return src_cnt;
  899. }
  900. static struct dma_async_tx_descriptor *
  901. ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
  902. unsigned int src_cnt, const unsigned char *scf, size_t len,
  903. unsigned long flags)
  904. {
  905. /* specify valid address for disabled result */
  906. if (flags & DMA_PREP_PQ_DISABLE_P)
  907. dst[0] = dst[1];
  908. if (flags & DMA_PREP_PQ_DISABLE_Q)
  909. dst[1] = dst[0];
  910. /* handle the single source multiply case from the raid6
  911. * recovery path
  912. */
  913. if ((flags & DMA_PREP_PQ_DISABLE_P) && src_cnt == 1) {
  914. dma_addr_t single_source[2];
  915. unsigned char single_source_coef[2];
  916. BUG_ON(flags & DMA_PREP_PQ_DISABLE_Q);
  917. single_source[0] = src[0];
  918. single_source[1] = src[0];
  919. single_source_coef[0] = scf[0];
  920. single_source_coef[1] = 0;
  921. return src_cnt_flags(src_cnt, flags) > 8 ?
  922. __ioat3_prep_pq16_lock(chan, NULL, dst, single_source,
  923. 2, single_source_coef, len,
  924. flags) :
  925. __ioat3_prep_pq_lock(chan, NULL, dst, single_source, 2,
  926. single_source_coef, len, flags);
  927. } else {
  928. return src_cnt_flags(src_cnt, flags) > 8 ?
  929. __ioat3_prep_pq16_lock(chan, NULL, dst, src, src_cnt,
  930. scf, len, flags) :
  931. __ioat3_prep_pq_lock(chan, NULL, dst, src, src_cnt,
  932. scf, len, flags);
  933. }
  934. }
  935. struct dma_async_tx_descriptor *
  936. ioat3_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
  937. unsigned int src_cnt, const unsigned char *scf, size_t len,
  938. enum sum_check_flags *pqres, unsigned long flags)
  939. {
  940. /* specify valid address for disabled result */
  941. if (flags & DMA_PREP_PQ_DISABLE_P)
  942. pq[0] = pq[1];
  943. if (flags & DMA_PREP_PQ_DISABLE_Q)
  944. pq[1] = pq[0];
  945. /* the cleanup routine only sets bits on validate failure, it
  946. * does not clear bits on validate success... so clear it here
  947. */
  948. *pqres = 0;
  949. return src_cnt_flags(src_cnt, flags) > 8 ?
  950. __ioat3_prep_pq16_lock(chan, pqres, pq, src, src_cnt, scf, len,
  951. flags) :
  952. __ioat3_prep_pq_lock(chan, pqres, pq, src, src_cnt, scf, len,
  953. flags);
  954. }
  955. static struct dma_async_tx_descriptor *
  956. ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
  957. unsigned int src_cnt, size_t len, unsigned long flags)
  958. {
  959. unsigned char scf[src_cnt];
  960. dma_addr_t pq[2];
  961. memset(scf, 0, src_cnt);
  962. pq[0] = dst;
  963. flags |= DMA_PREP_PQ_DISABLE_Q;
  964. pq[1] = dst; /* specify valid address for disabled result */
  965. return src_cnt_flags(src_cnt, flags) > 8 ?
  966. __ioat3_prep_pq16_lock(chan, NULL, pq, src, src_cnt, scf, len,
  967. flags) :
  968. __ioat3_prep_pq_lock(chan, NULL, pq, src, src_cnt, scf, len,
  969. flags);
  970. }
  971. struct dma_async_tx_descriptor *
  972. ioat3_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
  973. unsigned int src_cnt, size_t len,
  974. enum sum_check_flags *result, unsigned long flags)
  975. {
  976. unsigned char scf[src_cnt];
  977. dma_addr_t pq[2];
  978. /* the cleanup routine only sets bits on validate failure, it
  979. * does not clear bits on validate success... so clear it here
  980. */
  981. *result = 0;
  982. memset(scf, 0, src_cnt);
  983. pq[0] = src[0];
  984. flags |= DMA_PREP_PQ_DISABLE_Q;
  985. pq[1] = pq[0]; /* specify valid address for disabled result */
  986. return src_cnt_flags(src_cnt, flags) > 8 ?
  987. __ioat3_prep_pq16_lock(chan, result, pq, &src[1], src_cnt - 1,
  988. scf, len, flags) :
  989. __ioat3_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1,
  990. scf, len, flags);
  991. }
  992. static struct dma_async_tx_descriptor *
  993. ioat3_prep_interrupt_lock(struct dma_chan *c, unsigned long flags)
  994. {
  995. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  996. struct ioat_ring_ent *desc;
  997. struct ioat_dma_descriptor *hw;
  998. if (ioat2_check_space_lock(ioat, 1) == 0)
  999. desc = ioat2_get_ring_ent(ioat, ioat->head);
  1000. else
  1001. return NULL;
  1002. hw = desc->hw;
  1003. hw->ctl = 0;
  1004. hw->ctl_f.null = 1;
  1005. hw->ctl_f.int_en = 1;
  1006. hw->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  1007. hw->ctl_f.compl_write = 1;
  1008. hw->size = NULL_DESC_BUFFER_SIZE;
  1009. hw->src_addr = 0;
  1010. hw->dst_addr = 0;
  1011. desc->txd.flags = flags;
  1012. desc->len = 1;
  1013. dump_desc_dbg(ioat, desc);
  1014. /* we leave the channel locked to ensure in order submission */
  1015. return &desc->txd;
  1016. }
  1017. static void ioat3_dma_test_callback(void *dma_async_param)
  1018. {
  1019. struct completion *cmp = dma_async_param;
  1020. complete(cmp);
  1021. }
  1022. #define IOAT_NUM_SRC_TEST 6 /* must be <= 8 */
  1023. static int ioat_xor_val_self_test(struct ioatdma_device *device)
  1024. {
  1025. int i, src_idx;
  1026. struct page *dest;
  1027. struct page *xor_srcs[IOAT_NUM_SRC_TEST];
  1028. struct page *xor_val_srcs[IOAT_NUM_SRC_TEST + 1];
  1029. dma_addr_t dma_srcs[IOAT_NUM_SRC_TEST + 1];
  1030. dma_addr_t dest_dma;
  1031. struct dma_async_tx_descriptor *tx;
  1032. struct dma_chan *dma_chan;
  1033. dma_cookie_t cookie;
  1034. u8 cmp_byte = 0;
  1035. u32 cmp_word;
  1036. u32 xor_val_result;
  1037. int err = 0;
  1038. struct completion cmp;
  1039. unsigned long tmo;
  1040. struct device *dev = &device->pdev->dev;
  1041. struct dma_device *dma = &device->common;
  1042. u8 op = 0;
  1043. dev_dbg(dev, "%s\n", __func__);
  1044. if (!dma_has_cap(DMA_XOR, dma->cap_mask))
  1045. return 0;
  1046. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) {
  1047. xor_srcs[src_idx] = alloc_page(GFP_KERNEL);
  1048. if (!xor_srcs[src_idx]) {
  1049. while (src_idx--)
  1050. __free_page(xor_srcs[src_idx]);
  1051. return -ENOMEM;
  1052. }
  1053. }
  1054. dest = alloc_page(GFP_KERNEL);
  1055. if (!dest) {
  1056. while (src_idx--)
  1057. __free_page(xor_srcs[src_idx]);
  1058. return -ENOMEM;
  1059. }
  1060. /* Fill in src buffers */
  1061. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) {
  1062. u8 *ptr = page_address(xor_srcs[src_idx]);
  1063. for (i = 0; i < PAGE_SIZE; i++)
  1064. ptr[i] = (1 << src_idx);
  1065. }
  1066. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++)
  1067. cmp_byte ^= (u8) (1 << src_idx);
  1068. cmp_word = (cmp_byte << 24) | (cmp_byte << 16) |
  1069. (cmp_byte << 8) | cmp_byte;
  1070. memset(page_address(dest), 0, PAGE_SIZE);
  1071. dma_chan = container_of(dma->channels.next, struct dma_chan,
  1072. device_node);
  1073. if (dma->device_alloc_chan_resources(dma_chan) < 1) {
  1074. err = -ENODEV;
  1075. goto out;
  1076. }
  1077. /* test xor */
  1078. op = IOAT_OP_XOR;
  1079. dest_dma = dma_map_page(dev, dest, 0, PAGE_SIZE, DMA_FROM_DEVICE);
  1080. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1081. dma_srcs[i] = dma_map_page(dev, xor_srcs[i], 0, PAGE_SIZE,
  1082. DMA_TO_DEVICE);
  1083. tx = dma->device_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
  1084. IOAT_NUM_SRC_TEST, PAGE_SIZE,
  1085. DMA_PREP_INTERRUPT);
  1086. if (!tx) {
  1087. dev_err(dev, "Self-test xor prep failed\n");
  1088. err = -ENODEV;
  1089. goto dma_unmap;
  1090. }
  1091. async_tx_ack(tx);
  1092. init_completion(&cmp);
  1093. tx->callback = ioat3_dma_test_callback;
  1094. tx->callback_param = &cmp;
  1095. cookie = tx->tx_submit(tx);
  1096. if (cookie < 0) {
  1097. dev_err(dev, "Self-test xor setup failed\n");
  1098. err = -ENODEV;
  1099. goto dma_unmap;
  1100. }
  1101. dma->device_issue_pending(dma_chan);
  1102. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1103. if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_COMPLETE) {
  1104. dev_err(dev, "Self-test xor timed out\n");
  1105. err = -ENODEV;
  1106. goto dma_unmap;
  1107. }
  1108. dma_unmap_page(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1109. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1110. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
  1111. dma_sync_single_for_cpu(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1112. for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) {
  1113. u32 *ptr = page_address(dest);
  1114. if (ptr[i] != cmp_word) {
  1115. dev_err(dev, "Self-test xor failed compare\n");
  1116. err = -ENODEV;
  1117. goto free_resources;
  1118. }
  1119. }
  1120. dma_sync_single_for_device(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1121. /* skip validate if the capability is not present */
  1122. if (!dma_has_cap(DMA_XOR_VAL, dma_chan->device->cap_mask))
  1123. goto free_resources;
  1124. op = IOAT_OP_XOR_VAL;
  1125. /* validate the sources with the destintation page */
  1126. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1127. xor_val_srcs[i] = xor_srcs[i];
  1128. xor_val_srcs[i] = dest;
  1129. xor_val_result = 1;
  1130. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1131. dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE,
  1132. DMA_TO_DEVICE);
  1133. tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
  1134. IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
  1135. &xor_val_result, DMA_PREP_INTERRUPT);
  1136. if (!tx) {
  1137. dev_err(dev, "Self-test zero prep failed\n");
  1138. err = -ENODEV;
  1139. goto dma_unmap;
  1140. }
  1141. async_tx_ack(tx);
  1142. init_completion(&cmp);
  1143. tx->callback = ioat3_dma_test_callback;
  1144. tx->callback_param = &cmp;
  1145. cookie = tx->tx_submit(tx);
  1146. if (cookie < 0) {
  1147. dev_err(dev, "Self-test zero setup failed\n");
  1148. err = -ENODEV;
  1149. goto dma_unmap;
  1150. }
  1151. dma->device_issue_pending(dma_chan);
  1152. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1153. if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_COMPLETE) {
  1154. dev_err(dev, "Self-test validate timed out\n");
  1155. err = -ENODEV;
  1156. goto dma_unmap;
  1157. }
  1158. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1159. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
  1160. if (xor_val_result != 0) {
  1161. dev_err(dev, "Self-test validate failed compare\n");
  1162. err = -ENODEV;
  1163. goto free_resources;
  1164. }
  1165. memset(page_address(dest), 0, PAGE_SIZE);
  1166. /* test for non-zero parity sum */
  1167. op = IOAT_OP_XOR_VAL;
  1168. xor_val_result = 0;
  1169. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1170. dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE,
  1171. DMA_TO_DEVICE);
  1172. tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
  1173. IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
  1174. &xor_val_result, DMA_PREP_INTERRUPT);
  1175. if (!tx) {
  1176. dev_err(dev, "Self-test 2nd zero prep failed\n");
  1177. err = -ENODEV;
  1178. goto dma_unmap;
  1179. }
  1180. async_tx_ack(tx);
  1181. init_completion(&cmp);
  1182. tx->callback = ioat3_dma_test_callback;
  1183. tx->callback_param = &cmp;
  1184. cookie = tx->tx_submit(tx);
  1185. if (cookie < 0) {
  1186. dev_err(dev, "Self-test 2nd zero setup failed\n");
  1187. err = -ENODEV;
  1188. goto dma_unmap;
  1189. }
  1190. dma->device_issue_pending(dma_chan);
  1191. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1192. if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_COMPLETE) {
  1193. dev_err(dev, "Self-test 2nd validate timed out\n");
  1194. err = -ENODEV;
  1195. goto dma_unmap;
  1196. }
  1197. if (xor_val_result != SUM_CHECK_P_RESULT) {
  1198. dev_err(dev, "Self-test validate failed compare\n");
  1199. err = -ENODEV;
  1200. goto dma_unmap;
  1201. }
  1202. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1203. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
  1204. goto free_resources;
  1205. dma_unmap:
  1206. if (op == IOAT_OP_XOR) {
  1207. dma_unmap_page(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1208. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1209. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE,
  1210. DMA_TO_DEVICE);
  1211. } else if (op == IOAT_OP_XOR_VAL) {
  1212. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1213. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE,
  1214. DMA_TO_DEVICE);
  1215. }
  1216. free_resources:
  1217. dma->device_free_chan_resources(dma_chan);
  1218. out:
  1219. src_idx = IOAT_NUM_SRC_TEST;
  1220. while (src_idx--)
  1221. __free_page(xor_srcs[src_idx]);
  1222. __free_page(dest);
  1223. return err;
  1224. }
  1225. static int ioat3_dma_self_test(struct ioatdma_device *device)
  1226. {
  1227. int rc = ioat_dma_self_test(device);
  1228. if (rc)
  1229. return rc;
  1230. rc = ioat_xor_val_self_test(device);
  1231. if (rc)
  1232. return rc;
  1233. return 0;
  1234. }
  1235. static int ioat3_irq_reinit(struct ioatdma_device *device)
  1236. {
  1237. struct pci_dev *pdev = device->pdev;
  1238. int irq = pdev->irq, i;
  1239. if (!is_bwd_ioat(pdev))
  1240. return 0;
  1241. switch (device->irq_mode) {
  1242. case IOAT_MSIX:
  1243. for (i = 0; i < device->common.chancnt; i++) {
  1244. struct msix_entry *msix = &device->msix_entries[i];
  1245. struct ioat_chan_common *chan;
  1246. chan = ioat_chan_by_index(device, i);
  1247. devm_free_irq(&pdev->dev, msix->vector, chan);
  1248. }
  1249. pci_disable_msix(pdev);
  1250. break;
  1251. case IOAT_MSI:
  1252. pci_disable_msi(pdev);
  1253. /* fall through */
  1254. case IOAT_INTX:
  1255. devm_free_irq(&pdev->dev, irq, device);
  1256. break;
  1257. default:
  1258. return 0;
  1259. }
  1260. device->irq_mode = IOAT_NOIRQ;
  1261. return ioat_dma_setup_interrupts(device);
  1262. }
  1263. static int ioat3_reset_hw(struct ioat_chan_common *chan)
  1264. {
  1265. /* throw away whatever the channel was doing and get it
  1266. * initialized, with ioat3 specific workarounds
  1267. */
  1268. struct ioatdma_device *device = chan->device;
  1269. struct pci_dev *pdev = device->pdev;
  1270. u32 chanerr;
  1271. u16 dev_id;
  1272. int err;
  1273. ioat2_quiesce(chan, msecs_to_jiffies(100));
  1274. chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  1275. writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
  1276. if (device->version < IOAT_VER_3_3) {
  1277. /* clear any pending errors */
  1278. err = pci_read_config_dword(pdev,
  1279. IOAT_PCI_CHANERR_INT_OFFSET, &chanerr);
  1280. if (err) {
  1281. dev_err(&pdev->dev,
  1282. "channel error register unreachable\n");
  1283. return err;
  1284. }
  1285. pci_write_config_dword(pdev,
  1286. IOAT_PCI_CHANERR_INT_OFFSET, chanerr);
  1287. /* Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit
  1288. * (workaround for spurious config parity error after restart)
  1289. */
  1290. pci_read_config_word(pdev, IOAT_PCI_DEVICE_ID_OFFSET, &dev_id);
  1291. if (dev_id == PCI_DEVICE_ID_INTEL_IOAT_TBG0) {
  1292. pci_write_config_dword(pdev,
  1293. IOAT_PCI_DMAUNCERRSTS_OFFSET,
  1294. 0x10);
  1295. }
  1296. }
  1297. err = ioat2_reset_sync(chan, msecs_to_jiffies(200));
  1298. if (!err)
  1299. err = ioat3_irq_reinit(device);
  1300. if (err)
  1301. dev_err(&pdev->dev, "Failed to reset: %d\n", err);
  1302. return err;
  1303. }
  1304. static void ioat3_intr_quirk(struct ioatdma_device *device)
  1305. {
  1306. struct dma_device *dma;
  1307. struct dma_chan *c;
  1308. struct ioat_chan_common *chan;
  1309. u32 errmask;
  1310. dma = &device->common;
  1311. /*
  1312. * if we have descriptor write back error status, we mask the
  1313. * error interrupts
  1314. */
  1315. if (device->cap & IOAT_CAP_DWBES) {
  1316. list_for_each_entry(c, &dma->channels, device_node) {
  1317. chan = to_chan_common(c);
  1318. errmask = readl(chan->reg_base +
  1319. IOAT_CHANERR_MASK_OFFSET);
  1320. errmask |= IOAT_CHANERR_XOR_P_OR_CRC_ERR |
  1321. IOAT_CHANERR_XOR_Q_ERR;
  1322. writel(errmask, chan->reg_base +
  1323. IOAT_CHANERR_MASK_OFFSET);
  1324. }
  1325. }
  1326. }
  1327. int ioat3_dma_probe(struct ioatdma_device *device, int dca)
  1328. {
  1329. struct pci_dev *pdev = device->pdev;
  1330. int dca_en = system_has_dca_enabled(pdev);
  1331. struct dma_device *dma;
  1332. struct dma_chan *c;
  1333. struct ioat_chan_common *chan;
  1334. bool is_raid_device = false;
  1335. int err;
  1336. device->enumerate_channels = ioat2_enumerate_channels;
  1337. device->reset_hw = ioat3_reset_hw;
  1338. device->self_test = ioat3_dma_self_test;
  1339. device->intr_quirk = ioat3_intr_quirk;
  1340. dma = &device->common;
  1341. dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock;
  1342. dma->device_issue_pending = ioat2_issue_pending;
  1343. dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
  1344. dma->device_free_chan_resources = ioat2_free_chan_resources;
  1345. dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
  1346. dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;
  1347. device->cap = readl(device->reg_base + IOAT_DMA_CAP_OFFSET);
  1348. if (is_xeon_cb32(pdev) || is_bwd_noraid(pdev))
  1349. device->cap &= ~(IOAT_CAP_XOR | IOAT_CAP_PQ | IOAT_CAP_RAID16SS);
  1350. /* dca is incompatible with raid operations */
  1351. if (dca_en && (device->cap & (IOAT_CAP_XOR|IOAT_CAP_PQ)))
  1352. device->cap &= ~(IOAT_CAP_XOR|IOAT_CAP_PQ);
  1353. if (device->cap & IOAT_CAP_XOR) {
  1354. is_raid_device = true;
  1355. dma->max_xor = 8;
  1356. dma_cap_set(DMA_XOR, dma->cap_mask);
  1357. dma->device_prep_dma_xor = ioat3_prep_xor;
  1358. dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
  1359. dma->device_prep_dma_xor_val = ioat3_prep_xor_val;
  1360. }
  1361. if (device->cap & IOAT_CAP_PQ) {
  1362. is_raid_device = true;
  1363. dma->device_prep_dma_pq = ioat3_prep_pq;
  1364. dma->device_prep_dma_pq_val = ioat3_prep_pq_val;
  1365. dma_cap_set(DMA_PQ, dma->cap_mask);
  1366. dma_cap_set(DMA_PQ_VAL, dma->cap_mask);
  1367. if (device->cap & IOAT_CAP_RAID16SS) {
  1368. dma_set_maxpq(dma, 16, 0);
  1369. } else {
  1370. dma_set_maxpq(dma, 8, 0);
  1371. }
  1372. if (!(device->cap & IOAT_CAP_XOR)) {
  1373. dma->device_prep_dma_xor = ioat3_prep_pqxor;
  1374. dma->device_prep_dma_xor_val = ioat3_prep_pqxor_val;
  1375. dma_cap_set(DMA_XOR, dma->cap_mask);
  1376. dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
  1377. if (device->cap & IOAT_CAP_RAID16SS) {
  1378. dma->max_xor = 16;
  1379. } else {
  1380. dma->max_xor = 8;
  1381. }
  1382. }
  1383. }
  1384. dma->device_tx_status = ioat3_tx_status;
  1385. device->cleanup_fn = ioat3_cleanup_event;
  1386. device->timer_fn = ioat3_timer_event;
  1387. /* starting with CB3.3 super extended descriptors are supported */
  1388. if (device->cap & IOAT_CAP_RAID16SS) {
  1389. char pool_name[14];
  1390. int i;
  1391. for (i = 0; i < MAX_SED_POOLS; i++) {
  1392. snprintf(pool_name, 14, "ioat_hw%d_sed", i);
  1393. /* allocate SED DMA pool */
  1394. device->sed_hw_pool[i] = dmam_pool_create(pool_name,
  1395. &pdev->dev,
  1396. SED_SIZE * (i + 1), 64, 0);
  1397. if (!device->sed_hw_pool[i])
  1398. return -ENOMEM;
  1399. }
  1400. }
  1401. err = ioat_probe(device);
  1402. if (err)
  1403. return err;
  1404. ioat_set_tcp_copy_break(262144);
  1405. list_for_each_entry(c, &dma->channels, device_node) {
  1406. chan = to_chan_common(c);
  1407. writel(IOAT_DMA_DCA_ANY_CPU,
  1408. chan->reg_base + IOAT_DCACTRL_OFFSET);
  1409. }
  1410. err = ioat_register(device);
  1411. if (err)
  1412. return err;
  1413. ioat_kobject_add(device, &ioat2_ktype);
  1414. if (dca)
  1415. device->dca = ioat3_dca_init(pdev, device->reg_base);
  1416. return 0;
  1417. }