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 is only called with 9-16 sources */
  822. op = result ? IOAT_OP_PQ_VAL_16S : IOAT_OP_PQ_16S;
  823. dev_dbg(to_dev(chan), "%s\n", __func__);
  824. num_descs = ioat2_xferlen_to_descs(ioat, len);
  825. /*
  826. * 16 source pq is only available on cb3.3 and has no completion
  827. * write hw bug.
  828. */
  829. if (num_descs && ioat2_check_space_lock(ioat, num_descs) == 0)
  830. idx = ioat->head;
  831. else
  832. return NULL;
  833. i = 0;
  834. do {
  835. struct ioat_raw_descriptor *descs[4];
  836. size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
  837. desc = ioat2_get_ring_ent(ioat, idx + i);
  838. pq = desc->pq;
  839. descs[0] = (struct ioat_raw_descriptor *) pq;
  840. desc->sed = ioat3_alloc_sed(device, (src_cnt-2) >> 3);
  841. if (!desc->sed) {
  842. dev_err(to_dev(chan),
  843. "%s: no free sed entries\n", __func__);
  844. return NULL;
  845. }
  846. pq->sed_addr = desc->sed->dma;
  847. desc->sed->parent = desc;
  848. descs[1] = (struct ioat_raw_descriptor *)desc->sed->hw;
  849. descs[2] = (void *)descs[1] + 64;
  850. for (s = 0; s < src_cnt; s++)
  851. pq16_set_src(descs, src[s], offset, scf[s], s);
  852. /* see the comment for dma_maxpq in include/linux/dmaengine.h */
  853. if (dmaf_p_disabled_continue(flags))
  854. pq16_set_src(descs, dst[1], offset, 1, s++);
  855. else if (dmaf_continue(flags)) {
  856. pq16_set_src(descs, dst[0], offset, 0, s++);
  857. pq16_set_src(descs, dst[1], offset, 1, s++);
  858. pq16_set_src(descs, dst[1], offset, 0, s++);
  859. }
  860. pq->size = xfer_size;
  861. pq->p_addr = dst[0] + offset;
  862. pq->q_addr = dst[1] + offset;
  863. pq->ctl = 0;
  864. pq->ctl_f.op = op;
  865. pq->ctl_f.src_cnt = src16_cnt_to_hw(s);
  866. /* we turn on descriptor write back error status */
  867. if (device->cap & IOAT_CAP_DWBES)
  868. pq->ctl_f.wb_en = result ? 1 : 0;
  869. pq->ctl_f.p_disable = !!(flags & DMA_PREP_PQ_DISABLE_P);
  870. pq->ctl_f.q_disable = !!(flags & DMA_PREP_PQ_DISABLE_Q);
  871. len -= xfer_size;
  872. offset += xfer_size;
  873. } while (++i < num_descs);
  874. /* last pq descriptor carries the unmap parameters and fence bit */
  875. desc->txd.flags = flags;
  876. desc->len = total_len;
  877. if (result)
  878. desc->result = result;
  879. pq->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  880. /* with cb3.3 we should be able to do completion w/o a null desc */
  881. pq->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
  882. pq->ctl_f.compl_write = 1;
  883. dump_pq16_desc_dbg(ioat, desc);
  884. /* we leave the channel locked to ensure in order submission */
  885. return &desc->txd;
  886. }
  887. static int src_cnt_flags(unsigned int src_cnt, unsigned long flags)
  888. {
  889. if (dmaf_p_disabled_continue(flags))
  890. return src_cnt + 1;
  891. else if (dmaf_continue(flags))
  892. return src_cnt + 3;
  893. else
  894. return src_cnt;
  895. }
  896. static struct dma_async_tx_descriptor *
  897. ioat3_prep_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
  898. unsigned int src_cnt, const unsigned char *scf, size_t len,
  899. unsigned long flags)
  900. {
  901. /* specify valid address for disabled result */
  902. if (flags & DMA_PREP_PQ_DISABLE_P)
  903. dst[0] = dst[1];
  904. if (flags & DMA_PREP_PQ_DISABLE_Q)
  905. dst[1] = dst[0];
  906. /* handle the single source multiply case from the raid6
  907. * recovery path
  908. */
  909. if ((flags & DMA_PREP_PQ_DISABLE_P) && src_cnt == 1) {
  910. dma_addr_t single_source[2];
  911. unsigned char single_source_coef[2];
  912. BUG_ON(flags & DMA_PREP_PQ_DISABLE_Q);
  913. single_source[0] = src[0];
  914. single_source[1] = src[0];
  915. single_source_coef[0] = scf[0];
  916. single_source_coef[1] = 0;
  917. return src_cnt_flags(src_cnt, flags) > 8 ?
  918. __ioat3_prep_pq16_lock(chan, NULL, dst, single_source,
  919. 2, single_source_coef, len,
  920. flags) :
  921. __ioat3_prep_pq_lock(chan, NULL, dst, single_source, 2,
  922. single_source_coef, len, flags);
  923. } else {
  924. return src_cnt_flags(src_cnt, flags) > 8 ?
  925. __ioat3_prep_pq16_lock(chan, NULL, dst, src, src_cnt,
  926. scf, len, flags) :
  927. __ioat3_prep_pq_lock(chan, NULL, dst, src, src_cnt,
  928. scf, len, flags);
  929. }
  930. }
  931. struct dma_async_tx_descriptor *
  932. ioat3_prep_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
  933. unsigned int src_cnt, const unsigned char *scf, size_t len,
  934. enum sum_check_flags *pqres, unsigned long flags)
  935. {
  936. /* specify valid address for disabled result */
  937. if (flags & DMA_PREP_PQ_DISABLE_P)
  938. pq[0] = pq[1];
  939. if (flags & DMA_PREP_PQ_DISABLE_Q)
  940. pq[1] = pq[0];
  941. /* the cleanup routine only sets bits on validate failure, it
  942. * does not clear bits on validate success... so clear it here
  943. */
  944. *pqres = 0;
  945. return src_cnt_flags(src_cnt, flags) > 8 ?
  946. __ioat3_prep_pq16_lock(chan, pqres, pq, src, src_cnt, scf, len,
  947. flags) :
  948. __ioat3_prep_pq_lock(chan, pqres, pq, src, src_cnt, scf, len,
  949. flags);
  950. }
  951. static struct dma_async_tx_descriptor *
  952. ioat3_prep_pqxor(struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
  953. unsigned int src_cnt, size_t len, unsigned long flags)
  954. {
  955. unsigned char scf[src_cnt];
  956. dma_addr_t pq[2];
  957. memset(scf, 0, src_cnt);
  958. pq[0] = dst;
  959. flags |= DMA_PREP_PQ_DISABLE_Q;
  960. pq[1] = dst; /* specify valid address for disabled result */
  961. return src_cnt_flags(src_cnt, flags) > 8 ?
  962. __ioat3_prep_pq16_lock(chan, NULL, pq, src, src_cnt, scf, len,
  963. flags) :
  964. __ioat3_prep_pq_lock(chan, NULL, pq, src, src_cnt, scf, len,
  965. flags);
  966. }
  967. struct dma_async_tx_descriptor *
  968. ioat3_prep_pqxor_val(struct dma_chan *chan, dma_addr_t *src,
  969. unsigned int src_cnt, size_t len,
  970. enum sum_check_flags *result, unsigned long flags)
  971. {
  972. unsigned char scf[src_cnt];
  973. dma_addr_t pq[2];
  974. /* the cleanup routine only sets bits on validate failure, it
  975. * does not clear bits on validate success... so clear it here
  976. */
  977. *result = 0;
  978. memset(scf, 0, src_cnt);
  979. pq[0] = src[0];
  980. flags |= DMA_PREP_PQ_DISABLE_Q;
  981. pq[1] = pq[0]; /* specify valid address for disabled result */
  982. return src_cnt_flags(src_cnt, flags) > 8 ?
  983. __ioat3_prep_pq16_lock(chan, result, pq, &src[1], src_cnt - 1,
  984. scf, len, flags) :
  985. __ioat3_prep_pq_lock(chan, result, pq, &src[1], src_cnt - 1,
  986. scf, len, flags);
  987. }
  988. static struct dma_async_tx_descriptor *
  989. ioat3_prep_interrupt_lock(struct dma_chan *c, unsigned long flags)
  990. {
  991. struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
  992. struct ioat_ring_ent *desc;
  993. struct ioat_dma_descriptor *hw;
  994. if (ioat2_check_space_lock(ioat, 1) == 0)
  995. desc = ioat2_get_ring_ent(ioat, ioat->head);
  996. else
  997. return NULL;
  998. hw = desc->hw;
  999. hw->ctl = 0;
  1000. hw->ctl_f.null = 1;
  1001. hw->ctl_f.int_en = 1;
  1002. hw->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
  1003. hw->ctl_f.compl_write = 1;
  1004. hw->size = NULL_DESC_BUFFER_SIZE;
  1005. hw->src_addr = 0;
  1006. hw->dst_addr = 0;
  1007. desc->txd.flags = flags;
  1008. desc->len = 1;
  1009. dump_desc_dbg(ioat, desc);
  1010. /* we leave the channel locked to ensure in order submission */
  1011. return &desc->txd;
  1012. }
  1013. static void ioat3_dma_test_callback(void *dma_async_param)
  1014. {
  1015. struct completion *cmp = dma_async_param;
  1016. complete(cmp);
  1017. }
  1018. #define IOAT_NUM_SRC_TEST 6 /* must be <= 8 */
  1019. static int ioat_xor_val_self_test(struct ioatdma_device *device)
  1020. {
  1021. int i, src_idx;
  1022. struct page *dest;
  1023. struct page *xor_srcs[IOAT_NUM_SRC_TEST];
  1024. struct page *xor_val_srcs[IOAT_NUM_SRC_TEST + 1];
  1025. dma_addr_t dma_srcs[IOAT_NUM_SRC_TEST + 1];
  1026. dma_addr_t dest_dma;
  1027. struct dma_async_tx_descriptor *tx;
  1028. struct dma_chan *dma_chan;
  1029. dma_cookie_t cookie;
  1030. u8 cmp_byte = 0;
  1031. u32 cmp_word;
  1032. u32 xor_val_result;
  1033. int err = 0;
  1034. struct completion cmp;
  1035. unsigned long tmo;
  1036. struct device *dev = &device->pdev->dev;
  1037. struct dma_device *dma = &device->common;
  1038. u8 op = 0;
  1039. dev_dbg(dev, "%s\n", __func__);
  1040. if (!dma_has_cap(DMA_XOR, dma->cap_mask))
  1041. return 0;
  1042. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) {
  1043. xor_srcs[src_idx] = alloc_page(GFP_KERNEL);
  1044. if (!xor_srcs[src_idx]) {
  1045. while (src_idx--)
  1046. __free_page(xor_srcs[src_idx]);
  1047. return -ENOMEM;
  1048. }
  1049. }
  1050. dest = alloc_page(GFP_KERNEL);
  1051. if (!dest) {
  1052. while (src_idx--)
  1053. __free_page(xor_srcs[src_idx]);
  1054. return -ENOMEM;
  1055. }
  1056. /* Fill in src buffers */
  1057. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++) {
  1058. u8 *ptr = page_address(xor_srcs[src_idx]);
  1059. for (i = 0; i < PAGE_SIZE; i++)
  1060. ptr[i] = (1 << src_idx);
  1061. }
  1062. for (src_idx = 0; src_idx < IOAT_NUM_SRC_TEST; src_idx++)
  1063. cmp_byte ^= (u8) (1 << src_idx);
  1064. cmp_word = (cmp_byte << 24) | (cmp_byte << 16) |
  1065. (cmp_byte << 8) | cmp_byte;
  1066. memset(page_address(dest), 0, PAGE_SIZE);
  1067. dma_chan = container_of(dma->channels.next, struct dma_chan,
  1068. device_node);
  1069. if (dma->device_alloc_chan_resources(dma_chan) < 1) {
  1070. err = -ENODEV;
  1071. goto out;
  1072. }
  1073. /* test xor */
  1074. op = IOAT_OP_XOR;
  1075. dest_dma = dma_map_page(dev, dest, 0, PAGE_SIZE, DMA_FROM_DEVICE);
  1076. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1077. dma_srcs[i] = dma_map_page(dev, xor_srcs[i], 0, PAGE_SIZE,
  1078. DMA_TO_DEVICE);
  1079. tx = dma->device_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
  1080. IOAT_NUM_SRC_TEST, PAGE_SIZE,
  1081. DMA_PREP_INTERRUPT);
  1082. if (!tx) {
  1083. dev_err(dev, "Self-test xor prep failed\n");
  1084. err = -ENODEV;
  1085. goto dma_unmap;
  1086. }
  1087. async_tx_ack(tx);
  1088. init_completion(&cmp);
  1089. tx->callback = ioat3_dma_test_callback;
  1090. tx->callback_param = &cmp;
  1091. cookie = tx->tx_submit(tx);
  1092. if (cookie < 0) {
  1093. dev_err(dev, "Self-test xor setup failed\n");
  1094. err = -ENODEV;
  1095. goto dma_unmap;
  1096. }
  1097. dma->device_issue_pending(dma_chan);
  1098. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1099. if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  1100. dev_err(dev, "Self-test xor timed out\n");
  1101. err = -ENODEV;
  1102. goto dma_unmap;
  1103. }
  1104. dma_unmap_page(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1105. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1106. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
  1107. dma_sync_single_for_cpu(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1108. for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) {
  1109. u32 *ptr = page_address(dest);
  1110. if (ptr[i] != cmp_word) {
  1111. dev_err(dev, "Self-test xor failed compare\n");
  1112. err = -ENODEV;
  1113. goto free_resources;
  1114. }
  1115. }
  1116. dma_sync_single_for_device(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1117. /* skip validate if the capability is not present */
  1118. if (!dma_has_cap(DMA_XOR_VAL, dma_chan->device->cap_mask))
  1119. goto free_resources;
  1120. op = IOAT_OP_XOR_VAL;
  1121. /* validate the sources with the destintation page */
  1122. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1123. xor_val_srcs[i] = xor_srcs[i];
  1124. xor_val_srcs[i] = dest;
  1125. xor_val_result = 1;
  1126. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1127. dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE,
  1128. DMA_TO_DEVICE);
  1129. tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
  1130. IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
  1131. &xor_val_result, DMA_PREP_INTERRUPT);
  1132. if (!tx) {
  1133. dev_err(dev, "Self-test zero prep failed\n");
  1134. err = -ENODEV;
  1135. goto dma_unmap;
  1136. }
  1137. async_tx_ack(tx);
  1138. init_completion(&cmp);
  1139. tx->callback = ioat3_dma_test_callback;
  1140. tx->callback_param = &cmp;
  1141. cookie = tx->tx_submit(tx);
  1142. if (cookie < 0) {
  1143. dev_err(dev, "Self-test zero setup failed\n");
  1144. err = -ENODEV;
  1145. goto dma_unmap;
  1146. }
  1147. dma->device_issue_pending(dma_chan);
  1148. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1149. if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  1150. dev_err(dev, "Self-test validate timed out\n");
  1151. err = -ENODEV;
  1152. goto dma_unmap;
  1153. }
  1154. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1155. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
  1156. if (xor_val_result != 0) {
  1157. dev_err(dev, "Self-test validate failed compare\n");
  1158. err = -ENODEV;
  1159. goto free_resources;
  1160. }
  1161. memset(page_address(dest), 0, PAGE_SIZE);
  1162. /* test for non-zero parity sum */
  1163. op = IOAT_OP_XOR_VAL;
  1164. xor_val_result = 0;
  1165. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1166. dma_srcs[i] = dma_map_page(dev, xor_val_srcs[i], 0, PAGE_SIZE,
  1167. DMA_TO_DEVICE);
  1168. tx = dma->device_prep_dma_xor_val(dma_chan, dma_srcs,
  1169. IOAT_NUM_SRC_TEST + 1, PAGE_SIZE,
  1170. &xor_val_result, DMA_PREP_INTERRUPT);
  1171. if (!tx) {
  1172. dev_err(dev, "Self-test 2nd zero prep failed\n");
  1173. err = -ENODEV;
  1174. goto dma_unmap;
  1175. }
  1176. async_tx_ack(tx);
  1177. init_completion(&cmp);
  1178. tx->callback = ioat3_dma_test_callback;
  1179. tx->callback_param = &cmp;
  1180. cookie = tx->tx_submit(tx);
  1181. if (cookie < 0) {
  1182. dev_err(dev, "Self-test 2nd zero setup failed\n");
  1183. err = -ENODEV;
  1184. goto dma_unmap;
  1185. }
  1186. dma->device_issue_pending(dma_chan);
  1187. tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
  1188. if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  1189. dev_err(dev, "Self-test 2nd validate timed out\n");
  1190. err = -ENODEV;
  1191. goto dma_unmap;
  1192. }
  1193. if (xor_val_result != SUM_CHECK_P_RESULT) {
  1194. dev_err(dev, "Self-test validate failed compare\n");
  1195. err = -ENODEV;
  1196. goto dma_unmap;
  1197. }
  1198. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1199. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, DMA_TO_DEVICE);
  1200. goto free_resources;
  1201. dma_unmap:
  1202. if (op == IOAT_OP_XOR) {
  1203. dma_unmap_page(dev, dest_dma, PAGE_SIZE, DMA_FROM_DEVICE);
  1204. for (i = 0; i < IOAT_NUM_SRC_TEST; i++)
  1205. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE,
  1206. DMA_TO_DEVICE);
  1207. } else if (op == IOAT_OP_XOR_VAL) {
  1208. for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
  1209. dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE,
  1210. DMA_TO_DEVICE);
  1211. }
  1212. free_resources:
  1213. dma->device_free_chan_resources(dma_chan);
  1214. out:
  1215. src_idx = IOAT_NUM_SRC_TEST;
  1216. while (src_idx--)
  1217. __free_page(xor_srcs[src_idx]);
  1218. __free_page(dest);
  1219. return err;
  1220. }
  1221. static int ioat3_dma_self_test(struct ioatdma_device *device)
  1222. {
  1223. int rc = ioat_dma_self_test(device);
  1224. if (rc)
  1225. return rc;
  1226. rc = ioat_xor_val_self_test(device);
  1227. if (rc)
  1228. return rc;
  1229. return 0;
  1230. }
  1231. static int ioat3_irq_reinit(struct ioatdma_device *device)
  1232. {
  1233. int msixcnt = device->common.chancnt;
  1234. struct pci_dev *pdev = device->pdev;
  1235. int i;
  1236. struct msix_entry *msix;
  1237. struct ioat_chan_common *chan;
  1238. int err = 0;
  1239. switch (device->irq_mode) {
  1240. case IOAT_MSIX:
  1241. for (i = 0; i < msixcnt; i++) {
  1242. msix = &device->msix_entries[i];
  1243. chan = ioat_chan_by_index(device, i);
  1244. devm_free_irq(&pdev->dev, msix->vector, chan);
  1245. }
  1246. pci_disable_msix(pdev);
  1247. break;
  1248. case IOAT_MSIX_SINGLE:
  1249. msix = &device->msix_entries[0];
  1250. chan = ioat_chan_by_index(device, 0);
  1251. devm_free_irq(&pdev->dev, msix->vector, chan);
  1252. pci_disable_msix(pdev);
  1253. break;
  1254. case IOAT_MSI:
  1255. chan = ioat_chan_by_index(device, 0);
  1256. devm_free_irq(&pdev->dev, pdev->irq, chan);
  1257. pci_disable_msi(pdev);
  1258. break;
  1259. case IOAT_INTX:
  1260. chan = ioat_chan_by_index(device, 0);
  1261. devm_free_irq(&pdev->dev, pdev->irq, chan);
  1262. break;
  1263. default:
  1264. return 0;
  1265. }
  1266. device->irq_mode = IOAT_NOIRQ;
  1267. err = ioat_dma_setup_interrupts(device);
  1268. return err;
  1269. }
  1270. static int ioat3_reset_hw(struct ioat_chan_common *chan)
  1271. {
  1272. /* throw away whatever the channel was doing and get it
  1273. * initialized, with ioat3 specific workarounds
  1274. */
  1275. struct ioatdma_device *device = chan->device;
  1276. struct pci_dev *pdev = device->pdev;
  1277. u32 chanerr;
  1278. u16 dev_id;
  1279. int err;
  1280. ioat2_quiesce(chan, msecs_to_jiffies(100));
  1281. chanerr = readl(chan->reg_base + IOAT_CHANERR_OFFSET);
  1282. writel(chanerr, chan->reg_base + IOAT_CHANERR_OFFSET);
  1283. if (device->version < IOAT_VER_3_3) {
  1284. /* clear any pending errors */
  1285. err = pci_read_config_dword(pdev,
  1286. IOAT_PCI_CHANERR_INT_OFFSET, &chanerr);
  1287. if (err) {
  1288. dev_err(&pdev->dev,
  1289. "channel error register unreachable\n");
  1290. return err;
  1291. }
  1292. pci_write_config_dword(pdev,
  1293. IOAT_PCI_CHANERR_INT_OFFSET, chanerr);
  1294. /* Clear DMAUNCERRSTS Cfg-Reg Parity Error status bit
  1295. * (workaround for spurious config parity error after restart)
  1296. */
  1297. pci_read_config_word(pdev, IOAT_PCI_DEVICE_ID_OFFSET, &dev_id);
  1298. if (dev_id == PCI_DEVICE_ID_INTEL_IOAT_TBG0) {
  1299. pci_write_config_dword(pdev,
  1300. IOAT_PCI_DMAUNCERRSTS_OFFSET,
  1301. 0x10);
  1302. }
  1303. }
  1304. err = ioat2_reset_sync(chan, msecs_to_jiffies(200));
  1305. if (err) {
  1306. dev_err(&pdev->dev, "Failed to reset!\n");
  1307. return err;
  1308. }
  1309. if (device->irq_mode != IOAT_NOIRQ && is_bwd_ioat(pdev))
  1310. err = ioat3_irq_reinit(device);
  1311. return err;
  1312. }
  1313. static void ioat3_intr_quirk(struct ioatdma_device *device)
  1314. {
  1315. struct dma_device *dma;
  1316. struct dma_chan *c;
  1317. struct ioat_chan_common *chan;
  1318. u32 errmask;
  1319. dma = &device->common;
  1320. /*
  1321. * if we have descriptor write back error status, we mask the
  1322. * error interrupts
  1323. */
  1324. if (device->cap & IOAT_CAP_DWBES) {
  1325. list_for_each_entry(c, &dma->channels, device_node) {
  1326. chan = to_chan_common(c);
  1327. errmask = readl(chan->reg_base +
  1328. IOAT_CHANERR_MASK_OFFSET);
  1329. errmask |= IOAT_CHANERR_XOR_P_OR_CRC_ERR |
  1330. IOAT_CHANERR_XOR_Q_ERR;
  1331. writel(errmask, chan->reg_base +
  1332. IOAT_CHANERR_MASK_OFFSET);
  1333. }
  1334. }
  1335. }
  1336. int ioat3_dma_probe(struct ioatdma_device *device, int dca)
  1337. {
  1338. struct pci_dev *pdev = device->pdev;
  1339. int dca_en = system_has_dca_enabled(pdev);
  1340. struct dma_device *dma;
  1341. struct dma_chan *c;
  1342. struct ioat_chan_common *chan;
  1343. bool is_raid_device = false;
  1344. int err;
  1345. device->enumerate_channels = ioat2_enumerate_channels;
  1346. device->reset_hw = ioat3_reset_hw;
  1347. device->self_test = ioat3_dma_self_test;
  1348. device->intr_quirk = ioat3_intr_quirk;
  1349. dma = &device->common;
  1350. dma->device_prep_dma_memcpy = ioat2_dma_prep_memcpy_lock;
  1351. dma->device_issue_pending = ioat2_issue_pending;
  1352. dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
  1353. dma->device_free_chan_resources = ioat2_free_chan_resources;
  1354. dma_cap_set(DMA_INTERRUPT, dma->cap_mask);
  1355. dma->device_prep_dma_interrupt = ioat3_prep_interrupt_lock;
  1356. device->cap = readl(device->reg_base + IOAT_DMA_CAP_OFFSET);
  1357. if (is_xeon_cb32(pdev) || is_bwd_noraid(pdev))
  1358. device->cap &= ~(IOAT_CAP_XOR | IOAT_CAP_PQ | IOAT_CAP_RAID16SS);
  1359. /* dca is incompatible with raid operations */
  1360. if (dca_en && (device->cap & (IOAT_CAP_XOR|IOAT_CAP_PQ)))
  1361. device->cap &= ~(IOAT_CAP_XOR|IOAT_CAP_PQ);
  1362. if (device->cap & IOAT_CAP_XOR) {
  1363. is_raid_device = true;
  1364. dma->max_xor = 8;
  1365. dma_cap_set(DMA_XOR, dma->cap_mask);
  1366. dma->device_prep_dma_xor = ioat3_prep_xor;
  1367. dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
  1368. dma->device_prep_dma_xor_val = ioat3_prep_xor_val;
  1369. }
  1370. if (device->cap & IOAT_CAP_PQ) {
  1371. is_raid_device = true;
  1372. dma->device_prep_dma_pq = ioat3_prep_pq;
  1373. dma->device_prep_dma_pq_val = ioat3_prep_pq_val;
  1374. dma_cap_set(DMA_PQ, dma->cap_mask);
  1375. dma_cap_set(DMA_PQ_VAL, dma->cap_mask);
  1376. if (device->cap & IOAT_CAP_RAID16SS) {
  1377. dma_set_maxpq(dma, 16, 0);
  1378. } else {
  1379. dma_set_maxpq(dma, 8, 0);
  1380. }
  1381. if (!(device->cap & IOAT_CAP_XOR)) {
  1382. dma->device_prep_dma_xor = ioat3_prep_pqxor;
  1383. dma->device_prep_dma_xor_val = ioat3_prep_pqxor_val;
  1384. dma_cap_set(DMA_XOR, dma->cap_mask);
  1385. dma_cap_set(DMA_XOR_VAL, dma->cap_mask);
  1386. if (device->cap & IOAT_CAP_RAID16SS) {
  1387. dma->max_xor = 16;
  1388. } else {
  1389. dma->max_xor = 8;
  1390. }
  1391. }
  1392. }
  1393. dma->device_tx_status = ioat3_tx_status;
  1394. device->cleanup_fn = ioat3_cleanup_event;
  1395. device->timer_fn = ioat3_timer_event;
  1396. /* starting with CB3.3 super extended descriptors are supported */
  1397. if (device->cap & IOAT_CAP_RAID16SS) {
  1398. char pool_name[14];
  1399. int i;
  1400. /* allocate sw descriptor pool for SED */
  1401. device->sed_pool = kmem_cache_create("ioat_sed",
  1402. sizeof(struct ioat_sed_ent), 0, 0, NULL);
  1403. if (!device->sed_pool)
  1404. return -ENOMEM;
  1405. for (i = 0; i < MAX_SED_POOLS; i++) {
  1406. snprintf(pool_name, 14, "ioat_hw%d_sed", i);
  1407. /* allocate SED DMA pool */
  1408. device->sed_hw_pool[i] = dma_pool_create(pool_name,
  1409. &pdev->dev,
  1410. SED_SIZE * (i + 1), 64, 0);
  1411. if (!device->sed_hw_pool[i])
  1412. goto sed_pool_cleanup;
  1413. }
  1414. }
  1415. err = ioat_probe(device);
  1416. if (err)
  1417. return err;
  1418. ioat_set_tcp_copy_break(262144);
  1419. list_for_each_entry(c, &dma->channels, device_node) {
  1420. chan = to_chan_common(c);
  1421. writel(IOAT_DMA_DCA_ANY_CPU,
  1422. chan->reg_base + IOAT_DCACTRL_OFFSET);
  1423. }
  1424. err = ioat_register(device);
  1425. if (err)
  1426. return err;
  1427. ioat_kobject_add(device, &ioat2_ktype);
  1428. if (dca)
  1429. device->dca = ioat3_dca_init(pdev, device->reg_base);
  1430. return 0;
  1431. sed_pool_cleanup:
  1432. if (device->sed_pool) {
  1433. int i;
  1434. kmem_cache_destroy(device->sed_pool);
  1435. for (i = 0; i < MAX_SED_POOLS; i++)
  1436. if (device->sed_hw_pool[i])
  1437. dma_pool_destroy(device->sed_hw_pool[i]);
  1438. }
  1439. return -ENOMEM;
  1440. }
  1441. void ioat3_dma_remove(struct ioatdma_device *device)
  1442. {
  1443. if (device->sed_pool) {
  1444. int i;
  1445. kmem_cache_destroy(device->sed_pool);
  1446. for (i = 0; i < MAX_SED_POOLS; i++)
  1447. if (device->sed_hw_pool[i])
  1448. dma_pool_destroy(device->sed_hw_pool[i]);
  1449. }
  1450. }