102ac6454SAndrew Thompson /* $FreeBSD$ */ 202ac6454SAndrew Thompson /*- 302ac6454SAndrew Thompson * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 402ac6454SAndrew Thompson * 502ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 602ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 702ac6454SAndrew Thompson * are met: 802ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 902ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1002ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1102ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1202ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1302ac6454SAndrew Thompson * 1402ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1502ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1602ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1702ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1802ac6454SAndrew Thompson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1902ac6454SAndrew Thompson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2002ac6454SAndrew Thompson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2102ac6454SAndrew Thompson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2202ac6454SAndrew Thompson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2302ac6454SAndrew Thompson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2402ac6454SAndrew Thompson * SUCH DAMAGE. 2502ac6454SAndrew Thompson */ 2602ac6454SAndrew Thompson 2702ac6454SAndrew Thompson #include <dev/usb/usb_defs.h> 2802ac6454SAndrew Thompson #include <dev/usb/usb_mfunc.h> 2902ac6454SAndrew Thompson #include <dev/usb/usb_error.h> 3002ac6454SAndrew Thompson #include <dev/usb/usb.h> 3102ac6454SAndrew Thompson 3202ac6454SAndrew Thompson #include <dev/usb/usb_core.h> 3302ac6454SAndrew Thompson #include <dev/usb/usb_process.h> 3402ac6454SAndrew Thompson #include <dev/usb/usb_device.h> 3502ac6454SAndrew Thompson #include <dev/usb/usb_dynamic.h> 3602ac6454SAndrew Thompson 3702ac6454SAndrew Thompson /* function prototypes */ 3802ac6454SAndrew Thompson static usb2_temp_get_desc_t usb2_temp_get_desc_w; 3902ac6454SAndrew Thompson static usb2_temp_setup_by_index_t usb2_temp_setup_by_index_w; 4002ac6454SAndrew Thompson static usb2_temp_unsetup_t usb2_temp_unsetup_w; 4102ac6454SAndrew Thompson static usb2_test_quirk_t usb2_test_quirk_w; 4202ac6454SAndrew Thompson static usb2_test_huawei_autoinst_t usb2_test_huawei_autoinst_w; 4302ac6454SAndrew Thompson static usb2_quirk_ioctl_t usb2_quirk_ioctl_w; 4402ac6454SAndrew Thompson 4502ac6454SAndrew Thompson /* global variables */ 4602ac6454SAndrew Thompson usb2_temp_get_desc_t *usb2_temp_get_desc_p = &usb2_temp_get_desc_w; 4702ac6454SAndrew Thompson usb2_temp_setup_by_index_t *usb2_temp_setup_by_index_p = &usb2_temp_setup_by_index_w; 4802ac6454SAndrew Thompson usb2_temp_unsetup_t *usb2_temp_unsetup_p = &usb2_temp_unsetup_w; 4902ac6454SAndrew Thompson usb2_test_quirk_t *usb2_test_quirk_p = &usb2_test_quirk_w; 5002ac6454SAndrew Thompson usb2_test_huawei_autoinst_t *usb2_test_huawei_autoinst_p = &usb2_test_huawei_autoinst_w; 5102ac6454SAndrew Thompson usb2_quirk_ioctl_t *usb2_quirk_ioctl_p = &usb2_quirk_ioctl_w; 5202ac6454SAndrew Thompson devclass_t usb2_devclass_ptr = NULL; 5302ac6454SAndrew Thompson 5402ac6454SAndrew Thompson static usb2_error_t 5502ac6454SAndrew Thompson usb2_temp_setup_by_index_w(struct usb2_device *udev, uint16_t index) 5602ac6454SAndrew Thompson { 5702ac6454SAndrew Thompson return (USB_ERR_INVAL); 5802ac6454SAndrew Thompson } 5902ac6454SAndrew Thompson 6002ac6454SAndrew Thompson static uint8_t 6102ac6454SAndrew Thompson usb2_test_quirk_w(const struct usb2_lookup_info *info, uint16_t quirk) 6202ac6454SAndrew Thompson { 6302ac6454SAndrew Thompson return (0); /* no match */ 6402ac6454SAndrew Thompson } 6502ac6454SAndrew Thompson 6602ac6454SAndrew Thompson static int 6702ac6454SAndrew Thompson usb2_quirk_ioctl_w(unsigned long cmd, caddr_t data, int fflag, struct thread *td) 6802ac6454SAndrew Thompson { 6902ac6454SAndrew Thompson return (ENOIOCTL); 7002ac6454SAndrew Thompson } 7102ac6454SAndrew Thompson 7202ac6454SAndrew Thompson static void 7302ac6454SAndrew Thompson usb2_temp_get_desc_w(struct usb2_device *udev, struct usb2_device_request *req, const void **pPtr, uint16_t *pLength) 7402ac6454SAndrew Thompson { 7502ac6454SAndrew Thompson /* stall */ 7602ac6454SAndrew Thompson *pPtr = NULL; 7702ac6454SAndrew Thompson *pLength = 0; 7802ac6454SAndrew Thompson } 7902ac6454SAndrew Thompson 8002ac6454SAndrew Thompson static void 8102ac6454SAndrew Thompson usb2_temp_unsetup_w(struct usb2_device *udev) 8202ac6454SAndrew Thompson { 8302ac6454SAndrew Thompson if (udev->usb2_template_ptr) { 8402ac6454SAndrew Thompson 8502ac6454SAndrew Thompson free(udev->usb2_template_ptr, M_USB); 8602ac6454SAndrew Thompson 8702ac6454SAndrew Thompson udev->usb2_template_ptr = NULL; 8802ac6454SAndrew Thompson } 8902ac6454SAndrew Thompson } 9002ac6454SAndrew Thompson 9102ac6454SAndrew Thompson static uint8_t 9202ac6454SAndrew Thompson usb2_test_huawei_autoinst_w(struct usb2_device *udev, 9302ac6454SAndrew Thompson struct usb2_attach_arg *uaa) 9402ac6454SAndrew Thompson { 9502ac6454SAndrew Thompson return (USB_ERR_INVAL); 9602ac6454SAndrew Thompson } 9702ac6454SAndrew Thompson 9802ac6454SAndrew Thompson void 9902ac6454SAndrew Thompson usb2_quirk_unload(void *arg) 10002ac6454SAndrew Thompson { 10102ac6454SAndrew Thompson /* reset function pointers */ 10202ac6454SAndrew Thompson 10302ac6454SAndrew Thompson usb2_test_quirk_p = &usb2_test_quirk_w; 10402ac6454SAndrew Thompson usb2_quirk_ioctl_p = &usb2_quirk_ioctl_w; 10502ac6454SAndrew Thompson 10602ac6454SAndrew Thompson /* wait for CPU to exit the loaded functions, if any */ 10702ac6454SAndrew Thompson 10802ac6454SAndrew Thompson /* XXX this is a tradeoff */ 10902ac6454SAndrew Thompson 11002ac6454SAndrew Thompson pause("WAIT", hz); 11102ac6454SAndrew Thompson } 11202ac6454SAndrew Thompson 11302ac6454SAndrew Thompson void 11402ac6454SAndrew Thompson usb2_temp_unload(void *arg) 11502ac6454SAndrew Thompson { 11602ac6454SAndrew Thompson /* reset function pointers */ 11702ac6454SAndrew Thompson 11802ac6454SAndrew Thompson usb2_temp_get_desc_p = &usb2_temp_get_desc_w; 11902ac6454SAndrew Thompson usb2_temp_setup_by_index_p = &usb2_temp_setup_by_index_w; 12002ac6454SAndrew Thompson usb2_temp_unsetup_p = &usb2_temp_unsetup_w; 12102ac6454SAndrew Thompson 12202ac6454SAndrew Thompson /* wait for CPU to exit the loaded functions, if any */ 12302ac6454SAndrew Thompson 12402ac6454SAndrew Thompson /* XXX this is a tradeoff */ 12502ac6454SAndrew Thompson 12602ac6454SAndrew Thompson pause("WAIT", hz); 12702ac6454SAndrew Thompson } 12802ac6454SAndrew Thompson 12902ac6454SAndrew Thompson void 13002ac6454SAndrew Thompson usb2_bus_unload(void *arg) 13102ac6454SAndrew Thompson { 13202ac6454SAndrew Thompson /* reset function pointers */ 13302ac6454SAndrew Thompson 13402ac6454SAndrew Thompson usb2_devclass_ptr = NULL; 13502ac6454SAndrew Thompson 13602ac6454SAndrew Thompson /* wait for CPU to exit the loaded functions, if any */ 13702ac6454SAndrew Thompson 13802ac6454SAndrew Thompson /* XXX this is a tradeoff */ 13902ac6454SAndrew Thompson 14002ac6454SAndrew Thompson pause("WAIT", hz); 14102ac6454SAndrew Thompson } 14202ac6454SAndrew Thompson 14302ac6454SAndrew Thompson void 14402ac6454SAndrew Thompson usb2_test_huawei_unload(void *arg) 14502ac6454SAndrew Thompson { 14602ac6454SAndrew Thompson /* reset function pointers */ 14702ac6454SAndrew Thompson 14802ac6454SAndrew Thompson usb2_test_huawei_autoinst_p = &usb2_test_huawei_autoinst_w; 14902ac6454SAndrew Thompson 15002ac6454SAndrew Thompson /* wait for CPU to exit the loaded functions, if any */ 15102ac6454SAndrew Thompson 15202ac6454SAndrew Thompson /* XXX this is a tradeoff */ 15302ac6454SAndrew Thompson 15402ac6454SAndrew Thompson pause("WAIT", 16*hz); 15502ac6454SAndrew Thompson } 156