1 /* $NetBSD: isp1763var.h,v 1.1 2026/10/11 16:09:06 rkujawa Exp $ */ 2 3 /*- 4 * Copyright (c) 2026 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Radoslaw Kujawa. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _DEV_IC_ISP1763VAR_H_ 33 #define _DEV_IC_ISP1763VAR_H_ 34 35 #include <sys/types.h> 36 37 #ifdef _KERNEL 38 #include <sys/bus.h> 39 #include <sys/device.h> 40 #include <sys/mutex.h> 41 #include <sys/pool.h> 42 #include <sys/queue.h> 43 44 #include <dev/usb/usb.h> 45 #include <dev/usb/usbdi.h> 46 #include <dev/usb/usbdivar.h> 47 #endif 48 49 #include <dev/ic/isp1763reg.h> 50 51 /* What a transfer descriptor is built from. */ 52 struct isp1763hc_ptdreq { 53 uint16_t pr_mem; /* payload, CPU address */ 54 uint16_t pr_len; 55 uint16_t pr_mps; 56 uint8_t pr_mult; 57 uint8_t pr_addr; 58 uint8_t pr_ep; 59 uint8_t pr_token; 60 uint8_t pr_eptype; 61 uint8_t pr_hub; 62 uint8_t pr_port; 63 uint8_t pr_se; 64 uint8_t pr_uframe; 65 uint8_t pr_usa; 66 uint8_t pr_uscs; 67 bool pr_split; 68 bool pr_toggle; 69 bool pr_ping; 70 }; 71 72 void isp1763hc_ptd_build(const struct isp1763hc_ptdreq *, uint32_t *); 73 void isp1763hc_ptd_encode(const uint32_t *, uint8_t *, int); 74 void isp1763hc_ptd_decode(const uint8_t *, uint32_t *, int); 75 void isp1763hc_intr_sched(bool, u_int, uint8_t *, uint8_t *); 76 uint16_t isp1763hc_last_map(uint16_t); 77 78 #ifdef _KERNEL 79 80 /* A transfer descriptor queue: ATL or INT. */ 81 struct isp1763hc_queue { 82 struct isp1763hc_xfer *q_xfer[ISP1763_NSLOTS]; 83 TAILQ_HEAD(, isp1763hc_xfer) q_wait; 84 bus_size_t q_regdone; 85 bus_size_t q_regskip; 86 bus_size_t q_reglast; 87 uint16_t q_irq; 88 uint16_t q_ptdbase; 89 uint16_t q_membase; 90 uint16_t q_memsize; 91 uint16_t q_busy; 92 uint16_t q_skip; 93 }; 94 95 struct isp1763hc_softc { 96 device_t sc_dev; 97 struct usbd_bus sc_bus; 98 99 kmutex_t sc_lock; 100 kmutex_t sc_rhlock; 101 pool_cache_t sc_xferpool; 102 void *sc_softint; 103 device_t sc_child; 104 struct usbd_xfer *sc_intrxfer; 105 106 struct isp1763hc_queue sc_atl; 107 struct isp1763hc_queue sc_int; 108 109 uint16_t sc_hwmode; /* bus mode, front end */ 110 bool sc_dying; 111 bool sc_isreset; 112 113 /* Chip access, provided by the front end. */ 114 uint8_t (*sc_rd1)(struct isp1763hc_softc *, bus_size_t); 115 void (*sc_wr1)(struct isp1763hc_softc *, bus_size_t, 116 uint8_t); 117 uint16_t (*sc_rd2)(struct isp1763hc_softc *, bus_size_t); 118 void (*sc_wr2)(struct isp1763hc_softc *, bus_size_t, 119 uint16_t); 120 void (*sc_memrd)(struct isp1763hc_softc *, uint16_t, void *, 121 size_t); 122 void (*sc_memwr)(struct isp1763hc_softc *, uint16_t, 123 const void *, size_t); 124 void (*sc_intr_enable)(struct isp1763hc_softc *, bool); 125 }; 126 127 #define ISP_READ1(sc, r) ((sc)->sc_rd1((sc), (r))) 128 #define ISP_WRITE1(sc, r, v) ((sc)->sc_wr1((sc), (r), (v))) 129 #define ISP_READ2(sc, r) ((sc)->sc_rd2((sc), (r))) 130 #define ISP_WRITE2(sc, r, v) ((sc)->sc_wr2((sc), (r), (v))) 131 #define ISP_MEMREAD(sc, a, p, n) \ 132 ((sc)->sc_memrd((sc), (a), (p), (n))) 133 #define ISP_MEMWRITE(sc, a, p, n) \ 134 ((sc)->sc_memwr((sc), (a), (p), (n))) 135 #define ISP_INTR_ENABLE(sc, on) ((sc)->sc_intr_enable((sc), (on))) 136 137 int isp1763hc_attach(struct isp1763hc_softc *); 138 int isp1763hc_detach(struct isp1763hc_softc *, int); 139 int isp1763hc_activate(device_t, enum devact); 140 void isp1763hc_childdet(device_t, device_t); 141 void isp1763hc_shutdown(struct isp1763hc_softc *); 142 void isp1763hc_intr(struct isp1763hc_softc *); 143 144 #endif /* _KERNEL */ 145 146 #endif /* !_DEV_IC_ISP1763VAR_H_ */ 147