mmc_test.c 74 KB

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