PageRenderTime 1124ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/staging/bcm/Bcmchar.c

https://github.com/Mengqi/linux-2.6
C | 1633 lines | 1321 code | 226 blank | 86 comment | 302 complexity | f4a59218bf9cdfee8d155126f97b34a9 MD5 | raw file
  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. {