mmc_test.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305
  1. /*
  2. * Copyright 2007-2008 Pierre Ossman
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or (at
  7. * your option) any later version.
  8. */
  9. #include <linux/mmc/core.h>
  10. #include <linux/mmc/card.h>
  11. #include <linux/mmc/host.h>
  12. #include <linux/mmc/mmc.h>
  13. #include <linux/slab.h>
  14. #include <linux/scatterlist.h>
  15. #include <linux/swap.h> /* For nr_free_buffer_pages() */
  16. #include <linux/list.h>
  17. #include <linux/debugfs.h>
  18. #include <linux/uaccess.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/module.h>
  21. #define RESULT_OK 0
  22. #define RESULT_FAIL 1
  23. #define RESULT_UNSUP_HOST 2
  24. #define RESULT_UNSUP_CARD 3
  25. #define BUFFER_ORDER 2
  26. #define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER)
  27. #define TEST_ALIGN_END 8
  28. /*
  29. * Limit the test area size to the maximum MMC HC erase group size. Note that
  30. * the maximum SD allocation unit size is just 4MiB.
  31. */
  32. #define TEST_AREA_MAX_SIZE (128 * 1024 * 1024)
  33. /**
  34. * struct mmc_test_pages - pages allocated by 'alloc_pages()'.
  35. * @page: first page in the allocation
  36. * @order: order of the number of pages allocated
  37. */
  38. struct mmc_test_pages {
  39. struct page *page;
  40. unsigned int order;
  41. };
  42. /**
  43. * struct mmc_test_mem - allocated memory.
  44. * @arr: array of allocations
  45. * @cnt: number of allocations
  46. */
  47. struct mmc_test_mem {
  48. struct mmc_test_pages *arr;
  49. unsigned int cnt;
  50. };
  51. /**
  52. * struct mmc_test_area - information for performance tests.
  53. * @max_sz: test area size (in bytes)
  54. * @dev_addr: address on card at which to do performance tests
  55. * @max_tfr: maximum transfer size allowed by driver (in bytes)
  56. * @max_segs: maximum segments allowed by driver in scatterlist @sg
  57. * @max_seg_sz: maximum segment size allowed by driver
  58. * @blocks: number of (512 byte) blocks currently mapped by @sg
  59. * @sg_len: length of currently mapped scatterlist @sg
  60. * @mem: allocated memory
  61. * @sg: scatterlist
  62. */
  63. struct mmc_test_area {
  64. unsigned long max_sz;
  65. unsigned int dev_addr;
  66. unsigned int max_tfr;
  67. unsigned int max_segs;
  68. unsigned int max_seg_sz;
  69. unsigned int blocks;
  70. unsigned int sg_len;
  71. struct mmc_test_mem *mem;
  72. struct scatterlist *sg;
  73. };
  74. /**
  75. * struct mmc_test_transfer_result - transfer results for performance tests.
  76. * @link: double-linked list
  77. * @count: amount of group of sectors to check
  78. * @sectors: amount of sectors to check in one group
  79. * @ts: time values of transfer
  80. * @rate: calculated transfer rate
  81. * @iops: I/O operations per second (times 100)
  82. */
  83. struct mmc_test_transfer_result {
  84. struct list_head link;
  85. unsigned int count;
  86. unsigned int sectors;
  87. struct timespec ts;
  88. unsigned int rate;
  89. unsigned int iops;
  90. };
  91. /**
  92. * struct mmc_test_general_result - results for tests.
  93. * @link: double-linked list
  94. * @card: card under test
  95. * @testcase: number of test case
  96. * @result: result of test run
  97. * @tr_lst: transfer measurements if any as mmc_test_transfer_result
  98. */
  99. struct mmc_test_general_result {
  100. struct list_head link;
  101. struct mmc_card *card;
  102. int testcase;
  103. int result;
  104. struct list_head tr_lst;
  105. };
  106. /**
  107. * struct mmc_test_dbgfs_file - debugfs related file.
  108. * @link: double-linked list
  109. * @card: card under test
  110. * @file: file created under debugfs
  111. */
  112. struct mmc_test_dbgfs_file {
  113. struct list_head link;
  114. struct mmc_card *card;
  115. struct dentry *file;
  116. };
  117. /**
  118. * struct mmc_test_card - test information.
  119. * @card: card under test
  120. * @scratch: transfer buffer
  121. * @buffer: transfer buffer
  122. * @highmem: buffer for highmem tests
  123. * @area: information for performance tests
  124. * @gr: pointer to results of current testcase
  125. */
  126. struct mmc_test_card {
  127. struct mmc_card *card;
  128. u8 scratch[BUFFER_SIZE];
  129. u8 *buffer;
  130. #ifdef CONFIG_HIGHMEM
  131. struct page *highmem;
  132. #endif
  133. struct mmc_test_area area;
  134. struct mmc_test_general_result *gr;
  135. };
  136. enum mmc_test_prep_media {
  137. MMC_TEST_PREP_NONE = 0,
  138. MMC_TEST_PREP_WRITE_FULL = 1 << 0,
  139. MMC_TEST_PREP_ERASE = 1 << 1,
  140. };
  141. struct mmc_test_multiple_rw {
  142. unsigned int *sg_len;
  143. unsigned int *bs;
  144. unsigned int len;
  145. unsigned int size;
  146. bool do_write;
  147. bool do_nonblock_req;
  148. enum mmc_test_prep_media prepare;
  149. };
  150. struct mmc_test_async_req {
  151. struct mmc_async_req areq;
  152. struct mmc_test_card *test;
  153. };
  154. /*******************************************************************/
  155. /* General helper functions */
  156. /*******************************************************************/
  157. /*
  158. * Configure correct block size in card
  159. */
  160. static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size)
  161. {
  162. return mmc_set_blocklen(test->card, size);
  163. }
  164. static bool mmc_test_card_cmd23(struct mmc_card *card)
  165. {
  166. return mmc_card_mmc(card) ||
  167. (mmc_card_sd(card) && card->scr.cmds & SD_SCR_CMD23_SUPPORT);
  168. }
  169. static void mmc_test_prepare_sbc(struct mmc_test_card *test,
  170. struct mmc_request *mrq, unsigned int blocks)
  171. {
  172. struct mmc_card *card = test->card;
  173. if (!mrq->sbc || !mmc_host_cmd23(card->host) ||
  174. !mmc_test_card_cmd23(card) || !mmc_op_multi(mrq->cmd->opcode) ||
  175. (card->quirks & MMC_QUIRK_BLK_NO_CMD23)) {
  176. mrq->sbc = NULL;
  177. return;
  178. }
  179. mrq->sbc->opcode = MMC_SET_BLOCK_COUNT;
  180. mrq->sbc->arg = blocks;
  181. mrq->sbc->flags = MMC_RSP_R1 | MMC_CMD_AC;
  182. }
  183. /*
  184. * Fill in the mmc_request structure given a set of transfer parameters.
  185. */
  186. static void mmc_test_prepare_mrq(struct mmc_test_card *test,
  187. struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len,
  188. unsigned dev_addr, unsigned blocks, unsigned blksz, int write)
  189. {
  190. if (WARN_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop))
  191. return;
  192. if (blocks > 1) {
  193. mrq->cmd->opcode = write ?
  194. MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK;
  195. } else {
  196. mrq->cmd->opcode = write ?
  197. MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK;
  198. }
  199. mrq->cmd->arg = dev_addr;
  200. if (!mmc_card_blockaddr(test->card))
  201. mrq->cmd->arg <<= 9;
  202. mrq->cmd->flags = MMC_RSP_R1 | MMC_CMD_ADTC;
  203. if (blocks == 1)
  204. mrq->stop = NULL;
  205. else {
  206. mrq->stop->opcode = MMC_STOP_TRANSMISSION;
  207. mrq->stop->arg = 0;
  208. mrq->stop->flags = MMC_RSP_R1B | MMC_CMD_AC;
  209. }
  210. mrq->data->blksz = blksz;
  211. mrq->data->blocks = blocks;
  212. mrq->data->flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
  213. mrq->data->sg = sg;
  214. mrq->data->sg_len = sg_len;
  215. mmc_test_prepare_sbc(test, mrq, blocks);
  216. mmc_set_data_timeout(mrq->data, test->card);
  217. }
  218. static int mmc_test_busy(struct mmc_command *cmd)
  219. {
  220. return !(cmd->resp[0] & R1_READY_FOR_DATA) ||
  221. (R1_CURRENT_STATE(cmd->resp[0]) == R1_STATE_PRG);
  222. }
  223. /*
  224. * Wait for the card to finish the busy state
  225. */
  226. static int mmc_test_wait_busy(struct mmc_test_card *test)
  227. {
  228. int ret, busy;
  229. struct mmc_command cmd = {};
  230. busy = 0;
  231. do {
  232. memset(&cmd, 0, sizeof(struct mmc_command));
  233. cmd.opcode = MMC_SEND_STATUS;
  234. cmd.arg = test->card->rca << 16;
  235. cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
  236. ret = mmc_wait_for_cmd(test->card->host, &cmd, 0);
  237. if (ret)
  238. break;
  239. if (!busy && mmc_test_busy(&cmd)) {
  240. busy = 1;
  241. if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
  242. pr_info("%s: Warning: Host did not wait for busy state to end.\n",
  243. mmc_hostname(test->card->host));
  244. }
  245. } while (mmc_test_busy(&cmd));
  246. return ret;
  247. }
  248. /*
  249. * Transfer a single sector of kernel addressable data
  250. */
  251. static int mmc_test_buffer_transfer(struct mmc_test_card *test,
  252. u8 *buffer, unsigned addr, unsigned blksz, int write)
  253. {
  254. struct mmc_request mrq = {};
  255. struct mmc_command cmd = {};
  256. struct mmc_command stop = {};
  257. struct mmc_data data = {};
  258. struct scatterlist sg;
  259. mrq.cmd = &cmd;
  260. mrq.data = &data;
  261. mrq.stop = &stop;
  262. sg_init_one(&sg, buffer, blksz);
  263. mmc_test_prepare_mrq(test, &mrq, &sg, 1, addr, 1, blksz, write);
  264. mmc_wait_for_req(test->card->host, &mrq);
  265. if (cmd.error)
  266. return cmd.error;
  267. if (data.error)
  268. return data.error;
  269. return mmc_test_wait_busy(test);
  270. }
  271. static void mmc_test_free_mem(struct mmc_test_mem *mem)
  272. {
  273. if (!mem)
  274. return;
  275. while (mem->cnt--)
  276. __free_pages(mem->arr[mem->cnt].page,
  277. mem->arr[mem->cnt].order);
  278. kfree(mem->arr);
  279. kfree(mem);
  280. }
  281. /*
  282. * Allocate a lot of memory, preferably max_sz but at least min_sz. In case
  283. * there isn't much memory do not exceed 1/16th total lowmem pages. Also do
  284. * not exceed a maximum number of segments and try not to make segments much
  285. * bigger than maximum segment size.
  286. */
  287. static struct mmc_test_mem *mmc_test_alloc_mem(unsigned long min_sz,
  288. unsigned long max_sz,
  289. unsigned int max_segs,
  290. unsigned int max_seg_sz)
  291. {
  292. unsigned long max_page_cnt = DIV_ROUND_UP(max_sz, PAGE_SIZE);
  293. unsigned long min_page_cnt = DIV_ROUND_UP(min_sz, PAGE_SIZE);
  294. unsigned long max_seg_page_cnt = DIV_ROUND_UP(max_seg_sz, PAGE_SIZE);
  295. unsigned long page_cnt = 0;
  296. unsigned long limit = nr_free_buffer_pages() >> 4;
  297. struct mmc_test_mem *mem;
  298. if (max_page_cnt > limit)
  299. max_page_cnt = limit;
  300. if (min_page_cnt > max_page_cnt)
  301. min_page_cnt = max_page_cnt;
  302. if (max_seg_page_cnt > max_page_cnt)
  303. max_seg_page_cnt = max_page_cnt;
  304. if (max_segs > max_page_cnt)
  305. max_segs = max_page_cnt;
  306. mem = kzalloc(sizeof(*mem), GFP_KERNEL);
  307. if (!mem)
  308. return NULL;
  309. mem->arr = kcalloc(max_segs, sizeof(*mem->arr), GFP_KERNEL);
  310. if (!mem->arr)
  311. goto out_free;
  312. while (max_page_cnt) {
  313. struct page *page;
  314. unsigned int order;
  315. gfp_t flags = GFP_KERNEL | GFP_DMA | __GFP_NOWARN |
  316. __GFP_NORETRY;
  317. order = get_order(max_seg_page_cnt << PAGE_SHIFT);
  318. while (1) {
  319. page = alloc_pages(flags, order);
  320. if (page || !order)
  321. break;
  322. order -= 1;
  323. }
  324. if (!page) {
  325. if (page_cnt < min_page_cnt)
  326. goto out_free;
  327. break;
  328. }
  329. mem->arr[mem->cnt].page = page;
  330. mem->arr[mem->cnt].order = order;
  331. mem->cnt += 1;
  332. if (max_page_cnt <= (1UL << order))
  333. break;
  334. max_page_cnt -= 1UL << order;
  335. page_cnt += 1UL << order;
  336. if (mem->cnt >= max_segs) {
  337. if (page_cnt < min_page_cnt)
  338. goto out_free;
  339. break;
  340. }
  341. }
  342. return mem;
  343. out_free:
  344. mmc_test_free_mem(mem);
  345. return NULL;
  346. }
  347. /*
  348. * Map memory into a scatterlist. Optionally allow the same memory to be
  349. * mapped more than once.
  350. */
  351. static int mmc_test_map_sg(struct mmc_test_mem *mem, unsigned long size,
  352. struct scatterlist *sglist, int repeat,
  353. unsigned int max_segs, unsigned int max_seg_sz,
  354. unsigned int *sg_len, int min_sg_len)
  355. {
  356. struct scatterlist *sg = NULL;
  357. unsigned int i;
  358. unsigned long sz = size;
  359. sg_init_table(sglist, max_segs);
  360. if (min_sg_len > max_segs)
  361. min_sg_len = max_segs;
  362. *sg_len = 0;
  363. do {
  364. for (i = 0; i < mem->cnt; i++) {
  365. unsigned long len = PAGE_SIZE << mem->arr[i].order;
  366. if (min_sg_len && (size / min_sg_len < len))
  367. len = ALIGN(size / min_sg_len, 512);
  368. if (len > sz)
  369. len = sz;
  370. if (len > max_seg_sz)
  371. len = max_seg_sz;
  372. if (sg)
  373. sg = sg_next(sg);
  374. else
  375. sg = sglist;
  376. if (!sg)
  377. return -EINVAL;
  378. sg_set_page(sg, mem->arr[i].page, len, 0);
  379. sz -= len;
  380. *sg_len += 1;
  381. if (!sz)
  382. break;
  383. }
  384. } while (sz && repeat);
  385. if (sz)
  386. return -EINVAL;
  387. if (sg)
  388. sg_mark_end(sg);
  389. return 0;
  390. }
  391. /*
  392. * Map memory into a scatterlist so that no pages are contiguous. Allow the
  393. * same memory to be mapped more than once.
  394. */
  395. static int mmc_test_map_sg_max_scatter(struct mmc_test_mem *mem,
  396. unsigned long sz,
  397. struct scatterlist *sglist,
  398. unsigned int max_segs,
  399. unsigned int max_seg_sz,
  400. unsigned int *sg_len)
  401. {
  402. struct scatterlist *sg = NULL;
  403. unsigned int i = mem->cnt, cnt;
  404. unsigned long len;
  405. void *base, *addr, *last_addr = NULL;
  406. sg_init_table(sglist, max_segs);
  407. *sg_len = 0;
  408. while (sz) {
  409. base = page_address(mem->arr[--i].page);
  410. cnt = 1 << mem->arr[i].order;
  411. while (sz && cnt) {
  412. addr = base + PAGE_SIZE * --cnt;
  413. if (last_addr && last_addr + PAGE_SIZE == addr)
  414. continue;
  415. last_addr = addr;
  416. len = PAGE_SIZE;
  417. if (len > max_seg_sz)
  418. len = max_seg_sz;
  419. if (len > sz)
  420. len = sz;
  421. if (sg)
  422. sg = sg_next(sg);
  423. else
  424. sg = sglist;
  425. if (!sg)
  426. return -EINVAL;
  427. sg_set_page(sg, virt_to_page(addr), len, 0);
  428. sz -= len;
  429. *sg_len += 1;
  430. }
  431. if (i == 0)
  432. i = mem->cnt;
  433. }
  434. if (sg)
  435. sg_mark_end(sg);
  436. return 0;
  437. }
  438. /*
  439. * Calculate transfer rate in bytes per second.
  440. */
  441. static unsigned int mmc_test_rate(uint64_t bytes, struct timespec *ts)
  442. {
  443. uint64_t ns;
  444. ns = ts->tv_sec;
  445. ns *= 1000000000;
  446. ns += ts->tv_nsec;
  447. bytes *= 1000000000;
  448. while (ns > UINT_MAX) {
  449. bytes >>= 1;
  450. ns >>= 1;
  451. }
  452. if (!ns)
  453. return 0;
  454. do_div(bytes, (uint32_t)ns);
  455. return bytes;
  456. }
  457. /*
  458. * Save transfer results for future usage
  459. */
  460. static void mmc_test_save_transfer_result(struct mmc_test_card *test,
  461. unsigned int count, unsigned int sectors, struct timespec ts,
  462. unsigned int rate, unsigned int iops)
  463. {
  464. struct mmc_test_transfer_result *tr;
  465. if (!test->gr)
  466. return;
  467. tr = kmalloc(sizeof(*tr), GFP_KERNEL);
  468. if (!tr)
  469. return;
  470. tr->count = count;
  471. tr->sectors = sectors;
  472. tr->ts = ts;
  473. tr->rate = rate;
  474. tr->iops = iops;
  475. list_add_tail(&tr->link, &test->gr->tr_lst);
  476. }
  477. /*
  478. * Print the transfer rate.
  479. */
  480. static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
  481. struct timespec *ts1, struct timespec *ts2)
  482. {
  483. unsigned int rate, iops, sectors = bytes >> 9;
  484. struct timespec ts;
  485. ts = timespec_sub(*ts2, *ts1);
  486. rate = mmc_test_rate(bytes, &ts);
  487. iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */
  488. pr_info("%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
  489. "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
  490. mmc_hostname(test->card->host), sectors, sectors >> 1,
  491. (sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec,
  492. (unsigned long)ts.tv_nsec, rate / 1000, rate / 1024,
  493. iops / 100, iops % 100);
  494. mmc_test_save_transfer_result(test, 1, sectors, ts, rate, iops);
  495. }
  496. /*
  497. * Print the average transfer rate.
  498. */
  499. static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes,
  500. unsigned int count, struct timespec *ts1,
  501. struct timespec *ts2)
  502. {
  503. unsigned int rate, iops, sectors = bytes >> 9;
  504. uint64_t tot = bytes * count;
  505. struct timespec ts;
  506. ts = timespec_sub(*ts2, *ts1);
  507. rate = mmc_test_rate(tot, &ts);
  508. iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */
  509. pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
  510. "%lu.%09lu seconds (%u kB/s, %u KiB/s, "
  511. "%u.%02u IOPS, sg_len %d)\n",
  512. mmc_hostname(test->card->host), count, sectors, count,
  513. sectors >> 1, (sectors & 1 ? ".5" : ""),
  514. (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec,
  515. rate / 1000, rate / 1024, iops / 100, iops % 100,
  516. test->area.sg_len);
  517. mmc_test_save_transfer_result(test, count, sectors, ts, rate, iops);
  518. }
  519. /*
  520. * Return the card size in sectors.
  521. */
  522. static unsigned int mmc_test_capacity(struct mmc_card *card)
  523. {
  524. if (!mmc_card_sd(card) && mmc_card_blockaddr(card))
  525. return card->ext_csd.sectors;
  526. else
  527. return card->csd.capacity << (card->csd.read_blkbits - 9);
  528. }
  529. /*******************************************************************/
  530. /* Test preparation and cleanup */
  531. /*******************************************************************/
  532. /*
  533. * Fill the first couple of sectors of the card with known data
  534. * so that bad reads/writes can be detected
  535. */
  536. static int __mmc_test_prepare(struct mmc_test_card *test, int write)
  537. {
  538. int ret, i;
  539. ret = mmc_test_set_blksize(test, 512);
  540. if (ret)
  541. return ret;
  542. if (write)
  543. memset(test->buffer, 0xDF, 512);
  544. else {
  545. for (i = 0; i < 512; i++)
  546. test->buffer[i] = i;
  547. }
  548. for (i = 0; i < BUFFER_SIZE / 512; i++) {
  549. ret = mmc_test_buffer_transfer(test, test->buffer, i, 512, 1);
  550. if (ret)
  551. return ret;
  552. }
  553. return 0;
  554. }
  555. static int mmc_test_prepare_write(struct mmc_test_card *test)
  556. {
  557. return __mmc_test_prepare(test, 1);
  558. }
  559. static int mmc_test_prepare_read(struct mmc_test_card *test)
  560. {
  561. return __mmc_test_prepare(test, 0);
  562. }
  563. static int mmc_test_cleanup(struct mmc_test_card *test)
  564. {
  565. int ret, i;
  566. ret = mmc_test_set_blksize(test, 512);
  567. if (ret)
  568. return ret;
  569. memset(test->buffer, 0, 512);
  570. for (i = 0; i < BUFFER_SIZE / 512; i++) {
  571. ret = mmc_test_buffer_transfer(test, test->buffer, i, 512, 1);
  572. if (ret)
  573. return ret;
  574. }
  575. return 0;
  576. }
  577. /*******************************************************************/
  578. /* Test execution helpers */
  579. /*******************************************************************/
  580. /*
  581. * Modifies the mmc_request to perform the "short transfer" tests
  582. */
  583. static void mmc_test_prepare_broken_mrq(struct mmc_test_card *test,
  584. struct mmc_request *mrq, int write)
  585. {
  586. if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
  587. return;
  588. if (mrq->data->blocks > 1) {
  589. mrq->cmd->opcode = write ?
  590. MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK;
  591. mrq->stop = NULL;
  592. } else {
  593. mrq->cmd->opcode = MMC_SEND_STATUS;
  594. mrq->cmd->arg = test->card->rca << 16;
  595. }
  596. }
  597. /*
  598. * Checks that a normal transfer didn't have any errors
  599. */
  600. static int mmc_test_check_result(struct mmc_test_card *test,
  601. struct mmc_request *mrq)
  602. {
  603. int ret;
  604. if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
  605. return -EINVAL;
  606. ret = 0;
  607. if (mrq->sbc && mrq->sbc->error)
  608. ret = mrq->sbc->error;
  609. if (!ret && mrq->cmd->error)
  610. ret = mrq->cmd->error;
  611. if (!ret && mrq->data->error)
  612. ret = mrq->data->error;
  613. if (!ret && mrq->stop && mrq->stop->error)
  614. ret = mrq->stop->error;
  615. if (!ret && mrq->data->bytes_xfered !=
  616. mrq->data->blocks * mrq->data->blksz)
  617. ret = RESULT_FAIL;
  618. if (ret == -EINVAL)
  619. ret = RESULT_UNSUP_HOST;
  620. return ret;
  621. }
  622. static enum mmc_blk_status mmc_test_check_result_async(struct mmc_card *card,
  623. struct mmc_async_req *areq)
  624. {
  625. struct mmc_test_async_req *test_async =
  626. container_of(areq, struct mmc_test_async_req, areq);
  627. int ret;
  628. mmc_test_wait_busy(test_async->test);
  629. /*
  630. * FIXME: this would earlier just casts a regular error code,
  631. * either of the kernel type -ERRORCODE or the local test framework
  632. * RESULT_* errorcode, into an enum mmc_blk_status and return as
  633. * result check. Instead, convert it to some reasonable type by just
  634. * returning either MMC_BLK_SUCCESS or MMC_BLK_CMD_ERR.
  635. * If possible, a reasonable error code should be returned.
  636. */
  637. ret = mmc_test_check_result(test_async->test, areq->mrq);
  638. if (ret)
  639. return MMC_BLK_CMD_ERR;
  640. return MMC_BLK_SUCCESS;
  641. }
  642. /*
  643. * Checks that a "short transfer" behaved as expected
  644. */
  645. static int mmc_test_check_broken_result(struct mmc_test_card *test,
  646. struct mmc_request *mrq)
  647. {
  648. int ret;
  649. if (WARN_ON(!mrq || !mrq->cmd || !mrq->data))
  650. return -EINVAL;
  651. ret = 0;
  652. if (!ret && mrq->cmd->error)
  653. ret = mrq->cmd->error;
  654. if (!ret && mrq->data->error == 0)
  655. ret = RESULT_FAIL;
  656. if (!ret && mrq->data->error != -ETIMEDOUT)
  657. ret = mrq->data->error;
  658. if (!ret && mrq->stop && mrq->stop->error)
  659. ret = mrq->stop->error;
  660. if (mrq->data->blocks > 1) {
  661. if (!ret && mrq->data->bytes_xfered > mrq->data->blksz)
  662. ret = RESULT_FAIL;
  663. } else {
  664. if (!ret && mrq->data->bytes_xfered > 0)
  665. ret = RESULT_FAIL;
  666. }
  667. if (ret == -EINVAL)
  668. ret = RESULT_UNSUP_HOST;
  669. return ret;
  670. }
  671. /*
  672. * Tests nonblock transfer with certain parameters
  673. */
  674. static void mmc_test_nonblock_reset(struct mmc_request *mrq,
  675. struct mmc_command *cmd,
  676. struct mmc_command *stop,
  677. struct mmc_data *data)
  678. {
  679. memset(mrq, 0, sizeof(struct mmc_request));
  680. memset(cmd, 0, sizeof(struct mmc_command));
  681. memset(data, 0, sizeof(struct mmc_data));
  682. memset(stop, 0, sizeof(struct mmc_command));
  683. mrq->cmd = cmd;
  684. mrq->data = data;
  685. mrq->stop = stop;
  686. }
  687. static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
  688. struct scatterlist *sg, unsigned sg_len,
  689. unsigned dev_addr, unsigned blocks,
  690. unsigned blksz, int write, int count)
  691. {
  692. struct mmc_request mrq1;
  693. struct mmc_command cmd1;
  694. struct mmc_command stop1;
  695. struct mmc_data data1;
  696. struct mmc_request mrq2;
  697. struct mmc_command cmd2;
  698. struct mmc_command stop2;
  699. struct mmc_data data2;
  700. struct mmc_test_async_req test_areq[2];
  701. struct mmc_async_req *done_areq;
  702. struct mmc_async_req *cur_areq = &test_areq[0].areq;
  703. struct mmc_async_req *other_areq = &test_areq[1].areq;
  704. enum mmc_blk_status status;
  705. int i;
  706. int ret = RESULT_OK;
  707. test_areq[0].test = test;
  708. test_areq[1].test = test;
  709. mmc_test_nonblock_reset(&mrq1, &cmd1, &stop1, &data1);
  710. mmc_test_nonblock_reset(&mrq2, &cmd2, &stop2, &data2);
  711. cur_areq->mrq = &mrq1;
  712. cur_areq->err_check = mmc_test_check_result_async;
  713. other_areq->mrq = &mrq2;
  714. other_areq->err_check = mmc_test_check_result_async;
  715. for (i = 0; i < count; i++) {
  716. mmc_test_prepare_mrq(test, cur_areq->mrq, sg, sg_len, dev_addr,
  717. blocks, blksz, write);
  718. done_areq = mmc_start_req(test->card->host, cur_areq, &status);
  719. if (status != MMC_BLK_SUCCESS || (!done_areq && i > 0)) {
  720. ret = RESULT_FAIL;
  721. goto err;
  722. }
  723. if (done_areq) {
  724. if (done_areq->mrq == &mrq2)
  725. mmc_test_nonblock_reset(&mrq2, &cmd2,
  726. &stop2, &data2);
  727. else
  728. mmc_test_nonblock_reset(&mrq1, &cmd1,
  729. &stop1, &data1);
  730. }
  731. swap(cur_areq, other_areq);
  732. dev_addr += blocks;
  733. }
  734. done_areq = mmc_start_req(test->card->host, NULL, &status);
  735. if (status != MMC_BLK_SUCCESS)
  736. ret = RESULT_FAIL;
  737. return ret;
  738. err:
  739. return ret;
  740. }
  741. /*
  742. * Tests a basic transfer with certain parameters
  743. */
  744. static int mmc_test_simple_transfer(struct mmc_test_card *test,
  745. struct scatterlist *sg, unsigned sg_len, unsigned dev_addr,
  746. unsigned blocks, unsigned blksz, int write)
  747. {
  748. struct mmc_request mrq = {};
  749. struct mmc_command cmd = {};
  750. struct mmc_command stop = {};
  751. struct mmc_data data = {};
  752. mrq.cmd = &cmd;
  753. mrq.data = &data;
  754. mrq.stop = &stop;
  755. mmc_test_prepare_mrq(test, &mrq, sg, sg_len, dev_addr,
  756. blocks, blksz, write);
  757. mmc_wait_for_req(test->card->host, &mrq);
  758. mmc_test_wait_busy(test);
  759. return mmc_test_check_result(test, &mrq);
  760. }
  761. /*
  762. * Tests a transfer where the card will fail completely or partly
  763. */
  764. static int mmc_test_broken_transfer(struct mmc_test_card *test,
  765. unsigned blocks, unsigned blksz, int write)
  766. {
  767. struct mmc_request mrq = {};
  768. struct mmc_command cmd = {};
  769. struct mmc_command stop = {};
  770. struct mmc_data data = {};
  771. struct scatterlist sg;
  772. mrq.cmd = &cmd;
  773. mrq.data = &data;
  774. mrq.stop = &stop;
  775. sg_init_one(&sg, test->buffer, blocks * blksz);
  776. mmc_test_prepare_mrq(test, &mrq, &sg, 1, 0, blocks, blksz, write);
  777. mmc_test_prepare_broken_mrq(test, &mrq, write);
  778. mmc_wait_for_req(test->card->host, &mrq);
  779. mmc_test_wait_busy(test);
  780. return mmc_test_check_broken_result(test, &mrq);
  781. }
  782. /*
  783. * Does a complete transfer test where data is also validated
  784. *
  785. * Note: mmc_test_prepare() must have been done before this call
  786. */
  787. static int mmc_test_transfer(struct mmc_test_card *test,
  788. struct scatterlist *sg, unsigned sg_len, unsigned dev_addr,
  789. unsigned blocks, unsigned blksz, int write)
  790. {
  791. int ret, i;
  792. unsigned long flags;
  793. if (write) {
  794. for (i = 0; i < blocks * blksz; i++)
  795. test->scratch[i] = i;
  796. } else {
  797. memset(test->scratch, 0, BUFFER_SIZE);
  798. }
  799. local_irq_save(flags);
  800. sg_copy_from_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
  801. local_irq_restore(flags);
  802. ret = mmc_test_set_blksize(test, blksz);
  803. if (ret)
  804. return ret;
  805. ret = mmc_test_simple_transfer(test, sg, sg_len, dev_addr,
  806. blocks, blksz, write);
  807. if (ret)
  808. return ret;
  809. if (write) {
  810. int sectors;
  811. ret = mmc_test_set_blksize(test, 512);
  812. if (ret)
  813. return ret;
  814. sectors = (blocks * blksz + 511) / 512;
  815. if ((sectors * 512) == (blocks * blksz))
  816. sectors++;
  817. if ((sectors * 512) > BUFFER_SIZE)
  818. return -EINVAL;
  819. memset(test->buffer, 0, sectors * 512);
  820. for (i = 0; i < sectors; i++) {
  821. ret = mmc_test_buffer_transfer(test,
  822. test->buffer + i * 512,
  823. dev_addr + i, 512, 0);
  824. if (ret)
  825. return ret;
  826. }
  827. for (i = 0; i < blocks * blksz; i++) {
  828. if (test->buffer[i] != (u8)i)
  829. return RESULT_FAIL;
  830. }
  831. for (; i < sectors * 512; i++) {
  832. if (test->buffer[i] != 0xDF)
  833. return RESULT_FAIL;
  834. }
  835. } else {
  836. local_irq_save(flags);
  837. sg_copy_to_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
  838. local_irq_restore(flags);
  839. for (i = 0; i < blocks * blksz; i++) {
  840. if (test->scratch[i] != (u8)i)
  841. return RESULT_FAIL;
  842. }
  843. }
  844. return 0;
  845. }
  846. /*******************************************************************/
  847. /* Tests */
  848. /*******************************************************************/
  849. struct mmc_test_case {
  850. const char *name;
  851. int (*prepare)(struct mmc_test_card *);
  852. int (*run)(struct mmc_test_card *);
  853. int (*cleanup)(struct mmc_test_card *);
  854. };
  855. static int mmc_test_basic_write(struct mmc_test_card *test)
  856. {
  857. int ret;
  858. struct scatterlist sg;
  859. ret = mmc_test_set_blksize(test, 512);
  860. if (ret)
  861. return ret;
  862. sg_init_one(&sg, test->buffer, 512);
  863. return mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 1);
  864. }
  865. static int mmc_test_basic_read(struct mmc_test_card *test)
  866. {
  867. int ret;
  868. struct scatterlist sg;
  869. ret = mmc_test_set_blksize(test, 512);
  870. if (ret)
  871. return ret;
  872. sg_init_one(&sg, test->buffer, 512);
  873. return mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 0);
  874. }
  875. static int mmc_test_verify_write(struct mmc_test_card *test)
  876. {
  877. struct scatterlist sg;
  878. sg_init_one(&sg, test->buffer, 512);
  879. return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
  880. }
  881. static int mmc_test_verify_read(struct mmc_test_card *test)
  882. {
  883. struct scatterlist sg;
  884. sg_init_one(&sg, test->buffer, 512);
  885. return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
  886. }
  887. static int mmc_test_multi_write(struct mmc_test_card *test)
  888. {
  889. unsigned int size;
  890. struct scatterlist sg;
  891. if (test->card->host->max_blk_count == 1)
  892. return RESULT_UNSUP_HOST;
  893. size = PAGE_SIZE * 2;
  894. size = min(size, test->card->host->max_req_size);
  895. size = min(size, test->card->host->max_seg_size);
  896. size = min(size, test->card->host->max_blk_count * 512);
  897. if (size < 1024)
  898. return RESULT_UNSUP_HOST;
  899. sg_init_one(&sg, test->buffer, size);
  900. return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
  901. }
  902. static int mmc_test_multi_read(struct mmc_test_card *test)
  903. {
  904. unsigned int size;
  905. struct scatterlist sg;
  906. if (test->card->host->max_blk_count == 1)
  907. return RESULT_UNSUP_HOST;
  908. size = PAGE_SIZE * 2;
  909. size = min(size, test->card->host->max_req_size);
  910. size = min(size, test->card->host->max_seg_size);
  911. size = min(size, test->card->host->max_blk_count * 512);
  912. if (size < 1024)
  913. return RESULT_UNSUP_HOST;
  914. sg_init_one(&sg, test->buffer, size);
  915. return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
  916. }
  917. static int mmc_test_pow2_write(struct mmc_test_card *test)
  918. {
  919. int ret, i;
  920. struct scatterlist sg;
  921. if (!test->card->csd.write_partial)
  922. return RESULT_UNSUP_CARD;
  923. for (i = 1; i < 512; i <<= 1) {
  924. sg_init_one(&sg, test->buffer, i);
  925. ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
  926. if (ret)
  927. return ret;
  928. }
  929. return 0;
  930. }
  931. static int mmc_test_pow2_read(struct mmc_test_card *test)
  932. {
  933. int ret, i;
  934. struct scatterlist sg;
  935. if (!test->card->csd.read_partial)
  936. return RESULT_UNSUP_CARD;
  937. for (i = 1; i < 512; i <<= 1) {
  938. sg_init_one(&sg, test->buffer, i);
  939. ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
  940. if (ret)
  941. return ret;
  942. }
  943. return 0;
  944. }
  945. static int mmc_test_weird_write(struct mmc_test_card *test)
  946. {
  947. int ret, i;
  948. struct scatterlist sg;
  949. if (!test->card->csd.write_partial)
  950. return RESULT_UNSUP_CARD;
  951. for (i = 3; i < 512; i += 7) {
  952. sg_init_one(&sg, test->buffer, i);
  953. ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
  954. if (ret)
  955. return ret;
  956. }
  957. return 0;
  958. }
  959. static int mmc_test_weird_read(struct mmc_test_card *test)
  960. {
  961. int ret, i;
  962. struct scatterlist sg;
  963. if (!test->card->csd.read_partial)
  964. return RESULT_UNSUP_CARD;
  965. for (i = 3; i < 512; i += 7) {
  966. sg_init_one(&sg, test->buffer, i);
  967. ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
  968. if (ret)
  969. return ret;
  970. }
  971. return 0;
  972. }
  973. static int mmc_test_align_write(struct mmc_test_card *test)
  974. {
  975. int ret, i;
  976. struct scatterlist sg;
  977. for (i = 1; i < TEST_ALIGN_END; i++) {
  978. sg_init_one(&sg, test->buffer + i, 512);
  979. ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
  980. if (ret)
  981. return ret;
  982. }
  983. return 0;
  984. }
  985. static int mmc_test_align_read(struct mmc_test_card *test)
  986. {
  987. int ret, i;
  988. struct scatterlist sg;
  989. for (i = 1; i < TEST_ALIGN_END; i++) {
  990. sg_init_one(&sg, test->buffer + i, 512);
  991. ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
  992. if (ret)
  993. return ret;
  994. }
  995. return 0;
  996. }
  997. static int mmc_test_align_multi_write(struct mmc_test_card *test)
  998. {
  999. int ret, i;
  1000. unsigned int size;
  1001. struct scatterlist sg;
  1002. if (test->card->host->max_blk_count == 1)
  1003. return RESULT_UNSUP_HOST;
  1004. size = PAGE_SIZE * 2;
  1005. size = min(size, test->card->host->max_req_size);
  1006. size = min(size, test->card->host->max_seg_size);
  1007. size = min(size, test->card->host->max_blk_count * 512);
  1008. if (size < 1024)
  1009. return RESULT_UNSUP_HOST;
  1010. for (i = 1; i < TEST_ALIGN_END; i++) {
  1011. sg_init_one(&sg, test->buffer + i, size);
  1012. ret = mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
  1013. if (ret)
  1014. return ret;
  1015. }
  1016. return 0;
  1017. }
  1018. static int mmc_test_align_multi_read(struct mmc_test_card *test)
  1019. {
  1020. int ret, i;
  1021. unsigned int size;
  1022. struct scatterlist sg;
  1023. if (test->card->host->max_blk_count == 1)
  1024. return RESULT_UNSUP_HOST;
  1025. size = PAGE_SIZE * 2;
  1026. size = min(size, test->card->host->max_req_size);
  1027. size = min(size, test->card->host->max_seg_size);
  1028. size = min(size, test->card->host->max_blk_count * 512);
  1029. if (size < 1024)
  1030. return RESULT_UNSUP_HOST;
  1031. for (i = 1; i < TEST_ALIGN_END; i++) {
  1032. sg_init_one(&sg, test->buffer + i, size);
  1033. ret = mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
  1034. if (ret)
  1035. return ret;
  1036. }
  1037. return 0;
  1038. }
  1039. static int mmc_test_xfersize_write(struct mmc_test_card *test)
  1040. {
  1041. int ret;
  1042. ret = mmc_test_set_blksize(test, 512);
  1043. if (ret)
  1044. return ret;
  1045. return mmc_test_broken_transfer(test, 1, 512, 1);
  1046. }
  1047. static int mmc_test_xfersize_read(struct mmc_test_card *test)
  1048. {
  1049. int ret;
  1050. ret = mmc_test_set_blksize(test, 512);
  1051. if (ret)
  1052. return ret;
  1053. return mmc_test_broken_transfer(test, 1, 512, 0);
  1054. }
  1055. static int mmc_test_multi_xfersize_write(struct mmc_test_card *test)
  1056. {
  1057. int ret;
  1058. if (test->card->host->max_blk_count == 1)
  1059. return RESULT_UNSUP_HOST;
  1060. ret = mmc_test_set_blksize(test, 512);
  1061. if (ret)
  1062. return ret;
  1063. return mmc_test_broken_transfer(test, 2, 512, 1);
  1064. }
  1065. static int mmc_test_multi_xfersize_read(struct mmc_test_card *test)
  1066. {
  1067. int ret;
  1068. if (test->card->host->max_blk_count == 1)
  1069. return RESULT_UNSUP_HOST;
  1070. ret = mmc_test_set_blksize(test, 512);
  1071. if (ret)
  1072. return ret;
  1073. return mmc_test_broken_transfer(test, 2, 512, 0);
  1074. }
  1075. #ifdef CONFIG_HIGHMEM
  1076. static int mmc_test_write_high(struct mmc_test_card *test)
  1077. {
  1078. struct scatterlist sg;
  1079. sg_init_table(&sg, 1);
  1080. sg_set_page(&sg, test->highmem, 512, 0);
  1081. return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
  1082. }
  1083. static int mmc_test_read_high(struct mmc_test_card *test)
  1084. {
  1085. struct scatterlist sg;
  1086. sg_init_table(&sg, 1);
  1087. sg_set_page(&sg, test->highmem, 512, 0);
  1088. return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
  1089. }
  1090. static int mmc_test_multi_write_high(struct mmc_test_card *test)
  1091. {
  1092. unsigned int size;
  1093. struct scatterlist sg;
  1094. if (test->card->host->max_blk_count == 1)
  1095. return RESULT_UNSUP_HOST;
  1096. size = PAGE_SIZE * 2;
  1097. size = min(size, test->card->host->max_req_size);
  1098. size = min(size, test->card->host->max_seg_size);
  1099. size = min(size, test->card->host->max_blk_count * 512);
  1100. if (size < 1024)
  1101. return RESULT_UNSUP_HOST;
  1102. sg_init_table(&sg, 1);
  1103. sg_set_page(&sg, test->highmem, size, 0);
  1104. return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
  1105. }
  1106. static int mmc_test_multi_read_high(struct mmc_test_card *test)
  1107. {
  1108. unsigned int size;
  1109. struct scatterlist sg;
  1110. if (test->card->host->max_blk_count == 1)
  1111. return RESULT_UNSUP_HOST;
  1112. size = PAGE_SIZE * 2;
  1113. size = min(size, test->card->host->max_req_size);
  1114. size = min(size, test->card->host->max_seg_size);
  1115. size = min(size, test->card->host->max_blk_count * 512);
  1116. if (size < 1024)
  1117. return RESULT_UNSUP_HOST;
  1118. sg_init_table(&sg, 1);
  1119. sg_set_page(&sg, test->highmem, size, 0);
  1120. return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
  1121. }
  1122. #else
  1123. static int mmc_test_no_highmem(struct mmc_test_card *test)
  1124. {
  1125. pr_info("%s: Highmem not configured - test skipped\n",
  1126. mmc_hostname(test->card->host));
  1127. return 0;
  1128. }
  1129. #endif /* CONFIG_HIGHMEM */
  1130. /*
  1131. * Map sz bytes so that it can be transferred.
  1132. */
  1133. static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz,
  1134. int max_scatter, int min_sg_len)
  1135. {
  1136. struct mmc_test_area *t = &test->area;
  1137. int err;
  1138. t->blocks = sz >> 9;
  1139. if (max_scatter) {
  1140. err = mmc_test_map_sg_max_scatter(t->mem, sz, t->sg,
  1141. t->max_segs, t->max_seg_sz,
  1142. &t->sg_len);
  1143. } else {
  1144. err = mmc_test_map_sg(t->mem, sz, t->sg, 1, t->max_segs,
  1145. t->max_seg_sz, &t->sg_len, min_sg_len);
  1146. }
  1147. if (err)
  1148. pr_info("%s: Failed to map sg list\n",
  1149. mmc_hostname(test->card->host));
  1150. return err;
  1151. }
  1152. /*
  1153. * Transfer bytes mapped by mmc_test_area_map().
  1154. */
  1155. static int mmc_test_area_transfer(struct mmc_test_card *test,
  1156. unsigned int dev_addr, int write)
  1157. {
  1158. struct mmc_test_area *t = &test->area;
  1159. return mmc_test_simple_transfer(test, t->sg, t->sg_len, dev_addr,
  1160. t->blocks, 512, write);
  1161. }
  1162. /*
  1163. * Map and transfer bytes for multiple transfers.
  1164. */
  1165. static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz,
  1166. unsigned int dev_addr, int write,
  1167. int max_scatter, int timed, int count,
  1168. bool nonblock, int min_sg_len)
  1169. {
  1170. struct timespec ts1, ts2;
  1171. int ret = 0;
  1172. int i;
  1173. struct mmc_test_area *t = &test->area;
  1174. /*
  1175. * In the case of a maximally scattered transfer, the maximum transfer
  1176. * size is further limited by using PAGE_SIZE segments.
  1177. */
  1178. if (max_scatter) {
  1179. struct mmc_test_area *t = &test->area;
  1180. unsigned long max_tfr;
  1181. if (t->max_seg_sz >= PAGE_SIZE)
  1182. max_tfr = t->max_segs * PAGE_SIZE;
  1183. else
  1184. max_tfr = t->max_segs * t->max_seg_sz;
  1185. if (sz > max_tfr)
  1186. sz = max_tfr;
  1187. }
  1188. ret = mmc_test_area_map(test, sz, max_scatter, min_sg_len);
  1189. if (ret)
  1190. return ret;
  1191. if (timed)
  1192. getnstimeofday(&ts1);
  1193. if (nonblock)
  1194. ret = mmc_test_nonblock_transfer(test, t->sg, t->sg_len,
  1195. dev_addr, t->blocks, 512, write, count);
  1196. else
  1197. for (i = 0; i < count && ret == 0; i++) {
  1198. ret = mmc_test_area_transfer(test, dev_addr, write);
  1199. dev_addr += sz >> 9;
  1200. }
  1201. if (ret)
  1202. return ret;
  1203. if (timed)
  1204. getnstimeofday(&ts2);
  1205. if (timed)
  1206. mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2);
  1207. return 0;
  1208. }
  1209. static int mmc_test_area_io(struct mmc_test_card *test, unsigned long sz,
  1210. unsigned int dev_addr, int write, int max_scatter,
  1211. int timed)
  1212. {
  1213. return mmc_test_area_io_seq(test, sz, dev_addr, write, max_scatter,
  1214. timed, 1, false, 0);
  1215. }
  1216. /*
  1217. * Write the test area entirely.
  1218. */
  1219. static int mmc_test_area_fill(struct mmc_test_card *test)
  1220. {
  1221. struct mmc_test_area *t = &test->area;
  1222. return mmc_test_area_io(test, t->max_tfr, t->dev_addr, 1, 0, 0);
  1223. }
  1224. /*
  1225. * Erase the test area entirely.
  1226. */
  1227. static int mmc_test_area_erase(struct mmc_test_card *test)
  1228. {
  1229. struct mmc_test_area *t = &test->area;
  1230. if (!mmc_can_erase(test->card))
  1231. return 0;
  1232. return mmc_erase(test->card, t->dev_addr, t->max_sz >> 9,
  1233. MMC_ERASE_ARG);
  1234. }
  1235. /*
  1236. * Cleanup struct mmc_test_area.
  1237. */
  1238. static int mmc_test_area_cleanup(struct mmc_test_card *test)
  1239. {
  1240. struct mmc_test_area *t = &test->area;
  1241. kfree(t->sg);
  1242. mmc_test_free_mem(t->mem);
  1243. return 0;
  1244. }
  1245. /*
  1246. * Initialize an area for testing large transfers. The test area is set to the
  1247. * middle of the card because cards may have different characteristics at the
  1248. * front (for FAT file system optimization). Optionally, the area is erased
  1249. * (if the card supports it) which may improve write performance. Optionally,
  1250. * the area is filled with data for subsequent read tests.
  1251. */
  1252. static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
  1253. {
  1254. struct mmc_test_area *t = &test->area;
  1255. unsigned long min_sz = 64 * 1024, sz;
  1256. int ret;
  1257. ret = mmc_test_set_blksize(test, 512);
  1258. if (ret)
  1259. return ret;
  1260. /* Make the test area size about 4MiB */
  1261. sz = (unsigned long)test->card->pref_erase << 9;
  1262. t->max_sz = sz;
  1263. while (t->max_sz < 4 * 1024 * 1024)
  1264. t->max_sz += sz;
  1265. while (t->max_sz > TEST_AREA_MAX_SIZE && t->max_sz > sz)
  1266. t->max_sz -= sz;
  1267. t->max_segs = test->card->host->max_segs;
  1268. t->max_seg_sz = test->card->host->max_seg_size;
  1269. t->max_seg_sz -= t->max_seg_sz % 512;
  1270. t->max_tfr = t->max_sz;
  1271. if (t->max_tfr >> 9 > test->card->host->max_blk_count)
  1272. t->max_tfr = test->card->host->max_blk_count << 9;
  1273. if (t->max_tfr > test->card->host->max_req_size)
  1274. t->max_tfr = test->card->host->max_req_size;
  1275. if (t->max_tfr / t->max_seg_sz > t->max_segs)
  1276. t->max_tfr = t->max_segs * t->max_seg_sz;
  1277. /*
  1278. * Try to allocate enough memory for a max. sized transfer. Less is OK
  1279. * because the same memory can be mapped into the scatterlist more than
  1280. * once. Also, take into account the limits imposed on scatterlist
  1281. * segments by the host driver.
  1282. */
  1283. t->mem = mmc_test_alloc_mem(min_sz, t->max_tfr, t->max_segs,
  1284. t->max_seg_sz);
  1285. if (!t->mem)
  1286. return -ENOMEM;
  1287. t->sg = kmalloc_array(t->max_segs, sizeof(*t->sg), GFP_KERNEL);
  1288. if (!t->sg) {
  1289. ret = -ENOMEM;
  1290. goto out_free;
  1291. }
  1292. t->dev_addr = mmc_test_capacity(test->card) / 2;
  1293. t->dev_addr -= t->dev_addr % (t->max_sz >> 9);
  1294. if (erase) {
  1295. ret = mmc_test_area_erase(test);
  1296. if (ret)
  1297. goto out_free;
  1298. }
  1299. if (fill) {
  1300. ret = mmc_test_area_fill(test);
  1301. if (ret)
  1302. goto out_free;
  1303. }
  1304. return 0;
  1305. out_free:
  1306. mmc_test_area_cleanup(test);
  1307. return ret;
  1308. }
  1309. /*
  1310. * Prepare for large transfers. Do not erase the test area.
  1311. */
  1312. static int mmc_test_area_prepare(struct mmc_test_card *test)
  1313. {
  1314. return mmc_test_area_init(test, 0, 0);
  1315. }
  1316. /*
  1317. * Prepare for large transfers. Do erase the test area.
  1318. */
  1319. static int mmc_test_area_prepare_erase(struct mmc_test_card *test)
  1320. {
  1321. return mmc_test_area_init(test, 1, 0);
  1322. }
  1323. /*
  1324. * Prepare for large transfers. Erase and fill the test area.
  1325. */
  1326. static int mmc_test_area_prepare_fill(struct mmc_test_card *test)
  1327. {
  1328. return mmc_test_area_init(test, 1, 1);
  1329. }
  1330. /*
  1331. * Test best-case performance. Best-case performance is expected from
  1332. * a single large transfer.
  1333. *
  1334. * An additional option (max_scatter) allows the measurement of the same
  1335. * transfer but with no contiguous pages in the scatter list. This tests
  1336. * the efficiency of DMA to handle scattered pages.
  1337. */
  1338. static int mmc_test_best_performance(struct mmc_test_card *test, int write,
  1339. int max_scatter)
  1340. {
  1341. struct mmc_test_area *t = &test->area;
  1342. return mmc_test_area_io(test, t->max_tfr, t->dev_addr, write,
  1343. max_scatter, 1);
  1344. }
  1345. /*
  1346. * Best-case read performance.
  1347. */
  1348. static int mmc_test_best_read_performance(struct mmc_test_card *test)
  1349. {
  1350. return mmc_test_best_performance(test, 0, 0);
  1351. }
  1352. /*
  1353. * Best-case write performance.
  1354. */
  1355. static int mmc_test_best_write_performance(struct mmc_test_card *test)
  1356. {
  1357. return mmc_test_best_performance(test, 1, 0);
  1358. }
  1359. /*
  1360. * Best-case read performance into scattered pages.
  1361. */
  1362. static int mmc_test_best_read_perf_max_scatter(struct mmc_test_card *test)
  1363. {
  1364. return mmc_test_best_performance(test, 0, 1);
  1365. }
  1366. /*
  1367. * Best-case write performance from scattered pages.
  1368. */
  1369. static int mmc_test_best_write_perf_max_scatter(struct mmc_test_card *test)
  1370. {
  1371. return mmc_test_best_performance(test, 1, 1);
  1372. }
  1373. /*
  1374. * Single read performance by transfer size.
  1375. */
  1376. static int mmc_test_profile_read_perf(struct mmc_test_card *test)
  1377. {
  1378. struct mmc_test_area *t = &test->area;
  1379. unsigned long sz;
  1380. unsigned int dev_addr;
  1381. int ret;
  1382. for (sz = 512; sz < t->max_tfr; sz <<= 1) {
  1383. dev_addr = t->dev_addr + (sz >> 9);
  1384. ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
  1385. if (ret)
  1386. return ret;
  1387. }
  1388. sz = t->max_tfr;
  1389. dev_addr = t->dev_addr;
  1390. return mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
  1391. }
  1392. /*
  1393. * Single write performance by transfer size.
  1394. */
  1395. static int mmc_test_profile_write_perf(struct mmc_test_card *test)
  1396. {
  1397. struct mmc_test_area *t = &test->area;
  1398. unsigned long sz;
  1399. unsigned int dev_addr;
  1400. int ret;
  1401. ret = mmc_test_area_erase(test);
  1402. if (ret)
  1403. return ret;
  1404. for (sz = 512; sz < t->max_tfr; sz <<= 1) {
  1405. dev_addr = t->dev_addr + (sz >> 9);
  1406. ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
  1407. if (ret)
  1408. return ret;
  1409. }
  1410. ret = mmc_test_area_erase(test);
  1411. if (ret)
  1412. return ret;
  1413. sz = t->max_tfr;
  1414. dev_addr = t->dev_addr;
  1415. return mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
  1416. }
  1417. /*
  1418. * Single trim performance by transfer size.
  1419. */
  1420. static int mmc_test_profile_trim_perf(struct mmc_test_card *test)
  1421. {
  1422. struct mmc_test_area *t = &test->area;
  1423. unsigned long sz;
  1424. unsigned int dev_addr;
  1425. struct timespec ts1, ts2;
  1426. int ret;
  1427. if (!mmc_can_trim(test->card))
  1428. return RESULT_UNSUP_CARD;
  1429. if (!mmc_can_erase(test->card))
  1430. return RESULT_UNSUP_HOST;
  1431. for (sz = 512; sz < t->max_sz; sz <<= 1) {
  1432. dev_addr = t->dev_addr + (sz >> 9);
  1433. getnstimeofday(&ts1);
  1434. ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
  1435. if (ret)
  1436. return ret;
  1437. getnstimeofday(&ts2);
  1438. mmc_test_print_rate(test, sz, &ts1, &ts2);
  1439. }
  1440. dev_addr = t->dev_addr;
  1441. getnstimeofday(&ts1);
  1442. ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
  1443. if (ret)
  1444. return ret;
  1445. getnstimeofday(&ts2);
  1446. mmc_test_print_rate(test, sz, &ts1, &ts2);
  1447. return 0;
  1448. }
  1449. static int mmc_test_seq_read_perf(struct mmc_test_card *test, unsigned long sz)
  1450. {
  1451. struct mmc_test_area *t = &test->area;
  1452. unsigned int dev_addr, i, cnt;
  1453. struct timespec ts1, ts2;
  1454. int ret;
  1455. cnt = t->max_sz / sz;
  1456. dev_addr = t->dev_addr;
  1457. getnstimeofday(&ts1);
  1458. for (i = 0; i < cnt; i++) {
  1459. ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0);
  1460. if (ret)
  1461. return ret;
  1462. dev_addr += (sz >> 9);
  1463. }
  1464. getnstimeofday(&ts2);
  1465. mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
  1466. return 0;
  1467. }
  1468. /*
  1469. * Consecutive read performance by transfer size.
  1470. */
  1471. static int mmc_test_profile_seq_read_perf(struct mmc_test_card *test)
  1472. {
  1473. struct mmc_test_area *t = &test->area;
  1474. unsigned long sz;
  1475. int ret;
  1476. for (sz = 512; sz < t->max_tfr; sz <<= 1) {
  1477. ret = mmc_test_seq_read_perf(test, sz);
  1478. if (ret)
  1479. return ret;
  1480. }
  1481. sz = t->max_tfr;
  1482. return mmc_test_seq_read_perf(test, sz);
  1483. }
  1484. static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz)
  1485. {
  1486. struct mmc_test_area *t = &test->area;
  1487. unsigned int dev_addr, i, cnt;
  1488. struct timespec ts1, ts2;
  1489. int ret;
  1490. ret = mmc_test_area_erase(test);
  1491. if (ret)
  1492. return ret;
  1493. cnt = t->max_sz / sz;
  1494. dev_addr = t->dev_addr;
  1495. getnstimeofday(&ts1);
  1496. for (i = 0; i < cnt; i++) {
  1497. ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0);
  1498. if (ret)
  1499. return ret;
  1500. dev_addr += (sz >> 9);
  1501. }
  1502. getnstimeofday(&ts2);
  1503. mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
  1504. return 0;
  1505. }
  1506. /*
  1507. * Consecutive write performance by transfer size.
  1508. */
  1509. static int mmc_test_profile_seq_write_perf(struct mmc_test_card *test)
  1510. {
  1511. struct mmc_test_area *t = &test->area;
  1512. unsigned long sz;
  1513. int ret;
  1514. for (sz = 512; sz < t->max_tfr; sz <<= 1) {
  1515. ret = mmc_test_seq_write_perf(test, sz);
  1516. if (ret)
  1517. return ret;
  1518. }
  1519. sz = t->max_tfr;
  1520. return mmc_test_seq_write_perf(test, sz);
  1521. }
  1522. /*
  1523. * Consecutive trim performance by transfer size.
  1524. */
  1525. static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
  1526. {
  1527. struct mmc_test_area *t = &test->area;
  1528. unsigned long sz;
  1529. unsigned int dev_addr, i, cnt;
  1530. struct timespec ts1, ts2;
  1531. int ret;
  1532. if (!mmc_can_trim(test->card))
  1533. return RESULT_UNSUP_CARD;
  1534. if (!mmc_can_erase(test->card))
  1535. return RESULT_UNSUP_HOST;
  1536. for (sz = 512; sz <= t->max_sz; sz <<= 1) {
  1537. ret = mmc_test_area_erase(test);
  1538. if (ret)
  1539. return ret;
  1540. ret = mmc_test_area_fill(test);
  1541. if (ret)
  1542. return ret;
  1543. cnt = t->max_sz / sz;
  1544. dev_addr = t->dev_addr;
  1545. getnstimeofday(&ts1);
  1546. for (i = 0; i < cnt; i++) {
  1547. ret = mmc_erase(test->card, dev_addr, sz >> 9,
  1548. MMC_TRIM_ARG);
  1549. if (ret)
  1550. return ret;
  1551. dev_addr += (sz >> 9);
  1552. }
  1553. getnstimeofday(&ts2);
  1554. mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
  1555. }
  1556. return 0;
  1557. }
  1558. static unsigned int rnd_next = 1;
  1559. static unsigned int mmc_test_rnd_num(unsigned int rnd_cnt)
  1560. {
  1561. uint64_t r;
  1562. rnd_next = rnd_next * 1103515245 + 12345;
  1563. r = (rnd_next >> 16) & 0x7fff;
  1564. return (r * rnd_cnt) >> 15;
  1565. }
  1566. static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print,
  1567. unsigned long sz)
  1568. {
  1569. unsigned int dev_addr, cnt, rnd_addr, range1, range2, last_ea = 0, ea;
  1570. unsigned int ssz;
  1571. struct timespec ts1, ts2, ts;
  1572. int ret;
  1573. ssz = sz >> 9;
  1574. rnd_addr = mmc_test_capacity(test->card) / 4;
  1575. range1 = rnd_addr / test->card->pref_erase;
  1576. range2 = range1 / ssz;
  1577. getnstimeofday(&ts1);
  1578. for (cnt = 0; cnt < UINT_MAX; cnt++) {
  1579. getnstimeofday(&ts2);
  1580. ts = timespec_sub(ts2, ts1);
  1581. if (ts.tv_sec >= 10)
  1582. break;
  1583. ea = mmc_test_rnd_num(range1);
  1584. if (ea == last_ea)
  1585. ea -= 1;
  1586. last_ea = ea;
  1587. dev_addr = rnd_addr + test->card->pref_erase * ea +
  1588. ssz * mmc_test_rnd_num(range2);
  1589. ret = mmc_test_area_io(test, sz, dev_addr, write, 0, 0);
  1590. if (ret)
  1591. return ret;
  1592. }
  1593. if (print)
  1594. mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
  1595. return 0;
  1596. }
  1597. static int mmc_test_random_perf(struct mmc_test_card *test, int write)
  1598. {
  1599. struct mmc_test_area *t = &test->area;
  1600. unsigned int next;
  1601. unsigned long sz;
  1602. int ret;
  1603. for (sz = 512; sz < t->max_tfr; sz <<= 1) {
  1604. /*
  1605. * When writing, try to get more consistent results by running
  1606. * the test twice with exactly the same I/O but outputting the
  1607. * results only for the 2nd run.
  1608. */
  1609. if (write) {
  1610. next = rnd_next;
  1611. ret = mmc_test_rnd_perf(test, write, 0, sz);
  1612. if (ret)
  1613. return ret;
  1614. rnd_next = next;
  1615. }
  1616. ret = mmc_test_rnd_perf(test, write, 1, sz);
  1617. if (ret)
  1618. return ret;
  1619. }
  1620. sz = t->max_tfr;
  1621. if (write) {
  1622. next = rnd_next;
  1623. ret = mmc_test_rnd_perf(test, write, 0, sz);
  1624. if (ret)
  1625. return ret;
  1626. rnd_next = next;
  1627. }
  1628. return mmc_test_rnd_perf(test, write, 1, sz);
  1629. }
  1630. /*
  1631. * Random read performance by transfer size.
  1632. */
  1633. static int mmc_test_random_read_perf(struct mmc_test_card *test)
  1634. {
  1635. return mmc_test_random_perf(test, 0);
  1636. }
  1637. /*
  1638. * Random write performance by transfer size.
  1639. */
  1640. static int mmc_test_random_write_perf(struct mmc_test_card *test)
  1641. {
  1642. return mmc_test_random_perf(test, 1);
  1643. }
  1644. static int mmc_test_seq_perf(struct mmc_test_card *test, int write,
  1645. unsigned int tot_sz, int max_scatter)
  1646. {
  1647. struct mmc_test_area *t = &test->area;
  1648. unsigned int dev_addr, i, cnt, sz, ssz;
  1649. struct timespec ts1, ts2;
  1650. int ret;
  1651. sz = t->max_tfr;
  1652. /*
  1653. * In the case of a maximally scattered transfer, the maximum transfer
  1654. * size is further limited by using PAGE_SIZE segments.
  1655. */
  1656. if (max_scatter) {
  1657. unsigned long max_tfr;
  1658. if (t->max_seg_sz >= PAGE_SIZE)
  1659. max_tfr = t->max_segs * PAGE_SIZE;
  1660. else
  1661. max_tfr = t->max_segs * t->max_seg_sz;
  1662. if (sz > max_tfr)
  1663. sz = max_tfr;
  1664. }
  1665. ssz = sz >> 9;
  1666. dev_addr = mmc_test_capacity(test->card) / 4;
  1667. if (tot_sz > dev_addr << 9)
  1668. tot_sz = dev_addr << 9;
  1669. cnt = tot_sz / sz;
  1670. dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
  1671. getnstimeofday(&ts1);
  1672. for (i = 0; i < cnt; i++) {
  1673. ret = mmc_test_area_io(test, sz, dev_addr, write,
  1674. max_scatter, 0);
  1675. if (ret)
  1676. return ret;
  1677. dev_addr += ssz;
  1678. }
  1679. getnstimeofday(&ts2);
  1680. mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
  1681. return 0;
  1682. }
  1683. static int mmc_test_large_seq_perf(struct mmc_test_card *test, int write)
  1684. {
  1685. int ret, i;
  1686. for (i = 0; i < 10; i++) {
  1687. ret = mmc_test_seq_perf(test, write, 10 * 1024 * 1024, 1);
  1688. if (ret)
  1689. return ret;
  1690. }
  1691. for (i = 0; i < 5; i++) {
  1692. ret = mmc_test_seq_perf(test, write, 100 * 1024 * 1024, 1);
  1693. if (ret)
  1694. return ret;
  1695. }
  1696. for (i = 0; i < 3; i++) {
  1697. ret = mmc_test_seq_perf(test, write, 1000 * 1024 * 1024, 1);
  1698. if (ret)
  1699. return ret;
  1700. }
  1701. return ret;
  1702. }
  1703. /*
  1704. * Large sequential read performance.
  1705. */
  1706. static int mmc_test_large_seq_read_perf(struct mmc_test_card *test)
  1707. {
  1708. return mmc_test_large_seq_perf(test, 0);
  1709. }
  1710. /*
  1711. * Large sequential write performance.
  1712. */
  1713. static int mmc_test_large_seq_write_perf(struct mmc_test_card *test)
  1714. {
  1715. return mmc_test_large_seq_perf(test, 1);
  1716. }
  1717. static int mmc_test_rw_multiple(struct mmc_test_card *test,
  1718. struct mmc_test_multiple_rw *tdata,
  1719. unsigned int reqsize, unsigned int size,
  1720. int min_sg_len)
  1721. {
  1722. unsigned int dev_addr;
  1723. struct mmc_test_area *t = &test->area;
  1724. int ret = 0;
  1725. /* Set up test area */
  1726. if (size > mmc_test_capacity(test->card) / 2 * 512)
  1727. size = mmc_test_capacity(test->card) / 2 * 512;
  1728. if (reqsize > t->max_tfr)
  1729. reqsize = t->max_tfr;
  1730. dev_addr = mmc_test_capacity(test->card) / 4;
  1731. if ((dev_addr & 0xffff0000))
  1732. dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
  1733. else
  1734. dev_addr &= 0xfffff800; /* Round to 1MiB boundary */
  1735. if (!dev_addr)
  1736. goto err;
  1737. if (reqsize > size)
  1738. return 0;
  1739. /* prepare test area */
  1740. if (mmc_can_erase(test->card) &&
  1741. tdata->prepare & MMC_TEST_PREP_ERASE) {
  1742. ret = mmc_erase(test->card, dev_addr,
  1743. size / 512, MMC_SECURE_ERASE_ARG);
  1744. if (ret)
  1745. ret = mmc_erase(test->card, dev_addr,
  1746. size / 512, MMC_ERASE_ARG);
  1747. if (ret)
  1748. goto err;
  1749. }
  1750. /* Run test */
  1751. ret = mmc_test_area_io_seq(test, reqsize, dev_addr,
  1752. tdata->do_write, 0, 1, size / reqsize,
  1753. tdata->do_nonblock_req, min_sg_len);
  1754. if (ret)
  1755. goto err;
  1756. return ret;
  1757. err:
  1758. pr_info("[%s] error\n", __func__);
  1759. return ret;
  1760. }
  1761. static int mmc_test_rw_multiple_size(struct mmc_test_card *test,
  1762. struct mmc_test_multiple_rw *rw)
  1763. {
  1764. int ret = 0;
  1765. int i;
  1766. void *pre_req = test->card->host->ops->pre_req;
  1767. void *post_req = test->card->host->ops->post_req;
  1768. if (rw->do_nonblock_req &&
  1769. ((!pre_req && post_req) || (pre_req && !post_req))) {
  1770. pr_info("error: only one of pre/post is defined\n");
  1771. return -EINVAL;
  1772. }
  1773. for (i = 0 ; i < rw->len && ret == 0; i++) {
  1774. ret = mmc_test_rw_multiple(test, rw, rw->bs[i], rw->size, 0);
  1775. if (ret)
  1776. break;
  1777. }
  1778. return ret;
  1779. }
  1780. static int mmc_test_rw_multiple_sg_len(struct mmc_test_card *test,
  1781. struct mmc_test_multiple_rw *rw)
  1782. {
  1783. int ret = 0;
  1784. int i;
  1785. for (i = 0 ; i < rw->len && ret == 0; i++) {
  1786. ret = mmc_test_rw_multiple(test, rw, 512 * 1024, rw->size,
  1787. rw->sg_len[i]);
  1788. if (ret)
  1789. break;
  1790. }
  1791. return ret;
  1792. }
  1793. /*
  1794. * Multiple blocking write 4k to 4 MB chunks
  1795. */
  1796. static int mmc_test_profile_mult_write_blocking_perf(struct mmc_test_card *test)
  1797. {
  1798. unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
  1799. 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
  1800. struct mmc_test_multiple_rw test_data = {
  1801. .bs = bs,
  1802. .size = TEST_AREA_MAX_SIZE,
  1803. .len = ARRAY_SIZE(bs),
  1804. .do_write = true,
  1805. .do_nonblock_req = false,
  1806. .prepare = MMC_TEST_PREP_ERASE,
  1807. };
  1808. return mmc_test_rw_multiple_size(test, &test_data);
  1809. };
  1810. /*
  1811. * Multiple non-blocking write 4k to 4 MB chunks
  1812. */
  1813. static int mmc_test_profile_mult_write_nonblock_perf(struct mmc_test_card *test)
  1814. {
  1815. unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
  1816. 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
  1817. struct mmc_test_multiple_rw test_data = {
  1818. .bs = bs,
  1819. .size = TEST_AREA_MAX_SIZE,
  1820. .len = ARRAY_SIZE(bs),
  1821. .do_write = true,
  1822. .do_nonblock_req = true,
  1823. .prepare = MMC_TEST_PREP_ERASE,
  1824. };
  1825. return mmc_test_rw_multiple_size(test, &test_data);
  1826. }
  1827. /*
  1828. * Multiple blocking read 4k to 4 MB chunks
  1829. */
  1830. static int mmc_test_profile_mult_read_blocking_perf(struct mmc_test_card *test)
  1831. {
  1832. unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
  1833. 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
  1834. struct mmc_test_multiple_rw test_data = {
  1835. .bs = bs,
  1836. .size = TEST_AREA_MAX_SIZE,
  1837. .len = ARRAY_SIZE(bs),
  1838. .do_write = false,
  1839. .do_nonblock_req = false,
  1840. .prepare = MMC_TEST_PREP_NONE,
  1841. };
  1842. return mmc_test_rw_multiple_size(test, &test_data);
  1843. }
  1844. /*
  1845. * Multiple non-blocking read 4k to 4 MB chunks
  1846. */
  1847. static int mmc_test_profile_mult_read_nonblock_perf(struct mmc_test_card *test)
  1848. {
  1849. unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
  1850. 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
  1851. struct mmc_test_multiple_rw test_data = {
  1852. .bs = bs,
  1853. .size = TEST_AREA_MAX_SIZE,
  1854. .len = ARRAY_SIZE(bs),
  1855. .do_write = false,
  1856. .do_nonblock_req = true,
  1857. .prepare = MMC_TEST_PREP_NONE,
  1858. };
  1859. return mmc_test_rw_multiple_size(test, &test_data);
  1860. }
  1861. /*
  1862. * Multiple blocking write 1 to 512 sg elements
  1863. */
  1864. static int mmc_test_profile_sglen_wr_blocking_perf(struct mmc_test_card *test)
  1865. {
  1866. unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
  1867. 1 << 7, 1 << 8, 1 << 9};
  1868. struct mmc_test_multiple_rw test_data = {
  1869. .sg_len = sg_len,
  1870. .size = TEST_AREA_MAX_SIZE,
  1871. .len = ARRAY_SIZE(sg_len),
  1872. .do_write = true,
  1873. .do_nonblock_req = false,
  1874. .prepare = MMC_TEST_PREP_ERASE,
  1875. };
  1876. return mmc_test_rw_multiple_sg_len(test, &test_data);
  1877. };
  1878. /*
  1879. * Multiple non-blocking write 1 to 512 sg elements
  1880. */
  1881. static int mmc_test_profile_sglen_wr_nonblock_perf(struct mmc_test_card *test)
  1882. {
  1883. unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
  1884. 1 << 7, 1 << 8, 1 << 9};
  1885. struct mmc_test_multiple_rw test_data = {
  1886. .sg_len = sg_len,
  1887. .size = TEST_AREA_MAX_SIZE,
  1888. .len = ARRAY_SIZE(sg_len),
  1889. .do_write = true,
  1890. .do_nonblock_req = true,
  1891. .prepare = MMC_TEST_PREP_ERASE,
  1892. };
  1893. return mmc_test_rw_multiple_sg_len(test, &test_data);
  1894. }
  1895. /*
  1896. * Multiple blocking read 1 to 512 sg elements
  1897. */
  1898. static int mmc_test_profile_sglen_r_blocking_perf(struct mmc_test_card *test)
  1899. {
  1900. unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
  1901. 1 << 7, 1 << 8, 1 << 9};
  1902. struct mmc_test_multiple_rw test_data = {
  1903. .sg_len = sg_len,
  1904. .size = TEST_AREA_MAX_SIZE,
  1905. .len = ARRAY_SIZE(sg_len),
  1906. .do_write = false,
  1907. .do_nonblock_req = false,
  1908. .prepare = MMC_TEST_PREP_NONE,
  1909. };
  1910. return mmc_test_rw_multiple_sg_len(test, &test_data);
  1911. }
  1912. /*
  1913. * Multiple non-blocking read 1 to 512 sg elements
  1914. */
  1915. static int mmc_test_profile_sglen_r_nonblock_perf(struct mmc_test_card *test)
  1916. {
  1917. unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
  1918. 1 << 7, 1 << 8, 1 << 9};
  1919. struct mmc_test_multiple_rw test_data = {
  1920. .sg_len = sg_len,
  1921. .size = TEST_AREA_MAX_SIZE,
  1922. .len = ARRAY_SIZE(sg_len),
  1923. .do_write = false,
  1924. .do_nonblock_req = true,
  1925. .prepare = MMC_TEST_PREP_NONE,
  1926. };
  1927. return mmc_test_rw_multiple_sg_len(test, &test_data);
  1928. }
  1929. /*
  1930. * eMMC hardware reset.
  1931. */
  1932. static int mmc_test_reset(struct mmc_test_card *test)
  1933. {
  1934. struct mmc_card *card = test->card;
  1935. struct mmc_host *host = card->host;
  1936. int err;
  1937. err = mmc_hw_reset(host);
  1938. if (!err)
  1939. return RESULT_OK;
  1940. else if (err == -EOPNOTSUPP)
  1941. return RESULT_UNSUP_HOST;
  1942. return RESULT_FAIL;
  1943. }
  1944. struct mmc_test_req {
  1945. struct mmc_request mrq;
  1946. struct mmc_command sbc;
  1947. struct mmc_command cmd;
  1948. struct mmc_command stop;
  1949. struct mmc_command status;
  1950. struct mmc_data data;
  1951. };
  1952. static struct mmc_test_req *mmc_test_req_alloc(void)
  1953. {
  1954. struct mmc_test_req *rq = kzalloc(sizeof(*rq), GFP_KERNEL);
  1955. if (rq) {
  1956. rq->mrq.cmd = &rq->cmd;
  1957. rq->mrq.data = &rq->data;
  1958. rq->mrq.stop = &rq->stop;
  1959. }
  1960. return rq;
  1961. }
  1962. static int mmc_test_send_status(struct mmc_test_card *test,
  1963. struct mmc_command *cmd)
  1964. {
  1965. memset(cmd, 0, sizeof(*cmd));
  1966. cmd->opcode = MMC_SEND_STATUS;
  1967. if (!mmc_host_is_spi(test->card->host))
  1968. cmd->arg = test->card->rca << 16;
  1969. cmd->flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
  1970. return mmc_wait_for_cmd(test->card->host, cmd, 0);
  1971. }
  1972. static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
  1973. unsigned int dev_addr, int use_sbc,
  1974. int repeat_cmd, int write, int use_areq)
  1975. {
  1976. struct mmc_test_req *rq = mmc_test_req_alloc();
  1977. struct mmc_host *host = test->card->host;
  1978. struct mmc_test_area *t = &test->area;
  1979. struct mmc_test_async_req test_areq = { .test = test };
  1980. struct mmc_request *mrq;
  1981. unsigned long timeout;
  1982. bool expired = false;
  1983. enum mmc_blk_status blkstat = MMC_BLK_SUCCESS;
  1984. int ret = 0, cmd_ret;
  1985. u32 status = 0;
  1986. int count = 0;
  1987. if (!rq)
  1988. return -ENOMEM;
  1989. mrq = &rq->mrq;
  1990. if (use_sbc)
  1991. mrq->sbc = &rq->sbc;
  1992. mrq->cap_cmd_during_tfr = true;
  1993. test_areq.areq.mrq = mrq;
  1994. test_areq.areq.err_check = mmc_test_check_result_async;
  1995. mmc_test_prepare_mrq(test, mrq, t->sg, t->sg_len, dev_addr, t->blocks,
  1996. 512, write);
  1997. if (use_sbc && t->blocks > 1 && !mrq->sbc) {
  1998. ret = mmc_host_cmd23(host) ?
  1999. RESULT_UNSUP_CARD :
  2000. RESULT_UNSUP_HOST;
  2001. goto out_free;
  2002. }
  2003. /* Start ongoing data request */
  2004. if (use_areq) {
  2005. mmc_start_req(host, &test_areq.areq, &blkstat);
  2006. if (blkstat != MMC_BLK_SUCCESS) {
  2007. ret = RESULT_FAIL;
  2008. goto out_free;
  2009. }
  2010. } else {
  2011. mmc_wait_for_req(host, mrq);
  2012. }
  2013. timeout = jiffies + msecs_to_jiffies(3000);
  2014. do {
  2015. count += 1;
  2016. /* Send status command while data transfer in progress */
  2017. cmd_ret = mmc_test_send_status(test, &rq->status);
  2018. if (cmd_ret)
  2019. break;
  2020. status = rq->status.resp[0];
  2021. if (status & R1_ERROR) {
  2022. cmd_ret = -EIO;
  2023. break;
  2024. }
  2025. if (mmc_is_req_done(host, mrq))
  2026. break;
  2027. expired = time_after(jiffies, timeout);
  2028. if (expired) {
  2029. pr_info("%s: timeout waiting for Tran state status %#x\n",
  2030. mmc_hostname(host), status);
  2031. cmd_ret = -ETIMEDOUT;
  2032. break;
  2033. }
  2034. } while (repeat_cmd && R1_CURRENT_STATE(status) != R1_STATE_TRAN);
  2035. /* Wait for data request to complete */
  2036. if (use_areq) {
  2037. mmc_start_req(host, NULL, &blkstat);
  2038. if (blkstat != MMC_BLK_SUCCESS)
  2039. ret = RESULT_FAIL;
  2040. } else {
  2041. mmc_wait_for_req_done(test->card->host, mrq);
  2042. }
  2043. /*
  2044. * For cap_cmd_during_tfr request, upper layer must send stop if
  2045. * required.
  2046. */
  2047. if (mrq->data->stop && (mrq->data->error || !mrq->sbc)) {
  2048. if (ret)
  2049. mmc_wait_for_cmd(host, mrq->data->stop, 0);
  2050. else
  2051. ret = mmc_wait_for_cmd(host, mrq->data->stop, 0);
  2052. }
  2053. if (ret)
  2054. goto out_free;
  2055. if (cmd_ret) {
  2056. pr_info("%s: Send Status failed: status %#x, error %d\n",
  2057. mmc_hostname(test->card->host), status, cmd_ret);
  2058. }
  2059. ret = mmc_test_check_result(test, mrq);
  2060. if (ret)
  2061. goto out_free;
  2062. ret = mmc_test_wait_busy(test);
  2063. if (ret)
  2064. goto out_free;
  2065. if (repeat_cmd && (t->blocks + 1) << 9 > t->max_tfr)
  2066. pr_info("%s: %d commands completed during transfer of %u blocks\n",
  2067. mmc_hostname(test->card->host), count, t->blocks);
  2068. if (cmd_ret)
  2069. ret = cmd_ret;
  2070. out_free:
  2071. kfree(rq);
  2072. return ret;
  2073. }
  2074. static int __mmc_test_cmds_during_tfr(struct mmc_test_card *test,
  2075. unsigned long sz, int use_sbc, int write,
  2076. int use_areq)
  2077. {
  2078. struct mmc_test_area *t = &test->area;
  2079. int ret;
  2080. if (!(test->card->host->caps & MMC_CAP_CMD_DURING_TFR))
  2081. return RESULT_UNSUP_HOST;
  2082. ret = mmc_test_area_map(test, sz, 0, 0);
  2083. if (ret)
  2084. return ret;
  2085. ret = mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 0, write,
  2086. use_areq);
  2087. if (ret)
  2088. return ret;
  2089. return mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 1, write,
  2090. use_areq);
  2091. }
  2092. static int mmc_test_cmds_during_tfr(struct mmc_test_card *test, int use_sbc,
  2093. int write, int use_areq)
  2094. {
  2095. struct mmc_test_area *t = &test->area;
  2096. unsigned long sz;
  2097. int ret;
  2098. for (sz = 512; sz <= t->max_tfr; sz += 512) {
  2099. ret = __mmc_test_cmds_during_tfr(test, sz, use_sbc, write,
  2100. use_areq);
  2101. if (ret)
  2102. return ret;
  2103. }
  2104. return 0;
  2105. }
  2106. /*
  2107. * Commands during read - no Set Block Count (CMD23).
  2108. */
  2109. static int mmc_test_cmds_during_read(struct mmc_test_card *test)
  2110. {
  2111. return mmc_test_cmds_during_tfr(test, 0, 0, 0);
  2112. }
  2113. /*
  2114. * Commands during write - no Set Block Count (CMD23).
  2115. */
  2116. static int mmc_test_cmds_during_write(struct mmc_test_card *test)
  2117. {
  2118. return mmc_test_cmds_during_tfr(test, 0, 1, 0);
  2119. }
  2120. /*
  2121. * Commands during read - use Set Block Count (CMD23).
  2122. */
  2123. static int mmc_test_cmds_during_read_cmd23(struct mmc_test_card *test)
  2124. {
  2125. return mmc_test_cmds_during_tfr(test, 1, 0, 0);
  2126. }
  2127. /*
  2128. * Commands during write - use Set Block Count (CMD23).
  2129. */
  2130. static int mmc_test_cmds_during_write_cmd23(struct mmc_test_card *test)
  2131. {
  2132. return mmc_test_cmds_during_tfr(test, 1, 1, 0);
  2133. }
  2134. /*
  2135. * Commands during non-blocking read - use Set Block Count (CMD23).
  2136. */
  2137. static int mmc_test_cmds_during_read_cmd23_nonblock(struct mmc_test_card *test)
  2138. {
  2139. return mmc_test_cmds_during_tfr(test, 1, 0, 1);
  2140. }
  2141. /*
  2142. * Commands during non-blocking write - use Set Block Count (CMD23).
  2143. */
  2144. static int mmc_test_cmds_during_write_cmd23_nonblock(struct mmc_test_card *test)
  2145. {
  2146. return mmc_test_cmds_during_tfr(test, 1, 1, 1);
  2147. }
  2148. static const struct mmc_test_case mmc_test_cases[] = {
  2149. {
  2150. .name = "Basic write (no data verification)",
  2151. .run = mmc_test_basic_write,
  2152. },
  2153. {
  2154. .name = "Basic read (no data verification)",
  2155. .run = mmc_test_basic_read,
  2156. },
  2157. {
  2158. .name = "Basic write (with data verification)",
  2159. .prepare = mmc_test_prepare_write,
  2160. .run = mmc_test_verify_write,
  2161. .cleanup = mmc_test_cleanup,
  2162. },
  2163. {
  2164. .name = "Basic read (with data verification)",
  2165. .prepare = mmc_test_prepare_read,
  2166. .run = mmc_test_verify_read,
  2167. .cleanup = mmc_test_cleanup,
  2168. },
  2169. {
  2170. .name = "Multi-block write",
  2171. .prepare = mmc_test_prepare_write,
  2172. .run = mmc_test_multi_write,
  2173. .cleanup = mmc_test_cleanup,
  2174. },
  2175. {
  2176. .name = "Multi-block read",
  2177. .prepare = mmc_test_prepare_read,
  2178. .run = mmc_test_multi_read,
  2179. .cleanup = mmc_test_cleanup,
  2180. },
  2181. {
  2182. .name = "Power of two block writes",
  2183. .prepare = mmc_test_prepare_write,
  2184. .run = mmc_test_pow2_write,
  2185. .cleanup = mmc_test_cleanup,
  2186. },
  2187. {
  2188. .name = "Power of two block reads",
  2189. .prepare = mmc_test_prepare_read,
  2190. .run = mmc_test_pow2_read,
  2191. .cleanup = mmc_test_cleanup,
  2192. },
  2193. {
  2194. .name = "Weird sized block writes",
  2195. .prepare = mmc_test_prepare_write,
  2196. .run = mmc_test_weird_write,
  2197. .cleanup = mmc_test_cleanup,
  2198. },
  2199. {
  2200. .name = "Weird sized block reads",
  2201. .prepare = mmc_test_prepare_read,
  2202. .run = mmc_test_weird_read,
  2203. .cleanup = mmc_test_cleanup,
  2204. },
  2205. {
  2206. .name = "Badly aligned write",
  2207. .prepare = mmc_test_prepare_write,
  2208. .run = mmc_test_align_write,
  2209. .cleanup = mmc_test_cleanup,
  2210. },
  2211. {
  2212. .name = "Badly aligned read",
  2213. .prepare = mmc_test_prepare_read,
  2214. .run = mmc_test_align_read,
  2215. .cleanup = mmc_test_cleanup,
  2216. },
  2217. {
  2218. .name = "Badly aligned multi-block write",
  2219. .prepare = mmc_test_prepare_write,
  2220. .run = mmc_test_align_multi_write,
  2221. .cleanup = mmc_test_cleanup,
  2222. },
  2223. {
  2224. .name = "Badly aligned multi-block read",
  2225. .prepare = mmc_test_prepare_read,
  2226. .run = mmc_test_align_multi_read,
  2227. .cleanup = mmc_test_cleanup,
  2228. },
  2229. {
  2230. .name = "Correct xfer_size at write (start failure)",
  2231. .run = mmc_test_xfersize_write,
  2232. },
  2233. {
  2234. .name = "Correct xfer_size at read (start failure)",
  2235. .run = mmc_test_xfersize_read,
  2236. },
  2237. {
  2238. .name = "Correct xfer_size at write (midway failure)",
  2239. .run = mmc_test_multi_xfersize_write,
  2240. },
  2241. {
  2242. .name = "Correct xfer_size at read (midway failure)",
  2243. .run = mmc_test_multi_xfersize_read,
  2244. },
  2245. #ifdef CONFIG_HIGHMEM
  2246. {
  2247. .name = "Highmem write",
  2248. .prepare = mmc_test_prepare_write,
  2249. .run = mmc_test_write_high,
  2250. .cleanup = mmc_test_cleanup,
  2251. },
  2252. {
  2253. .name = "Highmem read",
  2254. .prepare = mmc_test_prepare_read,
  2255. .run = mmc_test_read_high,
  2256. .cleanup = mmc_test_cleanup,
  2257. },
  2258. {
  2259. .name = "Multi-block highmem write",
  2260. .prepare = mmc_test_prepare_write,
  2261. .run = mmc_test_multi_write_high,
  2262. .cleanup = mmc_test_cleanup,
  2263. },
  2264. {
  2265. .name = "Multi-block highmem read",
  2266. .prepare = mmc_test_prepare_read,
  2267. .run = mmc_test_multi_read_high,
  2268. .cleanup = mmc_test_cleanup,
  2269. },
  2270. #else
  2271. {
  2272. .name = "Highmem write",
  2273. .run = mmc_test_no_highmem,
  2274. },
  2275. {
  2276. .name = "Highmem read",
  2277. .run = mmc_test_no_highmem,
  2278. },
  2279. {
  2280. .name = "Multi-block highmem write",
  2281. .run = mmc_test_no_highmem,
  2282. },
  2283. {
  2284. .name = "Multi-block highmem read",
  2285. .run = mmc_test_no_highmem,
  2286. },
  2287. #endif /* CONFIG_HIGHMEM */
  2288. {
  2289. .name = "Best-case read performance",
  2290. .prepare = mmc_test_area_prepare_fill,
  2291. .run = mmc_test_best_read_performance,
  2292. .cleanup = mmc_test_area_cleanup,
  2293. },
  2294. {
  2295. .name = "Best-case write performance",
  2296. .prepare = mmc_test_area_prepare_erase,
  2297. .run = mmc_test_best_write_performance,
  2298. .cleanup = mmc_test_area_cleanup,
  2299. },
  2300. {
  2301. .name = "Best-case read performance into scattered pages",
  2302. .prepare = mmc_test_area_prepare_fill,
  2303. .run = mmc_test_best_read_perf_max_scatter,
  2304. .cleanup = mmc_test_area_cleanup,
  2305. },
  2306. {
  2307. .name = "Best-case write performance from scattered pages",
  2308. .prepare = mmc_test_area_prepare_erase,
  2309. .run = mmc_test_best_write_perf_max_scatter,
  2310. .cleanup = mmc_test_area_cleanup,
  2311. },
  2312. {
  2313. .name = "Single read performance by transfer size",
  2314. .prepare = mmc_test_area_prepare_fill,
  2315. .run = mmc_test_profile_read_perf,
  2316. .cleanup = mmc_test_area_cleanup,
  2317. },
  2318. {
  2319. .name = "Single write performance by transfer size",
  2320. .prepare = mmc_test_area_prepare,
  2321. .run = mmc_test_profile_write_perf,
  2322. .cleanup = mmc_test_area_cleanup,
  2323. },
  2324. {
  2325. .name = "Single trim performance by transfer size",
  2326. .prepare = mmc_test_area_prepare_fill,
  2327. .run = mmc_test_profile_trim_perf,
  2328. .cleanup = mmc_test_area_cleanup,
  2329. },
  2330. {
  2331. .name = "Consecutive read performance by transfer size",
  2332. .prepare = mmc_test_area_prepare_fill,
  2333. .run = mmc_test_profile_seq_read_perf,
  2334. .cleanup = mmc_test_area_cleanup,
  2335. },
  2336. {
  2337. .name = "Consecutive write performance by transfer size",
  2338. .prepare = mmc_test_area_prepare,
  2339. .run = mmc_test_profile_seq_write_perf,
  2340. .cleanup = mmc_test_area_cleanup,
  2341. },
  2342. {
  2343. .name = "Consecutive trim performance by transfer size",
  2344. .prepare = mmc_test_area_prepare,
  2345. .run = mmc_test_profile_seq_trim_perf,
  2346. .cleanup = mmc_test_area_cleanup,
  2347. },
  2348. {
  2349. .name = "Random read performance by transfer size",
  2350. .prepare = mmc_test_area_prepare,
  2351. .run = mmc_test_random_read_perf,
  2352. .cleanup = mmc_test_area_cleanup,
  2353. },
  2354. {
  2355. .name = "Random write performance by transfer size",
  2356. .prepare = mmc_test_area_prepare,
  2357. .run = mmc_test_random_write_perf,
  2358. .cleanup = mmc_test_area_cleanup,
  2359. },
  2360. {
  2361. .name = "Large sequential read into scattered pages",
  2362. .prepare = mmc_test_area_prepare,
  2363. .run = mmc_test_large_seq_read_perf,
  2364. .cleanup = mmc_test_area_cleanup,
  2365. },
  2366. {
  2367. .name = "Large sequential write from scattered pages",
  2368. .prepare = mmc_test_area_prepare,
  2369. .run = mmc_test_large_seq_write_perf,
  2370. .cleanup = mmc_test_area_cleanup,
  2371. },
  2372. {
  2373. .name = "Write performance with blocking req 4k to 4MB",
  2374. .prepare = mmc_test_area_prepare,
  2375. .run = mmc_test_profile_mult_write_blocking_perf,
  2376. .cleanup = mmc_test_area_cleanup,
  2377. },
  2378. {
  2379. .name = "Write performance with non-blocking req 4k to 4MB",
  2380. .prepare = mmc_test_area_prepare,
  2381. .run = mmc_test_profile_mult_write_nonblock_perf,
  2382. .cleanup = mmc_test_area_cleanup,
  2383. },
  2384. {
  2385. .name = "Read performance with blocking req 4k to 4MB",
  2386. .prepare = mmc_test_area_prepare,
  2387. .run = mmc_test_profile_mult_read_blocking_perf,
  2388. .cleanup = mmc_test_area_cleanup,
  2389. },
  2390. {
  2391. .name = "Read performance with non-blocking req 4k to 4MB",
  2392. .prepare = mmc_test_area_prepare,
  2393. .run = mmc_test_profile_mult_read_nonblock_perf,
  2394. .cleanup = mmc_test_area_cleanup,
  2395. },
  2396. {
  2397. .name = "Write performance blocking req 1 to 512 sg elems",
  2398. .prepare = mmc_test_area_prepare,
  2399. .run = mmc_test_profile_sglen_wr_blocking_perf,
  2400. .cleanup = mmc_test_area_cleanup,
  2401. },
  2402. {
  2403. .name = "Write performance non-blocking req 1 to 512 sg elems",
  2404. .prepare = mmc_test_area_prepare,
  2405. .run = mmc_test_profile_sglen_wr_nonblock_perf,
  2406. .cleanup = mmc_test_area_cleanup,
  2407. },
  2408. {
  2409. .name = "Read performance blocking req 1 to 512 sg elems",
  2410. .prepare = mmc_test_area_prepare,
  2411. .run = mmc_test_profile_sglen_r_blocking_perf,
  2412. .cleanup = mmc_test_area_cleanup,
  2413. },
  2414. {
  2415. .name = "Read performance non-blocking req 1 to 512 sg elems",
  2416. .prepare = mmc_test_area_prepare,
  2417. .run = mmc_test_profile_sglen_r_nonblock_perf,
  2418. .cleanup = mmc_test_area_cleanup,
  2419. },
  2420. {
  2421. .name = "Reset test",
  2422. .run = mmc_test_reset,
  2423. },
  2424. {
  2425. .name = "Commands during read - no Set Block Count (CMD23)",
  2426. .prepare = mmc_test_area_prepare,
  2427. .run = mmc_test_cmds_during_read,
  2428. .cleanup = mmc_test_area_cleanup,
  2429. },
  2430. {
  2431. .name = "Commands during write - no Set Block Count (CMD23)",
  2432. .prepare = mmc_test_area_prepare,
  2433. .run = mmc_test_cmds_during_write,
  2434. .cleanup = mmc_test_area_cleanup,
  2435. },
  2436. {
  2437. .name = "Commands during read - use Set Block Count (CMD23)",
  2438. .prepare = mmc_test_area_prepare,
  2439. .run = mmc_test_cmds_during_read_cmd23,
  2440. .cleanup = mmc_test_area_cleanup,
  2441. },
  2442. {
  2443. .name = "Commands during write - use Set Block Count (CMD23)",
  2444. .prepare = mmc_test_area_prepare,
  2445. .run = mmc_test_cmds_during_write_cmd23,
  2446. .cleanup = mmc_test_area_cleanup,
  2447. },
  2448. {
  2449. .name = "Commands during non-blocking read - use Set Block Count (CMD23)",
  2450. .prepare = mmc_test_area_prepare,
  2451. .run = mmc_test_cmds_during_read_cmd23_nonblock,
  2452. .cleanup = mmc_test_area_cleanup,
  2453. },
  2454. {
  2455. .name = "Commands during non-blocking write - use Set Block Count (CMD23)",
  2456. .prepare = mmc_test_area_prepare,
  2457. .run = mmc_test_cmds_during_write_cmd23_nonblock,
  2458. .cleanup = mmc_test_area_cleanup,
  2459. },
  2460. };
  2461. static DEFINE_MUTEX(mmc_test_lock);
  2462. static LIST_HEAD(mmc_test_result);
  2463. static void mmc_test_run(struct mmc_test_card *test, int testcase)
  2464. {
  2465. int i, ret;
  2466. pr_info("%s: Starting tests of card %s...\n",
  2467. mmc_hostname(test->card->host), mmc_card_id(test->card));
  2468. mmc_claim_host(test->card->host);
  2469. for (i = 0; i < ARRAY_SIZE(mmc_test_cases); i++) {
  2470. struct mmc_test_general_result *gr;
  2471. if (testcase && ((i + 1) != testcase))
  2472. continue;
  2473. pr_info("%s: Test case %d. %s...\n",
  2474. mmc_hostname(test->card->host), i + 1,
  2475. mmc_test_cases[i].name);
  2476. if (mmc_test_cases[i].prepare) {
  2477. ret = mmc_test_cases[i].prepare(test);
  2478. if (ret) {
  2479. pr_info("%s: Result: Prepare stage failed! (%d)\n",
  2480. mmc_hostname(test->card->host),
  2481. ret);
  2482. continue;
  2483. }
  2484. }
  2485. gr = kzalloc(sizeof(*gr), GFP_KERNEL);
  2486. if (gr) {
  2487. INIT_LIST_HEAD(&gr->tr_lst);
  2488. /* Assign data what we know already */
  2489. gr->card = test->card;
  2490. gr->testcase = i;
  2491. /* Append container to global one */
  2492. list_add_tail(&gr->link, &mmc_test_result);
  2493. /*
  2494. * Save the pointer to created container in our private
  2495. * structure.
  2496. */
  2497. test->gr = gr;
  2498. }
  2499. ret = mmc_test_cases[i].run(test);
  2500. switch (ret) {
  2501. case RESULT_OK:
  2502. pr_info("%s: Result: OK\n",
  2503. mmc_hostname(test->card->host));
  2504. break;
  2505. case RESULT_FAIL:
  2506. pr_info("%s: Result: FAILED\n",
  2507. mmc_hostname(test->card->host));
  2508. break;
  2509. case RESULT_UNSUP_HOST:
  2510. pr_info("%s: Result: UNSUPPORTED (by host)\n",
  2511. mmc_hostname(test->card->host));
  2512. break;
  2513. case RESULT_UNSUP_CARD:
  2514. pr_info("%s: Result: UNSUPPORTED (by card)\n",
  2515. mmc_hostname(test->card->host));
  2516. break;
  2517. default:
  2518. pr_info("%s: Result: ERROR (%d)\n",
  2519. mmc_hostname(test->card->host), ret);
  2520. }
  2521. /* Save the result */
  2522. if (gr)
  2523. gr->result = ret;
  2524. if (mmc_test_cases[i].cleanup) {
  2525. ret = mmc_test_cases[i].cleanup(test);
  2526. if (ret) {
  2527. pr_info("%s: Warning: Cleanup stage failed! (%d)\n",
  2528. mmc_hostname(test->card->host),
  2529. ret);
  2530. }
  2531. }
  2532. }
  2533. mmc_release_host(test->card->host);
  2534. pr_info("%s: Tests completed.\n",
  2535. mmc_hostname(test->card->host));
  2536. }
  2537. static void mmc_test_free_result(struct mmc_card *card)
  2538. {
  2539. struct mmc_test_general_result *gr, *grs;
  2540. mutex_lock(&mmc_test_lock);
  2541. list_for_each_entry_safe(gr, grs, &mmc_test_result, link) {
  2542. struct mmc_test_transfer_result *tr, *trs;
  2543. if (card && gr->card != card)
  2544. continue;
  2545. list_for_each_entry_safe(tr, trs, &gr->tr_lst, link) {
  2546. list_del(&tr->link);
  2547. kfree(tr);
  2548. }
  2549. list_del(&gr->link);
  2550. kfree(gr);
  2551. }
  2552. mutex_unlock(&mmc_test_lock);
  2553. }
  2554. static LIST_HEAD(mmc_test_file_test);
  2555. static int mtf_test_show(struct seq_file *sf, void *data)
  2556. {
  2557. struct mmc_card *card = (struct mmc_card *)sf->private;
  2558. struct mmc_test_general_result *gr;
  2559. mutex_lock(&mmc_test_lock);
  2560. list_for_each_entry(gr, &mmc_test_result, link) {
  2561. struct mmc_test_transfer_result *tr;
  2562. if (gr->card != card)
  2563. continue;
  2564. seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
  2565. list_for_each_entry(tr, &gr->tr_lst, link) {
  2566. seq_printf(sf, "%u %d %lu.%09lu %u %u.%02u\n",
  2567. tr->count, tr->sectors,
  2568. (unsigned long)tr->ts.tv_sec,
  2569. (unsigned long)tr->ts.tv_nsec,
  2570. tr->rate, tr->iops / 100, tr->iops % 100);
  2571. }
  2572. }
  2573. mutex_unlock(&mmc_test_lock);
  2574. return 0;
  2575. }
  2576. static int mtf_test_open(struct inode *inode, struct file *file)
  2577. {
  2578. return single_open(file, mtf_test_show, inode->i_private);
  2579. }
  2580. static ssize_t mtf_test_write(struct file *file, const char __user *buf,
  2581. size_t count, loff_t *pos)
  2582. {
  2583. struct seq_file *sf = (struct seq_file *)file->private_data;
  2584. struct mmc_card *card = (struct mmc_card *)sf->private;
  2585. struct mmc_test_card *test;
  2586. long testcase;
  2587. int ret;
  2588. ret = kstrtol_from_user(buf, count, 10, &testcase);
  2589. if (ret)
  2590. return ret;
  2591. test = kzalloc(sizeof(*test), GFP_KERNEL);
  2592. if (!test)
  2593. return -ENOMEM;
  2594. /*
  2595. * Remove all test cases associated with given card. Thus we have only
  2596. * actual data of the last run.
  2597. */
  2598. mmc_test_free_result(card);
  2599. test->card = card;
  2600. test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL);
  2601. #ifdef CONFIG_HIGHMEM
  2602. test->highmem = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, BUFFER_ORDER);
  2603. #endif
  2604. #ifdef CONFIG_HIGHMEM
  2605. if (test->buffer && test->highmem) {
  2606. #else
  2607. if (test->buffer) {
  2608. #endif
  2609. mutex_lock(&mmc_test_lock);
  2610. mmc_test_run(test, testcase);
  2611. mutex_unlock(&mmc_test_lock);
  2612. }
  2613. #ifdef CONFIG_HIGHMEM
  2614. __free_pages(test->highmem, BUFFER_ORDER);
  2615. #endif
  2616. kfree(test->buffer);
  2617. kfree(test);
  2618. return count;
  2619. }
  2620. static const struct file_operations mmc_test_fops_test = {
  2621. .open = mtf_test_open,
  2622. .read = seq_read,
  2623. .write = mtf_test_write,
  2624. .llseek = seq_lseek,
  2625. .release = single_release,
  2626. };
  2627. static int mtf_testlist_show(struct seq_file *sf, void *data)
  2628. {
  2629. int i;
  2630. mutex_lock(&mmc_test_lock);
  2631. seq_puts(sf, "0:\tRun all tests\n");
  2632. for (i = 0; i < ARRAY_SIZE(mmc_test_cases); i++)
  2633. seq_printf(sf, "%d:\t%s\n", i + 1, mmc_test_cases[i].name);
  2634. mutex_unlock(&mmc_test_lock);
  2635. return 0;
  2636. }
  2637. static int mtf_testlist_open(struct inode *inode, struct file *file)
  2638. {
  2639. return single_open(file, mtf_testlist_show, inode->i_private);
  2640. }
  2641. static const struct file_operations mmc_test_fops_testlist = {
  2642. .open = mtf_testlist_open,
  2643. .read = seq_read,
  2644. .llseek = seq_lseek,
  2645. .release = single_release,
  2646. };
  2647. static void mmc_test_free_dbgfs_file(struct mmc_card *card)
  2648. {
  2649. struct mmc_test_dbgfs_file *df, *dfs;
  2650. mutex_lock(&mmc_test_lock);
  2651. list_for_each_entry_safe(df, dfs, &mmc_test_file_test, link) {
  2652. if (card && df->card != card)
  2653. continue;
  2654. debugfs_remove(df->file);
  2655. list_del(&df->link);
  2656. kfree(df);
  2657. }
  2658. mutex_unlock(&mmc_test_lock);
  2659. }
  2660. static int __mmc_test_register_dbgfs_file(struct mmc_card *card,
  2661. const char *name, umode_t mode, const struct file_operations *fops)
  2662. {
  2663. struct dentry *file = NULL;
  2664. struct mmc_test_dbgfs_file *df;
  2665. if (card->debugfs_root)
  2666. file = debugfs_create_file(name, mode, card->debugfs_root,
  2667. card, fops);
  2668. if (IS_ERR_OR_NULL(file)) {
  2669. dev_err(&card->dev,
  2670. "Can't create %s. Perhaps debugfs is disabled.\n",
  2671. name);
  2672. return -ENODEV;
  2673. }
  2674. df = kmalloc(sizeof(*df), GFP_KERNEL);
  2675. if (!df) {
  2676. debugfs_remove(file);
  2677. dev_err(&card->dev,
  2678. "Can't allocate memory for internal usage.\n");
  2679. return -ENOMEM;
  2680. }
  2681. df->card = card;
  2682. df->file = file;
  2683. list_add(&df->link, &mmc_test_file_test);
  2684. return 0;
  2685. }
  2686. static int mmc_test_register_dbgfs_file(struct mmc_card *card)
  2687. {
  2688. int ret;
  2689. mutex_lock(&mmc_test_lock);
  2690. ret = __mmc_test_register_dbgfs_file(card, "test", S_IWUSR | S_IRUGO,
  2691. &mmc_test_fops_test);
  2692. if (ret)
  2693. goto err;
  2694. ret = __mmc_test_register_dbgfs_file(card, "testlist", S_IRUGO,
  2695. &mmc_test_fops_testlist);
  2696. if (ret)
  2697. goto err;
  2698. err:
  2699. mutex_unlock(&mmc_test_lock);
  2700. return ret;
  2701. }
  2702. static int mmc_test_probe(struct mmc_card *card)
  2703. {
  2704. int ret;
  2705. if (!mmc_card_mmc(card) && !mmc_card_sd(card))
  2706. return -ENODEV;
  2707. ret = mmc_test_register_dbgfs_file(card);
  2708. if (ret)
  2709. return ret;
  2710. dev_info(&card->dev, "Card claimed for testing.\n");
  2711. return 0;
  2712. }
  2713. static void mmc_test_remove(struct mmc_card *card)
  2714. {
  2715. mmc_test_free_result(card);
  2716. mmc_test_free_dbgfs_file(card);
  2717. }
  2718. static void mmc_test_shutdown(struct mmc_card *card)
  2719. {
  2720. }
  2721. static struct mmc_driver mmc_driver = {
  2722. .drv = {
  2723. .name = "mmc_test",
  2724. },
  2725. .probe = mmc_test_probe,
  2726. .remove = mmc_test_remove,
  2727. .shutdown = mmc_test_shutdown,
  2728. };
  2729. static int __init mmc_test_init(void)
  2730. {
  2731. return mmc_register_driver(&mmc_driver);
  2732. }
  2733. static void __exit mmc_test_exit(void)
  2734. {
  2735. /* Clear stalled data if card is still plugged */
  2736. mmc_test_free_result(NULL);
  2737. mmc_test_free_dbgfs_file(NULL);
  2738. mmc_unregister_driver(&mmc_driver);
  2739. }
  2740. module_init(mmc_test_init);
  2741. module_exit(mmc_test_exit);
  2742. MODULE_LICENSE("GPL");
  2743. MODULE_DESCRIPTION("Multimedia Card (MMC) host test driver");
  2744. MODULE_AUTHOR("Pierre Ossman");