2 * ---------------------------------------------------------------------------
6 * Conventional device interface for debugging/monitoring of the
7 * driver and h/w using unicli. This interface is also being used
8 * by the SME linux implementation and the helper apps.
10 * Copyright (C) 2005-2009 by Cambridge Silicon Radio Ltd.
12 * Refer to LICENSE.txt included with this source code for details on
15 * ---------------------------------------------------------------------------
20 * Part of this file contains an example for how to glue the OS layer
21 * with the HIP core lib, the SDIO glue layer, and the SME.
23 * When the unifi_sdio.ko modules loads, the linux kernel calls unifi_load().
24 * unifi_load() calls uf_sdio_load() which is exported by the SDIO glue
25 * layer. uf_sdio_load() registers this driver with the underlying SDIO driver.
26 * When a card is detected, the SDIO glue layer calls register_unifi_sdio()
27 * to pass the SDIO function context and ask the OS layer to initialise
28 * the card. register_unifi_sdio() allocates all the private data of the OS
29 * layer and calls uf_run_unifihelper() to start the SME. The SME calls
30 * unifi_sys_wifi_on_req() which uses the HIP core lib to initialise the card.
33 #include <linux/init.h>
34 #include <linux/slab.h>
35 #include <linux/poll.h>
36 #include <asm/uaccess.h>
37 #include <linux/jiffies.h>
38 #include <linux/version.h>
40 #include "csr_wifi_hip_unifiversion.h"
41 #include "unifi_priv.h"
42 #include "csr_wifi_hip_conversions.h"
43 #include "unifi_native.h"
45 /* Module parameter variables */
46 int buswidth
= 0; /* 0 means use default, values 1,4 */
47 int sdio_clock
= 50000; /* kHz */
49 /* fw_init prevents f/w initialisation on error. */
50 int fw_init
[MAX_UNIFI_DEVS
] = {-1, -1};
52 int led_mask
= 0; /* 0x0c00 for dev-pc-1503c, dev-pc-1528a */
53 int disable_hw_reset
= 0;
54 int disable_power_control
= 0;
55 int enable_wol
= UNIFI_WOL_OFF
; /* 0 for none, 1 for SDIO IRQ, 2 for PIO */
56 #if (defined CSR_SUPPORT_SME) && (defined CSR_SUPPORT_WEXT)
57 int tl_80211d
= (int)CSR_WIFI_SME_80211D_TRUST_LEVEL_MIB
;
59 int sdio_block_size
= -1; /* Override SDIO block size */
60 int sdio_byte_mode
= 0; /* 0 for block mode + padding, 1 for byte mode */
61 int coredump_max
= CSR_WIFI_HIP_NUM_COREDUMP_BUFFERS
;
62 int run_bh_once
= -1; /* Set for scheduled interrupt mode, -1 = default */
64 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
65 #define UNIFI_LOG_HIP_SIGNALS_FILTER_BULKDATA (1 << 1)
66 #define UNIFI_LOG_HIP_SIGNALS_FILTER_TIMESTAMP (1 << 2)
67 int log_hip_signals
= 0;
70 MODULE_DESCRIPTION("CSR UniFi (SDIO)");
72 module_param(buswidth
, int, S_IRUGO
|S_IWUSR
);
73 module_param(sdio_clock
, int, S_IRUGO
|S_IWUSR
);
74 module_param(unifi_debug
, int, S_IRUGO
|S_IWUSR
);
75 module_param_array(fw_init
, int, NULL
, S_IRUGO
|S_IWUSR
);
76 module_param(use_5g
, int, S_IRUGO
|S_IWUSR
);
77 module_param(led_mask
, int, S_IRUGO
|S_IWUSR
);
78 module_param(disable_hw_reset
, int, S_IRUGO
|S_IWUSR
);
79 module_param(disable_power_control
, int, S_IRUGO
|S_IWUSR
);
80 module_param(enable_wol
, int, S_IRUGO
|S_IWUSR
);
81 #if (defined CSR_SUPPORT_SME) && (defined CSR_SUPPORT_WEXT)
82 module_param(tl_80211d
, int, S_IRUGO
|S_IWUSR
);
84 module_param(sdio_block_size
, int, S_IRUGO
|S_IWUSR
);
85 module_param(sdio_byte_mode
, int, S_IRUGO
|S_IWUSR
);
86 module_param(coredump_max
, int, S_IRUGO
|S_IWUSR
);
87 module_param(run_bh_once
, int, S_IRUGO
|S_IWUSR
);
88 module_param(bh_priority
, int, S_IRUGO
|S_IWUSR
);
89 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
90 module_param(log_hip_signals
, int, S_IRUGO
|S_IWUSR
);
93 MODULE_PARM_DESC(buswidth
, "SDIO bus width (0=default), set 1 for 1-bit or 4 for 4-bit mode");
94 MODULE_PARM_DESC(sdio_clock
, "SDIO bus frequency in kHz, (default = 50 MHz)");
95 MODULE_PARM_DESC(unifi_debug
, "Diagnostic reporting level");
96 MODULE_PARM_DESC(fw_init
, "Set to 0 to prevent f/w initialization on error");
97 MODULE_PARM_DESC(use_5g
, "Use the 5G (802.11a) radio band");
98 MODULE_PARM_DESC(led_mask
, "LED mask flags");
99 MODULE_PARM_DESC(disable_hw_reset
, "Set to 1 to disable hardware reset");
100 MODULE_PARM_DESC(disable_power_control
, "Set to 1 to disable SDIO power control");
101 MODULE_PARM_DESC(enable_wol
, "Enable wake-on-wlan function 0=off, 1=SDIO, 2=PIO");
102 #if (defined CSR_SUPPORT_SME) && (defined CSR_SUPPORT_WEXT)
103 MODULE_PARM_DESC(tl_80211d
, "802.11d Trust Level (1-6, default = 5)");
105 MODULE_PARM_DESC(sdio_block_size
, "Set to override SDIO block size");
106 MODULE_PARM_DESC(sdio_byte_mode
, "Set to 1 for byte mode SDIO");
107 MODULE_PARM_DESC(coredump_max
, "Number of chip mini-coredump buffers to allocate");
108 MODULE_PARM_DESC(run_bh_once
, "Run BH only when firmware interrupts");
109 MODULE_PARM_DESC(bh_priority
, "Modify the BH thread priority");
110 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
111 MODULE_PARM_DESC(log_hip_signals
, "Set to 1 to enable HIP signal offline logging");
115 /* Callback for event logging to UDI clients */
116 static void udi_log_event(ul_client_t
*client
,
117 const u8
*signal
, int signal_len
,
118 const bulk_data_param_t
*bulkdata
,
121 static void udi_set_log_filter(ul_client_t
*pcli
,
122 unifiio_filter_t
*udi_filter
);
125 /* Mutex to protect access to priv->sme_cli */
126 DEFINE_SEMAPHORE(udi_mutex
);
128 s32
CsrHipResultToStatus(CsrResult csrResult
)
134 case CSR_RESULT_SUCCESS
:
137 case CSR_WIFI_HIP_RESULT_RANGE
:
140 case CSR_WIFI_HIP_RESULT_NO_DEVICE
:
143 case CSR_WIFI_HIP_RESULT_INVALID_VALUE
:
146 case CSR_WIFI_HIP_RESULT_NOT_FOUND
:
149 case CSR_WIFI_HIP_RESULT_NO_SPACE
:
152 case CSR_WIFI_HIP_RESULT_NO_MEMORY
:
155 case CSR_RESULT_FAILURE
:
159 /*unifi_warning(card->ospriv, "CsrHipResultToStatus: Unrecognised csrResult error code: %d\n", csrResult);*/
167 trace_putest_cmdid(unifi_putest_command_t putest_cmd
)
169 switch (putest_cmd
) {
170 case UNIFI_PUTEST_START
:
172 case UNIFI_PUTEST_STOP
:
174 case UNIFI_PUTEST_SET_SDIO_CLOCK
:
176 case UNIFI_PUTEST_CMD52_READ
:
178 case UNIFI_PUTEST_CMD52_BLOCK_READ
:
180 case UNIFI_PUTEST_CMD52_WRITE
:
182 case UNIFI_PUTEST_DL_FW
:
184 case UNIFI_PUTEST_DL_FW_BUFF
:
185 return "D/L FW BUFFER";
186 case UNIFI_PUTEST_COREDUMP_PREPARE
:
187 return "PREPARE COREDUMP";
188 case UNIFI_PUTEST_GP_READ16
:
190 case UNIFI_PUTEST_GP_WRITE16
:
193 return "ERROR: unrecognised command";
197 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
198 int uf_register_hip_offline_debug(unifi_priv_t
*priv
)
200 ul_client_t
*udi_cli
;
203 udi_cli
= ul_register_client(priv
, CLI_USING_WIRE_FORMAT
, udi_log_event
);
204 if (udi_cli
== NULL
) {
205 /* Too many clients already using this device */
206 unifi_error(priv
, "Too many UDI clients already open\n");
209 unifi_trace(priv
, UDBG1
, "Offline HIP client is registered\n");
211 down(&priv
->udi_logging_mutex
);
212 udi_cli
->event_hook
= udi_log_event
;
213 unifi_set_udi_hook(priv
->card
, logging_handler
);
214 /* Log all signals by default */
215 for (i
= 0; i
< SIG_FILTER_SIZE
; i
++) {
216 udi_cli
->signal_filter
[i
] = 0xFFFF;
218 priv
->logging_client
= udi_cli
;
219 up(&priv
->udi_logging_mutex
);
224 int uf_unregister_hip_offline_debug(unifi_priv_t
*priv
)
226 ul_client_t
*udi_cli
= priv
->logging_client
;
229 unifi_error(priv
, "Unknown HIP client unregister request\n");
233 unifi_trace(priv
, UDBG1
, "Offline HIP client is unregistered\n");
235 down(&priv
->udi_logging_mutex
);
236 priv
->logging_client
= NULL
;
237 udi_cli
->event_hook
= NULL
;
238 up(&priv
->udi_logging_mutex
);
240 ul_deregister_client(udi_cli
);
248 * ---------------------------------------------------------------------------
252 * Open and release entry points for the UniFi debug driver.
255 * Normal linux driver args.
259 * ---------------------------------------------------------------------------
262 unifi_open(struct inode
*inode
, struct file
*file
)
266 ul_client_t
*udi_cli
;
268 devno
= MINOR(inode
->i_rdev
) >> 1;
271 * Increase the ref_count for the char device clients.
272 * Make sure you call uf_put_instance() to decreace it if
273 * unifi_open returns an error.
275 priv
= uf_get_instance(devno
);
277 unifi_error(NULL
, "unifi_open: No device present\n");
281 /* Register this instance in the client's list. */
282 /* The minor number determines the nature of the client (Unicli or SME). */
283 if (MINOR(inode
->i_rdev
) & 0x1) {
284 udi_cli
= ul_register_client(priv
, CLI_USING_WIRE_FORMAT
, udi_log_event
);
285 if (udi_cli
== NULL
) {
286 /* Too many clients already using this device */
287 unifi_error(priv
, "Too many clients already open\n");
288 uf_put_instance(devno
);
291 unifi_trace(priv
, UDBG1
, "Client is registered to /dev/unifiudi%d\n", devno
);
294 * Even-numbered device nodes are the control application.
295 * This is the userspace helper containing SME or
301 #ifdef CSR_SME_USERSPACE
302 /* Check if a config client is already attached */
305 uf_put_instance(devno
);
307 unifi_info(priv
, "There is already a configuration client using the character device\n");
310 #endif /* CSR_SME_USERSPACE */
312 #ifdef CSR_SUPPORT_SME
313 udi_cli
= ul_register_client(priv
,
314 CLI_USING_WIRE_FORMAT
| CLI_SME_USERSPACE
,
317 /* Config client for native driver */
318 udi_cli
= ul_register_client(priv
,
320 sme_native_log_event
);
322 if (udi_cli
== NULL
) {
323 /* Too many clients already using this device */
325 uf_put_instance(devno
);
327 unifi_error(priv
, "Too many clients already open\n");
332 * Fill-in the pointer to the configuration client.
333 * This is the SME userspace helper or unifi_manager.
334 * Not used in the SME embedded version.
336 unifi_trace(priv
, UDBG1
, "SME client (id:%d s:0x%X) is registered\n",
337 udi_cli
->client_id
, udi_cli
->sender_id
);
338 /* Store the SME UniFi Linux Client */
339 if (priv
->sme_cli
== NULL
) {
340 priv
->sme_cli
= udi_cli
;
348 * Store the pointer to the client.
349 * All char driver's entry points will pass this pointer.
351 file
->private_data
= udi_cli
;
358 unifi_release(struct inode
*inode
, struct file
*filp
)
360 ul_client_t
*udi_cli
= (void*)filp
->private_data
;
364 priv
= uf_find_instance(udi_cli
->instance
);
366 unifi_error(priv
, "unifi_close: instance for device not found\n");
370 devno
= MINOR(inode
->i_rdev
) >> 1;
372 /* Even device nodes are the config client (i.e. SME or unifi_manager) */
373 if ((MINOR(inode
->i_rdev
) & 0x1) == 0) {
375 if (priv
->sme_cli
!= udi_cli
) {
376 unifi_notice(priv
, "Surprise closing config device: not the sme client\n");
378 unifi_notice(priv
, "SME client close (unifi%d)\n", devno
);
381 * Clear sme_cli before calling unifi_sys_... so it doesn't try to
382 * queue a reply to the (now gone) SME.
385 priv
->sme_cli
= NULL
;
388 #ifdef CSR_SME_USERSPACE
389 /* Power-down when config client closes */
391 CsrWifiRouterCtrlWifiOffReq req
= {{CSR_WIFI_ROUTER_CTRL_HIP_REQ
, 0, 0, 0, NULL
}};
392 CsrWifiRouterCtrlWifiOffReqHandler(priv
, &req
.common
);
397 /* It is possible that a blocking SME request was made from another process
398 * which did not get read by the SME before the WifiOffReq.
399 * So check for a pending request which will go unanswered and cancel
400 * the wait for event. As only one blocking request can be in progress at
401 * a time, up to one event should be completed.
403 uf_sme_cancel_request(priv
, 0);
405 #endif /* CSR_SME_USERSPACE */
408 unifi_trace(priv
, UDBG2
, "UDI client close (unifiudi%d)\n", devno
);
410 /* If the pointer matches the logging client, stop logging. */
411 down(&priv
->udi_logging_mutex
);
412 if (udi_cli
== priv
->logging_client
) {
413 priv
->logging_client
= NULL
;
415 up(&priv
->udi_logging_mutex
);
417 if (udi_cli
== priv
->amp_client
) {
418 priv
->amp_client
= NULL
;
422 /* Deregister this instance from the client's list. */
423 ul_deregister_client(udi_cli
);
425 uf_put_instance(devno
);
428 } /* unifi_release() */
433 * ---------------------------------------------------------------------------
436 * The read() driver entry point.
439 * filp The file descriptor returned by unifi_open()
440 * p The user space buffer to copy the read data
441 * len The size of the p buffer
445 * number of bytes read or an error code on failure
446 * ---------------------------------------------------------------------------
449 unifi_read(struct file
*filp
, char *p
, size_t len
, loff_t
*poff
)
451 ul_client_t
*pcli
= (void*)filp
->private_data
;
453 udi_log_t
*logptr
= NULL
;
458 priv
= uf_find_instance(pcli
->instance
);
460 unifi_error(priv
, "invalid priv\n");
464 if (!pcli
->udi_enabled
) {
465 unifi_error(priv
, "unifi_read: unknown client.");
469 if (list_empty(&pcli
->udi_log
)) {
470 if (filp
->f_flags
& O_NONBLOCK
) {
471 /* Non-blocking - just return if the udi_log is empty */
474 /* Blocking - wait on the UDI wait queue */
475 if (wait_event_interruptible(pcli
->udi_wq
,
476 !list_empty(&pcli
->udi_log
)))
478 unifi_error(priv
, "unifi_read: wait_event_interruptible failed.");
484 /* Read entry from list head and remove it from the list */
485 if (down_interruptible(&pcli
->udi_sem
)) {
488 l
= pcli
->udi_log
.next
;
492 /* Get a pointer to whole struct */
493 logptr
= list_entry(l
, udi_log_t
, q
);
494 if (logptr
== NULL
) {
495 unifi_error(priv
, "unifi_read: failed to get event.\n");
499 /* Get the real message */
500 msgptr
= &logptr
->msg
;
501 msglen
= msgptr
->length
;
503 printk(KERN_WARNING
"truncated read to %d actual msg len is %lu\n", msglen
, (long unsigned int)len
);
507 /* and pass it to the client (SME or Unicli). */
508 if (copy_to_user(p
, msgptr
, msglen
))
510 printk(KERN_ERR
"Failed to copy UDI log to user\n");
515 /* It is our resposibility to free the message buffer. */
525 * ---------------------------------------------------------------------------
526 * udi_send_signal_unpacked
528 * Sends an unpacked signal to UniFi.
531 * priv Pointer to private context struct
532 * data Pointer to request structure and data to send
533 * data_len Length of data in data pointer.
536 * Number of bytes written, error otherwise.
539 * All clients that use this function to send a signal to the unifi
540 * must use the host formatted structures.
541 * ---------------------------------------------------------------------------
544 udi_send_signal_unpacked(unifi_priv_t
*priv
, unsigned char* data
, uint data_len
)
546 CSR_SIGNAL
*sigptr
= (CSR_SIGNAL
*)data
;
547 CSR_DATAREF
*datarefptr
;
548 bulk_data_param_t bulk_data
;
550 uint bulk_data_offset
= 0;
554 /* Number of bytes in the signal */
555 signal_size
= SigGetSize(sigptr
);
556 if (!signal_size
|| (signal_size
> data_len
)) {
557 unifi_error(priv
, "unifi_sme_mlme_req - Invalid signal 0x%x size should be %d bytes\n",
558 sigptr
->SignalPrimitiveHeader
.SignalId
,
562 bytecount
= signal_size
;
564 /* Get a pointer to the information of the first data reference */
565 datarefptr
= (CSR_DATAREF
*)&sigptr
->u
;
567 /* Initialize the offset in the data buffer, bulk data is right after the signal. */
568 bulk_data_offset
= signal_size
;
570 /* store the references and the size of the bulk data to the bulkdata structure */
571 for (i
= 0; i
< UNIFI_MAX_DATA_REFERENCES
; i
++) {
572 /* the length of the bulk data is in the signal */
573 if ((datarefptr
+i
)->DataLength
) {
576 csrResult
= unifi_net_data_malloc(priv
, &bulk_data
.d
[i
], (datarefptr
+i
)->DataLength
);
577 if (csrResult
!= CSR_RESULT_SUCCESS
) {
578 unifi_error(priv
, "udi_send_signal_unpacked: failed to allocate request_data.\n");
582 dest
= (void*)bulk_data
.d
[i
].os_data_ptr
;
583 memcpy(dest
, data
+ bulk_data_offset
, bulk_data
.d
[i
].data_length
);
585 bulk_data
.d
[i
].data_length
= 0;
588 bytecount
+= bulk_data
.d
[i
].data_length
;
589 /* advance the offset, to point the next bulk data */
590 bulk_data_offset
+= bulk_data
.d
[i
].data_length
;
594 unifi_trace(priv
, UDBG3
, "SME Send: signal 0x%.4X\n", sigptr
->SignalPrimitiveHeader
.SignalId
);
596 /* Send the signal. */
597 r
= ul_send_signal_unpacked(priv
, sigptr
, &bulk_data
);
599 unifi_error(priv
, "udi_send_signal_unpacked: send failed (%d)\n", r
);
600 for(i
=0;i
<UNIFI_MAX_DATA_REFERENCES
;i
++) {
601 if(bulk_data
.d
[i
].data_length
!= 0) {
602 unifi_net_data_free(priv
, &bulk_data
.d
[i
]);
609 } /* udi_send_signal_unpacked() */
614 * ---------------------------------------------------------------------------
615 * udi_send_signal_raw
617 * Sends a packed signal to UniFi.
620 * priv Pointer to private context struct
621 * buf Pointer to request structure and data to send
622 * buflen Length of data in data pointer.
625 * Number of bytes written, error otherwise.
628 * All clients that use this function to send a signal to the unifi
629 * must use the wire formatted structures.
630 * ---------------------------------------------------------------------------
633 udi_send_signal_raw(unifi_priv_t
*priv
, unsigned char *buf
, int buflen
)
637 bulk_data_param_t data_ptrs
;
639 unsigned int num_data_refs
;
644 * The signal is the first thing in buf, the signal id is the
645 * first 16 bits of the signal.
647 /* Number of bytes in the signal */
648 sig_id
= GET_SIGNAL_ID(buf
);
649 signal_size
= buflen
;
650 signal_size
-= GET_PACKED_DATAREF_LEN(buf
, 0);
651 signal_size
-= GET_PACKED_DATAREF_LEN(buf
, 1);
652 if ((signal_size
<= 0) || (signal_size
> buflen
)) {
653 unifi_error(priv
, "udi_send_signal_raw - Couldn't find length of signal 0x%x\n",
657 unifi_trace(priv
, UDBG2
, "udi_send_signal_raw: signal 0x%.4X len:%d\n",
658 sig_id
, signal_size
);
659 /* Zero the data ref arrays */
660 memset(&data_ptrs
, 0, sizeof(data_ptrs
));
663 * Find the number of associated bulk data packets. Scan through
664 * the data refs to check that we have enough data and pick out
665 * pointers to appended bulk data.
668 bytecount
= signal_size
;
670 for (i
= 0; i
< UNIFI_MAX_DATA_REFERENCES
; ++i
)
672 unsigned int len
= GET_PACKED_DATAREF_LEN(buf
, i
);
673 unifi_trace(priv
, UDBG3
, "udi_send_signal_raw: data_ref length = %d\n", len
);
678 csrResult
= unifi_net_data_malloc(priv
, &data_ptrs
.d
[i
], len
);
679 if (csrResult
!= CSR_RESULT_SUCCESS
) {
680 unifi_error(priv
, "udi_send_signal_raw: failed to allocate request_data.\n");
684 dest
= (void*)data_ptrs
.d
[i
].os_data_ptr
;
685 memcpy(dest
, buf
+ bytecount
, len
);
690 data_ptrs
.d
[i
].data_length
= len
;
693 unifi_trace(priv
, UDBG3
, "Queueing signal 0x%.4X from UDI with %u data refs\n",
697 if (bytecount
> buflen
) {
698 unifi_error(priv
, "udi_send_signal_raw: Not enough data (%d instead of %d)\n", buflen
, bytecount
);
702 /* Send the signal calling the function that uses the wire-formatted signals. */
703 r
= ul_send_signal_raw(priv
, buf
, signal_size
, &data_ptrs
);
705 unifi_error(priv
, "udi_send_signal_raw: send failed (%d)\n", r
);
709 #ifdef CSR_NATIVE_LINUX
710 if (sig_id
== CSR_MLME_POWERMGT_REQUEST_ID
) {
711 int power_mode
= CSR_GET_UINT16_FROM_LITTLE_ENDIAN((buf
+
712 SIZEOF_SIGNAL_HEADER
+ (UNIFI_MAX_DATA_REFERENCES
*SIZEOF_DATAREF
)));
713 #ifdef CSR_SUPPORT_WEXT
714 /* Overide the wext power mode to the new value */
715 priv
->wext_conf
.power_mode
= power_mode
;
717 /* Configure deep sleep signaling */
718 if (power_mode
|| (priv
->interfacePriv
[0]->connected
== UnifiNotConnected
)) {
719 csrResult
= unifi_configure_low_power_mode(priv
->card
,
720 UNIFI_LOW_POWER_ENABLED
,
721 UNIFI_PERIODIC_WAKE_HOST_DISABLED
);
723 csrResult
= unifi_configure_low_power_mode(priv
->card
,
724 UNIFI_LOW_POWER_DISABLED
,
725 UNIFI_PERIODIC_WAKE_HOST_DISABLED
);
731 } /* udi_send_signal_raw */
734 * ---------------------------------------------------------------------------
737 * The write() driver entry point.
738 * A UniFi Debug Interface client such as unicli can write a signal
739 * plus bulk data to the driver for sending to the UniFi chip.
741 * Only one signal may be sent per write operation.
744 * filp The file descriptor returned by unifi_open()
745 * p The user space buffer to get the data from
746 * len The size of the p buffer
750 * number of bytes written or an error code on failure
751 * ---------------------------------------------------------------------------
754 unifi_write(struct file
*filp
, const char *p
, size_t len
, loff_t
*poff
)
756 ul_client_t
*pcli
= (ul_client_t
*)filp
->private_data
;
759 unsigned char *bufptr
;
763 bulk_data_param_t bulkdata
;
766 priv
= uf_find_instance(pcli
->instance
);
768 unifi_error(priv
, "invalid priv\n");
772 unifi_trace(priv
, UDBG5
, "unifi_write: len = %d\n", len
);
774 if (!pcli
->udi_enabled
) {
775 unifi_error(priv
, "udi disabled\n");
780 * AMP client sends only one signal at a time, so we can use
781 * unifi_net_data_malloc to save the extra copy.
783 if (pcli
== priv
->amp_client
) {
786 unsigned char *signal_buf
;
789 csrResult
= unifi_net_data_malloc(priv
, &bulkdata
.d
[0], len
);
790 if (csrResult
!= CSR_RESULT_SUCCESS
) {
791 unifi_error(priv
, "unifi_write: failed to allocate request_data.\n");
795 user_data_buf
= (char*)bulkdata
.d
[0].os_data_ptr
;
797 /* Get the data from the AMP client. */
798 if (copy_from_user((void*)user_data_buf
, p
, len
)) {
799 unifi_error(priv
, "unifi_write: copy from user failed\n");
800 unifi_net_data_free(priv
, &bulkdata
.d
[0]);
804 bulkdata
.d
[1].os_data_ptr
= NULL
;
805 bulkdata
.d
[1].data_length
= 0;
807 /* Number of bytes in the signal */
808 sig_id
= GET_SIGNAL_ID(bulkdata
.d
[0].os_data_ptr
);
810 signal_size
-= GET_PACKED_DATAREF_LEN(bulkdata
.d
[0].os_data_ptr
, 0);
811 signal_size
-= GET_PACKED_DATAREF_LEN(bulkdata
.d
[0].os_data_ptr
, 1);
812 if ((signal_size
<= 0) || (signal_size
> len
)) {
813 unifi_error(priv
, "unifi_write - Couldn't find length of signal 0x%x\n",
815 unifi_net_data_free(priv
, &bulkdata
.d
[0]);
819 unifi_trace(priv
, UDBG2
, "unifi_write: signal 0x%.4X len:%d\n",
820 sig_id
, signal_size
);
822 /* Allocate a buffer for the signal */
823 signal_buf
= kmalloc(signal_size
, GFP_KERNEL
);
825 unifi_net_data_free(priv
, &bulkdata
.d
[0]);
829 /* Get the signal from the os_data_ptr */
830 memcpy(signal_buf
, bulkdata
.d
[0].os_data_ptr
, signal_size
);
831 signal_buf
[5] = (pcli
->sender_id
>> 8) & 0xff;
833 if (signal_size
< len
) {
834 /* Remove the signal from the os_data_ptr */
835 bulkdata
.d
[0].data_length
-= signal_size
;
836 bulkdata
.d
[0].os_data_ptr
+= signal_size
;
838 bulkdata
.d
[0].data_length
= 0;
839 bulkdata
.d
[0].os_data_ptr
= NULL
;
842 /* Send the signal calling the function that uses the wire-formatted signals. */
843 r
= ul_send_signal_raw(priv
, signal_buf
, signal_size
, &bulkdata
);
845 unifi_error(priv
, "unifi_write: send failed (%d)\n", r
);
846 if (bulkdata
.d
[0].os_data_ptr
!= NULL
) {
847 unifi_net_data_free(priv
, &bulkdata
.d
[0]);
851 /* Free the signal buffer and return */
856 buf
= kmalloc(len
, GFP_KERNEL
);
861 /* Get the data from the client (SME or Unicli). */
862 if (copy_from_user((void*)buf
, p
, len
)) {
863 unifi_error(priv
, "copy from user failed\n");
869 * In SME userspace build read() contains a SYS or MGT message.
870 * Note that even though the SME sends one signal at a time, we can not
871 * use unifi_net_data_malloc because in the early stages, before having
872 * initialised the core, it will fail since the I/O block size is unknown.
874 #ifdef CSR_SME_USERSPACE
875 if (pcli
->configuration
& CLI_SME_USERSPACE
) {
876 CsrWifiRouterTransportRecv(priv
, buf
, len
);
882 /* ul_send_signal_raw will do a sanity check of len against signal content */
885 * udi_send_signal_raw() and udi_send_signal_unpacked() return the number of bytes consumed.
886 * A write call can pass multiple signal concatenated together.
891 while (remaining
> 0)
896 * Set the SenderProcessId.
897 * The SignalPrimitiveHeader is the first 3 16-bit words of the signal,
898 * the SenderProcessId is bytes 4,5.
899 * The MSB of the sender ID needs to be set to the client ID.
900 * The LSB is controlled by the SME.
902 bufptr
[5] = (pcli
->sender_id
>> 8) & 0xff;
904 /* use the appropriate interface, depending on the clients' configuration */
905 if (pcli
->configuration
& CLI_USING_WIRE_FORMAT
) {
906 unifi_trace(priv
, UDBG1
, "unifi_write: call udi_send_signal().\n");
907 r
= udi_send_signal_raw(priv
, bufptr
, remaining
);
909 r
= udi_send_signal_unpacked(priv
, bufptr
, remaining
);
912 /* Set the return value to the error code */
913 unifi_error(priv
, "unifi_write: (udi or sme)_send_signal() returns %d\n", r
);
924 return bytes_written
;
925 } /* unifi_write() */
928 static const char* build_type_to_string(unsigned char build_type
)
932 case UNIFI_BUILD_NME
: return "NME";
933 case UNIFI_BUILD_WEXT
: return "WEXT";
934 case UNIFI_BUILD_AP
: return "AP";
941 * ----------------------------------------------------------------
944 * Ioctl handler for unifi driver.
947 * inodep Pointer to inode structure.
948 * filp Pointer to file structure.
949 * cmd Ioctl cmd passed by user.
950 * arg Ioctl arg passed by user.
953 * 0 on success, -ve error code on error.
954 * ----------------------------------------------------------------
957 unifi_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
)
959 ul_client_t
*pcli
= (ul_client_t
*)filp
->private_data
;
961 struct net_device
*dev
;
966 #if (defined CSR_SUPPORT_SME)
967 unifi_cfg_command_t cfg_cmd
;
968 #if (defined CSR_SUPPORT_WEXT)
969 CsrWifiSmeCoexConfig coex_config
;
970 unsigned char uchar_param
;
971 unsigned char varbind
[MAX_VARBIND_LENGTH
];
975 unifi_putest_command_t putest_cmd
;
977 priv
= uf_find_instance(pcli
->instance
);
979 unifi_error(priv
, "ioctl error: unknown instance=%d\n", pcli
->instance
);
983 unifi_trace(priv
, UDBG5
, "unifi_ioctl: cmd=0x%X, arg=0x%lX\n", cmd
, arg
);
987 case UNIFI_GET_UDI_ENABLE
:
988 unifi_trace(priv
, UDBG4
, "UniFi Get UDI Enable\n");
990 down(&priv
->udi_logging_mutex
);
991 int_param
= (priv
->logging_client
== NULL
) ? 0 : 1;
992 up(&priv
->udi_logging_mutex
);
994 if (put_user(int_param
, (int*)arg
))
996 unifi_error(priv
, "UNIFI_GET_UDI_ENABLE: Failed to copy to user\n");
1002 case UNIFI_SET_UDI_ENABLE
:
1003 unifi_trace(priv
, UDBG4
, "UniFi Set UDI Enable\n");
1004 if (get_user(int_param
, (int*)arg
))
1006 unifi_error(priv
, "UNIFI_SET_UDI_ENABLE: Failed to copy from user\n");
1011 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
1012 if (log_hip_signals
) {
1013 unifi_error(priv
, "omnicli cannot be used when log_hip_signals is used\n");
1019 down(&priv
->udi_logging_mutex
);
1021 pcli
->event_hook
= udi_log_event
;
1022 unifi_set_udi_hook(priv
->card
, logging_handler
);
1023 /* Log all signals by default */
1024 for (i
= 0; i
< SIG_FILTER_SIZE
; i
++) {
1025 pcli
->signal_filter
[i
] = 0xFFFF;
1027 priv
->logging_client
= pcli
;
1030 priv
->logging_client
= NULL
;
1031 pcli
->event_hook
= NULL
;
1033 up(&priv
->udi_logging_mutex
);
1038 unifi_trace(priv
, UDBG4
, "UniFi Set MIB\n");
1039 #if (defined CSR_SUPPORT_SME) && (defined CSR_SUPPORT_WEXT)
1040 /* Read first 2 bytes and check length */
1041 if (copy_from_user((void*)varbind
, (void*)arg
, 2)) {
1043 "UNIFI_SET_MIB: Failed to copy in varbind header\n");
1048 if ((vblen
+ 2) > MAX_VARBIND_LENGTH
) {
1050 "UNIFI_SET_MIB: Varbind too long (%d, limit %d)\n",
1051 (vblen
+2), MAX_VARBIND_LENGTH
);
1055 /* Read rest of varbind */
1056 if (copy_from_user((void*)(varbind
+2), (void*)(arg
+2), vblen
)) {
1057 unifi_error(priv
, "UNIFI_SET_MIB: Failed to copy in varbind\n");
1064 r
= sme_mgt_mib_set(priv
, varbind
, vblen
);
1069 unifi_notice(priv
, "UNIFI_SET_MIB: Unsupported.\n");
1070 #endif /* CSR_SUPPORT_WEXT */
1074 unifi_trace(priv
, UDBG4
, "UniFi Get MIB\n");
1075 #if (defined CSR_SUPPORT_SME) && (defined CSR_SUPPORT_WEXT)
1076 /* Read first 2 bytes and check length */
1077 if (copy_from_user((void*)varbind
, (void*)arg
, 2)) {
1078 unifi_error(priv
, "UNIFI_GET_MIB: Failed to copy in varbind header\n");
1083 if ((vblen
+2) > MAX_VARBIND_LENGTH
) {
1084 unifi_error(priv
, "UNIFI_GET_MIB: Varbind too long (%d, limit %d)\n",
1085 (vblen
+2), MAX_VARBIND_LENGTH
);
1089 /* Read rest of varbind */
1090 if (copy_from_user((void*)(varbind
+2), (void*)(arg
+2), vblen
)) {
1091 unifi_error(priv
, "UNIFI_GET_MIB: Failed to copy in varbind\n");
1097 r
= sme_mgt_mib_get(priv
, varbind
, &vblen
);
1101 /* copy out varbind */
1102 if (vblen
> MAX_VARBIND_LENGTH
) {
1104 "UNIFI_GET_MIB: Varbind result too long (%d, limit %d)\n",
1105 vblen
, MAX_VARBIND_LENGTH
);
1109 if (copy_to_user((void*)arg
, varbind
, vblen
)) {
1114 unifi_notice(priv
, "UNIFI_GET_MIB: Unsupported.\n");
1115 #endif /* CSR_SUPPORT_WEXT */
1119 #if (defined CSR_SUPPORT_SME)
1120 if (get_user(cfg_cmd
, (unifi_cfg_command_t
*)arg
))
1122 unifi_error(priv
, "UNIFI_CFG: Failed to get the command\n");
1127 unifi_trace(priv
, UDBG1
, "UNIFI_CFG: Command is %d (t=%u) sz=%d\n",
1128 cfg_cmd
, jiffies_to_msecs(jiffies
), sizeof(unifi_cfg_command_t
));
1130 case UNIFI_CFG_POWER
:
1131 r
= unifi_cfg_power(priv
, (unsigned char*)arg
);
1133 case UNIFI_CFG_POWERSAVE
:
1134 r
= unifi_cfg_power_save(priv
, (unsigned char*)arg
);
1136 case UNIFI_CFG_POWERSUPPLY
:
1137 r
= unifi_cfg_power_supply(priv
, (unsigned char*)arg
);
1139 case UNIFI_CFG_FILTER
:
1140 r
= unifi_cfg_packet_filters(priv
, (unsigned char*)arg
);
1143 r
= unifi_cfg_get_info(priv
, (unsigned char*)arg
);
1145 case UNIFI_CFG_WMM_QOSINFO
:
1146 r
= unifi_cfg_wmm_qos_info(priv
, (unsigned char*)arg
);
1148 case UNIFI_CFG_WMM_ADDTS
:
1149 r
= unifi_cfg_wmm_addts(priv
, (unsigned char*)arg
);
1151 case UNIFI_CFG_WMM_DELTS
:
1152 r
= unifi_cfg_wmm_delts(priv
, (unsigned char*)arg
);
1154 case UNIFI_CFG_STRICT_DRAFT_N
:
1155 r
= unifi_cfg_strict_draft_n(priv
, (unsigned char*)arg
);
1157 case UNIFI_CFG_ENABLE_OKC
:
1158 r
= unifi_cfg_enable_okc(priv
, (unsigned char*)arg
);
1160 #ifdef CSR_SUPPORT_SME
1161 case UNIFI_CFG_CORE_DUMP
:
1162 CsrWifiRouterCtrlWifiOffIndSend(priv
->CSR_WIFI_SME_IFACEQUEUE
,0,CSR_WIFI_SME_CONTROL_INDICATION_ERROR
);
1163 unifi_trace(priv
, UDBG2
, "UNIFI_CFG_CORE_DUMP: sent wifi off indication\n");
1166 #ifdef CSR_SUPPORT_WEXT_AP
1167 case UNIFI_CFG_SET_AP_CONFIG
:
1168 r
= unifi_cfg_set_ap_config(priv
,(unsigned char*)arg
);
1172 unifi_error(priv
, "UNIFI_CFG: Unknown Command (%d)\n", cfg_cmd
);
1181 if (get_user(putest_cmd
, (unifi_putest_command_t
*)arg
))
1183 unifi_error(priv
, "UNIFI_PUTEST: Failed to get the command\n");
1188 unifi_trace(priv
, UDBG1
, "UNIFI_PUTEST: Command is %s\n",
1189 trace_putest_cmdid(putest_cmd
));
1190 switch (putest_cmd
) {
1191 case UNIFI_PUTEST_START
:
1192 r
= unifi_putest_start(priv
, (unsigned char*)arg
);
1194 case UNIFI_PUTEST_STOP
:
1195 r
= unifi_putest_stop(priv
, (unsigned char*)arg
);
1197 case UNIFI_PUTEST_SET_SDIO_CLOCK
:
1198 r
= unifi_putest_set_sdio_clock(priv
, (unsigned char*)arg
);
1200 case UNIFI_PUTEST_CMD52_READ
:
1201 r
= unifi_putest_cmd52_read(priv
, (unsigned char*)arg
);
1203 case UNIFI_PUTEST_CMD52_BLOCK_READ
:
1204 r
= unifi_putest_cmd52_block_read(priv
, (unsigned char*)arg
);
1206 case UNIFI_PUTEST_CMD52_WRITE
:
1207 r
= unifi_putest_cmd52_write(priv
, (unsigned char*)arg
);
1209 case UNIFI_PUTEST_DL_FW
:
1210 r
= unifi_putest_dl_fw(priv
, (unsigned char*)arg
);
1212 case UNIFI_PUTEST_DL_FW_BUFF
:
1213 r
= unifi_putest_dl_fw_buff(priv
, (unsigned char*)arg
);
1215 case UNIFI_PUTEST_COREDUMP_PREPARE
:
1216 r
= unifi_putest_coredump_prepare(priv
, (unsigned char*)arg
);
1218 case UNIFI_PUTEST_GP_READ16
:
1219 r
= unifi_putest_gp_read16(priv
, (unsigned char*)arg
);
1221 case UNIFI_PUTEST_GP_WRITE16
:
1222 r
= unifi_putest_gp_write16(priv
, (unsigned char*)arg
);
1225 unifi_error(priv
, "UNIFI_PUTEST: Unknown Command (%d)\n", putest_cmd
);
1231 case UNIFI_BUILD_TYPE
:
1232 unifi_trace(priv
, UDBG2
, "UNIFI_BUILD_TYPE userspace=%s\n", build_type_to_string(*(unsigned char*)arg
));
1233 #ifndef CSR_SUPPORT_WEXT_AP
1234 if (UNIFI_BUILD_AP
== *(unsigned char*)arg
)
1236 unifi_error(priv
, "Userspace has AP support, which is incompatible\n");
1240 #ifndef CSR_SUPPORT_WEXT
1241 if (UNIFI_BUILD_WEXT
== *(unsigned char*)arg
)
1243 unifi_error(priv
, "Userspace has WEXT support, which is incompatible\n");
1248 unifi_trace(priv
, UDBG2
, "UNIFI_INIT_HW.\n");
1249 priv
->init_progress
= UNIFI_INIT_NONE
;
1251 #if defined(CSR_SUPPORT_WEXT) || defined (CSR_NATIVE_LINUX)
1252 /* At this point we are ready to start the SME. */
1253 r
= sme_mgt_wifi_on(priv
);
1261 case UNIFI_INIT_NETDEV
:
1263 /* get the proper interfaceTagId */
1265 netInterface_priv_t
*interfacePriv
= priv
->interfacePriv
[interfaceTag
];
1267 dev
= priv
->netdev
[interfaceTag
];
1268 unifi_trace(priv
, UDBG2
, "UNIFI_INIT_NETDEV.\n");
1270 if (copy_from_user((void*)dev
->dev_addr
, (void*)arg
, 6)) {
1275 /* Attach the network device to the stack */
1276 if (!interfacePriv
->netdev_registered
)
1278 r
= uf_register_netdev(priv
,interfaceTag
);
1280 unifi_error(priv
, "Failed to register the network device.\n");
1285 /* Apply scheduled interrupt mode, if requested by module param */
1286 if (run_bh_once
!= -1) {
1287 unifi_set_interrupt_mode(priv
->card
, (u32
)run_bh_once
);
1290 priv
->init_progress
= UNIFI_INIT_COMPLETED
;
1292 /* Firmware initialisation is complete, so let the SDIO bus
1293 * clock be raised when convienent to the core.
1295 unifi_request_max_sdio_clock(priv
->card
);
1297 #ifdef CSR_SUPPORT_WEXT
1298 /* Notify the Android wpa_supplicant that we are ready */
1299 wext_send_started_event(priv
);
1302 unifi_info(priv
, "UniFi ready\n");
1304 #ifdef ANDROID_BUILD
1305 /* Release the wakelock */
1306 unifi_trace(priv
, UDBG1
, "netdev_init: release wake lock\n");
1307 wake_unlock(&unifi_sdio_wake_lock
);
1309 #ifdef CSR_NATIVE_SOFTMAC /* For softmac dev, force-enable the network interface rather than wait for a connected-ind */
1311 struct net_device
*dev
= priv
->netdev
[interfaceTag
];
1312 #ifdef CSR_SUPPORT_WEXT
1313 interfacePriv
->wait_netdev_change
= TRUE
;
1315 netif_carrier_on(dev
);
1320 case UNIFI_GET_INIT_STATUS
:
1321 unifi_trace(priv
, UDBG2
, "UNIFI_GET_INIT_STATUS.\n");
1322 if (put_user(priv
->init_progress
, (int*)arg
))
1324 printk(KERN_ERR
"UNIFI_GET_INIT_STATUS: Failed to copy to user\n");
1331 unifi_trace(priv
, UDBG4
, "Kick UniFi\n");
1332 unifi_sdio_interrupt_handler(priv
->card
);
1335 case UNIFI_SET_DEBUG
:
1337 unifi_trace(priv
, UDBG4
, "unifi_debug set to %d\n", unifi_debug
);
1340 case UNIFI_SET_TRACE
:
1341 /* no longer supported */
1346 case UNIFI_SET_UDI_LOG_MASK
:
1348 unifiio_filter_t udi_filter
;
1349 uint16_t *sig_ids_addr
;
1350 #define UF_MAX_SIG_IDS 128 /* Impose a sensible limit */
1352 if (copy_from_user((void*)(&udi_filter
), (void*)arg
, sizeof(udi_filter
))) {
1356 if ((udi_filter
.action
< UfSigFil_AllOn
) ||
1357 (udi_filter
.action
> UfSigFil_SelectOff
))
1360 "UNIFI_SET_UDI_LOG_MASK: Bad action value: %d\n",
1365 /* No signal list for "All" actions */
1366 if ((udi_filter
.action
== UfSigFil_AllOn
) ||
1367 (udi_filter
.action
== UfSigFil_AllOff
))
1369 udi_filter
.num_sig_ids
= 0;
1372 if (udi_filter
.num_sig_ids
> UF_MAX_SIG_IDS
) {
1374 "UNIFI_SET_UDI_LOG_MASK: too many signal ids (%d, max %d)\n",
1375 udi_filter
.num_sig_ids
, UF_MAX_SIG_IDS
);
1380 /* Copy in signal id list if given */
1381 if (udi_filter
.num_sig_ids
> 0) {
1382 /* Preserve userspace address of sig_ids array */
1383 sig_ids_addr
= udi_filter
.sig_ids
;
1384 /* Allocate kernel memory for sig_ids and copy to it */
1385 udi_filter
.sig_ids
=
1386 kmalloc(udi_filter
.num_sig_ids
* sizeof(uint16_t), GFP_KERNEL
);
1387 if (!udi_filter
.sig_ids
) {
1391 if (copy_from_user((void*)udi_filter
.sig_ids
,
1392 (void*)sig_ids_addr
,
1393 udi_filter
.num_sig_ids
* sizeof(uint16_t)))
1395 kfree(udi_filter
.sig_ids
);
1401 udi_set_log_filter(pcli
, &udi_filter
);
1403 if (udi_filter
.num_sig_ids
> 0) {
1404 kfree(udi_filter
.sig_ids
);
1409 case UNIFI_SET_AMP_ENABLE
:
1410 unifi_trace(priv
, UDBG4
, "UniFi Set AMP Enable\n");
1411 if (get_user(int_param
, (int*)arg
))
1413 unifi_error(priv
, "UNIFI_SET_AMP_ENABLE: Failed to copy from user\n");
1419 priv
->amp_client
= pcli
;
1421 priv
->amp_client
= NULL
;
1425 buf
= (u8
*)&int_param
;
1426 buf
[0] = UNIFI_SOFT_COMMAND_Q_LENGTH
- 1;
1427 buf
[1] = UNIFI_SOFT_TRAFFIC_Q_LENGTH
- 1;
1428 if (copy_to_user((void*)arg
, &int_param
, sizeof(int))) {
1434 case UNIFI_SET_UDI_SNAP_MASK
:
1436 unifiio_snap_filter_t snap_filter
;
1438 if (copy_from_user((void*)(&snap_filter
), (void*)arg
, sizeof(snap_filter
))) {
1443 if (pcli
->snap_filter
.count
) {
1444 pcli
->snap_filter
.count
= 0;
1445 kfree(pcli
->snap_filter
.protocols
);
1448 if (snap_filter
.count
== 0) {
1452 pcli
->snap_filter
.protocols
= kmalloc(snap_filter
.count
* sizeof(u16
), GFP_KERNEL
);
1453 if (!pcli
->snap_filter
.protocols
) {
1457 if (copy_from_user((void*)pcli
->snap_filter
.protocols
,
1458 (void*)snap_filter
.protocols
,
1459 snap_filter
.count
* sizeof(u16
)))
1461 kfree(pcli
->snap_filter
.protocols
);
1466 pcli
->snap_filter
.count
= snap_filter
.count
;
1471 case UNIFI_SME_PRESENT
:
1474 unifi_trace(priv
, UDBG4
, "UniFi SME Present IOCTL.\n");
1475 if (copy_from_user((void*)(&int_param
), (void*)arg
, sizeof(int)))
1477 printk(KERN_ERR
"UNIFI_SME_PRESENT: Failed to copy from user\n");
1482 priv
->sme_is_present
= int_param
;
1483 if (priv
->sme_is_present
== 1) {
1484 ind
= CONFIG_SME_PRESENT
;
1486 ind
= CONFIG_SME_NOT_PRESENT
;
1488 /* Send an indication to the helper app. */
1489 ul_log_config_ind(priv
, &ind
, sizeof(u8
));
1493 case UNIFI_CFG_PERIOD_TRAFFIC
:
1495 #if (defined CSR_SUPPORT_SME) && (defined CSR_SUPPORT_WEXT)
1496 CsrWifiSmeCoexConfig coexConfig
;
1497 #endif /* CSR_SUPPORT_SME && CSR_SUPPORT_WEXT */
1498 unifi_trace(priv
, UDBG4
, "UniFi Configure Periodic Traffic.\n");
1499 #if (defined CSR_SUPPORT_SME) && (defined CSR_SUPPORT_WEXT)
1500 if (copy_from_user((void*)(&uchar_param
), (void*)arg
, sizeof(unsigned char))) {
1501 unifi_error(priv
, "UNIFI_CFG_PERIOD_TRAFFIC: Failed to copy from user\n");
1506 if (uchar_param
== 0) {
1507 r
= sme_mgt_coex_config_get(priv
, &coexConfig
);
1509 unifi_error(priv
, "UNIFI_CFG_PERIOD_TRAFFIC: Get unifi_CoexInfoValue failed.\n");
1512 if (copy_to_user((void*)(arg
+ 1),
1514 sizeof(CsrWifiSmeCoexConfig
))) {
1521 if (copy_from_user((void*)(&coex_config
), (void*)(arg
+ 1), sizeof(CsrWifiSmeCoexConfig
)))
1523 unifi_error(priv
, "UNIFI_CFG_PERIOD_TRAFFIC: Failed to copy from user\n");
1528 coexConfig
= coex_config
;
1529 r
= sme_mgt_coex_config_set(priv
, &coexConfig
);
1531 unifi_error(priv
, "UNIFI_CFG_PERIOD_TRAFFIC: Set unifi_CoexInfoValue failed.\n");
1535 #endif /* CSR_SUPPORT_SME && CSR_SUPPORT_WEXT */
1538 case UNIFI_CFG_UAPSD_TRAFFIC
:
1539 unifi_trace(priv
, UDBG4
, "UniFi Configure U-APSD Mask.\n");
1540 #if (defined CSR_SUPPORT_SME) && (defined CSR_SUPPORT_WEXT)
1541 if (copy_from_user((void*)(&uchar_param
), (void*)arg
, sizeof(unsigned char))) {
1542 unifi_error(priv
, "UNIFI_CFG_UAPSD_TRAFFIC: Failed to copy from user\n");
1546 unifi_trace(priv
, UDBG4
, "New U-APSD Mask: 0x%x\n", uchar_param
);
1547 #endif /* CSR_SUPPORT_SME && CSR_SUPPORT_WEXT */
1550 #ifndef UNIFI_DISABLE_COREDUMP
1551 case UNIFI_COREDUMP_GET_REG
:
1552 unifi_trace(priv
, UDBG4
, "Mini-coredump data request\n");
1554 unifiio_coredump_req_t dump_req
; /* Public OS layer structure */
1555 unifi_coredump_req_t priv_req
; /* Private HIP structure */
1557 if (copy_from_user((void*)(&dump_req
), (void*)arg
, sizeof(dump_req
))) {
1561 memset(&priv_req
, 0, sizeof(priv_req
));
1562 priv_req
.index
= dump_req
.index
;
1563 priv_req
.offset
= dump_req
.offset
;
1565 /* Convert OS-layer's XAP memory space ID to HIP's ID in case they differ */
1566 switch (dump_req
.space
) {
1567 case UNIFIIO_COREDUMP_MAC_REG
: priv_req
.space
= UNIFI_COREDUMP_MAC_REG
; break;
1568 case UNIFIIO_COREDUMP_PHY_REG
: priv_req
.space
= UNIFI_COREDUMP_PHY_REG
; break;
1569 case UNIFIIO_COREDUMP_SH_DMEM
: priv_req
.space
= UNIFI_COREDUMP_SH_DMEM
; break;
1570 case UNIFIIO_COREDUMP_MAC_DMEM
: priv_req
.space
= UNIFI_COREDUMP_MAC_DMEM
; break;
1571 case UNIFIIO_COREDUMP_PHY_DMEM
: priv_req
.space
= UNIFI_COREDUMP_PHY_DMEM
; break;
1572 case UNIFIIO_COREDUMP_TRIGGER_MAGIC
: priv_req
.space
= UNIFI_COREDUMP_TRIGGER_MAGIC
; break;
1578 if (priv_req
.space
== UNIFI_COREDUMP_TRIGGER_MAGIC
) {
1579 /* Force a coredump grab now */
1580 unifi_trace(priv
, UDBG2
, "UNIFI_COREDUMP_GET_REG: Force capture\n");
1581 csrResult
= unifi_coredump_capture(priv
->card
, &priv_req
);
1582 r
= CsrHipResultToStatus(csrResult
);
1583 unifi_trace(priv
, UDBG5
, "UNIFI_COREDUMP_GET_REG: status %d\n", r
);
1585 /* Retrieve the appropriate register entry */
1586 csrResult
= unifi_coredump_get_value(priv
->card
, &priv_req
);
1587 r
= CsrHipResultToStatus(csrResult
);
1589 unifi_trace(priv
, UDBG5
, "UNIFI_COREDUMP_GET_REG: Status %d\n", r
);
1592 /* Update the OS-layer structure with values returned in the private */
1593 dump_req
.value
= priv_req
.value
;
1594 dump_req
.timestamp
= priv_req
.timestamp
;
1595 dump_req
.requestor
= priv_req
.requestor
;
1596 dump_req
.serial
= priv_req
.serial
;
1597 dump_req
.chip_ver
= priv_req
.chip_ver
;
1598 dump_req
.fw_ver
= priv_req
.fw_ver
;
1599 dump_req
.drv_build
= 0;
1601 unifi_trace(priv
, UDBG6
,
1602 "Dump: %d (seq %d): V:0x%04x (%d) @0x%02x:%04x = 0x%04x\n",
1603 dump_req
.index
, dump_req
.serial
,
1604 dump_req
.chip_ver
, dump_req
.drv_build
,
1605 dump_req
.space
, dump_req
.offset
, dump_req
.value
);
1607 if (copy_to_user((void*)arg
, (void*)&dump_req
, sizeof(dump_req
))) {
1620 } /* unifi_ioctl() */
1625 unifi_poll(struct file
*filp
, poll_table
*wait
)
1627 ul_client_t
*pcli
= (ul_client_t
*)filp
->private_data
;
1628 unsigned int mask
= 0;
1631 ready
= !list_empty(&pcli
->udi_log
);
1633 poll_wait(filp
, &pcli
->udi_wq
, wait
);
1636 mask
|= POLLIN
| POLLRDNORM
; /* readable */
1640 } /* unifi_poll() */
1645 * ---------------------------------------------------------------------------
1646 * udi_set_log_filter
1648 * Configure the bit mask that determines which signal primitives are
1649 * passed to the logging process.
1652 * pcli Pointer to the client to configure.
1653 * udi_filter Pointer to a unifiio_filter_t containing instructions.
1659 * SigGetFilterPos() returns a 32-bit value that contains an index and a
1660 * mask for accessing a signal_filter array. The top 16 bits specify an
1661 * index into a signal_filter, the bottom 16 bits specify a mask to
1663 * ---------------------------------------------------------------------------
1666 udi_set_log_filter(ul_client_t
*pcli
, unifiio_filter_t
*udi_filter
)
1671 if (udi_filter
->action
== UfSigFil_AllOn
)
1673 for (i
= 0; i
< SIG_FILTER_SIZE
; i
++) {
1674 pcli
->signal_filter
[i
] = 0xFFFF;
1677 else if (udi_filter
->action
== UfSigFil_AllOff
)
1679 for (i
= 0; i
< SIG_FILTER_SIZE
; i
++) {
1680 pcli
->signal_filter
[i
] = 0;
1683 else if (udi_filter
->action
== UfSigFil_SelectOn
)
1685 for (i
= 0; i
< udi_filter
->num_sig_ids
; i
++) {
1686 filter_pos
= SigGetFilterPos(udi_filter
->sig_ids
[i
]);
1687 if (filter_pos
== 0xFFFFFFFF)
1690 "Unrecognised signal id (0x%X) specifed in logging filter\n",
1691 udi_filter
->sig_ids
[i
]);
1693 pcli
->signal_filter
[filter_pos
>> 16] |= (filter_pos
& 0xFFFF);
1697 else if (udi_filter
->action
== UfSigFil_SelectOff
)
1699 for (i
= 0; i
< udi_filter
->num_sig_ids
; i
++) {
1700 filter_pos
= SigGetFilterPos(udi_filter
->sig_ids
[i
]);
1701 if (filter_pos
== 0xFFFFFFFF)
1704 "Unrecognised signal id (0x%X) specifed in logging filter\n",
1705 udi_filter
->sig_ids
[i
]);
1707 pcli
->signal_filter
[filter_pos
>> 16] &= ~(filter_pos
& 0xFFFF);
1712 } /* udi_set_log_filter() */
1716 * ---------------------------------------------------------------------------
1719 * Callback function to be registered as the UDI hook callback.
1720 * Copies the signal content into a new udi_log_t struct and adds
1721 * it to the read queue for this UDI client.
1724 * pcli A pointer to the client instance.
1725 * signal Pointer to the received signal.
1726 * signal_len Size of the signal structure in bytes.
1727 * bulkdata Pointers to any associated bulk data.
1728 * dir Direction of the signal. Zero means from host,
1729 * non-zero means to host.
1733 * ---------------------------------------------------------------------------
1736 udi_log_event(ul_client_t
*pcli
,
1737 const u8
*signal
, int signal_len
,
1738 const bulk_data_param_t
*bulkdata
,
1747 #ifdef OMNICLI_LINUX_EXTRA_LOG
1748 static volatile unsigned int printk_cpu
= UINT_MAX
;
1749 unsigned long long t
;
1750 unsigned long nanosec_rem
;
1751 unsigned long n_1000
;
1754 /* Just a sanity check */
1755 if ((signal
== NULL
) || (signal_len
<= 0)) {
1759 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
1760 /* When HIP offline signal logging is enabled, omnicli cannot run */
1761 if (log_hip_signals
)
1764 if (log_hip_signals
& UNIFI_LOG_HIP_SIGNALS_FILTER_TIMESTAMP
)
1766 int timestamp
= jiffies_to_msecs(jiffies
);
1767 unifi_debug_log_to_buf("T:");
1768 unifi_debug_log_to_buf("%04X%04X ", *(((u16
*)×tamp
) + 1),
1773 unifi_debug_log_to_buf("S%s:%04X R:%04X D:%04X ",
1776 *(u16
*)(signal
+ 2),
1777 *(u16
*)(signal
+ 4));
1778 unifi_debug_hex_to_buf(signal
+ 6, signal_len
- 6);
1780 /* Add bulk data (assume 1 bulk data per signal) */
1781 if ((log_hip_signals
& UNIFI_LOG_HIP_SIGNALS_FILTER_BULKDATA
) &&
1782 (bulkdata
->d
[0].data_length
> 0))
1784 unifi_debug_log_to_buf("\nD:");
1785 unifi_debug_hex_to_buf(bulkdata
->d
[0].os_data_ptr
, bulkdata
->d
[0].data_length
);
1787 unifi_debug_log_to_buf("\n");
1793 #ifdef CSR_NATIVE_LINUX
1794 uf_native_process_udi_signal(pcli
, signal
, signal_len
, bulkdata
, dir
);
1798 * Apply the logging filter - only report signals that have their
1799 * bit set in the filter mask.
1801 filter_pos
= SigGetFilterPos(GET_SIGNAL_ID(signal
));
1803 if ((filter_pos
!= 0xFFFFFFFF) &&
1804 ((pcli
->signal_filter
[filter_pos
>> 16] & (filter_pos
& 0xFFFF)) == 0))
1806 /* Signal is not wanted by client */
1811 /* Calculate the buffer we need to store signal plus bulk data */
1812 total_len
= signal_len
;
1813 for (i
= 0; i
< UNIFI_MAX_DATA_REFERENCES
; i
++) {
1814 total_len
+= bulkdata
->d
[i
].data_length
;
1817 /* Allocate log structure plus actual signal. */
1818 logptr
= (udi_log_t
*)kmalloc(sizeof(udi_log_t
) + total_len
, GFP_KERNEL
);
1820 if (logptr
== NULL
) {
1822 "Failed to allocate %lu bytes for a UDI log record\n",
1823 (long unsigned int)(sizeof(udi_log_t
) + total_len
));
1827 /* Fill in udi_log struct */
1828 INIT_LIST_HEAD(&logptr
->q
);
1829 msgptr
= &logptr
->msg
;
1830 msgptr
->length
= sizeof(udi_msg_t
) + total_len
;
1831 #ifdef OMNICLI_LINUX_EXTRA_LOG
1832 t
= cpu_clock(printk_cpu
);
1833 nanosec_rem
= do_div(t
, 1000000000);
1834 n_1000
= nanosec_rem
/1000;
1835 msgptr
->timestamp
= (t
<<10 ) | ((unsigned long)(n_1000
>> 10) & 0x3ff);
1837 msgptr
->timestamp
= jiffies_to_msecs(jiffies
);
1839 msgptr
->direction
= dir
;
1840 msgptr
->signal_length
= signal_len
;
1842 /* Copy signal and bulk data to the log */
1843 p
= (u8
*)(msgptr
+ 1);
1844 memcpy(p
, signal
, signal_len
);
1847 /* Append any bulk data */
1848 for (i
= 0; i
< UNIFI_MAX_DATA_REFERENCES
; i
++) {
1849 int len
= bulkdata
->d
[i
].data_length
;
1852 * Len here might not be the same as the length in the bulk data slot.
1853 * The slot length will always be even, but len could be odd.
1856 if (bulkdata
->d
[i
].os_data_ptr
) {
1857 memcpy(p
, bulkdata
->d
[i
].os_data_ptr
, len
);
1865 /* Add to tail of log queue */
1866 if (down_interruptible(&pcli
->udi_sem
)) {
1867 printk(KERN_WARNING
"udi_log_event_q: Failed to get udi sem\n");
1871 list_add_tail(&logptr
->q
, &pcli
->udi_log
);
1874 /* Wake any waiting user process */
1875 wake_up_interruptible(&pcli
->udi_wq
);
1877 } /* udi_log_event() */
1879 #ifdef CSR_SME_USERSPACE
1881 uf_sme_queue_message(unifi_priv_t
*priv
, u8
*buffer
, int length
)
1887 /* Just a sanity check */
1888 if ((buffer
== NULL
) || (length
<= 0)) {
1892 /* Allocate log structure plus actual signal. */
1893 logptr
= (udi_log_t
*)kmalloc(sizeof(udi_log_t
) + length
, GFP_ATOMIC
);
1894 if (logptr
== NULL
) {
1895 unifi_error(priv
, "Failed to allocate %d bytes for an SME message\n",
1896 sizeof(udi_log_t
) + length
);
1901 /* Fill in udi_log struct */
1902 INIT_LIST_HEAD(&logptr
->q
);
1903 msgptr
= &logptr
->msg
;
1904 msgptr
->length
= sizeof(udi_msg_t
) + length
;
1905 msgptr
->signal_length
= length
;
1907 /* Copy signal and bulk data to the log */
1908 p
= (u8
*)(msgptr
+ 1);
1909 memcpy(p
, buffer
, length
);
1911 /* Add to tail of log queue */
1913 if (priv
->sme_cli
== NULL
) {
1917 unifi_info(priv
, "Message for the SME dropped, SME has gone away\n");
1921 down(&priv
->sme_cli
->udi_sem
);
1922 list_add_tail(&logptr
->q
, &priv
->sme_cli
->udi_log
);
1923 up(&priv
->sme_cli
->udi_sem
);
1925 /* Wake any waiting user process */
1926 wake_up_interruptible(&priv
->sme_cli
->udi_wq
);
1929 /* It is our responsibility to free the buffer allocated in build_packed_*() */
1934 } /* uf_sme_queue_message() */
1938 ****************************************************************************
1940 * Driver instantiation
1942 ****************************************************************************
1944 static struct file_operations unifi_fops
= {
1945 .owner
= THIS_MODULE
,
1947 .release
= unifi_release
,
1949 .write
= unifi_write
,
1950 .unlocked_ioctl
= unifi_ioctl
,
1954 static dev_t unifi_first_devno
;
1955 static struct class *unifi_class
;
1958 int uf_create_device_nodes(unifi_priv_t
*priv
, int bus_id
)
1963 cdev_init(&priv
->unifi_cdev
, &unifi_fops
);
1965 /* cdev_init() should set the cdev owner, but it does not */
1966 priv
->unifi_cdev
.owner
= THIS_MODULE
;
1968 devno
= MKDEV(MAJOR(unifi_first_devno
),
1969 MINOR(unifi_first_devno
) + (bus_id
* 2));
1970 r
= cdev_add(&priv
->unifi_cdev
, devno
, 1);
1975 #ifdef SDIO_EXPORTS_STRUCT_DEVICE
1976 if (!device_create(unifi_class
, priv
->unifi_device
,
1977 devno
, priv
, "unifi%d", bus_id
)) {
1979 priv
->unifi_device
= device_create(unifi_class
, NULL
,
1980 devno
, priv
, "unifi%d", bus_id
);
1981 if (priv
->unifi_device
== NULL
) {
1982 #endif /* SDIO_EXPORTS_STRUCT_DEVICE */
1984 cdev_del(&priv
->unifi_cdev
);
1988 cdev_init(&priv
->unifiudi_cdev
, &unifi_fops
);
1990 /* cdev_init() should set the cdev owner, but it does not */
1991 priv
->unifiudi_cdev
.owner
= THIS_MODULE
;
1993 devno
= MKDEV(MAJOR(unifi_first_devno
),
1994 MINOR(unifi_first_devno
) + (bus_id
* 2) + 1);
1995 r
= cdev_add(&priv
->unifiudi_cdev
, devno
, 1);
1997 device_destroy(unifi_class
, priv
->unifi_cdev
.dev
);
1998 cdev_del(&priv
->unifi_cdev
);
2002 if (!device_create(unifi_class
,
2003 #ifdef SDIO_EXPORTS_STRUCT_DEVICE
2007 #endif /* SDIO_EXPORTS_STRUCT_DEVICE */
2008 devno
, priv
, "unifiudi%d", bus_id
)) {
2009 device_destroy(unifi_class
, priv
->unifi_cdev
.dev
);
2010 cdev_del(&priv
->unifiudi_cdev
);
2011 cdev_del(&priv
->unifi_cdev
);
2019 void uf_destroy_device_nodes(unifi_priv_t
*priv
)
2021 device_destroy(unifi_class
, priv
->unifiudi_cdev
.dev
);
2022 device_destroy(unifi_class
, priv
->unifi_cdev
.dev
);
2023 cdev_del(&priv
->unifiudi_cdev
);
2024 cdev_del(&priv
->unifi_cdev
);
2030 * ----------------------------------------------------------------
2031 * uf_create_debug_device
2033 * Allocates device numbers for unifi character device nodes
2034 * and creates a unifi class in sysfs
2037 * fops Pointer to the char device operations structure.
2040 * 0 on success, -ve error code on error.
2041 * ----------------------------------------------------------------
2044 uf_create_debug_device(struct file_operations
*fops
)
2048 /* Allocate two device numbers for each device. */
2049 ret
= alloc_chrdev_region(&unifi_first_devno
, 0, MAX_UNIFI_DEVS
*2, UNIFI_NAME
);
2051 unifi_error(NULL
, "Failed to add alloc dev numbers: %d\n", ret
);
2055 /* Create a UniFi class */
2056 unifi_class
= class_create(THIS_MODULE
, UNIFI_NAME
);
2057 if (IS_ERR(unifi_class
)) {
2058 unifi_error(NULL
, "Failed to create UniFi class\n");
2060 /* Release device numbers */
2061 unregister_chrdev_region(unifi_first_devno
, MAX_UNIFI_DEVS
*2);
2062 unifi_first_devno
= 0;
2067 } /* uf_create_debug_device() */
2071 * ----------------------------------------------------------------
2072 * uf_remove_debug_device
2074 * Destroys the unifi class and releases the allocated
2075 * device numbers for unifi character device nodes.
2080 * ----------------------------------------------------------------
2083 uf_remove_debug_device(void)
2085 /* Destroy the UniFi class */
2086 class_destroy(unifi_class
);
2088 /* Release device numbers */
2089 unregister_chrdev_region(unifi_first_devno
, MAX_UNIFI_DEVS
*2);
2090 unifi_first_devno
= 0;
2092 } /* uf_remove_debug_device() */
2096 * ---------------------------------------------------------------------------
2100 * ---------------------------------------------------------------------------
2107 printk("UniFi SDIO Driver: %s %s %s\n",
2109 __DATE__
, __TIME__
);
2111 #ifdef CSR_SME_USERSPACE
2112 #ifdef CSR_SUPPORT_WEXT
2113 printk("CSR SME with WEXT support\n");
2115 printk("CSR SME no WEXT support\n");
2116 #endif /* CSR_SUPPORT_WEXT */
2117 #endif /* CSR_SME_USERSPACE */
2119 #ifdef CSR_NATIVE_LINUX
2120 #ifdef CSR_SUPPORT_WEXT
2121 #error WEXT unsupported in the native driver
2123 printk("CSR native no WEXT support\n");
2125 #ifdef CSR_WIFI_SPLIT_PATCH
2126 printk("Split patch support\n");
2128 printk("Kernel %d.%d.%d\n",
2129 ((LINUX_VERSION_CODE
) >> 16) & 0xff,
2130 ((LINUX_VERSION_CODE
) >> 8) & 0xff,
2131 (LINUX_VERSION_CODE
) & 0xff);
2133 * Instantiate the /dev/unifi* device nodes.
2134 * We must do this before registering with the SDIO driver because it
2135 * will immediately call the "insert" callback if the card is
2138 r
= uf_create_debug_device(&unifi_fops
);
2143 /* Now register with the SDIO driver */
2146 uf_remove_debug_device();
2150 if (sdio_block_size
> -1) {
2151 unifi_info(NULL
, "sdio_block_size %d\n", sdio_block_size
);
2154 if (sdio_byte_mode
) {
2155 unifi_info(NULL
, "sdio_byte_mode\n");
2158 if (disable_power_control
) {
2159 unifi_info(NULL
, "disable_power_control\n");
2162 if (disable_hw_reset
) {
2163 unifi_info(NULL
, "disable_hw_reset\n");
2167 unifi_info(NULL
, "enable_wol %d\n", enable_wol
);
2170 if (run_bh_once
!= -1) {
2171 unifi_info(NULL
, "run_bh_once %d\n", run_bh_once
);
2175 } /* unifi_load() */
2181 /* The SDIO remove hook will call unifi_disconnect(). */
2184 uf_remove_debug_device();
2186 } /* unifi_unload() */
2188 module_init(unifi_load
);
2189 module_exit(unifi_unload
);
2191 MODULE_DESCRIPTION("UniFi Device driver");
2192 MODULE_AUTHOR("Cambridge Silicon Radio Ltd.");
2193 MODULE_LICENSE("GPL and additional rights");