aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb/rndis_host.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@mbnet.fi>2012-05-11 18:17:34 -0400
committerDavid S. Miller <davem@davemloft.net>2012-05-12 15:16:13 -0400
commit3eef36689888390cc30fbe0d27a5785e1df08de0 (patch)
treefe76bfb9e5e639f892cd1442f430e377a9979128 /drivers/net/usb/rndis_host.c
parentd5543206b281506a8eb5b960e766b1881fa0f799 (diff)
rndis_host: cleanup: byteswap data from device instead of RNDIS_* defines
All other values from device provided buffer are byteswapped, so it seems more logical to do same for these. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/usb/rndis_host.c')
-rw-r--r--drivers/net/usb/rndis_host.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/drivers/net/usb/rndis_host.c b/drivers/net/usb/rndis_host.c
index dd342dca9d74..74315fdd4ada 100644
--- a/drivers/net/usb/rndis_host.c
+++ b/drivers/net/usb/rndis_host.c
@@ -77,16 +77,17 @@ static void rndis_msg_indicate(struct usbnet *dev, struct rndis_indicate *msg,
77 if (dev->driver_info->indication) { 77 if (dev->driver_info->indication) {
78 dev->driver_info->indication(dev, msg, buflen); 78 dev->driver_info->indication(dev, msg, buflen);
79 } else { 79 } else {
80 switch (msg->status) { 80 u32 status = le32_to_cpu(msg->status);
81 case cpu_to_le32(RNDIS_STATUS_MEDIA_CONNECT): 81
82 switch (status) {
83 case RNDIS_STATUS_MEDIA_CONNECT:
82 dev_info(udev, "rndis media connect\n"); 84 dev_info(udev, "rndis media connect\n");
83 break; 85 break;
84 case cpu_to_le32(RNDIS_STATUS_MEDIA_DISCONNECT): 86 case RNDIS_STATUS_MEDIA_DISCONNECT:
85 dev_info(udev, "rndis media disconnect\n"); 87 dev_info(udev, "rndis media disconnect\n");
86 break; 88 break;
87 default: 89 default:
88 dev_info(udev, "rndis indication: 0x%08x\n", 90 dev_info(udev, "rndis indication: 0x%08x\n", status);
89 le32_to_cpu(msg->status));
90 } 91 }
91 } 92 }
92} 93}
@@ -109,16 +110,17 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen)
109 int retval; 110 int retval;
110 int partial; 111 int partial;
111 unsigned count; 112 unsigned count;
112 __le32 rsp; 113 u32 xid = 0, msg_len, request_id, msg_type, rsp,
113 u32 xid = 0, msg_len, request_id; 114 status;
114 115
115 /* REVISIT when this gets called from contexts other than probe() or 116 /* REVISIT when this gets called from contexts other than probe() or
116 * disconnect(): either serialize, or dispatch responses on xid 117 * disconnect(): either serialize, or dispatch responses on xid
117 */ 118 */
118 119
120 msg_type = le32_to_cpu(buf->msg_type);
121
119 /* Issue the request; xid is unique, don't bother byteswapping it */ 122 /* Issue the request; xid is unique, don't bother byteswapping it */
120 if (likely(buf->msg_type != cpu_to_le32(RNDIS_MSG_HALT) && 123 if (likely(msg_type != RNDIS_MSG_HALT && msg_type != RNDIS_MSG_RESET)) {
121 buf->msg_type != cpu_to_le32(RNDIS_MSG_RESET))) {
122 xid = dev->xid++; 124 xid = dev->xid++;
123 if (!xid) 125 if (!xid)
124 xid = dev->xid++; 126 xid = dev->xid++;
@@ -149,7 +151,7 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen)
149 } 151 }
150 152
151 /* Poll the control channel; the request probably completed immediately */ 153 /* Poll the control channel; the request probably completed immediately */
152 rsp = buf->msg_type | cpu_to_le32(RNDIS_MSG_COMPLETION); 154 rsp = le32_to_cpu(buf->msg_type) | RNDIS_MSG_COMPLETION;
153 for (count = 0; count < 10; count++) { 155 for (count = 0; count < 10; count++) {
154 memset(buf, 0, CONTROL_BUFFER_SIZE); 156 memset(buf, 0, CONTROL_BUFFER_SIZE);
155 retval = usb_control_msg(dev->udev, 157 retval = usb_control_msg(dev->udev,
@@ -160,30 +162,31 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen)
160 buf, buflen, 162 buf, buflen,
161 RNDIS_CONTROL_TIMEOUT_MS); 163 RNDIS_CONTROL_TIMEOUT_MS);
162 if (likely(retval >= 8)) { 164 if (likely(retval >= 8)) {
165 msg_type = le32_to_cpu(buf->msg_type);
163 msg_len = le32_to_cpu(buf->msg_len); 166 msg_len = le32_to_cpu(buf->msg_len);
167 status = le32_to_cpu(buf->status);
164 request_id = (__force u32) buf->request_id; 168 request_id = (__force u32) buf->request_id;
165 if (likely(buf->msg_type == rsp)) { 169 if (likely(msg_type == rsp)) {
166 if (likely(request_id == xid)) { 170 if (likely(request_id == xid)) {
167 if (unlikely(rsp == 171 if (unlikely(rsp == RNDIS_MSG_RESET_C))
168 cpu_to_le32(RNDIS_MSG_RESET_C)))
169 return 0; 172 return 0;
170 if (likely(cpu_to_le32(RNDIS_STATUS_SUCCESS) 173 if (likely(RNDIS_STATUS_SUCCESS ==
171 == buf->status)) 174 status))
172 return 0; 175 return 0;
173 dev_dbg(&info->control->dev, 176 dev_dbg(&info->control->dev,
174 "rndis reply status %08x\n", 177 "rndis reply status %08x\n",
175 le32_to_cpu(buf->status)); 178 status);
176 return -EL3RST; 179 return -EL3RST;
177 } 180 }
178 dev_dbg(&info->control->dev, 181 dev_dbg(&info->control->dev,
179 "rndis reply id %d expected %d\n", 182 "rndis reply id %d expected %d\n",
180 request_id, xid); 183 request_id, xid);
181 /* then likely retry */ 184 /* then likely retry */
182 } else switch (buf->msg_type) { 185 } else switch (msg_type) {
183 case cpu_to_le32(RNDIS_MSG_INDICATE): /* fault/event */ 186 case RNDIS_MSG_INDICATE: /* fault/event */
184 rndis_msg_indicate(dev, (void *)buf, buflen); 187 rndis_msg_indicate(dev, (void *)buf, buflen);
185 break; 188 break;
186 case cpu_to_le32(RNDIS_MSG_KEEPALIVE): { /* ping */ 189 case RNDIS_MSG_KEEPALIVE: { /* ping */
187 struct rndis_keepalive_c *msg = (void *)buf; 190 struct rndis_keepalive_c *msg = (void *)buf;
188 191
189 msg->msg_type = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C); 192 msg->msg_type = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C);
@@ -404,14 +407,14 @@ generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf, int flags)
404 phym = &phym_unspec; 407 phym = &phym_unspec;
405 } 408 }
406 if ((flags & FLAG_RNDIS_PHYM_WIRELESS) && 409 if ((flags & FLAG_RNDIS_PHYM_WIRELESS) &&
407 *phym != cpu_to_le32(RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN)) { 410 le32_to_cpup(phym) != RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN) {
408 netif_dbg(dev, probe, dev->net, 411 netif_dbg(dev, probe, dev->net,
409 "driver requires wireless physical medium, but device is not\n"); 412 "driver requires wireless physical medium, but device is not\n");
410 retval = -ENODEV; 413 retval = -ENODEV;
411 goto halt_fail_and_release; 414 goto halt_fail_and_release;
412 } 415 }
413 if ((flags & FLAG_RNDIS_PHYM_NOT_WIRELESS) && 416 if ((flags & FLAG_RNDIS_PHYM_NOT_WIRELESS) &&
414 *phym == cpu_to_le32(RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN)) { 417 le32_to_cpup(phym) == RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN) {
415 netif_dbg(dev, probe, dev->net, 418 netif_dbg(dev, probe, dev->net,
416 "driver requires non-wireless physical medium, but device is wireless.\n"); 419 "driver requires non-wireless physical medium, but device is wireless.\n");
417 retval = -ENODEV; 420 retval = -ENODEV;
@@ -496,16 +499,16 @@ int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
496 while (likely(skb->len)) { 499 while (likely(skb->len)) {
497 struct rndis_data_hdr *hdr = (void *)skb->data; 500 struct rndis_data_hdr *hdr = (void *)skb->data;
498 struct sk_buff *skb2; 501 struct sk_buff *skb2;
499 u32 msg_len, data_offset, data_len; 502 u32 msg_type, msg_len, data_offset, data_len;
500 503
504 msg_type = le32_to_cpu(hdr->msg_type);
501 msg_len = le32_to_cpu(hdr->msg_len); 505 msg_len = le32_to_cpu(hdr->msg_len);
502 data_offset = le32_to_cpu(hdr->data_offset); 506 data_offset = le32_to_cpu(hdr->data_offset);
503 data_len = le32_to_cpu(hdr->data_len); 507 data_len = le32_to_cpu(hdr->data_len);
504 508
505 /* don't choke if we see oob, per-packet data, etc */ 509 /* don't choke if we see oob, per-packet data, etc */
506 if (unlikely(hdr->msg_type != cpu_to_le32(RNDIS_MSG_PACKET) || 510 if (unlikely(msg_type != RNDIS_MSG_PACKET || skb->len < msg_len
507 skb->len < msg_len || 511 || (data_offset + data_len + 8) > msg_len)) {
508 (data_offset + data_len + 8) > msg_len)) {
509 dev->net->stats.rx_frame_errors++; 512 dev->net->stats.rx_frame_errors++;
510 netdev_dbg(dev->net, "bad rndis message %d/%d/%d/%d, len %d\n", 513 netdev_dbg(dev->net, "bad rndis message %d/%d/%d/%d, len %d\n",
511 le32_to_cpu(hdr->msg_type), 514 le32_to_cpu(hdr->msg_type),