* [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
@ 2011-08-02 16:20 Alexey Orishko
[not found] ` <1312302026-7077-1-git-send-email-alexey.orishko-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Alexey Orishko @ 2011-08-02 16:20 UTC (permalink / raw)
To: netdev-u79uwXL29TY76Z2rM5mHXA, davem-fT/PcQaiUtIeIZ0/mPfg9Q,
oliver-GvhC2dPhHPQdnm+yROfE0A
Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA, gregkh-l3A5Bk7waGM, Alexey Orishko
Changes:
- removed redandunt conversion for usb control requests
- added missing conversion for nth16.wNdpIndex
Thanks to Giuseppe Scrivano for providing fixes
This patch shall be applied on top of today's Josh Boyle patch
[PATCH v3] usbnet/cdc_ncm: Don't use stack variables for DMA
Signed-off-by: Alexey Orishko <alexey.orishko-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>
---
drivers/net/usb/cdc_ncm.c | 33 ++++++++++++++++-----------------
1 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index bbcb133..4b2a317 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -53,7 +53,7 @@
#include <linux/usb/usbnet.h>
#include <linux/usb/cdc.h>
-#define DRIVER_VERSION "01-June-2011"
+#define DRIVER_VERSION "02-Aug-2011"
/* CDC NCM subclass 3.2.1 */
#define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10
@@ -203,8 +203,8 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
req.bmRequestType = USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE;
req.bNotificationType = USB_CDC_GET_NTB_PARAMETERS;
req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = cpu_to_le16(sizeof(ctx->ncm_parm));
+ req.wIndex = iface_no;
+ req.wLength = sizeof(ctx->ncm_parm);
err = cdc_ncm_do_request(ctx, &req, &ctx->ncm_parm, 0, NULL, 1000);
if (err) {
@@ -257,7 +257,7 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
USB_RECIP_INTERFACE;
req.bNotificationType = USB_CDC_SET_NTB_INPUT_SIZE;
req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
+ req.wIndex = iface_no;
if (flags & USB_CDC_NCM_NCAP_NTB_INPUT_SIZE) {
struct usb_cdc_ncm_ndp_input_size *ndp_in_sz;
@@ -351,8 +351,8 @@ size_err:
req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
USB_RECIP_INTERFACE;
req.bNotificationType = USB_CDC_SET_CRC_MODE;
- req.wValue = cpu_to_le16(USB_CDC_NCM_CRC_NOT_APPENDED);
- req.wIndex = cpu_to_le16(iface_no);
+ req.wValue = USB_CDC_NCM_CRC_NOT_APPENDED;
+ req.wIndex = iface_no;
req.wLength = 0;
err = cdc_ncm_do_request(ctx, &req, NULL, 0, NULL, 1000);
@@ -365,8 +365,8 @@ size_err:
req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
USB_RECIP_INTERFACE;
req.bNotificationType = USB_CDC_SET_NTB_FORMAT;
- req.wValue = cpu_to_le16(USB_CDC_NCM_NTB16_FORMAT);
- req.wIndex = cpu_to_le16(iface_no);
+ req.wValue = USB_CDC_NCM_NTB16_FORMAT;
+ req.wIndex = iface_no;
req.wLength = 0;
err = cdc_ncm_do_request(ctx, &req, NULL, 0, NULL, 1000);
@@ -392,8 +392,8 @@ size_err:
USB_RECIP_INTERFACE;
req.bNotificationType = USB_CDC_GET_MAX_DATAGRAM_SIZE;
req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = cpu_to_le16(2);
+ req.wIndex = iface_no;
+ req.wLength = 2;
err = cdc_ncm_do_request(ctx, &req, max_datagram_size, 0, NULL,
1000);
@@ -426,7 +426,7 @@ size_err:
USB_RECIP_INTERFACE;
req.bNotificationType = USB_CDC_SET_MAX_DATAGRAM_SIZE;
req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
+ req.wIndex = iface_no;
req.wLength = 2;
*max_datagram_size =
cpu_to_le16(ctx->max_datagram_size);
@@ -702,6 +702,7 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
u32 offset;
u32 last_offset;
u16 n = 0;
+ u16 ndpIndex = 0;
u8 ready2send = 0;
/* if there is a remaining skb, it gets priority */
@@ -889,8 +890,8 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
cpu_to_le16(sizeof(ctx->tx_ncm.nth16));
ctx->tx_ncm.nth16.wSequence = cpu_to_le16(ctx->tx_seq);
ctx->tx_ncm.nth16.wBlockLength = cpu_to_le16(last_offset);
- ctx->tx_ncm.nth16.wNdpIndex = ALIGN(sizeof(struct usb_cdc_ncm_nth16),
- ctx->tx_ndp_modulus);
+ ndpIndex = ALIGN(sizeof(struct usb_cdc_ncm_nth16), ctx->tx_ndp_modulus);
+ ctx->tx_ncm.nth16.wNdpIndex = cpu_to_le16(ndpIndex);
memcpy(skb_out->data, &(ctx->tx_ncm.nth16), sizeof(ctx->tx_ncm.nth16));
ctx->tx_seq++;
@@ -903,12 +904,10 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
ctx->tx_ncm.ndp16.wLength = cpu_to_le16(rem);
ctx->tx_ncm.ndp16.wNextNdpIndex = 0; /* reserved */
- memcpy(((u8 *)skb_out->data) + ctx->tx_ncm.nth16.wNdpIndex,
- &(ctx->tx_ncm.ndp16),
+ memcpy(((u8 *)skb_out->data) + ndpIndex, &(ctx->tx_ncm.ndp16),
sizeof(ctx->tx_ncm.ndp16));
- memcpy(((u8 *)skb_out->data) + ctx->tx_ncm.nth16.wNdpIndex +
- sizeof(ctx->tx_ncm.ndp16),
+ memcpy(((u8 *)skb_out->data) + ndpIndex + sizeof(ctx->tx_ncm.ndp16),
&(ctx->tx_ncm.dpe16),
(ctx->tx_curr_frame_num + 1) *
sizeof(struct usb_cdc_ncm_dpe16));
--
1.7.4.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
[not found] ` <1312302026-7077-1-git-send-email-alexey.orishko-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>
@ 2011-08-02 18:30 ` Oliver Neukum
2011-08-02 19:45 ` Alan Stern
2011-08-03 10:42 ` David Miller
1 sibling, 1 reply; 11+ messages in thread
From: Oliver Neukum @ 2011-08-02 18:30 UTC (permalink / raw)
To: Alexey Orishko
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, davem-fT/PcQaiUtIeIZ0/mPfg9Q,
linux-usb-u79uwXL29TY76Z2rM5mHXA, gregkh-l3A5Bk7waGM,
Alexey Orishko
Am Dienstag, 2. August 2011, 18:20:26 schrieb Alexey Orishko:
> Changes:
> - removed redandunt conversion for usb control requests
> - added missing conversion for nth16.wNdpIndex
> Thanks to Giuseppe Scrivano for providing fixes
What? How can a conversion of endianness be redundant?
Either this version or the old version must be buggy. What is
happening here?
Regards
Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
2011-08-02 18:30 ` Oliver Neukum
@ 2011-08-02 19:45 ` Alan Stern
0 siblings, 0 replies; 11+ messages in thread
From: Alan Stern @ 2011-08-02 19:45 UTC (permalink / raw)
To: Oliver Neukum
Cc: Alexey Orishko, netdev, davem, linux-usb, gregkh, Alexey Orishko
On Tue, 2 Aug 2011, Oliver Neukum wrote:
> Am Dienstag, 2. August 2011, 18:20:26 schrieb Alexey Orishko:
> > Changes:
> > - removed redandunt conversion for usb control requests
> > - added missing conversion for nth16.wNdpIndex
> > Thanks to Giuseppe Scrivano for providing fixes
>
> What? How can a conversion of endianness be redundant?
When it's done twice. :-)
> Either this version or the old version must be buggy. What is
> happening here?
The old version is buggy. Read the code and you'll see.
Alan Stern
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
[not found] ` <1312302026-7077-1-git-send-email-alexey.orishko-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>
2011-08-02 18:30 ` Oliver Neukum
@ 2011-08-03 10:42 ` David Miller
[not found] ` <20110803.034253.417905916118311130.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
1 sibling, 1 reply; 11+ messages in thread
From: David Miller @ 2011-08-03 10:42 UTC (permalink / raw)
To: alexey.orishko-Re5JQEeQqe8AvxtiuMwx3w
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, oliver-GvhC2dPhHPQdnm+yROfE0A,
linux-usb-u79uwXL29TY76Z2rM5mHXA, gregkh-l3A5Bk7waGM,
alexey.orishko-0IS4wlFg1OjSUeElwK9/Pw
From: Alexey Orishko <alexey.orishko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Tue, 2 Aug 2011 18:20:26 +0200
> @@ -203,8 +203,8 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
> req.bmRequestType = USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE;
> req.bNotificationType = USB_CDC_GET_NTB_PARAMETERS;
> req.wValue = 0;
> - req.wIndex = cpu_to_le16(iface_no);
> - req.wLength = cpu_to_le16(sizeof(ctx->ncm_parm));
> + req.wIndex = iface_no;
> + req.wLength = sizeof(ctx->ncm_parm);
>
> err = cdc_ncm_do_request(ctx, &req, &ctx->ncm_parm, 0, NULL, 1000);
> if (err) {
This can't be correct.
"iface_no" is a u8 we read out of desc->bInterfaceNumber
we still have to extend it to a u16 and convert it to a little endian
16-bit value for the req.wIndex field.
If the types for the cdc notification struct are wrong, that's another
story entirely. But currently they are marked as __le16 so you must
resolve this first.
Otherwise your changes will result in several new sparse endian
warnings.
I'm not applying this, even if it is correct functionally.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
[not found] ` <20110803.034253.417905916118311130.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
@ 2011-08-03 11:13 ` Alexey ORISHKO
0 siblings, 0 replies; 11+ messages in thread
From: Alexey ORISHKO @ 2011-08-03 11:13 UTC (permalink / raw)
To: David Miller
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, oliver-GvhC2dPhHPQdnm+yROfE0A,
linux-usb-u79uwXL29TY76Z2rM5mHXA, gregkh-l3A5Bk7waGM,
alexey.orishko-Re5JQEeQqe8AvxtiuMwx3w
> -----Original Message-----
> From: David Miller [mailto:davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org]
> Sent: Wednesday, August 03, 2011 12:43 PM
> To: alexey.orishko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
> Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org; linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org;
> gregkh-l3A5Bk7waGM@public.gmane.org; Alexey ORISHKO
> Subject: Re: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
>
> From: Alexey Orishko <alexey.orishko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Date: Tue, 2 Aug 2011 18:20:26 +0200
>
> > @@ -203,8 +203,8 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
> > req.bmRequestType = USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE;
> > req.bNotificationType = USB_CDC_GET_NTB_PARAMETERS;
> > req.wValue = 0;
> > - req.wIndex = cpu_to_le16(iface_no);
> > - req.wLength = cpu_to_le16(sizeof(ctx->ncm_parm));
> > + req.wIndex = iface_no;
> > + req.wLength = sizeof(ctx->ncm_parm);
> >
> > err = cdc_ncm_do_request(ctx, &req, &ctx->ncm_parm, 0, NULL, 1000);
> > if (err) {
>
> This can't be correct.
>
> "iface_no" is a u8 we read out of desc->bInterfaceNumber
>
> we still have to extend it to a u16 and convert it to a little endian
> 16-bit value for the req.wIndex field.
>
> If the types for the cdc notification struct are wrong, that's another
> story entirely. But currently they are marked as __le16 so you must
> resolve this first.
Ok. I see where confusion started...
cdc_ncm is incorrectly using struct usb_cdc_notification (__le16) as input
to usb_control_msg() function, which is expecting u16 data type arguments.
I will post an updated patch shortly.
alexey
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
2011-08-04 8:10 ` Giuseppe Scrivano
@ 2011-08-04 8:43 ` David Miller
0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2011-08-04 8:43 UTC (permalink / raw)
To: giuseppe
Cc: alexey.orishko, netdev, oliver, linux-usb, gregkh, alexey.orishko
From: Giuseppe Scrivano <giuseppe@southpole.se>
Date: Thu, 04 Aug 2011 10:10:29 +0200
> cdc_ncm: fix endianness problem.
>
> Fix a misusage of the struct usb_cdc_notification to pass arguments to the
> usb_control_msg function. The usb_control_msg function expects host endian
> arguments but usb_cdc_notification stores these values as little endian.
>
> Now usb_control_msg is directly invoked with host endian values.
Applied.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
[not found] ` <20110803.191141.888495095889424492.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
@ 2011-08-04 8:10 ` Giuseppe Scrivano
2011-08-04 8:43 ` David Miller
0 siblings, 1 reply; 11+ messages in thread
From: Giuseppe Scrivano @ 2011-08-04 8:10 UTC (permalink / raw)
To: David Miller
Cc: alexey.orishko-0IS4wlFg1OjSUeElwK9/Pw,
netdev-u79uwXL29TY76Z2rM5mHXA, oliver-GvhC2dPhHPQdnm+yROfE0A,
linux-usb-u79uwXL29TY76Z2rM5mHXA, gregkh-l3A5Bk7waGM,
alexey.orishko-Re5JQEeQqe8AvxtiuMwx3w
Hello David,
David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org> writes:
> The patch looks great, but please repost this fresh with a more
> vebose commit log message explaining all the things we discussed
> to get the change to it's current form.
thanks for your review! I hope I was enough verbose this time :-)
Regards,
Giuseppe
>From 2ad27dac918eea4d39f3cc10796f4f08ead7210b Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <giuseppe-A9uVI2HLR7kOP4wsBPIw7w@public.gmane.org>
Date: Fri, 15 Jul 2011 15:34:14 +0200
Subject: [PATCH] cdc_ncm: fix endianness problem.
Fix a misusage of the struct usb_cdc_notification to pass arguments to the
usb_control_msg function. The usb_control_msg function expects host endian
arguments but usb_cdc_notification stores these values as little endian.
Now usb_control_msg is directly invoked with host endian values.
Signed-off-by: Giuseppe Scrivano <giuseppe-A9uVI2HLR7kOP4wsBPIw7w@public.gmane.org>
---
drivers/net/usb/cdc_ncm.c | 156 ++++++++++++++++-----------------------------
1 files changed, 56 insertions(+), 100 deletions(-)
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index f33ca6a..d3b9e95 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -54,7 +54,7 @@
#include <linux/usb/usbnet.h>
#include <linux/usb/cdc.h>
-#define DRIVER_VERSION "01-June-2011"
+#define DRIVER_VERSION "04-Aug-2011"
/* CDC NCM subclass 3.2.1 */
#define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10
@@ -164,35 +164,8 @@ cdc_ncm_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info));
}
-static int
-cdc_ncm_do_request(struct cdc_ncm_ctx *ctx, struct usb_cdc_notification *req,
- void *data, u16 flags, u16 *actlen, u16 timeout)
-{
- int err;
-
- err = usb_control_msg(ctx->udev, (req->bmRequestType & USB_DIR_IN) ?
- usb_rcvctrlpipe(ctx->udev, 0) :
- usb_sndctrlpipe(ctx->udev, 0),
- req->bNotificationType, req->bmRequestType,
- req->wValue,
- req->wIndex, data,
- req->wLength, timeout);
-
- if (err < 0) {
- if (actlen)
- *actlen = 0;
- return err;
- }
-
- if (actlen)
- *actlen = err;
-
- return 0;
-}
-
static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
{
- struct usb_cdc_notification req;
u32 val;
u8 flags;
u8 iface_no;
@@ -201,14 +174,14 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber;
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_GET_NTB_PARAMETERS;
- req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = cpu_to_le16(sizeof(ctx->ncm_parm));
-
- err = cdc_ncm_do_request(ctx, &req, &ctx->ncm_parm, 0, NULL, 1000);
- if (err) {
+ err = usb_control_msg(ctx->udev,
+ usb_rcvctrlpipe(ctx->udev, 0),
+ USB_CDC_GET_NTB_PARAMETERS,
+ USB_TYPE_CLASS | USB_DIR_IN
+ | USB_RECIP_INTERFACE,
+ 0, iface_no, &ctx->ncm_parm,
+ sizeof(ctx->ncm_parm), 10000);
+ if (err < 0) {
pr_debug("failed GET_NTB_PARAMETERS\n");
return 1;
}
@@ -254,31 +227,26 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
/* inform device about NTB input size changes */
if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) {
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
- USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_NTB_INPUT_SIZE;
- req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
if (flags & USB_CDC_NCM_NCAP_NTB_INPUT_SIZE) {
struct usb_cdc_ncm_ndp_input_size ndp_in_sz;
-
- req.wLength = 8;
- ndp_in_sz.dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
- ndp_in_sz.wNtbInMaxDatagrams =
- cpu_to_le16(CDC_NCM_DPT_DATAGRAMS_MAX);
- ndp_in_sz.wReserved = 0;
- err = cdc_ncm_do_request(ctx, &req, &ndp_in_sz, 0, NULL,
- 1000);
+ err = usb_control_msg(ctx->udev,
+ usb_sndctrlpipe(ctx->udev, 0),
+ USB_CDC_SET_NTB_INPUT_SIZE,
+ USB_TYPE_CLASS | USB_DIR_OUT
+ | USB_RECIP_INTERFACE,
+ 0, iface_no, &ndp_in_sz, 8, 1000);
} else {
__le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
-
- req.wLength = 4;
- err = cdc_ncm_do_request(ctx, &req, &dwNtbInMaxSize, 0,
- NULL, 1000);
+ err = usb_control_msg(ctx->udev,
+ usb_sndctrlpipe(ctx->udev, 0),
+ USB_CDC_SET_NTB_INPUT_SIZE,
+ USB_TYPE_CLASS | USB_DIR_OUT
+ | USB_RECIP_INTERFACE,
+ 0, iface_no, &dwNtbInMaxSize, 4, 1000);
}
- if (err)
+ if (err < 0)
pr_debug("Setting NTB Input Size failed\n");
}
@@ -333,29 +301,24 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
/* set CRC Mode */
if (flags & USB_CDC_NCM_NCAP_CRC_MODE) {
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
- USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_CRC_MODE;
- req.wValue = cpu_to_le16(USB_CDC_NCM_CRC_NOT_APPENDED);
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = 0;
-
- err = cdc_ncm_do_request(ctx, &req, NULL, 0, NULL, 1000);
- if (err)
+ err = usb_control_msg(ctx->udev, usb_sndctrlpipe(ctx->udev, 0),
+ USB_CDC_SET_CRC_MODE,
+ USB_TYPE_CLASS | USB_DIR_OUT
+ | USB_RECIP_INTERFACE,
+ USB_CDC_NCM_CRC_NOT_APPENDED,
+ iface_no, NULL, 0, 1000);
+ if (err < 0)
pr_debug("Setting CRC mode off failed\n");
}
/* set NTB format, if both formats are supported */
if (ntb_fmt_supported & USB_CDC_NCM_NTH32_SIGN) {
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
- USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_NTB_FORMAT;
- req.wValue = cpu_to_le16(USB_CDC_NCM_NTB16_FORMAT);
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = 0;
-
- err = cdc_ncm_do_request(ctx, &req, NULL, 0, NULL, 1000);
- if (err)
+ err = usb_control_msg(ctx->udev, usb_sndctrlpipe(ctx->udev, 0),
+ USB_CDC_SET_NTB_FORMAT, USB_TYPE_CLASS
+ | USB_DIR_OUT | USB_RECIP_INTERFACE,
+ USB_CDC_NCM_NTB16_FORMAT,
+ iface_no, NULL, 0, 1000);
+ if (err < 0)
pr_debug("Setting NTB format to 16-bit failed\n");
}
@@ -365,17 +328,13 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
if (flags & USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE) {
__le16 max_datagram_size;
u16 eth_max_sz = le16_to_cpu(ctx->ether_desc->wMaxSegmentSize);
-
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_IN |
- USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_GET_MAX_DATAGRAM_SIZE;
- req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = cpu_to_le16(2);
-
- err = cdc_ncm_do_request(ctx, &req, &max_datagram_size, 0, NULL,
- 1000);
- if (err) {
+ err = usb_control_msg(ctx->udev, usb_rcvctrlpipe(ctx->udev, 0),
+ USB_CDC_GET_MAX_DATAGRAM_SIZE,
+ USB_TYPE_CLASS | USB_DIR_IN
+ | USB_RECIP_INTERFACE,
+ 0, iface_no, &max_datagram_size,
+ 2, 1000);
+ if (err < 0) {
pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n",
CDC_NCM_MIN_DATAGRAM_SIZE);
} else {
@@ -396,17 +355,15 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
CDC_NCM_MIN_DATAGRAM_SIZE;
/* if value changed, update device */
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
- USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_MAX_DATAGRAM_SIZE;
- req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = 2;
- max_datagram_size = cpu_to_le16(ctx->max_datagram_size);
-
- err = cdc_ncm_do_request(ctx, &req, &max_datagram_size,
- 0, NULL, 1000);
- if (err)
+ err = usb_control_msg(ctx->udev,
+ usb_sndctrlpipe(ctx->udev, 0),
+ USB_CDC_SET_MAX_DATAGRAM_SIZE,
+ USB_TYPE_CLASS | USB_DIR_OUT
+ | USB_RECIP_INTERFACE,
+ 0,
+ iface_no, &max_datagram_size,
+ 2, 1000);
+ if (err < 0)
pr_debug("SET_MAX_DATAGRAM_SIZE failed\n");
}
@@ -672,7 +629,7 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
u32 rem;
u32 offset;
u32 last_offset;
- u16 n = 0;
+ u16 n = 0, index;
u8 ready2send = 0;
/* if there is a remaining skb, it gets priority */
@@ -860,8 +817,8 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
cpu_to_le16(sizeof(ctx->tx_ncm.nth16));
ctx->tx_ncm.nth16.wSequence = cpu_to_le16(ctx->tx_seq);
ctx->tx_ncm.nth16.wBlockLength = cpu_to_le16(last_offset);
- ctx->tx_ncm.nth16.wNdpIndex = ALIGN(sizeof(struct usb_cdc_ncm_nth16),
- ctx->tx_ndp_modulus);
+ index = ALIGN(sizeof(struct usb_cdc_ncm_nth16), ctx->tx_ndp_modulus);
+ ctx->tx_ncm.nth16.wNdpIndex = cpu_to_le16(index);
memcpy(skb_out->data, &(ctx->tx_ncm.nth16), sizeof(ctx->tx_ncm.nth16));
ctx->tx_seq++;
@@ -874,12 +831,11 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
ctx->tx_ncm.ndp16.wLength = cpu_to_le16(rem);
ctx->tx_ncm.ndp16.wNextNdpIndex = 0; /* reserved */
- memcpy(((u8 *)skb_out->data) + ctx->tx_ncm.nth16.wNdpIndex,
+ memcpy(((u8 *)skb_out->data) + index,
&(ctx->tx_ncm.ndp16),
sizeof(ctx->tx_ncm.ndp16));
- memcpy(((u8 *)skb_out->data) + ctx->tx_ncm.nth16.wNdpIndex +
- sizeof(ctx->tx_ncm.ndp16),
+ memcpy(((u8 *)skb_out->data) + index + sizeof(ctx->tx_ncm.ndp16),
&(ctx->tx_ncm.dpe16),
(ctx->tx_curr_frame_num + 1) *
sizeof(struct usb_cdc_ncm_dpe16));
--
1.7.5.4
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
2011-08-03 15:46 ` Giuseppe Scrivano
@ 2011-08-04 2:11 ` David Miller
[not found] ` <20110803.191141.888495095889424492.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: David Miller @ 2011-08-04 2:11 UTC (permalink / raw)
To: giuseppe
Cc: alexey.orishko, netdev, oliver, linux-usb, gregkh, alexey.orishko
From: Giuseppe Scrivano <giuseppe@southpole.se>
Date: Wed, 03 Aug 2011 17:46:43 +0200
>>From 7ba49d858103acb2ce4043127e3512ea29dff307 Mon Sep 17 00:00:00 2001
> From: Giuseppe Scrivano <giuseppe@southpole.se>
> Date: Fri, 15 Jul 2011 15:34:14 +0200
> Subject: [PATCH] cdc_ncm: fix endianess problem.
>
> Signed-off-by: Giuseppe Scrivano <giuseppe@southpole.se>
The patch looks great, but please repost this fresh with a more
vebose commit log message explaining all the things we discussed
to get the change to it's current form.
Thanks!
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
[not found] ` <2AC7D4AD8BA1C640B4C60C61C8E520153E3DEF6C26-8ZTw5gFVCTjVH5byLeRTJxkTb7+GphCuwzqs5ZKRSiY@public.gmane.org>
@ 2011-08-03 15:46 ` Giuseppe Scrivano
2011-08-04 2:11 ` David Miller
0 siblings, 1 reply; 11+ messages in thread
From: Giuseppe Scrivano @ 2011-08-03 15:46 UTC (permalink / raw)
To: Alexey ORISHKO
Cc: netdev@vger.kernel.org, oliver@neukum.org,
linux-usb@vger.kernel.org, gregkh@suse.de,
alexey.orishko@gmail.com
Alexey ORISHKO <alexey.orishko-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org> writes:
> Since it was incorrect to use struct usb_cdc_notification I would rather
> remove cdc_ncm_do_request() function and provide u16 parameters directly to
> usb_control_msg without creating yet additional structure for usb control request.
here another version, I have removed cdc_ncm_do_request and call
directly usb_control_msg. Tested on mips.
Cheers,
Giuseppe
>From 7ba49d858103acb2ce4043127e3512ea29dff307 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <giuseppe-A9uVI2HLR7kOP4wsBPIw7w@public.gmane.org>
Date: Fri, 15 Jul 2011 15:34:14 +0200
Subject: [PATCH] cdc_ncm: fix endianess problem.
Signed-off-by: Giuseppe Scrivano <giuseppe-A9uVI2HLR7kOP4wsBPIw7w@public.gmane.org>
---
drivers/net/usb/cdc_ncm.c | 156 ++++++++++++++++-----------------------------
1 files changed, 56 insertions(+), 100 deletions(-)
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index f33ca6a..9c37d54 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -54,7 +54,7 @@
#include <linux/usb/usbnet.h>
#include <linux/usb/cdc.h>
-#define DRIVER_VERSION "01-June-2011"
+#define DRIVER_VERSION "03-Aug-2011"
/* CDC NCM subclass 3.2.1 */
#define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10
@@ -164,35 +164,8 @@ cdc_ncm_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
usb_make_path(dev->udev, info->bus_info, sizeof(info->bus_info));
}
-static int
-cdc_ncm_do_request(struct cdc_ncm_ctx *ctx, struct usb_cdc_notification *req,
- void *data, u16 flags, u16 *actlen, u16 timeout)
-{
- int err;
-
- err = usb_control_msg(ctx->udev, (req->bmRequestType & USB_DIR_IN) ?
- usb_rcvctrlpipe(ctx->udev, 0) :
- usb_sndctrlpipe(ctx->udev, 0),
- req->bNotificationType, req->bmRequestType,
- req->wValue,
- req->wIndex, data,
- req->wLength, timeout);
-
- if (err < 0) {
- if (actlen)
- *actlen = 0;
- return err;
- }
-
- if (actlen)
- *actlen = err;
-
- return 0;
-}
-
static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
{
- struct usb_cdc_notification req;
u32 val;
u8 flags;
u8 iface_no;
@@ -201,14 +174,14 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber;
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_GET_NTB_PARAMETERS;
- req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = cpu_to_le16(sizeof(ctx->ncm_parm));
-
- err = cdc_ncm_do_request(ctx, &req, &ctx->ncm_parm, 0, NULL, 1000);
- if (err) {
+ err = usb_control_msg(ctx->udev,
+ usb_rcvctrlpipe(ctx->udev, 0),
+ USB_CDC_GET_NTB_PARAMETERS,
+ USB_TYPE_CLASS | USB_DIR_IN
+ | USB_RECIP_INTERFACE,
+ 0, iface_no, &ctx->ncm_parm,
+ sizeof(ctx->ncm_parm), 10000);
+ if (err < 0) {
pr_debug("failed GET_NTB_PARAMETERS\n");
return 1;
}
@@ -254,31 +227,26 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
/* inform device about NTB input size changes */
if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) {
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
- USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_NTB_INPUT_SIZE;
- req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
if (flags & USB_CDC_NCM_NCAP_NTB_INPUT_SIZE) {
struct usb_cdc_ncm_ndp_input_size ndp_in_sz;
-
- req.wLength = 8;
- ndp_in_sz.dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
- ndp_in_sz.wNtbInMaxDatagrams =
- cpu_to_le16(CDC_NCM_DPT_DATAGRAMS_MAX);
- ndp_in_sz.wReserved = 0;
- err = cdc_ncm_do_request(ctx, &req, &ndp_in_sz, 0, NULL,
- 1000);
+ err = usb_control_msg(ctx->udev,
+ usb_sndctrlpipe(ctx->udev, 0),
+ USB_CDC_SET_NTB_INPUT_SIZE,
+ USB_TYPE_CLASS | USB_DIR_OUT
+ | USB_RECIP_INTERFACE,
+ 0, iface_no, &ndp_in_sz, 8, 1000);
} else {
__le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
-
- req.wLength = 4;
- err = cdc_ncm_do_request(ctx, &req, &dwNtbInMaxSize, 0,
- NULL, 1000);
+ err = usb_control_msg(ctx->udev,
+ usb_sndctrlpipe(ctx->udev, 0),
+ USB_CDC_SET_NTB_INPUT_SIZE,
+ USB_TYPE_CLASS | USB_DIR_OUT
+ | USB_RECIP_INTERFACE,
+ 0, iface_no, &dwNtbInMaxSize, 4, 1000);
}
- if (err)
+ if (err < 0)
pr_debug("Setting NTB Input Size failed\n");
}
@@ -333,29 +301,24 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
/* set CRC Mode */
if (flags & USB_CDC_NCM_NCAP_CRC_MODE) {
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
- USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_CRC_MODE;
- req.wValue = cpu_to_le16(USB_CDC_NCM_CRC_NOT_APPENDED);
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = 0;
-
- err = cdc_ncm_do_request(ctx, &req, NULL, 0, NULL, 1000);
- if (err)
+ err = usb_control_msg(ctx->udev, usb_sndctrlpipe(ctx->udev, 0),
+ USB_CDC_SET_CRC_MODE,
+ USB_TYPE_CLASS | USB_DIR_OUT
+ | USB_RECIP_INTERFACE,
+ USB_CDC_NCM_CRC_NOT_APPENDED,
+ iface_no, NULL, 0, 1000);
+ if (err < 0)
pr_debug("Setting CRC mode off failed\n");
}
/* set NTB format, if both formats are supported */
if (ntb_fmt_supported & USB_CDC_NCM_NTH32_SIGN) {
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
- USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_NTB_FORMAT;
- req.wValue = cpu_to_le16(USB_CDC_NCM_NTB16_FORMAT);
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = 0;
-
- err = cdc_ncm_do_request(ctx, &req, NULL, 0, NULL, 1000);
- if (err)
+ err = usb_control_msg(ctx->udev, usb_sndctrlpipe(ctx->udev, 0),
+ USB_CDC_SET_NTB_FORMAT, USB_TYPE_CLASS
+ | USB_DIR_OUT | USB_RECIP_INTERFACE,
+ USB_CDC_NCM_NTB16_FORMAT,
+ iface_no, NULL, 0, 1000);
+ if (err < 0)
pr_debug("Setting NTB format to 16-bit failed\n");
}
@@ -365,17 +328,13 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
if (flags & USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE) {
__le16 max_datagram_size;
u16 eth_max_sz = le16_to_cpu(ctx->ether_desc->wMaxSegmentSize);
-
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_IN |
- USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_GET_MAX_DATAGRAM_SIZE;
- req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = cpu_to_le16(2);
-
- err = cdc_ncm_do_request(ctx, &req, &max_datagram_size, 0, NULL,
- 1000);
- if (err) {
+ err = usb_control_msg(ctx->udev, usb_rcvctrlpipe(ctx->udev, 0),
+ USB_CDC_GET_MAX_DATAGRAM_SIZE,
+ USB_TYPE_CLASS | USB_DIR_IN
+ | USB_RECIP_INTERFACE,
+ 0, iface_no, &max_datagram_size,
+ 2, 1000);
+ if (err < 0) {
pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n",
CDC_NCM_MIN_DATAGRAM_SIZE);
} else {
@@ -396,17 +355,15 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
CDC_NCM_MIN_DATAGRAM_SIZE;
/* if value changed, update device */
- req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
- USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_MAX_DATAGRAM_SIZE;
- req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = 2;
- max_datagram_size = cpu_to_le16(ctx->max_datagram_size);
-
- err = cdc_ncm_do_request(ctx, &req, &max_datagram_size,
- 0, NULL, 1000);
- if (err)
+ err = usb_control_msg(ctx->udev,
+ usb_sndctrlpipe(ctx->udev, 0),
+ USB_CDC_SET_MAX_DATAGRAM_SIZE,
+ USB_TYPE_CLASS | USB_DIR_OUT
+ | USB_RECIP_INTERFACE,
+ 0,
+ iface_no, &max_datagram_size,
+ 2, 1000);
+ if (err < 0)
pr_debug("SET_MAX_DATAGRAM_SIZE failed\n");
}
@@ -672,7 +629,7 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
u32 rem;
u32 offset;
u32 last_offset;
- u16 n = 0;
+ u16 n = 0, index;
u8 ready2send = 0;
/* if there is a remaining skb, it gets priority */
@@ -860,8 +817,8 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
cpu_to_le16(sizeof(ctx->tx_ncm.nth16));
ctx->tx_ncm.nth16.wSequence = cpu_to_le16(ctx->tx_seq);
ctx->tx_ncm.nth16.wBlockLength = cpu_to_le16(last_offset);
- ctx->tx_ncm.nth16.wNdpIndex = ALIGN(sizeof(struct usb_cdc_ncm_nth16),
- ctx->tx_ndp_modulus);
+ index = ALIGN(sizeof(struct usb_cdc_ncm_nth16), ctx->tx_ndp_modulus);
+ ctx->tx_ncm.nth16.wNdpIndex = cpu_to_le16(index);
memcpy(skb_out->data, &(ctx->tx_ncm.nth16), sizeof(ctx->tx_ncm.nth16));
ctx->tx_seq++;
@@ -874,12 +831,11 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
ctx->tx_ncm.ndp16.wLength = cpu_to_le16(rem);
ctx->tx_ncm.ndp16.wNextNdpIndex = 0; /* reserved */
- memcpy(((u8 *)skb_out->data) + ctx->tx_ncm.nth16.wNdpIndex,
+ memcpy(((u8 *)skb_out->data) + index,
&(ctx->tx_ncm.ndp16),
sizeof(ctx->tx_ncm.ndp16));
- memcpy(((u8 *)skb_out->data) + ctx->tx_ncm.nth16.wNdpIndex +
- sizeof(ctx->tx_ncm.ndp16),
+ memcpy(((u8 *)skb_out->data) + index + sizeof(ctx->tx_ncm.ndp16),
&(ctx->tx_ncm.dpe16),
(ctx->tx_curr_frame_num + 1) *
sizeof(struct usb_cdc_ncm_dpe16));
--
1.7.5.4
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 11+ messages in thread
* RE: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
[not found] ` <87hb5yock6.fsf-mXXj517/zsQ@public.gmane.org>
@ 2011-08-03 14:07 ` Alexey ORISHKO
[not found] ` <2AC7D4AD8BA1C640B4C60C61C8E520153E3DEF6C26-8ZTw5gFVCTjVH5byLeRTJxkTb7+GphCuwzqs5ZKRSiY@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Alexey ORISHKO @ 2011-08-03 14:07 UTC (permalink / raw)
To: Giuseppe Scrivano
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, oliver-GvhC2dPhHPQdnm+yROfE0A,
linux-usb-u79uwXL29TY76Z2rM5mHXA, gregkh-l3A5Bk7waGM,
alexey.orishko-Re5JQEeQqe8AvxtiuMwx3w
> From 8bd65735b4f0db5b6213f59a443c21d0d55dba8e Mon Sep 17 00:00:00 2001
> From: Giuseppe Scrivano <giuseppe-A9uVI2HLR7kOP4wsBPIw7w@public.gmane.org>
> Date: Fri, 15 Jul 2011 15:34:14 +0200
> Subject: [PATCH] cdc_ncm: fix endianess problem.
>
> Signed-off-by: Giuseppe Scrivano <giuseppe-A9uVI2HLR7kOP4wsBPIw7w@public.gmane.org>
> ---
> drivers/net/usb/cdc_ncm.c | 65 +++++++++++++++++++++++++-------------------
> -
> +struct cdc_ncm_request {
> + u8 bRequest;
> + u8 bmRequestType;
> + u16 wValue;
> + u16 wIndex;
> + u16 wLength;
> +} __packed;
Since it was incorrect to use struct usb_cdc_notification I would rather
remove cdc_ncm_do_request() function and provide u16 parameters directly to
usb_control_msg without creating yet additional structure for usb control request.
alexey
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS
@ 2011-08-03 13:21 Giuseppe Scrivano
[not found] ` <87hb5yock6.fsf-mXXj517/zsQ@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Giuseppe Scrivano @ 2011-08-03 13:21 UTC (permalink / raw)
To: alexey.orishko; +Cc: netdev, oliver, linux-usb, gregkh
Hello,
I have reworked the original patch I have submitted to Alexey.
Regards,
Giuseppe
>From 8bd65735b4f0db5b6213f59a443c21d0d55dba8e Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <giuseppe@southpole.se>
Date: Fri, 15 Jul 2011 15:34:14 +0200
Subject: [PATCH] cdc_ncm: fix endianess problem.
Signed-off-by: Giuseppe Scrivano <giuseppe@southpole.se>
---
drivers/net/usb/cdc_ncm.c | 65 +++++++++++++++++++++++++--------------------
1 files changed, 36 insertions(+), 29 deletions(-)
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index f33ca6a..cd5d819 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -54,7 +54,7 @@
#include <linux/usb/usbnet.h>
#include <linux/usb/cdc.h>
-#define DRIVER_VERSION "01-June-2011"
+#define DRIVER_VERSION "03-Aug-2011"
/* CDC NCM subclass 3.2.1 */
#define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10
@@ -136,6 +136,14 @@ struct cdc_ncm_ctx {
u16 connected;
};
+struct cdc_ncm_request {
+ u8 bRequest;
+ u8 bmRequestType;
+ u16 wValue;
+ u16 wIndex;
+ u16 wLength;
+} __packed;
+
static void cdc_ncm_tx_timeout(unsigned long arg);
static const struct driver_info cdc_ncm_info;
static struct usb_driver cdc_ncm_driver;
@@ -165,7 +173,7 @@ cdc_ncm_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
}
static int
-cdc_ncm_do_request(struct cdc_ncm_ctx *ctx, struct usb_cdc_notification *req,
+cdc_ncm_do_request(struct cdc_ncm_ctx *ctx, struct cdc_ncm_request *req,
void *data, u16 flags, u16 *actlen, u16 timeout)
{
int err;
@@ -173,7 +181,7 @@ cdc_ncm_do_request(struct cdc_ncm_ctx *ctx, struct usb_cdc_notification *req,
err = usb_control_msg(ctx->udev, (req->bmRequestType & USB_DIR_IN) ?
usb_rcvctrlpipe(ctx->udev, 0) :
usb_sndctrlpipe(ctx->udev, 0),
- req->bNotificationType, req->bmRequestType,
+ req->bRequest, req->bmRequestType,
req->wValue,
req->wIndex, data,
req->wLength, timeout);
@@ -192,7 +200,7 @@ cdc_ncm_do_request(struct cdc_ncm_ctx *ctx, struct usb_cdc_notification *req,
static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
{
- struct usb_cdc_notification req;
+ struct cdc_ncm_request req;
u32 val;
u8 flags;
u8 iface_no;
@@ -202,10 +210,10 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber;
req.bmRequestType = USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_GET_NTB_PARAMETERS;
+ req.bRequest = USB_CDC_GET_NTB_PARAMETERS;
req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = cpu_to_le16(sizeof(ctx->ncm_parm));
+ req.wIndex = iface_no;
+ req.wLength = sizeof(ctx->ncm_parm);
err = cdc_ncm_do_request(ctx, &req, &ctx->ncm_parm, 0, NULL, 1000);
if (err) {
@@ -256,9 +264,9 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
if (ctx->rx_max != le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize)) {
req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_NTB_INPUT_SIZE;
+ req.bRequest = USB_CDC_SET_NTB_INPUT_SIZE;
req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
+ req.wIndex = iface_no;
if (flags & USB_CDC_NCM_NCAP_NTB_INPUT_SIZE) {
struct usb_cdc_ncm_ndp_input_size ndp_in_sz;
@@ -335,9 +343,9 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
if (flags & USB_CDC_NCM_NCAP_CRC_MODE) {
req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_CRC_MODE;
- req.wValue = cpu_to_le16(USB_CDC_NCM_CRC_NOT_APPENDED);
- req.wIndex = cpu_to_le16(iface_no);
+ req.bRequest = USB_CDC_SET_CRC_MODE;
+ req.wValue = USB_CDC_NCM_CRC_NOT_APPENDED;
+ req.wIndex = iface_no;
req.wLength = 0;
err = cdc_ncm_do_request(ctx, &req, NULL, 0, NULL, 1000);
@@ -349,9 +357,9 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
if (ntb_fmt_supported & USB_CDC_NCM_NTH32_SIGN) {
req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_NTB_FORMAT;
- req.wValue = cpu_to_le16(USB_CDC_NCM_NTB16_FORMAT);
- req.wIndex = cpu_to_le16(iface_no);
+ req.bRequest = USB_CDC_SET_NTB_FORMAT;
+ req.wValue = USB_CDC_NCM_NTB16_FORMAT;
+ req.wIndex = iface_no;
req.wLength = 0;
err = cdc_ncm_do_request(ctx, &req, NULL, 0, NULL, 1000);
@@ -368,10 +376,10 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
req.bmRequestType = USB_TYPE_CLASS | USB_DIR_IN |
USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_GET_MAX_DATAGRAM_SIZE;
+ req.bRequest = USB_CDC_GET_MAX_DATAGRAM_SIZE;
req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
- req.wLength = cpu_to_le16(2);
+ req.wIndex = iface_no;
+ req.wLength = 2;
err = cdc_ncm_do_request(ctx, &req, &max_datagram_size, 0, NULL,
1000);
@@ -398,9 +406,9 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
/* if value changed, update device */
req.bmRequestType = USB_TYPE_CLASS | USB_DIR_OUT |
USB_RECIP_INTERFACE;
- req.bNotificationType = USB_CDC_SET_MAX_DATAGRAM_SIZE;
+ req.bRequest = USB_CDC_SET_MAX_DATAGRAM_SIZE;
req.wValue = 0;
- req.wIndex = cpu_to_le16(iface_no);
+ req.wIndex = iface_no;
req.wLength = 2;
max_datagram_size = cpu_to_le16(ctx->max_datagram_size);
@@ -672,7 +680,7 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
u32 rem;
u32 offset;
u32 last_offset;
- u16 n = 0;
+ u16 n = 0, index;
u8 ready2send = 0;
/* if there is a remaining skb, it gets priority */
@@ -860,8 +868,8 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
cpu_to_le16(sizeof(ctx->tx_ncm.nth16));
ctx->tx_ncm.nth16.wSequence = cpu_to_le16(ctx->tx_seq);
ctx->tx_ncm.nth16.wBlockLength = cpu_to_le16(last_offset);
- ctx->tx_ncm.nth16.wNdpIndex = ALIGN(sizeof(struct usb_cdc_ncm_nth16),
- ctx->tx_ndp_modulus);
+ index = ALIGN(sizeof(struct usb_cdc_ncm_nth16), ctx->tx_ndp_modulus);
+ ctx->tx_ncm.nth16.wNdpIndex = cpu_to_le16(index);
memcpy(skb_out->data, &(ctx->tx_ncm.nth16), sizeof(ctx->tx_ncm.nth16));
ctx->tx_seq++;
@@ -874,12 +882,11 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
ctx->tx_ncm.ndp16.wLength = cpu_to_le16(rem);
ctx->tx_ncm.ndp16.wNextNdpIndex = 0; /* reserved */
- memcpy(((u8 *)skb_out->data) + ctx->tx_ncm.nth16.wNdpIndex,
+ memcpy(((u8 *)skb_out->data) + index,
&(ctx->tx_ncm.ndp16),
sizeof(ctx->tx_ncm.ndp16));
- memcpy(((u8 *)skb_out->data) + ctx->tx_ncm.nth16.wNdpIndex +
- sizeof(ctx->tx_ncm.ndp16),
+ memcpy(((u8 *)skb_out->data) + index + sizeof(ctx->tx_ncm.ndp16),
&(ctx->tx_ncm.dpe16),
(ctx->tx_curr_frame_num + 1) *
sizeof(struct usb_cdc_ncm_dpe16));
@@ -1129,7 +1136,7 @@ cdc_ncm_speed_change(struct cdc_ncm_ctx *ctx,
static void cdc_ncm_status(struct usbnet *dev, struct urb *urb)
{
struct cdc_ncm_ctx *ctx;
- struct usb_cdc_notification *event;
+ struct cdc_ncm_request *event;
ctx = (struct cdc_ncm_ctx *)dev->data[0];
@@ -1145,7 +1152,7 @@ static void cdc_ncm_status(struct usbnet *dev, struct urb *urb)
event = urb->transfer_buffer;
- switch (event->bNotificationType) {
+ switch (event->bRequest) {
case USB_CDC_NOTIFY_NETWORK_CONNECTION:
/*
* According to the CDC NCM specification ch.7.1
@@ -1177,7 +1184,7 @@ static void cdc_ncm_status(struct usbnet *dev, struct urb *urb)
default:
dev_err(&dev->udev->dev, "NCM: unexpected "
- "notification 0x%02x!\n", event->bNotificationType);
+ "notification 0x%02x!\n", event->bRequest);
break;
}
}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-08-04 8:44 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-02 16:20 [PATCH ] cdc_ncm: fixes for big-endian architecture / MIPS Alexey Orishko
[not found] ` <1312302026-7077-1-git-send-email-alexey.orishko-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>
2011-08-02 18:30 ` Oliver Neukum
2011-08-02 19:45 ` Alan Stern
2011-08-03 10:42 ` David Miller
[not found] ` <20110803.034253.417905916118311130.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-08-03 11:13 ` Alexey ORISHKO
2011-08-03 13:21 Giuseppe Scrivano
[not found] ` <87hb5yock6.fsf-mXXj517/zsQ@public.gmane.org>
2011-08-03 14:07 ` Alexey ORISHKO
[not found] ` <2AC7D4AD8BA1C640B4C60C61C8E520153E3DEF6C26-8ZTw5gFVCTjVH5byLeRTJxkTb7+GphCuwzqs5ZKRSiY@public.gmane.org>
2011-08-03 15:46 ` Giuseppe Scrivano
2011-08-04 2:11 ` David Miller
[not found] ` <20110803.191141.888495095889424492.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2011-08-04 8:10 ` Giuseppe Scrivano
2011-08-04 8:43 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).