| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if_url.c,v 1.70 2019/08/23 04:32:57 mrg Exp $ */ | | 1 | /* $NetBSD: if_url.c,v 1.71 2019/08/30 05:59:17 mrg Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2001, 2002 | | 4 | * Copyright (c) 2001, 2002 |
5 | * Shingo WATANABE <nabe@nabechan.org>. All rights reserved. | | 5 | * Shingo WATANABE <nabe@nabechan.org>. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -34,27 +34,27 @@ | | | @@ -34,27 +34,27 @@ |
34 | * The RTL8150L(Realtek USB to fast ethernet controller) spec can be found at | | 34 | * The RTL8150L(Realtek USB to fast ethernet controller) spec can be found at |
35 | * ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/8150v14.pdf | | 35 | * ftp://ftp.realtek.com.tw/lancard/data_sheet/8150/8150v14.pdf |
36 | * ftp://152.104.125.40/lancard/data_sheet/8150/8150v14.pdf | | 36 | * ftp://152.104.125.40/lancard/data_sheet/8150/8150v14.pdf |
37 | */ | | 37 | */ |
38 | | | 38 | |
39 | /* | | 39 | /* |
40 | * TODO: | | 40 | * TODO: |
41 | * Interrupt Endpoint support | | 41 | * Interrupt Endpoint support |
42 | * External PHYs | | 42 | * External PHYs |
43 | * powerhook() support? | | 43 | * powerhook() support? |
44 | */ | | 44 | */ |
45 | | | 45 | |
46 | #include <sys/cdefs.h> | | 46 | #include <sys/cdefs.h> |
47 | __KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.70 2019/08/23 04:32:57 mrg Exp $"); | | 47 | __KERNEL_RCSID(0, "$NetBSD: if_url.c,v 1.71 2019/08/30 05:59:17 mrg Exp $"); |
48 | | | 48 | |
49 | #ifdef _KERNEL_OPT | | 49 | #ifdef _KERNEL_OPT |
50 | #include "opt_inet.h" | | 50 | #include "opt_inet.h" |
51 | #include "opt_usb.h" | | 51 | #include "opt_usb.h" |
52 | #endif | | 52 | #endif |
53 | | | 53 | |
54 | #include <sys/param.h> | | 54 | #include <sys/param.h> |
55 | | | 55 | |
56 | #include <net/if_ether.h> | | 56 | #include <net/if_ether.h> |
57 | #ifdef INET | | 57 | #ifdef INET |
58 | #include <netinet/in.h> | | 58 | #include <netinet/in.h> |
59 | #include <netinet/if_inarp.h> | | 59 | #include <netinet/if_inarp.h> |
60 | #endif | | 60 | #endif |
| @@ -180,75 +180,75 @@ url_attach(device_t parent, device_t sel | | | @@ -180,75 +180,75 @@ url_attach(device_t parent, device_t sel |
180 | un->un_ops = &url_ops; | | 180 | un->un_ops = &url_ops; |
181 | un->un_rx_xfer_flags = USBD_SHORT_XFER_OK; | | 181 | un->un_rx_xfer_flags = USBD_SHORT_XFER_OK; |
182 | un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER; | | 182 | un->un_tx_xfer_flags = USBD_FORCE_SHORT_XFER; |
183 | un->un_rx_list_cnt = URL_RX_LIST_CNT; | | 183 | un->un_rx_list_cnt = URL_RX_LIST_CNT; |
184 | un->un_tx_list_cnt = URL_TX_LIST_CNT; | | 184 | un->un_tx_list_cnt = URL_TX_LIST_CNT; |
185 | un->un_rx_bufsz = URL_BUFSZ; | | 185 | un->un_rx_bufsz = URL_BUFSZ; |
186 | un->un_tx_bufsz = URL_BUFSZ; | | 186 | un->un_tx_bufsz = URL_BUFSZ; |
187 | | | 187 | |
188 | /* Move the device into the configured state. */ | | 188 | /* Move the device into the configured state. */ |
189 | err = usbd_set_config_no(dev, URL_CONFIG_NO, 1); | | 189 | err = usbd_set_config_no(dev, URL_CONFIG_NO, 1); |
190 | if (err) { | | 190 | if (err) { |
191 | aprint_error_dev(self, "failed to set configuration" | | 191 | aprint_error_dev(self, "failed to set configuration" |
192 | ", err=%s\n", usbd_errstr(err)); | | 192 | ", err=%s\n", usbd_errstr(err)); |
193 | goto bad; | | 193 | return; |
194 | } | | 194 | } |
195 | | | 195 | |
196 | /* get control interface */ | | 196 | /* get control interface */ |
197 | err = usbd_device2interface_handle(dev, URL_IFACE_INDEX, &iface); | | 197 | err = usbd_device2interface_handle(dev, URL_IFACE_INDEX, &iface); |
198 | if (err) { | | 198 | if (err) { |
199 | aprint_error_dev(self, "failed to get interface, err=%s\n", | | 199 | aprint_error_dev(self, "failed to get interface, err=%s\n", |
200 | usbd_errstr(err)); | | 200 | usbd_errstr(err)); |
201 | goto bad; | | 201 | return; |
202 | } | | 202 | } |
203 | | | 203 | |
204 | un->un_iface = iface; | | 204 | un->un_iface = iface; |
205 | un->un_flags = url_lookup(uaa->uaa_vendor, uaa->uaa_product)->url_flags; | | 205 | un->un_flags = url_lookup(uaa->uaa_vendor, uaa->uaa_product)->url_flags; |
206 | #if 0 | | 206 | #if 0 |
207 | if (un->un_flags & URL_EXT_PHY) { | | 207 | if (un->un_flags & URL_EXT_PHY) { |
208 | un->un_read_reg_cb = url_ext_mii_read_reg; | | 208 | un->un_read_reg_cb = url_ext_mii_read_reg; |
209 | un->un_write_reg_cb = url_ext_mii_write_reg; | | 209 | un->un_write_reg_cb = url_ext_mii_write_reg; |
210 | } | | 210 | } |
211 | #endif | | 211 | #endif |
212 | | | 212 | |
213 | /* get interface descriptor */ | | 213 | /* get interface descriptor */ |
214 | id = usbd_get_interface_descriptor(un->un_iface); | | 214 | id = usbd_get_interface_descriptor(un->un_iface); |
215 | | | 215 | |
216 | /* find endpoints */ | | 216 | /* find endpoints */ |
217 | un->un_ed[USBNET_ENDPT_RX] = un->un_ed[USBNET_ENDPT_TX] = | | 217 | un->un_ed[USBNET_ENDPT_RX] = un->un_ed[USBNET_ENDPT_TX] = |
218 | un->un_ed[USBNET_ENDPT_INTR] = 0; | | 218 | un->un_ed[USBNET_ENDPT_INTR] = 0; |
219 | for (i = 0; i < id->bNumEndpoints; i++) { | | 219 | for (i = 0; i < id->bNumEndpoints; i++) { |
220 | ed = usbd_interface2endpoint_descriptor(un->un_iface, i); | | 220 | ed = usbd_interface2endpoint_descriptor(un->un_iface, i); |
221 | if (ed == NULL) { | | 221 | if (ed == NULL) { |
222 | aprint_error_dev(self, | | 222 | aprint_error_dev(self, |
223 | "couldn't get endpoint %d\n", i); | | 223 | "couldn't get endpoint %d\n", i); |
224 | goto bad; | | 224 | return; |
225 | } | | 225 | } |
226 | if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK && | | 226 | if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK && |
227 | UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN) | | 227 | UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN) |
228 | un->un_ed[USBNET_ENDPT_RX] = ed->bEndpointAddress; | | 228 | un->un_ed[USBNET_ENDPT_RX] = ed->bEndpointAddress; |
229 | else if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK && | | 229 | else if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK && |
230 | UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT) | | 230 | UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT) |
231 | un->un_ed[USBNET_ENDPT_TX] = ed->bEndpointAddress; | | 231 | un->un_ed[USBNET_ENDPT_TX] = ed->bEndpointAddress; |
232 | else if ((ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT && | | 232 | else if ((ed->bmAttributes & UE_XFERTYPE) == UE_INTERRUPT && |
233 | UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN) | | 233 | UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN) |
234 | un->un_ed[USBNET_ENDPT_INTR] = ed->bEndpointAddress; | | 234 | un->un_ed[USBNET_ENDPT_INTR] = ed->bEndpointAddress; |
235 | } | | 235 | } |
236 | | | 236 | |
237 | if (un->un_ed[USBNET_ENDPT_RX] == 0 || | | 237 | if (un->un_ed[USBNET_ENDPT_RX] == 0 || |
238 | un->un_ed[USBNET_ENDPT_TX] == 0 || | | 238 | un->un_ed[USBNET_ENDPT_TX] == 0 || |
239 | un->un_ed[USBNET_ENDPT_INTR] == 0) { | | 239 | un->un_ed[USBNET_ENDPT_INTR] == 0) { |
240 | aprint_error_dev(self, "missing endpoint\n"); | | 240 | aprint_error_dev(self, "missing endpoint\n"); |
241 | goto bad; | | 241 | return; |
242 | } | | 242 | } |
243 | | | 243 | |
244 | /* Set these up now for url_mem(). */ | | 244 | /* Set these up now for url_mem(). */ |
245 | usbnet_attach(un, "urldet"); | | 245 | usbnet_attach(un, "urldet"); |
246 | | | 246 | |
247 | /* reset the adapter */ | | 247 | /* reset the adapter */ |
248 | usbnet_lock(un); | | 248 | usbnet_lock(un); |
249 | url_reset(un); | | 249 | url_reset(un); |
250 | usbnet_unlock(un); | | 250 | usbnet_unlock(un); |
251 | | | 251 | |
252 | /* Get Ethernet Address */ | | 252 | /* Get Ethernet Address */ |
253 | usbnet_lock_mii(un); | | 253 | usbnet_lock_mii(un); |
254 | err = url_mem(un, URL_CMD_READMEM, URL_IDR0, (void *)un->un_eaddr, | | 254 | err = url_mem(un, URL_CMD_READMEM, URL_IDR0, (void *)un->un_eaddr, |