iop-adma.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  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. int ret;
  770. ret = dma_cookie_status(chan, cookie, txstate);
  771. if (ret == DMA_SUCCESS)
  772. return ret;
  773. iop_adma_slot_cleanup(iop_chan);
  774. return dma_cookie_status(chan, cookie, txstate);
  775. }
  776. static irqreturn_t iop_adma_eot_handler(int irq, void *data)
  777. {
  778. struct iop_adma_chan *chan = data;
  779. dev_dbg(chan->device->common.dev, "%s\n", __func__);
  780. tasklet_schedule(&chan->irq_tasklet);
  781. iop_adma_device_clear_eot_status(chan);
  782. return IRQ_HANDLED;
  783. }
  784. static irqreturn_t iop_adma_eoc_handler(int irq, void *data)
  785. {
  786. struct iop_adma_chan *chan = data;
  787. dev_dbg(chan->device->common.dev, "%s\n", __func__);
  788. tasklet_schedule(&chan->irq_tasklet);
  789. iop_adma_device_clear_eoc_status(chan);
  790. return IRQ_HANDLED;
  791. }
  792. static irqreturn_t iop_adma_err_handler(int irq, void *data)
  793. {
  794. struct iop_adma_chan *chan = data;
  795. unsigned long status = iop_chan_get_status(chan);
  796. dev_printk(KERN_ERR, chan->device->common.dev,
  797. "error ( %s%s%s%s%s%s%s)\n",
  798. iop_is_err_int_parity(status, chan) ? "int_parity " : "",
  799. iop_is_err_mcu_abort(status, chan) ? "mcu_abort " : "",
  800. iop_is_err_int_tabort(status, chan) ? "int_tabort " : "",
  801. iop_is_err_int_mabort(status, chan) ? "int_mabort " : "",
  802. iop_is_err_pci_tabort(status, chan) ? "pci_tabort " : "",
  803. iop_is_err_pci_mabort(status, chan) ? "pci_mabort " : "",
  804. iop_is_err_split_tx(status, chan) ? "split_tx " : "");
  805. iop_adma_device_clear_err_status(chan);
  806. BUG();
  807. return IRQ_HANDLED;
  808. }
  809. static void iop_adma_issue_pending(struct dma_chan *chan)
  810. {
  811. struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
  812. if (iop_chan->pending) {
  813. iop_chan->pending = 0;
  814. iop_chan_append(iop_chan);
  815. }
  816. }
  817. /*
  818. * Perform a transaction to verify the HW works.
  819. */
  820. #define IOP_ADMA_TEST_SIZE 2000
  821. static int __devinit iop_adma_memcpy_self_test(struct iop_adma_device *device)
  822. {
  823. int i;
  824. void *src, *dest;
  825. dma_addr_t src_dma, dest_dma;
  826. struct dma_chan *dma_chan;
  827. dma_cookie_t cookie;
  828. struct dma_async_tx_descriptor *tx;
  829. int err = 0;
  830. struct iop_adma_chan *iop_chan;
  831. dev_dbg(device->common.dev, "%s\n", __func__);
  832. src = kmalloc(IOP_ADMA_TEST_SIZE, GFP_KERNEL);
  833. if (!src)
  834. return -ENOMEM;
  835. dest = kzalloc(IOP_ADMA_TEST_SIZE, GFP_KERNEL);
  836. if (!dest) {
  837. kfree(src);
  838. return -ENOMEM;
  839. }
  840. /* Fill in src buffer */
  841. for (i = 0; i < IOP_ADMA_TEST_SIZE; i++)
  842. ((u8 *) src)[i] = (u8)i;
  843. /* Start copy, using first DMA channel */
  844. dma_chan = container_of(device->common.channels.next,
  845. struct dma_chan,
  846. device_node);
  847. if (iop_adma_alloc_chan_resources(dma_chan) < 1) {
  848. err = -ENODEV;
  849. goto out;
  850. }
  851. dest_dma = dma_map_single(dma_chan->device->dev, dest,
  852. IOP_ADMA_TEST_SIZE, DMA_FROM_DEVICE);
  853. src_dma = dma_map_single(dma_chan->device->dev, src,
  854. IOP_ADMA_TEST_SIZE, DMA_TO_DEVICE);
  855. tx = iop_adma_prep_dma_memcpy(dma_chan, dest_dma, src_dma,
  856. IOP_ADMA_TEST_SIZE,
  857. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  858. cookie = iop_adma_tx_submit(tx);
  859. iop_adma_issue_pending(dma_chan);
  860. msleep(1);
  861. if (iop_adma_status(dma_chan, cookie, NULL) !=
  862. DMA_SUCCESS) {
  863. dev_printk(KERN_ERR, dma_chan->device->dev,
  864. "Self-test copy timed out, disabling\n");
  865. err = -ENODEV;
  866. goto free_resources;
  867. }
  868. iop_chan = to_iop_adma_chan(dma_chan);
  869. dma_sync_single_for_cpu(&iop_chan->device->pdev->dev, dest_dma,
  870. IOP_ADMA_TEST_SIZE, DMA_FROM_DEVICE);
  871. if (memcmp(src, dest, IOP_ADMA_TEST_SIZE)) {
  872. dev_printk(KERN_ERR, dma_chan->device->dev,
  873. "Self-test copy failed compare, disabling\n");
  874. err = -ENODEV;
  875. goto free_resources;
  876. }
  877. free_resources:
  878. iop_adma_free_chan_resources(dma_chan);
  879. out:
  880. kfree(src);
  881. kfree(dest);
  882. return err;
  883. }
  884. #define IOP_ADMA_NUM_SRC_TEST 4 /* must be <= 15 */
  885. static int __devinit
  886. iop_adma_xor_val_self_test(struct iop_adma_device *device)
  887. {
  888. int i, src_idx;
  889. struct page *dest;
  890. struct page *xor_srcs[IOP_ADMA_NUM_SRC_TEST];
  891. struct page *zero_sum_srcs[IOP_ADMA_NUM_SRC_TEST + 1];
  892. dma_addr_t dma_srcs[IOP_ADMA_NUM_SRC_TEST + 1];
  893. dma_addr_t dma_addr, dest_dma;
  894. struct dma_async_tx_descriptor *tx;
  895. struct dma_chan *dma_chan;
  896. dma_cookie_t cookie;
  897. u8 cmp_byte = 0;
  898. u32 cmp_word;
  899. u32 zero_sum_result;
  900. int err = 0;
  901. struct iop_adma_chan *iop_chan;
  902. dev_dbg(device->common.dev, "%s\n", __func__);
  903. for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++) {
  904. xor_srcs[src_idx] = alloc_page(GFP_KERNEL);
  905. if (!xor_srcs[src_idx]) {
  906. while (src_idx--)
  907. __free_page(xor_srcs[src_idx]);
  908. return -ENOMEM;
  909. }
  910. }
  911. dest = alloc_page(GFP_KERNEL);
  912. if (!dest) {
  913. while (src_idx--)
  914. __free_page(xor_srcs[src_idx]);
  915. return -ENOMEM;
  916. }
  917. /* Fill in src buffers */
  918. for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++) {
  919. u8 *ptr = page_address(xor_srcs[src_idx]);
  920. for (i = 0; i < PAGE_SIZE; i++)
  921. ptr[i] = (1 << src_idx);
  922. }
  923. for (src_idx = 0; src_idx < IOP_ADMA_NUM_SRC_TEST; src_idx++)
  924. cmp_byte ^= (u8) (1 << src_idx);
  925. cmp_word = (cmp_byte << 24) | (cmp_byte << 16) |
  926. (cmp_byte << 8) | cmp_byte;
  927. memset(page_address(dest), 0, PAGE_SIZE);
  928. dma_chan = container_of(device->common.channels.next,
  929. struct dma_chan,
  930. device_node);
  931. if (iop_adma_alloc_chan_resources(dma_chan) < 1) {
  932. err = -ENODEV;
  933. goto out;
  934. }
  935. /* test xor */
  936. dest_dma = dma_map_page(dma_chan->device->dev, dest, 0,
  937. PAGE_SIZE, DMA_FROM_DEVICE);
  938. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++)
  939. dma_srcs[i] = dma_map_page(dma_chan->device->dev, xor_srcs[i],
  940. 0, PAGE_SIZE, DMA_TO_DEVICE);
  941. tx = iop_adma_prep_dma_xor(dma_chan, dest_dma, dma_srcs,
  942. IOP_ADMA_NUM_SRC_TEST, PAGE_SIZE,
  943. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  944. cookie = iop_adma_tx_submit(tx);
  945. iop_adma_issue_pending(dma_chan);
  946. msleep(8);
  947. if (iop_adma_status(dma_chan, cookie, NULL) !=
  948. DMA_SUCCESS) {
  949. dev_printk(KERN_ERR, dma_chan->device->dev,
  950. "Self-test xor timed out, disabling\n");
  951. err = -ENODEV;
  952. goto free_resources;
  953. }
  954. iop_chan = to_iop_adma_chan(dma_chan);
  955. dma_sync_single_for_cpu(&iop_chan->device->pdev->dev, dest_dma,
  956. PAGE_SIZE, DMA_FROM_DEVICE);
  957. for (i = 0; i < (PAGE_SIZE / sizeof(u32)); i++) {
  958. u32 *ptr = page_address(dest);
  959. if (ptr[i] != cmp_word) {
  960. dev_printk(KERN_ERR, dma_chan->device->dev,
  961. "Self-test xor failed compare, disabling\n");
  962. err = -ENODEV;
  963. goto free_resources;
  964. }
  965. }
  966. dma_sync_single_for_device(&iop_chan->device->pdev->dev, dest_dma,
  967. PAGE_SIZE, DMA_TO_DEVICE);
  968. /* skip zero sum if the capability is not present */
  969. if (!dma_has_cap(DMA_XOR_VAL, dma_chan->device->cap_mask))
  970. goto free_resources;
  971. /* zero sum the sources with the destintation page */
  972. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++)
  973. zero_sum_srcs[i] = xor_srcs[i];
  974. zero_sum_srcs[i] = dest;
  975. zero_sum_result = 1;
  976. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++)
  977. dma_srcs[i] = dma_map_page(dma_chan->device->dev,
  978. zero_sum_srcs[i], 0, PAGE_SIZE,
  979. DMA_TO_DEVICE);
  980. tx = iop_adma_prep_dma_xor_val(dma_chan, dma_srcs,
  981. IOP_ADMA_NUM_SRC_TEST + 1, PAGE_SIZE,
  982. &zero_sum_result,
  983. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  984. cookie = iop_adma_tx_submit(tx);
  985. iop_adma_issue_pending(dma_chan);
  986. msleep(8);
  987. if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  988. dev_printk(KERN_ERR, dma_chan->device->dev,
  989. "Self-test zero sum timed out, disabling\n");
  990. err = -ENODEV;
  991. goto free_resources;
  992. }
  993. if (zero_sum_result != 0) {
  994. dev_printk(KERN_ERR, dma_chan->device->dev,
  995. "Self-test zero sum failed compare, disabling\n");
  996. err = -ENODEV;
  997. goto free_resources;
  998. }
  999. /* test memset */
  1000. dma_addr = dma_map_page(dma_chan->device->dev, dest, 0,
  1001. PAGE_SIZE, DMA_FROM_DEVICE);
  1002. tx = iop_adma_prep_dma_memset(dma_chan, dma_addr, 0, PAGE_SIZE,
  1003. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  1004. cookie = iop_adma_tx_submit(tx);
  1005. iop_adma_issue_pending(dma_chan);
  1006. msleep(8);
  1007. if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  1008. dev_printk(KERN_ERR, dma_chan->device->dev,
  1009. "Self-test memset timed out, disabling\n");
  1010. err = -ENODEV;
  1011. goto free_resources;
  1012. }
  1013. for (i = 0; i < PAGE_SIZE/sizeof(u32); i++) {
  1014. u32 *ptr = page_address(dest);
  1015. if (ptr[i]) {
  1016. dev_printk(KERN_ERR, dma_chan->device->dev,
  1017. "Self-test memset failed compare, disabling\n");
  1018. err = -ENODEV;
  1019. goto free_resources;
  1020. }
  1021. }
  1022. /* test for non-zero parity sum */
  1023. zero_sum_result = 0;
  1024. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++)
  1025. dma_srcs[i] = dma_map_page(dma_chan->device->dev,
  1026. zero_sum_srcs[i], 0, PAGE_SIZE,
  1027. DMA_TO_DEVICE);
  1028. tx = iop_adma_prep_dma_xor_val(dma_chan, dma_srcs,
  1029. IOP_ADMA_NUM_SRC_TEST + 1, PAGE_SIZE,
  1030. &zero_sum_result,
  1031. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  1032. cookie = iop_adma_tx_submit(tx);
  1033. iop_adma_issue_pending(dma_chan);
  1034. msleep(8);
  1035. if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
  1036. dev_printk(KERN_ERR, dma_chan->device->dev,
  1037. "Self-test non-zero sum timed out, disabling\n");
  1038. err = -ENODEV;
  1039. goto free_resources;
  1040. }
  1041. if (zero_sum_result != 1) {
  1042. dev_printk(KERN_ERR, dma_chan->device->dev,
  1043. "Self-test non-zero sum failed compare, disabling\n");
  1044. err = -ENODEV;
  1045. goto free_resources;
  1046. }
  1047. free_resources:
  1048. iop_adma_free_chan_resources(dma_chan);
  1049. out:
  1050. src_idx = IOP_ADMA_NUM_SRC_TEST;
  1051. while (src_idx--)
  1052. __free_page(xor_srcs[src_idx]);
  1053. __free_page(dest);
  1054. return err;
  1055. }
  1056. #ifdef CONFIG_RAID6_PQ
  1057. static int __devinit
  1058. iop_adma_pq_zero_sum_self_test(struct iop_adma_device *device)
  1059. {
  1060. /* combined sources, software pq results, and extra hw pq results */
  1061. struct page *pq[IOP_ADMA_NUM_SRC_TEST+2+2];
  1062. /* ptr to the extra hw pq buffers defined above */
  1063. struct page **pq_hw = &pq[IOP_ADMA_NUM_SRC_TEST+2];
  1064. /* address conversion buffers (dma_map / page_address) */
  1065. void *pq_sw[IOP_ADMA_NUM_SRC_TEST+2];
  1066. dma_addr_t pq_src[IOP_ADMA_NUM_SRC_TEST+2];
  1067. dma_addr_t *pq_dest = &pq_src[IOP_ADMA_NUM_SRC_TEST];
  1068. int i;
  1069. struct dma_async_tx_descriptor *tx;
  1070. struct dma_chan *dma_chan;
  1071. dma_cookie_t cookie;
  1072. u32 zero_sum_result;
  1073. int err = 0;
  1074. struct device *dev;
  1075. dev_dbg(device->common.dev, "%s\n", __func__);
  1076. for (i = 0; i < ARRAY_SIZE(pq); i++) {
  1077. pq[i] = alloc_page(GFP_KERNEL);
  1078. if (!pq[i]) {
  1079. while (i--)
  1080. __free_page(pq[i]);
  1081. return -ENOMEM;
  1082. }
  1083. }
  1084. /* Fill in src buffers */
  1085. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++) {
  1086. pq_sw[i] = page_address(pq[i]);
  1087. memset(pq_sw[i], 0x11111111 * (1<<i), PAGE_SIZE);
  1088. }
  1089. pq_sw[i] = page_address(pq[i]);
  1090. pq_sw[i+1] = page_address(pq[i+1]);
  1091. dma_chan = container_of(device->common.channels.next,
  1092. struct dma_chan,
  1093. device_node);
  1094. if (iop_adma_alloc_chan_resources(dma_chan) < 1) {
  1095. err = -ENODEV;
  1096. goto out;
  1097. }
  1098. dev = dma_chan->device->dev;
  1099. /* initialize the dests */
  1100. memset(page_address(pq_hw[0]), 0 , PAGE_SIZE);
  1101. memset(page_address(pq_hw[1]), 0 , PAGE_SIZE);
  1102. /* test pq */
  1103. pq_dest[0] = dma_map_page(dev, pq_hw[0], 0, PAGE_SIZE, DMA_FROM_DEVICE);
  1104. pq_dest[1] = dma_map_page(dev, pq_hw[1], 0, PAGE_SIZE, DMA_FROM_DEVICE);
  1105. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST; i++)
  1106. pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE,
  1107. DMA_TO_DEVICE);
  1108. tx = iop_adma_prep_dma_pq(dma_chan, pq_dest, pq_src,
  1109. IOP_ADMA_NUM_SRC_TEST, (u8 *)raid6_gfexp,
  1110. PAGE_SIZE,
  1111. DMA_PREP_INTERRUPT |
  1112. DMA_CTRL_ACK);
  1113. cookie = iop_adma_tx_submit(tx);
  1114. iop_adma_issue_pending(dma_chan);
  1115. msleep(8);
  1116. if (iop_adma_status(dma_chan, cookie, NULL) !=
  1117. DMA_SUCCESS) {
  1118. dev_err(dev, "Self-test pq timed out, disabling\n");
  1119. err = -ENODEV;
  1120. goto free_resources;
  1121. }
  1122. raid6_call.gen_syndrome(IOP_ADMA_NUM_SRC_TEST+2, PAGE_SIZE, pq_sw);
  1123. if (memcmp(pq_sw[IOP_ADMA_NUM_SRC_TEST],
  1124. page_address(pq_hw[0]), PAGE_SIZE) != 0) {
  1125. dev_err(dev, "Self-test p failed compare, disabling\n");
  1126. err = -ENODEV;
  1127. goto free_resources;
  1128. }
  1129. if (memcmp(pq_sw[IOP_ADMA_NUM_SRC_TEST+1],
  1130. page_address(pq_hw[1]), PAGE_SIZE) != 0) {
  1131. dev_err(dev, "Self-test q failed compare, disabling\n");
  1132. err = -ENODEV;
  1133. goto free_resources;
  1134. }
  1135. /* test correct zero sum using the software generated pq values */
  1136. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 2; i++)
  1137. pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE,
  1138. DMA_TO_DEVICE);
  1139. zero_sum_result = ~0;
  1140. tx = iop_adma_prep_dma_pq_val(dma_chan, &pq_src[IOP_ADMA_NUM_SRC_TEST],
  1141. pq_src, IOP_ADMA_NUM_SRC_TEST,
  1142. raid6_gfexp, PAGE_SIZE, &zero_sum_result,
  1143. DMA_PREP_INTERRUPT|DMA_CTRL_ACK);
  1144. cookie = iop_adma_tx_submit(tx);
  1145. iop_adma_issue_pending(dma_chan);
  1146. msleep(8);
  1147. if (iop_adma_status(dma_chan, cookie, NULL) !=
  1148. DMA_SUCCESS) {
  1149. dev_err(dev, "Self-test pq-zero-sum timed out, disabling\n");
  1150. err = -ENODEV;
  1151. goto free_resources;
  1152. }
  1153. if (zero_sum_result != 0) {
  1154. dev_err(dev, "Self-test pq-zero-sum failed to validate: %x\n",
  1155. zero_sum_result);
  1156. err = -ENODEV;
  1157. goto free_resources;
  1158. }
  1159. /* test incorrect zero sum */
  1160. i = IOP_ADMA_NUM_SRC_TEST;
  1161. memset(pq_sw[i] + 100, 0, 100);
  1162. memset(pq_sw[i+1] + 200, 0, 200);
  1163. for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 2; i++)
  1164. pq_src[i] = dma_map_page(dev, pq[i], 0, PAGE_SIZE,
  1165. DMA_TO_DEVICE);
  1166. zero_sum_result = 0;
  1167. tx = iop_adma_prep_dma_pq_val(dma_chan, &pq_src[IOP_ADMA_NUM_SRC_TEST],
  1168. pq_src, IOP_ADMA_NUM_SRC_TEST,
  1169. raid6_gfexp, PAGE_SIZE, &zero_sum_result,
  1170. DMA_PREP_INTERRUPT|DMA_CTRL_ACK);
  1171. cookie = iop_adma_tx_submit(tx);
  1172. iop_adma_issue_pending(dma_chan);
  1173. msleep(8);
  1174. if (iop_adma_status(dma_chan, cookie, NULL) !=
  1175. DMA_SUCCESS) {
  1176. dev_err(dev, "Self-test !pq-zero-sum timed out, disabling\n");
  1177. err = -ENODEV;
  1178. goto free_resources;
  1179. }
  1180. if (zero_sum_result != (SUM_CHECK_P_RESULT | SUM_CHECK_Q_RESULT)) {
  1181. dev_err(dev, "Self-test !pq-zero-sum failed to validate: %x\n",
  1182. zero_sum_result);
  1183. err = -ENODEV;
  1184. goto free_resources;
  1185. }
  1186. free_resources:
  1187. iop_adma_free_chan_resources(dma_chan);
  1188. out:
  1189. i = ARRAY_SIZE(pq);
  1190. while (i--)
  1191. __free_page(pq[i]);
  1192. return err;
  1193. }
  1194. #endif
  1195. static int __devexit iop_adma_remove(struct platform_device *dev)
  1196. {
  1197. struct iop_adma_device *device = platform_get_drvdata(dev);
  1198. struct dma_chan *chan, *_chan;
  1199. struct iop_adma_chan *iop_chan;
  1200. struct iop_adma_platform_data *plat_data = dev->dev.platform_data;
  1201. dma_async_device_unregister(&device->common);
  1202. dma_free_coherent(&dev->dev, plat_data->pool_size,
  1203. device->dma_desc_pool_virt, device->dma_desc_pool);
  1204. list_for_each_entry_safe(chan, _chan, &device->common.channels,
  1205. device_node) {
  1206. iop_chan = to_iop_adma_chan(chan);
  1207. list_del(&chan->device_node);
  1208. kfree(iop_chan);
  1209. }
  1210. kfree(device);
  1211. return 0;
  1212. }
  1213. static int __devinit iop_adma_probe(struct platform_device *pdev)
  1214. {
  1215. struct resource *res;
  1216. int ret = 0, i;
  1217. struct iop_adma_device *adev;
  1218. struct iop_adma_chan *iop_chan;
  1219. struct dma_device *dma_dev;
  1220. struct iop_adma_platform_data *plat_data = pdev->dev.platform_data;
  1221. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1222. if (!res)
  1223. return -ENODEV;
  1224. if (!devm_request_mem_region(&pdev->dev, res->start,
  1225. resource_size(res), pdev->name))
  1226. return -EBUSY;
  1227. adev = kzalloc(sizeof(*adev), GFP_KERNEL);
  1228. if (!adev)
  1229. return -ENOMEM;
  1230. dma_dev = &adev->common;
  1231. /* allocate coherent memory for hardware descriptors
  1232. * note: writecombine gives slightly better performance, but
  1233. * requires that we explicitly flush the writes
  1234. */
  1235. if ((adev->dma_desc_pool_virt = dma_alloc_writecombine(&pdev->dev,
  1236. plat_data->pool_size,
  1237. &adev->dma_desc_pool,
  1238. GFP_KERNEL)) == NULL) {
  1239. ret = -ENOMEM;
  1240. goto err_free_adev;
  1241. }
  1242. dev_dbg(&pdev->dev, "%s: allocated descriptor pool virt %p phys %p\n",
  1243. __func__, adev->dma_desc_pool_virt,
  1244. (void *) adev->dma_desc_pool);
  1245. adev->id = plat_data->hw_id;
  1246. /* discover transaction capabilites from the platform data */
  1247. dma_dev->cap_mask = plat_data->cap_mask;
  1248. adev->pdev = pdev;
  1249. platform_set_drvdata(pdev, adev);
  1250. INIT_LIST_HEAD(&dma_dev->channels);
  1251. /* set base routines */
  1252. dma_dev->device_alloc_chan_resources = iop_adma_alloc_chan_resources;
  1253. dma_dev->device_free_chan_resources = iop_adma_free_chan_resources;
  1254. dma_dev->device_tx_status = iop_adma_status;
  1255. dma_dev->device_issue_pending = iop_adma_issue_pending;
  1256. dma_dev->dev = &pdev->dev;
  1257. /* set prep routines based on capability */
  1258. if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask))
  1259. dma_dev->device_prep_dma_memcpy = iop_adma_prep_dma_memcpy;
  1260. if (dma_has_cap(DMA_MEMSET, dma_dev->cap_mask))
  1261. dma_dev->device_prep_dma_memset = iop_adma_prep_dma_memset;
  1262. if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
  1263. dma_dev->max_xor = iop_adma_get_max_xor();
  1264. dma_dev->device_prep_dma_xor = iop_adma_prep_dma_xor;
  1265. }
  1266. if (dma_has_cap(DMA_XOR_VAL, dma_dev->cap_mask))
  1267. dma_dev->device_prep_dma_xor_val =
  1268. iop_adma_prep_dma_xor_val;
  1269. if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
  1270. dma_set_maxpq(dma_dev, iop_adma_get_max_pq(), 0);
  1271. dma_dev->device_prep_dma_pq = iop_adma_prep_dma_pq;
  1272. }
  1273. if (dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask))
  1274. dma_dev->device_prep_dma_pq_val =
  1275. iop_adma_prep_dma_pq_val;
  1276. if (dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask))
  1277. dma_dev->device_prep_dma_interrupt =
  1278. iop_adma_prep_dma_interrupt;
  1279. iop_chan = kzalloc(sizeof(*iop_chan), GFP_KERNEL);
  1280. if (!iop_chan) {
  1281. ret = -ENOMEM;
  1282. goto err_free_dma;
  1283. }
  1284. iop_chan->device = adev;
  1285. iop_chan->mmr_base = devm_ioremap(&pdev->dev, res->start,
  1286. resource_size(res));
  1287. if (!iop_chan->mmr_base) {
  1288. ret = -ENOMEM;
  1289. goto err_free_iop_chan;
  1290. }
  1291. tasklet_init(&iop_chan->irq_tasklet, iop_adma_tasklet, (unsigned long)
  1292. iop_chan);
  1293. /* clear errors before enabling interrupts */
  1294. iop_adma_device_clear_err_status(iop_chan);
  1295. for (i = 0; i < 3; i++) {
  1296. irq_handler_t handler[] = { iop_adma_eot_handler,
  1297. iop_adma_eoc_handler,
  1298. iop_adma_err_handler };
  1299. int irq = platform_get_irq(pdev, i);
  1300. if (irq < 0) {
  1301. ret = -ENXIO;
  1302. goto err_free_iop_chan;
  1303. } else {
  1304. ret = devm_request_irq(&pdev->dev, irq,
  1305. handler[i], 0, pdev->name, iop_chan);
  1306. if (ret)
  1307. goto err_free_iop_chan;
  1308. }
  1309. }
  1310. spin_lock_init(&iop_chan->lock);
  1311. INIT_LIST_HEAD(&iop_chan->chain);
  1312. INIT_LIST_HEAD(&iop_chan->all_slots);
  1313. iop_chan->common.device = dma_dev;
  1314. dma_cookie_init(&iop_chan->common);
  1315. list_add_tail(&iop_chan->common.device_node, &dma_dev->channels);
  1316. if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) {
  1317. ret = iop_adma_memcpy_self_test(adev);
  1318. dev_dbg(&pdev->dev, "memcpy self test returned %d\n", ret);
  1319. if (ret)
  1320. goto err_free_iop_chan;
  1321. }
  1322. if (dma_has_cap(DMA_XOR, dma_dev->cap_mask) ||
  1323. dma_has_cap(DMA_MEMSET, dma_dev->cap_mask)) {
  1324. ret = iop_adma_xor_val_self_test(adev);
  1325. dev_dbg(&pdev->dev, "xor self test returned %d\n", ret);
  1326. if (ret)
  1327. goto err_free_iop_chan;
  1328. }
  1329. if (dma_has_cap(DMA_PQ, dma_dev->cap_mask) &&
  1330. dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask)) {
  1331. #ifdef CONFIG_RAID6_PQ
  1332. ret = iop_adma_pq_zero_sum_self_test(adev);
  1333. dev_dbg(&pdev->dev, "pq self test returned %d\n", ret);
  1334. #else
  1335. /* can not test raid6, so do not publish capability */
  1336. dma_cap_clear(DMA_PQ, dma_dev->cap_mask);
  1337. dma_cap_clear(DMA_PQ_VAL, dma_dev->cap_mask);
  1338. ret = 0;
  1339. #endif
  1340. if (ret)
  1341. goto err_free_iop_chan;
  1342. }
  1343. dev_printk(KERN_INFO, &pdev->dev, "Intel(R) IOP: "
  1344. "( %s%s%s%s%s%s%s)\n",
  1345. dma_has_cap(DMA_PQ, dma_dev->cap_mask) ? "pq " : "",
  1346. dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask) ? "pq_val " : "",
  1347. dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "",
  1348. dma_has_cap(DMA_XOR_VAL, dma_dev->cap_mask) ? "xor_val " : "",
  1349. dma_has_cap(DMA_MEMSET, dma_dev->cap_mask) ? "fill " : "",
  1350. dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "",
  1351. dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : "");
  1352. dma_async_device_register(dma_dev);
  1353. goto out;
  1354. err_free_iop_chan:
  1355. kfree(iop_chan);
  1356. err_free_dma:
  1357. dma_free_coherent(&adev->pdev->dev, plat_data->pool_size,
  1358. adev->dma_desc_pool_virt, adev->dma_desc_pool);
  1359. err_free_adev:
  1360. kfree(adev);
  1361. out:
  1362. return ret;
  1363. }
  1364. static void iop_chan_start_null_memcpy(struct iop_adma_chan *iop_chan)
  1365. {
  1366. struct iop_adma_desc_slot *sw_desc, *grp_start;
  1367. dma_cookie_t cookie;
  1368. int slot_cnt, slots_per_op;
  1369. dev_dbg(iop_chan->device->common.dev, "%s\n", __func__);
  1370. spin_lock_bh(&iop_chan->lock);
  1371. slot_cnt = iop_chan_memcpy_slot_count(0, &slots_per_op);
  1372. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  1373. if (sw_desc) {
  1374. grp_start = sw_desc->group_head;
  1375. list_splice_init(&sw_desc->tx_list, &iop_chan->chain);
  1376. async_tx_ack(&sw_desc->async_tx);
  1377. iop_desc_init_memcpy(grp_start, 0);
  1378. iop_desc_set_byte_count(grp_start, iop_chan, 0);
  1379. iop_desc_set_dest_addr(grp_start, iop_chan, 0);
  1380. iop_desc_set_memcpy_src_addr(grp_start, 0);
  1381. cookie = dma_cookie_assign(&sw_desc->async_tx);
  1382. /* initialize the completed cookie to be less than
  1383. * the most recently used cookie
  1384. */
  1385. iop_chan->common.completed_cookie = cookie - 1;
  1386. /* channel should not be busy */
  1387. BUG_ON(iop_chan_is_busy(iop_chan));
  1388. /* clear any prior error-status bits */
  1389. iop_adma_device_clear_err_status(iop_chan);
  1390. /* disable operation */
  1391. iop_chan_disable(iop_chan);
  1392. /* set the descriptor address */
  1393. iop_chan_set_next_descriptor(iop_chan, sw_desc->async_tx.phys);
  1394. /* 1/ don't add pre-chained descriptors
  1395. * 2/ dummy read to flush next_desc write
  1396. */
  1397. BUG_ON(iop_desc_get_next_desc(sw_desc));
  1398. /* run the descriptor */
  1399. iop_chan_enable(iop_chan);
  1400. } else
  1401. dev_printk(KERN_ERR, iop_chan->device->common.dev,
  1402. "failed to allocate null descriptor\n");
  1403. spin_unlock_bh(&iop_chan->lock);
  1404. }
  1405. static void iop_chan_start_null_xor(struct iop_adma_chan *iop_chan)
  1406. {
  1407. struct iop_adma_desc_slot *sw_desc, *grp_start;
  1408. dma_cookie_t cookie;
  1409. int slot_cnt, slots_per_op;
  1410. dev_dbg(iop_chan->device->common.dev, "%s\n", __func__);
  1411. spin_lock_bh(&iop_chan->lock);
  1412. slot_cnt = iop_chan_xor_slot_count(0, 2, &slots_per_op);
  1413. sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
  1414. if (sw_desc) {
  1415. grp_start = sw_desc->group_head;
  1416. list_splice_init(&sw_desc->tx_list, &iop_chan->chain);
  1417. async_tx_ack(&sw_desc->async_tx);
  1418. iop_desc_init_null_xor(grp_start, 2, 0);
  1419. iop_desc_set_byte_count(grp_start, iop_chan, 0);
  1420. iop_desc_set_dest_addr(grp_start, iop_chan, 0);
  1421. iop_desc_set_xor_src_addr(grp_start, 0, 0);
  1422. iop_desc_set_xor_src_addr(grp_start, 1, 0);
  1423. cookie = dma_cookie_assign(&sw_desc->async_tx);
  1424. /* initialize the completed cookie to be less than
  1425. * the most recently used cookie
  1426. */
  1427. iop_chan->common.completed_cookie = cookie - 1;
  1428. /* channel should not be busy */
  1429. BUG_ON(iop_chan_is_busy(iop_chan));
  1430. /* clear any prior error-status bits */
  1431. iop_adma_device_clear_err_status(iop_chan);
  1432. /* disable operation */
  1433. iop_chan_disable(iop_chan);
  1434. /* set the descriptor address */
  1435. iop_chan_set_next_descriptor(iop_chan, sw_desc->async_tx.phys);
  1436. /* 1/ don't add pre-chained descriptors
  1437. * 2/ dummy read to flush next_desc write
  1438. */
  1439. BUG_ON(iop_desc_get_next_desc(sw_desc));
  1440. /* run the descriptor */
  1441. iop_chan_enable(iop_chan);
  1442. } else
  1443. dev_printk(KERN_ERR, iop_chan->device->common.dev,
  1444. "failed to allocate null descriptor\n");
  1445. spin_unlock_bh(&iop_chan->lock);
  1446. }
  1447. static struct platform_driver iop_adma_driver = {
  1448. .probe = iop_adma_probe,
  1449. .remove = __devexit_p(iop_adma_remove),
  1450. .driver = {
  1451. .owner = THIS_MODULE,
  1452. .name = "iop-adma",
  1453. },
  1454. };
  1455. module_platform_driver(iop_adma_driver);
  1456. MODULE_AUTHOR("Intel Corporation");
  1457. MODULE_DESCRIPTION("IOP ADMA Engine Driver");
  1458. MODULE_LICENSE("GPL");
  1459. MODULE_ALIAS("platform:iop-adma");