mmc_test.c 75 KB

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