sdio.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851
  1. /*
  2. * Marvell Wireless LAN device driver: SDIO specific handling
  3. *
  4. * Copyright (C) 2011, Marvell International Ltd.
  5. *
  6. * This software file (the "File") is distributed by Marvell International
  7. * Ltd. under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available by writing to the Free Software Foundation, Inc.,
  11. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
  12. * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  13. *
  14. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  17. * this warranty disclaimer.
  18. */
  19. #include <linux/firmware.h>
  20. #include "decl.h"
  21. #include "ioctl.h"
  22. #include "util.h"
  23. #include "fw.h"
  24. #include "main.h"
  25. #include "wmm.h"
  26. #include "11n.h"
  27. #include "sdio.h"
  28. #define SDIO_VERSION "1.0"
  29. /* The mwifiex_sdio_remove() callback function is called when
  30. * user removes this module from kernel space or ejects
  31. * the card from the slot. The driver handles these 2 cases
  32. * differently.
  33. * If the user is removing the module, the few commands (FUNC_SHUTDOWN,
  34. * HS_CANCEL etc.) are sent to the firmware.
  35. * If the card is removed, there is no need to send these command.
  36. *
  37. * The variable 'user_rmmod' is used to distinguish these two
  38. * scenarios. This flag is initialized as FALSE in case the card
  39. * is removed, and will be set to TRUE for module removal when
  40. * module_exit function is called.
  41. */
  42. static u8 user_rmmod;
  43. static struct mwifiex_if_ops sdio_ops;
  44. static struct semaphore add_remove_card_sem;
  45. static int mwifiex_sdio_resume(struct device *dev);
  46. /*
  47. * SDIO probe.
  48. *
  49. * This function probes an mwifiex device and registers it. It allocates
  50. * the card structure, enables SDIO function number and initiates the
  51. * device registration and initialization procedure by adding a logical
  52. * interface.
  53. */
  54. static int
  55. mwifiex_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id)
  56. {
  57. int ret;
  58. struct sdio_mmc_card *card = NULL;
  59. pr_debug("info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n",
  60. func->vendor, func->device, func->class, func->num);
  61. card = kzalloc(sizeof(struct sdio_mmc_card), GFP_KERNEL);
  62. if (!card)
  63. return -ENOMEM;
  64. card->func = func;
  65. func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
  66. if (id->driver_data) {
  67. struct mwifiex_sdio_device *data = (void *)id->driver_data;
  68. card->firmware = data->firmware;
  69. card->reg = data->reg;
  70. card->max_ports = data->max_ports;
  71. card->mp_agg_pkt_limit = data->mp_agg_pkt_limit;
  72. }
  73. sdio_claim_host(func);
  74. ret = sdio_enable_func(func);
  75. sdio_release_host(func);
  76. if (ret) {
  77. pr_err("%s: failed to enable function\n", __func__);
  78. kfree(card);
  79. return -EIO;
  80. }
  81. if (mwifiex_add_card(card, &add_remove_card_sem, &sdio_ops,
  82. MWIFIEX_SDIO)) {
  83. pr_err("%s: add card failed\n", __func__);
  84. kfree(card);
  85. sdio_claim_host(func);
  86. ret = sdio_disable_func(func);
  87. sdio_release_host(func);
  88. ret = -1;
  89. }
  90. return ret;
  91. }
  92. /*
  93. * SDIO remove.
  94. *
  95. * This function removes the interface and frees up the card structure.
  96. */
  97. static void
  98. mwifiex_sdio_remove(struct sdio_func *func)
  99. {
  100. struct sdio_mmc_card *card;
  101. struct mwifiex_adapter *adapter;
  102. struct mwifiex_private *priv;
  103. int i;
  104. pr_debug("info: SDIO func num=%d\n", func->num);
  105. card = sdio_get_drvdata(func);
  106. if (!card)
  107. return;
  108. adapter = card->adapter;
  109. if (!adapter || !adapter->priv_num)
  110. return;
  111. /* In case driver is removed when asynchronous FW load is in progress */
  112. wait_for_completion(&adapter->fw_load);
  113. if (user_rmmod) {
  114. if (adapter->is_suspended)
  115. mwifiex_sdio_resume(adapter->dev);
  116. for (i = 0; i < adapter->priv_num; i++)
  117. if ((GET_BSS_ROLE(adapter->priv[i]) ==
  118. MWIFIEX_BSS_ROLE_STA) &&
  119. adapter->priv[i]->media_connected)
  120. mwifiex_deauthenticate(adapter->priv[i], NULL);
  121. priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
  122. mwifiex_disable_auto_ds(priv);
  123. mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN);
  124. }
  125. mwifiex_remove_card(card->adapter, &add_remove_card_sem);
  126. kfree(card);
  127. }
  128. /*
  129. * SDIO suspend.
  130. *
  131. * Kernel needs to suspend all functions separately. Therefore all
  132. * registered functions must have drivers with suspend and resume
  133. * methods. Failing that the kernel simply removes the whole card.
  134. *
  135. * If already not suspended, this function allocates and sends a host
  136. * sleep activate request to the firmware and turns off the traffic.
  137. */
  138. static int mwifiex_sdio_suspend(struct device *dev)
  139. {
  140. struct sdio_func *func = dev_to_sdio_func(dev);
  141. struct sdio_mmc_card *card;
  142. struct mwifiex_adapter *adapter;
  143. mmc_pm_flag_t pm_flag = 0;
  144. int ret = 0;
  145. if (func) {
  146. pm_flag = sdio_get_host_pm_caps(func);
  147. pr_debug("cmd: %s: suspend: PM flag = 0x%x\n",
  148. sdio_func_id(func), pm_flag);
  149. if (!(pm_flag & MMC_PM_KEEP_POWER)) {
  150. pr_err("%s: cannot remain alive while host is"
  151. " suspended\n", sdio_func_id(func));
  152. return -ENOSYS;
  153. }
  154. card = sdio_get_drvdata(func);
  155. if (!card || !card->adapter) {
  156. pr_err("suspend: invalid card or adapter\n");
  157. return 0;
  158. }
  159. } else {
  160. pr_err("suspend: sdio_func is not specified\n");
  161. return 0;
  162. }
  163. adapter = card->adapter;
  164. /* Enable the Host Sleep */
  165. if (!mwifiex_enable_hs(adapter)) {
  166. dev_err(adapter->dev, "cmd: failed to suspend\n");
  167. return -EFAULT;
  168. }
  169. dev_dbg(adapter->dev, "cmd: suspend with MMC_PM_KEEP_POWER\n");
  170. ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
  171. /* Indicate device suspended */
  172. adapter->is_suspended = true;
  173. return ret;
  174. }
  175. /*
  176. * SDIO resume.
  177. *
  178. * Kernel needs to suspend all functions separately. Therefore all
  179. * registered functions must have drivers with suspend and resume
  180. * methods. Failing that the kernel simply removes the whole card.
  181. *
  182. * If already not resumed, this function turns on the traffic and
  183. * sends a host sleep cancel request to the firmware.
  184. */
  185. static int mwifiex_sdio_resume(struct device *dev)
  186. {
  187. struct sdio_func *func = dev_to_sdio_func(dev);
  188. struct sdio_mmc_card *card;
  189. struct mwifiex_adapter *adapter;
  190. mmc_pm_flag_t pm_flag = 0;
  191. if (func) {
  192. pm_flag = sdio_get_host_pm_caps(func);
  193. card = sdio_get_drvdata(func);
  194. if (!card || !card->adapter) {
  195. pr_err("resume: invalid card or adapter\n");
  196. return 0;
  197. }
  198. } else {
  199. pr_err("resume: sdio_func is not specified\n");
  200. return 0;
  201. }
  202. adapter = card->adapter;
  203. if (!adapter->is_suspended) {
  204. dev_warn(adapter->dev, "device already resumed\n");
  205. return 0;
  206. }
  207. adapter->is_suspended = false;
  208. /* Disable Host Sleep */
  209. mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
  210. MWIFIEX_ASYNC_CMD);
  211. return 0;
  212. }
  213. /* Device ID for SD8786 */
  214. #define SDIO_DEVICE_ID_MARVELL_8786 (0x9116)
  215. /* Device ID for SD8787 */
  216. #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
  217. /* Device ID for SD8797 */
  218. #define SDIO_DEVICE_ID_MARVELL_8797 (0x9129)
  219. /* WLAN IDs */
  220. static const struct sdio_device_id mwifiex_ids[] = {
  221. {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8786),
  222. .driver_data = (unsigned long) &mwifiex_sdio_sd8786},
  223. {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8787),
  224. .driver_data = (unsigned long) &mwifiex_sdio_sd8787},
  225. {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797),
  226. .driver_data = (unsigned long) &mwifiex_sdio_sd8797},
  227. {},
  228. };
  229. MODULE_DEVICE_TABLE(sdio, mwifiex_ids);
  230. static const struct dev_pm_ops mwifiex_sdio_pm_ops = {
  231. .suspend = mwifiex_sdio_suspend,
  232. .resume = mwifiex_sdio_resume,
  233. };
  234. static struct sdio_driver mwifiex_sdio = {
  235. .name = "mwifiex_sdio",
  236. .id_table = mwifiex_ids,
  237. .probe = mwifiex_sdio_probe,
  238. .remove = mwifiex_sdio_remove,
  239. .drv = {
  240. .owner = THIS_MODULE,
  241. .pm = &mwifiex_sdio_pm_ops,
  242. }
  243. };
  244. /*
  245. * This function writes data into SDIO card register.
  246. */
  247. static int
  248. mwifiex_write_reg(struct mwifiex_adapter *adapter, u32 reg, u32 data)
  249. {
  250. struct sdio_mmc_card *card = adapter->card;
  251. int ret = -1;
  252. sdio_claim_host(card->func);
  253. sdio_writeb(card->func, (u8) data, reg, &ret);
  254. sdio_release_host(card->func);
  255. return ret;
  256. }
  257. /*
  258. * This function reads data from SDIO card register.
  259. */
  260. static int
  261. mwifiex_read_reg(struct mwifiex_adapter *adapter, u32 reg, u32 *data)
  262. {
  263. struct sdio_mmc_card *card = adapter->card;
  264. int ret = -1;
  265. u8 val;
  266. sdio_claim_host(card->func);
  267. val = sdio_readb(card->func, reg, &ret);
  268. sdio_release_host(card->func);
  269. *data = val;
  270. return ret;
  271. }
  272. /*
  273. * This function writes multiple data into SDIO card memory.
  274. *
  275. * This does not work in suspended mode.
  276. */
  277. static int
  278. mwifiex_write_data_sync(struct mwifiex_adapter *adapter,
  279. u8 *buffer, u32 pkt_len, u32 port)
  280. {
  281. struct sdio_mmc_card *card = adapter->card;
  282. int ret;
  283. u8 blk_mode =
  284. (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
  285. u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
  286. u32 blk_cnt =
  287. (blk_mode ==
  288. BLOCK_MODE) ? (pkt_len /
  289. MWIFIEX_SDIO_BLOCK_SIZE) : pkt_len;
  290. u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
  291. if (adapter->is_suspended) {
  292. dev_err(adapter->dev,
  293. "%s: not allowed while suspended\n", __func__);
  294. return -1;
  295. }
  296. sdio_claim_host(card->func);
  297. ret = sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size);
  298. sdio_release_host(card->func);
  299. return ret;
  300. }
  301. /*
  302. * This function reads multiple data from SDIO card memory.
  303. */
  304. static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer,
  305. u32 len, u32 port, u8 claim)
  306. {
  307. struct sdio_mmc_card *card = adapter->card;
  308. int ret;
  309. u8 blk_mode = (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE
  310. : BLOCK_MODE;
  311. u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
  312. u32 blk_cnt = (blk_mode == BLOCK_MODE) ? (len / MWIFIEX_SDIO_BLOCK_SIZE)
  313. : len;
  314. u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
  315. if (claim)
  316. sdio_claim_host(card->func);
  317. ret = sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size);
  318. if (claim)
  319. sdio_release_host(card->func);
  320. return ret;
  321. }
  322. /*
  323. * This function wakes up the card.
  324. *
  325. * A host power up command is written to the card configuration
  326. * register to wake up the card.
  327. */
  328. static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
  329. {
  330. dev_dbg(adapter->dev, "event: wakeup device...\n");
  331. return mwifiex_write_reg(adapter, CONFIGURATION_REG, HOST_POWER_UP);
  332. }
  333. /*
  334. * This function is called after the card has woken up.
  335. *
  336. * The card configuration register is reset.
  337. */
  338. static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
  339. {
  340. dev_dbg(adapter->dev, "cmd: wakeup device completed\n");
  341. return mwifiex_write_reg(adapter, CONFIGURATION_REG, 0);
  342. }
  343. /*
  344. * This function initializes the IO ports.
  345. *
  346. * The following operations are performed -
  347. * - Read the IO ports (0, 1 and 2)
  348. * - Set host interrupt Reset-To-Read to clear
  349. * - Set auto re-enable interrupt
  350. */
  351. static int mwifiex_init_sdio_ioport(struct mwifiex_adapter *adapter)
  352. {
  353. u32 reg;
  354. struct sdio_mmc_card *card = adapter->card;
  355. adapter->ioport = 0;
  356. /* Read the IO port */
  357. if (!mwifiex_read_reg(adapter, IO_PORT_0_REG, &reg))
  358. adapter->ioport |= (reg & 0xff);
  359. else
  360. return -1;
  361. if (!mwifiex_read_reg(adapter, IO_PORT_1_REG, &reg))
  362. adapter->ioport |= ((reg & 0xff) << 8);
  363. else
  364. return -1;
  365. if (!mwifiex_read_reg(adapter, IO_PORT_2_REG, &reg))
  366. adapter->ioport |= ((reg & 0xff) << 16);
  367. else
  368. return -1;
  369. pr_debug("info: SDIO FUNC1 IO port: %#x\n", adapter->ioport);
  370. /* Set Host interrupt reset to read to clear */
  371. if (!mwifiex_read_reg(adapter, HOST_INT_RSR_REG, &reg))
  372. mwifiex_write_reg(adapter, HOST_INT_RSR_REG,
  373. reg | card->reg->sdio_int_mask);
  374. else
  375. return -1;
  376. /* Dnld/Upld ready set to auto reset */
  377. if (!mwifiex_read_reg(adapter, card->reg->card_misc_cfg_reg, &reg))
  378. mwifiex_write_reg(adapter, card->reg->card_misc_cfg_reg,
  379. reg | AUTO_RE_ENABLE_INT);
  380. else
  381. return -1;
  382. return 0;
  383. }
  384. /*
  385. * This function sends data to the card.
  386. */
  387. static int mwifiex_write_data_to_card(struct mwifiex_adapter *adapter,
  388. u8 *payload, u32 pkt_len, u32 port)
  389. {
  390. u32 i = 0;
  391. int ret;
  392. do {
  393. ret = mwifiex_write_data_sync(adapter, payload, pkt_len, port);
  394. if (ret) {
  395. i++;
  396. dev_err(adapter->dev, "host_to_card, write iomem"
  397. " (%d) failed: %d\n", i, ret);
  398. if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04))
  399. dev_err(adapter->dev, "write CFG reg failed\n");
  400. ret = -1;
  401. if (i > MAX_WRITE_IOMEM_RETRY)
  402. return ret;
  403. }
  404. } while (ret == -1);
  405. return ret;
  406. }
  407. /*
  408. * This function gets the read port.
  409. *
  410. * If control port bit is set in MP read bitmap, the control port
  411. * is returned, otherwise the current read port is returned and
  412. * the value is increased (provided it does not reach the maximum
  413. * limit, in which case it is reset to 1)
  414. */
  415. static int mwifiex_get_rd_port(struct mwifiex_adapter *adapter, u8 *port)
  416. {
  417. struct sdio_mmc_card *card = adapter->card;
  418. const struct mwifiex_sdio_card_reg *reg = card->reg;
  419. u32 rd_bitmap = card->mp_rd_bitmap;
  420. dev_dbg(adapter->dev, "data: mp_rd_bitmap=0x%08x\n", rd_bitmap);
  421. if (!(rd_bitmap & (CTRL_PORT_MASK | reg->data_port_mask)))
  422. return -1;
  423. if (card->mp_rd_bitmap & CTRL_PORT_MASK) {
  424. card->mp_rd_bitmap &= (u32) (~CTRL_PORT_MASK);
  425. *port = CTRL_PORT;
  426. dev_dbg(adapter->dev, "data: port=%d mp_rd_bitmap=0x%08x\n",
  427. *port, card->mp_rd_bitmap);
  428. } else {
  429. if (card->mp_rd_bitmap & (1 << card->curr_rd_port)) {
  430. card->mp_rd_bitmap &= (u32)
  431. (~(1 << card->curr_rd_port));
  432. *port = card->curr_rd_port;
  433. if (++card->curr_rd_port == card->max_ports)
  434. card->curr_rd_port = reg->start_rd_port;
  435. } else {
  436. return -1;
  437. }
  438. dev_dbg(adapter->dev,
  439. "data: port=%d mp_rd_bitmap=0x%08x -> 0x%08x\n",
  440. *port, rd_bitmap, card->mp_rd_bitmap);
  441. }
  442. return 0;
  443. }
  444. /*
  445. * This function gets the write port for data.
  446. *
  447. * The current write port is returned if available and the value is
  448. * increased (provided it does not reach the maximum limit, in which
  449. * case it is reset to 1)
  450. */
  451. static int mwifiex_get_wr_port_data(struct mwifiex_adapter *adapter, u8 *port)
  452. {
  453. struct sdio_mmc_card *card = adapter->card;
  454. u32 wr_bitmap = card->mp_wr_bitmap;
  455. dev_dbg(adapter->dev, "data: mp_wr_bitmap=0x%08x\n", wr_bitmap);
  456. if (!(wr_bitmap & card->mp_data_port_mask))
  457. return -1;
  458. if (card->mp_wr_bitmap & (1 << card->curr_wr_port)) {
  459. card->mp_wr_bitmap &= (u32) (~(1 << card->curr_wr_port));
  460. *port = card->curr_wr_port;
  461. if (++card->curr_wr_port == card->mp_end_port)
  462. card->curr_wr_port = card->reg->start_wr_port;
  463. } else {
  464. adapter->data_sent = true;
  465. return -EBUSY;
  466. }
  467. if (*port == CTRL_PORT) {
  468. dev_err(adapter->dev,
  469. "invalid data port=%d cur port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n",
  470. *port, card->curr_wr_port, wr_bitmap,
  471. card->mp_wr_bitmap);
  472. return -1;
  473. }
  474. dev_dbg(adapter->dev, "data: port=%d mp_wr_bitmap=0x%08x -> 0x%08x\n",
  475. *port, wr_bitmap, card->mp_wr_bitmap);
  476. return 0;
  477. }
  478. /*
  479. * This function polls the card status.
  480. */
  481. static int
  482. mwifiex_sdio_poll_card_status(struct mwifiex_adapter *adapter, u8 bits)
  483. {
  484. struct sdio_mmc_card *card = adapter->card;
  485. u32 tries;
  486. u32 cs;
  487. for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
  488. if (mwifiex_read_reg(adapter, card->reg->poll_reg, &cs))
  489. break;
  490. else if ((cs & bits) == bits)
  491. return 0;
  492. usleep_range(10, 20);
  493. }
  494. dev_err(adapter->dev, "poll card status failed, tries = %d\n", tries);
  495. return -1;
  496. }
  497. /*
  498. * This function reads the firmware status.
  499. */
  500. static int
  501. mwifiex_sdio_read_fw_status(struct mwifiex_adapter *adapter, u16 *dat)
  502. {
  503. struct sdio_mmc_card *card = adapter->card;
  504. const struct mwifiex_sdio_card_reg *reg = card->reg;
  505. u32 fws0, fws1;
  506. if (mwifiex_read_reg(adapter, reg->status_reg_0, &fws0))
  507. return -1;
  508. if (mwifiex_read_reg(adapter, reg->status_reg_1, &fws1))
  509. return -1;
  510. *dat = (u16) ((fws1 << 8) | fws0);
  511. return 0;
  512. }
  513. /*
  514. * This function disables the host interrupt.
  515. *
  516. * The host interrupt mask is read, the disable bit is reset and
  517. * written back to the card host interrupt mask register.
  518. */
  519. static int mwifiex_sdio_disable_host_int(struct mwifiex_adapter *adapter)
  520. {
  521. u32 host_int_mask;
  522. /* Read back the host_int_mask register */
  523. if (mwifiex_read_reg(adapter, HOST_INT_MASK_REG, &host_int_mask))
  524. return -1;
  525. /* Update with the mask and write back to the register */
  526. host_int_mask &= ~HOST_INT_DISABLE;
  527. if (mwifiex_write_reg(adapter, HOST_INT_MASK_REG, host_int_mask)) {
  528. dev_err(adapter->dev, "disable host interrupt failed\n");
  529. return -1;
  530. }
  531. return 0;
  532. }
  533. /*
  534. * This function enables the host interrupt.
  535. *
  536. * The host interrupt enable mask is written to the card
  537. * host interrupt mask register.
  538. */
  539. static int mwifiex_sdio_enable_host_int(struct mwifiex_adapter *adapter)
  540. {
  541. struct sdio_mmc_card *card = adapter->card;
  542. /* Simply write the mask to the register */
  543. if (mwifiex_write_reg(adapter, HOST_INT_MASK_REG,
  544. card->reg->host_int_enable)) {
  545. dev_err(adapter->dev, "enable host interrupt failed\n");
  546. return -1;
  547. }
  548. return 0;
  549. }
  550. /*
  551. * This function sends a data buffer to the card.
  552. */
  553. static int mwifiex_sdio_card_to_host(struct mwifiex_adapter *adapter,
  554. u32 *type, u8 *buffer,
  555. u32 npayload, u32 ioport)
  556. {
  557. int ret;
  558. u32 nb;
  559. if (!buffer) {
  560. dev_err(adapter->dev, "%s: buffer is NULL\n", __func__);
  561. return -1;
  562. }
  563. ret = mwifiex_read_data_sync(adapter, buffer, npayload, ioport, 1);
  564. if (ret) {
  565. dev_err(adapter->dev, "%s: read iomem failed: %d\n", __func__,
  566. ret);
  567. return -1;
  568. }
  569. nb = le16_to_cpu(*(__le16 *) (buffer));
  570. if (nb > npayload) {
  571. dev_err(adapter->dev, "%s: invalid packet, nb=%d npayload=%d\n",
  572. __func__, nb, npayload);
  573. return -1;
  574. }
  575. *type = le16_to_cpu(*(__le16 *) (buffer + 2));
  576. return ret;
  577. }
  578. /*
  579. * This function downloads the firmware to the card.
  580. *
  581. * Firmware is downloaded to the card in blocks. Every block download
  582. * is tested for CRC errors, and retried a number of times before
  583. * returning failure.
  584. */
  585. static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
  586. struct mwifiex_fw_image *fw)
  587. {
  588. struct sdio_mmc_card *card = adapter->card;
  589. const struct mwifiex_sdio_card_reg *reg = card->reg;
  590. int ret;
  591. u8 *firmware = fw->fw_buf;
  592. u32 firmware_len = fw->fw_len;
  593. u32 offset = 0;
  594. u32 base0, base1;
  595. u8 *fwbuf;
  596. u16 len = 0;
  597. u32 txlen, tx_blocks = 0, tries;
  598. u32 i = 0;
  599. if (!firmware_len) {
  600. dev_err(adapter->dev,
  601. "firmware image not found! Terminating download\n");
  602. return -1;
  603. }
  604. dev_dbg(adapter->dev, "info: downloading FW image (%d bytes)\n",
  605. firmware_len);
  606. /* Assume that the allocated buffer is 8-byte aligned */
  607. fwbuf = kzalloc(MWIFIEX_UPLD_SIZE, GFP_KERNEL);
  608. if (!fwbuf)
  609. return -ENOMEM;
  610. /* Perform firmware data transfer */
  611. do {
  612. /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY
  613. bits */
  614. ret = mwifiex_sdio_poll_card_status(adapter, CARD_IO_READY |
  615. DN_LD_CARD_RDY);
  616. if (ret) {
  617. dev_err(adapter->dev, "FW download with helper:"
  618. " poll status timeout @ %d\n", offset);
  619. goto done;
  620. }
  621. /* More data? */
  622. if (offset >= firmware_len)
  623. break;
  624. for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
  625. ret = mwifiex_read_reg(adapter, reg->base_0_reg,
  626. &base0);
  627. if (ret) {
  628. dev_err(adapter->dev,
  629. "dev BASE0 register read failed: "
  630. "base0=%#04X(%d). Terminating dnld\n",
  631. base0, base0);
  632. goto done;
  633. }
  634. ret = mwifiex_read_reg(adapter, reg->base_1_reg,
  635. &base1);
  636. if (ret) {
  637. dev_err(adapter->dev,
  638. "dev BASE1 register read failed: "
  639. "base1=%#04X(%d). Terminating dnld\n",
  640. base1, base1);
  641. goto done;
  642. }
  643. len = (u16) (((base1 & 0xff) << 8) | (base0 & 0xff));
  644. if (len)
  645. break;
  646. usleep_range(10, 20);
  647. }
  648. if (!len) {
  649. break;
  650. } else if (len > MWIFIEX_UPLD_SIZE) {
  651. dev_err(adapter->dev,
  652. "FW dnld failed @ %d, invalid length %d\n",
  653. offset, len);
  654. ret = -1;
  655. goto done;
  656. }
  657. txlen = len;
  658. if (len & BIT(0)) {
  659. i++;
  660. if (i > MAX_WRITE_IOMEM_RETRY) {
  661. dev_err(adapter->dev,
  662. "FW dnld failed @ %d, over max retry\n",
  663. offset);
  664. ret = -1;
  665. goto done;
  666. }
  667. dev_err(adapter->dev, "CRC indicated by the helper:"
  668. " len = 0x%04X, txlen = %d\n", len, txlen);
  669. len &= ~BIT(0);
  670. /* Setting this to 0 to resend from same offset */
  671. txlen = 0;
  672. } else {
  673. i = 0;
  674. /* Set blocksize to transfer - checking for last
  675. block */
  676. if (firmware_len - offset < txlen)
  677. txlen = firmware_len - offset;
  678. tx_blocks = (txlen + MWIFIEX_SDIO_BLOCK_SIZE - 1)
  679. / MWIFIEX_SDIO_BLOCK_SIZE;
  680. /* Copy payload to buffer */
  681. memmove(fwbuf, &firmware[offset], txlen);
  682. }
  683. ret = mwifiex_write_data_sync(adapter, fwbuf, tx_blocks *
  684. MWIFIEX_SDIO_BLOCK_SIZE,
  685. adapter->ioport);
  686. if (ret) {
  687. dev_err(adapter->dev,
  688. "FW download, write iomem (%d) failed @ %d\n",
  689. i, offset);
  690. if (mwifiex_write_reg(adapter, CONFIGURATION_REG, 0x04))
  691. dev_err(adapter->dev, "write CFG reg failed\n");
  692. ret = -1;
  693. goto done;
  694. }
  695. offset += txlen;
  696. } while (true);
  697. dev_dbg(adapter->dev, "info: FW download over, size %d bytes\n",
  698. offset);
  699. ret = 0;
  700. done:
  701. kfree(fwbuf);
  702. return ret;
  703. }
  704. /*
  705. * This function checks the firmware status in card.
  706. *
  707. * The winner interface is also determined by this function.
  708. */
  709. static int mwifiex_check_fw_status(struct mwifiex_adapter *adapter,
  710. u32 poll_num)
  711. {
  712. struct sdio_mmc_card *card = adapter->card;
  713. int ret = 0;
  714. u16 firmware_stat;
  715. u32 tries;
  716. u32 winner_status;
  717. /* Wait for firmware initialization event */
  718. for (tries = 0; tries < poll_num; tries++) {
  719. ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat);
  720. if (ret)
  721. continue;
  722. if (firmware_stat == FIRMWARE_READY_SDIO) {
  723. ret = 0;
  724. break;
  725. } else {
  726. mdelay(100);
  727. ret = -1;
  728. }
  729. }
  730. if (ret) {
  731. if (mwifiex_read_reg
  732. (adapter, card->reg->status_reg_0, &winner_status))
  733. winner_status = 0;
  734. if (winner_status)
  735. adapter->winner = 0;
  736. else
  737. adapter->winner = 1;
  738. }
  739. return ret;
  740. }
  741. /*
  742. * This function reads the interrupt status from card.
  743. */
  744. static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter)
  745. {
  746. struct sdio_mmc_card *card = adapter->card;
  747. u32 sdio_ireg;
  748. unsigned long flags;
  749. if (mwifiex_read_data_sync(adapter, card->mp_regs,
  750. card->reg->max_mp_regs,
  751. REG_PORT | MWIFIEX_SDIO_BYTE_MODE_MASK, 0)) {
  752. dev_err(adapter->dev, "read mp_regs failed\n");
  753. return;
  754. }
  755. sdio_ireg = card->mp_regs[HOST_INTSTATUS_REG];
  756. if (sdio_ireg) {
  757. /*
  758. * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
  759. * Clear the interrupt status register
  760. */
  761. dev_dbg(adapter->dev, "int: sdio_ireg = %#x\n", sdio_ireg);
  762. spin_lock_irqsave(&adapter->int_lock, flags);
  763. adapter->int_status |= sdio_ireg;
  764. spin_unlock_irqrestore(&adapter->int_lock, flags);
  765. }
  766. }
  767. /*
  768. * SDIO interrupt handler.
  769. *
  770. * This function reads the interrupt status from firmware and handles
  771. * the interrupt in current thread (ksdioirqd) right away.
  772. */
  773. static void
  774. mwifiex_sdio_interrupt(struct sdio_func *func)
  775. {
  776. struct mwifiex_adapter *adapter;
  777. struct sdio_mmc_card *card;
  778. card = sdio_get_drvdata(func);
  779. if (!card || !card->adapter) {
  780. pr_debug("int: func=%p card=%p adapter=%p\n",
  781. func, card, card ? card->adapter : NULL);
  782. return;
  783. }
  784. adapter = card->adapter;
  785. if (adapter->surprise_removed)
  786. return;
  787. if (!adapter->pps_uapsd_mode && adapter->ps_state == PS_STATE_SLEEP)
  788. adapter->ps_state = PS_STATE_AWAKE;
  789. mwifiex_interrupt_status(adapter);
  790. mwifiex_main_process(adapter);
  791. }
  792. /*
  793. * This function decodes a received packet.
  794. *
  795. * Based on the type, the packet is treated as either a data, or
  796. * a command response, or an event, and the correct handler
  797. * function is invoked.
  798. */
  799. static int mwifiex_decode_rx_packet(struct mwifiex_adapter *adapter,
  800. struct sk_buff *skb, u32 upld_typ)
  801. {
  802. u8 *cmd_buf;
  803. skb_pull(skb, INTF_HEADER_LEN);
  804. switch (upld_typ) {
  805. case MWIFIEX_TYPE_DATA:
  806. dev_dbg(adapter->dev, "info: --- Rx: Data packet ---\n");
  807. mwifiex_handle_rx_packet(adapter, skb);
  808. break;
  809. case MWIFIEX_TYPE_CMD:
  810. dev_dbg(adapter->dev, "info: --- Rx: Cmd Response ---\n");
  811. /* take care of curr_cmd = NULL case */
  812. if (!adapter->curr_cmd) {
  813. cmd_buf = adapter->upld_buf;
  814. if (adapter->ps_state == PS_STATE_SLEEP_CFM)
  815. mwifiex_process_sleep_confirm_resp(adapter,
  816. skb->data,
  817. skb->len);
  818. memcpy(cmd_buf, skb->data,
  819. min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER,
  820. skb->len));
  821. dev_kfree_skb_any(skb);
  822. } else {
  823. adapter->cmd_resp_received = true;
  824. adapter->curr_cmd->resp_skb = skb;
  825. }
  826. break;
  827. case MWIFIEX_TYPE_EVENT:
  828. dev_dbg(adapter->dev, "info: --- Rx: Event ---\n");
  829. adapter->event_cause = *(u32 *) skb->data;
  830. if ((skb->len > 0) && (skb->len < MAX_EVENT_SIZE))
  831. memcpy(adapter->event_body,
  832. skb->data + MWIFIEX_EVENT_HEADER_LEN,
  833. skb->len);
  834. /* event cause has been saved to adapter->event_cause */
  835. adapter->event_received = true;
  836. adapter->event_skb = skb;
  837. break;
  838. default:
  839. dev_err(adapter->dev, "unknown upload type %#x\n", upld_typ);
  840. dev_kfree_skb_any(skb);
  841. break;
  842. }
  843. return 0;
  844. }
  845. /*
  846. * This function transfers received packets from card to driver, performing
  847. * aggregation if required.
  848. *
  849. * For data received on control port, or if aggregation is disabled, the
  850. * received buffers are uploaded as separate packets. However, if aggregation
  851. * is enabled and required, the buffers are copied onto an aggregation buffer,
  852. * provided there is space left, processed and finally uploaded.
  853. */
  854. static int mwifiex_sdio_card_to_host_mp_aggr(struct mwifiex_adapter *adapter,
  855. struct sk_buff *skb, u8 port)
  856. {
  857. struct sdio_mmc_card *card = adapter->card;
  858. s32 f_do_rx_aggr = 0;
  859. s32 f_do_rx_cur = 0;
  860. s32 f_aggr_cur = 0;
  861. struct sk_buff *skb_deaggr;
  862. u32 pind;
  863. u32 pkt_len, pkt_type = 0;
  864. u8 *curr_ptr;
  865. u32 rx_len = skb->len;
  866. if (port == CTRL_PORT) {
  867. /* Read the command Resp without aggr */
  868. dev_dbg(adapter->dev, "info: %s: no aggregation for cmd "
  869. "response\n", __func__);
  870. f_do_rx_cur = 1;
  871. goto rx_curr_single;
  872. }
  873. if (!card->mpa_rx.enabled) {
  874. dev_dbg(adapter->dev, "info: %s: rx aggregation disabled\n",
  875. __func__);
  876. f_do_rx_cur = 1;
  877. goto rx_curr_single;
  878. }
  879. if (card->mp_rd_bitmap & (~((u32) CTRL_PORT_MASK))) {
  880. /* Some more data RX pending */
  881. dev_dbg(adapter->dev, "info: %s: not last packet\n", __func__);
  882. if (MP_RX_AGGR_IN_PROGRESS(card)) {
  883. if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len)) {
  884. f_aggr_cur = 1;
  885. } else {
  886. /* No room in Aggr buf, do rx aggr now */
  887. f_do_rx_aggr = 1;
  888. f_do_rx_cur = 1;
  889. }
  890. } else {
  891. /* Rx aggr not in progress */
  892. f_aggr_cur = 1;
  893. }
  894. } else {
  895. /* No more data RX pending */
  896. dev_dbg(adapter->dev, "info: %s: last packet\n", __func__);
  897. if (MP_RX_AGGR_IN_PROGRESS(card)) {
  898. f_do_rx_aggr = 1;
  899. if (MP_RX_AGGR_BUF_HAS_ROOM(card, skb->len))
  900. f_aggr_cur = 1;
  901. else
  902. /* No room in Aggr buf, do rx aggr now */
  903. f_do_rx_cur = 1;
  904. } else {
  905. f_do_rx_cur = 1;
  906. }
  907. }
  908. if (f_aggr_cur) {
  909. dev_dbg(adapter->dev, "info: current packet aggregation\n");
  910. /* Curr pkt can be aggregated */
  911. MP_RX_AGGR_SETUP(card, skb, port);
  912. if (MP_RX_AGGR_PKT_LIMIT_REACHED(card) ||
  913. MP_RX_AGGR_PORT_LIMIT_REACHED(card)) {
  914. dev_dbg(adapter->dev, "info: %s: aggregated packet "
  915. "limit reached\n", __func__);
  916. /* No more pkts allowed in Aggr buf, rx it */
  917. f_do_rx_aggr = 1;
  918. }
  919. }
  920. if (f_do_rx_aggr) {
  921. /* do aggr RX now */
  922. dev_dbg(adapter->dev, "info: do_rx_aggr: num of packets: %d\n",
  923. card->mpa_rx.pkt_cnt);
  924. if (mwifiex_read_data_sync(adapter, card->mpa_rx.buf,
  925. card->mpa_rx.buf_len,
  926. (adapter->ioport | 0x1000 |
  927. (card->mpa_rx.ports << 4)) +
  928. card->mpa_rx.start_port, 1))
  929. goto error;
  930. curr_ptr = card->mpa_rx.buf;
  931. for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) {
  932. /* get curr PKT len & type */
  933. pkt_len = *(u16 *) &curr_ptr[0];
  934. pkt_type = *(u16 *) &curr_ptr[2];
  935. /* copy pkt to deaggr buf */
  936. skb_deaggr = card->mpa_rx.skb_arr[pind];
  937. if ((pkt_type == MWIFIEX_TYPE_DATA) && (pkt_len <=
  938. card->mpa_rx.len_arr[pind])) {
  939. memcpy(skb_deaggr->data, curr_ptr, pkt_len);
  940. skb_trim(skb_deaggr, pkt_len);
  941. /* Process de-aggr packet */
  942. mwifiex_decode_rx_packet(adapter, skb_deaggr,
  943. pkt_type);
  944. } else {
  945. dev_err(adapter->dev, "wrong aggr pkt:"
  946. " type=%d len=%d max_len=%d\n",
  947. pkt_type, pkt_len,
  948. card->mpa_rx.len_arr[pind]);
  949. dev_kfree_skb_any(skb_deaggr);
  950. }
  951. curr_ptr += card->mpa_rx.len_arr[pind];
  952. }
  953. MP_RX_AGGR_BUF_RESET(card);
  954. }
  955. rx_curr_single:
  956. if (f_do_rx_cur) {
  957. dev_dbg(adapter->dev, "info: RX: port: %d, rx_len: %d\n",
  958. port, rx_len);
  959. if (mwifiex_sdio_card_to_host(adapter, &pkt_type,
  960. skb->data, skb->len,
  961. adapter->ioport + port))
  962. goto error;
  963. mwifiex_decode_rx_packet(adapter, skb, pkt_type);
  964. }
  965. return 0;
  966. error:
  967. if (MP_RX_AGGR_IN_PROGRESS(card)) {
  968. /* Multiport-aggregation transfer failed - cleanup */
  969. for (pind = 0; pind < card->mpa_rx.pkt_cnt; pind++) {
  970. /* copy pkt to deaggr buf */
  971. skb_deaggr = card->mpa_rx.skb_arr[pind];
  972. dev_kfree_skb_any(skb_deaggr);
  973. }
  974. MP_RX_AGGR_BUF_RESET(card);
  975. }
  976. if (f_do_rx_cur)
  977. /* Single transfer pending. Free curr buff also */
  978. dev_kfree_skb_any(skb);
  979. return -1;
  980. }
  981. /*
  982. * This function checks the current interrupt status.
  983. *
  984. * The following interrupts are checked and handled by this function -
  985. * - Data sent
  986. * - Command sent
  987. * - Packets received
  988. *
  989. * Since the firmware does not generate download ready interrupt if the
  990. * port updated is command port only, command sent interrupt checking
  991. * should be done manually, and for every SDIO interrupt.
  992. *
  993. * In case of Rx packets received, the packets are uploaded from card to
  994. * host and processed accordingly.
  995. */
  996. static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
  997. {
  998. struct sdio_mmc_card *card = adapter->card;
  999. const struct mwifiex_sdio_card_reg *reg = card->reg;
  1000. int ret = 0;
  1001. u8 sdio_ireg;
  1002. struct sk_buff *skb;
  1003. u8 port = CTRL_PORT;
  1004. u32 len_reg_l, len_reg_u;
  1005. u32 rx_blocks;
  1006. u16 rx_len;
  1007. unsigned long flags;
  1008. spin_lock_irqsave(&adapter->int_lock, flags);
  1009. sdio_ireg = adapter->int_status;
  1010. adapter->int_status = 0;
  1011. spin_unlock_irqrestore(&adapter->int_lock, flags);
  1012. if (!sdio_ireg)
  1013. return ret;
  1014. if (sdio_ireg & DN_LD_HOST_INT_STATUS) {
  1015. card->mp_wr_bitmap =
  1016. ((u32) card->mp_regs[reg->wr_bitmap_u]) << 8;
  1017. card->mp_wr_bitmap |=
  1018. (u32) card->mp_regs[reg->wr_bitmap_l];
  1019. dev_dbg(adapter->dev, "int: DNLD: wr_bitmap=0x%08x\n",
  1020. card->mp_wr_bitmap);
  1021. if (adapter->data_sent &&
  1022. (card->mp_wr_bitmap & card->mp_data_port_mask)) {
  1023. dev_dbg(adapter->dev,
  1024. "info: <--- Tx DONE Interrupt --->\n");
  1025. adapter->data_sent = false;
  1026. }
  1027. }
  1028. /* As firmware will not generate download ready interrupt if the port
  1029. updated is command port only, cmd_sent should be done for any SDIO
  1030. interrupt. */
  1031. if (adapter->cmd_sent) {
  1032. /* Check if firmware has attach buffer at command port and
  1033. update just that in wr_bit_map. */
  1034. card->mp_wr_bitmap |=
  1035. (u32) card->mp_regs[reg->wr_bitmap_l] & CTRL_PORT_MASK;
  1036. if (card->mp_wr_bitmap & CTRL_PORT_MASK)
  1037. adapter->cmd_sent = false;
  1038. }
  1039. dev_dbg(adapter->dev, "info: cmd_sent=%d data_sent=%d\n",
  1040. adapter->cmd_sent, adapter->data_sent);
  1041. if (sdio_ireg & UP_LD_HOST_INT_STATUS) {
  1042. card->mp_rd_bitmap =
  1043. ((u32) card->mp_regs[reg->rd_bitmap_u]) << 8;
  1044. card->mp_rd_bitmap |= (u32) card->mp_regs[reg->rd_bitmap_l];
  1045. dev_dbg(adapter->dev, "int: UPLD: rd_bitmap=0x%08x\n",
  1046. card->mp_rd_bitmap);
  1047. while (true) {
  1048. ret = mwifiex_get_rd_port(adapter, &port);
  1049. if (ret) {
  1050. dev_dbg(adapter->dev,
  1051. "info: no more rd_port available\n");
  1052. break;
  1053. }
  1054. len_reg_l = reg->rd_len_p0_l + (port << 1);
  1055. len_reg_u = reg->rd_len_p0_u + (port << 1);
  1056. rx_len = ((u16) card->mp_regs[len_reg_u]) << 8;
  1057. rx_len |= (u16) card->mp_regs[len_reg_l];
  1058. dev_dbg(adapter->dev, "info: RX: port=%d rx_len=%u\n",
  1059. port, rx_len);
  1060. rx_blocks =
  1061. (rx_len + MWIFIEX_SDIO_BLOCK_SIZE -
  1062. 1) / MWIFIEX_SDIO_BLOCK_SIZE;
  1063. if (rx_len <= INTF_HEADER_LEN ||
  1064. (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE) >
  1065. MWIFIEX_RX_DATA_BUF_SIZE) {
  1066. dev_err(adapter->dev, "invalid rx_len=%d\n",
  1067. rx_len);
  1068. return -1;
  1069. }
  1070. rx_len = (u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE);
  1071. skb = dev_alloc_skb(rx_len);
  1072. if (!skb) {
  1073. dev_err(adapter->dev, "%s: failed to alloc skb",
  1074. __func__);
  1075. return -1;
  1076. }
  1077. skb_put(skb, rx_len);
  1078. dev_dbg(adapter->dev, "info: rx_len = %d skb->len = %d\n",
  1079. rx_len, skb->len);
  1080. if (mwifiex_sdio_card_to_host_mp_aggr(adapter, skb,
  1081. port)) {
  1082. u32 cr = 0;
  1083. dev_err(adapter->dev, "card_to_host_mpa failed:"
  1084. " int status=%#x\n", sdio_ireg);
  1085. if (mwifiex_read_reg(adapter,
  1086. CONFIGURATION_REG, &cr))
  1087. dev_err(adapter->dev,
  1088. "read CFG reg failed\n");
  1089. dev_dbg(adapter->dev,
  1090. "info: CFG reg val = %d\n", cr);
  1091. if (mwifiex_write_reg(adapter,
  1092. CONFIGURATION_REG,
  1093. (cr | 0x04)))
  1094. dev_err(adapter->dev,
  1095. "write CFG reg failed\n");
  1096. dev_dbg(adapter->dev, "info: write success\n");
  1097. if (mwifiex_read_reg(adapter,
  1098. CONFIGURATION_REG, &cr))
  1099. dev_err(adapter->dev,
  1100. "read CFG reg failed\n");
  1101. dev_dbg(adapter->dev,
  1102. "info: CFG reg val =%x\n", cr);
  1103. return -1;
  1104. }
  1105. }
  1106. }
  1107. return 0;
  1108. }
  1109. /*
  1110. * This function aggregates transmission buffers in driver and downloads
  1111. * the aggregated packet to card.
  1112. *
  1113. * The individual packets are aggregated by copying into an aggregation
  1114. * buffer and then downloaded to the card. Previous unsent packets in the
  1115. * aggregation buffer are pre-copied first before new packets are added.
  1116. * Aggregation is done till there is space left in the aggregation buffer,
  1117. * or till new packets are available.
  1118. *
  1119. * The function will only download the packet to the card when aggregation
  1120. * stops, otherwise it will just aggregate the packet in aggregation buffer
  1121. * and return.
  1122. */
  1123. static int mwifiex_host_to_card_mp_aggr(struct mwifiex_adapter *adapter,
  1124. u8 *payload, u32 pkt_len, u8 port,
  1125. u32 next_pkt_len)
  1126. {
  1127. struct sdio_mmc_card *card = adapter->card;
  1128. int ret = 0;
  1129. s32 f_send_aggr_buf = 0;
  1130. s32 f_send_cur_buf = 0;
  1131. s32 f_precopy_cur_buf = 0;
  1132. s32 f_postcopy_cur_buf = 0;
  1133. if ((!card->mpa_tx.enabled) || (port == CTRL_PORT)) {
  1134. dev_dbg(adapter->dev, "info: %s: tx aggregation disabled\n",
  1135. __func__);
  1136. f_send_cur_buf = 1;
  1137. goto tx_curr_single;
  1138. }
  1139. if (next_pkt_len) {
  1140. /* More pkt in TX queue */
  1141. dev_dbg(adapter->dev, "info: %s: more packets in queue.\n",
  1142. __func__);
  1143. if (MP_TX_AGGR_IN_PROGRESS(card)) {
  1144. if (!MP_TX_AGGR_PORT_LIMIT_REACHED(card) &&
  1145. MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) {
  1146. f_precopy_cur_buf = 1;
  1147. if (!(card->mp_wr_bitmap &
  1148. (1 << card->curr_wr_port)) ||
  1149. !MP_TX_AGGR_BUF_HAS_ROOM(
  1150. card, pkt_len + next_pkt_len))
  1151. f_send_aggr_buf = 1;
  1152. } else {
  1153. /* No room in Aggr buf, send it */
  1154. f_send_aggr_buf = 1;
  1155. if (MP_TX_AGGR_PORT_LIMIT_REACHED(card) ||
  1156. !(card->mp_wr_bitmap &
  1157. (1 << card->curr_wr_port)))
  1158. f_send_cur_buf = 1;
  1159. else
  1160. f_postcopy_cur_buf = 1;
  1161. }
  1162. } else {
  1163. if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len) &&
  1164. (card->mp_wr_bitmap & (1 << card->curr_wr_port)))
  1165. f_precopy_cur_buf = 1;
  1166. else
  1167. f_send_cur_buf = 1;
  1168. }
  1169. } else {
  1170. /* Last pkt in TX queue */
  1171. dev_dbg(adapter->dev, "info: %s: Last packet in Tx Queue.\n",
  1172. __func__);
  1173. if (MP_TX_AGGR_IN_PROGRESS(card)) {
  1174. /* some packs in Aggr buf already */
  1175. f_send_aggr_buf = 1;
  1176. if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len))
  1177. f_precopy_cur_buf = 1;
  1178. else
  1179. /* No room in Aggr buf, send it */
  1180. f_send_cur_buf = 1;
  1181. } else {
  1182. f_send_cur_buf = 1;
  1183. }
  1184. }
  1185. if (f_precopy_cur_buf) {
  1186. dev_dbg(adapter->dev, "data: %s: precopy current buffer\n",
  1187. __func__);
  1188. MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
  1189. if (MP_TX_AGGR_PKT_LIMIT_REACHED(card) ||
  1190. MP_TX_AGGR_PORT_LIMIT_REACHED(card))
  1191. /* No more pkts allowed in Aggr buf, send it */
  1192. f_send_aggr_buf = 1;
  1193. }
  1194. if (f_send_aggr_buf) {
  1195. dev_dbg(adapter->dev, "data: %s: send aggr buffer: %d %d\n",
  1196. __func__,
  1197. card->mpa_tx.start_port, card->mpa_tx.ports);
  1198. ret = mwifiex_write_data_to_card(adapter, card->mpa_tx.buf,
  1199. card->mpa_tx.buf_len,
  1200. (adapter->ioport | 0x1000 |
  1201. (card->mpa_tx.ports << 4)) +
  1202. card->mpa_tx.start_port);
  1203. MP_TX_AGGR_BUF_RESET(card);
  1204. }
  1205. tx_curr_single:
  1206. if (f_send_cur_buf) {
  1207. dev_dbg(adapter->dev, "data: %s: send current buffer %d\n",
  1208. __func__, port);
  1209. ret = mwifiex_write_data_to_card(adapter, payload, pkt_len,
  1210. adapter->ioport + port);
  1211. }
  1212. if (f_postcopy_cur_buf) {
  1213. dev_dbg(adapter->dev, "data: %s: postcopy current buffer\n",
  1214. __func__);
  1215. MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port);
  1216. }
  1217. return ret;
  1218. }
  1219. /*
  1220. * This function downloads data from driver to card.
  1221. *
  1222. * Both commands and data packets are transferred to the card by this
  1223. * function.
  1224. *
  1225. * This function adds the SDIO specific header to the front of the buffer
  1226. * before transferring. The header contains the length of the packet and
  1227. * the type. The firmware handles the packets based upon this set type.
  1228. */
  1229. static int mwifiex_sdio_host_to_card(struct mwifiex_adapter *adapter,
  1230. u8 type, struct sk_buff *skb,
  1231. struct mwifiex_tx_param *tx_param)
  1232. {
  1233. struct sdio_mmc_card *card = adapter->card;
  1234. int ret;
  1235. u32 buf_block_len;
  1236. u32 blk_size;
  1237. u8 port = CTRL_PORT;
  1238. u8 *payload = (u8 *)skb->data;
  1239. u32 pkt_len = skb->len;
  1240. /* Allocate buffer and copy payload */
  1241. blk_size = MWIFIEX_SDIO_BLOCK_SIZE;
  1242. buf_block_len = (pkt_len + blk_size - 1) / blk_size;
  1243. *(u16 *) &payload[0] = (u16) pkt_len;
  1244. *(u16 *) &payload[2] = type;
  1245. /*
  1246. * This is SDIO specific header
  1247. * u16 length,
  1248. * u16 type (MWIFIEX_TYPE_DATA = 0, MWIFIEX_TYPE_CMD = 1,
  1249. * MWIFIEX_TYPE_EVENT = 3)
  1250. */
  1251. if (type == MWIFIEX_TYPE_DATA) {
  1252. ret = mwifiex_get_wr_port_data(adapter, &port);
  1253. if (ret) {
  1254. dev_err(adapter->dev, "%s: no wr_port available\n",
  1255. __func__);
  1256. return ret;
  1257. }
  1258. } else {
  1259. adapter->cmd_sent = true;
  1260. /* Type must be MWIFIEX_TYPE_CMD */
  1261. if (pkt_len <= INTF_HEADER_LEN ||
  1262. pkt_len > MWIFIEX_UPLD_SIZE)
  1263. dev_err(adapter->dev, "%s: payload=%p, nb=%d\n",
  1264. __func__, payload, pkt_len);
  1265. }
  1266. /* Transfer data to card */
  1267. pkt_len = buf_block_len * blk_size;
  1268. if (tx_param)
  1269. ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
  1270. port, tx_param->next_pkt_len
  1271. );
  1272. else
  1273. ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
  1274. port, 0);
  1275. if (ret) {
  1276. if (type == MWIFIEX_TYPE_CMD)
  1277. adapter->cmd_sent = false;
  1278. if (type == MWIFIEX_TYPE_DATA)
  1279. adapter->data_sent = false;
  1280. } else {
  1281. if (type == MWIFIEX_TYPE_DATA) {
  1282. if (!(card->mp_wr_bitmap & (1 << card->curr_wr_port)))
  1283. adapter->data_sent = true;
  1284. else
  1285. adapter->data_sent = false;
  1286. }
  1287. }
  1288. return ret;
  1289. }
  1290. /*
  1291. * This function allocates the MPA Tx and Rx buffers.
  1292. */
  1293. static int mwifiex_alloc_sdio_mpa_buffers(struct mwifiex_adapter *adapter,
  1294. u32 mpa_tx_buf_size, u32 mpa_rx_buf_size)
  1295. {
  1296. struct sdio_mmc_card *card = adapter->card;
  1297. int ret = 0;
  1298. card->mpa_tx.buf = kzalloc(mpa_tx_buf_size, GFP_KERNEL);
  1299. if (!card->mpa_tx.buf) {
  1300. ret = -1;
  1301. goto error;
  1302. }
  1303. card->mpa_tx.buf_size = mpa_tx_buf_size;
  1304. card->mpa_rx.buf = kzalloc(mpa_rx_buf_size, GFP_KERNEL);
  1305. if (!card->mpa_rx.buf) {
  1306. ret = -1;
  1307. goto error;
  1308. }
  1309. card->mpa_rx.buf_size = mpa_rx_buf_size;
  1310. error:
  1311. if (ret) {
  1312. kfree(card->mpa_tx.buf);
  1313. kfree(card->mpa_rx.buf);
  1314. }
  1315. return ret;
  1316. }
  1317. /*
  1318. * This function unregisters the SDIO device.
  1319. *
  1320. * The SDIO IRQ is released, the function is disabled and driver
  1321. * data is set to null.
  1322. */
  1323. static void
  1324. mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
  1325. {
  1326. struct sdio_mmc_card *card = adapter->card;
  1327. if (adapter->card) {
  1328. /* Release the SDIO IRQ */
  1329. sdio_claim_host(card->func);
  1330. sdio_release_irq(card->func);
  1331. sdio_disable_func(card->func);
  1332. sdio_release_host(card->func);
  1333. sdio_set_drvdata(card->func, NULL);
  1334. }
  1335. }
  1336. /*
  1337. * This function registers the SDIO device.
  1338. *
  1339. * SDIO IRQ is claimed, block size is set and driver data is initialized.
  1340. */
  1341. static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
  1342. {
  1343. int ret = 0;
  1344. struct sdio_mmc_card *card = adapter->card;
  1345. struct sdio_func *func = card->func;
  1346. /* save adapter pointer in card */
  1347. card->adapter = adapter;
  1348. sdio_claim_host(func);
  1349. /* Request the SDIO IRQ */
  1350. ret = sdio_claim_irq(func, mwifiex_sdio_interrupt);
  1351. if (ret) {
  1352. pr_err("claim irq failed: ret=%d\n", ret);
  1353. goto disable_func;
  1354. }
  1355. /* Set block size */
  1356. ret = sdio_set_block_size(card->func, MWIFIEX_SDIO_BLOCK_SIZE);
  1357. if (ret) {
  1358. pr_err("cannot set SDIO block size\n");
  1359. ret = -1;
  1360. goto release_irq;
  1361. }
  1362. sdio_release_host(func);
  1363. sdio_set_drvdata(func, card);
  1364. adapter->dev = &func->dev;
  1365. strcpy(adapter->fw_name, card->firmware);
  1366. return 0;
  1367. release_irq:
  1368. sdio_release_irq(func);
  1369. disable_func:
  1370. sdio_disable_func(func);
  1371. sdio_release_host(func);
  1372. adapter->card = NULL;
  1373. return -1;
  1374. }
  1375. /*
  1376. * This function initializes the SDIO driver.
  1377. *
  1378. * The following initializations steps are followed -
  1379. * - Read the Host interrupt status register to acknowledge
  1380. * the first interrupt got from bootloader
  1381. * - Disable host interrupt mask register
  1382. * - Get SDIO port
  1383. * - Initialize SDIO variables in card
  1384. * - Allocate MP registers
  1385. * - Allocate MPA Tx and Rx buffers
  1386. */
  1387. static int mwifiex_init_sdio(struct mwifiex_adapter *adapter)
  1388. {
  1389. struct sdio_mmc_card *card = adapter->card;
  1390. const struct mwifiex_sdio_card_reg *reg = card->reg;
  1391. int ret;
  1392. u32 sdio_ireg;
  1393. /*
  1394. * Read the HOST_INT_STATUS_REG for ACK the first interrupt got
  1395. * from the bootloader. If we don't do this we get a interrupt
  1396. * as soon as we register the irq.
  1397. */
  1398. mwifiex_read_reg(adapter, HOST_INTSTATUS_REG, &sdio_ireg);
  1399. /* Disable host interrupt mask register for SDIO */
  1400. mwifiex_sdio_disable_host_int(adapter);
  1401. /* Get SDIO ioport */
  1402. mwifiex_init_sdio_ioport(adapter);
  1403. /* Initialize SDIO variables in card */
  1404. card->mp_rd_bitmap = 0;
  1405. card->mp_wr_bitmap = 0;
  1406. card->curr_rd_port = reg->start_rd_port;
  1407. card->curr_wr_port = reg->start_wr_port;
  1408. card->mp_data_port_mask = reg->data_port_mask;
  1409. card->mpa_tx.buf_len = 0;
  1410. card->mpa_tx.pkt_cnt = 0;
  1411. card->mpa_tx.start_port = 0;
  1412. card->mpa_tx.enabled = 1;
  1413. card->mpa_tx.pkt_aggr_limit = card->mp_agg_pkt_limit;
  1414. card->mpa_rx.buf_len = 0;
  1415. card->mpa_rx.pkt_cnt = 0;
  1416. card->mpa_rx.start_port = 0;
  1417. card->mpa_rx.enabled = 1;
  1418. card->mpa_rx.pkt_aggr_limit = card->mp_agg_pkt_limit;
  1419. /* Allocate buffers for SDIO MP-A */
  1420. card->mp_regs = kzalloc(reg->max_mp_regs, GFP_KERNEL);
  1421. if (!card->mp_regs)
  1422. return -ENOMEM;
  1423. ret = mwifiex_alloc_sdio_mpa_buffers(adapter,
  1424. SDIO_MP_TX_AGGR_DEF_BUF_SIZE,
  1425. SDIO_MP_RX_AGGR_DEF_BUF_SIZE);
  1426. if (ret) {
  1427. dev_err(adapter->dev, "failed to alloc sdio mp-a buffers\n");
  1428. kfree(card->mp_regs);
  1429. return -1;
  1430. }
  1431. return ret;
  1432. }
  1433. /*
  1434. * This function resets the MPA Tx and Rx buffers.
  1435. */
  1436. static void mwifiex_cleanup_mpa_buf(struct mwifiex_adapter *adapter)
  1437. {
  1438. struct sdio_mmc_card *card = adapter->card;
  1439. MP_TX_AGGR_BUF_RESET(card);
  1440. MP_RX_AGGR_BUF_RESET(card);
  1441. }
  1442. /*
  1443. * This function cleans up the allocated card buffers.
  1444. *
  1445. * The following are freed by this function -
  1446. * - MP registers
  1447. * - MPA Tx buffer
  1448. * - MPA Rx buffer
  1449. */
  1450. static void mwifiex_cleanup_sdio(struct mwifiex_adapter *adapter)
  1451. {
  1452. struct sdio_mmc_card *card = adapter->card;
  1453. kfree(card->mp_regs);
  1454. kfree(card->mpa_tx.buf);
  1455. kfree(card->mpa_rx.buf);
  1456. }
  1457. /*
  1458. * This function updates the MP end port in card.
  1459. */
  1460. static void
  1461. mwifiex_update_mp_end_port(struct mwifiex_adapter *adapter, u16 port)
  1462. {
  1463. struct sdio_mmc_card *card = adapter->card;
  1464. const struct mwifiex_sdio_card_reg *reg = card->reg;
  1465. int i;
  1466. card->mp_end_port = port;
  1467. card->mp_data_port_mask = reg->data_port_mask;
  1468. for (i = 1; i <= card->max_ports - card->mp_end_port; i++)
  1469. card->mp_data_port_mask &= ~(1 << (card->max_ports - i));
  1470. card->curr_wr_port = reg->start_wr_port;
  1471. dev_dbg(adapter->dev, "cmd: mp_end_port %d, data port mask 0x%x\n",
  1472. port, card->mp_data_port_mask);
  1473. }
  1474. static struct mmc_host *reset_host;
  1475. static void sdio_card_reset_worker(struct work_struct *work)
  1476. {
  1477. struct mmc_host *target = reset_host;
  1478. /* The actual reset operation must be run outside of driver thread.
  1479. * This is because mmc_remove_host() will cause the device to be
  1480. * instantly destroyed, and the driver then needs to end its thread,
  1481. * leading to a deadlock.
  1482. *
  1483. * We run it in a totally independent workqueue.
  1484. */
  1485. pr_err("Resetting card...\n");
  1486. mmc_remove_host(target);
  1487. /* 20ms delay is based on experiment with sdhci controller */
  1488. mdelay(20);
  1489. mmc_add_host(target);
  1490. }
  1491. static DECLARE_WORK(card_reset_work, sdio_card_reset_worker);
  1492. /* This function resets the card */
  1493. static void mwifiex_sdio_card_reset(struct mwifiex_adapter *adapter)
  1494. {
  1495. struct sdio_mmc_card *card = adapter->card;
  1496. reset_host = card->func->card->host;
  1497. schedule_work(&card_reset_work);
  1498. }
  1499. static struct mwifiex_if_ops sdio_ops = {
  1500. .init_if = mwifiex_init_sdio,
  1501. .cleanup_if = mwifiex_cleanup_sdio,
  1502. .check_fw_status = mwifiex_check_fw_status,
  1503. .prog_fw = mwifiex_prog_fw_w_helper,
  1504. .register_dev = mwifiex_register_dev,
  1505. .unregister_dev = mwifiex_unregister_dev,
  1506. .enable_int = mwifiex_sdio_enable_host_int,
  1507. .process_int_status = mwifiex_process_int_status,
  1508. .host_to_card = mwifiex_sdio_host_to_card,
  1509. .wakeup = mwifiex_pm_wakeup_card,
  1510. .wakeup_complete = mwifiex_pm_wakeup_card_complete,
  1511. /* SDIO specific */
  1512. .update_mp_end_port = mwifiex_update_mp_end_port,
  1513. .cleanup_mpa_buf = mwifiex_cleanup_mpa_buf,
  1514. .cmdrsp_complete = mwifiex_sdio_cmdrsp_complete,
  1515. .event_complete = mwifiex_sdio_event_complete,
  1516. .card_reset = mwifiex_sdio_card_reset,
  1517. };
  1518. /*
  1519. * This function initializes the SDIO driver.
  1520. *
  1521. * This initiates the semaphore and registers the device with
  1522. * SDIO bus.
  1523. */
  1524. static int
  1525. mwifiex_sdio_init_module(void)
  1526. {
  1527. sema_init(&add_remove_card_sem, 1);
  1528. /* Clear the flag in case user removes the card. */
  1529. user_rmmod = 0;
  1530. return sdio_register_driver(&mwifiex_sdio);
  1531. }
  1532. /*
  1533. * This function cleans up the SDIO driver.
  1534. *
  1535. * The following major steps are followed for cleanup -
  1536. * - Resume the device if its suspended
  1537. * - Disconnect the device if connected
  1538. * - Shutdown the firmware
  1539. * - Unregister the device from SDIO bus.
  1540. */
  1541. static void
  1542. mwifiex_sdio_cleanup_module(void)
  1543. {
  1544. if (!down_interruptible(&add_remove_card_sem))
  1545. up(&add_remove_card_sem);
  1546. /* Set the flag as user is removing this module. */
  1547. user_rmmod = 1;
  1548. cancel_work_sync(&card_reset_work);
  1549. sdio_unregister_driver(&mwifiex_sdio);
  1550. }
  1551. module_init(mwifiex_sdio_init_module);
  1552. module_exit(mwifiex_sdio_cleanup_module);
  1553. MODULE_AUTHOR("Marvell International Ltd.");
  1554. MODULE_DESCRIPTION("Marvell WiFi-Ex SDIO Driver version " SDIO_VERSION);
  1555. MODULE_VERSION(SDIO_VERSION);
  1556. MODULE_LICENSE("GPL v2");
  1557. MODULE_FIRMWARE(SD8786_DEFAULT_FW_NAME);
  1558. MODULE_FIRMWARE(SD8787_DEFAULT_FW_NAME);
  1559. MODULE_FIRMWARE(SD8797_DEFAULT_FW_NAME);