Re: usb/181987: commit references a PR
The following reply was made to PR usb/181987; it has been noted by GNATS. From: dfil...@freebsd.org (dfilter service) To: bug-follo...@freebsd.org Cc: Subject: Re: usb/181987: commit references a PR Date: Thu, 24 Oct 2013 06:22:52 + (UTC) Author: hselasky Date: Thu Oct 24 06:22:43 2013 New Revision: 257041 URL: http://svnweb.freebsd.org/changeset/base/257041 Log: MFC r252912, r254828 and r256548: Add host mode support to the Mentor Graphics USB OTG controller driver. PR: usb/181987 Modified: stable/9/sys/dev/usb/controller/musb_otg.c stable/9/sys/dev/usb/controller/musb_otg.h stable/9/sys/dev/usb/controller/musb_otg_atmelarm.c Directory Properties: stable/9/sys/ (props changed) stable/9/sys/dev/ (props changed) Modified: stable/9/sys/dev/usb/controller/musb_otg.c == --- stable/9/sys/dev/usb/controller/musb_otg.c Thu Oct 24 06:06:17 2013 (r257040) +++ stable/9/sys/dev/usb/controller/musb_otg.c Thu Oct 24 06:22:43 2013 (r257041) @@ -90,6 +90,8 @@ SYSCTL_INT(_hw_usb_musbotg, OID_AUTO, de musbotgdebug, 0, Debug level); #endif +#define MAX_NAK_TO 16 + /* prototypes */ struct usb_bus_methods musbotg_bus_methods; @@ -98,17 +100,35 @@ struct usb_pipe_methods musbotg_device_c struct usb_pipe_methods musbotg_device_intr_methods; struct usb_pipe_methods musbotg_device_isoc_methods; -static musbotg_cmd_t musbotg_setup_rx; -static musbotg_cmd_t musbotg_setup_data_rx; -static musbotg_cmd_t musbotg_setup_data_tx; -static musbotg_cmd_t musbotg_setup_status; -static musbotg_cmd_t musbotg_data_rx; -static musbotg_cmd_t musbotg_data_tx; +/* Control transfers: Device mode */ +static musbotg_cmd_t musbotg_dev_ctrl_setup_rx; +static musbotg_cmd_t musbotg_dev_ctrl_data_rx; +static musbotg_cmd_t musbotg_dev_ctrl_data_tx; +static musbotg_cmd_t musbotg_dev_ctrl_status; + +/* Control transfers: Host mode */ +static musbotg_cmd_t musbotg_host_ctrl_setup_tx; +static musbotg_cmd_t musbotg_host_ctrl_data_rx; +static musbotg_cmd_t musbotg_host_ctrl_data_tx; +static musbotg_cmd_t musbotg_host_ctrl_status_rx; +static musbotg_cmd_t musbotg_host_ctrl_status_tx; + +/* Bulk, Interrupt, Isochronous: Device mode */ +static musbotg_cmd_t musbotg_dev_data_rx; +static musbotg_cmd_t musbotg_dev_data_tx; + +/* Bulk, Interrupt, Isochronous: Host mode */ +static musbotg_cmd_t musbotg_host_data_rx; +static musbotg_cmd_t musbotg_host_data_tx; + static void musbotg_device_done(struct usb_xfer *, usb_error_t); static void musbotg_do_poll(struct usb_bus *); static void musbotg_standard_done(struct usb_xfer *); static void musbotg_interrupt_poll(struct musbotg_softc *); static void musbotg_root_intr(struct musbotg_softc *); +static intmusbotg_channel_alloc(struct musbotg_softc *, struct musbotg_td *td); +static void musbotg_channel_free(struct musbotg_softc *, struct musbotg_td *td); +static void musbotg_ep_int_set(struct musbotg_softc *sc, int channel, int on); /* * Here is a configuration that the chip supports. @@ -123,6 +143,64 @@ static const struct usb_hw_ep_profile mu } }; +static int +musbotg_channel_alloc(struct musbotg_softc *sc, struct musbotg_td *td) +{ + int ch; + int ep; + + ep = td-ep_no; + + /* In device mode each EP got its own channel */ + if (sc-sc_mode == MUSB2_DEVICE_MODE) { + musbotg_ep_int_set(sc, ep, 1); + return (ep); + } + + /* + * All control transactions go through EP0 + */ + if (ep == 0) { + if (sc-sc_channel_mask (1 0)) + return (-1); + sc-sc_channel_mask |= (1 0); + musbotg_ep_int_set(sc, ep, 1); + return (0); + } + + for (ch = 1; ch MUSB2_EP_MAX; ch++) { + if (!(sc-sc_channel_mask (1 ch))) { + sc-sc_channel_mask |= (1 ch); + musbotg_ep_int_set(sc, ch, 1); + return (ch); + } + } + + DPRINTFN(-1, No available channels. Mask: %04x\n, sc-sc_channel_mask); + + return (-1); +} + +static void +musbotg_channel_free(struct musbotg_softc *sc, struct musbotg_td *td) +{ + + DPRINTFN(1, ep_no=%d\n, td-channel); + + if (sc-sc_mode == MUSB2_DEVICE_MODE) + return; + + if (td == NULL) + return; + if (td-channel == -1) + return; + + musbotg_ep_int_set(sc, td-channel, 0); + sc-sc_channel_mask = ~(1 td-channel); + + td-channel = -1; +} + static void musbotg_get_hw_ep_profile(struct usb_device *udev, const struct usb_hw_ep_profile **ppf, uint8_t ep_addr) @@ -213,6 +291,46 @@ musbotg_pull_down(struct musbotg_softc * } static void
Re: usb/181987: commit references a PR
The following reply was made to PR usb/181987; it has been noted by GNATS. From: dfil...@freebsd.org (dfilter service) To: bug-follo...@freebsd.org Cc: Subject: Re: usb/181987: commit references a PR Date: Thu, 24 Oct 2013 07:38:40 + (UTC) Author: hselasky Date: Thu Oct 24 07:38:32 2013 New Revision: 257043 URL: http://svnweb.freebsd.org/changeset/base/257043 Log: MFC r256548: Correct programming of XXX_MAXP register. This register is 16-bit wide and not 8-bit. Fix support for isochronous transfers in USB host mode. Fix a whitespace while at it. PR: usb/181987 Approved by: re (Xin Li) Modified: stable/10/sys/dev/usb/controller/musb_otg.c stable/10/sys/dev/usb/controller/musb_otg.h Directory Properties: stable/10/sys/ (props changed) Modified: stable/10/sys/dev/usb/controller/musb_otg.c == --- stable/10/sys/dev/usb/controller/musb_otg.cThu Oct 24 06:25:52 2013(r257042) +++ stable/10/sys/dev/usb/controller/musb_otg.cThu Oct 24 07:38:32 2013(r257043) @@ -1661,7 +1661,7 @@ repeat: } /* Max packet size */ - MUSB2_WRITE_1(sc, MUSB2_REG_TXMAXP, td-max_packet); + MUSB2_WRITE_2(sc, MUSB2_REG_TXMAXP, td-reg_max_packet); /* write command */ MUSB2_WRITE_1(sc, MUSB2_REG_TXCSRL, @@ -1726,13 +1726,16 @@ repeat: td-hport); /* RX NAK timeout */ - MUSB2_WRITE_1(sc, MUSB2_REG_RXNAKLIMIT, MAX_NAK_TO); + if (td-transfer_type MUSB2_MASK_TI_PROTO_ISOC) + MUSB2_WRITE_1(sc, MUSB2_REG_RXNAKLIMIT, 0); + else + MUSB2_WRITE_1(sc, MUSB2_REG_RXNAKLIMIT, MAX_NAK_TO); /* Protocol, speed, device endpoint */ MUSB2_WRITE_1(sc, MUSB2_REG_RXTI, td-transfer_type); /* Max packet size */ - MUSB2_WRITE_1(sc, MUSB2_REG_RXMAXP, td-max_packet); + MUSB2_WRITE_2(sc, MUSB2_REG_RXMAXP, td-reg_max_packet); /* Data Toggle */ csrh = MUSB2_READ_1(sc, MUSB2_REG_RXCSRH); @@ -1938,7 +1941,7 @@ musbotg_host_data_tx(struct musbotg_td * return (0); /* complete */ } - if (csr MUSB2_MASK_CSRL_TXNAKTO ) { + if (csr MUSB2_MASK_CSRL_TXNAKTO) { /* * Flush TX FIFO before clearing NAK TO */ @@ -2069,13 +2072,16 @@ musbotg_host_data_tx(struct musbotg_td * td-hport); /* TX NAK timeout */ - MUSB2_WRITE_1(sc, MUSB2_REG_TXNAKLIMIT, MAX_NAK_TO); + if (td-transfer_type MUSB2_MASK_TI_PROTO_ISOC) + MUSB2_WRITE_1(sc, MUSB2_REG_TXNAKLIMIT, 0); + else + MUSB2_WRITE_1(sc, MUSB2_REG_TXNAKLIMIT, MAX_NAK_TO); /* Protocol, speed, device endpoint */ MUSB2_WRITE_1(sc, MUSB2_REG_TXTI, td-transfer_type); /* Max packet size */ - MUSB2_WRITE_1(sc, MUSB2_REG_TXMAXP, td-max_packet); + MUSB2_WRITE_2(sc, MUSB2_REG_TXMAXP, td-reg_max_packet); if (!td-transaction_started) { csrh = MUSB2_READ_1(sc, MUSB2_REG_TXCSRH); @@ -2406,7 +2412,6 @@ musbotg_setup_standard_chain(struct usb_ if (xfer-flags_int.usb_mode == USB_MODE_HOST) { speed = usbd_get_speed(xfer-xroot-udev); - xfer_type = xfer-endpoint-edesc-bmAttributes UE_XFERTYPE; switch (speed) { case USB_SPEED_LOW: @@ -2444,7 +2449,6 @@ musbotg_setup_standard_chain(struct usb_ } temp.transfer_type |= ep_no; - td-max_packet = xfer-max_packet_size; td-toggle = xfer-endpoint-toggle_next; } @@ -2469,9 +2473,9 @@ musbotg_setup_standard_chain(struct usb_ x = 0; } - if (x != xfer-nframes) { - tx = 0; + tx = 0; + if (x != xfer-nframes) { if (xfer-endpointno UE_DIR_IN) tx = 1; @@ -2532,9 +2536,14 @@ musbotg_setup_standard_chain(struct usb_ } else { - /* regular data transfer */ - - temp.short_pkt = (xfer-flags.force_short_xfer) ? 0 : 1; + if (xfer-flags_int.isochronous_xfr) { + /* isochronous data transfer */ + /* don't force short */ + temp.short_pkt = 1; + } else { + /* regular data transfer */ + temp.short_pkt = (xfer-flags.force_short_xfer ? 0 : 1); + } } musbotg_setup_standard_chain_sub(temp); @@ -3158,7 +3167,12 @@ musbotg_init(struct musbotg_softc *sc
Re: usb/181987: commit references a PR
The following reply was made to PR usb/181987; it has been noted by GNATS. From: dfil...@freebsd.org (dfilter service) To: bug-follo...@freebsd.org Cc: Subject: Re: usb/181987: commit references a PR Date: Tue, 15 Oct 2013 17:11:22 + (UTC) Author: hselasky Date: Tue Oct 15 17:11:13 2013 New Revision: 256548 URL: http://svnweb.freebsd.org/changeset/base/256548 Log: Correct programming of XXX_MAXP register. This register is 16-bit wide and not 8-bit. Fix support for isochronous transfers in USB host mode. Fix a whitespace while at it. MFC after: 1 week Reported by: SAITOU Toshihide to...@ruby.ocn.ne.jp PR: usb/181987 Modified: head/sys/dev/usb/controller/musb_otg.c head/sys/dev/usb/controller/musb_otg.h Modified: head/sys/dev/usb/controller/musb_otg.c == --- head/sys/dev/usb/controller/musb_otg.c Tue Oct 15 17:03:02 2013 (r256547) +++ head/sys/dev/usb/controller/musb_otg.c Tue Oct 15 17:11:13 2013 (r256548) @@ -1661,7 +1661,7 @@ repeat: } /* Max packet size */ - MUSB2_WRITE_1(sc, MUSB2_REG_TXMAXP, td-max_packet); + MUSB2_WRITE_2(sc, MUSB2_REG_TXMAXP, td-reg_max_packet); /* write command */ MUSB2_WRITE_1(sc, MUSB2_REG_TXCSRL, @@ -1726,13 +1726,16 @@ repeat: td-hport); /* RX NAK timeout */ - MUSB2_WRITE_1(sc, MUSB2_REG_RXNAKLIMIT, MAX_NAK_TO); + if (td-transfer_type MUSB2_MASK_TI_PROTO_ISOC) + MUSB2_WRITE_1(sc, MUSB2_REG_RXNAKLIMIT, 0); + else + MUSB2_WRITE_1(sc, MUSB2_REG_RXNAKLIMIT, MAX_NAK_TO); /* Protocol, speed, device endpoint */ MUSB2_WRITE_1(sc, MUSB2_REG_RXTI, td-transfer_type); /* Max packet size */ - MUSB2_WRITE_1(sc, MUSB2_REG_RXMAXP, td-max_packet); + MUSB2_WRITE_2(sc, MUSB2_REG_RXMAXP, td-reg_max_packet); /* Data Toggle */ csrh = MUSB2_READ_1(sc, MUSB2_REG_RXCSRH); @@ -1938,7 +1941,7 @@ musbotg_host_data_tx(struct musbotg_td * return (0); /* complete */ } - if (csr MUSB2_MASK_CSRL_TXNAKTO ) { + if (csr MUSB2_MASK_CSRL_TXNAKTO) { /* * Flush TX FIFO before clearing NAK TO */ @@ -2069,13 +2072,16 @@ musbotg_host_data_tx(struct musbotg_td * td-hport); /* TX NAK timeout */ - MUSB2_WRITE_1(sc, MUSB2_REG_TXNAKLIMIT, MAX_NAK_TO); + if (td-transfer_type MUSB2_MASK_TI_PROTO_ISOC) + MUSB2_WRITE_1(sc, MUSB2_REG_TXNAKLIMIT, 0); + else + MUSB2_WRITE_1(sc, MUSB2_REG_TXNAKLIMIT, MAX_NAK_TO); /* Protocol, speed, device endpoint */ MUSB2_WRITE_1(sc, MUSB2_REG_TXTI, td-transfer_type); /* Max packet size */ - MUSB2_WRITE_1(sc, MUSB2_REG_TXMAXP, td-max_packet); + MUSB2_WRITE_2(sc, MUSB2_REG_TXMAXP, td-reg_max_packet); if (!td-transaction_started) { csrh = MUSB2_READ_1(sc, MUSB2_REG_TXCSRH); @@ -2406,7 +2412,6 @@ musbotg_setup_standard_chain(struct usb_ if (xfer-flags_int.usb_mode == USB_MODE_HOST) { speed = usbd_get_speed(xfer-xroot-udev); - xfer_type = xfer-endpoint-edesc-bmAttributes UE_XFERTYPE; switch (speed) { case USB_SPEED_LOW: @@ -2444,7 +2449,6 @@ musbotg_setup_standard_chain(struct usb_ } temp.transfer_type |= ep_no; - td-max_packet = xfer-max_packet_size; td-toggle = xfer-endpoint-toggle_next; } @@ -2469,9 +2473,9 @@ musbotg_setup_standard_chain(struct usb_ x = 0; } - if (x != xfer-nframes) { - tx = 0; + tx = 0; + if (x != xfer-nframes) { if (xfer-endpointno UE_DIR_IN) tx = 1; @@ -2532,9 +2536,14 @@ musbotg_setup_standard_chain(struct usb_ } else { - /* regular data transfer */ - - temp.short_pkt = (xfer-flags.force_short_xfer) ? 0 : 1; + if (xfer-flags_int.isochronous_xfr) { + /* isochronous data transfer */ + /* don't force short */ + temp.short_pkt = 1; + } else { + /* regular data transfer */ + temp.short_pkt = (xfer-flags.force_short_xfer ? 0 : 1); + } } musbotg_setup_standard_chain_sub(temp); @@ -3158,7 +3167,12 @@ musbotg_init(struct musbotg_softc *sc) if (dynfifo) { if (frx (temp = nrx