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/seq_file.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 DEFINE_SEMAPHORE(Unifi_instance_mutex
);
75 * When the device is removed, unregister waits on Unifi_cleanup_wq
76 * until all the UDI clients release the character device.
78 DECLARE_WAIT_QUEUE_HEAD(Unifi_cleanup_wq
);
82 * seq_file wrappers for procfile show routines.
84 static int uf_proc_show(struct seq_file
*m
, void *v
);
86 #define UNIFI_DEBUG_TXT_BUFFER (8 * 1024)
88 static int uf_proc_open(struct inode
*inode
, struct file
*file
)
90 return single_open_size(file
, uf_proc_show
, PDE_DATA(inode
),
91 UNIFI_DEBUG_TXT_BUFFER
);
94 static const struct file_operations uf_proc_fops
= {
98 .release
= single_release
,
101 #endif /* CONFIG_PROC_FS */
103 #ifdef CSR_WIFI_RX_PATH_SPLIT
105 static CsrResult
signal_buffer_init(unifi_priv_t
* priv
, int size
)
109 priv
->rxSignalBuffer
.writePointer
=
110 priv
->rxSignalBuffer
.readPointer
= 0;
111 priv
->rxSignalBuffer
.size
= size
;
112 /* Allocating Memory for Signal primitive pointer */
113 for(i
=0; i
<size
; i
++)
115 priv
->rxSignalBuffer
.rx_buff
[i
].sig_len
=0;
116 priv
->rxSignalBuffer
.rx_buff
[i
].bufptr
= kmalloc(UNIFI_PACKED_SIGBUF_SIZE
, GFP_KERNEL
);
117 if (priv
->rxSignalBuffer
.rx_buff
[i
].bufptr
== NULL
)
120 unifi_error(priv
, "signal_buffer_init:Failed to Allocate shared memory for T-H signals \n");
123 priv
->rxSignalBuffer
.rx_buff
[j
].sig_len
=0;
124 kfree(priv
->rxSignalBuffer
.rx_buff
[j
].bufptr
);
125 priv
->rxSignalBuffer
.rx_buff
[j
].bufptr
= NULL
;
134 static void signal_buffer_free(unifi_priv_t
* priv
, int size
)
138 for(i
=0; i
<size
; i
++)
140 priv
->rxSignalBuffer
.rx_buff
[i
].sig_len
=0;
141 kfree(priv
->rxSignalBuffer
.rx_buff
[i
].bufptr
);
142 priv
->rxSignalBuffer
.rx_buff
[i
].bufptr
= NULL
;
147 * ---------------------------------------------------------------------------
150 * Registers the network interface, installes the qdisc,
151 * and registers the inet handler.
152 * In the porting exercise, register the driver to the network
153 * stack if necessary.
156 * priv Pointer to driver context.
159 * O on success, non-zero otherwise.
162 * We will only unregister when the card is ejected, so we must
164 * ---------------------------------------------------------------------------
167 uf_register_netdev(unifi_priv_t
*priv
, int interfaceTag
)
170 netInterface_priv_t
*interfacePriv
= priv
->interfacePriv
[interfaceTag
];
172 if (interfaceTag
>= CSR_WIFI_NUM_INTERFACES
) {
173 unifi_error(priv
, "uf_register_netdev bad interfaceTag\n");
178 * Allocates a device number and registers device with the network
181 unifi_trace(priv
, UDBG5
, "uf_register_netdev: netdev %d - 0x%p\n",
182 interfaceTag
, priv
->netdev
[interfaceTag
]);
183 r
= register_netdev(priv
->netdev
[interfaceTag
]);
185 unifi_error(priv
, "Failed to register net device\n");
189 /* The device is registed */
190 interfacePriv
->netdev_registered
= 1;
192 #ifdef CSR_SUPPORT_SME
194 * Register the inet handler; it notifies us for changes in the IP address.
196 uf_register_inet_notifier();
197 #endif /* CSR_SUPPORT_SME */
199 unifi_notice(priv
, "unifi%d is %s\n",
200 priv
->instance
, priv
->netdev
[interfaceTag
]->name
);
203 } /* uf_register_netdev */
207 * ---------------------------------------------------------------------------
208 * uf_unregister_netdev
210 * Unregisters the network interface and the inet handler.
213 * priv Pointer to driver context.
218 * ---------------------------------------------------------------------------
221 uf_unregister_netdev(unifi_priv_t
*priv
)
225 #ifdef CSR_SUPPORT_SME
226 /* Unregister the inet handler... */
227 uf_unregister_inet_notifier();
228 #endif /* CSR_SUPPORT_SME */
230 for (i
=0; i
<CSR_WIFI_NUM_INTERFACES
; i
++) {
231 netInterface_priv_t
*interfacePriv
= priv
->interfacePriv
[i
];
232 if (interfacePriv
->netdev_registered
) {
233 unifi_trace(priv
, UDBG5
,
234 "uf_unregister_netdev: netdev %d - 0x%p\n",
237 /* ... and the netdev */
238 unregister_netdev(priv
->netdev
[i
]);
239 interfacePriv
->netdev_registered
= 0;
242 interfacePriv
->interfaceMode
= 0;
244 /* Enable all queues by default */
245 interfacePriv
->queueEnabled
[0] = 1;
246 interfacePriv
->queueEnabled
[1] = 1;
247 interfacePriv
->queueEnabled
[2] = 1;
248 interfacePriv
->queueEnabled
[3] = 1;
251 priv
->totalInterfaceCount
= 0;
252 } /* uf_unregister_netdev() */
256 * ---------------------------------------------------------------------------
257 * register_unifi_sdio
259 * This function is called from the Probe (or equivalent) method of
260 * the SDIO driver when a UniFi card is detected.
261 * We allocate the Linux net_device struct, initialise the HIP core
262 * lib, create the char device nodes and start the userspace helper
263 * to initialise the device.
266 * sdio_dev Pointer to SDIO context handle to use for all
268 * bus_id A small number indicating the SDIO card position on the
269 * bus. Typically this is the slot number, e.g. 0, 1 etc.
270 * Valid values are 0 to MAX_UNIFI_DEVS-1.
271 * dev Pointer to kernel device manager struct.
274 * Pointer to the unifi instance, or NULL on error.
275 * ---------------------------------------------------------------------------
277 static unifi_priv_t
*
278 register_unifi_sdio(CsrSdioFunction
*sdio_dev
, int bus_id
, struct device
*dev
)
280 unifi_priv_t
*priv
= NULL
;
284 if ((bus_id
< 0) || (bus_id
>= MAX_UNIFI_DEVS
)) {
285 unifi_error(priv
, "register_unifi_sdio: invalid device %d\n",
290 down(&Unifi_instance_mutex
);
292 if (In_use
[bus_id
] != UNIFI_DEV_NOT_IN_USE
) {
293 unifi_error(priv
, "register_unifi_sdio: device %d is already in use\n",
299 /* Allocate device private and net_device structs */
300 priv
= uf_alloc_netdevice(sdio_dev
, bus_id
);
302 unifi_error(priv
, "Failed to allocate driver private\n");
306 priv
->unifi_device
= dev
;
308 SET_NETDEV_DEV(priv
->netdev
[0], dev
);
310 /* We are not ready to send data yet. */
311 netif_carrier_off(priv
->netdev
[0]);
313 /* Allocate driver context. */
314 priv
->card
= unifi_alloc_card(priv
->sdio
, priv
);
315 if (priv
->card
== NULL
) {
316 unifi_error(priv
, "Failed to allocate UniFi driver card struct.\n");
320 if (Unifi_instances
[bus_id
]) {
321 unifi_error(priv
, "Internal error: instance for slot %d is already taken\n",
324 Unifi_instances
[bus_id
] = priv
;
325 In_use
[bus_id
] = UNIFI_DEV_IN_USE
;
327 /* Save the netdev_priv for use by the netdev event callback mechanism */
328 Unifi_netdev_instances
[bus_id
* CSR_WIFI_NUM_INTERFACES
] = netdev_priv(priv
->netdev
[0]);
330 /* Initialise the mini-coredump capture buffers */
331 csrResult
= unifi_coredump_init(priv
->card
, (u16
)coredump_max
);
332 if (csrResult
!= CSR_RESULT_SUCCESS
) {
333 unifi_error(priv
, "Couldn't allocate mini-coredump buffers\n");
336 /* Create the character device nodes */
337 r
= uf_create_device_nodes(priv
, bus_id
);
343 * We use the slot number as unifi device index.
345 scnprintf(priv
->proc_entry_name
, 64, "driver/unifi%d", priv
->instance
);
347 * The following complex casting is in place in order to eliminate 64-bit compilation warning
348 * "cast to/from pointer from/to integer of different size"
350 if (!proc_create_data(priv
->proc_entry_name
, 0, NULL
,
351 &uf_proc_fops
, (void *)(long)priv
->instance
))
353 unifi_error(priv
, "unifi: can't create /proc/driver/unifi\n");
356 /* Allocate the net_device for interfaces other than 0. */
359 priv
->totalInterfaceCount
=0;
361 for(i
=1;i
<CSR_WIFI_NUM_INTERFACES
;i
++)
363 if( !uf_alloc_netdevice_for_other_interfaces(priv
, i
) )
365 /* error occured while allocating the net_device for interface[i]. The net_device are
366 * allocated for the interfaces with id<i. Dont worry, all the allocated net_device will
367 * be releasing chen the control goes to the label failed0.
369 unifi_error(priv
, "Failed to allocate driver private for interface[%d]\n", i
);
374 SET_NETDEV_DEV(priv
->netdev
[i
], dev
);
376 /* We are not ready to send data yet. */
377 netif_carrier_off(priv
->netdev
[i
]);
379 /* Save the netdev_priv for use by the netdev event callback mechanism */
380 Unifi_netdev_instances
[bus_id
* CSR_WIFI_NUM_INTERFACES
+ i
] = netdev_priv(priv
->netdev
[i
]);
384 for(i
=0;i
<CSR_WIFI_NUM_INTERFACES
;i
++)
386 netInterface_priv_t
*interfacePriv
= priv
->interfacePriv
[i
];
387 interfacePriv
->netdev_registered
=0;
391 #ifdef CSR_WIFI_RX_PATH_SPLIT
392 if (signal_buffer_init(priv
, CSR_WIFI_RX_SIGNAL_BUFFER_SIZE
))
394 unifi_error(priv
, "Failed to allocate shared memory for T-H signals\n");
397 priv
->rx_workqueue
= create_singlethread_workqueue("rx_workq");
398 if (priv
->rx_workqueue
== NULL
) {
399 unifi_error(priv
, "create_singlethread_workqueue failed \n");
402 INIT_WORK(&priv
->rx_work_struct
, rx_wq_handler
);
405 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
408 uf_register_hip_offline_debug(priv
);
412 /* Initialise the SME related threads and parameters */
413 r
= uf_sme_init(priv
);
415 unifi_error(priv
, "SME initialisation failed.\n");
420 * Run the userspace helper program (unififw) to perform
421 * the device initialisation.
423 unifi_trace(priv
, UDBG1
, "run UniFi helper app...\n");
424 r
= uf_run_unifihelper(priv
);
426 unifi_notice(priv
, "unable to run UniFi helper app\n");
427 /* Not a fatal error. */
430 up(&Unifi_instance_mutex
);
435 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
438 uf_unregister_hip_offline_debug(priv
);
441 #ifdef CSR_WIFI_RX_PATH_SPLIT
442 flush_workqueue(priv
->rx_workqueue
);
443 destroy_workqueue(priv
->rx_workqueue
);
445 signal_buffer_free(priv
, CSR_WIFI_RX_SIGNAL_BUFFER_SIZE
);
448 /* Remove the device nodes */
449 uf_destroy_device_nodes(priv
);
451 /* Deregister priv->netdev_client */
452 ul_deregister_client(priv
->netdev_client
);
455 if (priv
&& priv
->card
) {
456 unifi_coredump_free(priv
->card
);
457 unifi_free_card(priv
->card
);
460 uf_free_netdevice(priv
);
463 up(&Unifi_instance_mutex
);
466 } /* register_unifi_sdio() */
470 * ---------------------------------------------------------------------------
471 * ask_unifi_sdio_cleanup
473 * We can not free our private context, until all the char device
474 * clients have closed the file handles. unregister_unifi_sdio() which
475 * is called when a card is removed, waits on Unifi_cleanup_wq until
476 * the reference count becomes zero. It is time to wake it up now.
479 * priv Pointer to driver context.
483 * ---------------------------------------------------------------------------
486 ask_unifi_sdio_cleanup(unifi_priv_t
*priv
)
490 * Now clear the flag that says the old instance is in use.
491 * This is used to prevent a new instance being started before old
492 * one has finshed closing down, for example if bounce makes the card
493 * appear to be ejected and re-inserted quickly.
495 In_use
[priv
->instance
] = UNIFI_DEV_CLEANUP
;
497 unifi_trace(NULL
, UDBG5
, "ask_unifi_sdio_cleanup: wake up cleanup workqueue.\n");
498 wake_up(&Unifi_cleanup_wq
);
500 } /* ask_unifi_sdio_cleanup() */
504 * ---------------------------------------------------------------------------
507 * Release any resources owned by a unifi instance.
510 * priv Pointer to the instance to free.
514 * ---------------------------------------------------------------------------
517 cleanup_unifi_sdio(unifi_priv_t
*priv
)
521 static const CsrWifiMacAddress broadcast_address
= {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
523 /* Remove the device nodes */
524 uf_destroy_device_nodes(priv
);
526 /* Mark this device as gone away by NULLing the entry in Unifi_instances */
527 Unifi_instances
[priv
->instance
] = NULL
;
529 unifi_trace(priv
, UDBG5
, "cleanup_unifi_sdio: remove_proc_entry\n");
531 * Free the children of priv before unifi_free_netdevice() frees
534 remove_proc_entry(priv
->proc_entry_name
, 0);
537 /* Unregister netdev as a client. */
538 if (priv
->netdev_client
) {
539 unifi_trace(priv
, UDBG2
, "Netdev client (id:%d s:0x%X) is unregistered\n",
540 priv
->netdev_client
->client_id
, priv
->netdev_client
->sender_id
);
541 ul_deregister_client(priv
->netdev_client
);
544 /* Destroy the SME related threads and parameters */
547 #ifdef CSR_SME_USERSPACE
548 priv
->smepriv
= NULL
;
551 #ifdef CSR_WIFI_HIP_DEBUG_OFFLINE
554 uf_unregister_hip_offline_debug(priv
);
558 /* Free any packets left in the Rx queues */
559 for(i
=0;i
<CSR_WIFI_NUM_INTERFACES
;i
++)
561 uf_free_pending_rx_packets(priv
, UF_UNCONTROLLED_PORT_Q
, broadcast_address
, i
);
562 uf_free_pending_rx_packets(priv
, UF_CONTROLLED_PORT_Q
, broadcast_address
, i
);
565 * We need to free the resources held by the core, which include tx skbs,
566 * otherwise we can not call unregister_netdev().
569 unifi_trace(priv
, UDBG5
, "cleanup_unifi_sdio: free card\n");
570 unifi_coredump_free(priv
->card
);
571 unifi_free_card(priv
->card
);
576 * Unregister the network device.
577 * We can not unregister the netdev before we release
578 * all pending packets in the core.
580 uf_unregister_netdev(priv
);
581 priv
->totalInterfaceCount
= 0;
583 /* Clear the table of registered netdev_priv's */
584 for (i
= 0; i
< CSR_WIFI_NUM_INTERFACES
; i
++) {
585 Unifi_netdev_instances
[priv
->instance
* CSR_WIFI_NUM_INTERFACES
+ i
] = NULL
;
588 unifi_trace(priv
, UDBG5
, "cleanup_unifi_sdio: uf_free_netdevice\n");
590 * When uf_free_netdevice() returns, the priv is invalid
591 * so we need to remember the instance to clear the global flag later.
593 priv_instance
= priv
->instance
;
595 #ifdef CSR_WIFI_RX_PATH_SPLIT
596 flush_workqueue(priv
->rx_workqueue
);
597 destroy_workqueue(priv
->rx_workqueue
);
598 signal_buffer_free(priv
, CSR_WIFI_RX_SIGNAL_BUFFER_SIZE
);
601 /* Priv is freed as part of the net_device */
602 uf_free_netdevice(priv
);
605 * Now clear the flag that says the old instance is in use.
606 * This is used to prevent a new instance being started before old
607 * one has finshed closing down, for example if bounce makes the card
608 * appear to be ejected and re-inserted quickly.
610 In_use
[priv_instance
] = UNIFI_DEV_NOT_IN_USE
;
612 unifi_trace(NULL
, UDBG5
, "cleanup_unifi_sdio: DONE.\n");
614 } /* cleanup_unifi_sdio() */
618 * ---------------------------------------------------------------------------
619 * unregister_unifi_sdio
621 * Call from SDIO driver when it detects that UniFi has been removed.
624 * bus_id Number of the card that was ejected.
628 * ---------------------------------------------------------------------------
631 unregister_unifi_sdio(int bus_id
)
635 u8 reason
= CONFIG_IND_EXIT
;
637 if ((bus_id
< 0) || (bus_id
>= MAX_UNIFI_DEVS
)) {
638 unifi_error(NULL
, "unregister_unifi_sdio: invalid device %d\n",
643 priv
= Unifi_instances
[bus_id
];
645 unifi_error(priv
, "unregister_unifi_sdio: device %d is not registered\n",
650 /* Stop the network traffic before freeing the core. */
651 for(interfaceTag
=0;interfaceTag
<priv
->totalInterfaceCount
;interfaceTag
++)
653 netInterface_priv_t
*interfacePriv
= priv
->interfacePriv
[interfaceTag
];
654 if(interfacePriv
->netdev_registered
)
656 netif_carrier_off(priv
->netdev
[interfaceTag
]);
657 netif_tx_stop_all_queues(priv
->netdev
[interfaceTag
]);
661 #ifdef CSR_NATIVE_LINUX
663 * If the unifi thread was started, signal it to stop. This
664 * should cause any userspace processes with open unifi device to
667 uf_stop_thread(priv
, &priv
->bh_thread
);
669 /* Unregister the interrupt handler */
670 if (csr_sdio_linux_remove_irq(priv
->sdio
)) {
672 "csr_sdio_linux_remove_irq failed to talk to card.\n");
675 /* Ensure no MLME functions are waiting on a the mlme_event semaphore. */
677 #endif /* CSR_NATIVE_LINUX */
679 ul_log_config_ind(priv
, &reason
, sizeof(u8
));
681 /* Deregister the UDI hook from the core. */
682 unifi_remove_udi_hook(priv
->card
, logging_handler
);
684 uf_put_instance(bus_id
);
687 * Wait until the device is cleaned up. i.e., when all userspace
688 * processes have closed any open unifi devices.
690 wait_event(Unifi_cleanup_wq
, In_use
[bus_id
] == UNIFI_DEV_CLEANUP
);
691 unifi_trace(NULL
, UDBG5
, "Received clean up event\n");
693 /* Now we can free the private context and the char device nodes */
694 cleanup_unifi_sdio(priv
);
696 } /* unregister_unifi_sdio() */
700 * ---------------------------------------------------------------------------
703 * Find the context structure for a given UniFi device instance.
706 * inst The instance number to look for.
710 * ---------------------------------------------------------------------------
713 uf_find_instance(int inst
)
715 if ((inst
< 0) || (inst
>= MAX_UNIFI_DEVS
)) {
718 return Unifi_instances
[inst
];
719 } /* uf_find_instance() */
723 * ---------------------------------------------------------------------------
726 * Find the device instance for a given context structure.
729 * priv The context structure pointer to look for.
732 * index of instance, -1 otherwise.
733 * ---------------------------------------------------------------------------
736 uf_find_priv(unifi_priv_t
*priv
)
744 for (inst
= 0; inst
< MAX_UNIFI_DEVS
; inst
++) {
745 if (Unifi_instances
[inst
] == priv
) {
751 } /* uf_find_priv() */
754 * ---------------------------------------------------------------------------
755 * uf_find_netdev_priv
757 * Find the device instance for a given netdev context structure.
760 * priv The context structure pointer to look for.
763 * index of instance, -1 otherwise.
764 * ---------------------------------------------------------------------------
767 uf_find_netdev_priv(netInterface_priv_t
*priv
)
775 for (inst
= 0; inst
< MAX_UNIFI_DEVS
* CSR_WIFI_NUM_INTERFACES
; inst
++) {
776 if (Unifi_netdev_instances
[inst
] == priv
) {
782 } /* uf_find_netdev_priv() */
785 * ---------------------------------------------------------------------------
788 * Find the context structure for a given UniFi device instance
789 * and increment the reference count.
792 * inst The instance number to look for.
795 * Pointer to the instance or NULL if no instance exists.
796 * ---------------------------------------------------------------------------
799 uf_get_instance(int inst
)
803 down(&Unifi_instance_mutex
);
805 priv
= uf_find_instance(inst
);
810 up(&Unifi_instance_mutex
);
816 * ---------------------------------------------------------------------------
819 * Decrement the context reference count, freeing resources and
820 * shutting down the driver when the count reaches zero.
823 * inst The instance number to look for.
826 * Pointer to the instance or NULL if no instance exists.
827 * ---------------------------------------------------------------------------
830 uf_put_instance(int inst
)
834 down(&Unifi_instance_mutex
);
836 priv
= uf_find_instance(inst
);
839 if (priv
->ref_count
== 0) {
840 ask_unifi_sdio_cleanup(priv
);
844 up(&Unifi_instance_mutex
);
849 * ---------------------------------------------------------------------------
852 * Read method for driver node in /proc/driver/unifi0
864 * ---------------------------------------------------------------------------
866 #ifdef CONFIG_PROC_FS
867 static int uf_proc_show(struct seq_file
*m
, void *v
)
873 * The following complex casting is in place in order to eliminate
874 * 64-bit compilation warning "cast to/from pointer from/to integer of
877 priv
= uf_find_instance((long)m
->private);
881 seq_printf(m
, "UniFi SDIO Driver: %s %s %s\n",
882 CSR_WIFI_VERSION
, __DATE__
, __TIME__
);
883 #ifdef CSR_SME_USERSPACE
884 seq_puts(m
, "SME: CSR userspace ");
885 #ifdef CSR_SUPPORT_WEXT
886 seq_puts(m
, "with WEXT support\n");
889 #endif /* CSR_SUPPORT_WEXT */
890 #endif /* CSR_SME_USERSPACE */
891 #ifdef CSR_NATIVE_LINUX
892 seq_puts(m
, "SME: native\n");
895 #ifdef CSR_SUPPORT_SME
896 seq_printf(m
, "Firmware (ROM) build:%u, Patch:%u\n",
897 priv
->card_info
.fw_build
,
898 priv
->sme_versions
.firmwarePatch
);
901 unifi_print_status(priv
->card
, m
);
903 seq_printf(m
, "Last dbg str: %s\n", priv
->last_debug_string
);
905 seq_puts(m
, "Last dbg16:");
906 for (i
= 0; i
< 8; i
++)
907 seq_printf(m
, " %04X", priv
->last_debug_word16
[i
]);
911 seq_printf(m
, " %04X", priv
->last_debug_word16
[i
]);
921 uf_lx_suspend(CsrSdioFunction
*sdio_ctx
)
923 unifi_priv_t
*priv
= sdio_ctx
->driverData
;
926 CsrSdioSuspendAcknowledge(sdio_ctx
, CSR_RESULT_SUCCESS
);
930 uf_lx_resume(CsrSdioFunction
*sdio_ctx
)
932 unifi_priv_t
*priv
= sdio_ctx
->driverData
;
935 CsrSdioResumeAcknowledge(sdio_ctx
, CSR_RESULT_SUCCESS
);
938 static int active_slot
= MAX_UNIFI_DEVS
;
939 static struct device
*os_devices
[MAX_UNIFI_DEVS
];
942 uf_add_os_device(int bus_id
, struct device
*os_device
)
944 if ((bus_id
< 0) || (bus_id
>= MAX_UNIFI_DEVS
)) {
945 unifi_error(NULL
, "uf_add_os_device: invalid device %d\n",
950 active_slot
= bus_id
;
951 os_devices
[bus_id
] = os_device
;
952 } /* uf_add_os_device() */
955 uf_remove_os_device(int bus_id
)
957 if ((bus_id
< 0) || (bus_id
>= MAX_UNIFI_DEVS
)) {
958 unifi_error(NULL
, "uf_remove_os_device: invalid device %d\n",
963 active_slot
= bus_id
;
964 os_devices
[bus_id
] = NULL
;
965 } /* uf_remove_os_device() */
968 uf_sdio_inserted(CsrSdioFunction
*sdio_ctx
)
972 unifi_trace(NULL
, UDBG5
, "uf_sdio_inserted(0x%p), slot_id=%d, dev=%p\n",
973 sdio_ctx
, active_slot
, os_devices
[active_slot
]);
975 priv
= register_unifi_sdio(sdio_ctx
, active_slot
, os_devices
[active_slot
]);
977 CsrSdioInsertedAcknowledge(sdio_ctx
, CSR_RESULT_FAILURE
);
981 sdio_ctx
->driverData
= priv
;
983 CsrSdioInsertedAcknowledge(sdio_ctx
, CSR_RESULT_SUCCESS
);
984 } /* uf_sdio_inserted() */
988 uf_sdio_removed(CsrSdioFunction
*sdio_ctx
)
990 unregister_unifi_sdio(active_slot
);
991 CsrSdioRemovedAcknowledge(sdio_ctx
);
992 } /* uf_sdio_removed() */
996 uf_sdio_dsr_handler(CsrSdioFunction
*sdio_ctx
)
998 unifi_priv_t
*priv
= sdio_ctx
->driverData
;
1000 unifi_sdio_interrupt_handler(priv
->card
);
1001 } /* uf_sdio_dsr_handler() */
1004 * ---------------------------------------------------------------------------
1005 * uf_sdio_int_handler
1007 * Interrupt callback function for SDIO interrupts.
1008 * This is called in kernel context (i.e. not interrupt context).
1009 * We retrieve the unifi context pointer and call the main UniFi
1010 * interrupt handler.
1013 * fdev SDIO context pointer
1017 * ---------------------------------------------------------------------------
1019 static CsrSdioInterruptDsrCallback
1020 uf_sdio_int_handler(CsrSdioFunction
*sdio_ctx
)
1022 return uf_sdio_dsr_handler
;
1023 } /* uf_sdio_int_handler() */
1028 static CsrSdioFunctionId unifi_ids
[] =
1031 .manfId
= SDIO_MANF_ID_CSR
,
1032 .cardId
= SDIO_CARD_ID_UNIFI_3
,
1033 .sdioFunction
= SDIO_WLAN_FUNC_ID_UNIFI_3
,
1034 .sdioInterface
= CSR_SDIO_ANY_SDIO_INTERFACE
,
1037 .manfId
= SDIO_MANF_ID_CSR
,
1038 .cardId
= SDIO_CARD_ID_UNIFI_4
,
1039 .sdioFunction
= SDIO_WLAN_FUNC_ID_UNIFI_4
,
1040 .sdioInterface
= CSR_SDIO_ANY_SDIO_INTERFACE
,
1046 * Structure to register with the glue layer.
1048 static CsrSdioFunctionDriver unifi_sdioFunction_drv
=
1050 .inserted
= uf_sdio_inserted
,
1051 .removed
= uf_sdio_removed
,
1052 .intr
= uf_sdio_int_handler
,
1053 .suspend
= uf_lx_suspend
,
1054 .resume
= uf_lx_resume
,
1057 .idsCount
= sizeof(unifi_ids
) / sizeof(unifi_ids
[0])
1062 * ---------------------------------------------------------------------------
1066 * These functions are called from the main module load and unload
1067 * functions. They perform the appropriate operations for the monolithic
1075 * ---------------------------------------------------------------------------
1080 CsrResult csrResult
;
1082 csrResult
= CsrSdioFunctionDriverRegister(&unifi_sdioFunction_drv
);
1083 if (csrResult
!= CSR_RESULT_SUCCESS
) {
1084 unifi_error(NULL
, "Failed to register UniFi SDIO driver: csrResult=%d\n", csrResult
);
1089 } /* uf_sdio_load() */
1094 uf_sdio_unload(void)
1096 CsrSdioFunctionDriverUnregister(&unifi_sdioFunction_drv
);
1097 } /* uf_sdio_unload() */