blob: c1e01f7d64ba2d313f387cc0740b01b9feb53b50 [file] [log] [blame]
Arnd Bergmannd16044cf2010-09-30 10:24:07 +02001#include <linux/fs.h>
2
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07003#include "headers.h"
Matthias Beyer8224ac22014-05-22 12:17:26 +02004
5static int bcm_handle_nvm_read_cmd(struct bcm_mini_adapter *Adapter,
6 PUCHAR pReadData, struct bcm_nvm_readwrite *stNVMReadWrite)
7{
8 INT Status = STATUS_FAILURE;
9
10 down(&Adapter->NVMRdmWrmLock);
11
12 if ((Adapter->IdleMode == TRUE) || (Adapter->bShutStatus == TRUE) ||
13 (Adapter->bPreparingForLowPowerMode == TRUE)) {
14
15 BCM_DEBUG_PRINT(Adapter,
16 DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
17 "Device is in Idle/Shutdown Mode\n");
18 up(&Adapter->NVMRdmWrmLock);
19 kfree(pReadData);
20 return -EACCES;
21 }
22
23 Status = BeceemNVMRead(Adapter, (PUINT)pReadData,
24 stNVMReadWrite->uiOffset,
25 stNVMReadWrite->uiNumBytes);
26 up(&Adapter->NVMRdmWrmLock);
27
28 if (Status != STATUS_SUCCESS) {
29 kfree(pReadData);
30 return Status;
31 }
32
33 if (copy_to_user(stNVMReadWrite->pBuffer, pReadData,
34 stNVMReadWrite->uiNumBytes)) {
35 kfree(pReadData);
36 return -EFAULT;
37 }
38
39 return STATUS_SUCCESS;
40}
41
Matthias Beyere5c34a12014-05-22 12:17:27 +020042static int handle_flash2x_adapter(struct bcm_mini_adapter *Adapter,
43 PUCHAR pReadData, struct bcm_nvm_readwrite *stNVMReadWrite)
44{
45 /*
46 * New Requirement:-
47 * DSD section updation will be allowed in two case:-
48 * 1. if DSD sig is present in DSD header means dongle
49 * is ok and updation is fruitfull
50 * 2. if point 1 failes then user buff should have
51 * DSD sig. this point ensures that if dongle is
52 * corrupted then user space program first modify
53 * the DSD header with valid DSD sig so that this
54 * as well as further write may be worthwhile.
55 *
56 * This restriction has been put assuming that
57 * if DSD sig is corrupted, DSD data won't be
58 * considered valid.
59 */
60 INT Status;
61 ULONG ulDSDMagicNumInUsrBuff = 0;
62
63 Status = BcmFlash2xCorruptSig(Adapter, Adapter->eActiveDSD);
64 if (Status == STATUS_SUCCESS)
65 return STATUS_SUCCESS;
66
67 if (((stNVMReadWrite->uiOffset + stNVMReadWrite->uiNumBytes) !=
68 Adapter->uiNVMDSDSize) ||
69 (stNVMReadWrite->uiNumBytes < SIGNATURE_SIZE)) {
70
71 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
72 "DSD Sig is present neither in Flash nor User provided Input..");
73 up(&Adapter->NVMRdmWrmLock);
74 kfree(pReadData);
75 return Status;
76 }
77
78 ulDSDMagicNumInUsrBuff =
79 ntohl(*(PUINT)(pReadData + stNVMReadWrite->uiNumBytes -
80 SIGNATURE_SIZE));
81 if (ulDSDMagicNumInUsrBuff != DSD_IMAGE_MAGIC_NUMBER) {
82 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
83 "DSD Sig is present neither in Flash nor User provided Input..");
84 up(&Adapter->NVMRdmWrmLock);
85 kfree(pReadData);
86 return Status;
87 }
88
89 return STATUS_SUCCESS;
90}
91
Stephen Hemmingerf8942e02010-09-08 14:46:36 -070092/***************************************************************
93* Function - bcm_char_open()
94*
95* Description - This is the "open" entry point for the character
96* driver.
97*
98* Parameters - inode: Pointer to the Inode structure of char device
99* filp : File pointer of the char device
100*
101* Returns - Zero(Success)
102****************************************************************/
Stephen Hemminger9e0a3162010-11-01 10:17:54 -0400103
Severin Gsponer14704cc2013-04-29 15:49:04 +0200104static int bcm_char_open(struct inode *inode, struct file *filp)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700105{
Kevin McKinney29794602012-05-26 12:05:12 -0400106 struct bcm_mini_adapter *Adapter = NULL;
Kevin McKinney774bea82012-05-26 12:05:00 -0400107 struct bcm_tarang_data *pTarang = NULL;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700108
109 Adapter = GET_BCM_ADAPTER(gblpnetdev);
Kevin McKinney774bea82012-05-26 12:05:00 -0400110 pTarang = kzalloc(sizeof(struct bcm_tarang_data), GFP_KERNEL);
Javier Martinez Canillas1e123322011-02-12 04:38:22 +0100111 if (!pTarang)
112 return -ENOMEM;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700113
Javier Martinez Canillas1e123322011-02-12 04:38:22 +0100114 pTarang->Adapter = Adapter;
115 pTarang->RxCntrlMsgBitMask = 0xFFFFFFFF & ~(1 << 0xB);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700116
117 down(&Adapter->RxAppControlQueuelock);
Javier Martinez Canillas1e123322011-02-12 04:38:22 +0100118 pTarang->next = Adapter->pTarangs;
119 Adapter->pTarangs = pTarang;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700120 up(&Adapter->RxAppControlQueuelock);
121
122 /* Store the Adapter structure */
123 filp->private_data = pTarang;
124
Kevin McKinney6c15e002011-08-15 22:07:41 -0400125 /* Start Queuing the control response Packets */
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700126 atomic_inc(&Adapter->ApplicationRunning);
Arnd Bergmannd16044cf2010-09-30 10:24:07 +0200127
128 nonseekable_open(inode, filp);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700129 return 0;
130}
Javier Martinez Canillas1e123322011-02-12 04:38:22 +0100131
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700132static int bcm_char_release(struct inode *inode, struct file *filp)
133{
Kevin McKinney774bea82012-05-26 12:05:00 -0400134 struct bcm_tarang_data *pTarang, *tmp, *ptmp;
Kevin McKinney29794602012-05-26 12:05:12 -0400135 struct bcm_mini_adapter *Adapter = NULL;
Javier Martinez Canillasa7d39762011-02-12 04:38:23 +0100136 struct sk_buff *pkt, *npkt;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700137
Kevin McKinney774bea82012-05-26 12:05:00 -0400138 pTarang = (struct bcm_tarang_data *)filp->private_data;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700139
Chuong Ngo0cd2da42013-10-23 15:11:20 -0400140 if (pTarang == NULL)
Javier Martinez Canillasa7d39762011-02-12 04:38:23 +0100141 return 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700142
143 Adapter = pTarang->Adapter;
144
Javier Martinez Canillasa7d39762011-02-12 04:38:23 +0100145 down(&Adapter->RxAppControlQueuelock);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700146
Javier Martinez Canillasa7d39762011-02-12 04:38:23 +0100147 tmp = Adapter->pTarangs;
148 for (ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next) {
149 if (tmp == pTarang)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700150 break;
151 }
152
Javier Martinez Canillasa7d39762011-02-12 04:38:23 +0100153 if (tmp) {
154 if (!ptmp)
155 Adapter->pTarangs = tmp->next;
156 else
157 ptmp->next = tmp->next;
158 } else {
159 up(&Adapter->RxAppControlQueuelock);
160 return 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700161 }
162
Javier Martinez Canillasa7d39762011-02-12 04:38:23 +0100163 pkt = pTarang->RxAppControlHead;
164 while (pkt) {
165 npkt = pkt->next;
166 kfree_skb(pkt);
167 pkt = npkt;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700168 }
169
Javier Martinez Canillasa7d39762011-02-12 04:38:23 +0100170 up(&Adapter->RxAppControlQueuelock);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700171
Kevin McKinney6c15e002011-08-15 22:07:41 -0400172 /* Stop Queuing the control response Packets */
Javier Martinez Canillasa7d39762011-02-12 04:38:23 +0100173 atomic_dec(&Adapter->ApplicationRunning);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700174
Javier Martinez Canillasa7d39762011-02-12 04:38:23 +0100175 kfree(pTarang);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700176
177 /* remove this filp from the asynchronously notified filp's */
Javier Martinez Canillasa7d39762011-02-12 04:38:23 +0100178 filp->private_data = NULL;
179 return 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700180}
181
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100182static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size,
183 loff_t *f_pos)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700184{
Kevin McKinney774bea82012-05-26 12:05:00 -0400185 struct bcm_tarang_data *pTarang = filp->private_data;
Kevin McKinney29794602012-05-26 12:05:12 -0400186 struct bcm_mini_adapter *Adapter = pTarang->Adapter;
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100187 struct sk_buff *Packet = NULL;
Kevin McKinney6c15e002011-08-15 22:07:41 -0400188 ssize_t PktLen = 0;
189 int wait_ret_val = 0;
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100190 unsigned long ret = 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700191
Matthias Beyer22840ad2014-05-22 12:17:25 +0200192 wait_ret_val = wait_event_interruptible(
193 Adapter->process_read_wait_queue,
194 (pTarang->RxAppControlHead ||
195 Adapter->device_removed));
196
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100197 if ((wait_ret_val == -ERESTARTSYS)) {
198 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
199 "Exiting as i've been asked to exit!!!\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700200 return wait_ret_val;
201 }
202
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100203 if (Adapter->device_removed) {
204 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
205 "Device Removed... Killing the Apps...\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700206 return -ENODEV;
207 }
208
Lisa Nguyenf70c8a92013-10-28 01:36:19 -0700209 if (false == Adapter->fw_download_done)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700210 return -EACCES;
211
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100212 down(&Adapter->RxAppControlQueuelock);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700213
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100214 if (pTarang->RxAppControlHead) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700215 Packet = pTarang->RxAppControlHead;
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100216 DEQUEUEPACKET(pTarang->RxAppControlHead,
217 pTarang->RxAppControlTail);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700218 pTarang->AppCtrlQueueLen--;
219 }
220
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100221 up(&Adapter->RxAppControlQueuelock);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700222
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100223 if (Packet) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700224 PktLen = Packet->len;
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100225 ret = copy_to_user(buf, Packet->data,
226 min_t(size_t, PktLen, size));
227 if (ret) {
Stephen Hemminger082e8892010-11-01 09:35:21 -0400228 dev_kfree_skb(Packet);
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100229 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
230 "Returning from copy to user failure\n");
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700231 return -EFAULT;
232 }
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100233 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Stephen Hemmingerada692b2010-11-01 09:26:47 -0400234 "Read %zd Bytes From Adapter packet = %p by process %d!\n",
235 PktLen, Packet, current->pid);
Stephen Hemminger082e8892010-11-01 09:35:21 -0400236 dev_kfree_skb(Packet);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700237 }
238
Javier Martinez Canillas7227ba02011-02-12 04:38:24 +0100239 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<\n");
240 return PktLen;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -0700241}
242
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200243static int bcm_char_ioctl_reg_read_private(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200244 struct bcm_mini_adapter *Adapter)
Dave Jones59fbe702014-02-13 14:45:05 -0500245{
246 struct bcm_rdm_buffer sRdmBuffer = {0};
247 struct bcm_ioctl_buffer IoBuffer;
248 PCHAR temp_buff;
249 INT Status = STATUS_FAILURE;
250 UINT Bufflen;
251 u16 temp_value;
252 int bytes;
253
254 /* Copy Ioctl Buffer structure */
255 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
256 return -EFAULT;
257
258 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
259 return -EINVAL;
260
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200261 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer,
262 IoBuffer.InputLength))
Dave Jones59fbe702014-02-13 14:45:05 -0500263 return -EFAULT;
264
265 if (IoBuffer.OutputLength > USHRT_MAX ||
266 IoBuffer.OutputLength == 0) {
267 return -EINVAL;
268 }
269
270 Bufflen = IoBuffer.OutputLength;
271 temp_value = 4 - (Bufflen % 4);
272 Bufflen += temp_value % 4;
273
274 temp_buff = kmalloc(Bufflen, GFP_KERNEL);
275 if (!temp_buff)
276 return -ENOMEM;
277
278 bytes = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
279 (PUINT)temp_buff, Bufflen);
280 if (bytes > 0) {
281 Status = STATUS_SUCCESS;
282 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
283 kfree(temp_buff);
284 return -EFAULT;
285 }
286 } else {
287 Status = bytes;
288 }
289
290 kfree(temp_buff);
291 return Status;
292}
293
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200294static int bcm_char_ioctl_reg_write_private(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200295 struct bcm_mini_adapter *Adapter)
Dave Jones68270092014-02-13 14:45:11 -0500296{
297 struct bcm_wrm_buffer sWrmBuffer = {0};
298 struct bcm_ioctl_buffer IoBuffer;
299 UINT uiTempVar = 0;
300 INT Status;
301
302 /* Copy Ioctl Buffer structure */
303
304 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
305 return -EFAULT;
306
307 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
308 return -EINVAL;
309
310 /* Get WrmBuffer structure */
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200311 if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer,
312 IoBuffer.InputLength))
Dave Jones68270092014-02-13 14:45:11 -0500313 return -EFAULT;
314
315 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
316 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
317 ((uiTempVar == EEPROM_REJECT_REG_1) ||
318 (uiTempVar == EEPROM_REJECT_REG_2) ||
319 (uiTempVar == EEPROM_REJECT_REG_3) ||
320 (uiTempVar == EEPROM_REJECT_REG_4))) {
321
322 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
323 "EEPROM Access Denied, not in VSG Mode\n");
324 return -EFAULT;
325 }
326
327 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
328 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
329
330 if (Status == STATUS_SUCCESS) {
331 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
332 DBG_LVL_ALL, "WRM Done\n");
333 } else {
334 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
335 DBG_LVL_ALL, "WRM Failed\n");
336 Status = -EFAULT;
337 }
338 return Status;
339}
340
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200341static int bcm_char_ioctl_eeprom_reg_read(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200342 struct bcm_mini_adapter *Adapter)
Dave Jones3195d4e2014-02-13 14:45:16 -0500343{
344 struct bcm_rdm_buffer sRdmBuffer = {0};
345 struct bcm_ioctl_buffer IoBuffer;
346 PCHAR temp_buff = NULL;
347 UINT uiTempVar = 0;
348 INT Status;
349 int bytes;
350
351 if ((Adapter->IdleMode == TRUE) ||
352 (Adapter->bShutStatus == TRUE) ||
353 (Adapter->bPreparingForLowPowerMode == TRUE)) {
354
355 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
356 "Device in Idle Mode, Blocking Rdms\n");
357 return -EACCES;
358 }
359
360 /* Copy Ioctl Buffer structure */
361 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
362 return -EFAULT;
363
364 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
365 return -EINVAL;
366
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200367 if (copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer,
368 IoBuffer.InputLength))
Dave Jones3195d4e2014-02-13 14:45:16 -0500369 return -EFAULT;
370
371 if (IoBuffer.OutputLength > USHRT_MAX ||
372 IoBuffer.OutputLength == 0) {
373 return -EINVAL;
374 }
375
376 temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
377 if (!temp_buff)
378 return STATUS_FAILURE;
379
380 if ((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
381 ((ULONG)sRdmBuffer.Register & 0x3)) {
382
383 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
384 "RDM Done On invalid Address : %x Access Denied.\n",
385 (int)sRdmBuffer.Register);
386
387 kfree(temp_buff);
388 return -EINVAL;
389 }
390
391 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
392 bytes = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
393 (PUINT)temp_buff, IoBuffer.OutputLength);
394
395 if (bytes > 0) {
396 Status = STATUS_SUCCESS;
397 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff, bytes)) {
398 kfree(temp_buff);
399 return -EFAULT;
400 }
401 } else {
402 Status = bytes;
403 }
404
405 kfree(temp_buff);
406 return Status;
407}
Dave Jones68270092014-02-13 14:45:11 -0500408
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200409static int bcm_char_ioctl_eeprom_reg_write(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200410 struct bcm_mini_adapter *Adapter,
411 UINT cmd)
Dave Jones4d4b00a2014-02-13 14:45:21 -0500412{
413 struct bcm_wrm_buffer sWrmBuffer = {0};
414 struct bcm_ioctl_buffer IoBuffer;
415 UINT uiTempVar = 0;
416 INT Status;
417
418 if ((Adapter->IdleMode == TRUE) ||
419 (Adapter->bShutStatus == TRUE) ||
420 (Adapter->bPreparingForLowPowerMode == TRUE)) {
421
422 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
423 "Device in Idle Mode, Blocking Wrms\n");
424 return -EACCES;
425 }
426
427 /* Copy Ioctl Buffer structure */
428 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
429 return -EFAULT;
430
431 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
432 return -EINVAL;
433
434 /* Get WrmBuffer structure */
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200435 if (copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer,
436 IoBuffer.InputLength))
Dave Jones4d4b00a2014-02-13 14:45:21 -0500437 return -EFAULT;
438
439 if ((((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
440 ((ULONG)sWrmBuffer.Register & 0x3)) {
441
442 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
443 "WRM Done On invalid Address : %x Access Denied.\n",
444 (int)sWrmBuffer.Register);
445 return -EINVAL;
446 }
447
448 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
449 if (!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
450 ((uiTempVar == EEPROM_REJECT_REG_1) ||
451 (uiTempVar == EEPROM_REJECT_REG_2) ||
452 (uiTempVar == EEPROM_REJECT_REG_3) ||
453 (uiTempVar == EEPROM_REJECT_REG_4)) &&
454 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
455
456 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
457 "EEPROM Access Denied, not in VSG Mode\n");
458 return -EFAULT;
459 }
460
461 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
462 (PUINT)sWrmBuffer.Data,
463 sWrmBuffer.Length);
464
465 if (Status == STATUS_SUCCESS) {
466 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG,
467 DBG_LVL_ALL, "WRM Done\n");
468 } else {
469 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
470 DBG_LVL_ALL, "WRM Failed\n");
471 Status = -EFAULT;
472 }
473 return Status;
474}
475
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200476static int bcm_char_ioctl_gpio_set_request(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200477 struct bcm_mini_adapter *Adapter)
Dave Jonesf494a912014-02-13 14:45:26 -0500478{
479 struct bcm_gpio_info gpio_info = {0};
480 struct bcm_ioctl_buffer IoBuffer;
481 UCHAR ucResetValue[4];
482 UINT value = 0;
483 UINT uiBit = 0;
484 UINT uiOperation = 0;
485 INT Status;
486 int bytes;
487
488 if ((Adapter->IdleMode == TRUE) ||
489 (Adapter->bShutStatus == TRUE) ||
490 (Adapter->bPreparingForLowPowerMode == TRUE)) {
491
492 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
493 DBG_LVL_ALL,
494 "GPIO Can't be set/clear in Low power Mode");
495 return -EACCES;
496 }
497
498 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
499 return -EFAULT;
500
501 if (IoBuffer.InputLength > sizeof(gpio_info))
502 return -EINVAL;
503
Matthias Beyer22840ad2014-05-22 12:17:25 +0200504 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200505 IoBuffer.InputLength))
Dave Jonesf494a912014-02-13 14:45:26 -0500506 return -EFAULT;
507
508 uiBit = gpio_info.uiGpioNumber;
509 uiOperation = gpio_info.uiGpioValue;
510 value = (1<<uiBit);
511
512 if (IsReqGpioIsLedInNVM(Adapter, value) == false) {
513 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
514 DBG_LVL_ALL,
515 "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",
516 value);
517 return -EINVAL;
518 }
519
520 /* Set - setting 1 */
521 if (uiOperation) {
522 /* Set the gpio output register */
523 Status = wrmaltWithLock(Adapter,
524 BCM_GPIO_OUTPUT_SET_REG,
525 (PUINT)(&value), sizeof(UINT));
526
527 if (Status == STATUS_SUCCESS) {
528 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
529 OSAL_DBG, DBG_LVL_ALL,
530 "Set the GPIO bit\n");
531 } else {
532 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
533 OSAL_DBG, DBG_LVL_ALL,
534 "Failed to set the %dth GPIO\n",
535 uiBit);
536 return Status;
537 }
538 } else {
539 /* Set the gpio output register */
540 Status = wrmaltWithLock(Adapter,
541 BCM_GPIO_OUTPUT_CLR_REG,
542 (PUINT)(&value), sizeof(UINT));
543
544 if (Status == STATUS_SUCCESS) {
545 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
546 OSAL_DBG, DBG_LVL_ALL,
547 "Set the GPIO bit\n");
548 } else {
549 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
550 OSAL_DBG, DBG_LVL_ALL,
551 "Failed to clear the %dth GPIO\n",
552 uiBit);
553 return Status;
554 }
555 }
556
557 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
558 (PUINT)ucResetValue, sizeof(UINT));
559 if (bytes < 0) {
560 Status = bytes;
561 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
562 "GPIO_MODE_REGISTER read failed");
563 return Status;
564 } else {
565 Status = STATUS_SUCCESS;
566 }
567
568 /* Set the gpio mode register to output */
569 *(UINT *)ucResetValue |= (1<<uiBit);
570 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER,
571 (PUINT)ucResetValue, sizeof(UINT));
572
573 if (Status == STATUS_SUCCESS) {
574 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
575 DBG_LVL_ALL,
576 "Set the GPIO to output Mode\n");
577 } else {
578 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
579 DBG_LVL_ALL,
580 "Failed to put GPIO in Output Mode\n");
581 }
582
583 return Status;
584}
585
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200586static int bcm_char_ioctl_led_thread_state_change_req(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200587 struct bcm_mini_adapter *Adapter)
Dave Jones3eccdbc2014-02-13 14:45:31 -0500588{
589 struct bcm_user_thread_req threadReq = {0};
590 struct bcm_ioctl_buffer IoBuffer;
591
592 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
593 "User made LED thread InActive");
594
595 if ((Adapter->IdleMode == TRUE) ||
596 (Adapter->bShutStatus == TRUE) ||
597 (Adapter->bPreparingForLowPowerMode == TRUE)) {
598
599 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
600 DBG_LVL_ALL,
601 "GPIO Can't be set/clear in Low power Mode");
602 return -EACCES;
603 }
604
605 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
606 return -EFAULT;
607
608 if (IoBuffer.InputLength > sizeof(threadReq))
609 return -EINVAL;
610
Matthias Beyer22840ad2014-05-22 12:17:25 +0200611 if (copy_from_user(&threadReq, IoBuffer.InputBuffer,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200612 IoBuffer.InputLength))
Dave Jones3eccdbc2014-02-13 14:45:31 -0500613 return -EFAULT;
614
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200615 /* if LED thread is running(Actively or Inactively)
616 * set it state to make inactive
617 */
Dave Jones3eccdbc2014-02-13 14:45:31 -0500618 if (Adapter->LEDInfo.led_thread_running) {
619 if (threadReq.ThreadState == LED_THREAD_ACTIVATION_REQ) {
620 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
621 OSAL_DBG, DBG_LVL_ALL,
622 "Activating thread req");
623 Adapter->DriverState = LED_THREAD_ACTIVE;
624 } else {
625 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
626 OSAL_DBG, DBG_LVL_ALL,
627 "DeActivating Thread req.....");
628 Adapter->DriverState = LED_THREAD_INACTIVE;
629 }
630
631 /* signal thread. */
632 wake_up(&Adapter->LEDInfo.notify_led_event);
633 }
634 return STATUS_SUCCESS;
635}
636
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200637static int bcm_char_ioctl_gpio_status_request(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200638 struct bcm_mini_adapter *Adapter)
Dave Jones3eedb5f2014-02-13 14:45:36 -0500639{
640 struct bcm_gpio_info gpio_info = {0};
641 struct bcm_ioctl_buffer IoBuffer;
642 ULONG uiBit = 0;
643 UCHAR ucRead[4];
644 INT Status;
645 int bytes;
646
647 if ((Adapter->IdleMode == TRUE) ||
648 (Adapter->bShutStatus == TRUE) ||
649 (Adapter->bPreparingForLowPowerMode == TRUE))
650 return -EACCES;
651
652 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
653 return -EFAULT;
654
655 if (IoBuffer.InputLength > sizeof(gpio_info))
656 return -EINVAL;
657
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200658 if (copy_from_user(&gpio_info, IoBuffer.InputBuffer,
659 IoBuffer.InputLength))
Dave Jones3eedb5f2014-02-13 14:45:36 -0500660 return -EFAULT;
661
662 uiBit = gpio_info.uiGpioNumber;
663
664 /* Set the gpio output register */
665 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
666 (PUINT)ucRead, sizeof(UINT));
667
668 if (bytes < 0) {
669 Status = bytes;
670 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
671 "RDM Failed\n");
672 return Status;
673 } else {
674 Status = STATUS_SUCCESS;
675 }
676 return Status;
677}
678
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200679static int bcm_char_ioctl_gpio_multi_request(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200680 struct bcm_mini_adapter *Adapter)
Dave Jones39032462014-02-13 14:45:41 -0500681{
682 struct bcm_gpio_multi_info gpio_multi_info[MAX_IDX];
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200683 struct bcm_gpio_multi_info *pgpio_multi_info =
684 (struct bcm_gpio_multi_info *)gpio_multi_info;
Dave Jones39032462014-02-13 14:45:41 -0500685 struct bcm_ioctl_buffer IoBuffer;
686 UCHAR ucResetValue[4];
687 INT Status = STATUS_FAILURE;
688 int bytes;
689
Matthias Beyer22840ad2014-05-22 12:17:25 +0200690 memset(pgpio_multi_info, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200691 MAX_IDX * sizeof(struct bcm_gpio_multi_info));
Dave Jones39032462014-02-13 14:45:41 -0500692
693 if ((Adapter->IdleMode == TRUE) ||
694 (Adapter->bShutStatus == TRUE) ||
695 (Adapter->bPreparingForLowPowerMode == TRUE))
696 return -EINVAL;
697
698 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
699 return -EFAULT;
700
701 if (IoBuffer.InputLength > sizeof(gpio_multi_info))
702 return -EINVAL;
Dan Carpentercfff3e5c2014-02-17 22:56:06 +0300703 if (IoBuffer.OutputLength > sizeof(gpio_multi_info))
704 IoBuffer.OutputLength = sizeof(gpio_multi_info);
Dave Jones39032462014-02-13 14:45:41 -0500705
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200706 if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200707 IoBuffer.InputLength))
Dave Jones39032462014-02-13 14:45:41 -0500708 return -EFAULT;
709
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200710 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_info[WIMAX_IDX].uiGPIOMask)
711 == false) {
Dave Jones39032462014-02-13 14:45:41 -0500712 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
713 DBG_LVL_ALL,
714 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
715 pgpio_multi_info[WIMAX_IDX].uiGPIOMask,
716 Adapter->gpioBitMap);
717 return -EINVAL;
718 }
719
720 /* Set the gpio output register */
721 if ((pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
722 (pgpio_multi_info[WIMAX_IDX].uiGPIOCommand)) {
723 /* Set 1's in GPIO OUTPUT REGISTER */
Matthias Beyer22840ad2014-05-22 12:17:25 +0200724 *(UINT *)ucResetValue = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
Dave Jones39032462014-02-13 14:45:41 -0500725 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
726 pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
727
728 if (*(UINT *) ucResetValue)
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200729 Status = wrmaltWithLock(Adapter,
730 BCM_GPIO_OUTPUT_SET_REG,
731 (PUINT)ucResetValue, sizeof(ULONG));
Dave Jones39032462014-02-13 14:45:41 -0500732
733 if (Status != STATUS_SUCCESS) {
734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200735 "WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
Dave Jones39032462014-02-13 14:45:41 -0500736 return Status;
737 }
738
739 /* Clear to 0's in GPIO OUTPUT REGISTER */
Matthias Beyer22840ad2014-05-22 12:17:25 +0200740 *(UINT *)ucResetValue =
741 (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200742 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
743 (~(pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
Dave Jones39032462014-02-13 14:45:41 -0500744
745 if (*(UINT *) ucResetValue)
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200746 Status = wrmaltWithLock(Adapter,
747 BCM_GPIO_OUTPUT_CLR_REG, (PUINT)ucResetValue,
748 sizeof(ULONG));
Dave Jones39032462014-02-13 14:45:41 -0500749
750 if (Status != STATUS_SUCCESS) {
751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
752 "WRM to BCM_GPIO_OUTPUT_CLR_REG Failed.");
753 return Status;
754 }
755 }
756
757 if (pgpio_multi_info[WIMAX_IDX].uiGPIOMask) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200758 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200759 (PUINT)ucResetValue, sizeof(UINT));
Dave Jones39032462014-02-13 14:45:41 -0500760
761 if (bytes < 0) {
762 Status = bytes;
763 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
764 "RDM to GPIO_PIN_STATE_REGISTER Failed.");
765 return Status;
766 } else {
767 Status = STATUS_SUCCESS;
768 }
769
Matthias Beyer22840ad2014-05-22 12:17:25 +0200770 pgpio_multi_info[WIMAX_IDX].uiGPIOValue =
771 (*(UINT *)ucResetValue &
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200772 pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
Dave Jones39032462014-02-13 14:45:41 -0500773 }
774
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200775 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_info,
776 IoBuffer.OutputLength);
Dave Jones39032462014-02-13 14:45:41 -0500777 if (Status) {
778 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200779 "Failed while copying Content to IOBufer for user space err:%d",
780 Status);
Dave Jones39032462014-02-13 14:45:41 -0500781 return -EFAULT;
782 }
783 return Status;
784}
785
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200786static int bcm_char_ioctl_gpio_mode_request(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200787 struct bcm_mini_adapter *Adapter)
Dave Jonese2d94d22014-02-13 14:45:47 -0500788{
789 struct bcm_gpio_multi_mode gpio_multi_mode[MAX_IDX];
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200790 struct bcm_gpio_multi_mode *pgpio_multi_mode =
791 (struct bcm_gpio_multi_mode *)gpio_multi_mode;
Dave Jonese2d94d22014-02-13 14:45:47 -0500792 struct bcm_ioctl_buffer IoBuffer;
793 UCHAR ucResetValue[4];
794 INT Status;
795 int bytes;
796
797 if ((Adapter->IdleMode == TRUE) ||
798 (Adapter->bShutStatus == TRUE) ||
799 (Adapter->bPreparingForLowPowerMode == TRUE))
800 return -EINVAL;
801
802 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
803 return -EFAULT;
804
805 if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
806 return -EINVAL;
Dan Carpentercfff3e5c2014-02-17 22:56:06 +0300807 if (IoBuffer.OutputLength > sizeof(gpio_multi_mode))
808 IoBuffer.OutputLength = sizeof(gpio_multi_mode);
Dave Jonese2d94d22014-02-13 14:45:47 -0500809
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200810 if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer,
811 IoBuffer.InputLength))
Dave Jonese2d94d22014-02-13 14:45:47 -0500812 return -EFAULT;
813
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200814 bytes = rdmaltWithLock(Adapter, (UINT)GPIO_MODE_REGISTER,
815 (PUINT)ucResetValue, sizeof(UINT));
Dave Jonese2d94d22014-02-13 14:45:47 -0500816
817 if (bytes < 0) {
818 Status = bytes;
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200819 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
820 "Read of GPIO_MODE_REGISTER failed");
Dave Jonese2d94d22014-02-13 14:45:47 -0500821 return Status;
822 } else {
823 Status = STATUS_SUCCESS;
824 }
825
826 /* Validating the request */
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200827 if (IsReqGpioIsLedInNVM(Adapter, pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)
828 == false) {
Dave Jonese2d94d22014-02-13 14:45:47 -0500829 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
830 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200831 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask,
832 Adapter->gpioBitMap);
Dave Jonese2d94d22014-02-13 14:45:47 -0500833 return -EINVAL;
834 }
835
836 if (pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) {
837 /* write all OUT's (1's) */
Matthias Beyer22840ad2014-05-22 12:17:25 +0200838 *(UINT *) ucResetValue |=
839 (pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
Dave Jonese2d94d22014-02-13 14:45:47 -0500840 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
841
842 /* write all IN's (0's) */
Matthias Beyer22840ad2014-05-22 12:17:25 +0200843 *(UINT *) ucResetValue &=
844 ~((~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
Dave Jonese2d94d22014-02-13 14:45:47 -0500845 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
846
847 /* Currently implemented return the modes of all GPIO's
848 * else needs to bit AND with mask
849 */
850 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
851
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200852 Status = wrmaltWithLock(Adapter, GPIO_MODE_REGISTER,
853 (PUINT)ucResetValue, sizeof(ULONG));
Dave Jonese2d94d22014-02-13 14:45:47 -0500854 if (Status == STATUS_SUCCESS) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200855 BCM_DEBUG_PRINT(Adapter,
856 DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
857 "WRM to GPIO_MODE_REGISTER Done");
Dave Jonese2d94d22014-02-13 14:45:47 -0500858 } else {
859 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
860 "WRM to GPIO_MODE_REGISTER Failed");
861 return -EFAULT;
862 }
863 } else {
864 /* if uiGPIOMask is 0 then return mode register configuration */
865 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)ucResetValue;
866 }
867
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200868 Status = copy_to_user(IoBuffer.OutputBuffer, &gpio_multi_mode,
869 IoBuffer.OutputLength);
Dave Jonese2d94d22014-02-13 14:45:47 -0500870 if (Status) {
871 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200872 "Failed while copying Content to IOBufer for user space err:%d",
873 Status);
Dave Jonese2d94d22014-02-13 14:45:47 -0500874 return -EFAULT;
875 }
876 return Status;
877}
Dave Jones3eccdbc2014-02-13 14:45:31 -0500878
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200879static int bcm_char_ioctl_misc_request(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200880 struct bcm_mini_adapter *Adapter)
Dave Jones0566ee92014-02-13 14:45:52 -0500881{
882 struct bcm_ioctl_buffer IoBuffer;
883 PVOID pvBuffer = NULL;
884 INT Status;
885
886 /* Copy Ioctl Buffer structure */
887 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
888 return -EFAULT;
889
890 if (IoBuffer.InputLength < sizeof(struct bcm_link_request))
891 return -EINVAL;
892
893 if (IoBuffer.InputLength > MAX_CNTL_PKT_SIZE)
894 return -EINVAL;
895
896 pvBuffer = memdup_user(IoBuffer.InputBuffer,
897 IoBuffer.InputLength);
898 if (IS_ERR(pvBuffer))
899 return PTR_ERR(pvBuffer);
900
901 down(&Adapter->LowPowerModeSync);
Matthias Beyer22840ad2014-05-22 12:17:25 +0200902 Status = wait_event_interruptible_timeout(
903 Adapter->lowpower_mode_wait_queue,
904 !Adapter->bPreparingForLowPowerMode,
905 (1 * HZ));
906
Dave Jones0566ee92014-02-13 14:45:52 -0500907 if (Status == -ERESTARTSYS)
908 goto cntrlEnd;
909
910 if (Adapter->bPreparingForLowPowerMode) {
911 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
912 "Preparing Idle Mode is still True - Hence Rejecting control message\n");
913 Status = STATUS_FAILURE;
914 goto cntrlEnd;
915 }
916 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
917
918cntrlEnd:
919 up(&Adapter->LowPowerModeSync);
920 kfree(pvBuffer);
921 return Status;
922}
923
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200924static int bcm_char_ioctl_buffer_download_start(
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200925 struct bcm_mini_adapter *Adapter)
Dave Jones79f99492014-02-13 14:45:57 -0500926{
927 INT Status;
928
929 if (down_trylock(&Adapter->NVMRdmWrmLock)) {
930 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
931 "IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
932 return -EACCES;
933 }
934
935 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200936 "Starting the firmware download PID =0x%x!!!!\n",
937 current->pid);
Dave Jones79f99492014-02-13 14:45:57 -0500938
939 if (down_trylock(&Adapter->fw_download_sema))
940 return -EBUSY;
941
942 Adapter->bBinDownloaded = false;
943 Adapter->fw_download_process_pid = current->pid;
944 Adapter->bCfgDownloaded = false;
945 Adapter->fw_download_done = false;
946 netif_carrier_off(Adapter->dev);
947 netif_stop_queue(Adapter->dev);
948 Status = reset_card_proc(Adapter);
949 if (Status) {
950 pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
951 up(&Adapter->fw_download_sema);
952 up(&Adapter->NVMRdmWrmLock);
953 return Status;
954 }
955 mdelay(10);
956
957 up(&Adapter->NVMRdmWrmLock);
958 return Status;
959}
960
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200961static int bcm_char_ioctl_buffer_download(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +0200962 struct bcm_mini_adapter *Adapter)
Dave Jonesd9db71b2014-02-13 14:46:02 -0500963{
964 struct bcm_firmware_info *psFwInfo = NULL;
965 struct bcm_ioctl_buffer IoBuffer;
966 INT Status;
967
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200968 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
969 "Starting the firmware download PID =0x%x!!!!\n", current->pid);
Dave Jonesd9db71b2014-02-13 14:46:02 -0500970
971 if (!down_trylock(&Adapter->fw_download_sema)) {
972 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
973 "Invalid way to download buffer. Use Start and then call this!!!\n");
974 up(&Adapter->fw_download_sema);
975 return -EINVAL;
976 }
977
978 /* Copy Ioctl Buffer structure */
979 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
980 up(&Adapter->fw_download_sema);
981 return -EFAULT;
982 }
983
984 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
985 "Length for FW DLD is : %lx\n", IoBuffer.InputLength);
986
987 if (IoBuffer.InputLength > sizeof(struct bcm_firmware_info)) {
988 up(&Adapter->fw_download_sema);
989 return -EINVAL;
990 }
991
992 psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
993 if (!psFwInfo) {
994 up(&Adapter->fw_download_sema);
995 return -ENOMEM;
996 }
997
Ebru Akagunduz18e26b32014-03-13 10:34:19 +0200998 if (copy_from_user(psFwInfo, IoBuffer.InputBuffer,
999 IoBuffer.InputLength)) {
Dave Jonesd9db71b2014-02-13 14:46:02 -05001000 up(&Adapter->fw_download_sema);
1001 kfree(psFwInfo);
1002 return -EFAULT;
1003 }
1004
1005 if (!psFwInfo->pvMappedFirmwareAddress ||
1006 (psFwInfo->u32FirmwareLength == 0)) {
1007
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001008 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1009 "Something else is wrong %lu\n",
Dave Jonesd9db71b2014-02-13 14:46:02 -05001010 psFwInfo->u32FirmwareLength);
1011 up(&Adapter->fw_download_sema);
1012 kfree(psFwInfo);
1013 Status = -EINVAL;
1014 return Status;
1015 }
1016
1017 Status = bcm_ioctl_fw_download(Adapter, psFwInfo);
1018
1019 if (Status != STATUS_SUCCESS) {
1020 if (psFwInfo->u32StartingAddress == CONFIG_BEGIN_ADDR)
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001021 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1022 "IOCTL: Configuration File Upload Failed\n");
Dave Jonesd9db71b2014-02-13 14:46:02 -05001023 else
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001024 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1025 "IOCTL: Firmware File Upload Failed\n");
Dave Jonesd9db71b2014-02-13 14:46:02 -05001026
1027 /* up(&Adapter->fw_download_sema); */
1028
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001029 if (Adapter->LEDInfo.led_thread_running &
1030 BCM_LED_THREAD_RUNNING_ACTIVELY) {
Dave Jonesd9db71b2014-02-13 14:46:02 -05001031 Adapter->DriverState = DRIVER_INIT;
1032 Adapter->LEDInfo.bLedInitDone = false;
1033 wake_up(&Adapter->LEDInfo.notify_led_event);
1034 }
1035 }
1036
1037 if (Status != STATUS_SUCCESS)
1038 up(&Adapter->fw_download_sema);
1039
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001040 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL,
1041 "IOCTL: Firmware File Uploaded\n");
Dave Jonesd9db71b2014-02-13 14:46:02 -05001042 kfree(psFwInfo);
1043 return Status;
1044}
1045
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001046static int bcm_char_ioctl_buffer_download_stop(void __user *argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001047 struct bcm_mini_adapter *Adapter)
Dave Jones49444b52014-02-13 14:46:07 -05001048{
1049 INT Status;
1050 int timeout = 0;
1051
1052 if (!down_trylock(&Adapter->fw_download_sema)) {
1053 up(&Adapter->fw_download_sema);
1054 return -EINVAL;
1055 }
1056
1057 if (down_trylock(&Adapter->NVMRdmWrmLock)) {
1058 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1059 "FW download blocked as EEPROM Read/Write is in progress\n");
1060 up(&Adapter->fw_download_sema);
1061 return -EACCES;
1062 }
1063
1064 Adapter->bBinDownloaded = TRUE;
1065 Adapter->bCfgDownloaded = TRUE;
1066 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
1067 Adapter->CurrNumRecvDescs = 0;
1068 Adapter->downloadDDR = 0;
1069
1070 /* setting the Mips to Run */
1071 Status = run_card_proc(Adapter);
1072
1073 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001074 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1075 "Firm Download Failed\n");
Dave Jones49444b52014-02-13 14:46:07 -05001076 up(&Adapter->fw_download_sema);
1077 up(&Adapter->NVMRdmWrmLock);
1078 return Status;
1079 } else {
1080 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
1081 DBG_LVL_ALL, "Firm Download Over...\n");
1082 }
1083
1084 mdelay(10);
1085
1086 /* Wait for MailBox Interrupt */
1087 if (StartInterruptUrb((struct bcm_interface_adapter *)Adapter->pvInterfaceAdapter))
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001088 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1089 "Unable to send interrupt...\n");
Dave Jones49444b52014-02-13 14:46:07 -05001090
1091 timeout = 5*HZ;
1092 Adapter->waiting_to_fw_download_done = false;
1093 wait_event_timeout(Adapter->ioctl_fw_dnld_wait_queue,
1094 Adapter->waiting_to_fw_download_done, timeout);
1095 Adapter->fw_download_process_pid = INVALID_PID;
1096 Adapter->fw_download_done = TRUE;
1097 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
1098 Adapter->CurrNumRecvDescs = 0;
1099 Adapter->PrevNumRecvDescs = 0;
1100 atomic_set(&Adapter->cntrlpktCnt, 0);
1101 Adapter->LinkUpStatus = 0;
1102 Adapter->LinkStatus = 0;
1103
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001104 if (Adapter->LEDInfo.led_thread_running &
1105 BCM_LED_THREAD_RUNNING_ACTIVELY) {
Dave Jones49444b52014-02-13 14:46:07 -05001106 Adapter->DriverState = FW_DOWNLOAD_DONE;
1107 wake_up(&Adapter->LEDInfo.notify_led_event);
1108 }
1109
1110 if (!timeout)
1111 Status = -ENODEV;
1112
1113 up(&Adapter->fw_download_sema);
1114 up(&Adapter->NVMRdmWrmLock);
1115 return Status;
1116}
1117
Dave Jones6e5781c2014-02-13 14:46:12 -05001118static int bcm_char_ioctl_chip_reset(struct bcm_mini_adapter *Adapter)
1119{
1120 INT Status;
1121 INT NVMAccess;
1122
1123 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1124 if (NVMAccess) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001125 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1126 " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
Dave Jones6e5781c2014-02-13 14:46:12 -05001127 return -EACCES;
1128 }
1129
1130 down(&Adapter->RxAppControlQueuelock);
1131 Status = reset_card_proc(Adapter);
1132 flushAllAppQ();
1133 up(&Adapter->RxAppControlQueuelock);
1134 up(&Adapter->NVMRdmWrmLock);
1135 ResetCounters(Adapter);
1136 return Status;
1137}
1138
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001139static int bcm_char_ioctl_qos_threshold(ULONG arg,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001140 struct bcm_mini_adapter *Adapter)
Dave Jones645926b2014-02-13 14:46:17 -05001141{
1142 USHORT uiLoopIndex;
1143
1144 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
1145 if (get_user(Adapter->PackInfo[uiLoopIndex].uiThreshold,
1146 (unsigned long __user *)arg)) {
1147 return -EFAULT;
1148 }
1149 }
1150 return 0;
1151}
1152
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001153static int bcm_char_ioctl_switch_transfer_mode(void __user *argp,
1154 struct bcm_mini_adapter *Adapter)
Dave Jonesa0ad9612014-02-13 14:46:22 -05001155{
1156 UINT uiData = 0;
1157
1158 if (copy_from_user(&uiData, argp, sizeof(UINT)))
1159 return -EFAULT;
1160
1161 if (uiData) {
1162 /* Allow All Packets */
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001163 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1164 "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
Dave Jonesa0ad9612014-02-13 14:46:22 -05001165 Adapter->TransferMode = ETH_PACKET_TUNNELING_MODE;
1166 } else {
1167 /* Allow IP only Packets */
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001168 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1169 "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
Dave Jonesa0ad9612014-02-13 14:46:22 -05001170 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
1171 }
1172 return STATUS_SUCCESS;
1173}
1174
Dave Jonesdfb442d2014-02-13 14:46:27 -05001175static int bcm_char_ioctl_get_driver_version(void __user *argp)
1176{
1177 struct bcm_ioctl_buffer IoBuffer;
1178 ulong len;
1179
1180 /* Copy Ioctl Buffer structure */
1181 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1182 return -EFAULT;
1183
1184 len = min_t(ulong, IoBuffer.OutputLength, strlen(DRV_VERSION) + 1);
1185
1186 if (copy_to_user(IoBuffer.OutputBuffer, DRV_VERSION, len))
1187 return -EFAULT;
1188
1189 return STATUS_SUCCESS;
1190}
1191
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001192static int bcm_char_ioctl_get_current_status(void __user *argp,
1193 struct bcm_mini_adapter *Adapter)
Dave Jones9c434f82014-02-13 14:46:32 -05001194{
1195 struct bcm_link_state link_state;
1196 struct bcm_ioctl_buffer IoBuffer;
1197
1198 /* Copy Ioctl Buffer structure */
1199 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001200 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1201 "copy_from_user failed..\n");
Dave Jones9c434f82014-02-13 14:46:32 -05001202 return -EFAULT;
1203 }
1204
1205 if (IoBuffer.OutputLength != sizeof(link_state))
1206 return -EINVAL;
1207
1208 memset(&link_state, 0, sizeof(link_state));
1209 link_state.bIdleMode = Adapter->IdleMode;
1210 link_state.bShutdownMode = Adapter->bShutStatus;
1211 link_state.ucLinkStatus = Adapter->LinkStatus;
1212
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001213 if (copy_to_user(IoBuffer.OutputBuffer, &link_state, min_t(size_t,
1214 sizeof(link_state), IoBuffer.OutputLength))) {
1215 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1216 "Copy_to_user Failed..\n");
Dave Jones9c434f82014-02-13 14:46:32 -05001217 return -EFAULT;
1218 }
1219 return STATUS_SUCCESS;
1220}
1221
Dave Jones0566ee92014-02-13 14:45:52 -05001222
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001223static int bcm_char_ioctl_set_mac_tracing(void __user *argp,
1224 struct bcm_mini_adapter *Adapter)
Dave Jonescfd01352014-02-13 14:46:37 -05001225{
1226 struct bcm_ioctl_buffer IoBuffer;
1227 UINT tracing_flag;
1228
1229 /* copy ioctl Buffer structure */
1230 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1231 return -EFAULT;
1232
1233 if (copy_from_user(&tracing_flag, IoBuffer.InputBuffer, sizeof(UINT)))
1234 return -EFAULT;
1235
1236 if (tracing_flag)
1237 Adapter->pTarangs->MacTracingEnabled = TRUE;
1238 else
1239 Adapter->pTarangs->MacTracingEnabled = false;
1240
1241 return STATUS_SUCCESS;
1242}
1243
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001244static int bcm_char_ioctl_get_dsx_indication(void __user *argp,
1245 struct bcm_mini_adapter *Adapter)
Dave Jones4d476af2014-02-13 14:46:42 -05001246{
1247 struct bcm_ioctl_buffer IoBuffer;
1248 ULONG ulSFId = 0;
1249
1250 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1251 return -EFAULT;
1252
1253 if (IoBuffer.OutputLength < sizeof(struct bcm_add_indication_alt)) {
1254 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001255 "Mismatch req: %lx needed is =0x%zx!!!",
1256 IoBuffer.OutputLength,
1257 sizeof(struct bcm_add_indication_alt));
Dave Jones4d476af2014-02-13 14:46:42 -05001258 return -EINVAL;
1259 }
1260
1261 if (copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
1262 return -EFAULT;
1263
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001264 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1265 "Get DSX Data SF ID is =%lx\n", ulSFId);
Dave Jones4d476af2014-02-13 14:46:42 -05001266 get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
1267 return STATUS_SUCCESS;
1268}
1269
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001270static int bcm_char_ioctl_get_host_mibs(void __user *argp,
1271 struct bcm_mini_adapter *Adapter, struct bcm_tarang_data *pTarang)
Dave Jonesdb9a4dc2014-02-13 14:46:47 -05001272{
1273 struct bcm_ioctl_buffer IoBuffer;
1274 INT Status = STATUS_FAILURE;
1275 PVOID temp_buff;
1276
1277 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1278 return -EFAULT;
1279
1280 if (IoBuffer.OutputLength != sizeof(struct bcm_host_stats_mibs)) {
1281 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001282 "Length Check failed %lu %zd\n", IoBuffer.OutputLength,
1283 sizeof(struct bcm_host_stats_mibs));
Dave Jonesdb9a4dc2014-02-13 14:46:47 -05001284 return -EINVAL;
1285 }
1286
1287 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1288 temp_buff = kzalloc(sizeof(struct bcm_host_stats_mibs), GFP_KERNEL);
1289 if (!temp_buff)
1290 return STATUS_FAILURE;
1291
1292 Status = ProcessGetHostMibs(Adapter, temp_buff);
1293 GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
1294
1295 if (Status != STATUS_FAILURE) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001296 if (copy_to_user(IoBuffer.OutputBuffer, temp_buff,
1297 sizeof(struct bcm_host_stats_mibs))) {
Dave Jonesdb9a4dc2014-02-13 14:46:47 -05001298 kfree(temp_buff);
1299 return -EFAULT;
1300 }
1301 }
1302
1303 kfree(temp_buff);
1304 return Status;
1305}
1306
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001307static int bcm_char_ioctl_bulk_wrm(void __user *argp,
1308 struct bcm_mini_adapter *Adapter, UINT cmd)
Dave Jonesb32384b2014-02-13 14:46:52 -05001309{
1310 struct bcm_bulk_wrm_buffer *pBulkBuffer;
1311 struct bcm_ioctl_buffer IoBuffer;
1312 UINT uiTempVar = 0;
1313 INT Status = STATUS_FAILURE;
1314 PCHAR pvBuffer = NULL;
1315
1316 if ((Adapter->IdleMode == TRUE) ||
1317 (Adapter->bShutStatus == TRUE) ||
1318 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1319
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001320 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,
1321 "Device in Idle/Shutdown Mode, Blocking Wrms\n");
Dave Jonesb32384b2014-02-13 14:46:52 -05001322 return -EACCES;
1323 }
1324
1325 /* Copy Ioctl Buffer structure */
1326 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1327 return -EFAULT;
1328
1329 if (IoBuffer.InputLength < sizeof(ULONG) * 2)
1330 return -EINVAL;
1331
1332 pvBuffer = memdup_user(IoBuffer.InputBuffer,
1333 IoBuffer.InputLength);
1334 if (IS_ERR(pvBuffer))
1335 return PTR_ERR(pvBuffer);
1336
1337 pBulkBuffer = (struct bcm_bulk_wrm_buffer *)pvBuffer;
1338
1339 if (((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1340 ((ULONG)pBulkBuffer->Register & 0x3)) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001341 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,
1342 "WRM Done On invalid Address : %x Access Denied.\n",
1343 (int)pBulkBuffer->Register);
Dave Jonesb32384b2014-02-13 14:46:52 -05001344 kfree(pvBuffer);
1345 return -EINVAL;
1346 }
1347
1348 uiTempVar = pBulkBuffer->Register & EEPROM_REJECT_MASK;
1349 if (!((Adapter->pstargetparams->m_u32Customize)&VSG_MODE) &&
1350 ((uiTempVar == EEPROM_REJECT_REG_1) ||
1351 (uiTempVar == EEPROM_REJECT_REG_2) ||
1352 (uiTempVar == EEPROM_REJECT_REG_3) ||
1353 (uiTempVar == EEPROM_REJECT_REG_4)) &&
1354 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
1355
1356 kfree(pvBuffer);
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001357 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,
1358 "EEPROM Access Denied, not in VSG Mode\n");
Dave Jonesb32384b2014-02-13 14:46:52 -05001359 return -EFAULT;
1360 }
1361
1362 if (pBulkBuffer->SwapEndian == false)
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001363 Status = wrmWithLock(Adapter, (UINT)pBulkBuffer->Register,
1364 (PCHAR)pBulkBuffer->Values,
1365 IoBuffer.InputLength - 2*sizeof(ULONG));
Dave Jonesb32384b2014-02-13 14:46:52 -05001366 else
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001367 Status = wrmaltWithLock(Adapter, (UINT)pBulkBuffer->Register,
1368 (PUINT)pBulkBuffer->Values,
1369 IoBuffer.InputLength - 2*sizeof(ULONG));
Dave Jonesb32384b2014-02-13 14:46:52 -05001370
1371 if (Status != STATUS_SUCCESS)
1372 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1373
1374 kfree(pvBuffer);
1375 return Status;
1376}
1377
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001378static int bcm_char_ioctl_get_nvm_size(void __user *argp,
1379 struct bcm_mini_adapter *Adapter)
Dave Jones1c55e382014-02-13 14:46:57 -05001380{
1381 struct bcm_ioctl_buffer IoBuffer;
1382
1383 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1384 return -EFAULT;
1385
1386 if (Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001387 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize,
1388 sizeof(UINT)))
Dave Jones1c55e382014-02-13 14:46:57 -05001389 return -EFAULT;
1390 }
1391
1392 return STATUS_SUCCESS;
1393}
Dave Jonescfd01352014-02-13 14:46:37 -05001394
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001395static int bcm_char_ioctl_cal_init(void __user *argp,
1396 struct bcm_mini_adapter *Adapter)
Dave Jones1e1ee182014-02-13 14:47:02 -05001397{
1398 struct bcm_ioctl_buffer IoBuffer;
1399 UINT uiSectorSize = 0;
1400 INT Status = STATUS_FAILURE;
1401
1402 if (Adapter->eNVMType == NVM_FLASH) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001403 if (copy_from_user(&IoBuffer, argp,
1404 sizeof(struct bcm_ioctl_buffer)))
Dave Jones1e1ee182014-02-13 14:47:02 -05001405 return -EFAULT;
1406
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001407 if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer,
1408 sizeof(UINT)))
Dave Jones1e1ee182014-02-13 14:47:02 -05001409 return -EFAULT;
1410
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001411 if ((uiSectorSize < MIN_SECTOR_SIZE) ||
1412 (uiSectorSize > MAX_SECTOR_SIZE)) {
1413 if (copy_to_user(IoBuffer.OutputBuffer,
1414 &Adapter->uiSectorSize, sizeof(UINT)))
Dave Jones1e1ee182014-02-13 14:47:02 -05001415 return -EFAULT;
1416 } else {
1417 if (IsFlash2x(Adapter)) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001418 if (copy_to_user(IoBuffer.OutputBuffer,
1419 &Adapter->uiSectorSize, sizeof(UINT)))
Dave Jones1e1ee182014-02-13 14:47:02 -05001420 return -EFAULT;
1421 } else {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001422 if ((TRUE == Adapter->bShutStatus) ||
1423 (TRUE == Adapter->IdleMode)) {
1424 BCM_DEBUG_PRINT(Adapter,
1425 DBG_TYPE_PRINTK, 0, 0,
1426 "Device is in Idle/Shutdown Mode\n");
Dave Jones1e1ee182014-02-13 14:47:02 -05001427 return -EACCES;
1428 }
1429
1430 Adapter->uiSectorSize = uiSectorSize;
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001431 BcmUpdateSectorSize(Adapter,
1432 Adapter->uiSectorSize);
Dave Jones1e1ee182014-02-13 14:47:02 -05001433 }
1434 }
1435 Status = STATUS_SUCCESS;
1436 } else {
1437 Status = STATUS_FAILURE;
1438 }
1439 return Status;
1440}
1441
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001442static int bcm_char_ioctl_set_debug(void __user *argp,
1443 struct bcm_mini_adapter *Adapter)
Dave Jones085ca022014-02-13 14:47:08 -05001444{
1445#ifdef DEBUG
1446 struct bcm_ioctl_buffer IoBuffer;
1447 struct bcm_user_debug_state sUserDebugState;
1448
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001449 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1450 "In SET_DEBUG ioctl\n");
Dave Jones085ca022014-02-13 14:47:08 -05001451 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1452 return -EFAULT;
1453
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001454 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer,
1455 sizeof(struct bcm_user_debug_state)))
Dave Jones085ca022014-02-13 14:47:08 -05001456 return -EFAULT;
1457
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001458 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,
1459 "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
Dave Jones085ca022014-02-13 14:47:08 -05001460 sUserDebugState.OnOff, sUserDebugState.Type);
1461 /* sUserDebugState.Subtype <<= 1; */
1462 sUserDebugState.Subtype = 1 << sUserDebugState.Subtype;
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001463 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,
1464 "actual Subtype=0x%x\n", sUserDebugState.Subtype);
Dave Jones085ca022014-02-13 14:47:08 -05001465
1466 /* Update new 'DebugState' in the Adapter */
1467 Adapter->stDebugState.type |= sUserDebugState.Type;
1468 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1469 * Valid indexes in 'subtype' array: 1,2,4,8
1470 * corresponding to valid Type values. Hence we can use the 'Type' field
1471 * as the index value, ignoring the array entries 0,3,5,6,7 !
1472 */
1473 if (sUserDebugState.OnOff)
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001474 Adapter->stDebugState.subtype[sUserDebugState.Type] |=
1475 sUserDebugState.Subtype;
Dave Jones085ca022014-02-13 14:47:08 -05001476 else
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001477 Adapter->stDebugState.subtype[sUserDebugState.Type] &=
1478 ~sUserDebugState.Subtype;
Dave Jones085ca022014-02-13 14:47:08 -05001479
1480 BCM_SHOW_DEBUG_BITMAP(Adapter);
1481#endif
1482 return STATUS_SUCCESS;
1483}
1484
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001485static int bcm_char_ioctl_nvm_rw(void __user *argp,
1486 struct bcm_mini_adapter *Adapter, UINT cmd)
Dave Jones5be531c2014-02-13 14:47:13 -05001487{
1488 struct bcm_nvm_readwrite stNVMReadWrite;
1489 struct timeval tv0, tv1;
1490 struct bcm_ioctl_buffer IoBuffer;
1491 PUCHAR pReadData = NULL;
Dave Jones5be531c2014-02-13 14:47:13 -05001492 INT Status = STATUS_FAILURE;
1493
1494 memset(&tv0, 0, sizeof(struct timeval));
1495 memset(&tv1, 0, sizeof(struct timeval));
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001496 if ((Adapter->eNVMType == NVM_FLASH) &&
1497 (Adapter->uiFlashLayoutMajorVersion == 0)) {
1498 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1499 "The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
Dave Jones5be531c2014-02-13 14:47:13 -05001500 return -EFAULT;
1501 }
1502
1503 if (IsFlash2x(Adapter)) {
1504 if ((Adapter->eActiveDSD != DSD0) &&
1505 (Adapter->eActiveDSD != DSD1) &&
1506 (Adapter->eActiveDSD != DSD2)) {
1507
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001508 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1509 "No DSD is active..hence NVM Command is blocked");
Dave Jones5be531c2014-02-13 14:47:13 -05001510 return STATUS_FAILURE;
1511 }
1512 }
1513
1514 /* Copy Ioctl Buffer structure */
1515 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1516 return -EFAULT;
1517
1518 if (copy_from_user(&stNVMReadWrite,
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001519 (IOCTL_BCM_NVM_READ == cmd) ?
1520 IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
Dave Jones5be531c2014-02-13 14:47:13 -05001521 sizeof(struct bcm_nvm_readwrite)))
1522 return -EFAULT;
1523
1524 /*
1525 * Deny the access if the offset crosses the cal area limit.
1526 */
1527 if (stNVMReadWrite.uiNumBytes > Adapter->uiNVMDSDSize)
1528 return STATUS_FAILURE;
1529
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001530 if (stNVMReadWrite.uiOffset >
Ebru Akagunduz7d057e72014-03-13 10:34:20 +02001531 Adapter->uiNVMDSDSize - stNVMReadWrite.uiNumBytes)
Dave Jones5be531c2014-02-13 14:47:13 -05001532 return STATUS_FAILURE;
Dave Jones5be531c2014-02-13 14:47:13 -05001533
1534 pReadData = memdup_user(stNVMReadWrite.pBuffer,
1535 stNVMReadWrite.uiNumBytes);
1536 if (IS_ERR(pReadData))
1537 return PTR_ERR(pReadData);
1538
1539 do_gettimeofday(&tv0);
1540 if (IOCTL_BCM_NVM_READ == cmd) {
Matthias Beyer8224ac22014-05-22 12:17:26 +02001541 int ret = bcm_handle_nvm_read_cmd(Adapter, pReadData,
1542 &stNVMReadWrite);
1543 if (ret != STATUS_SUCCESS)
1544 return ret;
Dave Jones5be531c2014-02-13 14:47:13 -05001545 } else {
1546 down(&Adapter->NVMRdmWrmLock);
1547
1548 if ((Adapter->IdleMode == TRUE) ||
1549 (Adapter->bShutStatus == TRUE) ||
1550 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1551
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001552 BCM_DEBUG_PRINT(Adapter,
1553 DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1554 "Device is in Idle/Shutdown Mode\n");
Dave Jones5be531c2014-02-13 14:47:13 -05001555 up(&Adapter->NVMRdmWrmLock);
1556 kfree(pReadData);
1557 return -EACCES;
1558 }
1559
1560 Adapter->bHeaderChangeAllowed = TRUE;
1561 if (IsFlash2x(Adapter)) {
Matthias Beyere5c34a12014-05-22 12:17:27 +02001562 int ret = handle_flash2x_adapter(Adapter,
1563 pReadData,
1564 &stNVMReadWrite);
1565 if (ret != STATUS_SUCCESS)
1566 return ret;
Dave Jones5be531c2014-02-13 14:47:13 -05001567 }
1568
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001569 Status = BeceemNVMWrite(Adapter, (PUINT)pReadData,
1570 stNVMReadWrite.uiOffset, stNVMReadWrite.uiNumBytes,
1571 stNVMReadWrite.bVerify);
Dave Jones5be531c2014-02-13 14:47:13 -05001572 if (IsFlash2x(Adapter))
1573 BcmFlash2xWriteSig(Adapter, Adapter->eActiveDSD);
1574
1575 Adapter->bHeaderChangeAllowed = false;
1576
1577 up(&Adapter->NVMRdmWrmLock);
1578
1579 if (Status != STATUS_SUCCESS) {
1580 kfree(pReadData);
1581 return Status;
1582 }
1583 }
1584
1585 do_gettimeofday(&tv1);
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001586 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1587 " timetaken by Write/read :%ld msec\n",
Matthias Beyer22840ad2014-05-22 12:17:25 +02001588 (tv1.tv_sec - tv0.tv_sec)*1000 +
1589 (tv1.tv_usec - tv0.tv_usec)/1000);
Dave Jones5be531c2014-02-13 14:47:13 -05001590
1591 kfree(pReadData);
1592 return STATUS_SUCCESS;
1593}
1594
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001595static int bcm_char_ioctl_flash2x_section_read(void __user *argp,
1596 struct bcm_mini_adapter *Adapter)
Dave Jonesb4571fc2014-02-13 14:47:18 -05001597{
1598 struct bcm_flash2x_readwrite sFlash2xRead = {0};
1599 struct bcm_ioctl_buffer IoBuffer;
1600 PUCHAR pReadBuff = NULL;
1601 UINT NOB = 0;
1602 UINT BuffSize = 0;
1603 UINT ReadBytes = 0;
1604 UINT ReadOffset = 0;
1605 INT Status = STATUS_FAILURE;
1606 void __user *OutPutBuff;
1607
1608 if (IsFlash2x(Adapter) != TRUE) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001609 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1610 "Flash Does not have 2.x map");
Dave Jonesb4571fc2014-02-13 14:47:18 -05001611 return -EINVAL;
1612 }
1613
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001614 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
1615 DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
Dave Jonesb4571fc2014-02-13 14:47:18 -05001616 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1617 return -EFAULT;
1618
1619 /* Reading FLASH 2.x READ structure */
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001620 if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer,
1621 sizeof(struct bcm_flash2x_readwrite)))
Dave Jonesb4571fc2014-02-13 14:47:18 -05001622 return -EFAULT;
1623
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001624 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001625 "\nsFlash2xRead.Section :%x",
1626 sFlash2xRead.Section);
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001627 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001628 "\nsFlash2xRead.offset :%x",
1629 sFlash2xRead.offset);
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001630 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001631 "\nsFlash2xRead.numOfBytes :%x",
1632 sFlash2xRead.numOfBytes);
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001633 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001634 "\nsFlash2xRead.bVerify :%x\n",
1635 sFlash2xRead.bVerify);
Dave Jonesb4571fc2014-02-13 14:47:18 -05001636
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001637 /* This was internal to driver for raw read.
1638 * now it has ben exposed to user space app.
1639 */
Dave Jonesb4571fc2014-02-13 14:47:18 -05001640 if (validateFlash2xReadWrite(Adapter, &sFlash2xRead) == false)
1641 return STATUS_FAILURE;
1642
1643 NOB = sFlash2xRead.numOfBytes;
1644 if (NOB > Adapter->uiSectorSize)
1645 BuffSize = Adapter->uiSectorSize;
1646 else
1647 BuffSize = NOB;
1648
1649 ReadOffset = sFlash2xRead.offset;
1650 OutPutBuff = IoBuffer.OutputBuffer;
Sachin Kamat806c4872014-05-29 17:05:20 +05301651 pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
Dave Jonesb4571fc2014-02-13 14:47:18 -05001652
1653 if (pReadBuff == NULL) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001654 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001655 "Memory allocation failed for Flash 2.x Read Structure");
Dave Jonesb4571fc2014-02-13 14:47:18 -05001656 return -ENOMEM;
1657 }
1658 down(&Adapter->NVMRdmWrmLock);
1659
1660 if ((Adapter->IdleMode == TRUE) ||
1661 (Adapter->bShutStatus == TRUE) ||
1662 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1663
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001664 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001665 DBG_LVL_ALL,
1666 "Device is in Idle/Shutdown Mode\n");
Dave Jonesb4571fc2014-02-13 14:47:18 -05001667 up(&Adapter->NVMRdmWrmLock);
1668 kfree(pReadBuff);
1669 return -EACCES;
1670 }
1671
1672 while (NOB) {
1673 if (NOB > Adapter->uiSectorSize)
1674 ReadBytes = Adapter->uiSectorSize;
1675 else
1676 ReadBytes = NOB;
1677
1678 /* Reading the data from Flash 2.x */
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001679 Status = BcmFlash2xBulkRead(Adapter, (PUINT)pReadBuff,
1680 sFlash2xRead.Section, ReadOffset, ReadBytes);
Dave Jonesb4571fc2014-02-13 14:47:18 -05001681 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001682 BCM_DEBUG_PRINT(Adapter,
1683 DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1684 "Flash 2x read err with Status :%d",
1685 Status);
Dave Jonesb4571fc2014-02-13 14:47:18 -05001686 break;
1687 }
1688
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001689 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
1690 DBG_LVL_ALL, pReadBuff, ReadBytes);
Dave Jonesb4571fc2014-02-13 14:47:18 -05001691
1692 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
1693 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001694 BCM_DEBUG_PRINT(Adapter,
1695 DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1696 "Copy to use failed with status :%d", Status);
Dave Jonesb4571fc2014-02-13 14:47:18 -05001697 up(&Adapter->NVMRdmWrmLock);
1698 kfree(pReadBuff);
1699 return -EFAULT;
1700 }
1701 NOB = NOB - ReadBytes;
1702 if (NOB) {
1703 ReadOffset = ReadOffset + ReadBytes;
1704 OutPutBuff = OutPutBuff + ReadBytes;
1705 }
1706 }
1707
1708 up(&Adapter->NVMRdmWrmLock);
1709 kfree(pReadBuff);
1710 return Status;
1711}
1712
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001713static int bcm_char_ioctl_flash2x_section_write(void __user *argp,
1714 struct bcm_mini_adapter *Adapter)
Dave Jones174b3b42014-02-13 14:47:23 -05001715{
1716 struct bcm_flash2x_readwrite sFlash2xWrite = {0};
1717 struct bcm_ioctl_buffer IoBuffer;
1718 PUCHAR pWriteBuff;
1719 void __user *InputAddr;
1720 UINT NOB = 0;
1721 UINT BuffSize = 0;
1722 UINT WriteOffset = 0;
1723 UINT WriteBytes = 0;
1724 INT Status = STATUS_FAILURE;
1725
1726 if (IsFlash2x(Adapter) != TRUE) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1728 "Flash Does not have 2.x map");
Dave Jones174b3b42014-02-13 14:47:23 -05001729 return -EINVAL;
1730 }
1731
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001732 /* First make this False so that we can enable the Sector
1733 * Permission Check in BeceemFlashBulkWrite
1734 */
Dave Jones174b3b42014-02-13 14:47:23 -05001735 Adapter->bAllDSDWriteAllow = false;
1736
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1738 "IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
Dave Jones174b3b42014-02-13 14:47:23 -05001739
1740 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1741 return -EFAULT;
1742
1743 /* Reading FLASH 2.x READ structure */
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001744 if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer,
1745 sizeof(struct bcm_flash2x_readwrite)))
Dave Jones174b3b42014-02-13 14:47:23 -05001746 return -EFAULT;
1747
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1749 "\nsFlash2xRead.Section :%x", sFlash2xWrite.Section);
1750 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1751 "\nsFlash2xRead.offset :%d", sFlash2xWrite.offset);
1752 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1753 "\nsFlash2xRead.numOfBytes :%x", sFlash2xWrite.numOfBytes);
1754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1755 "\nsFlash2xRead.bVerify :%x\n", sFlash2xWrite.bVerify);
Dave Jones174b3b42014-02-13 14:47:23 -05001756
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001757 if ((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1)
1758 && (sFlash2xWrite.Section != VSA2)) {
1759 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1760 "Only VSA write is allowed");
Dave Jones174b3b42014-02-13 14:47:23 -05001761 return -EINVAL;
1762 }
1763
1764 if (validateFlash2xReadWrite(Adapter, &sFlash2xWrite) == false)
1765 return STATUS_FAILURE;
1766
1767 InputAddr = sFlash2xWrite.pDataBuff;
1768 WriteOffset = sFlash2xWrite.offset;
1769 NOB = sFlash2xWrite.numOfBytes;
1770
1771 if (NOB > Adapter->uiSectorSize)
1772 BuffSize = Adapter->uiSectorSize;
1773 else
1774 BuffSize = NOB;
1775
1776 pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
1777
1778 if (pWriteBuff == NULL)
1779 return -ENOMEM;
1780
1781 /* extracting the remainder of the given offset. */
1782 WriteBytes = Adapter->uiSectorSize;
Matthias Beyer22840ad2014-05-22 12:17:25 +02001783 if (WriteOffset % Adapter->uiSectorSize) {
1784 WriteBytes = Adapter->uiSectorSize -
1785 (WriteOffset % Adapter->uiSectorSize);
1786 }
Dave Jones174b3b42014-02-13 14:47:23 -05001787
1788 if (NOB < WriteBytes)
1789 WriteBytes = NOB;
1790
1791 down(&Adapter->NVMRdmWrmLock);
1792
1793 if ((Adapter->IdleMode == TRUE) ||
1794 (Adapter->bShutStatus == TRUE) ||
1795 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1796
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001797 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1798 "Device is in Idle/Shutdown Mode\n");
Dave Jones174b3b42014-02-13 14:47:23 -05001799 up(&Adapter->NVMRdmWrmLock);
1800 kfree(pWriteBuff);
1801 return -EACCES;
1802 }
1803
1804 BcmFlash2xCorruptSig(Adapter, sFlash2xWrite.Section);
1805 do {
1806 Status = copy_from_user(pWriteBuff, InputAddr, WriteBytes);
1807 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001808 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1809 "Copy to user failed with status :%d", Status);
Dave Jones174b3b42014-02-13 14:47:23 -05001810 up(&Adapter->NVMRdmWrmLock);
1811 kfree(pWriteBuff);
1812 return -EFAULT;
1813 }
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001814 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS,
1815 OSAL_DBG, DBG_LVL_ALL, pWriteBuff, WriteBytes);
Dave Jones174b3b42014-02-13 14:47:23 -05001816
1817 /* Writing the data from Flash 2.x */
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001818 Status = BcmFlash2xBulkWrite(Adapter, (PUINT)pWriteBuff,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001819 sFlash2xWrite.Section,
1820 WriteOffset,
1821 WriteBytes,
1822 sFlash2xWrite.bVerify);
Dave Jones174b3b42014-02-13 14:47:23 -05001823
1824 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001825 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1826 "Flash 2x read err with Status :%d", Status);
Dave Jones174b3b42014-02-13 14:47:23 -05001827 break;
1828 }
1829
1830 NOB = NOB - WriteBytes;
1831 if (NOB) {
1832 WriteOffset = WriteOffset + WriteBytes;
1833 InputAddr = InputAddr + WriteBytes;
1834 if (NOB > Adapter->uiSectorSize)
1835 WriteBytes = Adapter->uiSectorSize;
1836 else
1837 WriteBytes = NOB;
1838 }
1839 } while (NOB > 0);
1840
1841 BcmFlash2xWriteSig(Adapter, sFlash2xWrite.Section);
1842 up(&Adapter->NVMRdmWrmLock);
1843 kfree(pWriteBuff);
1844 return Status;
1845}
1846
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001847static int bcm_char_ioctl_flash2x_section_bitmap(void __user *argp,
1848 struct bcm_mini_adapter *Adapter)
Dave Jones338a5c42014-02-13 14:47:28 -05001849{
1850 struct bcm_flash2x_bitmap *psFlash2xBitMap;
1851 struct bcm_ioctl_buffer IoBuffer;
Dave Jones338a5c42014-02-13 14:47:28 -05001852
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001853BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1854 "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
Dave Jones338a5c42014-02-13 14:47:28 -05001855
1856 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1857 return -EFAULT;
1858
1859 if (IoBuffer.OutputLength != sizeof(struct bcm_flash2x_bitmap))
1860 return -EINVAL;
1861
Matthias Beyer22840ad2014-05-22 12:17:25 +02001862 psFlash2xBitMap = kzalloc(sizeof(struct bcm_flash2x_bitmap),
1863 GFP_KERNEL);
1864
Dave Jones338a5c42014-02-13 14:47:28 -05001865 if (psFlash2xBitMap == NULL) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001866 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1867 "Memory is not available");
Dave Jones338a5c42014-02-13 14:47:28 -05001868 return -ENOMEM;
1869 }
1870
1871 /* Reading the Flash Sectio Bit map */
1872 down(&Adapter->NVMRdmWrmLock);
1873
1874 if ((Adapter->IdleMode == TRUE) ||
1875 (Adapter->bShutStatus == TRUE) ||
1876 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1877
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001878 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1879 "Device is in Idle/Shutdown Mode\n");
Dave Jones338a5c42014-02-13 14:47:28 -05001880 up(&Adapter->NVMRdmWrmLock);
1881 kfree(psFlash2xBitMap);
1882 return -EACCES;
1883 }
1884
1885 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1886 up(&Adapter->NVMRdmWrmLock);
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001887 if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap,
1888 sizeof(struct bcm_flash2x_bitmap))) {
Dave Jones338a5c42014-02-13 14:47:28 -05001889 kfree(psFlash2xBitMap);
1890 return -EFAULT;
1891 }
1892
1893 kfree(psFlash2xBitMap);
Peter Senna Tschudin4764ca92014-05-26 16:08:50 +02001894 return STATUS_FAILURE;
Dave Jones338a5c42014-02-13 14:47:28 -05001895}
1896
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001897static int bcm_char_ioctl_set_active_section(void __user *argp,
1898 struct bcm_mini_adapter *Adapter)
Dave Jones9e0d6e12014-02-13 14:47:33 -05001899{
1900 enum bcm_flash2x_section_val eFlash2xSectionVal = 0;
1901 INT Status = STATUS_FAILURE;
1902 struct bcm_ioctl_buffer IoBuffer;
1903
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001904 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001905 "IOCTL_BCM_SET_ACTIVE_SECTION Called");
Dave Jones9e0d6e12014-02-13 14:47:33 -05001906
1907 if (IsFlash2x(Adapter) != TRUE) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001908 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001909 "Flash Does not have 2.x map");
Dave Jones9e0d6e12014-02-13 14:47:33 -05001910 return -EINVAL;
1911 }
1912
Matthias Beyer22840ad2014-05-22 12:17:25 +02001913 Status = copy_from_user(&IoBuffer, argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001914 sizeof(struct bcm_ioctl_buffer));
Dave Jones9e0d6e12014-02-13 14:47:33 -05001915 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001916 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001917 "Copy of IOCTL BUFFER failed");
Dave Jones9e0d6e12014-02-13 14:47:33 -05001918 return -EFAULT;
1919 }
1920
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001921 Status = copy_from_user(&eFlash2xSectionVal,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001922 IoBuffer.InputBuffer, sizeof(INT));
Dave Jones9e0d6e12014-02-13 14:47:33 -05001923 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001924 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1925 "Copy of flash section val failed");
Dave Jones9e0d6e12014-02-13 14:47:33 -05001926 return -EFAULT;
1927 }
1928
1929 down(&Adapter->NVMRdmWrmLock);
1930
1931 if ((Adapter->IdleMode == TRUE) ||
1932 (Adapter->bShutStatus == TRUE) ||
1933 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1934
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001935 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001936 "Device is in Idle/Shutdown Mode\n");
Dave Jones9e0d6e12014-02-13 14:47:33 -05001937 up(&Adapter->NVMRdmWrmLock);
1938 return -EACCES;
1939 }
1940
1941 Status = BcmSetActiveSection(Adapter, eFlash2xSectionVal);
1942 if (Status)
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001943 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001944 "Failed to make it's priority Highest. Status %d",
1945 Status);
Dave Jones9e0d6e12014-02-13 14:47:33 -05001946
1947 up(&Adapter->NVMRdmWrmLock);
1948
1949 return Status;
1950}
1951
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001952static int bcm_char_ioctl_copy_section(void __user *argp,
1953 struct bcm_mini_adapter *Adapter)
Dave Jones3e2aea52014-02-13 14:47:43 -05001954{
1955 struct bcm_flash2x_copy_section sCopySectStrut = {0};
1956 struct bcm_ioctl_buffer IoBuffer;
1957 INT Status = STATUS_SUCCESS;
1958
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001959 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001960 "IOCTL_BCM_COPY_SECTION Called");
Dave Jones3e2aea52014-02-13 14:47:43 -05001961
1962 Adapter->bAllDSDWriteAllow = false;
1963 if (IsFlash2x(Adapter) != TRUE) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001964 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001965 "Flash Does not have 2.x map");
Dave Jones3e2aea52014-02-13 14:47:43 -05001966 return -EINVAL;
1967 }
1968
Matthias Beyer22840ad2014-05-22 12:17:25 +02001969 Status = copy_from_user(&IoBuffer, argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001970 sizeof(struct bcm_ioctl_buffer));
Dave Jones3e2aea52014-02-13 14:47:43 -05001971 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001972 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001973 "Copy of IOCTL BUFFER failed Status :%d",
1974 Status);
Dave Jones3e2aea52014-02-13 14:47:43 -05001975 return -EFAULT;
1976 }
1977
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001978 Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001979 sizeof(struct bcm_flash2x_copy_section));
Dave Jones3e2aea52014-02-13 14:47:43 -05001980 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001981 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001982 "Copy of Copy_Section_Struct failed with Status :%d",
1983 Status);
Dave Jones3e2aea52014-02-13 14:47:43 -05001984 return -EFAULT;
1985 }
1986
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001987 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001988 "Source SEction :%x", sCopySectStrut.SrcSection);
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001989 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001990 "Destination SEction :%x", sCopySectStrut.DstSection);
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001991 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001992 "offset :%x", sCopySectStrut.offset);
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001993 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001994 "NOB :%x", sCopySectStrut.numOfBytes);
Dave Jones3e2aea52014-02-13 14:47:43 -05001995
1996 if (IsSectionExistInFlash(Adapter, sCopySectStrut.SrcSection) == false) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02001997 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02001998 "Source Section<%x> does not exist in Flash ",
1999 sCopySectStrut.SrcSection);
Dave Jones3e2aea52014-02-13 14:47:43 -05002000 return -EINVAL;
2001 }
2002
2003 if (IsSectionExistInFlash(Adapter, sCopySectStrut.DstSection) == false) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002004 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002005 "Destinatio Section<%x> does not exist in Flash ",
2006 sCopySectStrut.DstSection);
Dave Jones3e2aea52014-02-13 14:47:43 -05002007 return -EINVAL;
2008 }
2009
2010 if (sCopySectStrut.SrcSection == sCopySectStrut.DstSection) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002011 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002012 "Source and Destination section should be different");
Dave Jones3e2aea52014-02-13 14:47:43 -05002013 return -EINVAL;
2014 }
2015
2016 down(&Adapter->NVMRdmWrmLock);
2017
2018 if ((Adapter->IdleMode == TRUE) ||
2019 (Adapter->bShutStatus == TRUE) ||
2020 (Adapter->bPreparingForLowPowerMode == TRUE)) {
2021
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002022 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002023 "Device is in Idle/Shutdown Mode\n");
Dave Jones3e2aea52014-02-13 14:47:43 -05002024 up(&Adapter->NVMRdmWrmLock);
2025 return -EACCES;
2026 }
2027
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002028 if (sCopySectStrut.SrcSection == ISO_IMAGE1 ||
2029 sCopySectStrut.SrcSection == ISO_IMAGE2) {
Dave Jones3e2aea52014-02-13 14:47:43 -05002030 if (IsNonCDLessDevice(Adapter)) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002031 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002032 "Device is Non-CDLess hence won't have ISO !!");
Dave Jones3e2aea52014-02-13 14:47:43 -05002033 Status = -EINVAL;
2034 } else if (sCopySectStrut.numOfBytes == 0) {
2035 Status = BcmCopyISO(Adapter, sCopySectStrut);
2036 } else {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002037 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002038 "Partial Copy of ISO section is not Allowed..");
Dave Jones3e2aea52014-02-13 14:47:43 -05002039 Status = STATUS_FAILURE;
2040 }
2041 up(&Adapter->NVMRdmWrmLock);
2042 return Status;
2043 }
2044
2045 Status = BcmCopySection(Adapter, sCopySectStrut.SrcSection,
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002046 sCopySectStrut.DstSection,
2047 sCopySectStrut.offset,
2048 sCopySectStrut.numOfBytes);
Dave Jones3e2aea52014-02-13 14:47:43 -05002049 up(&Adapter->NVMRdmWrmLock);
2050 return Status;
2051}
2052
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002053static int bcm_char_ioctl_get_flash_cs_info(void __user *argp,
2054 struct bcm_mini_adapter *Adapter)
Dave Jones3aae97f2014-02-13 14:47:48 -05002055{
2056 struct bcm_ioctl_buffer IoBuffer;
2057 INT Status = STATUS_SUCCESS;
2058
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002059 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002060 " IOCTL_BCM_GET_FLASH_CS_INFO Called");
Dave Jones3aae97f2014-02-13 14:47:48 -05002061
Matthias Beyer22840ad2014-05-22 12:17:25 +02002062 Status = copy_from_user(&IoBuffer, argp,
2063 sizeof(struct bcm_ioctl_buffer));
Dave Jones3aae97f2014-02-13 14:47:48 -05002064 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002065 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002066 "Copy of IOCTL BUFFER failed");
Dave Jones3aae97f2014-02-13 14:47:48 -05002067 return -EFAULT;
2068 }
2069
2070 if (Adapter->eNVMType != NVM_FLASH) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002071 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002072 "Connected device does not have flash");
Dave Jones3aae97f2014-02-13 14:47:48 -05002073 return -EINVAL;
2074 }
2075
2076 if (IsFlash2x(Adapter) == TRUE) {
2077 if (IoBuffer.OutputLength < sizeof(struct bcm_flash2x_cs_info))
2078 return -EINVAL;
2079
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002080 if (copy_to_user(IoBuffer.OutputBuffer,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002081 Adapter->psFlash2xCSInfo,
2082 sizeof(struct bcm_flash2x_cs_info)))
Dave Jones3aae97f2014-02-13 14:47:48 -05002083 return -EFAULT;
2084 } else {
2085 if (IoBuffer.OutputLength < sizeof(struct bcm_flash_cs_info))
2086 return -EINVAL;
2087
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002088 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002089 sizeof(struct bcm_flash_cs_info)))
Dave Jones3aae97f2014-02-13 14:47:48 -05002090 return -EFAULT;
2091 }
2092 return Status;
2093}
2094
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002095static int bcm_char_ioctl_select_dsd(void __user *argp,
2096 struct bcm_mini_adapter *Adapter)
Dave Jones3c06b7a2014-02-13 14:47:53 -05002097{
2098 struct bcm_ioctl_buffer IoBuffer;
2099 INT Status = STATUS_FAILURE;
2100 UINT SectOfset = 0;
2101 enum bcm_flash2x_section_val eFlash2xSectionVal;
2102
2103 eFlash2xSectionVal = NO_SECTION_VAL;
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002104 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002105 "IOCTL_BCM_SELECT_DSD Called");
Dave Jones3c06b7a2014-02-13 14:47:53 -05002106
2107 if (IsFlash2x(Adapter) != TRUE) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002108 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002109 "Flash Does not have 2.x map");
Dave Jones3c06b7a2014-02-13 14:47:53 -05002110 return -EINVAL;
2111 }
2112
Matthias Beyer22840ad2014-05-22 12:17:25 +02002113 Status = copy_from_user(&IoBuffer, argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002114 sizeof(struct bcm_ioctl_buffer));
Dave Jones3c06b7a2014-02-13 14:47:53 -05002115 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002116 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002117 "Copy of IOCTL BUFFER failed");
Dave Jones3c06b7a2014-02-13 14:47:53 -05002118 return -EFAULT;
2119 }
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002120 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer,
2121 sizeof(INT));
Dave Jones3c06b7a2014-02-13 14:47:53 -05002122 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002123 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002124 "Copy of flash section val failed");
Dave Jones3c06b7a2014-02-13 14:47:53 -05002125 return -EFAULT;
2126 }
2127
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002128 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002129 "Read Section :%d", eFlash2xSectionVal);
Dave Jones3c06b7a2014-02-13 14:47:53 -05002130 if ((eFlash2xSectionVal != DSD0) &&
2131 (eFlash2xSectionVal != DSD1) &&
2132 (eFlash2xSectionVal != DSD2)) {
2133
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002134 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002135 "Passed section<%x> is not DSD section",
2136 eFlash2xSectionVal);
Dave Jones3c06b7a2014-02-13 14:47:53 -05002137 return STATUS_FAILURE;
2138 }
2139
2140 SectOfset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectionVal);
2141 if (SectOfset == INVALID_OFFSET) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002142 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002143 "Provided Section val <%d> does not exist in Flash 2.x",
2144 eFlash2xSectionVal);
Dave Jones3c06b7a2014-02-13 14:47:53 -05002145 return -EINVAL;
2146 }
2147
2148 Adapter->bAllDSDWriteAllow = TRUE;
2149 Adapter->ulFlashCalStart = SectOfset;
2150 Adapter->eActiveDSD = eFlash2xSectionVal;
2151
2152 return STATUS_SUCCESS;
2153}
Dave Jones1e1ee182014-02-13 14:47:02 -05002154
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002155static int bcm_char_ioctl_nvm_raw_read(void __user *argp,
2156 struct bcm_mini_adapter *Adapter)
Dave Jonesb3e58042014-02-13 14:47:59 -05002157{
2158 struct bcm_nvm_readwrite stNVMRead;
2159 struct bcm_ioctl_buffer IoBuffer;
Dan Carpenteree2104e2014-02-17 22:57:31 +03002160 unsigned int NOB;
Dave Jonesb3e58042014-02-13 14:47:59 -05002161 INT BuffSize;
2162 INT ReadOffset = 0;
2163 UINT ReadBytes = 0;
2164 PUCHAR pReadBuff;
2165 void __user *OutPutBuff;
2166 INT Status = STATUS_FAILURE;
2167
2168 if (Adapter->eNVMType != NVM_FLASH) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002169 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002170 "NVM TYPE is not Flash");
Dave Jonesb3e58042014-02-13 14:47:59 -05002171 return -EINVAL;
2172 }
2173
2174 /* Copy Ioctl Buffer structure */
2175 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002176 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002177 "copy_from_user 1 failed\n");
Dave Jonesb3e58042014-02-13 14:47:59 -05002178 return -EFAULT;
2179 }
2180
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002181 if (copy_from_user(&stNVMRead, IoBuffer.OutputBuffer,
2182 sizeof(struct bcm_nvm_readwrite)))
Dave Jonesb3e58042014-02-13 14:47:59 -05002183 return -EFAULT;
2184
2185 NOB = stNVMRead.uiNumBytes;
2186 /* In Raw-Read max Buff size : 64MB */
2187
2188 if (NOB > DEFAULT_BUFF_SIZE)
2189 BuffSize = DEFAULT_BUFF_SIZE;
2190 else
2191 BuffSize = NOB;
2192
2193 ReadOffset = stNVMRead.uiOffset;
2194 OutPutBuff = stNVMRead.pBuffer;
2195
2196 pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
2197 if (pReadBuff == NULL) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002198 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002199 "Memory allocation failed for Flash 2.x Read Structure");
Dave Jonesb3e58042014-02-13 14:47:59 -05002200 return -ENOMEM;
2201 }
2202 down(&Adapter->NVMRdmWrmLock);
2203
2204 if ((Adapter->IdleMode == TRUE) ||
2205 (Adapter->bShutStatus == TRUE) ||
2206 (Adapter->bPreparingForLowPowerMode == TRUE)) {
2207
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002208 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2209 "Device is in Idle/Shutdown Mode\n");
Dave Jonesb3e58042014-02-13 14:47:59 -05002210 kfree(pReadBuff);
2211 up(&Adapter->NVMRdmWrmLock);
2212 return -EACCES;
2213 }
2214
2215 Adapter->bFlashRawRead = TRUE;
2216
2217 while (NOB) {
2218 if (NOB > DEFAULT_BUFF_SIZE)
2219 ReadBytes = DEFAULT_BUFF_SIZE;
2220 else
2221 ReadBytes = NOB;
2222
2223 /* Reading the data from Flash 2.x */
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002224 Status = BeceemNVMRead(Adapter, (PUINT)pReadBuff,
2225 ReadOffset, ReadBytes);
Dave Jonesb3e58042014-02-13 14:47:59 -05002226 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002227 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002228 "Flash 2x read err with Status :%d",
2229 Status);
Dave Jonesb3e58042014-02-13 14:47:59 -05002230 break;
2231 }
2232
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002233 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, OSAL_DBG,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002234 DBG_LVL_ALL, pReadBuff, ReadBytes);
Dave Jonesb3e58042014-02-13 14:47:59 -05002235
2236 Status = copy_to_user(OutPutBuff, pReadBuff, ReadBytes);
2237 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002238 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002239 "Copy to use failed with status :%d",
2240 Status);
Dave Jonesb3e58042014-02-13 14:47:59 -05002241 up(&Adapter->NVMRdmWrmLock);
2242 kfree(pReadBuff);
2243 return -EFAULT;
2244 }
2245 NOB = NOB - ReadBytes;
2246 if (NOB) {
2247 ReadOffset = ReadOffset + ReadBytes;
2248 OutPutBuff = OutPutBuff + ReadBytes;
2249 }
2250 }
2251 Adapter->bFlashRawRead = false;
2252 up(&Adapter->NVMRdmWrmLock);
2253 kfree(pReadBuff);
2254 return Status;
2255}
2256
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002257static int bcm_char_ioctl_cntrlmsg_mask(void __user *argp,
2258 struct bcm_mini_adapter *Adapter, struct bcm_tarang_data *pTarang)
Dave Jones8f7e14e2014-02-13 14:48:04 -05002259{
2260 struct bcm_ioctl_buffer IoBuffer;
2261 INT Status = STATUS_FAILURE;
2262 ULONG RxCntrlMsgBitMask = 0;
2263
2264 /* Copy Ioctl Buffer structure */
Matthias Beyer22840ad2014-05-22 12:17:25 +02002265 Status = copy_from_user(&IoBuffer, argp,
2266 sizeof(struct bcm_ioctl_buffer));
Dave Jones8f7e14e2014-02-13 14:48:04 -05002267 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002268 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002269 "copy of Ioctl buffer is failed from user space");
Dave Jones8f7e14e2014-02-13 14:48:04 -05002270 return -EFAULT;
2271 }
2272
2273 if (IoBuffer.InputLength != sizeof(unsigned long))
2274 return -EINVAL;
2275
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002276 Status = copy_from_user(&RxCntrlMsgBitMask, IoBuffer.InputBuffer,
2277 IoBuffer.InputLength);
Dave Jones8f7e14e2014-02-13 14:48:04 -05002278 if (Status) {
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002279 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002280 "copy of control bit mask failed from user space");
Dave Jones8f7e14e2014-02-13 14:48:04 -05002281 return -EFAULT;
2282 }
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002283 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002284 "\n Got user defined cntrl msg bit mask :%lx",
2285 RxCntrlMsgBitMask);
Dave Jones8f7e14e2014-02-13 14:48:04 -05002286 pTarang->RxCntrlMsgBitMask = RxCntrlMsgBitMask;
2287
2288 return Status;
2289}
2290
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002291static int bcm_char_ioctl_get_device_driver_info(void __user *argp,
2292 struct bcm_mini_adapter *Adapter)
Dave Jonesfe59cef2014-02-13 14:48:09 -05002293{
2294 struct bcm_driver_info DevInfo;
2295 struct bcm_ioctl_buffer IoBuffer;
2296
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002297 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2298 "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
Dave Jonesfe59cef2014-02-13 14:48:09 -05002299
2300 memset(&DevInfo, 0, sizeof(DevInfo));
2301 DevInfo.MaxRDMBufferSize = BUFFER_4K;
2302 DevInfo.u32DSDStartOffset = EEPROM_CALPARAM_START;
2303 DevInfo.u32RxAlignmentCorrection = 0;
2304 DevInfo.u32NVMType = Adapter->eNVMType;
2305 DevInfo.u32InterfaceType = BCM_USB;
2306
2307 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
2308 return -EFAULT;
2309
2310 if (IoBuffer.OutputLength < sizeof(DevInfo))
2311 return -EINVAL;
2312
2313 if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
2314 return -EFAULT;
2315
2316 return STATUS_SUCCESS;
2317}
2318
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002319static int bcm_char_ioctl_time_since_net_entry(void __user *argp,
2320 struct bcm_mini_adapter *Adapter)
Dave Jones84f7a542014-02-13 14:48:14 -05002321{
2322 struct bcm_time_elapsed stTimeElapsedSinceNetEntry = {0};
2323 struct bcm_ioctl_buffer IoBuffer;
2324
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002325 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002326 "IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
Dave Jones84f7a542014-02-13 14:48:14 -05002327
2328 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
2329 return -EFAULT;
2330
2331 if (IoBuffer.OutputLength < sizeof(struct bcm_time_elapsed))
2332 return -EINVAL;
2333
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002334 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry =
2335 get_seconds() - Adapter->liTimeSinceLastNetEntry;
Dave Jones84f7a542014-02-13 14:48:14 -05002336
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002337 if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002338 sizeof(struct bcm_time_elapsed)))
Dave Jones84f7a542014-02-13 14:48:14 -05002339 return -EFAULT;
2340
2341 return STATUS_SUCCESS;
2342}
2343
Dave Jonesb3e58042014-02-13 14:47:59 -05002344
Arnd Bergmann9f1c75a2010-09-30 10:24:11 +02002345static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002346{
Kevin McKinney774bea82012-05-26 12:05:00 -04002347 struct bcm_tarang_data *pTarang = filp->private_data;
Stephen Hemmingerada692b2010-11-01 09:26:47 -04002348 void __user *argp = (void __user *)arg;
Kevin McKinney29794602012-05-26 12:05:12 -04002349 struct bcm_mini_adapter *Adapter = pTarang->Adapter;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002350 INT Status = STATUS_FAILURE;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002351
Ingrid Cheung7fae8b02013-11-09 20:53:21 -05002352 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2353 "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX",
2354 cmd, arg);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002355
Kevin McKinney6c15e002011-08-15 22:07:41 -04002356 if (_IOC_TYPE(cmd) != BCM_IOCTL)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002357 return -EFAULT;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002358 if (_IOC_DIR(cmd) & _IOC_READ)
Arnd Bergmann44a17eff2010-09-30 10:24:12 +02002359 Status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002360 else if (_IOC_DIR(cmd) & _IOC_WRITE)
Kevin McKinney6c15e002011-08-15 22:07:41 -04002361 Status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002362 else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
Kevin McKinney6c15e002011-08-15 22:07:41 -04002363 Status = STATUS_SUCCESS;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002364
Kevin McKinney6c15e002011-08-15 22:07:41 -04002365 if (Status)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002366 return -EFAULT;
2367
Kevin McKinney6c15e002011-08-15 22:07:41 -04002368 if (Adapter->device_removed)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002369 return -EFAULT;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002370
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07002371 if (false == Adapter->fw_download_done) {
Kevin McKinney6c15e002011-08-15 22:07:41 -04002372 switch (cmd) {
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002373 case IOCTL_MAC_ADDR_REQ:
2374 case IOCTL_LINK_REQ:
2375 case IOCTL_CM_REQUEST:
2376 case IOCTL_SS_INFO_REQ:
2377 case IOCTL_SEND_CONTROL_MESSAGE:
2378 case IOCTL_IDLE_REQ:
Kevin McKinney6c15e002011-08-15 22:07:41 -04002379 case IOCTL_BCM_GPIO_SET_REQUEST:
2380 case IOCTL_BCM_GPIO_STATUS_REQUEST:
2381 return -EACCES;
2382 default:
2383 break;
2384 }
2385 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002386
Kevin McKinney6c15e002011-08-15 22:07:41 -04002387 Status = vendorextnIoctl(Adapter, cmd, arg);
2388 if (Status != CONTINUE_COMMON_PATH)
2389 return Status;
Stephen Hemmingerada692b2010-11-01 09:26:47 -04002390
Kevin McKinney6c15e002011-08-15 22:07:41 -04002391 switch (cmd) {
2392 /* Rdms for Swin Idle... */
Dave Jones59fbe702014-02-13 14:45:05 -05002393 case IOCTL_BCM_REGISTER_READ_PRIVATE:
2394 Status = bcm_char_ioctl_reg_read_private(argp, Adapter);
2395 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002396
Dave Jones68270092014-02-13 14:45:11 -05002397 case IOCTL_BCM_REGISTER_WRITE_PRIVATE:
2398 Status = bcm_char_ioctl_reg_write_private(argp, Adapter);
2399 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002400
2401 case IOCTL_BCM_REGISTER_READ:
Dave Jones3195d4e2014-02-13 14:45:16 -05002402 case IOCTL_BCM_EEPROM_REGISTER_READ:
2403 Status = bcm_char_ioctl_eeprom_reg_read(argp, Adapter);
2404 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002405
Kevin McKinney6c15e002011-08-15 22:07:41 -04002406 case IOCTL_BCM_REGISTER_WRITE:
Dave Jones4d4b00a2014-02-13 14:45:21 -05002407 case IOCTL_BCM_EEPROM_REGISTER_WRITE:
2408 Status = bcm_char_ioctl_eeprom_reg_write(argp, Adapter, cmd);
2409 return Status;
Kevin McKinneya2521d72012-11-22 14:48:54 -05002410
Dave Jonesf494a912014-02-13 14:45:26 -05002411 case IOCTL_BCM_GPIO_SET_REQUEST:
2412 Status = bcm_char_ioctl_gpio_set_request(argp, Adapter);
2413 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002414
Dave Jones3eccdbc2014-02-13 14:45:31 -05002415 case BCM_LED_THREAD_STATE_CHANGE_REQ:
Matthias Beyer22840ad2014-05-22 12:17:25 +02002416 Status = bcm_char_ioctl_led_thread_state_change_req(argp,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002417 Adapter);
Dave Jones3eccdbc2014-02-13 14:45:31 -05002418 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002419
Dave Jones3eedb5f2014-02-13 14:45:36 -05002420 case IOCTL_BCM_GPIO_STATUS_REQUEST:
2421 Status = bcm_char_ioctl_gpio_status_request(argp, Adapter);
2422 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002423
Dave Jones39032462014-02-13 14:45:41 -05002424 case IOCTL_BCM_GPIO_MULTI_REQUEST:
2425 Status = bcm_char_ioctl_gpio_multi_request(argp, Adapter);
2426 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002427
Dave Jonese2d94d22014-02-13 14:45:47 -05002428 case IOCTL_BCM_GPIO_MODE_REQUEST:
2429 Status = bcm_char_ioctl_gpio_mode_request(argp, Adapter);
2430 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002431
2432 case IOCTL_MAC_ADDR_REQ:
2433 case IOCTL_LINK_REQ:
2434 case IOCTL_CM_REQUEST:
2435 case IOCTL_SS_INFO_REQ:
2436 case IOCTL_SEND_CONTROL_MESSAGE:
Dave Jones0566ee92014-02-13 14:45:52 -05002437 case IOCTL_IDLE_REQ:
2438 Status = bcm_char_ioctl_misc_request(argp, Adapter);
2439 return Status;
Stephen Hemmingerada692b2010-11-01 09:26:47 -04002440
Dave Jones79f99492014-02-13 14:45:57 -05002441 case IOCTL_BCM_BUFFER_DOWNLOAD_START:
2442 Status = bcm_char_ioctl_buffer_download_start(Adapter);
Kevin McKinney8fbebb02011-11-27 20:51:46 -05002443 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002444
Dave Jonesd9db71b2014-02-13 14:46:02 -05002445 case IOCTL_BCM_BUFFER_DOWNLOAD:
2446 Status = bcm_char_ioctl_buffer_download(argp, Adapter);
Kevin McKinney8fbebb02011-11-27 20:51:46 -05002447 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002448
Dave Jones49444b52014-02-13 14:46:07 -05002449 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP:
2450 Status = bcm_char_ioctl_buffer_download_stop(argp, Adapter);
Kevin McKinney8fbebb02011-11-27 20:51:46 -05002451 return Status;
Dave Jones49444b52014-02-13 14:46:07 -05002452
Kevin McKinney6c15e002011-08-15 22:07:41 -04002453
2454 case IOCTL_BE_BUCKET_SIZE:
2455 Status = 0;
Matthias Beyer22840ad2014-05-22 12:17:25 +02002456 if (get_user(Adapter->BEBucketSize,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002457 (unsigned long __user *)arg))
Kevin McKinney6c15e002011-08-15 22:07:41 -04002458 Status = -EFAULT;
2459 break;
2460
2461 case IOCTL_RTPS_BUCKET_SIZE:
2462 Status = 0;
Matthias Beyer22840ad2014-05-22 12:17:25 +02002463 if (get_user(Adapter->rtPSBucketSize,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002464 (unsigned long __user *)arg))
Kevin McKinney6c15e002011-08-15 22:07:41 -04002465 Status = -EFAULT;
2466 break;
2467
Dave Jones6e5781c2014-02-13 14:46:12 -05002468 case IOCTL_CHIP_RESET:
2469 Status = bcm_char_ioctl_chip_reset(Adapter);
2470 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002471
Dave Jones645926b2014-02-13 14:46:17 -05002472 case IOCTL_QOS_THRESHOLD:
2473 Status = bcm_char_ioctl_qos_threshold(arg, Adapter);
2474 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002475
Kevin McKinney6c15e002011-08-15 22:07:41 -04002476 case IOCTL_DUMP_PACKET_INFO:
2477 DumpPackInfo(Adapter);
2478 DumpPhsRules(&Adapter->stBCMPhsContext);
2479 Status = STATUS_SUCCESS;
2480 break;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002481
Kevin McKinney6c15e002011-08-15 22:07:41 -04002482 case IOCTL_GET_PACK_INFO:
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002483 if (copy_to_user(argp, &Adapter->PackInfo,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002484 sizeof(struct bcm_packet_info)*NO_OF_QUEUES))
Kevin McKinney6c15e002011-08-15 22:07:41 -04002485 return -EFAULT;
2486 Status = STATUS_SUCCESS;
2487 break;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002488
Dave Jonesa0ad9612014-02-13 14:46:22 -05002489 case IOCTL_BCM_SWITCH_TRANSFER_MODE:
2490 Status = bcm_char_ioctl_switch_transfer_mode(argp, Adapter);
2491 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002492
Dave Jonesdfb442d2014-02-13 14:46:27 -05002493 case IOCTL_BCM_GET_DRIVER_VERSION:
2494 Status = bcm_char_ioctl_get_driver_version(argp);
2495 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002496
Dave Jones9c434f82014-02-13 14:46:32 -05002497 case IOCTL_BCM_GET_CURRENT_STATUS:
2498 Status = bcm_char_ioctl_get_current_status(argp, Adapter);
2499 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002500
Dave Jonescfd01352014-02-13 14:46:37 -05002501 case IOCTL_BCM_SET_MAC_TRACING:
2502 Status = bcm_char_ioctl_set_mac_tracing(argp, Adapter);
2503 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002504
Dave Jones4d476af2014-02-13 14:46:42 -05002505 case IOCTL_BCM_GET_DSX_INDICATION:
2506 Status = bcm_char_ioctl_get_dsx_indication(argp, Adapter);
2507 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002508
Dave Jonesdb9a4dc2014-02-13 14:46:47 -05002509 case IOCTL_BCM_GET_HOST_MIBS:
2510 Status = bcm_char_ioctl_get_host_mibs(argp, Adapter, pTarang);
2511 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002512
2513 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002514 if ((false == Adapter->bTriedToWakeUpFromlowPowerMode) &&
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002515 (TRUE == Adapter->IdleMode)) {
Kevin McKinney6c15e002011-08-15 22:07:41 -04002516 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
2517 Adapter->bWakeUpDevice = TRUE;
2518 wake_up(&Adapter->process_rx_cntrlpkt);
2519 }
2520
2521 Status = STATUS_SUCCESS;
2522 break;
2523
Dave Jonesb32384b2014-02-13 14:46:52 -05002524 case IOCTL_BCM_BULK_WRM:
2525 Status = bcm_char_ioctl_bulk_wrm(argp, Adapter, cmd);
2526 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002527
2528 case IOCTL_BCM_GET_NVM_SIZE:
Dave Jones1c55e382014-02-13 14:46:57 -05002529 Status = bcm_char_ioctl_get_nvm_size(argp, Adapter);
2530 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002531
Dave Jones1e1ee182014-02-13 14:47:02 -05002532 case IOCTL_BCM_CAL_INIT:
2533 Status = bcm_char_ioctl_cal_init(argp, Adapter);
2534 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002535
2536 case IOCTL_BCM_SET_DEBUG:
Dave Jones085ca022014-02-13 14:47:08 -05002537 Status = bcm_char_ioctl_set_debug(argp, Adapter);
2538 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002539
2540 case IOCTL_BCM_NVM_READ:
Dave Jones5be531c2014-02-13 14:47:13 -05002541 case IOCTL_BCM_NVM_WRITE:
2542 Status = bcm_char_ioctl_nvm_rw(argp, Adapter, cmd);
2543 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002544
Dave Jonesb4571fc2014-02-13 14:47:18 -05002545 case IOCTL_BCM_FLASH2X_SECTION_READ:
2546 Status = bcm_char_ioctl_flash2x_section_read(argp, Adapter);
2547 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002548
Dave Jones174b3b42014-02-13 14:47:23 -05002549 case IOCTL_BCM_FLASH2X_SECTION_WRITE:
2550 Status = bcm_char_ioctl_flash2x_section_write(argp, Adapter);
2551 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002552
Dave Jones338a5c42014-02-13 14:47:28 -05002553 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP:
2554 Status = bcm_char_ioctl_flash2x_section_bitmap(argp, Adapter);
2555 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002556
Dave Jones9e0d6e12014-02-13 14:47:33 -05002557 case IOCTL_BCM_SET_ACTIVE_SECTION:
2558 Status = bcm_char_ioctl_set_active_section(argp, Adapter);
2559 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002560
Dave Jones56b682a2014-02-13 14:47:38 -05002561 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION:
Kevin McKinney6c15e002011-08-15 22:07:41 -04002562 /* Right Now we are taking care of only DSD */
Lisa Nguyenf70c8a92013-10-28 01:36:19 -07002563 Adapter->bAllDSDWriteAllow = false;
Ebru Akagunduz18e26b32014-03-13 10:34:19 +02002564 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002565 "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
Kevin McKinney6c15e002011-08-15 22:07:41 -04002566 Status = STATUS_SUCCESS;
Dave Jones56b682a2014-02-13 14:47:38 -05002567 break;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002568
Dave Jones3e2aea52014-02-13 14:47:43 -05002569 case IOCTL_BCM_COPY_SECTION:
2570 Status = bcm_char_ioctl_copy_section(argp, Adapter);
2571 return Status;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002572
Dave Jones3aae97f2014-02-13 14:47:48 -05002573 case IOCTL_BCM_GET_FLASH_CS_INFO:
2574 Status = bcm_char_ioctl_get_flash_cs_info(argp, Adapter);
2575 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002576
Dave Jones3c06b7a2014-02-13 14:47:53 -05002577 case IOCTL_BCM_SELECT_DSD:
2578 Status = bcm_char_ioctl_select_dsd(argp, Adapter);
2579 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002580
Dave Jonesb3e58042014-02-13 14:47:59 -05002581 case IOCTL_BCM_NVM_RAW_READ:
2582 Status = bcm_char_ioctl_nvm_raw_read(argp, Adapter);
2583 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002584
Dave Jones8f7e14e2014-02-13 14:48:04 -05002585 case IOCTL_BCM_CNTRLMSG_MASK:
2586 Status = bcm_char_ioctl_cntrlmsg_mask(argp, Adapter, pTarang);
2587 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002588
Dave Jonesfe59cef2014-02-13 14:48:09 -05002589 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO:
2590 Status = bcm_char_ioctl_get_device_driver_info(argp, Adapter);
2591 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002592
Dave Jones84f7a542014-02-13 14:48:14 -05002593 case IOCTL_BCM_TIME_SINCE_NET_ENTRY:
2594 Status = bcm_char_ioctl_time_since_net_entry(argp, Adapter);
2595 return Status;
Kevin McKinney6c15e002011-08-15 22:07:41 -04002596
2597 case IOCTL_CLOSE_NOTIFICATION:
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002598 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2599 "IOCTL_CLOSE_NOTIFICATION");
Kevin McKinney6c15e002011-08-15 22:07:41 -04002600 break;
2601
2602 default:
2603 pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
2604 Status = STATUS_FAILURE;
2605 break;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002606 }
2607 return Status;
2608}
2609
2610
Javier Martinez Canillas78acd582011-02-12 04:38:25 +01002611static const struct file_operations bcm_fops = {
Arnd Bergmann9f1c75a2010-09-30 10:24:11 +02002612 .owner = THIS_MODULE,
2613 .open = bcm_char_open,
2614 .release = bcm_char_release,
2615 .read = bcm_char_read,
2616 .unlocked_ioctl = bcm_char_ioctl,
Arnd Bergmannd16044cf2010-09-30 10:24:07 +02002617 .llseek = no_llseek,
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002618};
2619
Kevin McKinney29794602012-05-26 12:05:12 -04002620int register_control_device_interface(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002621{
Stephen Hemminger9e0a3162010-11-01 10:17:54 -04002622
Javier Martinez Canillas78acd582011-02-12 04:38:25 +01002623 if (Adapter->major > 0)
Stephen Hemminger9e0a3162010-11-01 10:17:54 -04002624 return Adapter->major;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002625
Stephen Hemminger9e0a3162010-11-01 10:17:54 -04002626 Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
Javier Martinez Canillas78acd582011-02-12 04:38:25 +01002627 if (Adapter->major < 0) {
Stephen Hemminger9e0a3162010-11-01 10:17:54 -04002628 pr_err(DRV_NAME ": could not created character device\n");
2629 return Adapter->major;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002630 }
Stephen Hemminger9e0a3162010-11-01 10:17:54 -04002631
Javier Martinez Canillas78acd582011-02-12 04:38:25 +01002632 Adapter->pstCreatedClassDevice = device_create(bcm_class, NULL,
Matthias Beyer2c11ca22014-05-22 12:17:28 +02002633 MKDEV(Adapter->major, 0),
2634 Adapter, DEV_NAME);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002635
Javier Martinez Canillas78acd582011-02-12 04:38:25 +01002636 if (IS_ERR(Adapter->pstCreatedClassDevice)) {
Stephen Hemminger9e0a3162010-11-01 10:17:54 -04002637 pr_err(DRV_NAME ": class device create failed\n");
2638 unregister_chrdev(Adapter->major, DEV_NAME);
2639 return PTR_ERR(Adapter->pstCreatedClassDevice);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002640 }
Javier Martinez Canillas78acd582011-02-12 04:38:25 +01002641
Stephen Hemminger9e0a3162010-11-01 10:17:54 -04002642 return 0;
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002643}
2644
Kevin McKinney29794602012-05-26 12:05:12 -04002645void unregister_control_device_interface(struct bcm_mini_adapter *Adapter)
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002646{
Javier Martinez Canillas78acd582011-02-12 04:38:25 +01002647 if (Adapter->major > 0) {
2648 device_destroy(bcm_class, MKDEV(Adapter->major, 0));
Stephen Hemminger9e0a3162010-11-01 10:17:54 -04002649 unregister_chrdev(Adapter->major, DEV_NAME);
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002650 }
Stephen Hemmingerf8942e02010-09-08 14:46:36 -07002651}
Kevin McKinney6c15e002011-08-15 22:07:41 -04002652