mmc_test.c 75 KB

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