mmc_test.c 74 KB

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