mmc_test.c 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324
  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. /*
  677. * Tests nonblock transfer with certain parameters
  678. */
  679. static void mmc_test_nonblock_reset(struct mmc_request *mrq,
  680. struct mmc_command *cmd,
  681. struct mmc_command *stop,
  682. struct mmc_data *data)
  683. {
  684. memset(mrq, 0, sizeof(struct mmc_request));
  685. memset(cmd, 0, sizeof(struct mmc_command));
  686. memset(data, 0, sizeof(struct mmc_data));
  687. memset(stop, 0, sizeof(struct mmc_command));
  688. mrq->cmd = cmd;
  689. mrq->data = data;
  690. mrq->stop = stop;
  691. }
  692. static int mmc_test_nonblock_transfer(struct mmc_test_card *test,
  693. struct scatterlist *sg, unsigned sg_len,
  694. unsigned dev_addr, unsigned blocks,
  695. unsigned blksz, int write, int count)
  696. {
  697. struct mmc_request mrq1;
  698. struct mmc_command cmd1;
  699. struct mmc_command stop1;
  700. struct mmc_data data1;
  701. struct mmc_request mrq2;
  702. struct mmc_command cmd2;
  703. struct mmc_command stop2;
  704. struct mmc_data data2;
  705. struct mmc_test_async_req test_areq[2];
  706. struct mmc_async_req *done_areq;
  707. struct mmc_async_req *cur_areq = &test_areq[0].areq;
  708. struct mmc_async_req *other_areq = &test_areq[1].areq;
  709. enum mmc_blk_status status;
  710. int i;
  711. int ret = RESULT_OK;
  712. test_areq[0].test = test;
  713. test_areq[1].test = test;
  714. mmc_test_nonblock_reset(&mrq1, &cmd1, &stop1, &data1);
  715. mmc_test_nonblock_reset(&mrq2, &cmd2, &stop2, &data2);
  716. cur_areq->mrq = &mrq1;
  717. cur_areq->err_check = mmc_test_check_result_async;
  718. other_areq->mrq = &mrq2;
  719. other_areq->err_check = mmc_test_check_result_async;
  720. for (i = 0; i < count; i++) {
  721. mmc_test_prepare_mrq(test, cur_areq->mrq, sg, sg_len, dev_addr,
  722. blocks, blksz, write);
  723. done_areq = mmc_start_areq(test->card->host, cur_areq, &status);
  724. if (status != MMC_BLK_SUCCESS || (!done_areq && i > 0)) {
  725. ret = RESULT_FAIL;
  726. goto err;
  727. }
  728. if (done_areq) {
  729. if (done_areq->mrq == &mrq2)
  730. mmc_test_nonblock_reset(&mrq2, &cmd2,
  731. &stop2, &data2);
  732. else
  733. mmc_test_nonblock_reset(&mrq1, &cmd1,
  734. &stop1, &data1);
  735. }
  736. swap(cur_areq, other_areq);
  737. dev_addr += blocks;
  738. }
  739. done_areq = mmc_start_areq(test->card->host, NULL, &status);
  740. if (status != MMC_BLK_SUCCESS)
  741. ret = RESULT_FAIL;
  742. return ret;
  743. err:
  744. return ret;
  745. }
  746. /*
  747. * Tests a basic transfer with certain parameters
  748. */
  749. static int mmc_test_simple_transfer(struct mmc_test_card *test,
  750. struct scatterlist *sg, unsigned sg_len, unsigned dev_addr,
  751. unsigned blocks, unsigned blksz, int write)
  752. {
  753. struct mmc_request mrq = {};
  754. struct mmc_command cmd = {};
  755. struct mmc_command stop = {};
  756. struct mmc_data data = {};
  757. mrq.cmd = &cmd;
  758. mrq.data = &data;
  759. mrq.stop = &stop;
  760. mmc_test_prepare_mrq(test, &mrq, sg, sg_len, dev_addr,
  761. blocks, blksz, write);
  762. mmc_wait_for_req(test->card->host, &mrq);
  763. mmc_test_wait_busy(test);
  764. return mmc_test_check_result(test, &mrq);
  765. }
  766. /*
  767. * Tests a transfer where the card will fail completely or partly
  768. */
  769. static int mmc_test_broken_transfer(struct mmc_test_card *test,
  770. unsigned blocks, unsigned blksz, int write)
  771. {
  772. struct mmc_request mrq = {};
  773. struct mmc_command cmd = {};
  774. struct mmc_command stop = {};
  775. struct mmc_data data = {};
  776. struct scatterlist sg;
  777. mrq.cmd = &cmd;
  778. mrq.data = &data;
  779. mrq.stop = &stop;
  780. sg_init_one(&sg, test->buffer, blocks * blksz);
  781. mmc_test_prepare_mrq(test, &mrq, &sg, 1, 0, blocks, blksz, write);
  782. mmc_test_prepare_broken_mrq(test, &mrq, write);
  783. mmc_wait_for_req(test->card->host, &mrq);
  784. mmc_test_wait_busy(test);
  785. return mmc_test_check_broken_result(test, &mrq);
  786. }
  787. /*
  788. * Does a complete transfer test where data is also validated
  789. *
  790. * Note: mmc_test_prepare() must have been done before this call
  791. */
  792. static int mmc_test_transfer(struct mmc_test_card *test,
  793. struct scatterlist *sg, unsigned sg_len, unsigned dev_addr,
  794. unsigned blocks, unsigned blksz, int write)
  795. {
  796. int ret, i;
  797. unsigned long flags;
  798. if (write) {
  799. for (i = 0; i < blocks * blksz; i++)
  800. test->scratch[i] = i;
  801. } else {
  802. memset(test->scratch, 0, BUFFER_SIZE);
  803. }
  804. local_irq_save(flags);
  805. sg_copy_from_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
  806. local_irq_restore(flags);
  807. ret = mmc_test_set_blksize(test, blksz);
  808. if (ret)
  809. return ret;
  810. ret = mmc_test_simple_transfer(test, sg, sg_len, dev_addr,
  811. blocks, blksz, write);
  812. if (ret)
  813. return ret;
  814. if (write) {
  815. int sectors;
  816. ret = mmc_test_set_blksize(test, 512);
  817. if (ret)
  818. return ret;
  819. sectors = (blocks * blksz + 511) / 512;
  820. if ((sectors * 512) == (blocks * blksz))
  821. sectors++;
  822. if ((sectors * 512) > BUFFER_SIZE)
  823. return -EINVAL;
  824. memset(test->buffer, 0, sectors * 512);
  825. for (i = 0; i < sectors; i++) {
  826. ret = mmc_test_buffer_transfer(test,
  827. test->buffer + i * 512,
  828. dev_addr + i, 512, 0);
  829. if (ret)
  830. return ret;
  831. }
  832. for (i = 0; i < blocks * blksz; i++) {
  833. if (test->buffer[i] != (u8)i)
  834. return RESULT_FAIL;
  835. }
  836. for (; i < sectors * 512; i++) {
  837. if (test->buffer[i] != 0xDF)
  838. return RESULT_FAIL;
  839. }
  840. } else {
  841. local_irq_save(flags);
  842. sg_copy_to_buffer(sg, sg_len, test->scratch, BUFFER_SIZE);
  843. local_irq_restore(flags);
  844. for (i = 0; i < blocks * blksz; i++) {
  845. if (test->scratch[i] != (u8)i)
  846. return RESULT_FAIL;
  847. }
  848. }
  849. return 0;
  850. }
  851. /*******************************************************************/
  852. /* Tests */
  853. /*******************************************************************/
  854. struct mmc_test_case {
  855. const char *name;
  856. int (*prepare)(struct mmc_test_card *);
  857. int (*run)(struct mmc_test_card *);
  858. int (*cleanup)(struct mmc_test_card *);
  859. };
  860. static int mmc_test_basic_write(struct mmc_test_card *test)
  861. {
  862. int ret;
  863. struct scatterlist sg;
  864. ret = mmc_test_set_blksize(test, 512);
  865. if (ret)
  866. return ret;
  867. sg_init_one(&sg, test->buffer, 512);
  868. return mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 1);
  869. }
  870. static int mmc_test_basic_read(struct mmc_test_card *test)
  871. {
  872. int ret;
  873. struct scatterlist sg;
  874. ret = mmc_test_set_blksize(test, 512);
  875. if (ret)
  876. return ret;
  877. sg_init_one(&sg, test->buffer, 512);
  878. return mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 0);
  879. }
  880. static int mmc_test_verify_write(struct mmc_test_card *test)
  881. {
  882. struct scatterlist sg;
  883. sg_init_one(&sg, test->buffer, 512);
  884. return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
  885. }
  886. static int mmc_test_verify_read(struct mmc_test_card *test)
  887. {
  888. struct scatterlist sg;
  889. sg_init_one(&sg, test->buffer, 512);
  890. return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
  891. }
  892. static int mmc_test_multi_write(struct mmc_test_card *test)
  893. {
  894. unsigned int size;
  895. struct scatterlist sg;
  896. if (test->card->host->max_blk_count == 1)
  897. return RESULT_UNSUP_HOST;
  898. size = PAGE_SIZE * 2;
  899. size = min(size, test->card->host->max_req_size);
  900. size = min(size, test->card->host->max_seg_size);
  901. size = min(size, test->card->host->max_blk_count * 512);
  902. if (size < 1024)
  903. return RESULT_UNSUP_HOST;
  904. sg_init_one(&sg, test->buffer, size);
  905. return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
  906. }
  907. static int mmc_test_multi_read(struct mmc_test_card *test)
  908. {
  909. unsigned int size;
  910. struct scatterlist sg;
  911. if (test->card->host->max_blk_count == 1)
  912. return RESULT_UNSUP_HOST;
  913. size = PAGE_SIZE * 2;
  914. size = min(size, test->card->host->max_req_size);
  915. size = min(size, test->card->host->max_seg_size);
  916. size = min(size, test->card->host->max_blk_count * 512);
  917. if (size < 1024)
  918. return RESULT_UNSUP_HOST;
  919. sg_init_one(&sg, test->buffer, size);
  920. return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
  921. }
  922. static int mmc_test_pow2_write(struct mmc_test_card *test)
  923. {
  924. int ret, i;
  925. struct scatterlist sg;
  926. if (!test->card->csd.write_partial)
  927. return RESULT_UNSUP_CARD;
  928. for (i = 1; i < 512; i <<= 1) {
  929. sg_init_one(&sg, test->buffer, i);
  930. ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
  931. if (ret)
  932. return ret;
  933. }
  934. return 0;
  935. }
  936. static int mmc_test_pow2_read(struct mmc_test_card *test)
  937. {
  938. int ret, i;
  939. struct scatterlist sg;
  940. if (!test->card->csd.read_partial)
  941. return RESULT_UNSUP_CARD;
  942. for (i = 1; i < 512; i <<= 1) {
  943. sg_init_one(&sg, test->buffer, i);
  944. ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
  945. if (ret)
  946. return ret;
  947. }
  948. return 0;
  949. }
  950. static int mmc_test_weird_write(struct mmc_test_card *test)
  951. {
  952. int ret, i;
  953. struct scatterlist sg;
  954. if (!test->card->csd.write_partial)
  955. return RESULT_UNSUP_CARD;
  956. for (i = 3; i < 512; i += 7) {
  957. sg_init_one(&sg, test->buffer, i);
  958. ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1);
  959. if (ret)
  960. return ret;
  961. }
  962. return 0;
  963. }
  964. static int mmc_test_weird_read(struct mmc_test_card *test)
  965. {
  966. int ret, i;
  967. struct scatterlist sg;
  968. if (!test->card->csd.read_partial)
  969. return RESULT_UNSUP_CARD;
  970. for (i = 3; i < 512; i += 7) {
  971. sg_init_one(&sg, test->buffer, i);
  972. ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0);
  973. if (ret)
  974. return ret;
  975. }
  976. return 0;
  977. }
  978. static int mmc_test_align_write(struct mmc_test_card *test)
  979. {
  980. int ret, i;
  981. struct scatterlist sg;
  982. for (i = 1; i < TEST_ALIGN_END; i++) {
  983. sg_init_one(&sg, test->buffer + i, 512);
  984. ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
  985. if (ret)
  986. return ret;
  987. }
  988. return 0;
  989. }
  990. static int mmc_test_align_read(struct mmc_test_card *test)
  991. {
  992. int ret, i;
  993. struct scatterlist sg;
  994. for (i = 1; i < TEST_ALIGN_END; i++) {
  995. sg_init_one(&sg, test->buffer + i, 512);
  996. ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
  997. if (ret)
  998. return ret;
  999. }
  1000. return 0;
  1001. }
  1002. static int mmc_test_align_multi_write(struct mmc_test_card *test)
  1003. {
  1004. int ret, i;
  1005. unsigned int size;
  1006. struct scatterlist sg;
  1007. if (test->card->host->max_blk_count == 1)
  1008. return RESULT_UNSUP_HOST;
  1009. size = PAGE_SIZE * 2;
  1010. size = min(size, test->card->host->max_req_size);
  1011. size = min(size, test->card->host->max_seg_size);
  1012. size = min(size, test->card->host->max_blk_count * 512);
  1013. if (size < 1024)
  1014. return RESULT_UNSUP_HOST;
  1015. for (i = 1; i < TEST_ALIGN_END; i++) {
  1016. sg_init_one(&sg, test->buffer + i, size);
  1017. ret = mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
  1018. if (ret)
  1019. return ret;
  1020. }
  1021. return 0;
  1022. }
  1023. static int mmc_test_align_multi_read(struct mmc_test_card *test)
  1024. {
  1025. int ret, i;
  1026. unsigned int size;
  1027. struct scatterlist sg;
  1028. if (test->card->host->max_blk_count == 1)
  1029. return RESULT_UNSUP_HOST;
  1030. size = PAGE_SIZE * 2;
  1031. size = min(size, test->card->host->max_req_size);
  1032. size = min(size, test->card->host->max_seg_size);
  1033. size = min(size, test->card->host->max_blk_count * 512);
  1034. if (size < 1024)
  1035. return RESULT_UNSUP_HOST;
  1036. for (i = 1; i < TEST_ALIGN_END; i++) {
  1037. sg_init_one(&sg, test->buffer + i, size);
  1038. ret = mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
  1039. if (ret)
  1040. return ret;
  1041. }
  1042. return 0;
  1043. }
  1044. static int mmc_test_xfersize_write(struct mmc_test_card *test)
  1045. {
  1046. int ret;
  1047. ret = mmc_test_set_blksize(test, 512);
  1048. if (ret)
  1049. return ret;
  1050. return mmc_test_broken_transfer(test, 1, 512, 1);
  1051. }
  1052. static int mmc_test_xfersize_read(struct mmc_test_card *test)
  1053. {
  1054. int ret;
  1055. ret = mmc_test_set_blksize(test, 512);
  1056. if (ret)
  1057. return ret;
  1058. return mmc_test_broken_transfer(test, 1, 512, 0);
  1059. }
  1060. static int mmc_test_multi_xfersize_write(struct mmc_test_card *test)
  1061. {
  1062. int ret;
  1063. if (test->card->host->max_blk_count == 1)
  1064. return RESULT_UNSUP_HOST;
  1065. ret = mmc_test_set_blksize(test, 512);
  1066. if (ret)
  1067. return ret;
  1068. return mmc_test_broken_transfer(test, 2, 512, 1);
  1069. }
  1070. static int mmc_test_multi_xfersize_read(struct mmc_test_card *test)
  1071. {
  1072. int ret;
  1073. if (test->card->host->max_blk_count == 1)
  1074. return RESULT_UNSUP_HOST;
  1075. ret = mmc_test_set_blksize(test, 512);
  1076. if (ret)
  1077. return ret;
  1078. return mmc_test_broken_transfer(test, 2, 512, 0);
  1079. }
  1080. #ifdef CONFIG_HIGHMEM
  1081. static int mmc_test_write_high(struct mmc_test_card *test)
  1082. {
  1083. struct scatterlist sg;
  1084. sg_init_table(&sg, 1);
  1085. sg_set_page(&sg, test->highmem, 512, 0);
  1086. return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
  1087. }
  1088. static int mmc_test_read_high(struct mmc_test_card *test)
  1089. {
  1090. struct scatterlist sg;
  1091. sg_init_table(&sg, 1);
  1092. sg_set_page(&sg, test->highmem, 512, 0);
  1093. return mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
  1094. }
  1095. static int mmc_test_multi_write_high(struct mmc_test_card *test)
  1096. {
  1097. unsigned int size;
  1098. struct scatterlist sg;
  1099. if (test->card->host->max_blk_count == 1)
  1100. return RESULT_UNSUP_HOST;
  1101. size = PAGE_SIZE * 2;
  1102. size = min(size, test->card->host->max_req_size);
  1103. size = min(size, test->card->host->max_seg_size);
  1104. size = min(size, test->card->host->max_blk_count * 512);
  1105. if (size < 1024)
  1106. return RESULT_UNSUP_HOST;
  1107. sg_init_table(&sg, 1);
  1108. sg_set_page(&sg, test->highmem, size, 0);
  1109. return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 1);
  1110. }
  1111. static int mmc_test_multi_read_high(struct mmc_test_card *test)
  1112. {
  1113. unsigned int size;
  1114. struct scatterlist sg;
  1115. if (test->card->host->max_blk_count == 1)
  1116. return RESULT_UNSUP_HOST;
  1117. size = PAGE_SIZE * 2;
  1118. size = min(size, test->card->host->max_req_size);
  1119. size = min(size, test->card->host->max_seg_size);
  1120. size = min(size, test->card->host->max_blk_count * 512);
  1121. if (size < 1024)
  1122. return RESULT_UNSUP_HOST;
  1123. sg_init_table(&sg, 1);
  1124. sg_set_page(&sg, test->highmem, size, 0);
  1125. return mmc_test_transfer(test, &sg, 1, 0, size / 512, 512, 0);
  1126. }
  1127. #else
  1128. static int mmc_test_no_highmem(struct mmc_test_card *test)
  1129. {
  1130. pr_info("%s: Highmem not configured - test skipped\n",
  1131. mmc_hostname(test->card->host));
  1132. return 0;
  1133. }
  1134. #endif /* CONFIG_HIGHMEM */
  1135. /*
  1136. * Map sz bytes so that it can be transferred.
  1137. */
  1138. static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz,
  1139. int max_scatter, int min_sg_len)
  1140. {
  1141. struct mmc_test_area *t = &test->area;
  1142. int err;
  1143. t->blocks = sz >> 9;
  1144. if (max_scatter) {
  1145. err = mmc_test_map_sg_max_scatter(t->mem, sz, t->sg,
  1146. t->max_segs, t->max_seg_sz,
  1147. &t->sg_len);
  1148. } else {
  1149. err = mmc_test_map_sg(t->mem, sz, t->sg, 1, t->max_segs,
  1150. t->max_seg_sz, &t->sg_len, min_sg_len);
  1151. }
  1152. if (err)
  1153. pr_info("%s: Failed to map sg list\n",
  1154. mmc_hostname(test->card->host));
  1155. return err;
  1156. }
  1157. /*
  1158. * Transfer bytes mapped by mmc_test_area_map().
  1159. */
  1160. static int mmc_test_area_transfer(struct mmc_test_card *test,
  1161. unsigned int dev_addr, int write)
  1162. {
  1163. struct mmc_test_area *t = &test->area;
  1164. return mmc_test_simple_transfer(test, t->sg, t->sg_len, dev_addr,
  1165. t->blocks, 512, write);
  1166. }
  1167. /*
  1168. * Map and transfer bytes for multiple transfers.
  1169. */
  1170. static int mmc_test_area_io_seq(struct mmc_test_card *test, unsigned long sz,
  1171. unsigned int dev_addr, int write,
  1172. int max_scatter, int timed, int count,
  1173. bool nonblock, int min_sg_len)
  1174. {
  1175. struct timespec ts1, ts2;
  1176. int ret = 0;
  1177. int i;
  1178. struct mmc_test_area *t = &test->area;
  1179. /*
  1180. * In the case of a maximally scattered transfer, the maximum transfer
  1181. * size is further limited by using PAGE_SIZE segments.
  1182. */
  1183. if (max_scatter) {
  1184. struct mmc_test_area *t = &test->area;
  1185. unsigned long max_tfr;
  1186. if (t->max_seg_sz >= PAGE_SIZE)
  1187. max_tfr = t->max_segs * PAGE_SIZE;
  1188. else
  1189. max_tfr = t->max_segs * t->max_seg_sz;
  1190. if (sz > max_tfr)
  1191. sz = max_tfr;
  1192. }
  1193. ret = mmc_test_area_map(test, sz, max_scatter, min_sg_len);
  1194. if (ret)
  1195. return ret;
  1196. if (timed)
  1197. getnstimeofday(&ts1);
  1198. if (nonblock)
  1199. ret = mmc_test_nonblock_transfer(test, t->sg, t->sg_len,
  1200. dev_addr, t->blocks, 512, write, count);
  1201. else
  1202. for (i = 0; i < count && ret == 0; i++) {
  1203. ret = mmc_test_area_transfer(test, dev_addr, write);
  1204. dev_addr += sz >> 9;
  1205. }
  1206. if (ret)
  1207. return ret;
  1208. if (timed)
  1209. getnstimeofday(&ts2);
  1210. if (timed)
  1211. mmc_test_print_avg_rate(test, sz, count, &ts1, &ts2);
  1212. return 0;
  1213. }
  1214. static int mmc_test_area_io(struct mmc_test_card *test, unsigned long sz,
  1215. unsigned int dev_addr, int write, int max_scatter,
  1216. int timed)
  1217. {
  1218. return mmc_test_area_io_seq(test, sz, dev_addr, write, max_scatter,
  1219. timed, 1, false, 0);
  1220. }
  1221. /*
  1222. * Write the test area entirely.
  1223. */
  1224. static int mmc_test_area_fill(struct mmc_test_card *test)
  1225. {
  1226. struct mmc_test_area *t = &test->area;
  1227. return mmc_test_area_io(test, t->max_tfr, t->dev_addr, 1, 0, 0);
  1228. }
  1229. /*
  1230. * Erase the test area entirely.
  1231. */
  1232. static int mmc_test_area_erase(struct mmc_test_card *test)
  1233. {
  1234. struct mmc_test_area *t = &test->area;
  1235. if (!mmc_can_erase(test->card))
  1236. return 0;
  1237. return mmc_erase(test->card, t->dev_addr, t->max_sz >> 9,
  1238. MMC_ERASE_ARG);
  1239. }
  1240. /*
  1241. * Cleanup struct mmc_test_area.
  1242. */
  1243. static int mmc_test_area_cleanup(struct mmc_test_card *test)
  1244. {
  1245. struct mmc_test_area *t = &test->area;
  1246. kfree(t->sg);
  1247. mmc_test_free_mem(t->mem);
  1248. return 0;
  1249. }
  1250. /*
  1251. * Initialize an area for testing large transfers. The test area is set to the
  1252. * middle of the card because cards may have different characteristics at the
  1253. * front (for FAT file system optimization). Optionally, the area is erased
  1254. * (if the card supports it) which may improve write performance. Optionally,
  1255. * the area is filled with data for subsequent read tests.
  1256. */
  1257. static int mmc_test_area_init(struct mmc_test_card *test, int erase, int fill)
  1258. {
  1259. struct mmc_test_area *t = &test->area;
  1260. unsigned long min_sz = 64 * 1024, sz;
  1261. int ret;
  1262. ret = mmc_test_set_blksize(test, 512);
  1263. if (ret)
  1264. return ret;
  1265. /* Make the test area size about 4MiB */
  1266. sz = (unsigned long)test->card->pref_erase << 9;
  1267. t->max_sz = sz;
  1268. while (t->max_sz < 4 * 1024 * 1024)
  1269. t->max_sz += sz;
  1270. while (t->max_sz > TEST_AREA_MAX_SIZE && t->max_sz > sz)
  1271. t->max_sz -= sz;
  1272. t->max_segs = test->card->host->max_segs;
  1273. t->max_seg_sz = test->card->host->max_seg_size;
  1274. t->max_seg_sz -= t->max_seg_sz % 512;
  1275. t->max_tfr = t->max_sz;
  1276. if (t->max_tfr >> 9 > test->card->host->max_blk_count)
  1277. t->max_tfr = test->card->host->max_blk_count << 9;
  1278. if (t->max_tfr > test->card->host->max_req_size)
  1279. t->max_tfr = test->card->host->max_req_size;
  1280. if (t->max_tfr / t->max_seg_sz > t->max_segs)
  1281. t->max_tfr = t->max_segs * t->max_seg_sz;
  1282. /*
  1283. * Try to allocate enough memory for a max. sized transfer. Less is OK
  1284. * because the same memory can be mapped into the scatterlist more than
  1285. * once. Also, take into account the limits imposed on scatterlist
  1286. * segments by the host driver.
  1287. */
  1288. t->mem = mmc_test_alloc_mem(min_sz, t->max_tfr, t->max_segs,
  1289. t->max_seg_sz);
  1290. if (!t->mem)
  1291. return -ENOMEM;
  1292. t->sg = kmalloc_array(t->max_segs, sizeof(*t->sg), GFP_KERNEL);
  1293. if (!t->sg) {
  1294. ret = -ENOMEM;
  1295. goto out_free;
  1296. }
  1297. t->dev_addr = mmc_test_capacity(test->card) / 2;
  1298. t->dev_addr -= t->dev_addr % (t->max_sz >> 9);
  1299. if (erase) {
  1300. ret = mmc_test_area_erase(test);
  1301. if (ret)
  1302. goto out_free;
  1303. }
  1304. if (fill) {
  1305. ret = mmc_test_area_fill(test);
  1306. if (ret)
  1307. goto out_free;
  1308. }
  1309. return 0;
  1310. out_free:
  1311. mmc_test_area_cleanup(test);
  1312. return ret;
  1313. }
  1314. /*
  1315. * Prepare for large transfers. Do not erase the test area.
  1316. */
  1317. static int mmc_test_area_prepare(struct mmc_test_card *test)
  1318. {
  1319. return mmc_test_area_init(test, 0, 0);
  1320. }
  1321. /*
  1322. * Prepare for large transfers. Do erase the test area.
  1323. */
  1324. static int mmc_test_area_prepare_erase(struct mmc_test_card *test)
  1325. {
  1326. return mmc_test_area_init(test, 1, 0);
  1327. }
  1328. /*
  1329. * Prepare for large transfers. Erase and fill the test area.
  1330. */
  1331. static int mmc_test_area_prepare_fill(struct mmc_test_card *test)
  1332. {
  1333. return mmc_test_area_init(test, 1, 1);
  1334. }
  1335. /*
  1336. * Test best-case performance. Best-case performance is expected from
  1337. * a single large transfer.
  1338. *
  1339. * An additional option (max_scatter) allows the measurement of the same
  1340. * transfer but with no contiguous pages in the scatter list. This tests
  1341. * the efficiency of DMA to handle scattered pages.
  1342. */
  1343. static int mmc_test_best_performance(struct mmc_test_card *test, int write,
  1344. int max_scatter)
  1345. {
  1346. struct mmc_test_area *t = &test->area;
  1347. return mmc_test_area_io(test, t->max_tfr, t->dev_addr, write,
  1348. max_scatter, 1);
  1349. }
  1350. /*
  1351. * Best-case read performance.
  1352. */
  1353. static int mmc_test_best_read_performance(struct mmc_test_card *test)
  1354. {
  1355. return mmc_test_best_performance(test, 0, 0);
  1356. }
  1357. /*
  1358. * Best-case write performance.
  1359. */
  1360. static int mmc_test_best_write_performance(struct mmc_test_card *test)
  1361. {
  1362. return mmc_test_best_performance(test, 1, 0);
  1363. }
  1364. /*
  1365. * Best-case read performance into scattered pages.
  1366. */
  1367. static int mmc_test_best_read_perf_max_scatter(struct mmc_test_card *test)
  1368. {
  1369. return mmc_test_best_performance(test, 0, 1);
  1370. }
  1371. /*
  1372. * Best-case write performance from scattered pages.
  1373. */
  1374. static int mmc_test_best_write_perf_max_scatter(struct mmc_test_card *test)
  1375. {
  1376. return mmc_test_best_performance(test, 1, 1);
  1377. }
  1378. /*
  1379. * Single read performance by transfer size.
  1380. */
  1381. static int mmc_test_profile_read_perf(struct mmc_test_card *test)
  1382. {
  1383. struct mmc_test_area *t = &test->area;
  1384. unsigned long sz;
  1385. unsigned int dev_addr;
  1386. int ret;
  1387. for (sz = 512; sz < t->max_tfr; sz <<= 1) {
  1388. dev_addr = t->dev_addr + (sz >> 9);
  1389. ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
  1390. if (ret)
  1391. return ret;
  1392. }
  1393. sz = t->max_tfr;
  1394. dev_addr = t->dev_addr;
  1395. return mmc_test_area_io(test, sz, dev_addr, 0, 0, 1);
  1396. }
  1397. /*
  1398. * Single write performance by transfer size.
  1399. */
  1400. static int mmc_test_profile_write_perf(struct mmc_test_card *test)
  1401. {
  1402. struct mmc_test_area *t = &test->area;
  1403. unsigned long sz;
  1404. unsigned int dev_addr;
  1405. int ret;
  1406. ret = mmc_test_area_erase(test);
  1407. if (ret)
  1408. return ret;
  1409. for (sz = 512; sz < t->max_tfr; sz <<= 1) {
  1410. dev_addr = t->dev_addr + (sz >> 9);
  1411. ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
  1412. if (ret)
  1413. return ret;
  1414. }
  1415. ret = mmc_test_area_erase(test);
  1416. if (ret)
  1417. return ret;
  1418. sz = t->max_tfr;
  1419. dev_addr = t->dev_addr;
  1420. return mmc_test_area_io(test, sz, dev_addr, 1, 0, 1);
  1421. }
  1422. /*
  1423. * Single trim performance by transfer size.
  1424. */
  1425. static int mmc_test_profile_trim_perf(struct mmc_test_card *test)
  1426. {
  1427. struct mmc_test_area *t = &test->area;
  1428. unsigned long sz;
  1429. unsigned int dev_addr;
  1430. struct timespec ts1, ts2;
  1431. int ret;
  1432. if (!mmc_can_trim(test->card))
  1433. return RESULT_UNSUP_CARD;
  1434. if (!mmc_can_erase(test->card))
  1435. return RESULT_UNSUP_HOST;
  1436. for (sz = 512; sz < t->max_sz; sz <<= 1) {
  1437. dev_addr = t->dev_addr + (sz >> 9);
  1438. getnstimeofday(&ts1);
  1439. ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
  1440. if (ret)
  1441. return ret;
  1442. getnstimeofday(&ts2);
  1443. mmc_test_print_rate(test, sz, &ts1, &ts2);
  1444. }
  1445. dev_addr = t->dev_addr;
  1446. getnstimeofday(&ts1);
  1447. ret = mmc_erase(test->card, dev_addr, sz >> 9, MMC_TRIM_ARG);
  1448. if (ret)
  1449. return ret;
  1450. getnstimeofday(&ts2);
  1451. mmc_test_print_rate(test, sz, &ts1, &ts2);
  1452. return 0;
  1453. }
  1454. static int mmc_test_seq_read_perf(struct mmc_test_card *test, unsigned long sz)
  1455. {
  1456. struct mmc_test_area *t = &test->area;
  1457. unsigned int dev_addr, i, cnt;
  1458. struct timespec ts1, ts2;
  1459. int ret;
  1460. cnt = t->max_sz / sz;
  1461. dev_addr = t->dev_addr;
  1462. getnstimeofday(&ts1);
  1463. for (i = 0; i < cnt; i++) {
  1464. ret = mmc_test_area_io(test, sz, dev_addr, 0, 0, 0);
  1465. if (ret)
  1466. return ret;
  1467. dev_addr += (sz >> 9);
  1468. }
  1469. getnstimeofday(&ts2);
  1470. mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
  1471. return 0;
  1472. }
  1473. /*
  1474. * Consecutive read performance by transfer size.
  1475. */
  1476. static int mmc_test_profile_seq_read_perf(struct mmc_test_card *test)
  1477. {
  1478. struct mmc_test_area *t = &test->area;
  1479. unsigned long sz;
  1480. int ret;
  1481. for (sz = 512; sz < t->max_tfr; sz <<= 1) {
  1482. ret = mmc_test_seq_read_perf(test, sz);
  1483. if (ret)
  1484. return ret;
  1485. }
  1486. sz = t->max_tfr;
  1487. return mmc_test_seq_read_perf(test, sz);
  1488. }
  1489. static int mmc_test_seq_write_perf(struct mmc_test_card *test, unsigned long sz)
  1490. {
  1491. struct mmc_test_area *t = &test->area;
  1492. unsigned int dev_addr, i, cnt;
  1493. struct timespec ts1, ts2;
  1494. int ret;
  1495. ret = mmc_test_area_erase(test);
  1496. if (ret)
  1497. return ret;
  1498. cnt = t->max_sz / sz;
  1499. dev_addr = t->dev_addr;
  1500. getnstimeofday(&ts1);
  1501. for (i = 0; i < cnt; i++) {
  1502. ret = mmc_test_area_io(test, sz, dev_addr, 1, 0, 0);
  1503. if (ret)
  1504. return ret;
  1505. dev_addr += (sz >> 9);
  1506. }
  1507. getnstimeofday(&ts2);
  1508. mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
  1509. return 0;
  1510. }
  1511. /*
  1512. * Consecutive write performance by transfer size.
  1513. */
  1514. static int mmc_test_profile_seq_write_perf(struct mmc_test_card *test)
  1515. {
  1516. struct mmc_test_area *t = &test->area;
  1517. unsigned long sz;
  1518. int ret;
  1519. for (sz = 512; sz < t->max_tfr; sz <<= 1) {
  1520. ret = mmc_test_seq_write_perf(test, sz);
  1521. if (ret)
  1522. return ret;
  1523. }
  1524. sz = t->max_tfr;
  1525. return mmc_test_seq_write_perf(test, sz);
  1526. }
  1527. /*
  1528. * Consecutive trim performance by transfer size.
  1529. */
  1530. static int mmc_test_profile_seq_trim_perf(struct mmc_test_card *test)
  1531. {
  1532. struct mmc_test_area *t = &test->area;
  1533. unsigned long sz;
  1534. unsigned int dev_addr, i, cnt;
  1535. struct timespec ts1, ts2;
  1536. int ret;
  1537. if (!mmc_can_trim(test->card))
  1538. return RESULT_UNSUP_CARD;
  1539. if (!mmc_can_erase(test->card))
  1540. return RESULT_UNSUP_HOST;
  1541. for (sz = 512; sz <= t->max_sz; sz <<= 1) {
  1542. ret = mmc_test_area_erase(test);
  1543. if (ret)
  1544. return ret;
  1545. ret = mmc_test_area_fill(test);
  1546. if (ret)
  1547. return ret;
  1548. cnt = t->max_sz / sz;
  1549. dev_addr = t->dev_addr;
  1550. getnstimeofday(&ts1);
  1551. for (i = 0; i < cnt; i++) {
  1552. ret = mmc_erase(test->card, dev_addr, sz >> 9,
  1553. MMC_TRIM_ARG);
  1554. if (ret)
  1555. return ret;
  1556. dev_addr += (sz >> 9);
  1557. }
  1558. getnstimeofday(&ts2);
  1559. mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
  1560. }
  1561. return 0;
  1562. }
  1563. static unsigned int rnd_next = 1;
  1564. static unsigned int mmc_test_rnd_num(unsigned int rnd_cnt)
  1565. {
  1566. uint64_t r;
  1567. rnd_next = rnd_next * 1103515245 + 12345;
  1568. r = (rnd_next >> 16) & 0x7fff;
  1569. return (r * rnd_cnt) >> 15;
  1570. }
  1571. static int mmc_test_rnd_perf(struct mmc_test_card *test, int write, int print,
  1572. unsigned long sz)
  1573. {
  1574. unsigned int dev_addr, cnt, rnd_addr, range1, range2, last_ea = 0, ea;
  1575. unsigned int ssz;
  1576. struct timespec ts1, ts2, ts;
  1577. int ret;
  1578. ssz = sz >> 9;
  1579. rnd_addr = mmc_test_capacity(test->card) / 4;
  1580. range1 = rnd_addr / test->card->pref_erase;
  1581. range2 = range1 / ssz;
  1582. getnstimeofday(&ts1);
  1583. for (cnt = 0; cnt < UINT_MAX; cnt++) {
  1584. getnstimeofday(&ts2);
  1585. ts = timespec_sub(ts2, ts1);
  1586. if (ts.tv_sec >= 10)
  1587. break;
  1588. ea = mmc_test_rnd_num(range1);
  1589. if (ea == last_ea)
  1590. ea -= 1;
  1591. last_ea = ea;
  1592. dev_addr = rnd_addr + test->card->pref_erase * ea +
  1593. ssz * mmc_test_rnd_num(range2);
  1594. ret = mmc_test_area_io(test, sz, dev_addr, write, 0, 0);
  1595. if (ret)
  1596. return ret;
  1597. }
  1598. if (print)
  1599. mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
  1600. return 0;
  1601. }
  1602. static int mmc_test_random_perf(struct mmc_test_card *test, int write)
  1603. {
  1604. struct mmc_test_area *t = &test->area;
  1605. unsigned int next;
  1606. unsigned long sz;
  1607. int ret;
  1608. for (sz = 512; sz < t->max_tfr; sz <<= 1) {
  1609. /*
  1610. * When writing, try to get more consistent results by running
  1611. * the test twice with exactly the same I/O but outputting the
  1612. * results only for the 2nd run.
  1613. */
  1614. if (write) {
  1615. next = rnd_next;
  1616. ret = mmc_test_rnd_perf(test, write, 0, sz);
  1617. if (ret)
  1618. return ret;
  1619. rnd_next = next;
  1620. }
  1621. ret = mmc_test_rnd_perf(test, write, 1, sz);
  1622. if (ret)
  1623. return ret;
  1624. }
  1625. sz = t->max_tfr;
  1626. if (write) {
  1627. next = rnd_next;
  1628. ret = mmc_test_rnd_perf(test, write, 0, sz);
  1629. if (ret)
  1630. return ret;
  1631. rnd_next = next;
  1632. }
  1633. return mmc_test_rnd_perf(test, write, 1, sz);
  1634. }
  1635. /*
  1636. * Random read performance by transfer size.
  1637. */
  1638. static int mmc_test_random_read_perf(struct mmc_test_card *test)
  1639. {
  1640. return mmc_test_random_perf(test, 0);
  1641. }
  1642. /*
  1643. * Random write performance by transfer size.
  1644. */
  1645. static int mmc_test_random_write_perf(struct mmc_test_card *test)
  1646. {
  1647. return mmc_test_random_perf(test, 1);
  1648. }
  1649. static int mmc_test_seq_perf(struct mmc_test_card *test, int write,
  1650. unsigned int tot_sz, int max_scatter)
  1651. {
  1652. struct mmc_test_area *t = &test->area;
  1653. unsigned int dev_addr, i, cnt, sz, ssz;
  1654. struct timespec ts1, ts2;
  1655. int ret;
  1656. sz = t->max_tfr;
  1657. /*
  1658. * In the case of a maximally scattered transfer, the maximum transfer
  1659. * size is further limited by using PAGE_SIZE segments.
  1660. */
  1661. if (max_scatter) {
  1662. unsigned long max_tfr;
  1663. if (t->max_seg_sz >= PAGE_SIZE)
  1664. max_tfr = t->max_segs * PAGE_SIZE;
  1665. else
  1666. max_tfr = t->max_segs * t->max_seg_sz;
  1667. if (sz > max_tfr)
  1668. sz = max_tfr;
  1669. }
  1670. ssz = sz >> 9;
  1671. dev_addr = mmc_test_capacity(test->card) / 4;
  1672. if (tot_sz > dev_addr << 9)
  1673. tot_sz = dev_addr << 9;
  1674. cnt = tot_sz / sz;
  1675. dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
  1676. getnstimeofday(&ts1);
  1677. for (i = 0; i < cnt; i++) {
  1678. ret = mmc_test_area_io(test, sz, dev_addr, write,
  1679. max_scatter, 0);
  1680. if (ret)
  1681. return ret;
  1682. dev_addr += ssz;
  1683. }
  1684. getnstimeofday(&ts2);
  1685. mmc_test_print_avg_rate(test, sz, cnt, &ts1, &ts2);
  1686. return 0;
  1687. }
  1688. static int mmc_test_large_seq_perf(struct mmc_test_card *test, int write)
  1689. {
  1690. int ret, i;
  1691. for (i = 0; i < 10; i++) {
  1692. ret = mmc_test_seq_perf(test, write, 10 * 1024 * 1024, 1);
  1693. if (ret)
  1694. return ret;
  1695. }
  1696. for (i = 0; i < 5; i++) {
  1697. ret = mmc_test_seq_perf(test, write, 100 * 1024 * 1024, 1);
  1698. if (ret)
  1699. return ret;
  1700. }
  1701. for (i = 0; i < 3; i++) {
  1702. ret = mmc_test_seq_perf(test, write, 1000 * 1024 * 1024, 1);
  1703. if (ret)
  1704. return ret;
  1705. }
  1706. return ret;
  1707. }
  1708. /*
  1709. * Large sequential read performance.
  1710. */
  1711. static int mmc_test_large_seq_read_perf(struct mmc_test_card *test)
  1712. {
  1713. return mmc_test_large_seq_perf(test, 0);
  1714. }
  1715. /*
  1716. * Large sequential write performance.
  1717. */
  1718. static int mmc_test_large_seq_write_perf(struct mmc_test_card *test)
  1719. {
  1720. return mmc_test_large_seq_perf(test, 1);
  1721. }
  1722. static int mmc_test_rw_multiple(struct mmc_test_card *test,
  1723. struct mmc_test_multiple_rw *tdata,
  1724. unsigned int reqsize, unsigned int size,
  1725. int min_sg_len)
  1726. {
  1727. unsigned int dev_addr;
  1728. struct mmc_test_area *t = &test->area;
  1729. int ret = 0;
  1730. /* Set up test area */
  1731. if (size > mmc_test_capacity(test->card) / 2 * 512)
  1732. size = mmc_test_capacity(test->card) / 2 * 512;
  1733. if (reqsize > t->max_tfr)
  1734. reqsize = t->max_tfr;
  1735. dev_addr = mmc_test_capacity(test->card) / 4;
  1736. if ((dev_addr & 0xffff0000))
  1737. dev_addr &= 0xffff0000; /* Round to 64MiB boundary */
  1738. else
  1739. dev_addr &= 0xfffff800; /* Round to 1MiB boundary */
  1740. if (!dev_addr)
  1741. goto err;
  1742. if (reqsize > size)
  1743. return 0;
  1744. /* prepare test area */
  1745. if (mmc_can_erase(test->card) &&
  1746. tdata->prepare & MMC_TEST_PREP_ERASE) {
  1747. ret = mmc_erase(test->card, dev_addr,
  1748. size / 512, MMC_SECURE_ERASE_ARG);
  1749. if (ret)
  1750. ret = mmc_erase(test->card, dev_addr,
  1751. size / 512, MMC_ERASE_ARG);
  1752. if (ret)
  1753. goto err;
  1754. }
  1755. /* Run test */
  1756. ret = mmc_test_area_io_seq(test, reqsize, dev_addr,
  1757. tdata->do_write, 0, 1, size / reqsize,
  1758. tdata->do_nonblock_req, min_sg_len);
  1759. if (ret)
  1760. goto err;
  1761. return ret;
  1762. err:
  1763. pr_info("[%s] error\n", __func__);
  1764. return ret;
  1765. }
  1766. static int mmc_test_rw_multiple_size(struct mmc_test_card *test,
  1767. struct mmc_test_multiple_rw *rw)
  1768. {
  1769. int ret = 0;
  1770. int i;
  1771. void *pre_req = test->card->host->ops->pre_req;
  1772. void *post_req = test->card->host->ops->post_req;
  1773. if (rw->do_nonblock_req &&
  1774. ((!pre_req && post_req) || (pre_req && !post_req))) {
  1775. pr_info("error: only one of pre/post is defined\n");
  1776. return -EINVAL;
  1777. }
  1778. for (i = 0 ; i < rw->len && ret == 0; i++) {
  1779. ret = mmc_test_rw_multiple(test, rw, rw->bs[i], rw->size, 0);
  1780. if (ret)
  1781. break;
  1782. }
  1783. return ret;
  1784. }
  1785. static int mmc_test_rw_multiple_sg_len(struct mmc_test_card *test,
  1786. struct mmc_test_multiple_rw *rw)
  1787. {
  1788. int ret = 0;
  1789. int i;
  1790. for (i = 0 ; i < rw->len && ret == 0; i++) {
  1791. ret = mmc_test_rw_multiple(test, rw, 512 * 1024, rw->size,
  1792. rw->sg_len[i]);
  1793. if (ret)
  1794. break;
  1795. }
  1796. return ret;
  1797. }
  1798. /*
  1799. * Multiple blocking write 4k to 4 MB chunks
  1800. */
  1801. static int mmc_test_profile_mult_write_blocking_perf(struct mmc_test_card *test)
  1802. {
  1803. unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
  1804. 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
  1805. struct mmc_test_multiple_rw test_data = {
  1806. .bs = bs,
  1807. .size = TEST_AREA_MAX_SIZE,
  1808. .len = ARRAY_SIZE(bs),
  1809. .do_write = true,
  1810. .do_nonblock_req = false,
  1811. .prepare = MMC_TEST_PREP_ERASE,
  1812. };
  1813. return mmc_test_rw_multiple_size(test, &test_data);
  1814. };
  1815. /*
  1816. * Multiple non-blocking write 4k to 4 MB chunks
  1817. */
  1818. static int mmc_test_profile_mult_write_nonblock_perf(struct mmc_test_card *test)
  1819. {
  1820. unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
  1821. 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
  1822. struct mmc_test_multiple_rw test_data = {
  1823. .bs = bs,
  1824. .size = TEST_AREA_MAX_SIZE,
  1825. .len = ARRAY_SIZE(bs),
  1826. .do_write = true,
  1827. .do_nonblock_req = true,
  1828. .prepare = MMC_TEST_PREP_ERASE,
  1829. };
  1830. return mmc_test_rw_multiple_size(test, &test_data);
  1831. }
  1832. /*
  1833. * Multiple blocking read 4k to 4 MB chunks
  1834. */
  1835. static int mmc_test_profile_mult_read_blocking_perf(struct mmc_test_card *test)
  1836. {
  1837. unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
  1838. 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
  1839. struct mmc_test_multiple_rw test_data = {
  1840. .bs = bs,
  1841. .size = TEST_AREA_MAX_SIZE,
  1842. .len = ARRAY_SIZE(bs),
  1843. .do_write = false,
  1844. .do_nonblock_req = false,
  1845. .prepare = MMC_TEST_PREP_NONE,
  1846. };
  1847. return mmc_test_rw_multiple_size(test, &test_data);
  1848. }
  1849. /*
  1850. * Multiple non-blocking read 4k to 4 MB chunks
  1851. */
  1852. static int mmc_test_profile_mult_read_nonblock_perf(struct mmc_test_card *test)
  1853. {
  1854. unsigned int bs[] = {1 << 12, 1 << 13, 1 << 14, 1 << 15, 1 << 16,
  1855. 1 << 17, 1 << 18, 1 << 19, 1 << 20, 1 << 22};
  1856. struct mmc_test_multiple_rw test_data = {
  1857. .bs = bs,
  1858. .size = TEST_AREA_MAX_SIZE,
  1859. .len = ARRAY_SIZE(bs),
  1860. .do_write = false,
  1861. .do_nonblock_req = true,
  1862. .prepare = MMC_TEST_PREP_NONE,
  1863. };
  1864. return mmc_test_rw_multiple_size(test, &test_data);
  1865. }
  1866. /*
  1867. * Multiple blocking write 1 to 512 sg elements
  1868. */
  1869. static int mmc_test_profile_sglen_wr_blocking_perf(struct mmc_test_card *test)
  1870. {
  1871. unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
  1872. 1 << 7, 1 << 8, 1 << 9};
  1873. struct mmc_test_multiple_rw test_data = {
  1874. .sg_len = sg_len,
  1875. .size = TEST_AREA_MAX_SIZE,
  1876. .len = ARRAY_SIZE(sg_len),
  1877. .do_write = true,
  1878. .do_nonblock_req = false,
  1879. .prepare = MMC_TEST_PREP_ERASE,
  1880. };
  1881. return mmc_test_rw_multiple_sg_len(test, &test_data);
  1882. };
  1883. /*
  1884. * Multiple non-blocking write 1 to 512 sg elements
  1885. */
  1886. static int mmc_test_profile_sglen_wr_nonblock_perf(struct mmc_test_card *test)
  1887. {
  1888. unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
  1889. 1 << 7, 1 << 8, 1 << 9};
  1890. struct mmc_test_multiple_rw test_data = {
  1891. .sg_len = sg_len,
  1892. .size = TEST_AREA_MAX_SIZE,
  1893. .len = ARRAY_SIZE(sg_len),
  1894. .do_write = true,
  1895. .do_nonblock_req = true,
  1896. .prepare = MMC_TEST_PREP_ERASE,
  1897. };
  1898. return mmc_test_rw_multiple_sg_len(test, &test_data);
  1899. }
  1900. /*
  1901. * Multiple blocking read 1 to 512 sg elements
  1902. */
  1903. static int mmc_test_profile_sglen_r_blocking_perf(struct mmc_test_card *test)
  1904. {
  1905. unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
  1906. 1 << 7, 1 << 8, 1 << 9};
  1907. struct mmc_test_multiple_rw test_data = {
  1908. .sg_len = sg_len,
  1909. .size = TEST_AREA_MAX_SIZE,
  1910. .len = ARRAY_SIZE(sg_len),
  1911. .do_write = false,
  1912. .do_nonblock_req = false,
  1913. .prepare = MMC_TEST_PREP_NONE,
  1914. };
  1915. return mmc_test_rw_multiple_sg_len(test, &test_data);
  1916. }
  1917. /*
  1918. * Multiple non-blocking read 1 to 512 sg elements
  1919. */
  1920. static int mmc_test_profile_sglen_r_nonblock_perf(struct mmc_test_card *test)
  1921. {
  1922. unsigned int sg_len[] = {1, 1 << 3, 1 << 4, 1 << 5, 1 << 6,
  1923. 1 << 7, 1 << 8, 1 << 9};
  1924. struct mmc_test_multiple_rw test_data = {
  1925. .sg_len = sg_len,
  1926. .size = TEST_AREA_MAX_SIZE,
  1927. .len = ARRAY_SIZE(sg_len),
  1928. .do_write = false,
  1929. .do_nonblock_req = true,
  1930. .prepare = MMC_TEST_PREP_NONE,
  1931. };
  1932. return mmc_test_rw_multiple_sg_len(test, &test_data);
  1933. }
  1934. /*
  1935. * eMMC hardware reset.
  1936. */
  1937. static int mmc_test_reset(struct mmc_test_card *test)
  1938. {
  1939. struct mmc_card *card = test->card;
  1940. struct mmc_host *host = card->host;
  1941. int err;
  1942. err = mmc_hw_reset(host);
  1943. if (!err)
  1944. return RESULT_OK;
  1945. else if (err == -EOPNOTSUPP)
  1946. return RESULT_UNSUP_HOST;
  1947. return RESULT_FAIL;
  1948. }
  1949. struct mmc_test_req {
  1950. struct mmc_request mrq;
  1951. struct mmc_command sbc;
  1952. struct mmc_command cmd;
  1953. struct mmc_command stop;
  1954. struct mmc_command status;
  1955. struct mmc_data data;
  1956. };
  1957. static struct mmc_test_req *mmc_test_req_alloc(void)
  1958. {
  1959. struct mmc_test_req *rq = kzalloc(sizeof(*rq), GFP_KERNEL);
  1960. if (rq) {
  1961. rq->mrq.cmd = &rq->cmd;
  1962. rq->mrq.data = &rq->data;
  1963. rq->mrq.stop = &rq->stop;
  1964. }
  1965. return rq;
  1966. }
  1967. static int mmc_test_send_status(struct mmc_test_card *test,
  1968. struct mmc_command *cmd)
  1969. {
  1970. memset(cmd, 0, sizeof(*cmd));
  1971. cmd->opcode = MMC_SEND_STATUS;
  1972. if (!mmc_host_is_spi(test->card->host))
  1973. cmd->arg = test->card->rca << 16;
  1974. cmd->flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
  1975. return mmc_wait_for_cmd(test->card->host, cmd, 0);
  1976. }
  1977. static int mmc_test_ongoing_transfer(struct mmc_test_card *test,
  1978. unsigned int dev_addr, int use_sbc,
  1979. int repeat_cmd, int write, int use_areq)
  1980. {
  1981. struct mmc_test_req *rq = mmc_test_req_alloc();
  1982. struct mmc_host *host = test->card->host;
  1983. struct mmc_test_area *t = &test->area;
  1984. struct mmc_test_async_req test_areq = { .test = test };
  1985. struct mmc_request *mrq;
  1986. unsigned long timeout;
  1987. bool expired = false;
  1988. enum mmc_blk_status blkstat = MMC_BLK_SUCCESS;
  1989. int ret = 0, cmd_ret;
  1990. u32 status = 0;
  1991. int count = 0;
  1992. if (!rq)
  1993. return -ENOMEM;
  1994. mrq = &rq->mrq;
  1995. if (use_sbc)
  1996. mrq->sbc = &rq->sbc;
  1997. mrq->cap_cmd_during_tfr = true;
  1998. test_areq.areq.mrq = mrq;
  1999. test_areq.areq.err_check = mmc_test_check_result_async;
  2000. mmc_test_prepare_mrq(test, mrq, t->sg, t->sg_len, dev_addr, t->blocks,
  2001. 512, write);
  2002. if (use_sbc && t->blocks > 1 && !mrq->sbc) {
  2003. ret = mmc_host_cmd23(host) ?
  2004. RESULT_UNSUP_CARD :
  2005. RESULT_UNSUP_HOST;
  2006. goto out_free;
  2007. }
  2008. /* Start ongoing data request */
  2009. if (use_areq) {
  2010. mmc_start_areq(host, &test_areq.areq, &blkstat);
  2011. if (blkstat != MMC_BLK_SUCCESS) {
  2012. ret = RESULT_FAIL;
  2013. goto out_free;
  2014. }
  2015. } else {
  2016. mmc_wait_for_req(host, mrq);
  2017. }
  2018. timeout = jiffies + msecs_to_jiffies(3000);
  2019. do {
  2020. count += 1;
  2021. /* Send status command while data transfer in progress */
  2022. cmd_ret = mmc_test_send_status(test, &rq->status);
  2023. if (cmd_ret)
  2024. break;
  2025. status = rq->status.resp[0];
  2026. if (status & R1_ERROR) {
  2027. cmd_ret = -EIO;
  2028. break;
  2029. }
  2030. if (mmc_is_req_done(host, mrq))
  2031. break;
  2032. expired = time_after(jiffies, timeout);
  2033. if (expired) {
  2034. pr_info("%s: timeout waiting for Tran state status %#x\n",
  2035. mmc_hostname(host), status);
  2036. cmd_ret = -ETIMEDOUT;
  2037. break;
  2038. }
  2039. } while (repeat_cmd && R1_CURRENT_STATE(status) != R1_STATE_TRAN);
  2040. /* Wait for data request to complete */
  2041. if (use_areq) {
  2042. mmc_start_areq(host, NULL, &blkstat);
  2043. if (blkstat != MMC_BLK_SUCCESS)
  2044. ret = RESULT_FAIL;
  2045. } else {
  2046. mmc_wait_for_req_done(test->card->host, mrq);
  2047. }
  2048. /*
  2049. * For cap_cmd_during_tfr request, upper layer must send stop if
  2050. * required.
  2051. */
  2052. if (mrq->data->stop && (mrq->data->error || !mrq->sbc)) {
  2053. if (ret)
  2054. mmc_wait_for_cmd(host, mrq->data->stop, 0);
  2055. else
  2056. ret = mmc_wait_for_cmd(host, mrq->data->stop, 0);
  2057. }
  2058. if (ret)
  2059. goto out_free;
  2060. if (cmd_ret) {
  2061. pr_info("%s: Send Status failed: status %#x, error %d\n",
  2062. mmc_hostname(test->card->host), status, cmd_ret);
  2063. }
  2064. ret = mmc_test_check_result(test, mrq);
  2065. if (ret)
  2066. goto out_free;
  2067. ret = mmc_test_wait_busy(test);
  2068. if (ret)
  2069. goto out_free;
  2070. if (repeat_cmd && (t->blocks + 1) << 9 > t->max_tfr)
  2071. pr_info("%s: %d commands completed during transfer of %u blocks\n",
  2072. mmc_hostname(test->card->host), count, t->blocks);
  2073. if (cmd_ret)
  2074. ret = cmd_ret;
  2075. out_free:
  2076. kfree(rq);
  2077. return ret;
  2078. }
  2079. static int __mmc_test_cmds_during_tfr(struct mmc_test_card *test,
  2080. unsigned long sz, int use_sbc, int write,
  2081. int use_areq)
  2082. {
  2083. struct mmc_test_area *t = &test->area;
  2084. int ret;
  2085. if (!(test->card->host->caps & MMC_CAP_CMD_DURING_TFR))
  2086. return RESULT_UNSUP_HOST;
  2087. ret = mmc_test_area_map(test, sz, 0, 0);
  2088. if (ret)
  2089. return ret;
  2090. ret = mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 0, write,
  2091. use_areq);
  2092. if (ret)
  2093. return ret;
  2094. return mmc_test_ongoing_transfer(test, t->dev_addr, use_sbc, 1, write,
  2095. use_areq);
  2096. }
  2097. static int mmc_test_cmds_during_tfr(struct mmc_test_card *test, int use_sbc,
  2098. int write, int use_areq)
  2099. {
  2100. struct mmc_test_area *t = &test->area;
  2101. unsigned long sz;
  2102. int ret;
  2103. for (sz = 512; sz <= t->max_tfr; sz += 512) {
  2104. ret = __mmc_test_cmds_during_tfr(test, sz, use_sbc, write,
  2105. use_areq);
  2106. if (ret)
  2107. return ret;
  2108. }
  2109. return 0;
  2110. }
  2111. /*
  2112. * Commands during read - no Set Block Count (CMD23).
  2113. */
  2114. static int mmc_test_cmds_during_read(struct mmc_test_card *test)
  2115. {
  2116. return mmc_test_cmds_during_tfr(test, 0, 0, 0);
  2117. }
  2118. /*
  2119. * Commands during write - no Set Block Count (CMD23).
  2120. */
  2121. static int mmc_test_cmds_during_write(struct mmc_test_card *test)
  2122. {
  2123. return mmc_test_cmds_during_tfr(test, 0, 1, 0);
  2124. }
  2125. /*
  2126. * Commands during read - use Set Block Count (CMD23).
  2127. */
  2128. static int mmc_test_cmds_during_read_cmd23(struct mmc_test_card *test)
  2129. {
  2130. return mmc_test_cmds_during_tfr(test, 1, 0, 0);
  2131. }
  2132. /*
  2133. * Commands during write - use Set Block Count (CMD23).
  2134. */
  2135. static int mmc_test_cmds_during_write_cmd23(struct mmc_test_card *test)
  2136. {
  2137. return mmc_test_cmds_during_tfr(test, 1, 1, 0);
  2138. }
  2139. /*
  2140. * Commands during non-blocking read - use Set Block Count (CMD23).
  2141. */
  2142. static int mmc_test_cmds_during_read_cmd23_nonblock(struct mmc_test_card *test)
  2143. {
  2144. return mmc_test_cmds_during_tfr(test, 1, 0, 1);
  2145. }
  2146. /*
  2147. * Commands during non-blocking write - use Set Block Count (CMD23).
  2148. */
  2149. static int mmc_test_cmds_during_write_cmd23_nonblock(struct mmc_test_card *test)
  2150. {
  2151. return mmc_test_cmds_during_tfr(test, 1, 1, 1);
  2152. }
  2153. static const struct mmc_test_case mmc_test_cases[] = {
  2154. {
  2155. .name = "Basic write (no data verification)",
  2156. .run = mmc_test_basic_write,
  2157. },
  2158. {
  2159. .name = "Basic read (no data verification)",
  2160. .run = mmc_test_basic_read,
  2161. },
  2162. {
  2163. .name = "Basic write (with data verification)",
  2164. .prepare = mmc_test_prepare_write,
  2165. .run = mmc_test_verify_write,
  2166. .cleanup = mmc_test_cleanup,
  2167. },
  2168. {
  2169. .name = "Basic read (with data verification)",
  2170. .prepare = mmc_test_prepare_read,
  2171. .run = mmc_test_verify_read,
  2172. .cleanup = mmc_test_cleanup,
  2173. },
  2174. {
  2175. .name = "Multi-block write",
  2176. .prepare = mmc_test_prepare_write,
  2177. .run = mmc_test_multi_write,
  2178. .cleanup = mmc_test_cleanup,
  2179. },
  2180. {
  2181. .name = "Multi-block read",
  2182. .prepare = mmc_test_prepare_read,
  2183. .run = mmc_test_multi_read,
  2184. .cleanup = mmc_test_cleanup,
  2185. },
  2186. {
  2187. .name = "Power of two block writes",
  2188. .prepare = mmc_test_prepare_write,
  2189. .run = mmc_test_pow2_write,
  2190. .cleanup = mmc_test_cleanup,
  2191. },
  2192. {
  2193. .name = "Power of two block reads",
  2194. .prepare = mmc_test_prepare_read,
  2195. .run = mmc_test_pow2_read,
  2196. .cleanup = mmc_test_cleanup,
  2197. },
  2198. {
  2199. .name = "Weird sized block writes",
  2200. .prepare = mmc_test_prepare_write,
  2201. .run = mmc_test_weird_write,
  2202. .cleanup = mmc_test_cleanup,
  2203. },
  2204. {
  2205. .name = "Weird sized block reads",
  2206. .prepare = mmc_test_prepare_read,
  2207. .run = mmc_test_weird_read,
  2208. .cleanup = mmc_test_cleanup,
  2209. },
  2210. {
  2211. .name = "Badly aligned write",
  2212. .prepare = mmc_test_prepare_write,
  2213. .run = mmc_test_align_write,
  2214. .cleanup = mmc_test_cleanup,
  2215. },
  2216. {
  2217. .name = "Badly aligned read",
  2218. .prepare = mmc_test_prepare_read,
  2219. .run = mmc_test_align_read,
  2220. .cleanup = mmc_test_cleanup,
  2221. },
  2222. {
  2223. .name = "Badly aligned multi-block write",
  2224. .prepare = mmc_test_prepare_write,
  2225. .run = mmc_test_align_multi_write,
  2226. .cleanup = mmc_test_cleanup,
  2227. },
  2228. {
  2229. .name = "Badly aligned multi-block read",
  2230. .prepare = mmc_test_prepare_read,
  2231. .run = mmc_test_align_multi_read,
  2232. .cleanup = mmc_test_cleanup,
  2233. },
  2234. {
  2235. .name = "Correct xfer_size at write (start failure)",
  2236. .run = mmc_test_xfersize_write,
  2237. },
  2238. {
  2239. .name = "Correct xfer_size at read (start failure)",
  2240. .run = mmc_test_xfersize_read,
  2241. },
  2242. {
  2243. .name = "Correct xfer_size at write (midway failure)",
  2244. .run = mmc_test_multi_xfersize_write,
  2245. },
  2246. {
  2247. .name = "Correct xfer_size at read (midway failure)",
  2248. .run = mmc_test_multi_xfersize_read,
  2249. },
  2250. #ifdef CONFIG_HIGHMEM
  2251. {
  2252. .name = "Highmem write",
  2253. .prepare = mmc_test_prepare_write,
  2254. .run = mmc_test_write_high,
  2255. .cleanup = mmc_test_cleanup,
  2256. },
  2257. {
  2258. .name = "Highmem read",
  2259. .prepare = mmc_test_prepare_read,
  2260. .run = mmc_test_read_high,
  2261. .cleanup = mmc_test_cleanup,
  2262. },
  2263. {
  2264. .name = "Multi-block highmem write",
  2265. .prepare = mmc_test_prepare_write,
  2266. .run = mmc_test_multi_write_high,
  2267. .cleanup = mmc_test_cleanup,
  2268. },
  2269. {
  2270. .name = "Multi-block highmem read",
  2271. .prepare = mmc_test_prepare_read,
  2272. .run = mmc_test_multi_read_high,
  2273. .cleanup = mmc_test_cleanup,
  2274. },
  2275. #else
  2276. {
  2277. .name = "Highmem write",
  2278. .run = mmc_test_no_highmem,
  2279. },
  2280. {
  2281. .name = "Highmem read",
  2282. .run = mmc_test_no_highmem,
  2283. },
  2284. {
  2285. .name = "Multi-block highmem write",
  2286. .run = mmc_test_no_highmem,
  2287. },
  2288. {
  2289. .name = "Multi-block highmem read",
  2290. .run = mmc_test_no_highmem,
  2291. },
  2292. #endif /* CONFIG_HIGHMEM */
  2293. {
  2294. .name = "Best-case read performance",
  2295. .prepare = mmc_test_area_prepare_fill,
  2296. .run = mmc_test_best_read_performance,
  2297. .cleanup = mmc_test_area_cleanup,
  2298. },
  2299. {
  2300. .name = "Best-case write performance",
  2301. .prepare = mmc_test_area_prepare_erase,
  2302. .run = mmc_test_best_write_performance,
  2303. .cleanup = mmc_test_area_cleanup,
  2304. },
  2305. {
  2306. .name = "Best-case read performance into scattered pages",
  2307. .prepare = mmc_test_area_prepare_fill,
  2308. .run = mmc_test_best_read_perf_max_scatter,
  2309. .cleanup = mmc_test_area_cleanup,
  2310. },
  2311. {
  2312. .name = "Best-case write performance from scattered pages",
  2313. .prepare = mmc_test_area_prepare_erase,
  2314. .run = mmc_test_best_write_perf_max_scatter,
  2315. .cleanup = mmc_test_area_cleanup,
  2316. },
  2317. {
  2318. .name = "Single read performance by transfer size",
  2319. .prepare = mmc_test_area_prepare_fill,
  2320. .run = mmc_test_profile_read_perf,
  2321. .cleanup = mmc_test_area_cleanup,
  2322. },
  2323. {
  2324. .name = "Single write performance by transfer size",
  2325. .prepare = mmc_test_area_prepare,
  2326. .run = mmc_test_profile_write_perf,
  2327. .cleanup = mmc_test_area_cleanup,
  2328. },
  2329. {
  2330. .name = "Single trim performance by transfer size",
  2331. .prepare = mmc_test_area_prepare_fill,
  2332. .run = mmc_test_profile_trim_perf,
  2333. .cleanup = mmc_test_area_cleanup,
  2334. },
  2335. {
  2336. .name = "Consecutive read performance by transfer size",
  2337. .prepare = mmc_test_area_prepare_fill,
  2338. .run = mmc_test_profile_seq_read_perf,
  2339. .cleanup = mmc_test_area_cleanup,
  2340. },
  2341. {
  2342. .name = "Consecutive write performance by transfer size",
  2343. .prepare = mmc_test_area_prepare,
  2344. .run = mmc_test_profile_seq_write_perf,
  2345. .cleanup = mmc_test_area_cleanup,
  2346. },
  2347. {
  2348. .name = "Consecutive trim performance by transfer size",
  2349. .prepare = mmc_test_area_prepare,
  2350. .run = mmc_test_profile_seq_trim_perf,
  2351. .cleanup = mmc_test_area_cleanup,
  2352. },
  2353. {
  2354. .name = "Random read performance by transfer size",
  2355. .prepare = mmc_test_area_prepare,
  2356. .run = mmc_test_random_read_perf,
  2357. .cleanup = mmc_test_area_cleanup,
  2358. },
  2359. {
  2360. .name = "Random write performance by transfer size",
  2361. .prepare = mmc_test_area_prepare,
  2362. .run = mmc_test_random_write_perf,
  2363. .cleanup = mmc_test_area_cleanup,
  2364. },
  2365. {
  2366. .name = "Large sequential read into scattered pages",
  2367. .prepare = mmc_test_area_prepare,
  2368. .run = mmc_test_large_seq_read_perf,
  2369. .cleanup = mmc_test_area_cleanup,
  2370. },
  2371. {
  2372. .name = "Large sequential write from scattered pages",
  2373. .prepare = mmc_test_area_prepare,
  2374. .run = mmc_test_large_seq_write_perf,
  2375. .cleanup = mmc_test_area_cleanup,
  2376. },
  2377. {
  2378. .name = "Write performance with blocking req 4k to 4MB",
  2379. .prepare = mmc_test_area_prepare,
  2380. .run = mmc_test_profile_mult_write_blocking_perf,
  2381. .cleanup = mmc_test_area_cleanup,
  2382. },
  2383. {
  2384. .name = "Write performance with non-blocking req 4k to 4MB",
  2385. .prepare = mmc_test_area_prepare,
  2386. .run = mmc_test_profile_mult_write_nonblock_perf,
  2387. .cleanup = mmc_test_area_cleanup,
  2388. },
  2389. {
  2390. .name = "Read performance with blocking req 4k to 4MB",
  2391. .prepare = mmc_test_area_prepare,
  2392. .run = mmc_test_profile_mult_read_blocking_perf,
  2393. .cleanup = mmc_test_area_cleanup,
  2394. },
  2395. {
  2396. .name = "Read performance with non-blocking req 4k to 4MB",
  2397. .prepare = mmc_test_area_prepare,
  2398. .run = mmc_test_profile_mult_read_nonblock_perf,
  2399. .cleanup = mmc_test_area_cleanup,
  2400. },
  2401. {
  2402. .name = "Write performance blocking req 1 to 512 sg elems",
  2403. .prepare = mmc_test_area_prepare,
  2404. .run = mmc_test_profile_sglen_wr_blocking_perf,
  2405. .cleanup = mmc_test_area_cleanup,
  2406. },
  2407. {
  2408. .name = "Write performance non-blocking req 1 to 512 sg elems",
  2409. .prepare = mmc_test_area_prepare,
  2410. .run = mmc_test_profile_sglen_wr_nonblock_perf,
  2411. .cleanup = mmc_test_area_cleanup,
  2412. },
  2413. {
  2414. .name = "Read performance blocking req 1 to 512 sg elems",
  2415. .prepare = mmc_test_area_prepare,
  2416. .run = mmc_test_profile_sglen_r_blocking_perf,
  2417. .cleanup = mmc_test_area_cleanup,
  2418. },
  2419. {
  2420. .name = "Read performance non-blocking req 1 to 512 sg elems",
  2421. .prepare = mmc_test_area_prepare,
  2422. .run = mmc_test_profile_sglen_r_nonblock_perf,
  2423. .cleanup = mmc_test_area_cleanup,
  2424. },
  2425. {
  2426. .name = "Reset test",
  2427. .run = mmc_test_reset,
  2428. },
  2429. {
  2430. .name = "Commands during read - no Set Block Count (CMD23)",
  2431. .prepare = mmc_test_area_prepare,
  2432. .run = mmc_test_cmds_during_read,
  2433. .cleanup = mmc_test_area_cleanup,
  2434. },
  2435. {
  2436. .name = "Commands during write - no Set Block Count (CMD23)",
  2437. .prepare = mmc_test_area_prepare,
  2438. .run = mmc_test_cmds_during_write,
  2439. .cleanup = mmc_test_area_cleanup,
  2440. },
  2441. {
  2442. .name = "Commands during read - use Set Block Count (CMD23)",
  2443. .prepare = mmc_test_area_prepare,
  2444. .run = mmc_test_cmds_during_read_cmd23,
  2445. .cleanup = mmc_test_area_cleanup,
  2446. },
  2447. {
  2448. .name = "Commands during write - use Set Block Count (CMD23)",
  2449. .prepare = mmc_test_area_prepare,
  2450. .run = mmc_test_cmds_during_write_cmd23,
  2451. .cleanup = mmc_test_area_cleanup,
  2452. },
  2453. {
  2454. .name = "Commands during non-blocking read - use Set Block Count (CMD23)",
  2455. .prepare = mmc_test_area_prepare,
  2456. .run = mmc_test_cmds_during_read_cmd23_nonblock,
  2457. .cleanup = mmc_test_area_cleanup,
  2458. },
  2459. {
  2460. .name = "Commands during non-blocking write - use Set Block Count (CMD23)",
  2461. .prepare = mmc_test_area_prepare,
  2462. .run = mmc_test_cmds_during_write_cmd23_nonblock,
  2463. .cleanup = mmc_test_area_cleanup,
  2464. },
  2465. };
  2466. static DEFINE_MUTEX(mmc_test_lock);
  2467. static LIST_HEAD(mmc_test_result);
  2468. static void mmc_test_run(struct mmc_test_card *test, int testcase)
  2469. {
  2470. int i, ret;
  2471. pr_info("%s: Starting tests of card %s...\n",
  2472. mmc_hostname(test->card->host), mmc_card_id(test->card));
  2473. mmc_claim_host(test->card->host);
  2474. for (i = 0; i < ARRAY_SIZE(mmc_test_cases); i++) {
  2475. struct mmc_test_general_result *gr;
  2476. if (testcase && ((i + 1) != testcase))
  2477. continue;
  2478. pr_info("%s: Test case %d. %s...\n",
  2479. mmc_hostname(test->card->host), i + 1,
  2480. mmc_test_cases[i].name);
  2481. if (mmc_test_cases[i].prepare) {
  2482. ret = mmc_test_cases[i].prepare(test);
  2483. if (ret) {
  2484. pr_info("%s: Result: Prepare stage failed! (%d)\n",
  2485. mmc_hostname(test->card->host),
  2486. ret);
  2487. continue;
  2488. }
  2489. }
  2490. gr = kzalloc(sizeof(*gr), GFP_KERNEL);
  2491. if (gr) {
  2492. INIT_LIST_HEAD(&gr->tr_lst);
  2493. /* Assign data what we know already */
  2494. gr->card = test->card;
  2495. gr->testcase = i;
  2496. /* Append container to global one */
  2497. list_add_tail(&gr->link, &mmc_test_result);
  2498. /*
  2499. * Save the pointer to created container in our private
  2500. * structure.
  2501. */
  2502. test->gr = gr;
  2503. }
  2504. ret = mmc_test_cases[i].run(test);
  2505. switch (ret) {
  2506. case RESULT_OK:
  2507. pr_info("%s: Result: OK\n",
  2508. mmc_hostname(test->card->host));
  2509. break;
  2510. case RESULT_FAIL:
  2511. pr_info("%s: Result: FAILED\n",
  2512. mmc_hostname(test->card->host));
  2513. break;
  2514. case RESULT_UNSUP_HOST:
  2515. pr_info("%s: Result: UNSUPPORTED (by host)\n",
  2516. mmc_hostname(test->card->host));
  2517. break;
  2518. case RESULT_UNSUP_CARD:
  2519. pr_info("%s: Result: UNSUPPORTED (by card)\n",
  2520. mmc_hostname(test->card->host));
  2521. break;
  2522. default:
  2523. pr_info("%s: Result: ERROR (%d)\n",
  2524. mmc_hostname(test->card->host), ret);
  2525. }
  2526. /* Save the result */
  2527. if (gr)
  2528. gr->result = ret;
  2529. if (mmc_test_cases[i].cleanup) {
  2530. ret = mmc_test_cases[i].cleanup(test);
  2531. if (ret) {
  2532. pr_info("%s: Warning: Cleanup stage failed! (%d)\n",
  2533. mmc_hostname(test->card->host),
  2534. ret);
  2535. }
  2536. }
  2537. }
  2538. mmc_release_host(test->card->host);
  2539. pr_info("%s: Tests completed.\n",
  2540. mmc_hostname(test->card->host));
  2541. }
  2542. static void mmc_test_free_result(struct mmc_card *card)
  2543. {
  2544. struct mmc_test_general_result *gr, *grs;
  2545. mutex_lock(&mmc_test_lock);
  2546. list_for_each_entry_safe(gr, grs, &mmc_test_result, link) {
  2547. struct mmc_test_transfer_result *tr, *trs;
  2548. if (card && gr->card != card)
  2549. continue;
  2550. list_for_each_entry_safe(tr, trs, &gr->tr_lst, link) {
  2551. list_del(&tr->link);
  2552. kfree(tr);
  2553. }
  2554. list_del(&gr->link);
  2555. kfree(gr);
  2556. }
  2557. mutex_unlock(&mmc_test_lock);
  2558. }
  2559. static LIST_HEAD(mmc_test_file_test);
  2560. static int mtf_test_show(struct seq_file *sf, void *data)
  2561. {
  2562. struct mmc_card *card = (struct mmc_card *)sf->private;
  2563. struct mmc_test_general_result *gr;
  2564. mutex_lock(&mmc_test_lock);
  2565. list_for_each_entry(gr, &mmc_test_result, link) {
  2566. struct mmc_test_transfer_result *tr;
  2567. if (gr->card != card)
  2568. continue;
  2569. seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
  2570. list_for_each_entry(tr, &gr->tr_lst, link) {
  2571. seq_printf(sf, "%u %d %lu.%09lu %u %u.%02u\n",
  2572. tr->count, tr->sectors,
  2573. (unsigned long)tr->ts.tv_sec,
  2574. (unsigned long)tr->ts.tv_nsec,
  2575. tr->rate, tr->iops / 100, tr->iops % 100);
  2576. }
  2577. }
  2578. mutex_unlock(&mmc_test_lock);
  2579. return 0;
  2580. }
  2581. static int mtf_test_open(struct inode *inode, struct file *file)
  2582. {
  2583. return single_open(file, mtf_test_show, inode->i_private);
  2584. }
  2585. static ssize_t mtf_test_write(struct file *file, const char __user *buf,
  2586. size_t count, loff_t *pos)
  2587. {
  2588. struct seq_file *sf = (struct seq_file *)file->private_data;
  2589. struct mmc_card *card = (struct mmc_card *)sf->private;
  2590. struct mmc_test_card *test;
  2591. long testcase;
  2592. int ret;
  2593. ret = kstrtol_from_user(buf, count, 10, &testcase);
  2594. if (ret)
  2595. return ret;
  2596. test = kzalloc(sizeof(*test), GFP_KERNEL);
  2597. if (!test)
  2598. return -ENOMEM;
  2599. /*
  2600. * Remove all test cases associated with given card. Thus we have only
  2601. * actual data of the last run.
  2602. */
  2603. mmc_test_free_result(card);
  2604. test->card = card;
  2605. test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL);
  2606. #ifdef CONFIG_HIGHMEM
  2607. test->highmem = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, BUFFER_ORDER);
  2608. #endif
  2609. #ifdef CONFIG_HIGHMEM
  2610. if (test->buffer && test->highmem) {
  2611. #else
  2612. if (test->buffer) {
  2613. #endif
  2614. mutex_lock(&mmc_test_lock);
  2615. mmc_test_run(test, testcase);
  2616. mutex_unlock(&mmc_test_lock);
  2617. }
  2618. #ifdef CONFIG_HIGHMEM
  2619. __free_pages(test->highmem, BUFFER_ORDER);
  2620. #endif
  2621. kfree(test->buffer);
  2622. kfree(test);
  2623. return count;
  2624. }
  2625. static const struct file_operations mmc_test_fops_test = {
  2626. .open = mtf_test_open,
  2627. .read = seq_read,
  2628. .write = mtf_test_write,
  2629. .llseek = seq_lseek,
  2630. .release = single_release,
  2631. };
  2632. static int mtf_testlist_show(struct seq_file *sf, void *data)
  2633. {
  2634. int i;
  2635. mutex_lock(&mmc_test_lock);
  2636. seq_puts(sf, "0:\tRun all tests\n");
  2637. for (i = 0; i < ARRAY_SIZE(mmc_test_cases); i++)
  2638. seq_printf(sf, "%d:\t%s\n", i + 1, mmc_test_cases[i].name);
  2639. mutex_unlock(&mmc_test_lock);
  2640. return 0;
  2641. }
  2642. static int mtf_testlist_open(struct inode *inode, struct file *file)
  2643. {
  2644. return single_open(file, mtf_testlist_show, inode->i_private);
  2645. }
  2646. static const struct file_operations mmc_test_fops_testlist = {
  2647. .open = mtf_testlist_open,
  2648. .read = seq_read,
  2649. .llseek = seq_lseek,
  2650. .release = single_release,
  2651. };
  2652. static void mmc_test_free_dbgfs_file(struct mmc_card *card)
  2653. {
  2654. struct mmc_test_dbgfs_file *df, *dfs;
  2655. mutex_lock(&mmc_test_lock);
  2656. list_for_each_entry_safe(df, dfs, &mmc_test_file_test, link) {
  2657. if (card && df->card != card)
  2658. continue;
  2659. debugfs_remove(df->file);
  2660. list_del(&df->link);
  2661. kfree(df);
  2662. }
  2663. mutex_unlock(&mmc_test_lock);
  2664. }
  2665. static int __mmc_test_register_dbgfs_file(struct mmc_card *card,
  2666. const char *name, umode_t mode, const struct file_operations *fops)
  2667. {
  2668. struct dentry *file = NULL;
  2669. struct mmc_test_dbgfs_file *df;
  2670. if (card->debugfs_root)
  2671. file = debugfs_create_file(name, mode, card->debugfs_root,
  2672. card, fops);
  2673. if (IS_ERR_OR_NULL(file)) {
  2674. dev_err(&card->dev,
  2675. "Can't create %s. Perhaps debugfs is disabled.\n",
  2676. name);
  2677. return -ENODEV;
  2678. }
  2679. df = kmalloc(sizeof(*df), GFP_KERNEL);
  2680. if (!df) {
  2681. debugfs_remove(file);
  2682. dev_err(&card->dev,
  2683. "Can't allocate memory for internal usage.\n");
  2684. return -ENOMEM;
  2685. }
  2686. df->card = card;
  2687. df->file = file;
  2688. list_add(&df->link, &mmc_test_file_test);
  2689. return 0;
  2690. }
  2691. static int mmc_test_register_dbgfs_file(struct mmc_card *card)
  2692. {
  2693. int ret;
  2694. mutex_lock(&mmc_test_lock);
  2695. ret = __mmc_test_register_dbgfs_file(card, "test", S_IWUSR | S_IRUGO,
  2696. &mmc_test_fops_test);
  2697. if (ret)
  2698. goto err;
  2699. ret = __mmc_test_register_dbgfs_file(card, "testlist", S_IRUGO,
  2700. &mmc_test_fops_testlist);
  2701. if (ret)
  2702. goto err;
  2703. err:
  2704. mutex_unlock(&mmc_test_lock);
  2705. return ret;
  2706. }
  2707. static int mmc_test_probe(struct mmc_card *card)
  2708. {
  2709. int ret;
  2710. if (!mmc_card_mmc(card) && !mmc_card_sd(card))
  2711. return -ENODEV;
  2712. ret = mmc_test_register_dbgfs_file(card);
  2713. if (ret)
  2714. return ret;
  2715. if (card->ext_csd.cmdq_en) {
  2716. mmc_claim_host(card->host);
  2717. ret = mmc_cmdq_disable(card);
  2718. mmc_release_host(card->host);
  2719. if (ret)
  2720. return ret;
  2721. }
  2722. dev_info(&card->dev, "Card claimed for testing.\n");
  2723. return 0;
  2724. }
  2725. static void mmc_test_remove(struct mmc_card *card)
  2726. {
  2727. if (card->reenable_cmdq) {
  2728. mmc_claim_host(card->host);
  2729. mmc_cmdq_enable(card);
  2730. mmc_release_host(card->host);
  2731. }
  2732. mmc_test_free_result(card);
  2733. mmc_test_free_dbgfs_file(card);
  2734. }
  2735. static void mmc_test_shutdown(struct mmc_card *card)
  2736. {
  2737. }
  2738. static struct mmc_driver mmc_driver = {
  2739. .drv = {
  2740. .name = "mmc_test",
  2741. },
  2742. .probe = mmc_test_probe,
  2743. .remove = mmc_test_remove,
  2744. .shutdown = mmc_test_shutdown,
  2745. };
  2746. static int __init mmc_test_init(void)
  2747. {
  2748. return mmc_register_driver(&mmc_driver);
  2749. }
  2750. static void __exit mmc_test_exit(void)
  2751. {
  2752. /* Clear stalled data if card is still plugged */
  2753. mmc_test_free_result(NULL);
  2754. mmc_test_free_dbgfs_file(NULL);
  2755. mmc_unregister_driver(&mmc_driver);
  2756. }
  2757. module_init(mmc_test_init);
  2758. module_exit(mmc_test_exit);
  2759. MODULE_LICENSE("GPL");
  2760. MODULE_DESCRIPTION("Multimedia Card (MMC) host test driver");
  2761. MODULE_AUTHOR("Pierre Ossman");