sdio.c 46 KB

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