Changeset ae3a941 in mainline for uspace/drv/bus/usb/usbhub
- Timestamp:
- 2018-02-26T16:51:40Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e773f58
- Parents:
- 3692678
- Location:
- uspace/drv/bus/usb/usbhub
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhub/port.c
r3692678 rae3a941 49 49 #include "status.h" 50 50 51 #define port_log(lvl, port, fmt, ...) do { usb_log_##lvl("(%p-%u): " fmt, (port->hub), (port->port_number), ##__VA_ARGS__); } while (0) 51 #define port_log(lvl, port, fmt, ...) do { \ 52 usb_log_##lvl("(%p-%u): " fmt, \ 53 (port->hub), (port->port_number), ##__VA_ARGS__); \ 54 } while (0) 52 55 53 56 /** Initialize hub port information. … … 55 58 * @param port Port to be initialized. 56 59 */ 57 void usb_hub_port_init(usb_hub_port_t *port, usb_hub_dev_t *hub, unsigned int port_number) 60 void usb_hub_port_init(usb_hub_port_t *port, usb_hub_dev_t *hub, 61 unsigned int port_number) 58 62 { 59 63 assert(port); … … 79 83 async_exch_t *exch = usb_device_bus_exchange_begin(port->hub->usb_device); 80 84 if (!exch) { 81 port_log(error, port, "Cannot remove the device, failed creating exchange."); 85 port_log(error, port, "Cannot remove the device, " 86 "failed creating exchange."); 82 87 return; 83 88 } … … 85 90 const errno_t err = usbhc_device_remove(exch, port->port_number); 86 91 if (err) 87 port_log(error, port, "Failed to remove device: %s", str_error(err)); 92 port_log(error, port, "Failed to remove device: %s", 93 str_error(err)); 88 94 89 95 usb_device_bus_exchange_end(exch); … … 109 115 err = usb_hub_reserve_default_address(port->hub, exch, &port->base); 110 116 if (err != EOK) { 111 port_log(error, port, "Failed to reserve default address: %s", str_error(err)); 117 port_log(error, port, "Failed to reserve default address: %s", 118 str_error(err)); 112 119 return err; 113 120 } … … 118 125 119 126 port_log(debug, port, "Resetting port."); 120 if ((err = usb_hub_set_port_feature(port->hub, port->port_number, USB_HUB_FEATURE_PORT_RESET))) { 121 port_log(warning, port, "Port reset request failed: %s", str_error(err)); 127 if ((err = usb_hub_set_port_feature(port->hub, port->port_number, 128 USB_HUB_FEATURE_PORT_RESET))) { 129 port_log(warning, port, "Port reset request failed: %s", 130 str_error(err)); 122 131 goto out_address; 123 132 } 124 133 125 134 if ((err = usb_port_wait_for_enabled(&port->base))) { 126 port_log(error, port, "Failed to reset port: %s", str_error(err)); 135 port_log(error, port, "Failed to reset port: %s", 136 str_error(err)); 127 137 goto out_address; 128 138 } 129 139 130 140 port_log(debug, port, "Enumerating device."); 131 if ((err = usbhc_device_enumerate(exch, port->port_number, port->speed))) { 132 port_log(error, port, "Failed to enumerate device: %s", str_error(err)); 141 if ((err = usbhc_device_enumerate(exch, port->port_number, 142 port->speed))) { 143 port_log(error, port, "Failed to enumerate device: %s", 144 str_error(err)); 133 145 /* Disable the port */ 134 usb_hub_clear_port_feature(port->hub, port->port_number, USB2_HUB_FEATURE_PORT_ENABLE); 146 usb_hub_clear_port_feature(port->hub, port->port_number, 147 USB2_HUB_FEATURE_PORT_ENABLE); 135 148 goto out_address; 136 149 } … … 151 164 152 165 port_log(debug, port, "Issuing a warm reset."); 153 if ((err = usb_hub_set_port_feature(port->hub, port->port_number, USB3_HUB_FEATURE_BH_PORT_RESET))) { 154 port_log(warning, port, "Port reset request failed: %s", str_error(err)); 166 if ((err = usb_hub_set_port_feature(port->hub, port->port_number, 167 USB3_HUB_FEATURE_BH_PORT_RESET))) { 168 port_log(warning, port, "Port reset request failed: %s", 169 str_error(err)); 155 170 return err; 156 171 } 157 172 158 173 if ((err = usb_port_wait_for_enabled(&port->base))) { 159 port_log(error, port, "Failed to reset port: %s", str_error(err)); 174 port_log(error, port, "Failed to reset port: %s", 175 str_error(err)); 160 176 return err; 161 177 } 162 178 163 179 port_log(debug, port, "Enumerating device."); 164 if ((err = usbhc_device_enumerate(exch, port->port_number, port->speed))) { 165 port_log(error, port, "Failed to enumerate device: %s", str_error(err)); 180 if ((err = usbhc_device_enumerate(exch, port->port_number, 181 port->speed))) { 182 port_log(error, port, "Failed to enumerate device: %s", 183 str_error(err)); 166 184 return err; 167 185 } … … 193 211 { 194 212 const bool connected = !!(status & USB_HUB_PORT_STATUS_CONNECTION); 195 port_log(debug, port, "Connection change: device %s.", connected ? "attached" : "removed"); 213 port_log(debug, port, "Connection change: device %s.", connected 214 ? "attached" : "removed"); 196 215 197 216 if (connected) { … … 212 231 } 213 232 214 static void port_changed_overcurrent(usb_hub_port_t *port, usb_port_status_t status) 233 static void port_changed_overcurrent(usb_hub_port_t *port, 234 usb_port_status_t status) 215 235 { 216 236 const bool overcurrent = !!(status & USB_HUB_PORT_STATUS_OC); … … 225 245 226 246 if (!overcurrent) { 227 const errno_t err = usb_hub_set_port_feature(port->hub, port->port_number, USB_HUB_FEATURE_PORT_POWER); 247 const errno_t err = usb_hub_set_port_feature(port->hub, 248 port->port_number, USB_HUB_FEATURE_PORT_POWER); 228 249 if (err) 229 port_log(error, port, "Failed to set port power after OC: %s.", str_error(err)); 250 port_log(error, port, "Failed to set port power " 251 "after OC: %s.", str_error(err)); 230 252 } 231 253 } … … 245 267 246 268 static void check_port_change(usb_hub_port_t *port, usb_port_status_t *status, 247 change_handler_t handler, usb_port_status_t mask, usb_hub_class_feature_t feature) 269 change_handler_t handler, usb_port_status_t mask, 270 usb_hub_class_feature_t feature) 248 271 { 249 272 if ((*status & mask) == 0) … … 273 296 274 297 usb_port_status_t status = 0; 275 const errno_t err = usb_hub_get_port_status(port->hub, port->port_number, &status); 298 const errno_t err = usb_hub_get_port_status(port->hub, 299 port->port_number, &status); 276 300 if (err != EOK) { 277 port_log(error, port, "Failed to get port status: %s.", str_error(err)); 301 port_log(error, port, "Failed to get port status: %s.", 302 str_error(err)); 278 303 return; 279 304 } 280 305 281 306 check_port_change(port, &status, &port_changed_connection, 282 USB_HUB_PORT_STATUS_C_CONNECTION, USB_HUB_FEATURE_C_PORT_CONNECTION); 307 USB_HUB_PORT_STATUS_C_CONNECTION, 308 USB_HUB_FEATURE_C_PORT_CONNECTION); 283 309 284 310 check_port_change(port, &status, &port_changed_overcurrent, … … 290 316 if (port->hub->speed <= USB_SPEED_HIGH) { 291 317 check_port_change(port, &status, &port_changed_enabled, 292 USB2_HUB_PORT_STATUS_C_ENABLE, USB2_HUB_FEATURE_C_PORT_ENABLE); 318 USB2_HUB_PORT_STATUS_C_ENABLE, 319 USB2_HUB_FEATURE_C_PORT_ENABLE); 293 320 } else { 294 321 check_port_change(port, &status, &port_changed_reset, 295 USB3_HUB_PORT_STATUS_C_BH_RESET, USB3_HUB_FEATURE_C_BH_PORT_RESET); 322 USB3_HUB_PORT_STATUS_C_BH_RESET, 323 USB3_HUB_FEATURE_C_BH_PORT_RESET); 296 324 297 325 check_port_change(port, &status, NULL, 298 USB3_HUB_PORT_STATUS_C_LINK_STATE, USB3_HUB_FEATURE_C_PORT_LINK_STATE); 326 USB3_HUB_PORT_STATUS_C_LINK_STATE, 327 USB3_HUB_FEATURE_C_PORT_LINK_STATE); 299 328 } 300 329 301 330 /* Check for changes we ignored */ 302 331 if (status & 0xffff0000) { 303 port_log(debug, port, "Port status change igored. Status: %#08" PRIx32, status); 332 port_log(debug, port, "Port status change igored. " 333 "Status: %#08" PRIx32, status); 304 334 } 305 335 } -
uspace/drv/bus/usb/usbhub/status.h
r3692678 rae3a941 59 59 if (hub_speed == USB_SPEED_SUPER) 60 60 return USB_SPEED_SUPER; 61 if (hub_speed == USB_SPEED_HIGH && (status & USB2_HUB_PORT_STATUS_HIGH_SPEED)) 61 if (hub_speed == USB_SPEED_HIGH 62 && (status & USB2_HUB_PORT_STATUS_HIGH_SPEED)) 62 63 return USB_SPEED_HIGH; 63 64 if ((status & USB2_HUB_PORT_STATUS_LOW_SPEED) != 0) -
uspace/drv/bus/usb/usbhub/usbhub.h
r3692678 rae3a941 84 84 85 85 errno_t usb_hub_set_depth(const usb_hub_dev_t *); 86 errno_t usb_hub_get_port_status(const usb_hub_dev_t *, size_t, usb_port_status_t *); 87 errno_t usb_hub_set_port_feature(const usb_hub_dev_t *, size_t, usb_hub_class_feature_t); 88 errno_t usb_hub_clear_port_feature(const usb_hub_dev_t *, size_t, usb_hub_class_feature_t); 86 errno_t usb_hub_get_port_status(const usb_hub_dev_t *, size_t, 87 usb_port_status_t *); 88 errno_t usb_hub_set_port_feature(const usb_hub_dev_t *, size_t, 89 usb_hub_class_feature_t); 90 errno_t usb_hub_clear_port_feature(const usb_hub_dev_t *, size_t, 91 usb_hub_class_feature_t); 89 92 90 93 bool hub_port_changes_callback(usb_device_t *, uint8_t *, size_t, void *); 91 94 92 errno_t usb_hub_reserve_default_address(usb_hub_dev_t *, async_exch_t *, usb_port_t *); 95 errno_t usb_hub_reserve_default_address(usb_hub_dev_t *, async_exch_t *, 96 usb_port_t *); 93 97 errno_t usb_hub_release_default_address(usb_hub_dev_t *, async_exch_t *); 94 98
Note:
See TracChangeset
for help on using the changeset viewer.
