dma_v3.c 47 KB

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