| @@ -1,41 +1,41 @@ | | | @@ -1,41 +1,41 @@ |
1 | /* $NetBSD: if_urtwn.c,v 1.53.2.4 2018/08/08 10:28:35 martin Exp $ */ | | 1 | /* $NetBSD: if_urtwn.c,v 1.53.2.5 2018/12/18 18:32:00 martin Exp $ */ |
2 | /* $OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $ */ | | 2 | /* $OpenBSD: if_urtwn.c,v 1.42 2015/02/10 23:25:46 mpi Exp $ */ |
3 | | | 3 | |
4 | /*- | | 4 | /*- |
5 | * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> | | 5 | * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> |
6 | * Copyright (c) 2014 Kevin Lo <kevlo@FreeBSD.org> | | 6 | * Copyright (c) 2014 Kevin Lo <kevlo@FreeBSD.org> |
7 | * Copyright (c) 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au> | | 7 | * Copyright (c) 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au> |
8 | * | | 8 | * |
9 | * Permission to use, copy, modify, and distribute this software for any | | 9 | * Permission to use, copy, modify, and distribute this software for any |
10 | * purpose with or without fee is hereby granted, provided that the above | | 10 | * purpose with or without fee is hereby granted, provided that the above |
11 | * copyright notice and this permission notice appear in all copies. | | 11 | * copyright notice and this permission notice appear in all copies. |
12 | * | | 12 | * |
13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | | 13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | | 14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | | 15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | | 16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | | 17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | | 18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | | 19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
20 | */ | | 20 | */ |
21 | | | 21 | |
22 | /*- | | 22 | /*- |
23 | * Driver for Realtek RTL8188CE-VAU/RTL8188CUS/RTL8188EU/RTL8188RU/RTL8192CU | | 23 | * Driver for Realtek RTL8188CE-VAU/RTL8188CUS/RTL8188EU/RTL8188RU/RTL8192CU |
24 | * RTL8192EU. | | 24 | * RTL8192EU. |
25 | */ | | 25 | */ |
26 | | | 26 | |
27 | #include <sys/cdefs.h> | | 27 | #include <sys/cdefs.h> |
28 | __KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.53.2.4 2018/08/08 10:28:35 martin Exp $"); | | 28 | __KERNEL_RCSID(0, "$NetBSD: if_urtwn.c,v 1.53.2.5 2018/12/18 18:32:00 martin Exp $"); |
29 | | | 29 | |
30 | #ifdef _KERNEL_OPT | | 30 | #ifdef _KERNEL_OPT |
31 | #include "opt_inet.h" | | 31 | #include "opt_inet.h" |
32 | #include "opt_usb.h" | | 32 | #include "opt_usb.h" |
33 | #endif | | 33 | #endif |
34 | | | 34 | |
35 | #include <sys/param.h> | | 35 | #include <sys/param.h> |
36 | #include <sys/sockio.h> | | 36 | #include <sys/sockio.h> |
37 | #include <sys/sysctl.h> | | 37 | #include <sys/sysctl.h> |
38 | #include <sys/mbuf.h> | | 38 | #include <sys/mbuf.h> |
39 | #include <sys/kernel.h> | | 39 | #include <sys/kernel.h> |
40 | #include <sys/socket.h> | | 40 | #include <sys/socket.h> |
41 | #include <sys/systm.h> | | 41 | #include <sys/systm.h> |
| @@ -1020,27 +1020,27 @@ urtwn_fw_cmd(struct urtwn_softc *sc, uin | | | @@ -1020,27 +1020,27 @@ urtwn_fw_cmd(struct urtwn_softc *sc, uin |
1020 | device_xname(sc->sc_dev), __func__, id, buf, len)); | | 1020 | device_xname(sc->sc_dev), __func__, id, buf, len)); |
1021 | | | 1021 | |
1022 | KASSERT(mutex_owned(&sc->sc_write_mtx)); | | 1022 | KASSERT(mutex_owned(&sc->sc_write_mtx)); |
1023 | | | 1023 | |
1024 | mutex_enter(&sc->sc_fwcmd_mtx); | | 1024 | mutex_enter(&sc->sc_fwcmd_mtx); |
1025 | fwcur = sc->fwcur; | | 1025 | fwcur = sc->fwcur; |
1026 | sc->fwcur = (sc->fwcur + 1) % R92C_H2C_NBOX; | | 1026 | sc->fwcur = (sc->fwcur + 1) % R92C_H2C_NBOX; |
1027 | mutex_exit(&sc->sc_fwcmd_mtx); | | 1027 | mutex_exit(&sc->sc_fwcmd_mtx); |
1028 | | | 1028 | |
1029 | /* Wait for current FW box to be empty. */ | | 1029 | /* Wait for current FW box to be empty. */ |
1030 | for (ntries = 0; ntries < 100; ntries++) { | | 1030 | for (ntries = 0; ntries < 100; ntries++) { |
1031 | if (!(urtwn_read_1(sc, R92C_HMETFR) & (1 << fwcur))) | | 1031 | if (!(urtwn_read_1(sc, R92C_HMETFR) & (1 << fwcur))) |
1032 | break; | | 1032 | break; |
1033 | DELAY(10); | | 1033 | DELAY(2000); |
1034 | } | | 1034 | } |
1035 | if (ntries == 100) { | | 1035 | if (ntries == 100) { |
1036 | aprint_error_dev(sc->sc_dev, | | 1036 | aprint_error_dev(sc->sc_dev, |
1037 | "could not send firmware command %d\n", id); | | 1037 | "could not send firmware command %d\n", id); |
1038 | return ETIMEDOUT; | | 1038 | return ETIMEDOUT; |
1039 | } | | 1039 | } |
1040 | | | 1040 | |
1041 | memset(&cmd, 0, sizeof(cmd)); | | 1041 | memset(&cmd, 0, sizeof(cmd)); |
1042 | KASSERT(len <= sizeof(cmd.msg)); | | 1042 | KASSERT(len <= sizeof(cmd.msg)); |
1043 | memcpy(cmd.msg, buf, len); | | 1043 | memcpy(cmd.msg, buf, len); |
1044 | | | 1044 | |
1045 | /* Write the first word last since that will trigger the FW. */ | | 1045 | /* Write the first word last since that will trigger the FW. */ |
1046 | cp = (uint8_t *)&cmd; | | 1046 | cp = (uint8_t *)&cmd; |
| @@ -3464,32 +3464,32 @@ urtwn_load_firmware(struct urtwn_softc * | | | @@ -3464,32 +3464,32 @@ urtwn_load_firmware(struct urtwn_softc * |
3464 | aprint_error_dev(sc->sc_dev, | | 3464 | aprint_error_dev(sc->sc_dev, |
3465 | "timeout waiting for checksum report\n"); | | 3465 | "timeout waiting for checksum report\n"); |
3466 | error = ETIMEDOUT; | | 3466 | error = ETIMEDOUT; |
3467 | goto fail; | | 3467 | goto fail; |
3468 | } | | 3468 | } |
3469 | | | 3469 | |
3470 | /* Wait for firmware readiness. */ | | 3470 | /* Wait for firmware readiness. */ |
3471 | reg = urtwn_read_4(sc, R92C_MCUFWDL); | | 3471 | reg = urtwn_read_4(sc, R92C_MCUFWDL); |
3472 | reg = (reg & ~R92C_MCUFWDL_WINTINI_RDY) | R92C_MCUFWDL_RDY; | | 3472 | reg = (reg & ~R92C_MCUFWDL_WINTINI_RDY) | R92C_MCUFWDL_RDY; |
3473 | urtwn_write_4(sc, R92C_MCUFWDL, reg); | | 3473 | urtwn_write_4(sc, R92C_MCUFWDL, reg); |
3474 | if (ISSET(sc->chip, URTWN_CHIP_88E) || | | 3474 | if (ISSET(sc->chip, URTWN_CHIP_88E) || |
3475 | ISSET(sc->chip, URTWN_CHIP_92EU)) | | 3475 | ISSET(sc->chip, URTWN_CHIP_92EU)) |
3476 | urtwn_r88e_fw_reset(sc); | | 3476 | urtwn_r88e_fw_reset(sc); |
3477 | for (ntries = 0; ntries < 1000; ntries++) { | | 3477 | for (ntries = 0; ntries < 6000; ntries++) { |
3478 | if (urtwn_read_4(sc, R92C_MCUFWDL) & R92C_MCUFWDL_WINTINI_RDY) | | 3478 | if (urtwn_read_4(sc, R92C_MCUFWDL) & R92C_MCUFWDL_WINTINI_RDY) |
3479 | break; | | 3479 | break; |
3480 | DELAY(5); | | 3480 | DELAY(5); |
3481 | } | | 3481 | } |
3482 | if (ntries == 1000) { | | 3482 | if (ntries == 6000) { |
3483 | aprint_error_dev(sc->sc_dev, | | 3483 | aprint_error_dev(sc->sc_dev, |
3484 | "timeout waiting for firmware readiness\n"); | | 3484 | "timeout waiting for firmware readiness\n"); |
3485 | error = ETIMEDOUT; | | 3485 | error = ETIMEDOUT; |
3486 | goto fail; | | 3486 | goto fail; |
3487 | } | | 3487 | } |
3488 | fail: | | 3488 | fail: |
3489 | firmware_free(fw, fwlen); | | 3489 | firmware_free(fw, fwlen); |
3490 | return error; | | 3490 | return error; |
3491 | } | | 3491 | } |
3492 | | | 3492 | |
3493 | static __inline int | | 3493 | static __inline int |
3494 | urtwn_dma_init(struct urtwn_softc *sc) | | 3494 | urtwn_dma_init(struct urtwn_softc *sc) |
3495 | { | | 3495 | { |