dma_v3.c 47 KB

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