Re: uhub2: device problem, disabling port 2
On 22/11/13(Fri) 13:48, Stuart Henderson wrote: uhub2: port 2, set config at addr 3 failed uhub2: device problem, disabling port 2 When this happens, is there any way to get the port back without rebooting? Have you tried suspending/resuming the machine? Apart from that, the diff below is adapted from FreeBSD's r162977 and should fix most of the cases that generate such disabling port X error. Miod has recently bugged me about it, but as always I'm slacking... Can you give it a try and tell me if it improves your situation? I have a hard time finding the right machine/device combinaison to test it. Index: ehci.c === RCS file: /home/ncvs/src/sys/dev/usb/ehci.c,v retrieving revision 1.138 diff -u -p -r1.138 ehci.c --- ehci.c 9 Nov 2013 08:46:05 - 1.138 +++ ehci.c 25 Nov 2013 14:12:20 - @@ -3052,7 +3052,6 @@ ehci_device_request(struct usbd_xfer *xf usb_device_request_t *req = xfer-request; struct usbd_device *dev = epipe-pipe.device; struct ehci_softc *sc = (struct ehci_softc *)dev-bus; - int addr = dev-address; struct ehci_soft_qtd *setup, *stat, *next; struct ehci_soft_qh *sqh; int isread; @@ -3066,7 +3065,7 @@ ehci_device_request(struct usbd_xfer *xf DPRINTFN(3,(ehci_device_request: type=0x%02x, request=0x%02x, wValue=0x%04x, wIndex=0x%04x len=%u, addr=%d, endpt=%d\n, req-bmRequestType, req-bRequest, UGETW(req-wValue), - UGETW(req-wIndex), len, addr, + UGETW(req-wIndex), len, dev-address, epipe-pipe.endpoint-edesc-bEndpointAddress)); setup = ehci_alloc_sqtd(sc); @@ -3082,17 +3081,6 @@ ehci_device_request(struct usbd_xfer *xf sqh = epipe-sqh; epipe-u.ctl.length = len; - - /* Update device address and length since they may have changed - during the setup of the control pipe in usbd_new_device(). */ - /* XXX This only needs to be done once, but it's too early in open. */ - /* Should not touch ED here! */ - sqh-qh.qh_endp = - (sqh-qh.qh_endp htole32(~(EHCI_QH_ADDRMASK | EHCI_QH_MPLMASK))) | - htole32( -EHCI_QH_SET_ADDR(addr) | -EHCI_QH_SET_MPL(UGETW(epipe-pipe.endpoint-edesc-wMaxPacketSize)) - ); /* Set up data transaction */ if (len != 0) { Index: ohci.c === RCS file: /home/ncvs/src/sys/dev/usb/ohci.c,v retrieving revision 1.116 diff -u -p -r1.116 ohci.c --- ohci.c 9 Nov 2013 08:46:05 - 1.116 +++ ohci.c 25 Nov 2013 14:12:20 - @@ -1604,7 +1604,6 @@ ohci_device_request(struct usbd_xfer *xf usb_device_request_t *req = xfer-request; struct usbd_device *dev = opipe-pipe.device; struct ohci_softc *sc = (struct ohci_softc *)dev-bus; - int addr = dev-address; struct ohci_soft_td *setup, *stat, *next, *tail; struct ohci_soft_ed *sed; int isread; @@ -1618,7 +1617,7 @@ ohci_device_request(struct usbd_xfer *xf DPRINTFN(3,(ohci_device_control type=0x%02x, request=0x%02x, wValue=0x%04x, wIndex=0x%04x len=%u, addr=%d, endpt=%d\n, req-bmRequestType, req-bRequest, UGETW(req-wValue), - UGETW(req-wIndex), len, addr, + UGETW(req-wIndex), len, dev-address, opipe-pipe.endpoint-edesc-bEndpointAddress)); setup = opipe-tail.td; @@ -1636,15 +1635,6 @@ ohci_device_request(struct usbd_xfer *xf sed = opipe-sed; opipe-u.ctl.length = len; - - /* Update device address and length since they may have changed - during the setup of the control pipe in usbd_new_device(). */ - /* XXX This only needs to be done once, but it's too early in open. */ - /* Should not touch ED here! */ - sed-ed.ed_flags = htole32( -(letoh32(sed-ed.ed_flags) ~(OHCI_ED_ADDRMASK | OHCI_ED_MAXPMASK)) | -OHCI_ED_SET_FA(addr) | -OHCI_ED_SET_MAXP(UGETW(opipe-pipe.endpoint-edesc-wMaxPacketSize))); next = stat; Index: usb_subr.c === RCS file: /home/ncvs/src/sys/dev/usb/usb_subr.c,v retrieving revision 1.95 diff -u -p -r1.95 usb_subr.c --- usb_subr.c 19 Nov 2013 14:04:07 - 1.95 +++ usb_subr.c 25 Nov 2013 14:12:20 - @@ -1164,6 +1164,15 @@ usbd_new_device(struct device *parent, s USETW(dev-def_ep_desc.wMaxPacketSize, dd-bMaxPacketSize); + /* Re-establish the default pipe with the new max packet size. */ + usbd_abort_pipe(dev-default_pipe); + err = usbd_setup_pipe(dev, 0, dev-def_ep, USBD_DEFAULT_INTERVAL, + dev-default_pipe); + if (err) { + usb_free_device(dev, up); + return (err); + } + err =
Re: NSD 4
I've had one test report so far, has anyone else tested this? On 2013/11/22 21:04, Stuart Henderson wrote: I've got an update of NSD to v4.0, it's a fairly large diff so I've put it at http://junkpile.org/nsd4.diff (apply diff in /usr/src, it includes changes to etc/rc.d/nsd which must also be installed - to build NSD itself use make -f Makefile.bsd-wrapper obj make -f Makefile.bsd-wrapper sudo make -f Makefile.bsd-wrapper install.) I have not yet updated the sample config file (except as noted below, an old working config file will still be OK). Tested so far on powerpc and amd64, it would be particularly nice to have some reports from people using this on other arch, comments about the upgrade procedure would also be good. Update notes (also repeated in the diff file): cd /usr/sbin rm nsd-notify nsd-patch nsd-xfer nsd-zonec nsdc cd /usr/share/man/man8 rm nsd-notify.8 nsd-patch.8 nsd-xfer.8 nsd-zonec.8 nsdc.8 chown _nsd /var/nsd/db/nsd.db install -o _nsd -g _nsd -d 750 /var/nsd/run/xfr mv /etc/nsd.conf to /var/nsd/etc/nsd.conf - needed to support reloads while in chroot printf '\nremote-control:\n\tcontrol-enable: yes\n' /var/nsd/etc.nsd.conf $EDITOR /var/nsd/etc/nsd.conf - if you have include lines, edit them to specify the *full* path e.g. include /var/nsd/etc/nsd.local - nsd strips the chroot prefix as needed - remove any old cronjobs that run nsdc patch, this is no longer needed N.B. NSD now uses mmap() to access its database. From what I have read so far access is done just via the mmap rather than a mixture of that and write(), but I may have missed something, more eyes on this would be very welcome.
Re: NSD 4
On Mon, Nov 25, 2013 at 06:15:48PM +, Stuart Henderson wrote: I've had one test report so far, has anyone else tested this? Update notes (also repeated in the diff file): cd /usr/sbin rm nsd-notify nsd-patch nsd-xfer nsd-zonec nsdc cd /usr/share/man/man8 rm nsd-notify.8 nsd-patch.8 nsd-xfer.8 nsd-zonec.8 nsdc.8 chown _nsd /var/nsd/db/nsd.db install -o _nsd -g _nsd -d 750 /var/nsd/run/xfr mv /etc/nsd.conf to /var/nsd/etc/nsd.conf - needed to support reloads while in chroot printf '\nremote-control:\n\tcontrol-enable: yes\n' /var/nsd/etc.nsd.conf $EDITOR /var/nsd/etc/nsd.conf - if you have include lines, edit them to specify the *full* path e.g. include /var/nsd/etc/nsd.local - nsd strips the chroot prefix as needed - remove any old cronjobs that run nsdc patch, this is no longer needed N.B. NSD now uses mmap() to access its database. From what I have read so far access is done just via the mmap rather than a mixture of that and write(), but I may have missed something, more eyes on this would be very welcome. I have been testing this on sparc64 (though i notice now that i built a complete userland via make build instead of the specific make options above. Sorry if this messes with something.) Some things i ran into: There is a typo on the printf-line above: s,etc\.nsd.conf,etc/nsd.conf, And while nitpicking, maby the to in the mv line should be removed for easy copy-pasting. I needed to create a /var/nsd/etc directory (perms based on /var/named/etc/): # install -o root -g _nsd -d -m 750 /var/nsd/etc (Is it possible that the /var/nsd/run/xfr creation above misses a -m)? I also believe you need some wider permissions on the /var/nsd/db/ directory in order to use the nsd-control addzone/delzone stuff. I added a pattern to the config: --- pattern: name: slave zonefile: slave/%s.zone --- ... and played around with: # nsd-control addzone example.com slave # nsd-control delzone example.com ... which caused errors like the following: Nov 25 18:49:58 crash nsd[21185]: could not create zone list /db/zone.list: Permission denied Nov 25 18:49:58 crash nsd[21185]: zone example.com could not be added Nov 25 18:52:10 crash nsd[21185]: could not open /db/zone.list~: Permission denied Nov 25 18:57:12 crash nsd[21185]: could not open /db/zone.list~: Permission denied I solved this personally with: # chown _nsd:wheel /var/nsd/db/ Wanting to write out the dynamically added zone also needs permissions (in my example config) for zones/slave/: # nsd-control write Nov 25 19:55:40 crash nsd[19519]: cannot write zone example.com file slave/example.com.zone~: Permission denied I solved that with (again based on my personal config): # chown _nsd /var/nsd/zones/slave I have not tested this a lot, but at least dig @127.0.0.1 works for the example.com zone. Just thought I should throw this info out there, I think it is great you are doing the work to get NSD 4 in base. Thanks a lot :). Regards, Patrik Lundin
[PATCH] SLIST mergesort implementation
This is an implementation of the merge sort algorithm for SLIST in queue(3). Merge sort is a stable algorithm that provides us a worst case run time of O(n lg n) and uses at most O(n) of stack (where 'n' is the current number of elements in the list). The patch attached to this mail provides the following macros: SLIST_MERGESORT_PROTOTYPE(name, type, field) SLIST_MERGESORT_PROTOTYPE_STATIC(name, type, field) These macros generates the merge sort functions prototypes, where: - 'name' is the prefix prepended to the function name; - 'type' is the struct type that we are using; - 'field' is the data structure pointer to the next entry; SLIST_MERGESORT_GENERATE(name, type, field, cmp) SLIST_MERGESORT_GENERATE_STATIC(name, type, field, cmp) These macros generates the merge sort functions, where: - 'name' prefix prepended to the function name; - 'type' struct type that we are using; - 'field' data structure pointer to the next entry; - 'cmp' the compare function that determines where to move the items (' 0' means move left, ' 0' means move right and '0' items are equal); NOTE: the compare function MUST return an signed variable, it doesn't matter what type it is, it is recommended to return an integer (int). The parameters must be 'struct type *' or 'void *'. SLIST_MERGESORT(name, head) This macro calls the mergesort function with name prefix 'name' and returns a pointer to the list head (struct type *), if the list is empty NULL is returned instead. - 'name' prefix prepended to the functions name; - 'head' is a pointer to the list head created by SLIST_HEAD(); It is possible to generate multiple sort functions using the 'name' parameter illustrated by 'NHEAD' in the sample in this mail. Usage example: SAMPLE START #include sys/queue.h #include err.h #include stdio.h #include stdlib.h struct number { int n_number; SLIST_ENTRY(number) n_entry; }; static SLIST_HEAD(NHEAD, number) nhead = SLIST_HEAD_INITIALIZER(nhead); static int number_cmp(struct number *n, struct number *nn) { if (n-n_number nn-n_number) return (1); else if (n-n_number nn-n_number) return (-1); return (0); } SLIST_MERGESORT_PROTOTYPE_STATIC(NHEAD, number, n_entry) SLIST_MERGESORT_GENERATE_STATIC(NHEAD, number, n_entry, number_cmp) int main(int argc, char *argv[]) { struct number *n; int i; for (i = 1; i 500; i++) { n = calloc(1, sizeof(*n)); if (n == NULL) err(1, calloc); n-n_number = i; SLIST_INSERT_HEAD(nhead, n, n_entry); } printf(List:\n); SLIST_FOREACH(n, nhead, n_entry) printf( %d, n-n_number); printf(\n); SLIST_MERGESORT(NHEAD, nhead); printf(List sorted:\n); SLIST_FOREACH(n, nhead, n_entry) printf( %d, n-n_number); printf(\n); exit(EXIT_SUCCESS); } SAMPLE END Index: queue.h === RCS file: /cvs/src/sys/sys/queue.h,v retrieving revision 1.38 diff -u -p -r1.38 queue.h --- queue.h 3 Jul 2013 15:05:21 - 1.38 +++ queue.h 26 Nov 2013 01:16:44 - @@ -161,6 +161,57 @@ struct { \ } \ } while (0) + +#define SLIST_MERGESORT_PROTOTYPE(name, type, field) \ + SLIST_MERGESORT_PROTOTYPE_INTERNAL(name, type, field,) +#define SLIST_MERGESORT_PROTOTYPE_STATIC(name, type, field)\ + SLIST_MERGESORT_PROTOTYPE_INTERNAL(name, type, field, __attribute__((__unused__)) static) +#define SLIST_MERGESORT_PROTOTYPE_INTERNAL(name, type, field, attr)\ + attr struct type *name##_MERGE(struct type *, struct type *); \ + attr struct type *name##_MERGESORT(struct type *); + +#define SLIST_MERGESORT_GENERATE(name, type, field, cmp) \ + SLIST_MERGESORT_GENERATE_INTERNAL(name, type, field, cmp,) +#define SLIST_MERGESORT_GENERATE_STATIC(name, type, field, cmp) \ + SLIST_MERGESORT_GENERATE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) +#define SLIST_MERGESORT_GENERATE_INTERNAL(name, type, field, cmp, attr) \ + attr struct type * \ + name##_MERGE(struct type *s, struct type *e) { \ + struct type head; \ + struct type *a = head; \ + while ((s != NULL) (e != NULL)) {\ + if ((cmp)(s, e) 0) { \ + a-field.sle_next = s; \ + a = s; \ +
Re: [PATCH] SLIST mergesort implementation
This is an implementation of the merge sort algorithm for SLIST in queue(3). Sorting is something you do in an algorithm when you need it, specific to that algorithm, exactly where you need it. queue.h is supposed to be a minimal API, general access so that the specifics remain in the code using it. It is supposed to be approachable, not heavy with cross-purposes. I see you did not document it, nor show a specific case where it is absolutely neccessary. That says a lot.