diff options
author | David Brownell <david-b@pacbell.net> | 2005-04-28 16:48:09 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-06-27 17:43:50 -0400 |
commit | 907cba35f7f24587f0eff60073e1f4e1e01c976d (patch) | |
tree | 1a26929d319d3c5677529a9ca5483f9129fc6445 /drivers/usb/gadget | |
parent | 340600ab4cf0cc41efd01a65af97ebb7d35a7f85 (diff) |
[PATCH] USB: ethernet gadget updates (mostly cleanup)
Some cleanup for the the Ethernet part of the Ethernet/RNDIS gadget driver:
- Remove remnants of ancient endpoint init logic; this is simpler, clearer
- Save a smidgeon of space in the object file
- Get rid of some #ifdeffery, mostly by using some newish inlines
- Reset more driver state as part of USB reset
- Remove a needless wrapper around an RNDIS call
- Improve and comment the status interrupt handling:
* RNDIS sometimes needs to queue these transfers (rarely in normal
cases, but reproducibly while Windows was deadlocking its USB stack)
* Mark requests as busy/not
- Enable the SET_NETDEV_DEV() call; sysfs seems to behave sanely now
This is a net shrink of source code.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r-- | drivers/usb/gadget/ether.c | 287 |
1 files changed, 107 insertions, 180 deletions
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index a766c29c3ec9..3830a0a0fd50 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -84,7 +84,7 @@ | |||
84 | */ | 84 | */ |
85 | 85 | ||
86 | #define DRIVER_DESC "Ethernet Gadget" | 86 | #define DRIVER_DESC "Ethernet Gadget" |
87 | #define DRIVER_VERSION "Equinox 2004" | 87 | #define DRIVER_VERSION "May Day 2005" |
88 | 88 | ||
89 | static const char shortname [] = "ether"; | 89 | static const char shortname [] = "ether"; |
90 | static const char driver_desc [] = DRIVER_DESC; | 90 | static const char driver_desc [] = DRIVER_DESC; |
@@ -141,9 +141,6 @@ struct eth_dev { | |||
141 | * It also ASSUMES a self-powered device, without remote wakeup, | 141 | * It also ASSUMES a self-powered device, without remote wakeup, |
142 | * although remote wakeup support would make sense. | 142 | * although remote wakeup support would make sense. |
143 | */ | 143 | */ |
144 | static const char *EP_IN_NAME; | ||
145 | static const char *EP_OUT_NAME; | ||
146 | static const char *EP_STATUS_NAME; | ||
147 | 144 | ||
148 | /*-------------------------------------------------------------------------*/ | 145 | /*-------------------------------------------------------------------------*/ |
149 | 146 | ||
@@ -313,6 +310,7 @@ static inline int rndis_active(struct eth_dev *dev) | |||
313 | #define FS_BPS (19 * 64 * 1 * 1000 * 8) | 310 | #define FS_BPS (19 * 64 * 1 * 1000 * 8) |
314 | 311 | ||
315 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 312 | #ifdef CONFIG_USB_GADGET_DUALSPEED |
313 | #define DEVSPEED USB_SPEED_HIGH | ||
316 | 314 | ||
317 | static unsigned qmult = 5; | 315 | static unsigned qmult = 5; |
318 | module_param (qmult, uint, S_IRUGO|S_IWUSR); | 316 | module_param (qmult, uint, S_IRUGO|S_IWUSR); |
@@ -331,6 +329,8 @@ static inline int BITRATE(struct usb_gadget *g) | |||
331 | } | 329 | } |
332 | 330 | ||
333 | #else /* full speed (low speed doesn't do bulk) */ | 331 | #else /* full speed (low speed doesn't do bulk) */ |
332 | #define DEVSPEED USB_SPEED_FULL | ||
333 | |||
334 | #define qlen(gadget) DEFAULT_QLEN | 334 | #define qlen(gadget) DEFAULT_QLEN |
335 | 335 | ||
336 | static inline int BITRATE(struct usb_gadget *g) | 336 | static inline int BITRATE(struct usb_gadget *g) |
@@ -540,7 +540,7 @@ static const struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = { | |||
540 | .bDataInterface = 0x01, | 540 | .bDataInterface = 0x01, |
541 | }; | 541 | }; |
542 | 542 | ||
543 | static struct usb_cdc_acm_descriptor acm_descriptor = { | 543 | static const struct usb_cdc_acm_descriptor acm_descriptor = { |
544 | .bLength = sizeof acm_descriptor, | 544 | .bLength = sizeof acm_descriptor, |
545 | .bDescriptorType = USB_DT_CS_INTERFACE, | 545 | .bDescriptorType = USB_DT_CS_INTERFACE, |
546 | .bDescriptorSubType = USB_CDC_ACM_TYPE, | 546 | .bDescriptorSubType = USB_CDC_ACM_TYPE, |
@@ -848,7 +848,7 @@ static const struct usb_descriptor_header *hs_rndis_function [] = { | |||
848 | #else | 848 | #else |
849 | 849 | ||
850 | /* if there's no high speed support, maxpacket doesn't change. */ | 850 | /* if there's no high speed support, maxpacket doesn't change. */ |
851 | #define ep_desc(g,hs,fs) fs | 851 | #define ep_desc(g,hs,fs) (((void)(g)), (fs)) |
852 | 852 | ||
853 | static inline void __init hs_subset_descriptors(void) | 853 | static inline void __init hs_subset_descriptors(void) |
854 | { | 854 | { |
@@ -948,10 +948,31 @@ config_buf (enum usb_device_speed speed, | |||
948 | static void eth_start (struct eth_dev *dev, int gfp_flags); | 948 | static void eth_start (struct eth_dev *dev, int gfp_flags); |
949 | static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags); | 949 | static int alloc_requests (struct eth_dev *dev, unsigned n, int gfp_flags); |
950 | 950 | ||
951 | #ifdef DEV_CONFIG_CDC | 951 | static int |
952 | static inline int ether_alt_ep_setup (struct eth_dev *dev, struct usb_ep *ep) | 952 | set_ether_config (struct eth_dev *dev, int gfp_flags) |
953 | { | 953 | { |
954 | const struct usb_endpoint_descriptor *d; | 954 | int result = 0; |
955 | struct usb_gadget *gadget = dev->gadget; | ||
956 | |||
957 | /* status endpoint used for RNDIS and (optionally) CDC */ | ||
958 | if (!subset_active(dev) && dev->status_ep) { | ||
959 | dev->status = ep_desc (gadget, &hs_status_desc, | ||
960 | &fs_status_desc); | ||
961 | dev->status_ep->driver_data = dev; | ||
962 | |||
963 | result = usb_ep_enable (dev->status_ep, dev->status); | ||
964 | if (result != 0) { | ||
965 | DEBUG (dev, "enable %s --> %d\n", | ||
966 | dev->status_ep->name, result); | ||
967 | goto done; | ||
968 | } | ||
969 | } | ||
970 | |||
971 | dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); | ||
972 | dev->in_ep->driver_data = dev; | ||
973 | |||
974 | dev->out = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc); | ||
975 | dev->out_ep->driver_data = dev; | ||
955 | 976 | ||
956 | /* With CDC, the host isn't allowed to use these two data | 977 | /* With CDC, the host isn't allowed to use these two data |
957 | * endpoints in the default altsetting for the interface. | 978 | * endpoints in the default altsetting for the interface. |
@@ -961,135 +982,33 @@ static inline int ether_alt_ep_setup (struct eth_dev *dev, struct usb_ep *ep) | |||
961 | * a side effect of setting a packet filter. Deactivation is | 982 | * a side effect of setting a packet filter. Deactivation is |
962 | * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG. | 983 | * from REMOTE_NDIS_HALT_MSG, reset from REMOTE_NDIS_RESET_MSG. |
963 | */ | 984 | */ |
964 | 985 | if (!cdc_active(dev)) { | |
965 | /* one endpoint writes data back IN to the host */ | 986 | result = usb_ep_enable (dev->in_ep, dev->in); |
966 | if (strcmp (ep->name, EP_IN_NAME) == 0) { | 987 | if (result != 0) { |
967 | d = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); | 988 | DEBUG(dev, "enable %s --> %d\n", |
968 | ep->driver_data = dev; | 989 | dev->in_ep->name, result); |
969 | dev->in = d; | 990 | goto done; |
970 | |||
971 | /* one endpoint just reads OUT packets */ | ||
972 | } else if (strcmp (ep->name, EP_OUT_NAME) == 0) { | ||
973 | d = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc); | ||
974 | ep->driver_data = dev; | ||
975 | dev->out = d; | ||
976 | |||
977 | /* optional status/notification endpoint */ | ||
978 | } else if (EP_STATUS_NAME && | ||
979 | strcmp (ep->name, EP_STATUS_NAME) == 0) { | ||
980 | int result; | ||
981 | |||
982 | d = ep_desc (dev->gadget, &hs_status_desc, &fs_status_desc); | ||
983 | result = usb_ep_enable (ep, d); | ||
984 | if (result < 0) | ||
985 | return result; | ||
986 | |||
987 | ep->driver_data = dev; | ||
988 | dev->status = d; | ||
989 | } | ||
990 | return 0; | ||
991 | } | ||
992 | #endif | ||
993 | |||
994 | #if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) | ||
995 | static inline int ether_ep_setup (struct eth_dev *dev, struct usb_ep *ep) | ||
996 | { | ||
997 | int result; | ||
998 | const struct usb_endpoint_descriptor *d; | ||
999 | |||
1000 | /* CDC subset is simpler: if the device is there, | ||
1001 | * it's live with rx and tx endpoints. | ||
1002 | * | ||
1003 | * Do this as a shortcut for RNDIS too. | ||
1004 | */ | ||
1005 | |||
1006 | /* one endpoint writes data back IN to the host */ | ||
1007 | if (strcmp (ep->name, EP_IN_NAME) == 0) { | ||
1008 | d = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); | ||
1009 | result = usb_ep_enable (ep, d); | ||
1010 | if (result < 0) | ||
1011 | return result; | ||
1012 | |||
1013 | ep->driver_data = dev; | ||
1014 | dev->in = d; | ||
1015 | |||
1016 | /* one endpoint just reads OUT packets */ | ||
1017 | } else if (strcmp (ep->name, EP_OUT_NAME) == 0) { | ||
1018 | d = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc); | ||
1019 | result = usb_ep_enable (ep, d); | ||
1020 | if (result < 0) | ||
1021 | return result; | ||
1022 | |||
1023 | ep->driver_data = dev; | ||
1024 | dev->out = d; | ||
1025 | } | ||
1026 | |||
1027 | return 0; | ||
1028 | } | ||
1029 | #endif | ||
1030 | |||
1031 | static int | ||
1032 | set_ether_config (struct eth_dev *dev, int gfp_flags) | ||
1033 | { | ||
1034 | int result = 0; | ||
1035 | struct usb_ep *ep; | ||
1036 | struct usb_gadget *gadget = dev->gadget; | ||
1037 | |||
1038 | gadget_for_each_ep (ep, gadget) { | ||
1039 | #ifdef DEV_CONFIG_CDC | ||
1040 | if (!dev->rndis && dev->cdc) { | ||
1041 | result = ether_alt_ep_setup (dev, ep); | ||
1042 | if (result == 0) | ||
1043 | continue; | ||
1044 | } | 991 | } |
1045 | #endif | ||
1046 | 992 | ||
1047 | #ifdef CONFIG_USB_ETH_RNDIS | 993 | result = usb_ep_enable (dev->out_ep, dev->out); |
1048 | if (dev->rndis && strcmp (ep->name, EP_STATUS_NAME) == 0) { | 994 | if (result != 0) { |
1049 | const struct usb_endpoint_descriptor *d; | 995 | DEBUG (dev, "enable %s --> %d\n", |
1050 | d = ep_desc (gadget, &hs_status_desc, &fs_status_desc); | 996 | dev->in_ep->name, result); |
1051 | result = usb_ep_enable (ep, d); | 997 | goto done; |
1052 | if (result == 0) { | ||
1053 | ep->driver_data = dev; | ||
1054 | dev->status = d; | ||
1055 | continue; | ||
1056 | } | ||
1057 | } else | ||
1058 | #endif | ||
1059 | |||
1060 | { | ||
1061 | #if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) | ||
1062 | result = ether_ep_setup (dev, ep); | ||
1063 | if (result == 0) | ||
1064 | continue; | ||
1065 | #endif | ||
1066 | } | 998 | } |
1067 | |||
1068 | /* stop on error */ | ||
1069 | ERROR (dev, "can't enable %s, result %d\n", ep->name, result); | ||
1070 | break; | ||
1071 | } | 999 | } |
1072 | if (!result && (!dev->in_ep || !dev->out_ep)) | ||
1073 | result = -ENODEV; | ||
1074 | 1000 | ||
1001 | done: | ||
1075 | if (result == 0) | 1002 | if (result == 0) |
1076 | result = alloc_requests (dev, qlen (gadget), gfp_flags); | 1003 | result = alloc_requests (dev, qlen (gadget), gfp_flags); |
1077 | 1004 | ||
1078 | /* on error, disable any endpoints */ | 1005 | /* on error, disable any endpoints */ |
1079 | if (result < 0) { | 1006 | if (result < 0) { |
1080 | #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) | 1007 | if (!subset_active(dev)) |
1081 | if (dev->status) | ||
1082 | (void) usb_ep_disable (dev->status_ep); | 1008 | (void) usb_ep_disable (dev->status_ep); |
1083 | #endif | ||
1084 | dev->status = NULL; | 1009 | dev->status = NULL; |
1085 | #if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) | 1010 | (void) usb_ep_disable (dev->in_ep); |
1086 | if (dev->rndis || !dev->cdc) { | 1011 | (void) usb_ep_disable (dev->out_ep); |
1087 | if (dev->in) | ||
1088 | (void) usb_ep_disable (dev->in_ep); | ||
1089 | if (dev->out) | ||
1090 | (void) usb_ep_disable (dev->out_ep); | ||
1091 | } | ||
1092 | #endif | ||
1093 | dev->in = NULL; | 1012 | dev->in = NULL; |
1094 | dev->out = NULL; | 1013 | dev->out = NULL; |
1095 | } else | 1014 | } else |
@@ -1097,8 +1016,7 @@ set_ether_config (struct eth_dev *dev, int gfp_flags) | |||
1097 | /* activate non-CDC configs right away | 1016 | /* activate non-CDC configs right away |
1098 | * this isn't strictly according to the RNDIS spec | 1017 | * this isn't strictly according to the RNDIS spec |
1099 | */ | 1018 | */ |
1100 | #if defined(DEV_CONFIG_SUBSET) || defined(CONFIG_USB_ETH_RNDIS) | 1019 | if (!cdc_active (dev)) { |
1101 | if (dev->rndis || !dev->cdc) { | ||
1102 | netif_carrier_on (dev->net); | 1020 | netif_carrier_on (dev->net); |
1103 | if (netif_running (dev->net)) { | 1021 | if (netif_running (dev->net)) { |
1104 | spin_unlock (&dev->lock); | 1022 | spin_unlock (&dev->lock); |
@@ -1106,7 +1024,6 @@ set_ether_config (struct eth_dev *dev, int gfp_flags) | |||
1106 | spin_lock (&dev->lock); | 1024 | spin_lock (&dev->lock); |
1107 | } | 1025 | } |
1108 | } | 1026 | } |
1109 | #endif | ||
1110 | 1027 | ||
1111 | if (result == 0) | 1028 | if (result == 0) |
1112 | DEBUG (dev, "qlen %d\n", qlen (gadget)); | 1029 | DEBUG (dev, "qlen %d\n", qlen (gadget)); |
@@ -1153,6 +1070,8 @@ static void eth_reset_config (struct eth_dev *dev) | |||
1153 | if (dev->status) { | 1070 | if (dev->status) { |
1154 | usb_ep_disable (dev->status_ep); | 1071 | usb_ep_disable (dev->status_ep); |
1155 | } | 1072 | } |
1073 | dev->rndis = 0; | ||
1074 | dev->cdc_filter = 0; | ||
1156 | dev->config = 0; | 1075 | dev->config = 0; |
1157 | } | 1076 | } |
1158 | 1077 | ||
@@ -1165,9 +1084,6 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags) | |||
1165 | int result = 0; | 1084 | int result = 0; |
1166 | struct usb_gadget *gadget = dev->gadget; | 1085 | struct usb_gadget *gadget = dev->gadget; |
1167 | 1086 | ||
1168 | if (number == dev->config) | ||
1169 | return 0; | ||
1170 | |||
1171 | if (gadget_is_sa1100 (gadget) | 1087 | if (gadget_is_sa1100 (gadget) |
1172 | && dev->config | 1088 | && dev->config |
1173 | && atomic_read (&dev->tx_qlen) != 0) { | 1089 | && atomic_read (&dev->tx_qlen) != 0) { |
@@ -1177,12 +1093,8 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags) | |||
1177 | } | 1093 | } |
1178 | eth_reset_config (dev); | 1094 | eth_reset_config (dev); |
1179 | 1095 | ||
1180 | /* default: pass all packets, no multicast filtering */ | ||
1181 | dev->cdc_filter = DEFAULT_FILTER; | ||
1182 | |||
1183 | switch (number) { | 1096 | switch (number) { |
1184 | case DEV_CONFIG_VALUE: | 1097 | case DEV_CONFIG_VALUE: |
1185 | dev->rndis = 0; | ||
1186 | result = set_ether_config (dev, gfp_flags); | 1098 | result = set_ether_config (dev, gfp_flags); |
1187 | break; | 1099 | break; |
1188 | #ifdef CONFIG_USB_ETH_RNDIS | 1100 | #ifdef CONFIG_USB_ETH_RNDIS |
@@ -1234,6 +1146,13 @@ eth_set_config (struct eth_dev *dev, unsigned number, int gfp_flags) | |||
1234 | 1146 | ||
1235 | #ifdef DEV_CONFIG_CDC | 1147 | #ifdef DEV_CONFIG_CDC |
1236 | 1148 | ||
1149 | /* The interrupt endpoint is used in CDC networking models (Ethernet, ATM) | ||
1150 | * only to notify the host about link status changes (which we support) or | ||
1151 | * report completion of some encapsulated command (as used in RNDIS). Since | ||
1152 | * we want this CDC Ethernet code to be vendor-neutral, we don't use that | ||
1153 | * command mechanism; and only one status request is ever queued. | ||
1154 | */ | ||
1155 | |||
1237 | static void eth_status_complete (struct usb_ep *ep, struct usb_request *req) | 1156 | static void eth_status_complete (struct usb_ep *ep, struct usb_request *req) |
1238 | { | 1157 | { |
1239 | struct usb_cdc_notification *event = req->buf; | 1158 | struct usb_cdc_notification *event = req->buf; |
@@ -1262,7 +1181,7 @@ static void eth_status_complete (struct usb_ep *ep, struct usb_request *req) | |||
1262 | } else if (value != -ECONNRESET) | 1181 | } else if (value != -ECONNRESET) |
1263 | DEBUG (dev, "event %02x --> %d\n", | 1182 | DEBUG (dev, "event %02x --> %d\n", |
1264 | event->bNotificationType, value); | 1183 | event->bNotificationType, value); |
1265 | event->bmRequestType = 0xff; | 1184 | req->context = NULL; |
1266 | } | 1185 | } |
1267 | 1186 | ||
1268 | static void issue_start_status (struct eth_dev *dev) | 1187 | static void issue_start_status (struct eth_dev *dev) |
@@ -1279,6 +1198,8 @@ static void issue_start_status (struct eth_dev *dev) | |||
1279 | * a "cancel the whole queue" primitive since any | 1198 | * a "cancel the whole queue" primitive since any |
1280 | * unlink-one primitive has way too many error modes. | 1199 | * unlink-one primitive has way too many error modes. |
1281 | * here, we "know" toggle is already clear... | 1200 | * here, we "know" toggle is already clear... |
1201 | * | ||
1202 | * FIXME iff req->context != null just dequeue it | ||
1282 | */ | 1203 | */ |
1283 | usb_ep_disable (dev->status_ep); | 1204 | usb_ep_disable (dev->status_ep); |
1284 | usb_ep_enable (dev->status_ep, dev->status); | 1205 | usb_ep_enable (dev->status_ep, dev->status); |
@@ -1295,6 +1216,8 @@ static void issue_start_status (struct eth_dev *dev) | |||
1295 | 1216 | ||
1296 | req->length = sizeof *event; | 1217 | req->length = sizeof *event; |
1297 | req->complete = eth_status_complete; | 1218 | req->complete = eth_status_complete; |
1219 | req->context = dev; | ||
1220 | |||
1298 | value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC); | 1221 | value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC); |
1299 | if (value < 0) | 1222 | if (value < 0) |
1300 | DEBUG (dev, "status buf queue --> %d\n", value); | 1223 | DEBUG (dev, "status buf queue --> %d\n", value); |
@@ -1459,9 +1382,11 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) | |||
1459 | 1382 | ||
1460 | /* CDC requires the data transfers not be done from | 1383 | /* CDC requires the data transfers not be done from |
1461 | * the default interface setting ... also, setting | 1384 | * the default interface setting ... also, setting |
1462 | * the non-default interface clears filters etc. | 1385 | * the non-default interface resets filters etc. |
1463 | */ | 1386 | */ |
1464 | if (wValue == 1) { | 1387 | if (wValue == 1) { |
1388 | if (!cdc_active (dev)) | ||
1389 | break; | ||
1465 | usb_ep_enable (dev->in_ep, dev->in); | 1390 | usb_ep_enable (dev->in_ep, dev->in); |
1466 | usb_ep_enable (dev->out_ep, dev->out); | 1391 | usb_ep_enable (dev->out_ep, dev->out); |
1467 | dev->cdc_filter = DEFAULT_FILTER; | 1392 | dev->cdc_filter = DEFAULT_FILTER; |
@@ -1691,10 +1616,8 @@ rx_submit (struct eth_dev *dev, struct usb_request *req, int gfp_flags) | |||
1691 | */ | 1616 | */ |
1692 | size = (sizeof (struct ethhdr) + dev->net->mtu + RX_EXTRA); | 1617 | size = (sizeof (struct ethhdr) + dev->net->mtu + RX_EXTRA); |
1693 | size += dev->out_ep->maxpacket - 1; | 1618 | size += dev->out_ep->maxpacket - 1; |
1694 | #ifdef CONFIG_USB_ETH_RNDIS | 1619 | if (rndis_active(dev)) |
1695 | if (dev->rndis) | ||
1696 | size += sizeof (struct rndis_packet_msg_type); | 1620 | size += sizeof (struct rndis_packet_msg_type); |
1697 | #endif | ||
1698 | size -= size % dev->out_ep->maxpacket; | 1621 | size -= size % dev->out_ep->maxpacket; |
1699 | 1622 | ||
1700 | if ((skb = alloc_skb (size + NET_IP_ALIGN, gfp_flags)) == 0) { | 1623 | if ((skb = alloc_skb (size + NET_IP_ALIGN, gfp_flags)) == 0) { |
@@ -1862,8 +1785,6 @@ static void rx_fill (struct eth_dev *dev, int gfp_flags) | |||
1862 | struct usb_request *req; | 1785 | struct usb_request *req; |
1863 | unsigned long flags; | 1786 | unsigned long flags; |
1864 | 1787 | ||
1865 | clear_bit (WORK_RX_MEMORY, &dev->todo); | ||
1866 | |||
1867 | /* fill unused rxq slots with some skb */ | 1788 | /* fill unused rxq slots with some skb */ |
1868 | spin_lock_irqsave (&dev->lock, flags); | 1789 | spin_lock_irqsave (&dev->lock, flags); |
1869 | while (!list_empty (&dev->rx_reqs)) { | 1790 | while (!list_empty (&dev->rx_reqs)) { |
@@ -1886,11 +1807,9 @@ static void eth_work (void *_dev) | |||
1886 | { | 1807 | { |
1887 | struct eth_dev *dev = _dev; | 1808 | struct eth_dev *dev = _dev; |
1888 | 1809 | ||
1889 | if (test_bit (WORK_RX_MEMORY, &dev->todo)) { | 1810 | if (test_and_clear_bit (WORK_RX_MEMORY, &dev->todo)) { |
1890 | if (netif_running (dev->net)) | 1811 | if (netif_running (dev->net)) |
1891 | rx_fill (dev, GFP_KERNEL); | 1812 | rx_fill (dev, GFP_KERNEL); |
1892 | else | ||
1893 | clear_bit (WORK_RX_MEMORY, &dev->todo); | ||
1894 | } | 1813 | } |
1895 | 1814 | ||
1896 | if (dev->todo) | 1815 | if (dev->todo) |
@@ -2039,27 +1958,31 @@ drop: | |||
2039 | 1958 | ||
2040 | #ifdef CONFIG_USB_ETH_RNDIS | 1959 | #ifdef CONFIG_USB_ETH_RNDIS |
2041 | 1960 | ||
2042 | static void rndis_send_media_state (struct eth_dev *dev, int connect) | 1961 | /* The interrupt endpoint is used in RNDIS to notify the host when messages |
2043 | { | 1962 | * other than data packets are available ... notably the REMOTE_NDIS_*_CMPLT |
2044 | if (!dev) | 1963 | * messages, but also REMOTE_NDIS_INDICATE_STATUS_MSG and potentially even |
2045 | return; | 1964 | * REMOTE_NDIS_KEEPALIVE_MSG. |
2046 | 1965 | * | |
2047 | if (connect) { | 1966 | * The RNDIS control queue is processed by GET_ENCAPSULATED_RESPONSE, and |
2048 | if (rndis_signal_connect (dev->rndis_config)) | 1967 | * normally just one notification will be queued. |
2049 | return; | 1968 | */ |
2050 | } else { | 1969 | |
2051 | if (rndis_signal_disconnect (dev->rndis_config)) | 1970 | static struct usb_request *eth_req_alloc (struct usb_ep *, unsigned, unsigned); |
2052 | return; | 1971 | static void eth_req_free (struct usb_ep *ep, struct usb_request *req); |
2053 | } | ||
2054 | } | ||
2055 | 1972 | ||
2056 | static void | 1973 | static void |
2057 | rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req) | 1974 | rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *req) |
2058 | { | 1975 | { |
1976 | struct eth_dev *dev = ep->driver_data; | ||
1977 | |||
2059 | if (req->status || req->actual != req->length) | 1978 | if (req->status || req->actual != req->length) |
2060 | DEBUG ((struct eth_dev *) ep->driver_data, | 1979 | DEBUG (dev, |
2061 | "rndis control ack complete --> %d, %d/%d\n", | 1980 | "rndis control ack complete --> %d, %d/%d\n", |
2062 | req->status, req->actual, req->length); | 1981 | req->status, req->actual, req->length); |
1982 | req->context = NULL; | ||
1983 | |||
1984 | if (req != dev->stat_req) | ||
1985 | eth_req_free(ep, req); | ||
2063 | } | 1986 | } |
2064 | 1987 | ||
2065 | static int rndis_control_ack (struct net_device *net) | 1988 | static int rndis_control_ack (struct net_device *net) |
@@ -2074,11 +1997,19 @@ static int rndis_control_ack (struct net_device *net) | |||
2074 | return -ENODEV; | 1997 | return -ENODEV; |
2075 | } | 1998 | } |
2076 | 1999 | ||
2000 | /* in case queue length > 1 */ | ||
2001 | if (resp->context) { | ||
2002 | resp = eth_req_alloc (dev->status_ep, 8, GFP_ATOMIC); | ||
2003 | if (!resp) | ||
2004 | return -ENOMEM; | ||
2005 | } | ||
2006 | |||
2077 | /* Send RNDIS RESPONSE_AVAILABLE notification; | 2007 | /* Send RNDIS RESPONSE_AVAILABLE notification; |
2078 | * USB_CDC_NOTIFY_RESPONSE_AVAILABLE should work too | 2008 | * USB_CDC_NOTIFY_RESPONSE_AVAILABLE should work too |
2079 | */ | 2009 | */ |
2080 | resp->length = 8; | 2010 | resp->length = 8; |
2081 | resp->complete = rndis_control_ack_complete; | 2011 | resp->complete = rndis_control_ack_complete; |
2012 | resp->context = dev; | ||
2082 | 2013 | ||
2083 | *((__le32 *) resp->buf) = __constant_cpu_to_le32 (1); | 2014 | *((__le32 *) resp->buf) = __constant_cpu_to_le32 (1); |
2084 | *((__le32 *) resp->buf + 1) = __constant_cpu_to_le32 (0); | 2015 | *((__le32 *) resp->buf + 1) = __constant_cpu_to_le32 (0); |
@@ -2109,7 +2040,7 @@ static void eth_start (struct eth_dev *dev, int gfp_flags) | |||
2109 | rndis_set_param_medium (dev->rndis_config, | 2040 | rndis_set_param_medium (dev->rndis_config, |
2110 | NDIS_MEDIUM_802_3, | 2041 | NDIS_MEDIUM_802_3, |
2111 | BITRATE(dev->gadget)/100); | 2042 | BITRATE(dev->gadget)/100); |
2112 | rndis_send_media_state (dev, 1); | 2043 | (void) rndis_signal_connect (dev->rndis_config); |
2113 | } | 2044 | } |
2114 | #endif | 2045 | #endif |
2115 | } | 2046 | } |
@@ -2156,7 +2087,7 @@ static int eth_stop (struct net_device *net) | |||
2156 | if (dev->rndis) { | 2087 | if (dev->rndis) { |
2157 | rndis_set_param_medium (dev->rndis_config, | 2088 | rndis_set_param_medium (dev->rndis_config, |
2158 | NDIS_MEDIUM_802_3, 0); | 2089 | NDIS_MEDIUM_802_3, 0); |
2159 | rndis_send_media_state (dev, 0); | 2090 | (void) rndis_signal_disconnect (dev->rndis_config); |
2160 | } | 2091 | } |
2161 | #endif | 2092 | #endif |
2162 | 2093 | ||
@@ -2165,15 +2096,16 @@ static int eth_stop (struct net_device *net) | |||
2165 | 2096 | ||
2166 | /*-------------------------------------------------------------------------*/ | 2097 | /*-------------------------------------------------------------------------*/ |
2167 | 2098 | ||
2168 | static struct usb_request *eth_req_alloc (struct usb_ep *ep, unsigned size) | 2099 | static struct usb_request * |
2100 | eth_req_alloc (struct usb_ep *ep, unsigned size, unsigned gfp_flags) | ||
2169 | { | 2101 | { |
2170 | struct usb_request *req; | 2102 | struct usb_request *req; |
2171 | 2103 | ||
2172 | req = usb_ep_alloc_request (ep, GFP_KERNEL); | 2104 | req = usb_ep_alloc_request (ep, gfp_flags); |
2173 | if (!req) | 2105 | if (!req) |
2174 | return NULL; | 2106 | return NULL; |
2175 | 2107 | ||
2176 | req->buf = kmalloc (size, GFP_KERNEL); | 2108 | req->buf = kmalloc (size, gfp_flags); |
2177 | if (!req->buf) { | 2109 | if (!req->buf) { |
2178 | usb_ep_free_request (ep, req); | 2110 | usb_ep_free_request (ep, req); |
2179 | req = NULL; | 2111 | req = NULL; |
@@ -2371,13 +2303,11 @@ autoconf_fail: | |||
2371 | gadget->name); | 2303 | gadget->name); |
2372 | return -ENODEV; | 2304 | return -ENODEV; |
2373 | } | 2305 | } |
2374 | EP_IN_NAME = in_ep->name; | ||
2375 | in_ep->driver_data = in_ep; /* claim */ | 2306 | in_ep->driver_data = in_ep; /* claim */ |
2376 | 2307 | ||
2377 | out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc); | 2308 | out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc); |
2378 | if (!out_ep) | 2309 | if (!out_ep) |
2379 | goto autoconf_fail; | 2310 | goto autoconf_fail; |
2380 | EP_OUT_NAME = out_ep->name; | ||
2381 | out_ep->driver_data = out_ep; /* claim */ | 2311 | out_ep->driver_data = out_ep; /* claim */ |
2382 | 2312 | ||
2383 | #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) | 2313 | #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) |
@@ -2387,7 +2317,6 @@ autoconf_fail: | |||
2387 | if (cdc || rndis) { | 2317 | if (cdc || rndis) { |
2388 | status_ep = usb_ep_autoconfig (gadget, &fs_status_desc); | 2318 | status_ep = usb_ep_autoconfig (gadget, &fs_status_desc); |
2389 | if (status_ep) { | 2319 | if (status_ep) { |
2390 | EP_STATUS_NAME = status_ep->name; | ||
2391 | status_ep->driver_data = status_ep; /* claim */ | 2320 | status_ep->driver_data = status_ep; /* claim */ |
2392 | } else if (rndis) { | 2321 | } else if (rndis) { |
2393 | dev_err (&gadget->dev, | 2322 | dev_err (&gadget->dev, |
@@ -2429,7 +2358,7 @@ autoconf_fail: | |||
2429 | hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; | 2358 | hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress; |
2430 | hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; | 2359 | hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress; |
2431 | #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) | 2360 | #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) |
2432 | if (EP_STATUS_NAME) | 2361 | if (status_ep) |
2433 | hs_status_desc.bEndpointAddress = | 2362 | hs_status_desc.bEndpointAddress = |
2434 | fs_status_desc.bEndpointAddress; | 2363 | fs_status_desc.bEndpointAddress; |
2435 | #endif | 2364 | #endif |
@@ -2502,7 +2431,7 @@ autoconf_fail: | |||
2502 | SET_ETHTOOL_OPS(net, &ops); | 2431 | SET_ETHTOOL_OPS(net, &ops); |
2503 | 2432 | ||
2504 | /* preallocate control message data and buffer */ | 2433 | /* preallocate control message data and buffer */ |
2505 | dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ); | 2434 | dev->req = eth_req_alloc (gadget->ep0, USB_BUFSIZ, GFP_KERNEL); |
2506 | if (!dev->req) | 2435 | if (!dev->req) |
2507 | goto fail; | 2436 | goto fail; |
2508 | dev->req->complete = eth_setup_complete; | 2437 | dev->req->complete = eth_setup_complete; |
@@ -2510,11 +2439,12 @@ autoconf_fail: | |||
2510 | /* ... and maybe likewise for status transfer */ | 2439 | /* ... and maybe likewise for status transfer */ |
2511 | if (dev->status_ep) { | 2440 | if (dev->status_ep) { |
2512 | dev->stat_req = eth_req_alloc (dev->status_ep, | 2441 | dev->stat_req = eth_req_alloc (dev->status_ep, |
2513 | STATUS_BYTECOUNT); | 2442 | STATUS_BYTECOUNT, GFP_KERNEL); |
2514 | if (!dev->stat_req) { | 2443 | if (!dev->stat_req) { |
2515 | eth_req_free (gadget->ep0, dev->req); | 2444 | eth_req_free (gadget->ep0, dev->req); |
2516 | goto fail; | 2445 | goto fail; |
2517 | } | 2446 | } |
2447 | dev->stat_req->context = NULL; | ||
2518 | } | 2448 | } |
2519 | 2449 | ||
2520 | /* finish hookup to lower layer ... */ | 2450 | /* finish hookup to lower layer ... */ |
@@ -2529,16 +2459,16 @@ autoconf_fail: | |||
2529 | netif_stop_queue (dev->net); | 2459 | netif_stop_queue (dev->net); |
2530 | netif_carrier_off (dev->net); | 2460 | netif_carrier_off (dev->net); |
2531 | 2461 | ||
2532 | // SET_NETDEV_DEV (dev->net, &gadget->dev); | 2462 | SET_NETDEV_DEV (dev->net, &gadget->dev); |
2533 | status = register_netdev (dev->net); | 2463 | status = register_netdev (dev->net); |
2534 | if (status < 0) | 2464 | if (status < 0) |
2535 | goto fail1; | 2465 | goto fail1; |
2536 | 2466 | ||
2537 | INFO (dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); | 2467 | INFO (dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); |
2538 | INFO (dev, "using %s, OUT %s IN %s%s%s\n", gadget->name, | 2468 | INFO (dev, "using %s, OUT %s IN %s%s%s\n", gadget->name, |
2539 | EP_OUT_NAME, EP_IN_NAME, | 2469 | out_ep->name, in_ep->name, |
2540 | EP_STATUS_NAME ? " STATUS " : "", | 2470 | status_ep ? " STATUS " : "", |
2541 | EP_STATUS_NAME ? EP_STATUS_NAME : "" | 2471 | status_ep ? status_ep->name : "" |
2542 | ); | 2472 | ); |
2543 | INFO (dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n", | 2473 | INFO (dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n", |
2544 | net->dev_addr [0], net->dev_addr [1], | 2474 | net->dev_addr [0], net->dev_addr [1], |
@@ -2613,11 +2543,8 @@ eth_resume (struct usb_gadget *gadget) | |||
2613 | /*-------------------------------------------------------------------------*/ | 2543 | /*-------------------------------------------------------------------------*/ |
2614 | 2544 | ||
2615 | static struct usb_gadget_driver eth_driver = { | 2545 | static struct usb_gadget_driver eth_driver = { |
2616 | #ifdef CONFIG_USB_GADGET_DUALSPEED | 2546 | .speed = DEVSPEED, |
2617 | .speed = USB_SPEED_HIGH, | 2547 | |
2618 | #else | ||
2619 | .speed = USB_SPEED_FULL, | ||
2620 | #endif | ||
2621 | .function = (char *) driver_desc, | 2548 | .function = (char *) driver_desc, |
2622 | .bind = eth_bind, | 2549 | .bind = eth_bind, |
2623 | .unbind = eth_unbind, | 2550 | .unbind = eth_unbind, |