2 * ---------------------------------------------------------------------------
6 * This file contains routines that the SDIO driver can call when a
7 * UniFi card is first inserted (or detected) and removed.
9 * When used with sdioemb, the udev scripts (at least on Ubuntu) don't
10 * recognise a UniFi being added to the system. This is because sdioemb
11 * does not register itself as a device_driver, it uses it's own code
12 * to handle insert and remove.
13 * To have Ubuntu recognise UniFi, edit /etc/udev/rules.d/85-ifupdown.rules
14 * to change this line:
15 * SUBSYSTEM=="net", DRIVERS=="?*", GOTO="net_start"
17 * #SUBSYSTEM=="net", DRIVERS=="?*", GOTO="net_start"
18 * SUBSYSTEM=="net", GOTO="net_start"
20 * Then you can add a stanza to /etc/network/interfaces like this:
22 * iface eth1 inet dhcp
23 * wpa-conf /etc/wpa_supplicant.conf
24 * This will then automatically associate when a car dis inserted.
26 * Copyright (C) 2006-2009 by Cambridge Silicon Radio Ltd.
28 * Refer to LICENSE.txt included with this source code for details on
31 * ---------------------------------------------------------------------------
33 #include <linux/proc_fs.h>
34 #include <linux/version.h>
36 #include "csr_wifi_hip_unifi.h"
37 #include "csr_wifi_hip_unifiversion.h"
38 #include "csr_wifi_hip_unifi_udi.h" /* for unifi_print_status() */
40 #include "unifi_priv.h"
43 * Array of pointers to context structs for unifi devices that are present.
44 * The index in the array corresponds to the wlan interface number
45 * (if "wlan*" is used). If "eth*" is used, the eth* numbers are allocated
46 * after any Ethernet cards.
48 * The Arasan PCI-SDIO controller card supported by this driver has 2 slots,
49 * hence a max of 2 devices.
51 static unifi_priv_t *Unifi_instances[MAX_UNIFI_DEVS];
53 /* Array of pointers to netdev objects used by the UniFi driver, as there
54 * are now many per instance. This is used to determine which netdev events
55 * are for UniFi as opposed to other net interfaces.
57 static netInterface_priv_t *Unifi_netdev_instances[MAX_UNIFI_DEVS * CSR_WIFI_NUM_INTERFACES];
60 * Array to hold the status of each unifi device in each slot.
61 * We only process an insert event when In_use[] for the slot is
62 * UNIFI_DEV_NOT_IN_USE. Otherwise, it means that the slot is in use or
63 * we are in the middle of a cleanup (the action on unplug).
65 #define UNIFI_DEV_NOT_IN_USE 0
66 #define UNIFI_DEV_IN_USE 1
67 #define UNIFI_DEV_CLEANUP 2
68 static int In_use[MAX_UNIFI_DEVS];
70 * Mutex to prevent UDI clients to open the character device before the priv
71 * is created and initialised.
73 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
74 DEFINE_SEMAPHORE(Unifi_instance_mutex);
76 DECLARE_MUTEX(Unifi_instance_mutex);
79 * When the device is removed, unregister waits on Unifi_cleanup_wq
80 * until all the UDI clients release the character device.
82 DECLARE_WAIT_QUEUE_HEAD(Unifi_cleanup_wq);
85 static int uf_read_proc(char *page, char **start, off_t offset, int count,
86 int *eof, void *data);
88 #ifdef CSR_WIFI_RX_PATH_SPLIT
90 static CsrResult signal_buffer_init(unifi_priv_t * priv, int size)
95 priv->rxSignalBuffer.writePointer =
96 priv->rxSignalBuffer.readPointer = 0;
97 priv->rxSignalBuffer.size = size;
98 /* Allocating Memory for Signal primitive pointer */
101 priv->rxSignalBuffer.rx_buff[i].sig_len=0;
102 priv->rxSignalBuffer.rx_buff[i].bufptr = kmalloc(UNIFI_PACKED_SIGBUF_SIZE, GFP_KERNEL);
103 if (priv->rxSignalBuffer.rx_buff[i].bufptr == NULL)
106 unifi_error(priv,"signal_buffer_init:Failed to Allocate shared memory for T-H signals \n");
109 priv->rxSignalBuffer.rx_buff[j].sig_len=0;
110 kfree(priv->rxSignalBuffer.rx_buff[j].bufptr);
111 priv->rxSignalBuffer.rx_buff[j].bufptr = NULL;
122 static void signal_buffer_free(unifi_priv_t * priv, int size)
126 for(i=0; i<size; i++)
128 priv->rxSignalBuffer.rx_buff[i].sig_len=0;
129 kfree(priv->rxSignalBuffer.rx_buff[i].bufptr);
130 priv->rxSignalBuffer.rx_buff[i].bufptr = NULL;
135 * ---------------------------------------------------------------------------
138 * Registers the network interface, installes the qdisc,
139 * and registers the inet handler.
140 * In the porting exercise, register the driver to the network
141 * stack if necessary.
144 * priv Pointer to driver context.
147 * O on success, non-zero otherwise.
150 * We will only unregister when the card is ejected, so we must
152 * ---------------------------------------------------------------------------
155 uf_register_netdev(unifi_priv_t *priv, int interfaceTag)
158 netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
160 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
161 unifi_error(priv, "uf_register_netdev bad interfaceTag\n");
166 * Allocates a device number and registers device with the network
169 unifi_trace(priv, UDBG5, "uf_register_netdev: netdev %d - 0x%p\n",
170 interfaceTag, priv->netdev[interfaceTag]);
171 r = register_netdev(priv->netdev[interfaceTag]);
173 unifi_error(priv, "Failed to register net device\n");
177 /* The device is registed */
178 interfacePriv->netdev_registered = 1;
180 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
181 #ifdef CONFIG_NET_SCHED
184 * uf_install_qdisc() holds the network device lock, we can not
185 * install the qdisk before the network device is registered.
187 r = uf_install_qdisc(priv->netdev[interfaceTag]);
189 unifi_error(priv, "Failed to install qdisc\n");
192 #endif /* CONFIG_NET_SCHED */
193 #endif /* LINUX_VERSION_CODE */
195 #ifdef CSR_SUPPORT_SME
197 * Register the inet handler; it notifies us for changes in the IP address.
199 uf_register_inet_notifier();
200 #endif /* CSR_SUPPORT_SME */
202 unifi_notice(priv, "unifi%d is %s\n",
203 priv->instance, priv->netdev[interfaceTag]->name);
206 } /* uf_register_netdev */
210 * ---------------------------------------------------------------------------
211 * uf_unregister_netdev
213 * Unregisters the network interface and the inet handler.
216 * priv Pointer to driver context.
221 * ---------------------------------------------------------------------------
224 uf_unregister_netdev(unifi_priv_t *priv)
228 #ifdef CSR_SUPPORT_SME
229 /* Unregister the inet handler... */
230 uf_unregister_inet_notifier();
231 #endif /* CSR_SUPPORT_SME */
233 for (i=0; i<CSR_WIFI_NUM_INTERFACES; i++) {
234 netInterface_priv_t *interfacePriv = priv->interfacePriv[i];
235 if (interfacePriv->netdev_registered) {
236 unifi_trace(priv, UDBG5,
237 "uf_unregister_netdev: netdev %d - 0x%p\n",
240 /* ... and the netdev */
241 unregister_netdev(priv->netdev[i]);
242 interfacePriv->netdev_registered = 0;
245 interfacePriv->interfaceMode = 0;
247 /* Enable all queues by default */
248 interfacePriv->queueEnabled[0] = 1;
249 interfacePriv->queueEnabled[1] = 1;
250 interfacePriv->queueEnabled[2] = 1;
251 interfacePriv->queueEnabled[3] = 1;
254 priv->totalInterfaceCount = 0;
255 } /* uf_unregister_netdev() */
259 * ---------------------------------------------------------------------------
260 * register_unifi_sdio
262 * This function is called from the Probe (or equivalent) method of
263 * the SDIO driver when a UniFi card is detected.
264 * We allocate the Linux net_device struct, initialise the HIP core
265 * lib, create the char device nodes and start the userspace helper
266 * to initialise the device.
269 * sdio_dev Pointer to SDIO context handle to use for all
271 * bus_id A small number indicating the SDIO card position on the
272 * bus. Typically this is the slot number, e.g. 0, 1 etc.
273 * Valid values are 0 to MAX_UNIFI_DEVS-1.
274 * dev Pointer to kernel device manager struct.
277 * Pointer to the unifi instance, or NULL on error.
278 * ---------------------------------------------------------------------------
280 static unifi_priv_t *
281 register_unifi_sdio(CsrSdioFunction *sdio_dev, int bus_id, struct device *dev)
283 unifi_priv_t *priv = NULL;
289 if ((bus_id < 0) || (bus_id >= MAX_UNIFI_DEVS)) {
290 unifi_error(priv, "register_unifi_sdio: invalid device %d\n",
295 down(&Unifi_instance_mutex);
297 if (In_use[bus_id] != UNIFI_DEV_NOT_IN_USE) {
298 unifi_error(priv, "register_unifi_sdio: device %d is already in use\n",
304 /* Allocate device private and net_device structs */
305 priv = uf_alloc_netdevice(sdio_dev, bus_id);
307 unifi_error(priv, "Failed to allocate driver private\n");
311 priv->unifi_device = dev;
313 SET_NETDEV_DEV(priv->netdev[0], dev);
315 /* We are not ready to send data yet. */
316 netif_carrier_off(priv->netdev[0]);
318 /* Allocate driver context. */
319 priv->card = unifi_alloc_card(priv->sdio, priv);
320 if (priv->card == NULL) {
321 unifi_error(priv, "Failed to allocate UniFi driver card struct.\n");
325 if (Unifi_instances[bus_id]) {
326 unifi_error(priv, "Internal error: instance for slot %d is already taken\n",
329 Unifi_instances[bus_id] = priv;
330 In_use[bus_id] = UNIFI_DEV_IN_USE;
332 /* Save the netdev_priv for use by the netdev event callback mechanism */
333 Unifi_netdev_instances[bus_id * CSR_WIFI_NUM_INTERFACES] = netdev_priv(priv->netdev[0]);
335 /* Initialise the mini-coredump capture buffers */
336 csrResult = unifi_coredump_init(priv->card, (u16)coredump_max);
337 if (csrResult != CSR_RESULT_SUCCESS) {
338 unifi_error(priv, "Couldn't allocate mini-coredump buffers\n");
341 /* Create the character device nodes */
342 r = uf_create_device_nodes(priv, bus_id);
348 * We use the slot number as unifi device index.
350 scnprintf(priv->proc_entry_name, 64, "driver/unifi%d", priv->instance);
352 * The following complex casting is in place in order to eliminate 64-bit compilation warning
353 * "cast to/from pointer from/to integer of different size"
355 if (!create_proc_read_entry(priv->proc_entry_name, 0, 0,
356 uf_read_proc, (void *)(long)priv->instance))
358 unifi_error(priv, "unifi: can't create /proc/driver/unifi\n");
361 /* Allocate the net_device for interfaces other than 0. */
364 priv->totalInterfaceCount =0;
366 for(i=1;i<CSR_WIFI_NUM_INTERFACES;i++)
368 if( !uf_alloc_netdevice_for_other_interfaces(priv,i) )
370 /* error occured while allocating the net_device for interface[i]. The net_device are
371 * allocated for the interfaces with id<i. Dont worry, all the allocated net_device will
372 * be releasing chen the control goes to the label failed0.
374 unifi_error(priv, "Failed to allocate driver private for interface[%d]\n",i);
379 SET_NETDEV_DEV(priv->netdev[i], dev);
381 /* We are not ready to send data yet. */
382 netif_carrier_off(priv->netdev[i]);
384 /* Save the netdev_priv for use by the netdev event callback mechanism */
385 Unifi_netdev_instances[bus_id * CSR_WIFI_NUM_INTERFACES + i] = netdev_priv(priv->netdev[i]);
389 for(i=0;i<CSR_WIFI_NUM_INTERFACES;i++)
391 netInterface_priv_t *interfacePriv = priv->interfacePriv[i];
392 interfacePriv->netdev_registered=0;
396 #ifdef CSR_WIFI_RX_PATH_SPLIT
397 if (signal_buffer_init(priv, CSR_WIFI_RX_SIGNAL_BUFFER_SIZE))
399 unifi_error(priv,"Failed to allocate shared memory for T-H signals\n");
402 priv->rx_workqueue = create_singlethread_workqueue("rx_workq");
403 if (priv->rx_workqueue == NULL) {
404 unifi_error(priv,"create_singlethread_workqueue failed \n");
407 INIT_WORK(&priv->rx_work_struct, rx_wq_handler);
410 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
413 uf_register_hip_offline_debug(priv);
417 /* Initialise the SME related threads and parameters */
418 r = uf_sme_init(priv);
420 unifi_error(priv, "SME initialisation failed.\n");
425 * Run the userspace helper program (unififw) to perform
426 * the device initialisation.
428 unifi_trace(priv, UDBG1, "run UniFi helper app...\n");
429 r = uf_run_unifihelper(priv);
431 unifi_notice(priv, "unable to run UniFi helper app\n");
432 /* Not a fatal error. */
435 up(&Unifi_instance_mutex);
441 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
444 uf_unregister_hip_offline_debug(priv);
447 #ifdef CSR_WIFI_RX_PATH_SPLIT
448 flush_workqueue(priv->rx_workqueue);
449 destroy_workqueue(priv->rx_workqueue);
451 signal_buffer_free(priv,CSR_WIFI_RX_SIGNAL_BUFFER_SIZE);
454 /* Remove the device nodes */
455 uf_destroy_device_nodes(priv);
457 /* Deregister priv->netdev_client */
458 ul_deregister_client(priv->netdev_client);
461 if (priv && priv->card) {
462 unifi_coredump_free(priv->card);
463 unifi_free_card(priv->card);
466 uf_free_netdevice(priv);
469 up(&Unifi_instance_mutex);
473 } /* register_unifi_sdio() */
477 * ---------------------------------------------------------------------------
478 * ask_unifi_sdio_cleanup
480 * We can not free our private context, until all the char device
481 * clients have closed the file handles. unregister_unifi_sdio() which
482 * is called when a card is removed, waits on Unifi_cleanup_wq until
483 * the reference count becomes zero. It is time to wake it up now.
486 * priv Pointer to driver context.
490 * ---------------------------------------------------------------------------
493 ask_unifi_sdio_cleanup(unifi_priv_t *priv)
498 * Now clear the flag that says the old instance is in use.
499 * This is used to prevent a new instance being started before old
500 * one has finshed closing down, for example if bounce makes the card
501 * appear to be ejected and re-inserted quickly.
503 In_use[priv->instance] = UNIFI_DEV_CLEANUP;
505 unifi_trace(NULL, UDBG5, "ask_unifi_sdio_cleanup: wake up cleanup workqueue.\n");
506 wake_up(&Unifi_cleanup_wq);
510 } /* ask_unifi_sdio_cleanup() */
514 * ---------------------------------------------------------------------------
517 * Release any resources owned by a unifi instance.
520 * priv Pointer to the instance to free.
524 * ---------------------------------------------------------------------------
527 cleanup_unifi_sdio(unifi_priv_t *priv)
531 static const CsrWifiMacAddress broadcast_address = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
535 /* Remove the device nodes */
536 uf_destroy_device_nodes(priv);
538 /* Mark this device as gone away by NULLing the entry in Unifi_instances */
539 Unifi_instances[priv->instance] = NULL;
541 unifi_trace(priv, UDBG5, "cleanup_unifi_sdio: remove_proc_entry\n");
543 * Free the children of priv before unifi_free_netdevice() frees
546 remove_proc_entry(priv->proc_entry_name, 0);
549 /* Unregister netdev as a client. */
550 if (priv->netdev_client) {
551 unifi_trace(priv, UDBG2, "Netdev client (id:%d s:0x%X) is unregistered\n",
552 priv->netdev_client->client_id, priv->netdev_client->sender_id);
553 ul_deregister_client(priv->netdev_client);
556 /* Destroy the SME related threads and parameters */
559 #ifdef CSR_SME_USERSPACE
560 priv->smepriv = NULL;
563 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
566 uf_unregister_hip_offline_debug(priv);
570 /* Free any packets left in the Rx queues */
571 for(i=0;i<CSR_WIFI_NUM_INTERFACES;i++)
573 uf_free_pending_rx_packets(priv, UF_UNCONTROLLED_PORT_Q, broadcast_address,i);
574 uf_free_pending_rx_packets(priv, UF_CONTROLLED_PORT_Q, broadcast_address,i);
577 * We need to free the resources held by the core, which include tx skbs,
578 * otherwise we can not call unregister_netdev().
581 unifi_trace(priv, UDBG5, "cleanup_unifi_sdio: free card\n");
582 unifi_coredump_free(priv->card);
583 unifi_free_card(priv->card);
588 * Unregister the network device.
589 * We can not unregister the netdev before we release
590 * all pending packets in the core.
592 uf_unregister_netdev(priv);
593 priv->totalInterfaceCount = 0;
595 /* Clear the table of registered netdev_priv's */
596 for (i = 0; i < CSR_WIFI_NUM_INTERFACES; i++) {
597 Unifi_netdev_instances[priv->instance * CSR_WIFI_NUM_INTERFACES + i] = NULL;
600 unifi_trace(priv, UDBG5, "cleanup_unifi_sdio: uf_free_netdevice\n");
602 * When uf_free_netdevice() returns, the priv is invalid
603 * so we need to remember the instance to clear the global flag later.
605 priv_instance = priv->instance;
607 #ifdef CSR_WIFI_RX_PATH_SPLIT
608 flush_workqueue(priv->rx_workqueue);
609 destroy_workqueue(priv->rx_workqueue);
610 signal_buffer_free(priv,CSR_WIFI_RX_SIGNAL_BUFFER_SIZE);
613 /* Priv is freed as part of the net_device */
614 uf_free_netdevice(priv);
617 * Now clear the flag that says the old instance is in use.
618 * This is used to prevent a new instance being started before old
619 * one has finshed closing down, for example if bounce makes the card
620 * appear to be ejected and re-inserted quickly.
622 In_use[priv_instance] = UNIFI_DEV_NOT_IN_USE;
624 unifi_trace(NULL, UDBG5, "cleanup_unifi_sdio: DONE.\n");
628 } /* cleanup_unifi_sdio() */
632 * ---------------------------------------------------------------------------
633 * unregister_unifi_sdio
635 * Call from SDIO driver when it detects that UniFi has been removed.
638 * bus_id Number of the card that was ejected.
642 * ---------------------------------------------------------------------------
645 unregister_unifi_sdio(int bus_id)
649 u8 reason = CONFIG_IND_EXIT;
651 if ((bus_id < 0) || (bus_id >= MAX_UNIFI_DEVS)) {
652 unifi_error(NULL, "unregister_unifi_sdio: invalid device %d\n",
657 priv = Unifi_instances[bus_id];
659 unifi_error(priv, "unregister_unifi_sdio: device %d is not registered\n",
665 /* Stop the network traffic before freeing the core. */
666 for(interfaceTag=0;interfaceTag<priv->totalInterfaceCount;interfaceTag++)
668 netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag];
669 if(interfacePriv->netdev_registered)
671 netif_carrier_off(priv->netdev[interfaceTag]);
672 netif_tx_stop_all_queues(priv->netdev[interfaceTag]);
676 #ifdef CSR_NATIVE_LINUX
678 * If the unifi thread was started, signal it to stop. This
679 * should cause any userspace processes with open unifi device to
682 uf_stop_thread(priv, &priv->bh_thread);
684 /* Unregister the interrupt handler */
685 if (csr_sdio_linux_remove_irq(priv->sdio)) {
687 "csr_sdio_linux_remove_irq failed to talk to card.\n");
690 /* Ensure no MLME functions are waiting on a the mlme_event semaphore. */
692 #endif /* CSR_NATIVE_LINUX */
694 ul_log_config_ind(priv, &reason, sizeof(u8));
696 /* Deregister the UDI hook from the core. */
697 unifi_remove_udi_hook(priv->card, logging_handler);
699 uf_put_instance(bus_id);
702 * Wait until the device is cleaned up. i.e., when all userspace
703 * processes have closed any open unifi devices.
705 wait_event(Unifi_cleanup_wq, In_use[bus_id] == UNIFI_DEV_CLEANUP);
706 unifi_trace(NULL, UDBG5, "Received clean up event\n");
708 /* Now we can free the private context and the char device nodes */
709 cleanup_unifi_sdio(priv);
711 } /* unregister_unifi_sdio() */
715 * ---------------------------------------------------------------------------
718 * Find the context structure for a given UniFi device instance.
721 * inst The instance number to look for.
725 * ---------------------------------------------------------------------------
728 uf_find_instance(int inst)
730 if ((inst < 0) || (inst >= MAX_UNIFI_DEVS)) {
733 return Unifi_instances[inst];
734 } /* uf_find_instance() */
738 * ---------------------------------------------------------------------------
741 * Find the device instance for a given context structure.
744 * priv The context structure pointer to look for.
747 * index of instance, -1 otherwise.
748 * ---------------------------------------------------------------------------
751 uf_find_priv(unifi_priv_t *priv)
759 for (inst = 0; inst < MAX_UNIFI_DEVS; inst++) {
760 if (Unifi_instances[inst] == priv) {
766 } /* uf_find_priv() */
769 * ---------------------------------------------------------------------------
770 * uf_find_netdev_priv
772 * Find the device instance for a given netdev context structure.
775 * priv The context structure pointer to look for.
778 * index of instance, -1 otherwise.
779 * ---------------------------------------------------------------------------
782 uf_find_netdev_priv(netInterface_priv_t *priv)
790 for (inst = 0; inst < MAX_UNIFI_DEVS * CSR_WIFI_NUM_INTERFACES; inst++) {
791 if (Unifi_netdev_instances[inst] == priv) {
797 } /* uf_find_netdev_priv() */
800 * ---------------------------------------------------------------------------
803 * Find the context structure for a given UniFi device instance
804 * and increment the reference count.
807 * inst The instance number to look for.
810 * Pointer to the instance or NULL if no instance exists.
811 * ---------------------------------------------------------------------------
814 uf_get_instance(int inst)
818 down(&Unifi_instance_mutex);
820 priv = uf_find_instance(inst);
825 up(&Unifi_instance_mutex);
831 * ---------------------------------------------------------------------------
834 * Decrement the context reference count, freeing resources and
835 * shutting down the driver when the count reaches zero.
838 * inst The instance number to look for.
841 * Pointer to the instance or NULL if no instance exists.
842 * ---------------------------------------------------------------------------
845 uf_put_instance(int inst)
849 down(&Unifi_instance_mutex);
851 priv = uf_find_instance(inst);
854 if (priv->ref_count == 0) {
855 ask_unifi_sdio_cleanup(priv);
859 up(&Unifi_instance_mutex);
864 * ---------------------------------------------------------------------------
867 * Read method for driver node in /proc/driver/unifi0
879 * ---------------------------------------------------------------------------
881 #ifdef CONFIG_PROC_FS
883 uf_read_proc(char *page, char **start, off_t offset, int count,
884 int *eof, void *data)
886 #define UNIFI_DEBUG_TXT_BUFFER 8*1024
888 int actual_amount_to_copy;
890 s32 remain = UNIFI_DEBUG_TXT_BUFFER;
895 * The following complex casting is in place in order to eliminate 64-bit compilation warning
896 * "cast to/from pointer from/to integer of different size"
898 priv = uf_find_instance((int)(long)data);
903 p = kmalloc( UNIFI_DEBUG_TXT_BUFFER, GFP_KERNEL );
907 written = scnprintf(p, remain, "UniFi SDIO Driver: %s %s %s\n",
908 CSR_WIFI_VERSION, __DATE__, __TIME__);
909 UNIFI_SNPRINTF_RET(p, remain, written);
910 #ifdef CSR_SME_USERSPACE
911 written = scnprintf(p, remain, "SME: CSR userspace ");
912 UNIFI_SNPRINTF_RET(p, remain, written);
913 #ifdef CSR_SUPPORT_WEXT
914 written = scnprintf(p, remain, "with WEXT support\n");
916 written = scnprintf(p, remain, "\n");
917 #endif /* CSR_SUPPORT_WEXT */
918 UNIFI_SNPRINTF_RET(p, remain, written);
919 #endif /* CSR_SME_USERSPACE */
920 #ifdef CSR_NATIVE_LINUX
921 written = scnprintf(p, remain, "SME: native\n");
922 UNIFI_SNPRINTF_RET(p, remain, written);
925 #ifdef CSR_SUPPORT_SME
926 written = scnprintf(p, remain,
927 "Firmware (ROM) build:%u, Patch:%u\n",
928 priv->card_info.fw_build,
929 priv->sme_versions.firmwarePatch);
930 UNIFI_SNPRINTF_RET(p, remain, written);
932 p += unifi_print_status(priv->card, p, &remain);
934 written = scnprintf(p, remain, "Last dbg str: %s\n",
935 priv->last_debug_string);
936 UNIFI_SNPRINTF_RET(p, remain, written);
938 written = scnprintf(p, remain, "Last dbg16:");
939 UNIFI_SNPRINTF_RET(p, remain, written);
940 for (i = 0; i < 8; i++) {
941 written = scnprintf(p, remain, " %04X",
942 priv->last_debug_word16[i]);
943 UNIFI_SNPRINTF_RET(p, remain, written);
945 written = scnprintf(p, remain, "\n");
946 UNIFI_SNPRINTF_RET(p, remain, written);
947 written = scnprintf(p, remain, " ");
948 UNIFI_SNPRINTF_RET(p, remain, written);
949 for (; i < 16; i++) {
950 written = scnprintf(p, remain, " %04X",
951 priv->last_debug_word16[i]);
952 UNIFI_SNPRINTF_RET(p, remain, written);
954 written = scnprintf(p, remain, "\n");
955 UNIFI_SNPRINTF_RET(p, remain, written);
958 written = UNIFI_DEBUG_TXT_BUFFER - remain;
960 if( offset >= written )
967 if( offset + count > written )
969 actual_amount_to_copy = written - offset;
974 actual_amount_to_copy = count;
977 memcpy( page, &(orig_p[offset]), actual_amount_to_copy );
981 return( actual_amount_to_copy );
982 } /* uf_read_proc() */
989 uf_lx_suspend(CsrSdioFunction *sdio_ctx)
991 unifi_priv_t *priv = sdio_ctx->driverData;
994 CsrSdioSuspendAcknowledge(sdio_ctx, CSR_RESULT_SUCCESS);
998 uf_lx_resume(CsrSdioFunction *sdio_ctx)
1000 unifi_priv_t *priv = sdio_ctx->driverData;
1003 CsrSdioResumeAcknowledge(sdio_ctx, CSR_RESULT_SUCCESS);
1006 static int active_slot = MAX_UNIFI_DEVS;
1007 static struct device *os_devices[MAX_UNIFI_DEVS];
1010 uf_add_os_device(int bus_id, struct device *os_device)
1012 if ((bus_id < 0) || (bus_id >= MAX_UNIFI_DEVS)) {
1013 unifi_error(NULL, "uf_add_os_device: invalid device %d\n",
1018 active_slot = bus_id;
1019 os_devices[bus_id] = os_device;
1020 } /* uf_add_os_device() */
1023 uf_remove_os_device(int bus_id)
1025 if ((bus_id < 0) || (bus_id >= MAX_UNIFI_DEVS)) {
1026 unifi_error(NULL, "uf_remove_os_device: invalid device %d\n",
1031 active_slot = bus_id;
1032 os_devices[bus_id] = NULL;
1033 } /* uf_remove_os_device() */
1036 uf_sdio_inserted(CsrSdioFunction *sdio_ctx)
1040 unifi_trace(NULL, UDBG5, "uf_sdio_inserted(0x%p), slot_id=%d, dev=%p\n",
1041 sdio_ctx, active_slot, os_devices[active_slot]);
1043 priv = register_unifi_sdio(sdio_ctx, active_slot, os_devices[active_slot]);
1045 CsrSdioInsertedAcknowledge(sdio_ctx, CSR_RESULT_FAILURE);
1049 sdio_ctx->driverData = priv;
1051 CsrSdioInsertedAcknowledge(sdio_ctx, CSR_RESULT_SUCCESS);
1052 } /* uf_sdio_inserted() */
1056 uf_sdio_removed(CsrSdioFunction *sdio_ctx)
1058 unregister_unifi_sdio(active_slot);
1059 CsrSdioRemovedAcknowledge(sdio_ctx);
1060 } /* uf_sdio_removed() */
1064 uf_sdio_dsr_handler(CsrSdioFunction *sdio_ctx)
1066 unifi_priv_t *priv = sdio_ctx->driverData;
1068 unifi_sdio_interrupt_handler(priv->card);
1069 } /* uf_sdio_dsr_handler() */
1072 * ---------------------------------------------------------------------------
1073 * uf_sdio_int_handler
1075 * Interrupt callback function for SDIO interrupts.
1076 * This is called in kernel context (i.e. not interrupt context).
1077 * We retrieve the unifi context pointer and call the main UniFi
1078 * interrupt handler.
1081 * fdev SDIO context pointer
1085 * ---------------------------------------------------------------------------
1087 static CsrSdioInterruptDsrCallback
1088 uf_sdio_int_handler(CsrSdioFunction *sdio_ctx)
1090 return uf_sdio_dsr_handler;
1091 } /* uf_sdio_int_handler() */
1096 static CsrSdioFunctionId unifi_ids[] =
1099 .manfId = SDIO_MANF_ID_CSR,
1100 .cardId = SDIO_CARD_ID_UNIFI_3,
1101 .sdioFunction = SDIO_WLAN_FUNC_ID_UNIFI_3,
1102 .sdioInterface = CSR_SDIO_ANY_SDIO_INTERFACE,
1105 .manfId = SDIO_MANF_ID_CSR,
1106 .cardId = SDIO_CARD_ID_UNIFI_4,
1107 .sdioFunction = SDIO_WLAN_FUNC_ID_UNIFI_4,
1108 .sdioInterface = CSR_SDIO_ANY_SDIO_INTERFACE,
1114 * Structure to register with the glue layer.
1116 static CsrSdioFunctionDriver unifi_sdioFunction_drv =
1118 .inserted = uf_sdio_inserted,
1119 .removed = uf_sdio_removed,
1120 .intr = uf_sdio_int_handler,
1121 .suspend = uf_lx_suspend,
1122 .resume = uf_lx_resume,
1125 .idsCount = sizeof(unifi_ids) / sizeof(unifi_ids[0])
1130 * ---------------------------------------------------------------------------
1134 * These functions are called from the main module load and unload
1135 * functions. They perform the appropriate operations for the monolithic
1143 * ---------------------------------------------------------------------------
1148 CsrResult csrResult;
1150 csrResult = CsrSdioFunctionDriverRegister(&unifi_sdioFunction_drv);
1151 if (csrResult != CSR_RESULT_SUCCESS) {
1152 unifi_error(NULL, "Failed to register UniFi SDIO driver: csrResult=%d\n", csrResult);
1157 } /* uf_sdio_load() */
1162 uf_sdio_unload(void)
1164 CsrSdioFunctionDriverUnregister(&unifi_sdioFunction_drv);
1165 } /* uf_sdio_unload() */