Bcmchar.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144
  1. #include <linux/fs.h>
  2. #include "headers.h"
  3. /***************************************************************
  4. * Function - bcm_char_open()
  5. *
  6. * Description - This is the "open" entry point for the character
  7. * driver.
  8. *
  9. * Parameters - inode: Pointer to the Inode structure of char device
  10. * filp : File pointer of the char device
  11. *
  12. * Returns - Zero(Success)
  13. ****************************************************************/
  14. static int bcm_char_open(struct inode *inode, struct file * filp)
  15. {
  16. PMINI_ADAPTER Adapter = NULL;
  17. PPER_TARANG_DATA pTarang = NULL;
  18. Adapter = GET_BCM_ADAPTER(gblpnetdev);
  19. pTarang = kzalloc(sizeof(PER_TARANG_DATA), GFP_KERNEL);
  20. if (!pTarang)
  21. return -ENOMEM;
  22. pTarang->Adapter = Adapter;
  23. pTarang->RxCntrlMsgBitMask = 0xFFFFFFFF & ~(1 << 0xB);
  24. down(&Adapter->RxAppControlQueuelock);
  25. pTarang->next = Adapter->pTarangs;
  26. Adapter->pTarangs = pTarang;
  27. up(&Adapter->RxAppControlQueuelock);
  28. /* Store the Adapter structure */
  29. filp->private_data = pTarang;
  30. /*Start Queuing the control response Packets*/
  31. atomic_inc(&Adapter->ApplicationRunning);
  32. nonseekable_open(inode, filp);
  33. return 0;
  34. }
  35. static int bcm_char_release(struct inode *inode, struct file *filp)
  36. {
  37. PPER_TARANG_DATA pTarang, tmp, ptmp;
  38. PMINI_ADAPTER Adapter = NULL;
  39. struct sk_buff *pkt, *npkt;
  40. pTarang = (PPER_TARANG_DATA)filp->private_data;
  41. if (pTarang == NULL) {
  42. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
  43. "ptarang is null\n");
  44. return 0;
  45. }
  46. Adapter = pTarang->Adapter;
  47. down(&Adapter->RxAppControlQueuelock);
  48. tmp = Adapter->pTarangs;
  49. for (ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next) {
  50. if (tmp == pTarang)
  51. break;
  52. }
  53. if (tmp) {
  54. if (!ptmp)
  55. Adapter->pTarangs = tmp->next;
  56. else
  57. ptmp->next = tmp->next;
  58. } else {
  59. up(&Adapter->RxAppControlQueuelock);
  60. return 0;
  61. }
  62. pkt = pTarang->RxAppControlHead;
  63. while (pkt) {
  64. npkt = pkt->next;
  65. kfree_skb(pkt);
  66. pkt = npkt;
  67. }
  68. up(&Adapter->RxAppControlQueuelock);
  69. /*Stop Queuing the control response Packets*/
  70. atomic_dec(&Adapter->ApplicationRunning);
  71. kfree(pTarang);
  72. /* remove this filp from the asynchronously notified filp's */
  73. filp->private_data = NULL;
  74. return 0;
  75. }
  76. static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size,
  77. loff_t *f_pos)
  78. {
  79. PPER_TARANG_DATA pTarang = filp->private_data;
  80. PMINI_ADAPTER Adapter = pTarang->Adapter;
  81. struct sk_buff *Packet = NULL;
  82. ssize_t PktLen = 0;
  83. int wait_ret_val = 0;
  84. unsigned long ret = 0;
  85. wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue,
  86. (pTarang->RxAppControlHead ||
  87. Adapter->device_removed));
  88. if ((wait_ret_val == -ERESTARTSYS)) {
  89. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
  90. "Exiting as i've been asked to exit!!!\n");
  91. return wait_ret_val;
  92. }
  93. if (Adapter->device_removed) {
  94. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
  95. "Device Removed... Killing the Apps...\n");
  96. return -ENODEV;
  97. }
  98. if (FALSE == Adapter->fw_download_done)
  99. return -EACCES;
  100. down(&Adapter->RxAppControlQueuelock);
  101. if (pTarang->RxAppControlHead) {
  102. Packet = pTarang->RxAppControlHead;
  103. DEQUEUEPACKET(pTarang->RxAppControlHead,
  104. pTarang->RxAppControlTail);
  105. pTarang->AppCtrlQueueLen--;
  106. }
  107. up(&Adapter->RxAppControlQueuelock);
  108. if (Packet) {
  109. PktLen = Packet->len;
  110. ret = copy_to_user(buf, Packet->data,
  111. min_t(size_t, PktLen, size));
  112. if (ret) {
  113. dev_kfree_skb(Packet);
  114. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
  115. "Returning from copy to user failure\n");
  116. return -EFAULT;
  117. }
  118. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
  119. "Read %zd Bytes From Adapter packet = %p by process %d!\n",
  120. PktLen, Packet, current->pid);
  121. dev_kfree_skb(Packet);
  122. }
  123. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<\n");
  124. return PktLen;
  125. }
  126. static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
  127. {
  128. PPER_TARANG_DATA pTarang = filp->private_data;
  129. void __user *argp = (void __user *)arg;
  130. PMINI_ADAPTER Adapter = pTarang->Adapter;
  131. INT Status = STATUS_FAILURE;
  132. int timeout = 0;
  133. IOCTL_BUFFER IoBuffer;
  134. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX", cmd, arg);
  135. if(_IOC_TYPE(cmd) != BCM_IOCTL)
  136. return -EFAULT;
  137. if(_IOC_DIR(cmd) & _IOC_READ)
  138. Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
  139. else if (_IOC_DIR(cmd) & _IOC_WRITE)
  140. Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
  141. else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
  142. Status = STATUS_SUCCESS;
  143. if(Status)
  144. return -EFAULT;
  145. if(Adapter->device_removed)
  146. {
  147. return -EFAULT;
  148. }
  149. if(FALSE == Adapter->fw_download_done)
  150. {
  151. switch (cmd)
  152. {
  153. case IOCTL_MAC_ADDR_REQ:
  154. case IOCTL_LINK_REQ:
  155. case IOCTL_CM_REQUEST:
  156. case IOCTL_SS_INFO_REQ:
  157. case IOCTL_SEND_CONTROL_MESSAGE:
  158. case IOCTL_IDLE_REQ:
  159. case IOCTL_BCM_GPIO_SET_REQUEST:
  160. case IOCTL_BCM_GPIO_STATUS_REQUEST:
  161. return -EACCES;
  162. default:
  163. break;
  164. }
  165. }
  166. Status = vendorextnIoctl(Adapter, cmd, arg);
  167. if(Status != CONTINUE_COMMON_PATH )
  168. return Status;
  169. switch(cmd){
  170. // Rdms for Swin Idle...
  171. case IOCTL_BCM_REGISTER_READ_PRIVATE:
  172. {
  173. RDM_BUFFER sRdmBuffer = {0};
  174. PCHAR temp_buff;
  175. UINT Bufflen;
  176. /* Copy Ioctl Buffer structure */
  177. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  178. return -EFAULT;
  179. if (IoBuffer.InputLength > sizeof(sRdmBuffer))
  180. return -EINVAL;
  181. if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
  182. return -EFAULT;
  183. /* FIXME: need to restrict BuffLen */
  184. Bufflen = IoBuffer.OutputLength + (4 - IoBuffer.OutputLength%4)%4;
  185. temp_buff = kmalloc(Bufflen, GFP_KERNEL);
  186. if(!temp_buff)
  187. return -ENOMEM;
  188. Status = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
  189. (PUINT)temp_buff, Bufflen);
  190. if(Status == STATUS_SUCCESS)
  191. {
  192. if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
  193. Status = -EFAULT;
  194. }
  195. kfree(temp_buff);
  196. break;
  197. }
  198. case IOCTL_BCM_REGISTER_WRITE_PRIVATE:
  199. {
  200. WRM_BUFFER sWrmBuffer = {0};
  201. UINT uiTempVar=0;
  202. /* Copy Ioctl Buffer structure */
  203. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  204. return -EFAULT;
  205. if (IoBuffer.InputLength > sizeof(sWrmBuffer))
  206. return -EINVAL;
  207. /* Get WrmBuffer structure */
  208. if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
  209. return -EFAULT;
  210. uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
  211. if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
  212. ((uiTempVar == EEPROM_REJECT_REG_1)||
  213. (uiTempVar == EEPROM_REJECT_REG_2) ||
  214. (uiTempVar == EEPROM_REJECT_REG_3) ||
  215. (uiTempVar == EEPROM_REJECT_REG_4)))
  216. {
  217. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
  218. return -EFAULT;
  219. }
  220. Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
  221. (PUINT)sWrmBuffer.Data, sizeof(ULONG));
  222. if(Status == STATUS_SUCCESS)
  223. {
  224. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"WRM Done\n");
  225. }
  226. else
  227. {
  228. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
  229. Status = -EFAULT;
  230. }
  231. break;
  232. }
  233. case IOCTL_BCM_REGISTER_READ:
  234. case IOCTL_BCM_EEPROM_REGISTER_READ:
  235. {
  236. RDM_BUFFER sRdmBuffer = {0};
  237. PCHAR temp_buff = NULL;
  238. UINT uiTempVar = 0;
  239. if((Adapter->IdleMode == TRUE) ||
  240. (Adapter->bShutStatus ==TRUE) ||
  241. (Adapter->bPreparingForLowPowerMode ==TRUE))
  242. {
  243. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
  244. return -EACCES;
  245. }
  246. /* Copy Ioctl Buffer structure */
  247. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  248. return -EFAULT;
  249. if (IoBuffer.InputLength > sizeof(sRdmBuffer))
  250. return -EINVAL;
  251. if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
  252. return -EFAULT;
  253. /* FIXME: don't trust user supplied length */
  254. temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
  255. if(!temp_buff)
  256. return STATUS_FAILURE;
  257. if((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
  258. ((ULONG)sRdmBuffer.Register & 0x3))
  259. {
  260. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
  261. (int)sRdmBuffer.Register);
  262. return -EINVAL;
  263. }
  264. uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
  265. Status = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
  266. (PUINT)temp_buff, IoBuffer.OutputLength);
  267. if(Status == STATUS_SUCCESS)
  268. if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
  269. Status = -EFAULT;
  270. kfree(temp_buff);
  271. break;
  272. }
  273. case IOCTL_BCM_REGISTER_WRITE:
  274. case IOCTL_BCM_EEPROM_REGISTER_WRITE:
  275. {
  276. WRM_BUFFER sWrmBuffer = {0};
  277. UINT uiTempVar=0;
  278. if((Adapter->IdleMode == TRUE) ||
  279. (Adapter->bShutStatus ==TRUE) ||
  280. (Adapter->bPreparingForLowPowerMode ==TRUE))
  281. {
  282. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
  283. return -EACCES;
  284. }
  285. /* Copy Ioctl Buffer structure */
  286. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  287. return -EFAULT;
  288. if (IoBuffer.InputLength > sizeof(sWrmBuffer))
  289. return -EINVAL;
  290. /* Get WrmBuffer structure */
  291. if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
  292. return -EFAULT;
  293. if( (((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
  294. ((ULONG)sWrmBuffer.Register & 0x3) )
  295. {
  296. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n",
  297. (int)sWrmBuffer.Register);
  298. return -EINVAL;
  299. }
  300. uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
  301. if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
  302. ((uiTempVar == EEPROM_REJECT_REG_1)||
  303. (uiTempVar == EEPROM_REJECT_REG_2) ||
  304. (uiTempVar == EEPROM_REJECT_REG_3) ||
  305. (uiTempVar == EEPROM_REJECT_REG_4)) &&
  306. (cmd == IOCTL_BCM_REGISTER_WRITE))
  307. {
  308. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
  309. return -EFAULT;
  310. }
  311. Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
  312. (PUINT)sWrmBuffer.Data, sWrmBuffer.Length);
  313. if(Status == STATUS_SUCCESS)
  314. {
  315. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "WRM Done\n");
  316. }
  317. else
  318. {
  319. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM Failed\n");
  320. Status = -EFAULT;
  321. }
  322. break;
  323. }
  324. case IOCTL_BCM_GPIO_SET_REQUEST:
  325. {
  326. UCHAR ucResetValue[4];
  327. UINT value =0;
  328. UINT uiBit = 0;
  329. UINT uiOperation = 0;
  330. GPIO_INFO gpio_info = {0};
  331. if((Adapter->IdleMode == TRUE) ||
  332. (Adapter->bShutStatus ==TRUE) ||
  333. (Adapter->bPreparingForLowPowerMode ==TRUE))
  334. {
  335. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
  336. return -EACCES;
  337. }
  338. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  339. return -EFAULT;
  340. if (IoBuffer.InputLength > sizeof(gpio_info))
  341. return -EINVAL;
  342. if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
  343. return -EFAULT;
  344. uiBit = gpio_info.uiGpioNumber;
  345. uiOperation = gpio_info.uiGpioValue;
  346. value= (1<<uiBit);
  347. if(IsReqGpioIsLedInNVM(Adapter,value) ==FALSE)
  348. {
  349. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",value);
  350. Status = -EINVAL;
  351. break;
  352. }
  353. if(uiOperation)//Set - setting 1
  354. {
  355. //Set the gpio output register
  356. Status = wrmaltWithLock(Adapter,BCM_GPIO_OUTPUT_SET_REG ,
  357. (PUINT)(&value), sizeof(UINT));
  358. if(Status == STATUS_SUCCESS)
  359. {
  360. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Set the GPIO bit\n");
  361. }
  362. else
  363. {
  364. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Failed to set the %dth GPIO \n",uiBit);
  365. break;
  366. }
  367. }
  368. else//Unset - setting 0
  369. {
  370. //Set the gpio output register
  371. Status = wrmaltWithLock(Adapter,BCM_GPIO_OUTPUT_CLR_REG ,
  372. (PUINT)(&value), sizeof(UINT));
  373. if(Status == STATUS_SUCCESS)
  374. {
  375. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Set the GPIO bit\n");
  376. }
  377. else
  378. {
  379. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Failed to clear the %dth GPIO \n",uiBit);
  380. break;
  381. }
  382. }
  383. Status = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
  384. (PUINT)ucResetValue, sizeof(UINT));
  385. if (STATUS_SUCCESS != Status)
  386. {
  387. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO_MODE_REGISTER read failed");
  388. break;
  389. }
  390. //Set the gpio mode register to output
  391. *(UINT*)ucResetValue |= (1<<uiBit);
  392. Status = wrmaltWithLock(Adapter,GPIO_MODE_REGISTER ,
  393. (PUINT)ucResetValue, sizeof(UINT));
  394. if(Status == STATUS_SUCCESS)
  395. {
  396. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Set the GPIO to output Mode\n");
  397. }
  398. else
  399. {
  400. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Failed to put GPIO in Output Mode\n");
  401. break;
  402. }
  403. }
  404. break;
  405. case BCM_LED_THREAD_STATE_CHANGE_REQ:
  406. {
  407. USER_THREAD_REQ threadReq = { 0 };
  408. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"User made LED thread InActive");
  409. if((Adapter->IdleMode == TRUE) ||
  410. (Adapter->bShutStatus ==TRUE) ||
  411. (Adapter->bPreparingForLowPowerMode ==TRUE))
  412. {
  413. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
  414. Status = -EACCES;
  415. break;
  416. }
  417. if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  418. return -EFAULT;
  419. if (IoBuffer.InputLength > sizeof(threadReq))
  420. return -EINVAL;
  421. if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
  422. return -EFAULT;
  423. //if LED thread is running(Actively or Inactively) set it state to make inactive
  424. if(Adapter->LEDInfo.led_thread_running)
  425. {
  426. if(threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ)
  427. {
  428. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Activating thread req");
  429. Adapter->DriverState = LED_THREAD_ACTIVE;
  430. }
  431. else
  432. {
  433. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DeActivating Thread req.....");
  434. Adapter->DriverState = LED_THREAD_INACTIVE;
  435. }
  436. //signal thread.
  437. wake_up(&Adapter->LEDInfo.notify_led_event);
  438. }
  439. }
  440. break;
  441. case IOCTL_BCM_GPIO_STATUS_REQUEST:
  442. {
  443. ULONG uiBit = 0;
  444. UCHAR ucRead[4];
  445. GPIO_INFO gpio_info = {0};
  446. if((Adapter->IdleMode == TRUE) ||
  447. (Adapter->bShutStatus ==TRUE) ||
  448. (Adapter->bPreparingForLowPowerMode ==TRUE))
  449. return -EACCES;
  450. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  451. return -EFAULT;
  452. if (IoBuffer.InputLength > sizeof(gpio_info))
  453. return -EINVAL;
  454. if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
  455. return -EFAULT;
  456. uiBit = gpio_info.uiGpioNumber;
  457. //Set the gpio output register
  458. Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
  459. (PUINT)ucRead, sizeof(UINT));
  460. if(Status != STATUS_SUCCESS)
  461. {
  462. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Failed\n");
  463. return Status;
  464. }
  465. }
  466. break;
  467. case IOCTL_BCM_GPIO_MULTI_REQUEST:
  468. {
  469. UCHAR ucResetValue[4];
  470. GPIO_MULTI_INFO gpio_multi_info[MAX_IDX];
  471. PGPIO_MULTI_INFO pgpio_multi_info = (PGPIO_MULTI_INFO)gpio_multi_info;
  472. memset( pgpio_multi_info, 0, MAX_IDX * sizeof( GPIO_MULTI_INFO));
  473. if((Adapter->IdleMode == TRUE) ||
  474. (Adapter->bShutStatus ==TRUE) ||
  475. (Adapter->bPreparingForLowPowerMode ==TRUE))
  476. return -EINVAL;
  477. if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  478. return -EFAULT;
  479. if (IoBuffer.InputLength > sizeof(gpio_multi_info))
  480. return -EINVAL;
  481. if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
  482. return -EFAULT;
  483. if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_info[WIMAX_IDX].uiGPIOMask)== FALSE)
  484. {
  485. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",pgpio_multi_info[WIMAX_IDX].uiGPIOMask,Adapter->gpioBitMap);
  486. Status = -EINVAL;
  487. break;
  488. }
  489. /* Set the gpio output register */
  490. if( ( pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
  491. ( pgpio_multi_info[WIMAX_IDX].uiGPIOCommand))
  492. {
  493. /* Set 1's in GPIO OUTPUT REGISTER */
  494. *(UINT*) ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
  495. pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
  496. pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
  497. if( *(UINT*) ucResetValue)
  498. Status = wrmaltWithLock( Adapter, BCM_GPIO_OUTPUT_SET_REG , (PUINT) ucResetValue, sizeof(ULONG));
  499. if( Status != STATUS_SUCCESS)
  500. {
  501. BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
  502. return Status;
  503. }
  504. /* Clear to 0's in GPIO OUTPUT REGISTER */
  505. *(UINT*) ucResetValue = (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
  506. pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
  507. ( ~( pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
  508. if( *(UINT*) ucResetValue)
  509. Status = wrmaltWithLock( Adapter, BCM_GPIO_OUTPUT_CLR_REG , (PUINT) ucResetValue, sizeof(ULONG));
  510. if( Status != STATUS_SUCCESS)
  511. {
  512. BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to BCM_GPIO_OUTPUT_CLR_REG Failed." );
  513. return Status;
  514. }
  515. }
  516. if( pgpio_multi_info[WIMAX_IDX].uiGPIOMask)
  517. {
  518. Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, (PUINT)ucResetValue, sizeof(UINT));
  519. if(Status != STATUS_SUCCESS)
  520. {
  521. BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"RDM to GPIO_PIN_STATE_REGISTER Failed.");
  522. return Status;
  523. }
  524. pgpio_multi_info[WIMAX_IDX].uiGPIOValue = ( *(UINT*)ucResetValue &
  525. pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
  526. }
  527. Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info, IoBuffer.OutputLength);
  528. if(Status)
  529. {
  530. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
  531. break;
  532. }
  533. }
  534. break;
  535. case IOCTL_BCM_GPIO_MODE_REQUEST:
  536. {
  537. UCHAR ucResetValue[4];
  538. GPIO_MULTI_MODE gpio_multi_mode[MAX_IDX];
  539. PGPIO_MULTI_MODE pgpio_multi_mode = ( PGPIO_MULTI_MODE) gpio_multi_mode;
  540. if((Adapter->IdleMode == TRUE) ||
  541. (Adapter->bShutStatus ==TRUE) ||
  542. (Adapter->bPreparingForLowPowerMode ==TRUE))
  543. return -EINVAL;
  544. if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  545. return -EFAULT;
  546. if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
  547. return -EINVAL;
  548. if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength))
  549. return -EFAULT;
  550. Status = rdmaltWithLock( Adapter, ( UINT) GPIO_MODE_REGISTER, ( PUINT) ucResetValue, sizeof( UINT));
  551. if( STATUS_SUCCESS != Status)
  552. {
  553. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Read of GPIO_MODE_REGISTER failed");
  554. return Status;
  555. }
  556. //Validating the request
  557. if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)== FALSE)
  558. {
  559. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",pgpio_multi_mode[WIMAX_IDX].uiGPIOMask,Adapter->gpioBitMap);
  560. Status = -EINVAL;
  561. break;
  562. }
  563. if( pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)
  564. {
  565. /* write all OUT's (1's) */
  566. *( UINT*) ucResetValue |= ( pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
  567. pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
  568. /* write all IN's (0's) */
  569. *( UINT*) ucResetValue &= ~( ( ~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
  570. pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
  571. /* Currently implemented return the modes of all GPIO's
  572. * else needs to bit AND with mask
  573. * */
  574. pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT*)ucResetValue;
  575. Status = wrmaltWithLock( Adapter, GPIO_MODE_REGISTER , ( PUINT) ucResetValue, sizeof( ULONG));
  576. if( Status == STATUS_SUCCESS)
  577. {
  578. BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "WRM to GPIO_MODE_REGISTER Done");
  579. }
  580. else
  581. {
  582. BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0,"WRM to GPIO_MODE_REGISTER Failed");
  583. Status = -EFAULT;
  584. break;
  585. }
  586. }
  587. else /* if uiGPIOMask is 0 then return mode register configuration */
  588. {
  589. pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *( UINT*) ucResetValue;
  590. }
  591. Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode, IoBuffer.OutputLength);
  592. if(Status)
  593. {
  594. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
  595. break;
  596. }
  597. }
  598. break;
  599. case IOCTL_MAC_ADDR_REQ:
  600. case IOCTL_LINK_REQ:
  601. case IOCTL_CM_REQUEST:
  602. case IOCTL_SS_INFO_REQ:
  603. case IOCTL_SEND_CONTROL_MESSAGE:
  604. case IOCTL_IDLE_REQ:
  605. {
  606. PVOID pvBuffer=NULL;
  607. /* Copy Ioctl Buffer structure */
  608. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  609. return -EFAULT;
  610. /* FIXME: don't accept any length from user */
  611. pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
  612. if(!pvBuffer)
  613. return -ENOMEM;
  614. if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
  615. {
  616. Status = -EFAULT;
  617. kfree(pvBuffer);
  618. break;
  619. }
  620. down(&Adapter->LowPowerModeSync);
  621. Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue,
  622. !Adapter->bPreparingForLowPowerMode,
  623. (1 * HZ));
  624. if(Status == -ERESTARTSYS)
  625. goto cntrlEnd;
  626. if(Adapter->bPreparingForLowPowerMode)
  627. {
  628. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Preparing Idle Mode is still True - Hence Rejecting control message\n");
  629. Status = STATUS_FAILURE ;
  630. goto cntrlEnd ;
  631. }
  632. Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
  633. cntrlEnd:
  634. up(&Adapter->LowPowerModeSync);
  635. kfree(pvBuffer);
  636. break;
  637. }
  638. case IOCTL_BCM_BUFFER_DOWNLOAD_START:
  639. {
  640. INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock) ;
  641. if(NVMAccess)
  642. {
  643. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
  644. return -EACCES;
  645. }
  646. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
  647. if(!down_trylock(&Adapter->fw_download_sema))
  648. {
  649. Adapter->bBinDownloaded=FALSE;
  650. Adapter->fw_download_process_pid=current->pid;
  651. Adapter->bCfgDownloaded=FALSE;
  652. Adapter->fw_download_done=FALSE;
  653. netif_carrier_off(Adapter->dev);
  654. netif_stop_queue(Adapter->dev);
  655. Status = reset_card_proc(Adapter);
  656. if(Status)
  657. {
  658. pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
  659. up(&Adapter->fw_download_sema);
  660. up(&Adapter->NVMRdmWrmLock);
  661. break;
  662. }
  663. mdelay(10);
  664. }
  665. else
  666. {
  667. Status = -EBUSY;
  668. }
  669. up(&Adapter->NVMRdmWrmLock);
  670. break;
  671. }
  672. case IOCTL_BCM_BUFFER_DOWNLOAD:
  673. {
  674. FIRMWARE_INFO *psFwInfo = NULL;
  675. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
  676. do{
  677. if(!down_trylock(&Adapter->fw_download_sema))
  678. {
  679. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid way to download buffer. Use Start and then call this!!!\n");
  680. Status=-EINVAL;
  681. break;
  682. }
  683. /* Copy Ioctl Buffer structure */
  684. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  685. return -EFAULT;
  686. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Length for FW DLD is : %lx\n",
  687. IoBuffer.InputLength);
  688. if (IoBuffer.InputLength > sizeof(FIRMWARE_INFO))
  689. return -EINVAL;
  690. psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
  691. if(!psFwInfo)
  692. return -ENOMEM;
  693. if(copy_from_user(psFwInfo, IoBuffer.InputBuffer, IoBuffer.InputLength))
  694. return -EFAULT;
  695. if(!psFwInfo->pvMappedFirmwareAddress ||
  696. (psFwInfo->u32FirmwareLength == 0))
  697. {
  698. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Something else is wrong %lu\n",
  699. psFwInfo->u32FirmwareLength);
  700. Status = -EINVAL;
  701. break;
  702. }
  703. Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
  704. if(Status != STATUS_SUCCESS)
  705. {
  706. if(psFwInfo->u32StartingAddress==CONFIG_BEGIN_ADDR)
  707. {
  708. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "IOCTL: Configuration File Upload Failed\n");
  709. }
  710. else
  711. {
  712. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "IOCTL: Firmware File Upload Failed\n");
  713. }
  714. //up(&Adapter->fw_download_sema);
  715. if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
  716. {
  717. Adapter->DriverState = DRIVER_INIT;
  718. Adapter->LEDInfo.bLedInitDone = FALSE;
  719. wake_up(&Adapter->LEDInfo.notify_led_event);
  720. }
  721. }
  722. break ;
  723. }while(0);
  724. if(Status != STATUS_SUCCESS)
  725. up(&Adapter->fw_download_sema);
  726. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
  727. kfree(psFwInfo);
  728. break;
  729. }
  730. case IOCTL_BCM_BUFFER_DOWNLOAD_STOP:
  731. {
  732. INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
  733. if(NVMAccess)
  734. {
  735. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " FW download blocked as EEPROM Read/Write is in progress\n");
  736. up(&Adapter->fw_download_sema);
  737. return -EACCES;
  738. }
  739. if(down_trylock(&Adapter->fw_download_sema))
  740. {
  741. Adapter->bBinDownloaded=TRUE;
  742. Adapter->bCfgDownloaded=TRUE;
  743. atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
  744. Adapter->CurrNumRecvDescs=0;
  745. Adapter->downloadDDR = 0;
  746. //setting the Mips to Run
  747. Status = run_card_proc(Adapter);
  748. if(Status)
  749. {
  750. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Firm Download Failed\n");
  751. up(&Adapter->fw_download_sema);
  752. up(&Adapter->NVMRdmWrmLock);
  753. break;
  754. }
  755. else
  756. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Firm Download Over...\n");
  757. mdelay(10);
  758. /* Wait for MailBox Interrupt */
  759. if(StartInterruptUrb((PS_INTERFACE_ADAPTER)Adapter->pvInterfaceAdapter))
  760. {
  761. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Unable to send interrupt...\n");
  762. }
  763. timeout = 5*HZ;
  764. Adapter->waiting_to_fw_download_done = FALSE;
  765. wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
  766. Adapter->waiting_to_fw_download_done, timeout);
  767. Adapter->fw_download_process_pid=INVALID_PID;
  768. Adapter->fw_download_done=TRUE;
  769. atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
  770. Adapter->CurrNumRecvDescs = 0;
  771. Adapter->PrevNumRecvDescs = 0;
  772. atomic_set(&Adapter->cntrlpktCnt,0);
  773. Adapter->LinkUpStatus = 0;
  774. Adapter->LinkStatus = 0;
  775. if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
  776. {
  777. Adapter->DriverState = FW_DOWNLOAD_DONE;
  778. wake_up(&Adapter->LEDInfo.notify_led_event);
  779. }
  780. if(!timeout)
  781. {
  782. Status = -ENODEV;
  783. }
  784. }
  785. else
  786. {
  787. Status = -EINVAL;
  788. }
  789. up(&Adapter->fw_download_sema);
  790. up(&Adapter->NVMRdmWrmLock);
  791. break;
  792. }
  793. case IOCTL_BE_BUCKET_SIZE:
  794. Status = 0;
  795. if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
  796. Status = -EFAULT;
  797. break;
  798. case IOCTL_RTPS_BUCKET_SIZE:
  799. Status = 0;
  800. if (get_user(Adapter->rtPSBucketSize, (unsigned long __user *)arg))
  801. Status = -EFAULT;
  802. break;
  803. case IOCTL_CHIP_RESET:
  804. {
  805. INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
  806. if(NVMAccess)
  807. {
  808. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
  809. return -EACCES;
  810. }
  811. down(&Adapter->RxAppControlQueuelock);
  812. Status = reset_card_proc(Adapter);
  813. flushAllAppQ();
  814. up(&Adapter->RxAppControlQueuelock);
  815. up(&Adapter->NVMRdmWrmLock);
  816. ResetCounters(Adapter);
  817. break;
  818. }
  819. case IOCTL_QOS_THRESHOLD:
  820. {
  821. USHORT uiLoopIndex;
  822. Status = 0;
  823. for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
  824. if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
  825. (unsigned long __user *)arg)) {
  826. Status = -EFAULT;
  827. break;
  828. }
  829. }
  830. break;
  831. }
  832. case IOCTL_DUMP_PACKET_INFO:
  833. DumpPackInfo(Adapter);
  834. DumpPhsRules(&Adapter->stBCMPhsContext);
  835. Status = STATUS_SUCCESS;
  836. break;
  837. case IOCTL_GET_PACK_INFO:
  838. if(copy_to_user(argp, &Adapter->PackInfo, sizeof(PacketInfo)*NO_OF_QUEUES))
  839. return -EFAULT;
  840. Status = STATUS_SUCCESS;
  841. break;
  842. case IOCTL_BCM_SWITCH_TRANSFER_MODE:
  843. {
  844. UINT uiData = 0;
  845. if(copy_from_user(&uiData, argp, sizeof(UINT)))
  846. return -EFAULT;
  847. if(uiData) /* Allow All Packets */
  848. {
  849. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
  850. Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
  851. }
  852. else /* Allow IP only Packets */
  853. {
  854. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
  855. Adapter->TransferMode = IP_PACKET_ONLY_MODE;
  856. }
  857. Status = STATUS_SUCCESS;
  858. break;
  859. }
  860. case IOCTL_BCM_GET_DRIVER_VERSION:
  861. {
  862. /* Copy Ioctl Buffer structure */
  863. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  864. return -EFAULT;
  865. if(copy_to_user(IoBuffer.OutputBuffer, VER_FILEVERSION_STR, IoBuffer.OutputLength))
  866. return -EFAULT;
  867. Status = STATUS_SUCCESS;
  868. break;
  869. }
  870. case IOCTL_BCM_GET_CURRENT_STATUS:
  871. {
  872. LINK_STATE link_state;
  873. /* Copy Ioctl Buffer structure */
  874. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  875. {
  876. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user failed..\n");
  877. Status = -EFAULT;
  878. break;
  879. }
  880. if (IoBuffer.OutputLength != sizeof(link_state)) {
  881. Status = -EINVAL;
  882. break;
  883. }
  884. memset(&link_state, 0, sizeof(link_state));
  885. link_state.bIdleMode = Adapter->IdleMode;
  886. link_state.bShutdownMode = Adapter->bShutStatus;
  887. link_state.ucLinkStatus = Adapter->LinkStatus;
  888. if (copy_to_user(IoBuffer.OutputBuffer, &link_state,
  889. min_t(size_t, sizeof(link_state), IoBuffer.OutputLength)))
  890. {
  891. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
  892. Status = -EFAULT;
  893. break;
  894. }
  895. Status = STATUS_SUCCESS;
  896. break;
  897. }
  898. case IOCTL_BCM_SET_MAC_TRACING:
  899. {
  900. UINT tracing_flag;
  901. /* copy ioctl Buffer structure */
  902. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  903. return -EFAULT;
  904. if(copy_from_user(&tracing_flag,IoBuffer.InputBuffer,sizeof(UINT)))
  905. return -EFAULT;
  906. if (tracing_flag)
  907. Adapter->pTarangs->MacTracingEnabled = TRUE;
  908. else
  909. Adapter->pTarangs->MacTracingEnabled = FALSE;
  910. break;
  911. }
  912. case IOCTL_BCM_GET_DSX_INDICATION:
  913. {
  914. ULONG ulSFId=0;
  915. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  916. return -EFAULT;
  917. if(IoBuffer.OutputLength < sizeof(stLocalSFAddIndicationAlt))
  918. {
  919. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,
  920. "Mismatch req: %lx needed is =0x%zx!!!",
  921. IoBuffer.OutputLength, sizeof(stLocalSFAddIndicationAlt));
  922. return -EINVAL;
  923. }
  924. if(copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
  925. return -EFAULT;
  926. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId );
  927. get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
  928. Status=STATUS_SUCCESS;
  929. }
  930. break;
  931. case IOCTL_BCM_GET_HOST_MIBS:
  932. {
  933. PVOID temp_buff;
  934. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  935. return -EFAULT;
  936. if(IoBuffer.OutputLength != sizeof(S_MIBS_HOST_STATS_MIBS))
  937. {
  938. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,
  939. "Length Check failed %lu %zd\n",
  940. IoBuffer.OutputLength, sizeof(S_MIBS_HOST_STATS_MIBS));
  941. return -EINVAL;
  942. }
  943. /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
  944. temp_buff = kzalloc(sizeof(S_MIBS_HOST_STATS_MIBS), GFP_KERNEL);
  945. if(!temp_buff)
  946. return STATUS_FAILURE;
  947. Status = ProcessGetHostMibs(Adapter, temp_buff);
  948. GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
  949. if (Status != STATUS_FAILURE)
  950. if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(S_MIBS_HOST_STATS_MIBS)))
  951. Status = -EFAULT;
  952. kfree(temp_buff);
  953. break;
  954. }
  955. case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
  956. if((FALSE == Adapter->bTriedToWakeUpFromlowPowerMode) && (TRUE==Adapter->IdleMode))
  957. {
  958. Adapter->usIdleModePattern = ABORT_IDLE_MODE;
  959. Adapter->bWakeUpDevice = TRUE;
  960. wake_up(&Adapter->process_rx_cntrlpkt);
  961. }
  962. Status = STATUS_SUCCESS;
  963. break;
  964. case IOCTL_BCM_BULK_WRM:
  965. {
  966. PBULKWRM_BUFFER pBulkBuffer;
  967. UINT uiTempVar=0;
  968. PCHAR pvBuffer = NULL;
  969. if((Adapter->IdleMode == TRUE) ||
  970. (Adapter->bShutStatus ==TRUE) ||
  971. (Adapter->bPreparingForLowPowerMode ==TRUE))
  972. {
  973. BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Device in Idle/Shutdown Mode, Blocking Wrms\n");
  974. Status = -EACCES;
  975. break;
  976. }
  977. /* Copy Ioctl Buffer structure */
  978. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  979. return -EFAULT;
  980. /* FIXME: restrict length */
  981. pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
  982. if(!pvBuffer)
  983. return -ENOMEM;
  984. /* Get WrmBuffer structure */
  985. if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
  986. {
  987. kfree(pvBuffer);
  988. Status = -EFAULT;
  989. break;
  990. }
  991. pBulkBuffer = (PBULKWRM_BUFFER)pvBuffer;
  992. if(((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
  993. ((ULONG)pBulkBuffer->Register & 0x3))
  994. {
  995. kfree(pvBuffer);
  996. BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"WRM Done On invalid Address : %x Access Denied.\n",(int)pBulkBuffer->Register);
  997. Status = -EINVAL;
  998. break;
  999. }
  1000. uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
  1001. if(!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE)
  1002. && ((uiTempVar == EEPROM_REJECT_REG_1)||
  1003. (uiTempVar == EEPROM_REJECT_REG_2) ||
  1004. (uiTempVar == EEPROM_REJECT_REG_3) ||
  1005. (uiTempVar == EEPROM_REJECT_REG_4)) &&
  1006. (cmd == IOCTL_BCM_REGISTER_WRITE))
  1007. {
  1008. kfree(pvBuffer);
  1009. BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"EEPROM Access Denied, not in VSG Mode\n");
  1010. Status = -EFAULT;
  1011. break;
  1012. }
  1013. if(pBulkBuffer->SwapEndian == FALSE)
  1014. Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register, (PCHAR)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
  1015. else
  1016. Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register, (PUINT)pBulkBuffer->Values, IoBuffer.InputLength - 2*sizeof(ULONG));
  1017. if(Status != STATUS_SUCCESS)
  1018. {
  1019. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
  1020. }
  1021. kfree(pvBuffer);
  1022. break;
  1023. }
  1024. case IOCTL_BCM_GET_NVM_SIZE:
  1025. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  1026. return -EFAULT;
  1027. if(Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH ) {
  1028. if(copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize, sizeof(UINT)))
  1029. return -EFAULT;
  1030. }
  1031. Status = STATUS_SUCCESS ;
  1032. break;
  1033. case IOCTL_BCM_CAL_INIT :
  1034. {
  1035. UINT uiSectorSize = 0 ;
  1036. if(Adapter->eNVMType == NVM_FLASH)
  1037. {
  1038. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  1039. return -EFAULT;
  1040. if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer, sizeof(UINT)))
  1041. return -EFAULT;
  1042. if((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE))
  1043. {
  1044. if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize,
  1045. sizeof(UINT)))
  1046. return -EFAULT;
  1047. }
  1048. else
  1049. {
  1050. if(IsFlash2x(Adapter))
  1051. {
  1052. if (copy_to_user(IoBuffer.OutputBuffer,
  1053. &Adapter->uiSectorSize ,
  1054. sizeof(UINT)))
  1055. return -EFAULT;
  1056. }
  1057. else
  1058. {
  1059. if((TRUE == Adapter->bShutStatus) ||
  1060. (TRUE == Adapter->IdleMode))
  1061. {
  1062. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle/Shutdown Mode\n");
  1063. return -EACCES;
  1064. }
  1065. Adapter->uiSectorSize = uiSectorSize ;
  1066. BcmUpdateSectorSize(Adapter,Adapter->uiSectorSize);
  1067. }
  1068. }
  1069. Status = STATUS_SUCCESS ;
  1070. }
  1071. else
  1072. {
  1073. Status = STATUS_FAILURE;
  1074. }
  1075. }
  1076. break;
  1077. case IOCTL_BCM_SET_DEBUG :
  1078. #ifdef DEBUG
  1079. {
  1080. USER_BCM_DBG_STATE sUserDebugState;
  1081. // BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Entered the ioctl %x \n", IOCTL_BCM_SET_DEBUG );
  1082. BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
  1083. if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  1084. return -EFAULT;
  1085. if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE)))
  1086. return -EFAULT;
  1087. BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
  1088. sUserDebugState.OnOff, sUserDebugState.Type);
  1089. //sUserDebugState.Subtype <<= 1;
  1090. sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
  1091. BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "actual Subtype=0x%x\n", sUserDebugState.Subtype);
  1092. // Update new 'DebugState' in the Adapter
  1093. Adapter->stDebugState.type |= sUserDebugState.Type;
  1094. /* Subtype: A bitmap of 32 bits for Subtype per Type.
  1095. * Valid indexes in 'subtype' array: 1,2,4,8
  1096. * corresponding to valid Type values. Hence we can use the 'Type' field
  1097. * as the index value, ignoring the array entries 0,3,5,6,7 !
  1098. */
  1099. if (sUserDebugState.OnOff)
  1100. Adapter->stDebugState.subtype[sUserDebugState.Type] |= sUserDebugState.Subtype;
  1101. else
  1102. Adapter->stDebugState.subtype[sUserDebugState.Type] &= ~sUserDebugState.Subtype;
  1103. BCM_SHOW_DEBUG_BITMAP(Adapter);
  1104. }
  1105. #endif
  1106. break;
  1107. case IOCTL_BCM_NVM_READ:
  1108. case IOCTL_BCM_NVM_WRITE:
  1109. {
  1110. NVM_READWRITE stNVMReadWrite;
  1111. PUCHAR pReadData = NULL;
  1112. ULONG ulDSDMagicNumInUsrBuff = 0;
  1113. struct timeval tv0, tv1;
  1114. memset(&tv0,0,sizeof(struct timeval));
  1115. memset(&tv1,0,sizeof(struct timeval));
  1116. if((Adapter->eNVMType == NVM_FLASH) && (Adapter->uiFlashLayoutMajorVersion == 0))
  1117. {
  1118. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,"The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
  1119. Status = -EFAULT;
  1120. break;
  1121. }
  1122. if(IsFlash2x(Adapter))
  1123. {
  1124. if((Adapter->eActiveDSD != DSD0) &&
  1125. (Adapter->eActiveDSD != DSD1) &&
  1126. (Adapter->eActiveDSD != DSD2))
  1127. {
  1128. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"No DSD is active..hence NVM Command is blocked");
  1129. return STATUS_FAILURE ;
  1130. }
  1131. }
  1132. /* Copy Ioctl Buffer structure */
  1133. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  1134. return -EFAULT;
  1135. if(copy_from_user(&stNVMReadWrite,
  1136. (IOCTL_BCM_NVM_READ == cmd) ? IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
  1137. sizeof(NVM_READWRITE)))
  1138. return -EFAULT;
  1139. //
  1140. // Deny the access if the offset crosses the cal area limit.
  1141. //
  1142. if((stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) > Adapter->uiNVMDSDSize)
  1143. {
  1144. //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Can't allow access beyond NVM Size: 0x%x 0x%x\n", stNVMReadWrite.uiOffset ,
  1145. // stNVMReadWrite.uiNumBytes);
  1146. Status = STATUS_FAILURE;
  1147. break;
  1148. }
  1149. pReadData = kzalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL);
  1150. if(!pReadData)
  1151. return -ENOMEM;
  1152. if(copy_from_user(pReadData, stNVMReadWrite.pBuffer,
  1153. stNVMReadWrite.uiNumBytes))
  1154. {
  1155. Status = -EFAULT;
  1156. kfree(pReadData);
  1157. break;
  1158. }
  1159. do_gettimeofday(&tv0);
  1160. if(IOCTL_BCM_NVM_READ == cmd)
  1161. {
  1162. down(&Adapter->NVMRdmWrmLock);
  1163. if((Adapter->IdleMode == TRUE) ||
  1164. (Adapter->bShutStatus ==TRUE) ||
  1165. (Adapter->bPreparingForLowPowerMode ==TRUE))
  1166. {
  1167. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
  1168. up(&Adapter->NVMRdmWrmLock);
  1169. kfree(pReadData);
  1170. return -EACCES;
  1171. }
  1172. Status = BeceemNVMRead(Adapter, (PUINT)pReadData,
  1173. stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes);
  1174. up(&Adapter->NVMRdmWrmLock);
  1175. if(Status != STATUS_SUCCESS)
  1176. {
  1177. kfree(pReadData);
  1178. return Status;
  1179. }
  1180. if(copy_to_user(stNVMReadWrite.pBuffer,pReadData, stNVMReadWrite.uiNumBytes))
  1181. {
  1182. kfree(pReadData);
  1183. Status = -EFAULT;
  1184. }
  1185. }
  1186. else
  1187. {
  1188. down(&Adapter->NVMRdmWrmLock);
  1189. if((Adapter->IdleMode == TRUE) ||
  1190. (Adapter->bShutStatus ==TRUE) ||
  1191. (Adapter->bPreparingForLowPowerMode ==TRUE))
  1192. {
  1193. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
  1194. up(&Adapter->NVMRdmWrmLock);
  1195. kfree(pReadData);
  1196. return -EACCES;
  1197. }
  1198. Adapter->bHeaderChangeAllowed = TRUE ;
  1199. if(IsFlash2x(Adapter))
  1200. {
  1201. /*
  1202. New Requirement:-
  1203. DSD section updation will be allowed in two case:-
  1204. 1. if DSD sig is present in DSD header means dongle is ok and updation is fruitfull
  1205. 2. if point 1 failes then user buff should have DSD sig. this point ensures that if dongle is
  1206. corrupted then user space program first modify the DSD header with valid DSD sig so
  1207. that this as well as further write may be worthwhile.
  1208. This restriction has been put assuming that if DSD sig is corrupted, DSD
  1209. data won't be considered valid.
  1210. */
  1211. Status = BcmFlash2xCorruptSig(Adapter,Adapter->eActiveDSD);
  1212. if(Status != STATUS_SUCCESS)
  1213. {
  1214. if(( (stNVMReadWrite.uiOffset + stNVMReadWrite.uiNumBytes) != Adapter->uiNVMDSDSize ) ||
  1215. (stNVMReadWrite.uiNumBytes < SIGNATURE_SIZE))
  1216. {
  1217. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
  1218. up(&Adapter->NVMRdmWrmLock);
  1219. kfree(pReadData);
  1220. return Status;
  1221. }
  1222. ulDSDMagicNumInUsrBuff = ntohl(*(PUINT)(pReadData + stNVMReadWrite.uiNumBytes - SIGNATURE_SIZE));
  1223. if(ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER)
  1224. {
  1225. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
  1226. up(&Adapter->NVMRdmWrmLock);
  1227. kfree(pReadData);
  1228. return Status;
  1229. }
  1230. }
  1231. }
  1232. Status = BeceemNVMWrite(Adapter, (PUINT )pReadData,
  1233. stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes, stNVMReadWrite.bVerify);
  1234. if(IsFlash2x(Adapter))
  1235. BcmFlash2xWriteSig(Adapter,Adapter->eActiveDSD);
  1236. Adapter->bHeaderChangeAllowed = FALSE ;
  1237. up(&Adapter->NVMRdmWrmLock);
  1238. if(Status != STATUS_SUCCESS)
  1239. {
  1240. kfree(pReadData);
  1241. return Status;
  1242. }
  1243. }
  1244. do_gettimeofday(&tv1);
  1245. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " timetaken by Write/read :%ld msec\n",(tv1.tv_sec - tv0.tv_sec)*1000 +(tv1.tv_usec - tv0.tv_usec)/1000);
  1246. kfree(pReadData);
  1247. Status = STATUS_SUCCESS;
  1248. }
  1249. break;
  1250. case IOCTL_BCM_FLASH2X_SECTION_READ :
  1251. {
  1252. FLASH2X_READWRITE sFlash2xRead = {0};
  1253. PUCHAR pReadBuff = NULL ;
  1254. UINT NOB = 0;
  1255. UINT BuffSize = 0;
  1256. UINT ReadBytes = 0;
  1257. UINT ReadOffset = 0;
  1258. void __user *OutPutBuff;
  1259. if(IsFlash2x(Adapter) != TRUE)
  1260. {
  1261. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
  1262. return -EINVAL;
  1263. }
  1264. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
  1265. if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  1266. return -EFAULT;
  1267. //Reading FLASH 2.x READ structure
  1268. if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer,sizeof(FLASH2X_READWRITE)))
  1269. return -EFAULT;
  1270. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xRead.Section);
  1271. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%x" ,sFlash2xRead.offset);
  1272. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xRead.numOfBytes);
  1273. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xRead.bVerify);
  1274. //This was internal to driver for raw read. now it has ben exposed to user space app.
  1275. if(validateFlash2xReadWrite(Adapter,&sFlash2xRead) == FALSE)
  1276. return STATUS_FAILURE ;
  1277. NOB = sFlash2xRead.numOfBytes;
  1278. if(NOB > Adapter->uiSectorSize )
  1279. BuffSize = Adapter->uiSectorSize;
  1280. else
  1281. BuffSize = NOB ;
  1282. ReadOffset = sFlash2xRead.offset ;
  1283. OutPutBuff = IoBuffer.OutputBuffer;
  1284. pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
  1285. if(pReadBuff == NULL)
  1286. {
  1287. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
  1288. return -ENOMEM;
  1289. }
  1290. down(&Adapter->NVMRdmWrmLock);
  1291. if((Adapter->IdleMode == TRUE) ||
  1292. (Adapter->bShutStatus ==TRUE) ||
  1293. (Adapter->bPreparingForLowPowerMode ==TRUE))
  1294. {
  1295. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
  1296. up(&Adapter->NVMRdmWrmLock);
  1297. kfree(pReadBuff);
  1298. return -EACCES;
  1299. }
  1300. while(NOB)
  1301. {
  1302. if(NOB > Adapter->uiSectorSize )
  1303. ReadBytes = Adapter->uiSectorSize;
  1304. else
  1305. ReadBytes = NOB;
  1306. //Reading the data from Flash 2.x
  1307. Status = BcmFlash2xBulkRead(Adapter,(PUINT)pReadBuff,sFlash2xRead.Section,ReadOffset,ReadBytes);
  1308. if(Status)
  1309. {
  1310. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Flash 2x read err with Status :%d", Status);
  1311. break ;
  1312. }
  1313. BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff, ReadBytes);
  1314. Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
  1315. if(Status)
  1316. {
  1317. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Copy to use failed with status :%d", Status);
  1318. break;
  1319. }
  1320. NOB = NOB - ReadBytes;
  1321. if(NOB)
  1322. {
  1323. ReadOffset = ReadOffset + ReadBytes ;
  1324. OutPutBuff = OutPutBuff + ReadBytes ;
  1325. }
  1326. }
  1327. up(&Adapter->NVMRdmWrmLock);
  1328. kfree(pReadBuff);
  1329. }
  1330. break ;
  1331. case IOCTL_BCM_FLASH2X_SECTION_WRITE :
  1332. {
  1333. FLASH2X_READWRITE sFlash2xWrite = {0};
  1334. PUCHAR pWriteBuff;
  1335. void __user *InputAddr;
  1336. UINT NOB = 0;
  1337. UINT BuffSize = 0;
  1338. UINT WriteOffset = 0;
  1339. UINT WriteBytes = 0;
  1340. if(IsFlash2x(Adapter) != TRUE)
  1341. {
  1342. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
  1343. return -EINVAL;
  1344. }
  1345. //First make this False so that we can enable the Sector Permission Check in BeceemFlashBulkWrite
  1346. Adapter->bAllDSDWriteAllow = FALSE;
  1347. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
  1348. if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  1349. return -EFAULT;
  1350. //Reading FLASH 2.x READ structure
  1351. if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE)))
  1352. return -EFAULT;
  1353. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xWrite.Section);
  1354. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%d" ,sFlash2xWrite.offset);
  1355. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xWrite.numOfBytes);
  1356. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xWrite.bVerify);
  1357. if((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) &&
  1358. (sFlash2xWrite.Section != VSA2) )
  1359. {
  1360. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Only VSA write is allowed");
  1361. return -EINVAL;
  1362. }
  1363. if(validateFlash2xReadWrite(Adapter,&sFlash2xWrite) == FALSE)
  1364. return STATUS_FAILURE ;
  1365. InputAddr = sFlash2xWrite.pDataBuff;
  1366. WriteOffset = sFlash2xWrite.offset ;
  1367. NOB = sFlash2xWrite.numOfBytes;
  1368. if(NOB > Adapter->uiSectorSize )
  1369. BuffSize = Adapter->uiSectorSize;
  1370. else
  1371. BuffSize = NOB ;
  1372. pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
  1373. if(pWriteBuff == NULL)
  1374. return -ENOMEM;
  1375. //extracting the remainder of the given offset.
  1376. WriteBytes = Adapter->uiSectorSize ;
  1377. if(WriteOffset % Adapter->uiSectorSize)
  1378. WriteBytes =Adapter->uiSectorSize - (WriteOffset % Adapter->uiSectorSize);
  1379. if(NOB < WriteBytes)
  1380. WriteBytes = NOB;
  1381. down(&Adapter->NVMRdmWrmLock);
  1382. if((Adapter->IdleMode == TRUE) ||
  1383. (Adapter->bShutStatus ==TRUE) ||
  1384. (Adapter->bPreparingForLowPowerMode ==TRUE))
  1385. {
  1386. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
  1387. up(&Adapter->NVMRdmWrmLock);
  1388. kfree(pWriteBuff);
  1389. return -EACCES;
  1390. }
  1391. BcmFlash2xCorruptSig(Adapter,sFlash2xWrite.Section);
  1392. do
  1393. {
  1394. Status = copy_from_user(pWriteBuff,InputAddr,WriteBytes);
  1395. if(Status)
  1396. {
  1397. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to user failed with status :%d", Status);
  1398. break ;
  1399. }
  1400. BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pWriteBuff,WriteBytes);
  1401. //Writing the data from Flash 2.x
  1402. Status = BcmFlash2xBulkWrite(Adapter,(PUINT)pWriteBuff,sFlash2xWrite.Section,WriteOffset,WriteBytes,sFlash2xWrite.bVerify);
  1403. if(Status)
  1404. {
  1405. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash 2x read err with Status :%d", Status);
  1406. break ;
  1407. }
  1408. NOB = NOB - WriteBytes;
  1409. if(NOB)
  1410. {
  1411. WriteOffset = WriteOffset + WriteBytes ;
  1412. InputAddr = InputAddr + WriteBytes ;
  1413. if(NOB > Adapter->uiSectorSize )
  1414. WriteBytes = Adapter->uiSectorSize;
  1415. else
  1416. WriteBytes = NOB;
  1417. }
  1418. } while(NOB > 0);
  1419. BcmFlash2xWriteSig(Adapter,sFlash2xWrite.Section);
  1420. up(&Adapter->NVMRdmWrmLock);
  1421. kfree(pWriteBuff);
  1422. }
  1423. break ;
  1424. case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP :
  1425. {
  1426. PFLASH2X_BITMAP psFlash2xBitMap;
  1427. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
  1428. if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  1429. return -EFAULT;
  1430. if(IoBuffer.OutputLength != sizeof(FLASH2X_BITMAP))
  1431. return -EINVAL;
  1432. psFlash2xBitMap = kzalloc(sizeof(FLASH2X_BITMAP), GFP_KERNEL);
  1433. if(psFlash2xBitMap == NULL)
  1434. {
  1435. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory is not available");
  1436. return -ENOMEM ;
  1437. }
  1438. //Reading the Flash Sectio Bit map
  1439. down(&Adapter->NVMRdmWrmLock);
  1440. if((Adapter->IdleMode == TRUE) ||
  1441. (Adapter->bShutStatus ==TRUE) ||
  1442. (Adapter->bPreparingForLowPowerMode ==TRUE))
  1443. {
  1444. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
  1445. up(&Adapter->NVMRdmWrmLock);
  1446. kfree(psFlash2xBitMap);
  1447. return -EACCES;
  1448. }
  1449. BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
  1450. up(&Adapter->NVMRdmWrmLock);
  1451. if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP)))
  1452. Status = -EFAULT;
  1453. kfree(psFlash2xBitMap);
  1454. }
  1455. break ;
  1456. case IOCTL_BCM_SET_ACTIVE_SECTION :
  1457. {
  1458. FLASH2X_SECTION_VAL eFlash2xSectionVal = 0;
  1459. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SET_ACTIVE_SECTION Called");
  1460. if(IsFlash2x(Adapter) != TRUE)
  1461. {
  1462. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
  1463. return -EINVAL;
  1464. }
  1465. Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
  1466. if(Status)
  1467. {
  1468. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
  1469. return Status;
  1470. }
  1471. Status = copy_from_user(&eFlash2xSectionVal,IoBuffer.InputBuffer, sizeof(INT));
  1472. if(Status)
  1473. {
  1474. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
  1475. return Status;
  1476. }
  1477. down(&Adapter->NVMRdmWrmLock);
  1478. if((Adapter->IdleMode == TRUE) ||
  1479. (Adapter->bShutStatus ==TRUE) ||
  1480. (Adapter->bPreparingForLowPowerMode ==TRUE))
  1481. {
  1482. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
  1483. up(&Adapter->NVMRdmWrmLock);
  1484. return -EACCES;
  1485. }
  1486. Status = BcmSetActiveSection(Adapter,eFlash2xSectionVal);
  1487. if(Status)
  1488. {
  1489. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed to make it's priority Highest. Status %d", Status);
  1490. }
  1491. up(&Adapter->NVMRdmWrmLock);
  1492. }
  1493. break ;
  1494. case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION :
  1495. {
  1496. //Right Now we are taking care of only DSD
  1497. Adapter->bAllDSDWriteAllow = FALSE ;
  1498. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
  1499. Status = STATUS_SUCCESS ;
  1500. }
  1501. break ;
  1502. case IOCTL_BCM_COPY_SECTION :
  1503. {
  1504. FLASH2X_COPY_SECTION sCopySectStrut = {0};
  1505. Status = STATUS_SUCCESS;
  1506. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_COPY_SECTION Called");
  1507. Adapter->bAllDSDWriteAllow = FALSE ;
  1508. if(IsFlash2x(Adapter) != TRUE)
  1509. {
  1510. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
  1511. return -EINVAL;
  1512. }
  1513. Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
  1514. if(Status)
  1515. {
  1516. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
  1517. return Status;
  1518. }
  1519. Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION));
  1520. if(Status)
  1521. {
  1522. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
  1523. return Status;
  1524. }
  1525. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
  1526. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
  1527. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "offset :%x", sCopySectStrut.offset);
  1528. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "NOB :%x", sCopySectStrut.numOfBytes);
  1529. if(IsSectionExistInFlash(Adapter,sCopySectStrut.SrcSection) == FALSE)
  1530. {
  1531. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Source Section<%x> does not exixt in Flash ", sCopySectStrut.SrcSection);
  1532. return -EINVAL;
  1533. }
  1534. if(IsSectionExistInFlash(Adapter,sCopySectStrut.DstSection) == FALSE)
  1535. {
  1536. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Destinatio Section<%x> does not exixt in Flash ", sCopySectStrut.DstSection);
  1537. return -EINVAL;
  1538. }
  1539. if(sCopySectStrut.SrcSection == sCopySectStrut.DstSection)
  1540. {
  1541. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Source and Destination section should be different");
  1542. return -EINVAL;
  1543. }
  1544. down(&Adapter->NVMRdmWrmLock);
  1545. if((Adapter->IdleMode == TRUE) ||
  1546. (Adapter->bShutStatus ==TRUE) ||
  1547. (Adapter->bPreparingForLowPowerMode ==TRUE))
  1548. {
  1549. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
  1550. up(&Adapter->NVMRdmWrmLock);
  1551. return -EACCES;
  1552. }
  1553. if(sCopySectStrut.SrcSection == ISO_IMAGE1 || sCopySectStrut.SrcSection == ISO_IMAGE2)
  1554. {
  1555. if(IsNonCDLessDevice(Adapter))
  1556. {
  1557. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is Non-CDLess hence won't have ISO !!");
  1558. Status = -EINVAL ;
  1559. }
  1560. else if(sCopySectStrut.numOfBytes == 0)
  1561. {
  1562. Status = BcmCopyISO(Adapter,sCopySectStrut);
  1563. }
  1564. else
  1565. {
  1566. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Partial Copy of ISO section is not Allowed..");
  1567. Status = STATUS_FAILURE ;
  1568. }
  1569. up(&Adapter->NVMRdmWrmLock);
  1570. return Status;
  1571. }
  1572. Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
  1573. sCopySectStrut.DstSection,sCopySectStrut.offset,sCopySectStrut.numOfBytes);
  1574. up(&Adapter->NVMRdmWrmLock);
  1575. }
  1576. break ;
  1577. case IOCTL_BCM_GET_FLASH_CS_INFO :
  1578. {
  1579. Status = STATUS_SUCCESS;
  1580. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_GET_FLASH_CS_INFO Called");
  1581. Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
  1582. if(Status)
  1583. {
  1584. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
  1585. break;
  1586. }
  1587. if(Adapter->eNVMType != NVM_FLASH)
  1588. {
  1589. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Connected device does not have flash");
  1590. Status = -EINVAL;
  1591. break;
  1592. }
  1593. if(IsFlash2x(Adapter) == TRUE)
  1594. {
  1595. if(IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO))
  1596. return -EINVAL;
  1597. if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO)))
  1598. return -EFAULT;
  1599. }
  1600. else
  1601. {
  1602. if(IoBuffer.OutputLength < sizeof(FLASH_CS_INFO))
  1603. return -EINVAL;
  1604. if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO)))
  1605. return -EFAULT;
  1606. }
  1607. }
  1608. break ;
  1609. case IOCTL_BCM_SELECT_DSD :
  1610. {
  1611. UINT SectOfset = 0;
  1612. FLASH2X_SECTION_VAL eFlash2xSectionVal;
  1613. eFlash2xSectionVal = NO_SECTION_VAL ;
  1614. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_SELECT_DSD Called");
  1615. if(IsFlash2x(Adapter) != TRUE)
  1616. {
  1617. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash Does not have 2.x map");
  1618. return -EINVAL;
  1619. }
  1620. Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
  1621. if(Status)
  1622. {
  1623. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
  1624. return Status;
  1625. }
  1626. Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
  1627. if(Status)
  1628. {
  1629. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
  1630. return Status;
  1631. }
  1632. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Read Section :%d", eFlash2xSectionVal);
  1633. if((eFlash2xSectionVal != DSD0) &&
  1634. (eFlash2xSectionVal != DSD1) &&
  1635. (eFlash2xSectionVal != DSD2) )
  1636. {
  1637. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Passed section<%x> is not DSD section", eFlash2xSectionVal);
  1638. return STATUS_FAILURE ;
  1639. }
  1640. SectOfset= BcmGetSectionValStartOffset(Adapter,eFlash2xSectionVal);
  1641. if(SectOfset == INVALID_OFFSET)
  1642. {
  1643. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Provided Section val <%d> does not exixt in Flash 2.x", eFlash2xSectionVal);
  1644. return -EINVAL;
  1645. }
  1646. Adapter->bAllDSDWriteAllow = TRUE ;
  1647. Adapter->ulFlashCalStart = SectOfset ;
  1648. Adapter->eActiveDSD = eFlash2xSectionVal;
  1649. }
  1650. Status = STATUS_SUCCESS ;
  1651. break;
  1652. case IOCTL_BCM_NVM_RAW_READ :
  1653. {
  1654. NVM_READWRITE stNVMRead;
  1655. INT NOB ;
  1656. INT BuffSize ;
  1657. INT ReadOffset = 0;
  1658. UINT ReadBytes = 0 ;
  1659. PUCHAR pReadBuff;
  1660. void __user *OutPutBuff;
  1661. if(Adapter->eNVMType != NVM_FLASH)
  1662. {
  1663. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"NVM TYPE is not Flash ");
  1664. return -EINVAL ;
  1665. }
  1666. /* Copy Ioctl Buffer structure */
  1667. if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  1668. {
  1669. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n");
  1670. Status = -EFAULT;
  1671. break;
  1672. }
  1673. if(copy_from_user(&stNVMRead, IoBuffer.OutputBuffer,sizeof(NVM_READWRITE)))
  1674. return -EFAULT;
  1675. NOB = stNVMRead.uiNumBytes;
  1676. //In Raw-Read max Buff size : 64MB
  1677. if(NOB > DEFAULT_BUFF_SIZE)
  1678. BuffSize = DEFAULT_BUFF_SIZE;
  1679. else
  1680. BuffSize = NOB ;
  1681. ReadOffset = stNVMRead.uiOffset;
  1682. OutPutBuff = stNVMRead.pBuffer;
  1683. pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
  1684. if(pReadBuff == NULL)
  1685. {
  1686. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
  1687. Status = -ENOMEM;
  1688. break;
  1689. }
  1690. down(&Adapter->NVMRdmWrmLock);
  1691. if((Adapter->IdleMode == TRUE) ||
  1692. (Adapter->bShutStatus ==TRUE) ||
  1693. (Adapter->bPreparingForLowPowerMode ==TRUE))
  1694. {
  1695. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
  1696. kfree(pReadBuff);
  1697. up(&Adapter->NVMRdmWrmLock);
  1698. return -EACCES;
  1699. }
  1700. Adapter->bFlashRawRead = TRUE ;
  1701. while(NOB)
  1702. {
  1703. if(NOB > DEFAULT_BUFF_SIZE )
  1704. ReadBytes = DEFAULT_BUFF_SIZE;
  1705. else
  1706. ReadBytes = NOB;
  1707. //Reading the data from Flash 2.x
  1708. Status = BeceemNVMRead(Adapter,(PUINT)pReadBuff,ReadOffset,ReadBytes);
  1709. if(Status)
  1710. {
  1711. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Flash 2x read err with Status :%d", Status);
  1712. break;
  1713. }
  1714. BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff,ReadBytes);
  1715. Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
  1716. if(Status)
  1717. {
  1718. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to use failed with status :%d", Status);
  1719. break;
  1720. }
  1721. NOB = NOB - ReadBytes;
  1722. if(NOB)
  1723. {
  1724. ReadOffset = ReadOffset + ReadBytes ;
  1725. OutPutBuff = OutPutBuff + ReadBytes ;
  1726. }
  1727. }
  1728. Adapter->bFlashRawRead = FALSE ;
  1729. up(&Adapter->NVMRdmWrmLock);
  1730. kfree(pReadBuff);
  1731. break ;
  1732. }
  1733. case IOCTL_BCM_CNTRLMSG_MASK:
  1734. {
  1735. ULONG RxCntrlMsgBitMask = 0 ;
  1736. /* Copy Ioctl Buffer structure */
  1737. Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
  1738. if(Status)
  1739. {
  1740. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of Ioctl buffer is failed from user space");
  1741. Status = -EFAULT;
  1742. break;
  1743. }
  1744. if (IoBuffer.InputLength != sizeof(unsigned long)) {
  1745. Status = -EINVAL;
  1746. break;
  1747. }
  1748. Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer, IoBuffer.InputLength);
  1749. if(Status)
  1750. {
  1751. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of control bit mask failed from user space");
  1752. Status = -EFAULT;
  1753. break;
  1754. }
  1755. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
  1756. pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask ;
  1757. }
  1758. break;
  1759. case IOCTL_BCM_GET_DEVICE_DRIVER_INFO:
  1760. {
  1761. DEVICE_DRIVER_INFO DevInfo;
  1762. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
  1763. DevInfo.MaxRDMBufferSize = BUFFER_4K;
  1764. DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
  1765. DevInfo.u32RxAlignmentCorrection = 0;
  1766. DevInfo.u32NVMType = Adapter->eNVMType;
  1767. DevInfo.u32InterfaceType = BCM_USB;
  1768. if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  1769. return -EFAULT;
  1770. if(IoBuffer.OutputLength < sizeof(DevInfo))
  1771. return -EINVAL;
  1772. if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
  1773. return -EFAULT;
  1774. }
  1775. break ;
  1776. case IOCTL_BCM_TIME_SINCE_NET_ENTRY:
  1777. {
  1778. ST_TIME_ELAPSED stTimeElapsedSinceNetEntry = {0};
  1779. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
  1780. if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
  1781. return -EFAULT;
  1782. if(IoBuffer.OutputLength < sizeof(ST_TIME_ELAPSED))
  1783. return -EINVAL;
  1784. stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = get_seconds() - Adapter->liTimeSinceLastNetEntry;
  1785. if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(ST_TIME_ELAPSED)))
  1786. return -EFAULT;
  1787. }
  1788. break;
  1789. case IOCTL_CLOSE_NOTIFICATION:
  1790. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_CLOSE_NOTIFICATION");
  1791. break;
  1792. default:
  1793. pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
  1794. Status = STATUS_FAILURE;
  1795. break;
  1796. }
  1797. return Status;
  1798. }
  1799. static const struct file_operations bcm_fops = {
  1800. .owner = THIS_MODULE,
  1801. .open = bcm_char_open,
  1802. .release = bcm_char_release,
  1803. .read = bcm_char_read,
  1804. .unlocked_ioctl = bcm_char_ioctl,
  1805. .llseek = no_llseek,
  1806. };
  1807. extern struct class *bcm_class;
  1808. int register_control_device_interface(PMINI_ADAPTER Adapter)
  1809. {
  1810. if (Adapter->major > 0)
  1811. return Adapter->major;
  1812. Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
  1813. if (Adapter->major < 0) {
  1814. pr_err(DRV_NAME ": could not created character device\n");
  1815. return Adapter->major;
  1816. }
  1817. Adapter->pstCreatedClassDevice = device_create(bcm_class, NULL,
  1818. MKDEV(Adapter->major, 0),
  1819. Adapter, DEV_NAME);
  1820. if (IS_ERR(Adapter->pstCreatedClassDevice)) {
  1821. pr_err(DRV_NAME ": class device create failed\n");
  1822. unregister_chrdev(Adapter->major, DEV_NAME);
  1823. return PTR_ERR(Adapter->pstCreatedClassDevice);
  1824. }
  1825. return 0;
  1826. }
  1827. void unregister_control_device_interface(PMINI_ADAPTER Adapter)
  1828. {
  1829. if (Adapter->major > 0) {
  1830. device_destroy(bcm_class, MKDEV(Adapter->major, 0));
  1831. unregister_chrdev(Adapter->major, DEV_NAME);
  1832. }
  1833. }