Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/usb/net/if_ure.c
| Show All 18 Lines | |||||
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||
| * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
| * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
| * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
| * SUCH DAMAGE. | * SUCH DAMAGE. | ||||
| */ | */ | ||||
| #include "opt_inet6.h" | |||||
| #include <sys/param.h> | #include <sys/param.h> | ||||
| #include <sys/systm.h> | #include <sys/systm.h> | ||||
| #include <sys/bus.h> | #include <sys/bus.h> | ||||
| #include <sys/condvar.h> | #include <sys/condvar.h> | ||||
| #include <sys/kernel.h> | #include <sys/kernel.h> | ||||
| #include <sys/lock.h> | #include <sys/lock.h> | ||||
| #include <sys/module.h> | #include <sys/module.h> | ||||
| #include <sys/mutex.h> | #include <sys/mutex.h> | ||||
| #include <sys/sbuf.h> | #include <sys/sbuf.h> | ||||
| #include <sys/socket.h> | #include <sys/socket.h> | ||||
| #include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
| #include <sys/unistd.h> | #include <sys/unistd.h> | ||||
| #include <net/if.h> | #include <net/if.h> | ||||
| #include <net/if_var.h> | #include <net/if_var.h> | ||||
| #include <net/if_media.h> | #include <net/if_media.h> | ||||
| /* needed for checksum offload */ | /* needed for checksum offload */ | ||||
| #include <netinet/in.h> | #include <netinet/in.h> | ||||
| #include <netinet/ip.h> | #include <netinet/ip.h> | ||||
| #ifdef INET6 | |||||
| #include <netinet/ip6.h> | |||||
| #include <netinet6/ip6_var.h> | |||||
| #endif | |||||
| #include <dev/mii/mii.h> | #include <dev/mii/mii.h> | ||||
| #include <dev/mii/miivar.h> | #include <dev/mii/miivar.h> | ||||
| #include <dev/usb/usb.h> | #include <dev/usb/usb.h> | ||||
| #include <dev/usb/usbdi.h> | #include <dev/usb/usbdi.h> | ||||
| #include <dev/usb/usbdi_util.h> | #include <dev/usb/usbdi_util.h> | ||||
| #include "usbdevs.h" | #include "usbdevs.h" | ||||
| #define USB_DEBUG_VAR ure_debug | #define USB_DEBUG_VAR ure_debug | ||||
| #include <dev/usb/usb_debug.h> | #include <dev/usb/usb_debug.h> | ||||
| #include <dev/usb/usb_process.h> | #include <dev/usb/usb_process.h> | ||||
| #include <dev/usb/net/usb_ethernet.h> | #include <dev/usb/net/usb_ethernet.h> | ||||
| #include <dev/usb/net/if_urereg.h> | #include <dev/usb/net/if_urereg.h> | ||||
| #include "miibus_if.h" | #include "miibus_if.h" | ||||
| #include "opt_inet6.h" | |||||
| #ifdef USB_DEBUG | #ifdef USB_DEBUG | ||||
| static int ure_debug = 0; | static int ure_debug = 0; | ||||
| static SYSCTL_NODE(_hw_usb, OID_AUTO, ure, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, | static SYSCTL_NODE(_hw_usb, OID_AUTO, ure, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, | ||||
| "USB ure"); | "USB ure"); | ||||
| SYSCTL_INT(_hw_usb_ure, OID_AUTO, debug, CTLFLAG_RWTUN, &ure_debug, 0, | SYSCTL_INT(_hw_usb_ure, OID_AUTO, debug, CTLFLAG_RWTUN, &ure_debug, 0, | ||||
| "Debug level"); | "Debug level"); | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 2,099 Lines • ▼ Show 20 Lines | |||||
| * should be dropped. | * should be dropped. | ||||
| */ | */ | ||||
| static int | static int | ||||
| ure_txcsum(struct mbuf *m, int caps, uint32_t *regout) | ure_txcsum(struct mbuf *m, int caps, uint32_t *regout) | ||||
| { | { | ||||
| struct ip ip; | struct ip ip; | ||||
| struct ether_header *eh; | struct ether_header *eh; | ||||
| int flags; | int flags; | ||||
| uint32_t data; | |||||
| uint32_t reg; | uint32_t reg; | ||||
| int l3off, l4off; | int l3off, l4off; | ||||
| uint16_t type; | uint16_t type; | ||||
| *regout = 0; | *regout = 0; | ||||
| flags = m->m_pkthdr.csum_flags; | flags = m->m_pkthdr.csum_flags; | ||||
| if (flags == 0) | if (flags == 0) | ||||
| return (0); | return (0); | ||||
| Show All 18 Lines | default: | ||||
| return (0); | return (0); | ||||
| } | } | ||||
| reg = 0; | reg = 0; | ||||
| if (flags & CSUM_IP) | if (flags & CSUM_IP) | ||||
| reg |= URE_TXPKT_IPV4_CS; | reg |= URE_TXPKT_IPV4_CS; | ||||
| data = m->m_pkthdr.csum_data; | |||||
| if (flags & (CSUM_IP_TCP | CSUM_IP_UDP)) { | if (flags & (CSUM_IP_TCP | CSUM_IP_UDP)) { | ||||
| m_copydata(m, l3off, sizeof ip, (caddr_t)&ip); | m_copydata(m, l3off, sizeof ip, (caddr_t)&ip); | ||||
| l4off = l3off + (ip.ip_hl << 2) + data; | l4off = l3off + (ip.ip_hl << 2); | ||||
| if (__predict_false(l4off > URE_L4_OFFSET_MAX)) | if (__predict_false(l4off > URE_L4_OFFSET_MAX)) | ||||
| return (1); | return (1); | ||||
| reg |= URE_TXPKT_IPV4_CS; | reg |= URE_TXPKT_IPV4_CS; | ||||
| if (flags & CSUM_IP_TCP) | if (flags & CSUM_IP_TCP) | ||||
| reg |= URE_TXPKT_TCP_CS; | reg |= URE_TXPKT_TCP_CS; | ||||
| else if (flags & CSUM_IP_UDP) | else if (flags & CSUM_IP_UDP) | ||||
| reg |= URE_TXPKT_UDP_CS; | reg |= URE_TXPKT_UDP_CS; | ||||
| reg |= l4off << URE_L4_OFFSET_SHIFT; | reg |= l4off << URE_L4_OFFSET_SHIFT; | ||||
| } | } | ||||
| #ifdef INET6 | #ifdef INET6 | ||||
| else if (flags & (CSUM_IP6_TCP | CSUM_IP6_UDP)) { | else if (flags & (CSUM_IP6_TCP | CSUM_IP6_UDP)) { | ||||
| l4off = l3off + data; | l4off = ip6_lasthdr(m, l3off, IPPROTO_IPV6, NULL); | ||||
| if (__predict_false(l4off < 0)) | |||||
| return (1); | |||||
| if (__predict_false(l4off > URE_L4_OFFSET_MAX)) | if (__predict_false(l4off > URE_L4_OFFSET_MAX)) | ||||
| return (1); | return (1); | ||||
| reg |= URE_TXPKT_IPV6_CS; | reg |= URE_TXPKT_IPV6_CS; | ||||
| if (flags & CSUM_IP6_TCP) | if (flags & CSUM_IP6_TCP) | ||||
| reg |= URE_TXPKT_TCP_CS; | reg |= URE_TXPKT_TCP_CS; | ||||
| else if (flags & CSUM_IP6_UDP) | else if (flags & CSUM_IP6_UDP) | ||||
| reg |= URE_TXPKT_UDP_CS; | reg |= URE_TXPKT_UDP_CS; | ||||
| reg |= l4off << URE_L4_OFFSET_SHIFT; | reg |= l4off << URE_L4_OFFSET_SHIFT; | ||||
| } | } | ||||
| #endif | #endif | ||||
| *regout = reg; | *regout = reg; | ||||
| return 0; | return 0; | ||||
| } | } | ||||