iop-adma.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  1. /*
  2. * offload engine driver for the Intel Xscale series of i/o processors
  3. * Copyright © 2006, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. /*
  20. * This driver supports the asynchrounous DMA copy and RAID engines available
  21. * on the Intel Xscale(R) family of I/O Processors (IOP 32x, 33x, 134x)
  22. */
  23. #include <linux/init.h>
  24. #include <linux/module.h>
  25. #include <linux/delay.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/memory.h>
  31. #include <linux/ioport.h>
  32. #include <linux/raid/pq.h>
  33. #include <linux/slab.h>
  34. #include <mach/adma.h>
  35. #include "dmaengine.h"
  36. #define to_iop_adma_chan(chan) container_of(chan, struct iop_adma_chan, common)
  37. #define to_iop_adma_device(dev) \
  38. container_of(dev, struct iop_adma_device, common)
  39. #define tx_to_iop_adma_slot(tx) \
  40. container_of(tx, struct iop_adma_desc_slot, async_tx)
  41. /**
  42. * iop_adma_free_slots - flags descriptor slots for reuse
  43. * @slot: Slot to free
  44. * Caller must hold &iop_chan->lock while calling this function
  45. */
  46. static void iop_adma_free_slots(struct iop_adma_desc_slot *slot)
  47. {
  48. int stride = slot->slots_per_op;
  49. while (stride--) {
  50. slot->slots_per_op = 0;
  51. slot = list_entry(slot->slot_node.next,
  52. struct iop_adma_desc_slot,
  53. slot_node);
  54. }
  55. }
  56. static void
  57. iop_desc_unmap(struct iop_adma_chan *iop_chan, struct iop_adma_desc_slot *desc)
  58. {
  59. struct dma_async_tx_descriptor *tx = &desc->async_tx;
  60. struct iop_adma_desc_slot *unmap = desc->group_head;
  61. struct device *dev = &iop_chan->device->pdev->dev;
  62. u32 len = unmap->unmap_len;
  63. enum dma_ctrl_flags flags = tx->flags;
  64. u32 src_cnt;
  65. dma_addr_t addr;
  66. dma_addr_t dest;
  67. src_cnt = unmap->unmap_src_cnt;
  68. dest = iop_desc_get_dest_addr(unmap, iop_chan);
  69. if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
  70. enum dma_data_direction dir;
  71. if (src_cnt > 1) /* is xor? */
  72. dir = DMA_BIDIRECTIONAL;
  73. else
  74. dir = DMA_FROM_DEVICE;
  75. dma_unmap_page(dev, dest, len, dir);
  76. }
  77. if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
  78. while (src_cnt--) {
  79. addr = iop_desc_get_src_addr(unmap, iop_chan, src_cnt);
  80. if (addr == dest)
  81. continue;
  82. dma_unmap_page(dev, addr, len, DMA_TO_DEVICE);
  83. }
  84. }
  85. desc->group_head = NULL;
  86. }
  87. static void
  88. iop_desc_unmap_pq(struct iop_adma_chan *iop_chan, struct iop_adma_desc_slot *desc)
  89. {
  90. struct dma_async_tx_descriptor *tx = &desc->async_tx;
  91. struct iop_adma_desc_slot *unmap = desc->group_head;
  92. struct device *dev = &iop_chan->device->pdev->dev;
  93. u32 len = unmap->unmap_len;
  94. enum dma_ctrl_flags flags = tx->flags;
  95. u32 src_cnt = unmap->unmap_src_cnt;
  96. dma_addr_t pdest = iop_desc_get_dest_addr(unmap, iop_chan);
  97. dma_addr_t qdest = iop_desc_get_qdest_addr(unmap, iop_chan);
  98. int i;
  99. if (tx->flags & DMA_PREP_CONTINUE)
  100. src_cnt -= 3;
  101. if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP) && !desc->pq_check_result) {
  102. dma_unmap_page(dev, pdest, len, DMA_BIDIRECTIONAL);
  103. dma_unmap_page(dev, qdest, len, DMA_BIDIRECTIONAL);
  104. }
  105. if (!(flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
  106. dma_addr_t addr;
  107. for (i = 0; i < src_cnt; i++) {
  108. addr = iop_desc_get_src_addr(unmap, iop_chan, i);
  109. dma_unmap_page(dev, addr, len, DMA_TO_DEVICE);
  110. }
  111. if (desc->pq_check_result) {
  112. dma_unmap_page(dev, pdest, len, DMA_TO_DEVICE);
  113. dma_unmap_page(dev, qdest, len, DMA_TO_DEVICE);
  114. }
  115. }
  116. desc->group_head = NULL;
  117. }
  118. static dma_cookie_t
  119. iop_adma_run_tx_complete_actions(struct iop_adma_desc_slot *desc,
  120. struct iop_adma_chan *iop_chan, dma_cookie_t cookie)
  121. {
  122. struct dma_async_tx_descriptor *tx = &desc->async_tx;
  123. BUG_ON(tx->cookie < 0);
  124. if (tx->cookie > 0) {
  125. cookie = tx->cookie;
  126. tx->cookie = 0;
  127. /* call the callback (must not sleep or submit new
  128. * operations to this channel)
  129. */
  130. if (tx->callback)
  131. tx->callback(tx->callback_param);
  132. /* unmap dma addresses
  133. * (unmap_single vs unmap_page?)
  134. */
  135. if (desc->group_head && desc->unmap_len) {
  136. if (iop_desc_is_pq(desc))
  137. iop_desc_unmap_pq(iop_chan, desc);
  138. else
  139. iop_desc_unmap(iop_chan, desc);
  140. }
  141. }
  142. /* run dependent operations */
  143. dma_run_dependencies(tx);
  144. return cookie;
  145. }
  146. static int
  147. iop_adma_clean_slot(struct iop_adma_desc_slot *desc,
  148. struct iop_adma_chan *iop_chan)
  149. {
  150. /* the client is allowed to attach dependent operations
  151. * until 'ack' is set
  152. */
  153. if (!async_tx_test_ack(&desc->async_tx))
  154. return 0;
  155. /* leave the last descriptor in the chain
  156. * so we can append to it
  157. */
  158. if (desc->chain_node.next == &iop_chan->chain)
  159. return 1;
  160. dev_dbg(iop_chan->device->common.dev,
  161. "\tfree slot: %d slots_per_op: %d\n",
  162. desc->idx, desc->slots_per_op);
  163. list_del(&desc->chain_node);
  164. iop_adma_free_slots(desc);
  165. return 0;
  166. }
  167. static void __iop_adma_slot_cleanup(struct iop_adma_chan *iop_chan)
  168. {
  169. struct iop_adma_desc_slot *iter, *_iter, *grp_start = NULL;
  170. dma_cookie_t cookie = 0;
  171. u32 current_desc = iop_chan_get_current_descriptor(iop_chan);
  172. int busy = iop_chan_is_busy(iop_chan);
  173. int seen_current = 0, slot_cnt = 0, slots_per_op = 0;
  174. dev_dbg(iop_chan->device->common.dev, "%s\n", __func__);
  175. /* free completed slots from the chain starting with
  176. * the oldest descriptor
  177. */
  178. list_for_each_entry_safe(iter, _iter, &iop_chan->chain,
  179. chain_node) {
  180. pr_debug("\tcookie: %d slot: %d busy: %d "
  181. "this_desc: %#x next_desc: %#x ack: %d\n",
  182. iter->async_tx.cookie, iter->idx, busy,
  183. iter->async_tx.phys, iop_desc_get_next_desc(iter),
  184. async_tx_test_ack(&iter->async_tx));
  185. prefetch(_iter);
  186. prefetch(&_iter->async_tx);
  187. /* do not advance past the current descriptor loaded into the
  188. * hardware channel, subsequent descriptors are either in
  189. * process or have not been submitted
  190. */
  191. if (seen_current)
  192. break;
  193. /* stop the search if we reach the current descriptor and the
  194. * channel is busy, or if it appears that the current descriptor
  195. * needs to be re-read (i.e. has been appended to)
  196. */
  197. if (iter->async_tx.phys == current_desc) {
  198. BUG_ON(seen_current++);
  199. if (busy || iop_desc_get_next_desc(iter))
  200. break;
  201. }
  202. /* detect the start of a group transaction */
  203. if (!slot_cnt && !slots_per_op) {
  204. slot_cnt = iter->slot_cnt;
  205. slots_per_op = iter->slots_per_op;
  206. if (slot_cnt <= slots_per_op) {
  207. slot_cnt = 0;
  208. slots_per_op = 0;
  209. }
  210. }
  211. if (slot_cnt) {
  212. pr_debug("\tgroup++\n");
  213. if (!grp_start)
  214. grp_start = iter;
  215. slot_cnt -= slots_per_op;
  216. }
  217. /* all the members of a group are complete */
  218. if (slots_per_op != 0 && slot_cnt == 0) {
  219. struct iop_adma_desc_slot *grp_iter, *_grp_iter;
  220. int end_of_chain = 0;
  221. pr_debug("\tgroup end\n");
  222. /* collect the total results */
  223. if (grp_start->xor_check_result) {
  224. u32 zero_sum_result = 0;
  225. slot_cnt = grp_start->slot_cnt;
  226. grp_iter = grp_start;
  227. list_for_each_entry_from(grp_iter,
  228. &iop_chan->chain, chain_node) {
  229. zero_sum_result |=
  230. iop_desc_get_zero_result(grp_iter);
  231. pr_debug("\titer%d result: %d\n",
  232. grp_iter->idx, zero_sum_result);
  233. slot_cnt -= slots_per_op;
  234. if (slot_cnt == 0)
  235. break;
  236. }
  237. pr_debug("\tgrp_start->xor_check_result: %p\n",
  238. grp_start->xor_check_result);
  239. *grp_start->xor_check_result = zero_sum_result;
  240. }
  241. /* clean up the group */
  242. slot_cnt = grp_start->slot_cnt;
  243. grp_iter = grp_start;
  244. list_for_each_entry_safe_from(grp_iter, _grp_iter,
  245. &iop_chan->chain, chain_node) {
  246. cookie = iop_adma_run_tx_complete_actions(
  247. grp_iter, iop_chan, cookie);
  248. slot_cnt -= slots_per_op;
  249. end_of_chain = iop_adma_clean_slot(grp_iter,
  250. iop_chan);
  251. if (slot_cnt == 0 || end_of_chain)
  252. break;
  253. }
  254. /* the group should be complete at this point */
  255. BUG_ON(slot_cnt);
  256. slots_per_op = 0;
  257. grp_start = NULL;
  258. if (end_of_chain)
  259. break;
  260. else
  261. continue;
  262. } else if (slots_per_op) /* wait for group completion */
  263. continue;
  264. /* write back zero sum results (single descriptor case) */
  265. if (iter->xor_check_result && iter->async_tx.cookie)
  266. *iter->xor_check_result =
  267. iop_desc_get_zero_result(iter);
  268. cookie = iop_adma_run_tx_complete_actions(
  269. iter, iop_chan, cookie);
  270. if (iop_adma_clean_slot(iter, iop_chan))
  271. break;
  272. }
  273. if (cookie > 0) {
  274. iop_chan->common.completed_cookie = cookie;
  275. pr_debug("\tcompleted cookie %d\n", cookie);
  276. }
  277. }
  278. static void
  279. iop_adma_slot_cleanup(struct iop_adma_chan *iop_chan)
  280. {
  281. spin_lock_bh(&iop_chan->lock);
  282. __iop_adma_slot_cleanup(iop_chan);
  283. spin_unlock_bh(&iop_chan->lock);
  284. }
  285. static void iop_adma_tasklet(unsigned long data)
  286. {
  287. struct iop_adma_chan *iop_chan = (struct iop_adma_chan *) data;
  288. /* lockdep will flag depedency submissions as potentially
  289. * recursive locking, this is not the case as a dependency
  290. * submission will never recurse a channels submit routine.
  291. * There are checks in async_tx.c to prevent this.
  292. */
  293. spin_lock_nested(&iop_chan->lock, SINGLE_DEPTH_NESTING);
  294. __iop_adma_slot_cleanup(iop_chan);
  295. spin_unlock(&iop_chan->lock);
  296. }
  297. static struct iop_adma_desc_slot *
  298. iop_adma_alloc_slots(struct iop_adma_chan *iop_chan, int num_slots,
  299. int slots_per_op)
  300. {
  301. struct iop_adma_desc_slot *iter, *_iter, *alloc_start = NULL;
  302. LIST_HEAD(chain);
  303. int slots_found, retry = 0;
  304. /* start search from the last allocated descrtiptor
  305. * if a contiguous allocation can not be found start searching
  306. * from the beginning of the list
  307. */
  308. retry:
  309. slots_found = 0;
  310. if (retry == 0)
  311. iter = iop_chan->last_used;
  312. else
  313. iter = list_entry(&iop_chan->all_slots,
  314. struct iop_adma_desc_slot,
  315. slot_node);
  316. list_for_each_entry_safe_continue(
  317. iter, _iter, &iop_chan->all_slots, slot_node) {
  318. prefetch(_iter);
  319. prefetch(&_iter->async_tx);
  320. if (iter->slots_per_op) {
  321. /* give up after finding the first busy slot
  322. * on the second pass through the list
  323. */
  324. if (retry)
  325. break;
  326. slots_found = 0;
  327. continue;
  328. }
  329. /* start the allocation if the slot is correctly aligned */
  330. if (!slots_found++) {
  331. if (iop_desc_is_aligned(iter, slots_per_op))
  332. alloc_start = iter;
  333. else {
  334. slots_found = 0;
  335. continue;
  336. }
  337. }
  338. if (slots_found == num_slots) {
  339. struct iop_adma_desc_slot *alloc_tail = NULL;
  340. struct iop_adma_desc_slot *last_used = NULL;
  341. iter = alloc_start;
  342. while (num_slots) {
  343. int i;
  344. dev_dbg(iop_chan->device->common.dev,
  345. "allocated slot: %d "
  346. "(desc %p phys: %#x) slots_per_op %d\n",
  347. iter->idx, iter->hw_desc,
  348. iter->async_tx.phys, slots_per_op);
  349. /* pre-ack all but the last descriptor */
  350. if (num_slots != slots_per_op)
  351. async_tx_ack(&iter->async_tx);
  352. list_add_tail(&iter->chain_node, &chain);
  353. alloc_tail = iter;
  354. iter->async_tx.cookie = 0;
  355. iter->slot_cnt = num_slots;
  356. iter->xor_check_result = NULL;
  357. for (i = 0; i < slots_per_op; i++) {
  358. iter->slots_per_op = slots_per_op - i;
  359. last_used = iter;
  360. iter = list_entry(iter->slot_node.next,
  361. struct iop_adma_desc_slot,
  362. slot_node);
  363. }
  364. num_slots -= slots_per_op;
  365. }
  366. alloc_tail->group_head = alloc_start;
  367. alloc_tail->async_tx.cookie = -EBUSY;
  368. list_splice(&chain, &alloc_tail->tx_list);
  369. iop_chan->last_used = last_used;
  370. iop_desc_clear_next_desc(alloc_start);
  371. iop_desc_clear_next_desc(alloc_tail);
  372. return alloc_tail;
  373. }
  374. }
  375. if (!retry++)
  376. goto retry;
  377. /* perform direct reclaim if the allocation fails */
  378. __iop_adma_slot_cleanup(iop_chan);
  379. return NULL;
  380. }
  381. static void iop_adma_check_threshold(struct iop_adma_chan *iop_chan)
  382. {
  383. dev_dbg(iop_chan->device->common.dev, "pending: %d\n",
  384. iop_chan->pending);
  385. if (iop_chan->pending >= IOP_ADMA_THRESHOLD) {
  386. iop_chan->pending = 0;
  387. iop_chan_append(iop_chan);
  388. }
  389. }
  390. static dma_cookie_t
  391. iop_adma_tx_submit(struct dma_async_tx_descriptor *tx)
  392. {
  393. struct iop_adma_desc_slot *sw_desc = tx_to_iop_adma_slot(tx);
  394. struct iop_adma_chan *iop_chan = to_iop_adma_chan(tx->chan);
  395. struct iop_adma_desc_slot *grp_start, *old_chain_tail;
  396. int slot_cnt;
  397. int slots_per_op;
  398. dma_cookie_t cookie;
  399. dma_addr_t next_dma;
  400. grp_start = sw_desc->group_head;
  401. slot_cnt = grp_start->slot_cnt;
  402. slots_per_op = grp_start->slots_per_op;
  403. spin_lock_bh(&iop_chan->lock);
  404. cookie = dma_cookie_assign(tx);
  405. old_chain_tail = list_entry(iop_chan->chain.prev,
  406. struct iop_adma_desc_slot, chain_node);
  407. list_splice_init(&sw_desc->tx_list,
  408. &old_chain_tail->chain_node);
  409. /* fix up the hardware chain */
  410. next_dma = grp_start->async_tx.phys;
  411. iop_desc_set_next_desc(old_chain_tail, next_dma);
  412. BUG_ON(iop_desc_get_next_desc(old_chain_tail) != next_dma); /* flush */
  413. /* check for pre-chained descriptors */
  414. iop_paranoia(iop_desc_get_next_desc(sw_desc));
  415. /* increment the pending count by the number of slots
  416. * memcpy operations have a 1:1 (slot:operation) relation
  417. * other operations are heavier and will pop the threshold
  418. * more often.
  419. */
  420. iop_chan->pending += slot_cnt;
  421. iop_adma_check_threshold(iop_chan);
  422. spin_unlock_bh(&iop_chan->lock);
  423. dev_dbg(iop_chan->device->common.dev, "%s cookie: %d slot: %d\n",
  424. __func__, sw_desc->async_tx.cookie, sw_desc->idx);
  425. return cookie;
  426. }
  427. static void iop_chan_start_null_memcpy(struct iop_adma_chan *iop_chan);
  428. static void iop_chan_start_null_xor(struct iop_adma_chan *iop_chan);
  429. /**
  430. * iop_adma_alloc_chan_resources - returns the number of allocated descriptors
  431. * @chan - allocate descriptor resources for this channel
  432. * @client - current client requesting the channel be ready for requests
  433. *
  434. * Note: We keep the slots for 1 operation on iop_chan->chain at all times. To
  435. * avoid deadlock, via async_xor, num_descs_in_pool must at a minimum be
  436. * greater than 2x the number slots needed to satisfy a device->max_xor
  437. * request.
  438. * */
  439. static int iop_adma_alloc_chan_resources(struct dma_chan *chan)
  440. {
  441. char *hw_desc;
  442. int idx;
  443. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  444. struct iop_adma_desc_slot *slot = NULL;
  445. int init = iop_chan->slots_allocated ? 0 : 1;
  446. struct iop_adma_platform_data *plat_data =
  447. iop_chan->device->pdev->dev.platform_data;
  448. int num_descs_in_pool = plat_data->pool_size/IOP_ADMA_SLOT_SIZE;
  449. /* Allocate descriptor slots */
  450. do {
  451. idx = iop_chan->slots_allocated;
  452. if (idx == num_descs_in_pool)
  453. break;
  454. slot = kzalloc(sizeof(*slot), GFP_KERNEL);
  455. if (!slot) {
  456. printk(KERN_INFO "IOP ADMA Channel only initialized"
  457. " %d descriptor slots", idx);
  458. break;
  459. }
  460. hw_desc = (char *) iop_chan->device->dma_desc_pool_virt;
  461. slot->hw_desc = (void *) &hw_desc[idx * IOP_ADMA_SLOT_SIZE];
  462. dma_async_tx_descriptor_init(&slot->async_tx, chan);
  463. slot->async_tx.tx_submit = iop_adma_tx_submit;
  464. INIT_LIST_HEAD(&slot->tx_list);
  465. INIT_LIST_HEAD(&slot->chain_node);
  466. INIT_LIST_HEAD(&slot->slot_node);
  467. hw_desc = (char *) iop_chan->device->dma_desc_pool;
  468. slot->async_tx.phys =
  469. (dma_addr_t) &hw_desc[idx * IOP_ADMA_SLOT_SIZE];
  470. slot->idx = idx;
  471. spin_lock_bh(&iop_chan->lock);
  472. iop_chan->slots_allocated++;
  473. list_add_tail(&slot->slot_node, &iop_chan->all_slots);
  474. spin_unlock_bh(&iop_chan->lock);
  475. } while (iop_chan->slots_allocated < num_descs_in_pool);
  476. if (idx && !iop_chan->last_used)
  477. iop_chan->last_used = list_entry(iop_chan->all_slots.next,
  478. struct iop_adma_desc_slot,
  479. slot_node);
  480. dev_dbg(iop_chan->device->common.dev,
  481. "allocated %d descriptor slots last_used: %p\n",
  482. iop_chan->slots_allocated, iop_chan->last_used);
  483. /* initialize the channel and the chain with a null operation */
  484. if (init) {
  485. if (dma_has_cap(DMA_MEMCPY,
  486. iop_chan->device->common.cap_mask))
  487. iop_chan_start_null_memcpy(iop_chan);
  488. else if (dma_has_cap(DMA_XOR,
  489. iop_chan->device->common.cap_mask))
  490. iop_chan_start_null_xor(iop_chan);
  491. else
  492. BUG();
  493. }
  494. return (idx > 0) ? idx : -ENOMEM;
  495. }
  496. static struct dma_async_tx_descriptor *
  497. iop_adma_prep_dma_interrupt(struct dma_chan *chan, unsigned long flags)
  498. {
  499. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  500. struct iop_adma_desc_slot *sw_desc, *grp_start;
  501. int slot_cnt, slots_per_op;
  502. dev_dbg(iop_chan->device->common.dev, "%s\n", __func__);
  503. spin_lock_bh(&iop_chan->lock);
  504. slot_cnt = iop_chan_interrupt_slot_count(&slots_per_op, iop_chan);
  505. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  506. if (sw_desc) {
  507. grp_start = sw_desc->group_head;
  508. iop_desc_init_interrupt(grp_start, iop_chan);
  509. grp_start->unmap_len = 0;
  510. sw_desc->async_tx.flags = flags;
  511. }
  512. spin_unlock_bh(&iop_chan->lock);
  513. return sw_desc ? &sw_desc->async_tx : NULL;
  514. }
  515. static struct dma_async_tx_descriptor *
  516. iop_adma_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dma_dest,
  517. dma_addr_t dma_src, size_t len, unsigned long flags)
  518. {
  519. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  520. struct iop_adma_desc_slot *sw_desc, *grp_start;
  521. int slot_cnt, slots_per_op;
  522. if (unlikely(!len))
  523. return NULL;
  524. BUG_ON(len > IOP_ADMA_MAX_BYTE_COUNT);
  525. dev_dbg(iop_chan->device->common.dev, "%s len: %u\n",
  526. __func__, len);
  527. spin_lock_bh(&iop_chan->lock);
  528. slot_cnt = iop_chan_memcpy_slot_count(len, &slots_per_op);
  529. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  530. if (sw_desc) {
  531. grp_start = sw_desc->group_head;
  532. iop_desc_init_memcpy(grp_start, flags);
  533. iop_desc_set_byte_count(grp_start, iop_chan, len);
  534. iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
  535. iop_desc_set_memcpy_src_addr(grp_start, dma_src);
  536. sw_desc->unmap_src_cnt = 1;
  537. sw_desc->unmap_len = len;
  538. sw_desc->async_tx.flags = flags;
  539. }
  540. spin_unlock_bh(&iop_chan->lock);
  541. return sw_desc ? &sw_desc->async_tx : NULL;
  542. }
  543. static struct dma_async_tx_descriptor *
  544. iop_adma_prep_dma_memset(struct dma_chan *chan, dma_addr_t dma_dest,
  545. int value, size_t len, unsigned long flags)
  546. {
  547. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  548. struct iop_adma_desc_slot *sw_desc, *grp_start;
  549. int slot_cnt, slots_per_op;
  550. if (unlikely(!len))
  551. return NULL;
  552. BUG_ON(len > IOP_ADMA_MAX_BYTE_COUNT);
  553. dev_dbg(iop_chan->device->common.dev, "%s len: %u\n",
  554. __func__, len);
  555. spin_lock_bh(&iop_chan->lock);
  556. slot_cnt = iop_chan_memset_slot_count(len, &slots_per_op);
  557. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  558. if (sw_desc) {
  559. grp_start = sw_desc->group_head;
  560. iop_desc_init_memset(grp_start, flags);
  561. iop_desc_set_byte_count(grp_start, iop_chan, len);
  562. iop_desc_set_block_fill_val(grp_start, value);
  563. iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
  564. sw_desc->unmap_src_cnt = 1;
  565. sw_desc->unmap_len = len;
  566. sw_desc->async_tx.flags = flags;
  567. }
  568. spin_unlock_bh(&iop_chan->lock);
  569. return sw_desc ? &sw_desc->async_tx : NULL;
  570. }
  571. static struct dma_async_tx_descriptor *
  572. iop_adma_prep_dma_xor(struct dma_chan *chan, dma_addr_t dma_dest,
  573. dma_addr_t *dma_src, unsigned int src_cnt, size_t len,
  574. unsigned long flags)
  575. {
  576. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  577. struct iop_adma_desc_slot *sw_desc, *grp_start;
  578. int slot_cnt, slots_per_op;
  579. if (unlikely(!len))
  580. return NULL;
  581. BUG_ON(len > IOP_ADMA_XOR_MAX_BYTE_COUNT);
  582. dev_dbg(iop_chan->device->common.dev,
  583. "%s src_cnt: %d len: %u flags: %lx\n",
  584. __func__, src_cnt, len, flags);
  585. spin_lock_bh(&iop_chan->lock);
  586. slot_cnt = iop_chan_xor_slot_count(len, src_cnt, &slots_per_op);
  587. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  588. if (sw_desc) {
  589. grp_start = sw_desc->group_head;
  590. iop_desc_init_xor(grp_start, src_cnt, flags);
  591. iop_desc_set_byte_count(grp_start, iop_chan, len);
  592. iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
  593. sw_desc->unmap_src_cnt = src_cnt;
  594. sw_desc->unmap_len = len;
  595. sw_desc->async_tx.flags = flags;
  596. while (src_cnt--)
  597. iop_desc_set_xor_src_addr(grp_start, src_cnt,
  598. dma_src[src_cnt]);
  599. }
  600. spin_unlock_bh(&iop_chan->lock);
  601. return sw_desc ? &sw_desc->async_tx : NULL;
  602. }
  603. static struct dma_async_tx_descriptor *
  604. iop_adma_prep_dma_xor_val(struct dma_chan *chan, dma_addr_t *dma_src,
  605. unsigned int src_cnt, size_t len, u32 *result,
  606. unsigned long flags)
  607. {
  608. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  609. struct iop_adma_desc_slot *sw_desc, *grp_start;
  610. int slot_cnt, slots_per_op;
  611. if (unlikely(!len))
  612. return NULL;
  613. dev_dbg(iop_chan->device->common.dev, "%s src_cnt: %d len: %u\n",
  614. __func__, src_cnt, len);
  615. spin_lock_bh(&iop_chan->lock);
  616. slot_cnt = iop_chan_zero_sum_slot_count(len, src_cnt, &slots_per_op);
  617. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  618. if (sw_desc) {
  619. grp_start = sw_desc->group_head;
  620. iop_desc_init_zero_sum(grp_start, src_cnt, flags);
  621. iop_desc_set_zero_sum_byte_count(grp_start, len);
  622. grp_start->xor_check_result = result;
  623. pr_debug("\t%s: grp_start->xor_check_result: %p\n",
  624. __func__, grp_start->xor_check_result);
  625. sw_desc->unmap_src_cnt = src_cnt;
  626. sw_desc->unmap_len = len;
  627. sw_desc->async_tx.flags = flags;
  628. while (src_cnt--)
  629. iop_desc_set_zero_sum_src_addr(grp_start, src_cnt,
  630. dma_src[src_cnt]);
  631. }
  632. spin_unlock_bh(&iop_chan->lock);
  633. return sw_desc ? &sw_desc->async_tx : NULL;
  634. }
  635. static struct dma_async_tx_descriptor *
  636. iop_adma_prep_dma_pq(struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
  637. unsigned int src_cnt, const unsigned char *scf, size_t len,
  638. unsigned long flags)
  639. {
  640. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  641. struct iop_adma_desc_slot *sw_desc, *g;
  642. int slot_cnt, slots_per_op;
  643. int continue_srcs;
  644. if (unlikely(!len))
  645. return NULL;
  646. BUG_ON(len > IOP_ADMA_XOR_MAX_BYTE_COUNT);
  647. dev_dbg(iop_chan->device->common.dev,
  648. "%s src_cnt: %d len: %u flags: %lx\n",
  649. __func__, src_cnt, len, flags);
  650. if (dmaf_p_disabled_continue(flags))
  651. continue_srcs = 1+src_cnt;
  652. else if (dmaf_continue(flags))
  653. continue_srcs = 3+src_cnt;
  654. else
  655. continue_srcs = 0+src_cnt;
  656. spin_lock_bh(&iop_chan->lock);
  657. slot_cnt = iop_chan_pq_slot_count(len, continue_srcs, &slots_per_op);
  658. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  659. if (sw_desc) {
  660. int i;
  661. g = sw_desc->group_head;
  662. iop_desc_set_byte_count(g, iop_chan, len);
  663. /* even if P is disabled its destination address (bits
  664. * [3:0]) must match Q. It is ok if P points to an
  665. * invalid address, it won't be written.
  666. */
  667. if (flags & DMA_PREP_PQ_DISABLE_P)
  668. dst[0] = dst[1] & 0x7;
  669. iop_desc_set_pq_addr(g, dst);
  670. sw_desc->unmap_src_cnt = src_cnt;
  671. sw_desc->unmap_len = len;
  672. sw_desc->async_tx.flags = flags;
  673. for (i = 0; i < src_cnt; i++)
  674. iop_desc_set_pq_src_addr(g, i, src[i], scf[i]);
  675. /* if we are continuing a previous operation factor in
  676. * the old p and q values, see the comment for dma_maxpq
  677. * in include/linux/dmaengine.h
  678. */
  679. if (dmaf_p_disabled_continue(flags))
  680. iop_desc_set_pq_src_addr(g, i++, dst[1], 1);
  681. else if (dmaf_continue(flags)) {
  682. iop_desc_set_pq_src_addr(g, i++, dst[0], 0);
  683. iop_desc_set_pq_src_addr(g, i++, dst[1], 1);
  684. iop_desc_set_pq_src_addr(g, i++, dst[1], 0);
  685. }
  686. iop_desc_init_pq(g, i, flags);
  687. }
  688. spin_unlock_bh(&iop_chan->lock);
  689. return sw_desc ? &sw_desc->async_tx : NULL;
  690. }
  691. static struct dma_async_tx_descriptor *
  692. iop_adma_prep_dma_pq_val(struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
  693. unsigned int src_cnt, const unsigned char *scf,
  694. size_t len, enum sum_check_flags *pqres,
  695. unsigned long flags)
  696. {
  697. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  698. struct iop_adma_desc_slot *sw_desc, *g;
  699. int slot_cnt, slots_per_op;
  700. if (unlikely(!len))
  701. return NULL;
  702. BUG_ON(len > IOP_ADMA_XOR_MAX_BYTE_COUNT);
  703. dev_dbg(iop_chan->device->common.dev, "%s src_cnt: %d len: %u\n",
  704. __func__, src_cnt, len);
  705. spin_lock_bh(&iop_chan->lock);
  706. slot_cnt = iop_chan_pq_zero_sum_slot_count(len, src_cnt + 2, &slots_per_op);
  707. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  708. if (sw_desc) {
  709. /* for validate operations p and q are tagged onto the
  710. * end of the source list
  711. */
  712. int pq_idx = src_cnt;
  713. g = sw_desc->group_head;
  714. iop_desc_init_pq_zero_sum(g, src_cnt+2, flags);
  715. iop_desc_set_pq_zero_sum_byte_count(g, len);
  716. g->pq_check_result = pqres;
  717. pr_debug("\t%s: g->pq_check_result: %p\n",
  718. __func__, g->pq_check_result);
  719. sw_desc->unmap_src_cnt = src_cnt+2;
  720. sw_desc->unmap_len = len;
  721. sw_desc->async_tx.flags = flags;
  722. while (src_cnt--)
  723. iop_desc_set_pq_zero_sum_src_addr(g, src_cnt,
  724. src[src_cnt],
  725. scf[src_cnt]);
  726. iop_desc_set_pq_zero_sum_addr(g, pq_idx, src);
  727. }
  728. spin_unlock_bh(&iop_chan->lock);
  729. return sw_desc ? &sw_desc->async_tx : NULL;
  730. }
  731. static void iop_adma_free_chan_resources(struct dma_chan *chan)
  732. {
  733. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  734. struct iop_adma_desc_slot *iter, *_iter;
  735. int in_use_descs = 0;
  736. iop_adma_slot_cleanup(iop_chan);
  737. spin_lock_bh(&iop_chan->lock);
  738. list_for_each_entry_safe(iter, _iter, &iop_chan->chain,
  739. chain_node) {
  740. in_use_descs++;
  741. list_del(&iter->chain_node);
  742. }
  743. list_for_each_entry_safe_reverse(
  744. iter, _iter, &iop_chan->all_slots, slot_node) {
  745. list_del(&iter->slot_node);
  746. kfree(iter);
  747. iop_chan->slots_allocated--;
  748. }
  749. iop_chan->last_used = NULL;
  750. dev_dbg(iop_chan->device->common.dev, "%s slots_allocated %d\n",
  751. __func__, iop_chan->slots_allocated);
  752. spin_unlock_bh(&iop_chan->lock);
  753. /* one is ok since we left it on there on purpose */
  754. if (in_use_descs > 1)
  755. printk(KERN_ERR "IOP: Freeing %d in use descriptors!\n",
  756. in_use_descs - 1);
  757. }
  758. /**
  759. * iop_adma_status - poll the status of an ADMA transaction
  760. * @chan: ADMA channel handle
  761. * @cookie: ADMA transaction identifier
  762. * @txstate: a holder for the current state of the channel or NULL
  763. */
  764. static enum dma_status iop_adma_status(struct dma_chan *chan,
  765. dma_cookie_t cookie,
  766. struct dma_tx_state *txstate)
  767. {
  768. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  769. ret = dma_cookie_status(chan, cookie, txstate);
  770. if (ret == DMA_SUCCESS)
  771. return ret;
  772. iop_adma_slot_cleanup(iop_chan);
  773. return dma_cookie_status(chan, cookie, txstate);
  774. }
  775. static irqreturn_t iop_adma_eot_handler(int irq, void *data)
  776. {
  777. struct iop_adma_chan *chan = data;
  778. dev_dbg(chan->device->common.dev, "%s\n", __func__);
  779. tasklet_schedule(&chan->irq_tasklet);
  780. iop_adma_device_clear_eot_status(chan);
  781. return IRQ_HANDLED;
  782. }
  783. static irqreturn_t iop_adma_eoc_handler(int irq, void *data)
  784. {
  785. struct iop_adma_chan *chan = data;
  786. dev_dbg(chan->device->common.dev, "%s\n", __func__);
  787. tasklet_schedule(&chan->irq_tasklet);
  788. iop_adma_device_clear_eoc_status(chan);
  789. return IRQ_HANDLED;
  790. }
  791. static irqreturn_t iop_adma_err_handler(int irq, void *data)
  792. {
  793. struct iop_adma_chan *chan = data;
  794. unsigned long status = iop_chan_get_status(chan);
  795. dev_printk(KERN_ERR, chan->device->common.dev,
  796. "error ( %s%s%s%s%s%s%s)\n",
  797. iop_is_err_int_parity(status, chan) ? "int_parity " : "",
  798. iop_is_err_mcu_abort(status, chan) ? "mcu_abort " : "",
  799. iop_is_err_int_tabort(status, chan) ? "int_tabort " : "",
  800. iop_is_err_int_mabort(status, chan) ? "int_mabort " : "",
  801. iop_is_err_pci_tabort(status, chan) ? "pci_tabort " : "",
  802. iop_is_err_pci_mabort(status, chan) ? "pci_mabort " : "",
  803. iop_is_err_split_tx(status, chan) ? "split_tx " : "");
  804. iop_adma_device_clear_err_status(chan);
  805. BUG();
  806. return IRQ_HANDLED;
  807. }
  808. static void iop_adma_issue_pending(struct dma_chan *chan)
  809. {
  810. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  811. if (iop_chan->pending) {
  812. iop_chan->pending = 0;
  813. iop_chan_append(iop_chan);
  814. }
  815. }
  816. /*
  817. * Perform a transaction to verify the HW works.
  818. */
  819. #define IOP_ADMA_TEST_SIZE 2000
  820. static int __devinit iop_adma_memcpy_self_test(struct iop_adma_device *device)
  821. {
  822. int i;
  823. void *src, *dest;
  824. dma_addr_t src_dma, dest_dma;
  825. struct dma_chan *dma_chan;
  826. dma_cookie_t cookie;
  827. struct dma_async_tx_descriptor *tx;
  828. int err = 0;
  829. struct iop_adma_chan *iop_chan;
  830. dev_dbg(device->common.dev, "%s\n", __func__);
  831. src = kmalloc(IOP_ADMA_TEST_SIZE, GFP_KERNEL);
  832. if (!src)
  833. return -ENOMEM;
  834. dest = kzalloc(IOP_ADMA_TEST_SIZE, GFP_KERNEL);
  835. if (!dest) {
  836. kfree(src);
  837. return -ENOMEM;
  838. }
  839. /* Fill in src buffer */
  840. for (i = 0; i < IOP_ADMA_TEST_SIZE; i++)
  841. ((u8 *) src)[i] = (u8)i;
  842. /* Start copy, using first DMA channel */
  843. dma_chan = container_of(device->common.channels.next,
  844. struct dma_chan,
  845. device_node);
  846. if (iop_adma_alloc_chan_resources(dma_chan) < 1) {
  847. err = -ENODEV;
  848. goto out;
  849. }
  850. dest_dma = dma_map_single(dma_chan->device->dev, dest,
  851. IOP_ADMA_TEST_SIZE, DMA_FROM_DEVICE);
  852. src_dma = dma_map_single(dma_chan->device->dev, src,
  853. IOP_ADMA_TEST_SIZE, DMA_TO_DEVICE);
  854. tx = iop_adma_prep_dma_memcpy(dma_chan, dest_dma, src_dma,
  855. IOP_ADMA_TEST_SIZE,
  856. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  857. cookie = iop_adma_tx_submit(tx);
  858. iop_adma_issue_pending(dma_chan);
  859. msleep(1);
  860. if (iop_adma_status(dma_chan, cookie, NULL) !=
  861. DMA_SUCCESS) {
  862. dev_printk(KERN_ERR, dma_chan->device->dev,
  863. "Self-test copy timed out, disabling\n");
  864. err = -ENODEV;
  865. goto free_resources;
  866. }
  867. iop_chan = to_iop_adma_chan(dma_chan);
  868. dma_sync_single_for_cpu(&iop_chan->device->pdev->dev, dest_dma,
  869. IOP_ADMA_TEST_SIZE, DMA_FROM_DEVICE);
  870. if (memcmp(src, dest, IOP_ADMA_TEST_SIZE)) {
  871. dev_printk(KERN_ERR, dma_chan->device->dev,
  872. "Self-test copy failed compare, disabling\n");
  873. err = -ENODEV;
  874. goto free_resources;
  875. }
  876. free_resources:
  877. iop_adma_free_chan_resources(dma_chan);
  878. out:
  879. kfree(src);
  880. kfree(dest);
  881. return err;
  882. }
  883. #define IOP_ADMA_NUM_SRC_TEST 4 /* must be <= 15 */
  884. static int __devinit
  885. iop_adma_xor_val_self_test(struct iop_adma_device *device)
  886. {
  887. int i, src_idx;
  888. struct page *dest;
  889. struct page *xor_srcs[IOP_ADMA_NUM_SRC_TEST];
  890. struct page *zero_sum_srcs[IOP_ADMA_NUM_SRC_TEST + 1];
  891. dma_addr_t dma_srcs[IOP_ADMA_NUM_SRC_TEST + 1];
  892. dma_addr_t dma_addr, dest_dma;
  893. struct dma_async_tx_descriptor *tx;
  894. struct dma_chan *dma_chan;
  895. dma_cookie_t cookie;
  896. u8 cmp_byte = 0;
  897. u32 cmp_word;
  898. u32 zero_sum_result;
  899. int err = 0;
  900. struct iop_adma_chan *iop_chan;
  901. dev_dbg(device->common.dev, "%s\n", __func__);
  902. for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++) {
  903. xor_srcs[src_idx] = alloc_page(GFP_KERNEL);
  904. if (!xor_srcs[src_idx]) {
  905. while (src_idx--)
  906. __free_page(xor_srcs[src_idx]);
  907. return -ENOMEM;
  908. }
  909. }
  910. dest = alloc_page(GFP_KERNEL);
  911. if (!dest) {
  912. while (src_idx--)
  913. __free_page(xor_srcs[src_idx]);
  914. return -ENOMEM;
  915. }
  916. /* Fill in src buffers */
  917. for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++) {
  918. u8 *ptr = page_address(xor_srcs[src_idx]);
  919. for (i = 0; i < PAGE_SIZE; i++)
  920. ptr[i] = (1 << src_idx);
  921. }
  922. for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++)
  923. cmp_byte ^= (u8) (1 << src_idx);
  924. cmp_word = (cmp_byte << 24) | (cmp_byte << 16) |
  925. (cmp_byte << 8) | cmp_byte;
  926. memset(page_address(dest), 0, PAGE_SIZE);
  927. dma_chan = container_of(device->common.channels.next,
  928. struct dma_chan,
  929. device_node);
  930. if (iop_adma_alloc_chan_resources(dma_chan) < 1) {
  931. err = -ENODEV;
  932. goto out;
  933. }
  934. /* test xor */
  935. dest_dma = dma_map_page(dma_chan->device->dev, dest, 0,
  936. PAGE_SIZE, DMA_FROM_DEVICE);
  937. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++)
  938. dma_srcs[i] = dma_map_page(dma_chan->device->dev, xor_srcs[i],
  939. 0, PAGE_SIZE, DMA_TO_DEVICE);
  940. tx = iop_adma_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
  941. IOP_ADMA_NUM_SRC_TEST, PAGE_SIZE,
  942. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  943. cookie = iop_adma_tx_submit(tx);
  944. iop_adma_issue_pending(dma_chan);
  945. msleep(8);
  946. if (iop_adma_status(dma_chan, cookie, NULL) !=
  947. DMA_SUCCESS) {
  948. dev_printk(KERN_ERR, dma_chan->device->dev,
  949. "Self-test xor timed out, disabling\n");
  950. err = -ENODEV;
  951. goto free_resources;
  952. }
  953. iop_chan = to_iop_adma_chan(dma_chan);
  954. dma_sync_single_for_cpu(&iop_chan->device->pdev->dev, dest_dma,
  955. PAGE_SIZE, DMA_FROM_DEVICE);
  956. for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) {
  957. u32 *ptr = page_address(dest);
  958. if (ptr[i] != cmp_word) {
  959. dev_printk(KERN_ERR, dma_chan->device->dev,
  960. "Self-test xor failed compare, disabling\n");
  961. err = -ENODEV;
  962. goto free_resources;
  963. }
  964. }
  965. dma_sync_single_for_device(&iop_chan->device->pdev->dev, dest_dma,
  966. PAGE_SIZE, DMA_TO_DEVICE);
  967. /* skip zero sum if the capability is not present */
  968. if (!dma_has_cap(DMA_XOR_VAL, dma_chan->device->cap_mask))
  969. goto free_resources;
  970. /* zero sum the sources with the destintation page */
  971. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++)
  972. zero_sum_srcs[i] = xor_srcs[i];
  973. zero_sum_srcs[i] = dest;
  974. zero_sum_result = 1;
  975. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++)
  976. dma_srcs[i] = dma_map_page(dma_chan->device->dev,
  977. zero_sum_srcs[i], 0, PAGE_SIZE,
  978. DMA_TO_DEVICE);
  979. tx = iop_adma_prep_dma_xor_val(dma_chan, dma_srcs,
  980. IOP_ADMA_NUM_SRC_TEST + 1, PAGE_SIZE,
  981. &zero_sum_result,
  982. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  983. cookie = iop_adma_tx_submit(tx);
  984. iop_adma_issue_pending(dma_chan);
  985. msleep(8);
  986. if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  987. dev_printk(KERN_ERR, dma_chan->device->dev,
  988. "Self-test zero sum timed out, disabling\n");
  989. err = -ENODEV;
  990. goto free_resources;
  991. }
  992. if (zero_sum_result != 0) {
  993. dev_printk(KERN_ERR, dma_chan->device->dev,
  994. "Self-test zero sum failed compare, disabling\n");
  995. err = -ENODEV;
  996. goto free_resources;
  997. }
  998. /* test memset */
  999. dma_addr = dma_map_page(dma_chan->device->dev, dest, 0,
  1000. PAGE_SIZE, DMA_FROM_DEVICE);
  1001. tx = iop_adma_prep_dma_memset(dma_chan, dma_addr, 0, PAGE_SIZE,
  1002. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  1003. cookie = iop_adma_tx_submit(tx);
  1004. iop_adma_issue_pending(dma_chan);
  1005. msleep(8);
  1006. if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  1007. dev_printk(KERN_ERR, dma_chan->device->dev,
  1008. "Self-test memset timed out, disabling\n");
  1009. err = -ENODEV;
  1010. goto free_resources;
  1011. }
  1012. for (i = 0; i < PAGE_SIZE/sizeof(u32); i++) {
  1013. u32 *ptr = page_address(dest);
  1014. if (ptr[i]) {
  1015. dev_printk(KERN_ERR, dma_chan->device->dev,
  1016. "Self-test memset failed compare, disabling\n");
  1017. err = -ENODEV;
  1018. goto free_resources;
  1019. }
  1020. }
  1021. /* test for non-zero parity sum */
  1022. zero_sum_result = 0;
  1023. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++)
  1024. dma_srcs[i] = dma_map_page(dma_chan->device->dev,
  1025. zero_sum_srcs[i], 0, PAGE_SIZE,
  1026. DMA_TO_DEVICE);
  1027. tx = iop_adma_prep_dma_xor_val(dma_chan, dma_srcs,
  1028. IOP_ADMA_NUM_SRC_TEST + 1, PAGE_SIZE,
  1029. &zero_sum_result,
  1030. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  1031. cookie = iop_adma_tx_submit(tx);
  1032. iop_adma_issue_pending(dma_chan);
  1033. msleep(8);
  1034. if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  1035. dev_printk(KERN_ERR, dma_chan->device->dev,
  1036. "Self-test non-zero sum timed out, disabling\n");
  1037. err = -ENODEV;
  1038. goto free_resources;
  1039. }
  1040. if (zero_sum_result != 1) {
  1041. dev_printk(KERN_ERR, dma_chan->device->dev,
  1042. "Self-test non-zero sum failed compare, disabling\n");
  1043. err = -ENODEV;
  1044. goto free_resources;
  1045. }
  1046. free_resources:
  1047. iop_adma_free_chan_resources(dma_chan);
  1048. out:
  1049. src_idx = IOP_ADMA_NUM_SRC_TEST;
  1050. while (src_idx--)
  1051. __free_page(xor_srcs[src_idx]);
  1052. __free_page(dest);
  1053. return err;
  1054. }
  1055. #ifdef CONFIG_RAID6_PQ
  1056. static int __devinit
  1057. iop_adma_pq_zero_sum_self_test(struct iop_adma_device *device)
  1058. {
  1059. /* combined sources, software pq results, and extra hw pq results */
  1060. struct page *pq[IOP_ADMA_NUM_SRC_TEST+2+2];
  1061. /* ptr to the extra hw pq buffers defined above */
  1062. struct page **pq_hw = &pq[IOP_ADMA_NUM_SRC_TEST+2];
  1063. /* address conversion buffers (dma_map / page_address) */
  1064. void *pq_sw[IOP_ADMA_NUM_SRC_TEST+2];
  1065. dma_addr_t pq_src[IOP_ADMA_NUM_SRC_TEST];
  1066. dma_addr_t pq_dest[2];
  1067. int i;
  1068. struct dma_async_tx_descriptor *tx;
  1069. struct dma_chan *dma_chan;
  1070. dma_cookie_t cookie;
  1071. u32 zero_sum_result;
  1072. int err = 0;
  1073. struct device *dev;
  1074. dev_dbg(device->common.dev, "%s\n", __func__);
  1075. for (i = 0; i < ARRAY_SIZE(pq); i++) {
  1076. pq[i] = alloc_page(GFP_KERNEL);
  1077. if (!pq[i]) {
  1078. while (i--)
  1079. __free_page(pq[i]);
  1080. return -ENOMEM;
  1081. }
  1082. }
  1083. /* Fill in src buffers */
  1084. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++) {
  1085. pq_sw[i] = page_address(pq[i]);
  1086. memset(pq_sw[i], 0x11111111 * (1<<i), PAGE_SIZE);
  1087. }
  1088. pq_sw[i] = page_address(pq[i]);
  1089. pq_sw[i+1] = page_address(pq[i+1]);
  1090. dma_chan = container_of(device->common.channels.next,
  1091. struct dma_chan,
  1092. device_node);
  1093. if (iop_adma_alloc_chan_resources(dma_chan) < 1) {
  1094. err = -ENODEV;
  1095. goto out;
  1096. }
  1097. dev = dma_chan->device->dev;
  1098. /* initialize the dests */
  1099. memset(page_address(pq_hw[0]), 0 , PAGE_SIZE);
  1100. memset(page_address(pq_hw[1]), 0 , PAGE_SIZE);
  1101. /* test pq */
  1102. pq_dest[0] = dma_map_page(dev, pq_hw[0], 0, PAGE_SIZE, DMA_FROM_DEVICE);
  1103. pq_dest[1] = dma_map_page(dev, pq_hw[1], 0, PAGE_SIZE, DMA_FROM_DEVICE);
  1104. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++)
  1105. pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE,
  1106. DMA_TO_DEVICE);
  1107. tx = iop_adma_prep_dma_pq(dma_chan, pq_dest, pq_src,
  1108. IOP_ADMA_NUM_SRC_TEST, (u8 *)raid6_gfexp,
  1109. PAGE_SIZE,
  1110. DMA_PREP_INTERRUPT |
  1111. DMA_CTRL_ACK);
  1112. cookie = iop_adma_tx_submit(tx);
  1113. iop_adma_issue_pending(dma_chan);
  1114. msleep(8);
  1115. if (iop_adma_status(dma_chan, cookie, NULL) !=
  1116. DMA_SUCCESS) {
  1117. dev_err(dev, "Self-test pq timed out, disabling\n");
  1118. err = -ENODEV;
  1119. goto free_resources;
  1120. }
  1121. raid6_call.gen_syndrome(IOP_ADMA_NUM_SRC_TEST+2, PAGE_SIZE, pq_sw);
  1122. if (memcmp(pq_sw[IOP_ADMA_NUM_SRC_TEST],
  1123. page_address(pq_hw[0]), PAGE_SIZE) != 0) {
  1124. dev_err(dev, "Self-test p failed compare, disabling\n");
  1125. err = -ENODEV;
  1126. goto free_resources;
  1127. }
  1128. if (memcmp(pq_sw[IOP_ADMA_NUM_SRC_TEST+1],
  1129. page_address(pq_hw[1]), PAGE_SIZE) != 0) {
  1130. dev_err(dev, "Self-test q failed compare, disabling\n");
  1131. err = -ENODEV;
  1132. goto free_resources;
  1133. }
  1134. /* test correct zero sum using the software generated pq values */
  1135. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 2; i++)
  1136. pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE,
  1137. DMA_TO_DEVICE);
  1138. zero_sum_result = ~0;
  1139. tx = iop_adma_prep_dma_pq_val(dma_chan, &pq_src[IOP_ADMA_NUM_SRC_TEST],
  1140. pq_src, IOP_ADMA_NUM_SRC_TEST,
  1141. raid6_gfexp, PAGE_SIZE, &zero_sum_result,
  1142. DMA_PREP_INTERRUPT|DMA_CTRL_ACK);
  1143. cookie = iop_adma_tx_submit(tx);
  1144. iop_adma_issue_pending(dma_chan);
  1145. msleep(8);
  1146. if (iop_adma_status(dma_chan, cookie, NULL) !=
  1147. DMA_SUCCESS) {
  1148. dev_err(dev, "Self-test pq-zero-sum timed out, disabling\n");
  1149. err = -ENODEV;
  1150. goto free_resources;
  1151. }
  1152. if (zero_sum_result != 0) {
  1153. dev_err(dev, "Self-test pq-zero-sum failed to validate: %x\n",
  1154. zero_sum_result);
  1155. err = -ENODEV;
  1156. goto free_resources;
  1157. }
  1158. /* test incorrect zero sum */
  1159. i = IOP_ADMA_NUM_SRC_TEST;
  1160. memset(pq_sw[i] + 100, 0, 100);
  1161. memset(pq_sw[i+1] + 200, 0, 200);
  1162. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 2; i++)
  1163. pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE,
  1164. DMA_TO_DEVICE);
  1165. zero_sum_result = 0;
  1166. tx = iop_adma_prep_dma_pq_val(dma_chan, &pq_src[IOP_ADMA_NUM_SRC_TEST],
  1167. pq_src, IOP_ADMA_NUM_SRC_TEST,
  1168. raid6_gfexp, PAGE_SIZE, &zero_sum_result,
  1169. DMA_PREP_INTERRUPT|DMA_CTRL_ACK);
  1170. cookie = iop_adma_tx_submit(tx);
  1171. iop_adma_issue_pending(dma_chan);
  1172. msleep(8);
  1173. if (iop_adma_status(dma_chan, cookie, NULL) !=
  1174. DMA_SUCCESS) {
  1175. dev_err(dev, "Self-test !pq-zero-sum timed out, disabling\n");
  1176. err = -ENODEV;
  1177. goto free_resources;
  1178. }
  1179. if (zero_sum_result != (SUM_CHECK_P_RESULT | SUM_CHECK_Q_RESULT)) {
  1180. dev_err(dev, "Self-test !pq-zero-sum failed to validate: %x\n",
  1181. zero_sum_result);
  1182. err = -ENODEV;
  1183. goto free_resources;
  1184. }
  1185. free_resources:
  1186. iop_adma_free_chan_resources(dma_chan);
  1187. out:
  1188. i = ARRAY_SIZE(pq);
  1189. while (i--)
  1190. __free_page(pq[i]);
  1191. return err;
  1192. }
  1193. #endif
  1194. static int __devexit iop_adma_remove(struct platform_device *dev)
  1195. {
  1196. struct iop_adma_device *device = platform_get_drvdata(dev);
  1197. struct dma_chan *chan, *_chan;
  1198. struct iop_adma_chan *iop_chan;
  1199. struct iop_adma_platform_data *plat_data = dev->dev.platform_data;
  1200. dma_async_device_unregister(&device->common);
  1201. dma_free_coherent(&dev->dev, plat_data->pool_size,
  1202. device->dma_desc_pool_virt, device->dma_desc_pool);
  1203. list_for_each_entry_safe(chan, _chan, &device->common.channels,
  1204. device_node) {
  1205. iop_chan = to_iop_adma_chan(chan);
  1206. list_del(&chan->device_node);
  1207. kfree(iop_chan);
  1208. }
  1209. kfree(device);
  1210. return 0;
  1211. }
  1212. static int __devinit iop_adma_probe(struct platform_device *pdev)
  1213. {
  1214. struct resource *res;
  1215. int ret = 0, i;
  1216. struct iop_adma_device *adev;
  1217. struct iop_adma_chan *iop_chan;
  1218. struct dma_device *dma_dev;
  1219. struct iop_adma_platform_data *plat_data = pdev->dev.platform_data;
  1220. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1221. if (!res)
  1222. return -ENODEV;
  1223. if (!devm_request_mem_region(&pdev->dev, res->start,
  1224. resource_size(res), pdev->name))
  1225. return -EBUSY;
  1226. adev = kzalloc(sizeof(*adev), GFP_KERNEL);
  1227. if (!adev)
  1228. return -ENOMEM;
  1229. dma_dev = &adev->common;
  1230. /* allocate coherent memory for hardware descriptors
  1231. * note: writecombine gives slightly better performance, but
  1232. * requires that we explicitly flush the writes
  1233. */
  1234. if ((adev->dma_desc_pool_virt = dma_alloc_writecombine(&pdev->dev,
  1235. plat_data->pool_size,
  1236. &adev->dma_desc_pool,
  1237. GFP_KERNEL)) == NULL) {
  1238. ret = -ENOMEM;
  1239. goto err_free_adev;
  1240. }
  1241. dev_dbg(&pdev->dev, "%s: allocted descriptor pool virt %p phys %p\n",
  1242. __func__, adev->dma_desc_pool_virt,
  1243. (void *) adev->dma_desc_pool);
  1244. adev->id = plat_data->hw_id;
  1245. /* discover transaction capabilites from the platform data */
  1246. dma_dev->cap_mask = plat_data->cap_mask;
  1247. adev->pdev = pdev;
  1248. platform_set_drvdata(pdev, adev);
  1249. INIT_LIST_HEAD(&dma_dev->channels);
  1250. /* set base routines */
  1251. dma_dev->device_alloc_chan_resources = iop_adma_alloc_chan_resources;
  1252. dma_dev->device_free_chan_resources = iop_adma_free_chan_resources;
  1253. dma_dev->device_tx_status = iop_adma_status;
  1254. dma_dev->device_issue_pending = iop_adma_issue_pending;
  1255. dma_dev->dev = &pdev->dev;
  1256. /* set prep routines based on capability */
  1257. if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask))
  1258. dma_dev->device_prep_dma_memcpy = iop_adma_prep_dma_memcpy;
  1259. if (dma_has_cap(DMA_MEMSET, dma_dev->cap_mask))
  1260. dma_dev->device_prep_dma_memset = iop_adma_prep_dma_memset;
  1261. if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
  1262. dma_dev->max_xor = iop_adma_get_max_xor();
  1263. dma_dev->device_prep_dma_xor = iop_adma_prep_dma_xor;
  1264. }
  1265. if (dma_has_cap(DMA_XOR_VAL, dma_dev->cap_mask))
  1266. dma_dev->device_prep_dma_xor_val =
  1267. iop_adma_prep_dma_xor_val;
  1268. if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
  1269. dma_set_maxpq(dma_dev, iop_adma_get_max_pq(), 0);
  1270. dma_dev->device_prep_dma_pq = iop_adma_prep_dma_pq;
  1271. }
  1272. if (dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask))
  1273. dma_dev->device_prep_dma_pq_val =
  1274. iop_adma_prep_dma_pq_val;
  1275. if (dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask))
  1276. dma_dev->device_prep_dma_interrupt =
  1277. iop_adma_prep_dma_interrupt;
  1278. iop_chan = kzalloc(sizeof(*iop_chan), GFP_KERNEL);
  1279. if (!iop_chan) {
  1280. ret = -ENOMEM;
  1281. goto err_free_dma;
  1282. }
  1283. iop_chan->device = adev;
  1284. iop_chan->mmr_base = devm_ioremap(&pdev->dev, res->start,
  1285. resource_size(res));
  1286. if (!iop_chan->mmr_base) {
  1287. ret = -ENOMEM;
  1288. goto err_free_iop_chan;
  1289. }
  1290. tasklet_init(&iop_chan->irq_tasklet, iop_adma_tasklet, (unsigned long)
  1291. iop_chan);
  1292. /* clear errors before enabling interrupts */
  1293. iop_adma_device_clear_err_status(iop_chan);
  1294. for (i = 0; i < 3; i++) {
  1295. irq_handler_t handler[] = { iop_adma_eot_handler,
  1296. iop_adma_eoc_handler,
  1297. iop_adma_err_handler };
  1298. int irq = platform_get_irq(pdev, i);
  1299. if (irq < 0) {
  1300. ret = -ENXIO;
  1301. goto err_free_iop_chan;
  1302. } else {
  1303. ret = devm_request_irq(&pdev->dev, irq,
  1304. handler[i], 0, pdev->name, iop_chan);
  1305. if (ret)
  1306. goto err_free_iop_chan;
  1307. }
  1308. }
  1309. spin_lock_init(&iop_chan->lock);
  1310. INIT_LIST_HEAD(&iop_chan->chain);
  1311. INIT_LIST_HEAD(&iop_chan->all_slots);
  1312. iop_chan->common.device = dma_dev;
  1313. list_add_tail(&iop_chan->common.device_node, &dma_dev->channels);
  1314. if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
  1315. ret = iop_adma_memcpy_self_test(adev);
  1316. dev_dbg(&pdev->dev, "memcpy self test returned %d\n", ret);
  1317. if (ret)
  1318. goto err_free_iop_chan;
  1319. }
  1320. if (dma_has_cap(DMA_XOR, dma_dev->cap_mask) ||
  1321. dma_has_cap(DMA_MEMSET, dma_dev->cap_mask)) {
  1322. ret = iop_adma_xor_val_self_test(adev);
  1323. dev_dbg(&pdev->dev, "xor self test returned %d\n", ret);
  1324. if (ret)
  1325. goto err_free_iop_chan;
  1326. }
  1327. if (dma_has_cap(DMA_PQ, dma_dev->cap_mask) &&
  1328. dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask)) {
  1329. #ifdef CONFIG_RAID6_PQ
  1330. ret = iop_adma_pq_zero_sum_self_test(adev);
  1331. dev_dbg(&pdev->dev, "pq self test returned %d\n", ret);
  1332. #else
  1333. /* can not test raid6, so do not publish capability */
  1334. dma_cap_clear(DMA_PQ, dma_dev->cap_mask);
  1335. dma_cap_clear(DMA_PQ_VAL, dma_dev->cap_mask);
  1336. ret = 0;
  1337. #endif
  1338. if (ret)
  1339. goto err_free_iop_chan;
  1340. }
  1341. dev_printk(KERN_INFO, &pdev->dev, "Intel(R) IOP: "
  1342. "( %s%s%s%s%s%s%s)\n",
  1343. dma_has_cap(DMA_PQ, dma_dev->cap_mask) ? "pq " : "",
  1344. dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask) ? "pq_val " : "",
  1345. dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "",
  1346. dma_has_cap(DMA_XOR_VAL, dma_dev->cap_mask) ? "xor_val " : "",
  1347. dma_has_cap(DMA_MEMSET, dma_dev->cap_mask) ? "fill " : "",
  1348. dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "",
  1349. dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : "");
  1350. dma_async_device_register(dma_dev);
  1351. goto out;
  1352. err_free_iop_chan:
  1353. kfree(iop_chan);
  1354. err_free_dma:
  1355. dma_free_coherent(&adev->pdev->dev, plat_data->pool_size,
  1356. adev->dma_desc_pool_virt, adev->dma_desc_pool);
  1357. err_free_adev:
  1358. kfree(adev);
  1359. out:
  1360. return ret;
  1361. }
  1362. static void iop_chan_start_null_memcpy(struct iop_adma_chan *iop_chan)
  1363. {
  1364. struct iop_adma_desc_slot *sw_desc, *grp_start;
  1365. dma_cookie_t cookie;
  1366. int slot_cnt, slots_per_op;
  1367. dev_dbg(iop_chan->device->common.dev, "%s\n", __func__);
  1368. spin_lock_bh(&iop_chan->lock);
  1369. slot_cnt = iop_chan_memcpy_slot_count(0, &slots_per_op);
  1370. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  1371. if (sw_desc) {
  1372. grp_start = sw_desc->group_head;
  1373. list_splice_init(&sw_desc->tx_list, &iop_chan->chain);
  1374. async_tx_ack(&sw_desc->async_tx);
  1375. iop_desc_init_memcpy(grp_start, 0);
  1376. iop_desc_set_byte_count(grp_start, iop_chan, 0);
  1377. iop_desc_set_dest_addr(grp_start, iop_chan, 0);
  1378. iop_desc_set_memcpy_src_addr(grp_start, 0);
  1379. cookie = iop_chan->common.cookie;
  1380. cookie++;
  1381. if (cookie <= 1)
  1382. cookie = 2;
  1383. /* initialize the completed cookie to be less than
  1384. * the most recently used cookie
  1385. */
  1386. iop_chan->common.completed_cookie = cookie - 1;
  1387. iop_chan->common.cookie = sw_desc->async_tx.cookie = cookie;
  1388. /* channel should not be busy */
  1389. BUG_ON(iop_chan_is_busy(iop_chan));
  1390. /* clear any prior error-status bits */
  1391. iop_adma_device_clear_err_status(iop_chan);
  1392. /* disable operation */
  1393. iop_chan_disable(iop_chan);
  1394. /* set the descriptor address */
  1395. iop_chan_set_next_descriptor(iop_chan, sw_desc->async_tx.phys);
  1396. /* 1/ don't add pre-chained descriptors
  1397. * 2/ dummy read to flush next_desc write
  1398. */
  1399. BUG_ON(iop_desc_get_next_desc(sw_desc));
  1400. /* run the descriptor */
  1401. iop_chan_enable(iop_chan);
  1402. } else
  1403. dev_printk(KERN_ERR, iop_chan->device->common.dev,
  1404. "failed to allocate null descriptor\n");
  1405. spin_unlock_bh(&iop_chan->lock);
  1406. }
  1407. static void iop_chan_start_null_xor(struct iop_adma_chan *iop_chan)
  1408. {
  1409. struct iop_adma_desc_slot *sw_desc, *grp_start;
  1410. dma_cookie_t cookie;
  1411. int slot_cnt, slots_per_op;
  1412. dev_dbg(iop_chan->device->common.dev, "%s\n", __func__);
  1413. spin_lock_bh(&iop_chan->lock);
  1414. slot_cnt = iop_chan_xor_slot_count(0, 2, &slots_per_op);
  1415. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  1416. if (sw_desc) {
  1417. grp_start = sw_desc->group_head;
  1418. list_splice_init(&sw_desc->tx_list, &iop_chan->chain);
  1419. async_tx_ack(&sw_desc->async_tx);
  1420. iop_desc_init_null_xor(grp_start, 2, 0);
  1421. iop_desc_set_byte_count(grp_start, iop_chan, 0);
  1422. iop_desc_set_dest_addr(grp_start, iop_chan, 0);
  1423. iop_desc_set_xor_src_addr(grp_start, 0, 0);
  1424. iop_desc_set_xor_src_addr(grp_start, 1, 0);
  1425. cookie = iop_chan->common.cookie;
  1426. cookie++;
  1427. if (cookie <= 1)
  1428. cookie = 2;
  1429. /* initialize the completed cookie to be less than
  1430. * the most recently used cookie
  1431. */
  1432. iop_chan->common.completed_cookie = cookie - 1;
  1433. iop_chan->common.cookie = sw_desc->async_tx.cookie = cookie;
  1434. /* channel should not be busy */
  1435. BUG_ON(iop_chan_is_busy(iop_chan));
  1436. /* clear any prior error-status bits */
  1437. iop_adma_device_clear_err_status(iop_chan);
  1438. /* disable operation */
  1439. iop_chan_disable(iop_chan);
  1440. /* set the descriptor address */
  1441. iop_chan_set_next_descriptor(iop_chan, sw_desc->async_tx.phys);
  1442. /* 1/ don't add pre-chained descriptors
  1443. * 2/ dummy read to flush next_desc write
  1444. */
  1445. BUG_ON(iop_desc_get_next_desc(sw_desc));
  1446. /* run the descriptor */
  1447. iop_chan_enable(iop_chan);
  1448. } else
  1449. dev_printk(KERN_ERR, iop_chan->device->common.dev,
  1450. "failed to allocate null descriptor\n");
  1451. spin_unlock_bh(&iop_chan->lock);
  1452. }
  1453. static struct platform_driver iop_adma_driver = {
  1454. .probe = iop_adma_probe,
  1455. .remove = __devexit_p(iop_adma_remove),
  1456. .driver = {
  1457. .owner = THIS_MODULE,
  1458. .name = "iop-adma",
  1459. },
  1460. };
  1461. module_platform_driver(iop_adma_driver);
  1462. MODULE_AUTHOR("Intel Corporation");
  1463. MODULE_DESCRIPTION("IOP ADMA Engine Driver");
  1464. MODULE_LICENSE("GPL");
  1465. MODULE_ALIAS("platform:iop-adma");