diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000000..d3452fd3cef --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.c diff=cpp +*.h diff=cpp +*.cpp diff=cpp +*.hpp diff=cpp +*.py diff=python diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..26a1bb9d193 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +_.tinderbox.* +_.amd64.* +_.arm.* +_.arm64.* +_.i386.* +_.ia64.* +_.mips.* +_.pc98.* +_.powerpc.* +_.riscv.* +_.sparc64.* +_.sun4v.* +GPATH +GRTAGS +GTAGS +ID +cscope.out +?cscope.out diff --git a/UPDATING b/UPDATING index 3a0ade37586..799a1755e47 100644 --- a/UPDATING +++ b/UPDATING @@ -821,7 +821,7 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 12.x IS SLOW: 20150623: An additional fix for the issue described in the 20150614 sendmail - entry below has been been committed in revision 284717. + entry below has been committed in revision 284717. 20150616: FreeBSD's old make (fmake) has been removed from the system. It is @@ -829,7 +829,7 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 12.x IS SLOW: 20150615: The fix for the issue described in the 20150614 sendmail entry - below has been been committed in revision 284436. The work + below has been committed in revision 284436. The work around described in that entry is no longer needed unless the default setting is overridden by a confDH_PARAMETERS configuration setting of '5' or pointing to a 512 bit DH parameter file. diff --git a/bin/pax/buf_subs.c b/bin/pax/buf_subs.c index c9a46640799..153b599193d 100644 --- a/bin/pax/buf_subs.c +++ b/bin/pax/buf_subs.c @@ -485,7 +485,7 @@ wr_rdbuf(char *out, int outcnt) int cnt; /* - * while there is data to copy copy into the write buffer. when the + * while there is data to copy into the write buffer. when the * write buffer fills, flush it to the archive and continue */ while (outcnt > 0) { diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 7898693c968..6adc3ac6426 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -43,7 +43,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include /* For WIFSIGNALED(status) */ #include /* @@ -840,7 +839,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) struct parsefile *savetopfile; volatile int e; char *lastarg; - int realstatus; + int signaled; int do_clearcmdentry; const char *path = pathval(); int i; @@ -1163,9 +1162,9 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) parent: /* parent process gets here (if we forked) */ if (mode == FORK_FG) { /* argument to fork */ INTOFF; - exitstatus = waitforjob(jp, &realstatus); + exitstatus = waitforjob(jp, &signaled); INTON; - if (iflag && loopnest > 0 && WIFSIGNALED(realstatus)) { + if (iflag && loopnest > 0 && signaled) { evalskip = SKIPBREAK; skipcount = loopnest; } diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index e2434493417..d5293a08158 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -1016,7 +1016,7 @@ vforkexecshell(struct job *jp, char **argv, char **envp, const char *path, int i */ int -waitforjob(struct job *jp, int *origstatus) +waitforjob(struct job *jp, int *signaled) { #if JOBS int propagate_int = jp->jobctl && jp->foreground; @@ -1039,8 +1039,8 @@ waitforjob(struct job *jp, int *origstatus) setcurjob(jp); #endif status = jp->ps[jp->nprocs - 1].status; - if (origstatus != NULL) - *origstatus = status; + if (signaled != NULL) + *signaled = WIFSIGNALED(status); /* convert to 8 bits */ if (WIFEXITED(status)) st = WEXITSTATUS(status); diff --git a/bin/sh/tests/builtins/var-assign.0 b/bin/sh/tests/builtins/var-assign.0 index ace39c042d5..efeb4bd130a 100644 --- a/bin/sh/tests/builtins/var-assign.0 +++ b/bin/sh/tests/builtins/var-assign.0 @@ -47,7 +47,7 @@ do ${SH} -c "VAR=1; VAR=0 ${cmd}; exit \${VAR}" >/dev/null 2>&1 done -# For other built-ins and utilites they do not. +# For other built-ins and utilities they do not. set -- ${UTILS} for cmd in "$@" do diff --git a/contrib/elftoolchain/readelf/readelf.c b/contrib/elftoolchain/readelf/readelf.c index 46fe8025bc7..0c9e8b0a7c7 100644 --- a/contrib/elftoolchain/readelf/readelf.c +++ b/contrib/elftoolchain/readelf/readelf.c @@ -2753,6 +2753,7 @@ dump_dyn_val(struct readelf *re, GElf_Dyn *dyn, uint32_t stab) case DT_SYMENT: case DT_RELSZ: case DT_RELENT: + case DT_PREINIT_ARRAYSZ: case DT_INIT_ARRAYSZ: case DT_FINI_ARRAYSZ: case DT_GNU_CONFLICTSZ: diff --git a/etc/devd/hyperv.conf b/etc/devd/hyperv.conf index 10a4e2b9e5c..e90aea3e23b 100644 --- a/etc/devd/hyperv.conf +++ b/etc/devd/hyperv.conf @@ -39,39 +39,39 @@ notify 11 { # # How network VF works with hn(4) on Hyper-V in non-transparent mode: # -# - Each network VF has a cooresponding hn(4). -# - The network VF and the it's cooresponding hn(4) have the same hardware +# - Each network VF has a corresponding hn(4). +# - The network VF and the it's corresponding hn(4) have the same hardware # address. # - Once the network VF is up, e.g. ifconfig VF up: # o All of the transmission should go through the network VF. # o Most of the reception goes through the network VF. -# o Small amount of reception may go through the cooresponding hn(4). -# This reception will happen, even if the the cooresponding hn(4) is -# down. The cooresponding hn(4) will change the reception interface +# o Small amount of reception may go through the corresponding hn(4). +# This reception will happen, even if the corresponding hn(4) is +# down. The corresponding hn(4) will change the reception interface # to the network VF, so that network layer and application layer will # be tricked into thinking that these packets were received by the # network VF. -# o The cooresponding hn(4) pretends the physical link is down. +# o The corresponding hn(4) pretends the physical link is down. # - Once the network VF is down or detached: -# o All of the transmission should go through the cooresponding hn(4). -# o All of the reception goes through the cooresponding hn(4). -# o The cooresponding hn(4) fallbacks to the original physical link +# o All of the transmission should go through the corresponding hn(4). +# o All of the reception goes through the corresponding hn(4). +# o The corresponding hn(4) fallbacks to the original physical link # detection logic. # # All these features are mainly used to help live migration, during which # the network VF will be detached, while the network communication to the # VM must not be cut off. In order to reach this level of live migration # transparency, we use failover mode lagg(4) with the network VF and the -# cooresponding hn(4) attached to it. +# corresponding hn(4) attached to it. # # To ease user configuration for both network VF and non-network VF, the # lagg(4) will be created by the following rules, and the configuration -# of the cooresponding hn(4) will be applied to the lagg(4) automatically. +# of the corresponding hn(4) will be applied to the lagg(4) automatically. # # NOTE: # If live migration is not needed at all, the following rules could be # commented out, and the network VF interface could be used exclusively. -# Most often the cooresponding hn(4) could be completely ignored. +# Most often the corresponding hn(4) could be completely ignored. # # # Default workflow for the network VF bringup: diff --git a/etc/mail/mailer.conf b/etc/mail/mailer.conf index 3fa69223046..3f4bd392639 100644 --- a/etc/mail/mailer.conf +++ b/etc/mail/mailer.conf @@ -3,7 +3,6 @@ # Execute the "real" sendmail program, named /usr/libexec/sendmail/sendmail # sendmail /usr/libexec/sendmail/sendmail -send-mail /usr/libexec/sendmail/sendmail mailq /usr/libexec/sendmail/sendmail newaliases /usr/libexec/sendmail/sendmail hoststat /usr/libexec/sendmail/sendmail diff --git a/etc/portsnap.conf b/etc/portsnap.conf index e0e57dc643d..261be1bafff 100644 --- a/etc/portsnap.conf +++ b/etc/portsnap.conf @@ -30,7 +30,6 @@ KEYPRINT=9b5feee6d69f170e3dd0a2c8e469ddbd64f13f978f2f3aede40c98633216c330 # REFUSE korean polish portuguese russian ukrainian vietnamese # List of INDEX files to build and the DESCRIBE file to use for each -#INDEX INDEX-9 DESCRIBE.9 #INDEX INDEX-10 DESCRIBE.10 #INDEX INDEX-11 DESCRIBE.11 INDEX INDEX-12 DESCRIBE.12 diff --git a/etc/rc.initdiskless b/etc/rc.initdiskless index 3e9c2c70099..99e067d508a 100644 --- a/etc/rc.initdiskless +++ b/etc/rc.initdiskless @@ -67,7 +67,7 @@ # /conf/T/M/remount # The contents of the file is a mount command. E.g. if # /conf/1.2.3.4/foo/remount contains "mount -o ro /dev/ad0s3", -# then /dev/ad0s3 will be be mounted on /conf/1.2.3.4/foo/ +# then /dev/ad0s3 will be mounted on /conf/1.2.3.4/foo/ # # /conf/T/M/remount_optional # If this file exists, then failure to execute the mount diff --git a/etc/rc.subr b/etc/rc.subr index caafd88b3f0..9a4adac03e8 100644 --- a/etc/rc.subr +++ b/etc/rc.subr @@ -1542,7 +1542,7 @@ debug() # is created. # # update `file' has changed and needs to be backed up. -# If `cur' exists, it is copied to to `back' +# If `cur' exists, it is copied to `back' # and then `file' is copied to `cur'. # # remove `file' is no longer being tracked by the backups diff --git a/lib/libc/include/reentrant.h b/lib/libc/include/reentrant.h index aaad889103e..690f4ef1b9a 100644 --- a/lib/libc/include/reentrant.h +++ b/lib/libc/include/reentrant.h @@ -67,7 +67,7 @@ * Implementation Details: * * The mutex primitives used by the library (mutex_t, mutex_lock, etc.) - * are macros which expand to the cooresponding primitives provided by + * are macros which expand to the corresponding primitives provided by * the thread engine or to nothing. The latter is used so that code is * not unreasonably cluttered with #ifdefs when all thread safe support * is removed. diff --git a/lib/libc/locale/euc.c b/lib/libc/locale/euc.c index f5b5fd47306..55055965ab4 100644 --- a/lib/libc/locale/euc.c +++ b/lib/libc/locale/euc.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-3-Clause * * Copyright 2013 Garrett D'Amore * Copyright 2011 Nexenta Systems, Inc. All rights reserved. diff --git a/lib/libc/mips/SYS.h b/lib/libc/mips/SYS.h index 99d3b470fa9..c4767a5cd96 100644 --- a/lib/libc/mips/SYS.h +++ b/lib/libc/mips/SYS.h @@ -2,7 +2,7 @@ /* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: (BSD-4-Clause AND BSD-3-Clause) * * Copyright (c) 1996 Jonathan Stone * All rights reserved. diff --git a/lib/libc/sparc64/fpu/fpu_reg.h b/lib/libc/sparc64/fpu/fpu_reg.h index edd455569af..cbfcff94c00 100644 --- a/lib/libc/sparc64/fpu/fpu_reg.h +++ b/lib/libc/sparc64/fpu/fpu_reg.h @@ -31,7 +31,7 @@ #define _LIBC_SPARC64_FPU_FPU_REG_H_ /* - * These are not really of type char[]. They are are arrays of functions defined + * These are not really of type char[]. They are arrays of functions defined * in fpu_reg.S; each array member loads/stores a certain fpu register of the * given size. */ diff --git a/lib/libc/stdio/fflush.3 b/lib/libc/stdio/fflush.3 index 6132bafb41a..890323c4243 100644 --- a/lib/libc/stdio/fflush.3 +++ b/lib/libc/stdio/fflush.3 @@ -32,7 +32,7 @@ .\" @(#)fflush.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd December 25, 2017 .Dt FFLUSH 3 .Os .Sh NAME @@ -87,9 +87,7 @@ is set to indicate the error. The .Fa stream argument -is not an open stream, or, in the case of -.Fn fflush , -not a stream open for writing. +is not an open stream. .El .Pp The function @@ -97,7 +95,12 @@ The function may also fail and set .Va errno for any of the errors specified for the routine -.Xr write 2 . +.Xr write 2 , +except that in case of +.Fa stream +being a read-only descriptor, +.Fn fflush +returns 0. .Sh SEE ALSO .Xr write 2 , .Xr fclose 3 , diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index 0cf53713043..ac327be950c 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -190,7 +190,7 @@ The .Fa ext[2] and .Fa ext[3] -members are always passed throught the kernel as-is, +members are always passed through the kernel as-is, making additional context available to application. .El .Pp diff --git a/lib/libc/sys/sendfile.2 b/lib/libc/sys/sendfile.2 index 313c349ee9f..ef9d9bb60cd 100644 --- a/lib/libc/sys/sendfile.2 +++ b/lib/libc/sys/sendfile.2 @@ -190,7 +190,7 @@ may read ahead when reading the file. A macro .Fn SF_FLAGS is provided to combine readahead amount and flags. -Example shows specifing readahead of 16 pages and +An example showing specifying readahead of 16 pages and .Dv SF_NOCACHE flag: .Pp diff --git a/lib/libcam/camlib.h b/lib/libcam/camlib.h index 4aab63b3195..1cb65785442 100644 --- a/lib/libcam/camlib.h +++ b/lib/libcam/camlib.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-4-Clause AND BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-4-Clause) * * Copyright (c) 1997, 1998 Kenneth D. Merry. * All rights reserved. diff --git a/lib/libedit/map.c b/lib/libedit/map.c index 2d4475c38f1..00b42e17fed 100644 --- a/lib/libedit/map.c +++ b/lib/libedit/map.c @@ -370,7 +370,7 @@ private const el_action_t el_map_vi_insert[] = { * NOTE: These mappings do NOT Correspond well * to the KSH VI editing assignments. * On the other and they are convenient and - * many people have have gotten used to them. + * many people have gotten used to them. */ /* 0 */ ED_UNASSIGNED, /* ^@ */ /* 1 */ ED_MOVE_TO_BEG, /* ^A */ diff --git a/lib/libedit/refresh.c b/lib/libedit/refresh.c index 8f4b08e66e4..844554ee188 100644 --- a/lib/libedit/refresh.c +++ b/lib/libedit/refresh.c @@ -1148,7 +1148,7 @@ re_fastaddc(EditLine *el) /* re_clear_display(): - * clear the screen buffers so that new new prompt starts fresh. + * clear the screen buffers so that new prompt starts fresh. */ protected void re_clear_display(EditLine *el) diff --git a/lib/libefivar/uefi-dputil.c b/lib/libefivar/uefi-dputil.c index 911a1a021a2..1d4cba3a60b 100644 --- a/lib/libefivar/uefi-dputil.c +++ b/lib/libefivar/uefi-dputil.c @@ -134,7 +134,7 @@ GetDevicePathSize ( @param MaxSize The maximum size of the device path data structure. @retval TRUE DevicePath is valid. - @retval FALSE The length of any node node in the DevicePath is less + @retval FALSE The length of any node in the DevicePath is less than sizeof (EFI_DEVICE_PATH_PROTOCOL). @retval FALSE If MaxSize is not zero, the size of the DevicePath exceeds MaxSize. diff --git a/lib/libopenbsd/imsg_init.3 b/lib/libopenbsd/imsg_init.3 index eb4b1a665d5..22b20af3bd6 100644 --- a/lib/libopenbsd/imsg_init.3 +++ b/lib/libopenbsd/imsg_init.3 @@ -347,7 +347,7 @@ On success returns a pointer to the buffer; on failure it returns NULL. .Pp .Fn ibuf_dynamic -allocates a resizeable buffer of initial length +allocates a resizable buffer of initial length .Fa len and maximum size .Fa max . diff --git a/lib/libufs/type.c b/lib/libufs/type.c index 3fce7e26cec..498b71ab954 100644 --- a/lib/libufs/type.c +++ b/lib/libufs/type.c @@ -83,6 +83,7 @@ ufs_disk_fillout(struct uufsd *disk, const char *name) } if (sbread(disk) == -1) { ERROR(disk, "could not read superblock to fill out disk"); + ufs_disk_close(disk); return (-1); } return (0); diff --git a/lib/libutil/humanize_number.3 b/lib/libutil/humanize_number.3 index 3a883caf2e9..9259f377abf 100644 --- a/lib/libutil/humanize_number.3 +++ b/lib/libutil/humanize_number.3 @@ -200,3 +200,9 @@ The .Dv HN_IEC_PREFIXES flag was introduced in .Fx 9.0 . +.Sh CAVEATS +For numbers greater than 999 using buffer length of 4 and less can cause +rounding errors. +When using +.Dv HN_IEC_PREFIXES +the same error occurs for buffer length of 5 or less. diff --git a/lib/libutil/humanize_number.c b/lib/libutil/humanize_number.c index 5e8fe3dfd18..e03a9b9ad0a 100644 --- a/lib/libutil/humanize_number.c +++ b/lib/libutil/humanize_number.c @@ -145,7 +145,8 @@ humanize_number(char *buf, size_t len, int64_t quotient, */ for (i = 0; (quotient >= max || (quotient == max - 1 && - remainder >= divisordeccut)) && i < maxscale; i++) { + (remainder >= divisordeccut || remainder >= + divisor / 2))) && i < maxscale; i++) { remainder = quotient % divisor; quotient /= divisor; } diff --git a/lib/libutil/pty.c b/lib/libutil/pty.c index 1ef445a7b3b..8faf9154538 100644 --- a/lib/libutil/pty.c +++ b/lib/libutil/pty.c @@ -101,12 +101,13 @@ forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp) return (-1); switch (pid = fork()) { case -1: + (void)close(slave); return (-1); case 0: /* * child */ - (void) close(master); + (void)close(master); login_tty(slave); return (0); } diff --git a/lib/libutil/tests/humanize_number_test.c b/lib/libutil/tests/humanize_number_test.c index 2d66204fefe..bcf091452bd 100644 --- a/lib/libutil/tests/humanize_number_test.c +++ b/lib/libutil/tests/humanize_number_test.c @@ -49,333 +49,337 @@ static struct { int64_t num; int flags; int scale; + size_t buflen; } test_args[] = { /* tests 0-13 test 1000 suffixes */ - { 2, "0 ", (int64_t)0L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 k", (int64_t)500L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 G", (int64_t)500*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 T", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 P", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 2, "1 ", (int64_t)1L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 k", (int64_t)1500L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 M", (int64_t)1500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 G", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 T", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 P", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 E", (int64_t)1500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 2, "0 ", (int64_t)0L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 k", (int64_t)500L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 G", (int64_t)500*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 T", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 P", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 2, "1 ", (int64_t)1L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 k", (int64_t)1500L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 M", (int64_t)1500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 G", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 T", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 P", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 E", (int64_t)1500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, /* tests 14-27 test 1024 suffixes */ - { 2, "0 ", (int64_t)0L, 0, HN_AUTOSCALE }, - { 3, "1 K", (int64_t)512L, 0, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)512*1024L, 0, HN_AUTOSCALE }, - { 3, "1 G", (int64_t)512*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "1 T", (int64_t)512*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "1 P", (int64_t)512*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "1 E", (int64_t)512*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 2, "1 ", (int64_t)1L, 0, HN_AUTOSCALE }, - { 3, "2 K", (int64_t)1536L, 0, HN_AUTOSCALE }, - { 3, "2 M", (int64_t)1536*1024L, 0, HN_AUTOSCALE }, - { 3, "2 G", (int64_t)1536*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "2 T", (int64_t)1536*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "2 P", (int64_t)1536*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 3, "2 E", (int64_t)1536*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 2, "0 ", (int64_t)0L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 K", (int64_t)512L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)512*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 G", (int64_t)512*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 T", (int64_t)512*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 P", (int64_t)512*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 E", (int64_t)512*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 2, "1 ", (int64_t)1L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 K", (int64_t)1536L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 M", (int64_t)1536*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 G", (int64_t)1536*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 T", (int64_t)1536*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 P", (int64_t)1536*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "2 E", (int64_t)1536*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 4 }, /* tests 28-37 test rounding */ - { 3, "0 M", (int64_t)500*1000L-1, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)1000*1000L + 500*1000L-1, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "2 M", (int64_t)1000*1000L + 500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 3, "0 K", (int64_t)512L-1, 0, HN_AUTOSCALE }, - { 3, "1 K", (int64_t)512L, 0, HN_AUTOSCALE }, - { 3, "0 M", (int64_t)512*1024L-1, 0, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)512*1024L, 0, HN_AUTOSCALE }, - { 3, "1 M", (int64_t)1024*1024L + 512*1024L-1, 0, HN_AUTOSCALE }, - { 3, "2 M", (int64_t)1024*1024L + 512*1024L, 0, HN_AUTOSCALE }, + { 3, "0 M", (int64_t)500*1000L-1, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)1000*1000L + 500*1000L-1, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "2 M", (int64_t)1000*1000L + 500*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 4 }, + { 3, "0 K", (int64_t)512L-1, 0, HN_AUTOSCALE, 4 }, + { 3, "1 K", (int64_t)512L, 0, HN_AUTOSCALE, 4 }, + { 3, "0 M", (int64_t)512*1024L-1, 0, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)512*1024L, 0, HN_AUTOSCALE, 4 }, + { 3, "1 M", (int64_t)1024*1024L + 512*1024L-1, 0, HN_AUTOSCALE, 4 }, + { 3, "2 M", (int64_t)1024*1024L + 512*1024L, 0, HN_AUTOSCALE, 4 }, /* tests 38-61 test specific scale factors with 1000 divisor */ - { 3, "0 k", (int64_t)0L, HN_DIVISOR_1000, 1 }, - { 3, "1 k", (int64_t)500L, HN_DIVISOR_1000, 1 }, - { 3, "0 M", (int64_t)500L, HN_DIVISOR_1000, 2 }, - { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, 2 }, - { 3, "0 G", (int64_t)500*1000L, HN_DIVISOR_1000, 3 }, - { 3, "1 G", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 3 }, - { 3, "0 T", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 4 }, - { 3, "1 T", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, 4 }, - { 3, "0 P", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, 5 }, - { 3, "1 P", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, 5 }, - { 3, "0 E", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 3, "1 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 3, "0 k", (int64_t)1L, HN_DIVISOR_1000, 1 }, - { 3, "2 k", (int64_t)1500L, HN_DIVISOR_1000, 1 }, - { 3, "0 M", (int64_t)1500L, HN_DIVISOR_1000, 2 }, - { 3, "2 M", (int64_t)1500*1000L, HN_DIVISOR_1000, 2 }, - { 3, "0 G", (int64_t)1500*1000L, HN_DIVISOR_1000, 3 }, - { 3, "2 G", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 3 }, - { 3, "0 T", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 4 }, - { 3, "2 T", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, 4 }, - { 3, "0 P", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, 5 }, - { 3, "2 P", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, 5 }, - { 3, "0 E", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 3, "2 E", (int64_t)1500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, + { 3, "0 k", (int64_t)0L, HN_DIVISOR_1000, 1, 4 }, + { 3, "1 k", (int64_t)500L, HN_DIVISOR_1000, 1, 4 }, + { 3, "0 M", (int64_t)500L, HN_DIVISOR_1000, 2, 4 }, + { 3, "1 M", (int64_t)500*1000L, HN_DIVISOR_1000, 2, 4 }, + { 3, "0 G", (int64_t)500*1000L, HN_DIVISOR_1000, 3, 4 }, + { 3, "1 G", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 3, 4 }, + { 3, "0 T", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 4, 4 }, + { 3, "1 T", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, 4, 4 }, + { 3, "0 P", (int64_t)500*1000*1000*1000L, HN_DIVISOR_1000, 5, 4 }, + { 3, "1 P", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, 5, 4 }, + { 3, "0 E", (int64_t)500*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 4 }, + { 3, "1 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 4 }, + { 3, "0 k", (int64_t)1L, HN_DIVISOR_1000, 1, 4 }, + { 3, "2 k", (int64_t)1500L, HN_DIVISOR_1000, 1, 4 }, + { 3, "0 M", (int64_t)1500L, HN_DIVISOR_1000, 2, 4 }, + { 3, "2 M", (int64_t)1500*1000L, HN_DIVISOR_1000, 2, 4 }, + { 3, "0 G", (int64_t)1500*1000L, HN_DIVISOR_1000, 3, 4 }, + { 3, "2 G", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 3, 4 }, + { 3, "0 T", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 4, 4 }, + { 3, "2 T", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, 4, 4 }, + { 3, "0 P", (int64_t)1500*1000*1000*1000L, HN_DIVISOR_1000, 5, 4 }, + { 3, "2 P", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, 5, 4 }, + { 3, "0 E", (int64_t)1500*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 4 }, + { 3, "2 E", (int64_t)1500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 4 }, /* tests 62-85 test specific scale factors with 1024 divisor */ - { 3, "0 K", (int64_t)0L, 0, 1 }, - { 3, "1 K", (int64_t)512L, 0, 1 }, - { 3, "0 M", (int64_t)512L, 0, 2 }, - { 3, "1 M", (int64_t)512*1024L, 0, 2 }, - { 3, "0 G", (int64_t)512*1024L, 0, 3 }, - { 3, "1 G", (int64_t)512*1024*1024L, 0, 3 }, - { 3, "0 T", (int64_t)512*1024*1024L, 0, 4 }, - { 3, "1 T", (int64_t)512*1024*1024*1024L, 0, 4 }, - { 3, "0 P", (int64_t)512*1024*1024*1024L, 0, 5 }, - { 3, "1 P", (int64_t)512*1024*1024*1024*1024L, 0, 5 }, - { 3, "0 E", (int64_t)512*1024*1024*1024*1024L, 0, 6 }, - { 3, "1 E", (int64_t)512*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 K", (int64_t)1L, 0, 1 }, - { 3, "2 K", (int64_t)1536L, 0, 1 }, - { 3, "0 M", (int64_t)1536L, 0, 2 }, - { 3, "2 M", (int64_t)1536*1024L, 0, 2 }, - { 3, "0 G", (int64_t)1536*1024L, 0, 3 }, - { 3, "2 G", (int64_t)1536*1024*1024L, 0, 3 }, - { 3, "0 T", (int64_t)1536*1024*1024L, 0, 4 }, - { 3, "2 T", (int64_t)1536*1024*1024*1024L, 0, 4 }, - { 3, "0 P", (int64_t)1536*1024*1024*1024L, 0, 5 }, - { 3, "2 P", (int64_t)1536*1024*1024*1024*1024L, 0, 5 }, - { 3, "0 E", (int64_t)1536*1024*1024*1024*1024L, 0, 6 }, - { 3, "2 E", (int64_t)1536*1024*1024*1024*1024*1024L, 0, 6 }, + { 3, "0 K", (int64_t)0L, 0, 1, 4 }, + { 3, "1 K", (int64_t)512L, 0, 1, 4 }, + { 3, "0 M", (int64_t)512L, 0, 2, 4 }, + { 3, "1 M", (int64_t)512*1024L, 0, 2, 4 }, + { 3, "0 G", (int64_t)512*1024L, 0, 3, 4 }, + { 3, "1 G", (int64_t)512*1024*1024L, 0, 3, 4 }, + { 3, "0 T", (int64_t)512*1024*1024L, 0, 4, 4 }, + { 3, "1 T", (int64_t)512*1024*1024*1024L, 0, 4, 4 }, + { 3, "0 P", (int64_t)512*1024*1024*1024L, 0, 5, 4 }, + { 3, "1 P", (int64_t)512*1024*1024*1024*1024L, 0, 5, 4 }, + { 3, "0 E", (int64_t)512*1024*1024*1024*1024L, 0, 6, 4 }, + { 3, "1 E", (int64_t)512*1024*1024*1024*1024*1024L, 0, 6, 4 }, + { 3, "0 K", (int64_t)1L, 0, 1, 4 }, + { 3, "2 K", (int64_t)1536L, 0, 1, 4 }, + { 3, "0 M", (int64_t)1536L, 0, 2, 4 }, + { 3, "2 M", (int64_t)1536*1024L, 0, 2, 4 }, + { 3, "0 G", (int64_t)1536*1024L, 0, 3, 4 }, + { 3, "2 G", (int64_t)1536*1024*1024L, 0, 3, 4 }, + { 3, "0 T", (int64_t)1536*1024*1024L, 0, 4, 4 }, + { 3, "2 T", (int64_t)1536*1024*1024*1024L, 0, 4, 4 }, + { 3, "0 P", (int64_t)1536*1024*1024*1024L, 0, 5, 4 }, + { 3, "2 P", (int64_t)1536*1024*1024*1024*1024L, 0, 5, 4 }, + { 3, "0 E", (int64_t)1536*1024*1024*1024*1024L, 0, 6, 4 }, + { 3, "2 E", (int64_t)1536*1024*1024*1024*1024*1024L, 0, 6, 4 }, /* tests 86-99 test invalid specific scale values of < 0 or >= 7 with and without HN_DIVISOR_1000 set */ /* all should return errors with new code; with old, the latter 3 are instead processed as if having AUTOSCALE and/or GETSCALE set */ - { -1, "", (int64_t)1L, 0, 7 }, - { -1, "", (int64_t)1L, HN_DIVISOR_1000, 7 }, - { -1, "", (int64_t)1L, 0, 1000 }, - { -1, "", (int64_t)1L, HN_DIVISOR_1000, 1000 }, - { -1, "", (int64_t)0L, 0, 1000*1000 }, - { -1, "", (int64_t)0L, HN_DIVISOR_1000, 1000*1000 }, - { -1, "", (int64_t)0L, 0, INT_MAX }, - { -1, "", (int64_t)0L, HN_DIVISOR_1000, INT_MAX }, + { -1, "", (int64_t)1L, 0, 7, 4 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, 7, 4 }, + { -1, "", (int64_t)1L, 0, 1000, 4 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, 1000, 4 }, + { -1, "", (int64_t)0L, 0, 1000*1000, 4 }, + { -1, "", (int64_t)0L, HN_DIVISOR_1000, 1000*1000, 4 }, + { -1, "", (int64_t)0L, 0, INT_MAX, 4 }, + { -1, "", (int64_t)0L, HN_DIVISOR_1000, INT_MAX, 4 }, /* Negative scale values are not handled well by the existing library routine - should report as error */ /* all should return errors with new code, fail assertion with old */ - { -1, "", (int64_t)1L, 0, -1 }, - { -1, "", (int64_t)1L, HN_DIVISOR_1000, -1 }, - { -1, "", (int64_t)1L, 0, -1000 }, - { -1, "", (int64_t)1L, HN_DIVISOR_1000, -1000 }, + { -1, "", (int64_t)1L, 0, -1, 4 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, -1, 4 }, + { -1, "", (int64_t)1L, 0, -1000, 4 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, -1000, 4 }, /* __INT_MIN doesn't print properly, skipped. */ - { -1, "", (int64_t)1L, 0, -__INT_MAX }, - { -1, "", (int64_t)1L, HN_DIVISOR_1000, -__INT_MAX }, + { -1, "", (int64_t)1L, 0, -__INT_MAX, 4 }, + { -1, "", (int64_t)1L, HN_DIVISOR_1000, -__INT_MAX, 4 }, /* tests for scale == 0, without autoscale */ /* tests 100-114 test scale 0 with 1000 divisor - print first N digits */ - { 2, "0 ", (int64_t)0L, HN_DIVISOR_1000, 0 }, - { 2, "1 ", (int64_t)1L, HN_DIVISOR_1000, 0 }, - { 3, "10 ", (int64_t)10L, HN_DIVISOR_1000, 0 }, - { 3, "0 M", (int64_t)150L, HN_DIVISOR_1000, HN_NOSPACE }, - { 3, "0 M", (int64_t)500L, HN_DIVISOR_1000, HN_NOSPACE }, - { 3, "0 M", (int64_t)999L, HN_DIVISOR_1000, HN_NOSPACE }, - { 4, "150", (int64_t)150L, HN_DIVISOR_1000, 0 }, - { 4, "500", (int64_t)500L, HN_DIVISOR_1000, 0 }, - { 4, "999", (int64_t)999L, HN_DIVISOR_1000, 0 }, - { 5, "100", (int64_t)1000L, HN_DIVISOR_1000, 0 }, - { 5, "150", (int64_t)1500L, HN_DIVISOR_1000, 0 }, - { 7, "500", (int64_t)500*1000L, HN_DIVISOR_1000, 0 }, - { 8, "150", (int64_t)1500*1000L, HN_DIVISOR_1000, 0 }, - { 10, "500", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 0 }, - { 11, "150", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 0 }, + { 2, "0 ", (int64_t)0L, HN_DIVISOR_1000, 0, 4 }, + { 2, "1 ", (int64_t)1L, HN_DIVISOR_1000, 0, 4 }, + { 3, "10 ", (int64_t)10L, HN_DIVISOR_1000, 0, 4 }, + { 3, "0 M", (int64_t)150L, HN_DIVISOR_1000, HN_NOSPACE, 4 }, + { 3, "0 M", (int64_t)500L, HN_DIVISOR_1000, HN_NOSPACE, 4 }, + { 3, "0 M", (int64_t)999L, HN_DIVISOR_1000, HN_NOSPACE, 4 }, + { 4, "150", (int64_t)150L, HN_DIVISOR_1000, 0, 4 }, + { 4, "500", (int64_t)500L, HN_DIVISOR_1000, 0, 4 }, + { 4, "999", (int64_t)999L, HN_DIVISOR_1000, 0, 4 }, + { 5, "100", (int64_t)1000L, HN_DIVISOR_1000, 0, 4 }, + { 5, "150", (int64_t)1500L, HN_DIVISOR_1000, 0, 4 }, + { 7, "500", (int64_t)500*1000L, HN_DIVISOR_1000, 0, 4 }, + { 8, "150", (int64_t)1500*1000L, HN_DIVISOR_1000, 0, 4 }, + { 10, "500", (int64_t)500*1000*1000L, HN_DIVISOR_1000, 0, 4 }, + { 11, "150", (int64_t)1500*1000*1000L, HN_DIVISOR_1000, 0, 4 }, /* tests 115-126 test scale 0 with 1024 divisor - print first N digits */ - { 2, "0 ", (int64_t)0L, 0, 0 }, - { 2, "1 ", (int64_t)1L, 0, 0 }, - { 3, "10 ", (int64_t)10L, 0, 0 }, - { 4, "150", (int64_t)150L, 0, 0 }, - { 4, "500", (int64_t)500L, 0, 0 }, - { 4, "999", (int64_t)999L, 0, 0 }, - { 5, "100", (int64_t)1000L, 0, 0 }, - { 5, "150", (int64_t)1500L, 0, 0 }, - { 7, "500", (int64_t)500*1000L, 0, 0 }, - { 8, "150", (int64_t)1500*1000L, 0, 0 }, - { 10, "500", (int64_t)500*1000*1000L, 0, 0 }, - { 11, "150", (int64_t)1500*1000*1000L, 0, 0 }, + { 2, "0 ", (int64_t)0L, 0, 0, 4 }, + { 2, "1 ", (int64_t)1L, 0, 0, 4 }, + { 3, "10 ", (int64_t)10L, 0, 0, 4 }, + { 4, "150", (int64_t)150L, 0, 0, 4 }, + { 4, "500", (int64_t)500L, 0, 0, 4 }, + { 4, "999", (int64_t)999L, 0, 0, 4 }, + { 5, "100", (int64_t)1000L, 0, 0, 4 }, + { 5, "150", (int64_t)1500L, 0, 0, 4 }, + { 7, "500", (int64_t)500*1000L, 0, 0, 4 }, + { 8, "150", (int64_t)1500*1000L, 0, 0, 4 }, + { 10, "500", (int64_t)500*1000*1000L, 0, 0, 4 }, + { 11, "150", (int64_t)1500*1000*1000L, 0, 0, 4 }, + + /* Test case for rounding of edge numbers around 999.5+, see PR224498. + * Require buflen >= 5 */ + { 4, "1.0M", (int64_t)1023500, HN_DECIMAL|HN_B|HN_NOSPACE, HN_AUTOSCALE, 5 }, /* Test boundary cases for very large positive/negative number formatting */ /* Explicit scale, divisor 1024 */ - /* XXX = requires length 5 (buflen 6) for some cases*/ - /* KLUDGE - test loop below will bump length 5 up to 5 */ - { 3, "8 E", INT64_MAX, 0, 6 }, - { 4, "-8 E", -INT64_MAX, 0, 6 }, - { 3, "0 E", (int64_t)92*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 E", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 E", (int64_t)81*1024*1024*1024*1024*1024L, 0, 6 }, - { 3, "0 E", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 6 }, - { 4, "92 P", (int64_t)92*1024*1024*1024*1024*1024L, 0, 5 }, - { 5, "-92 P", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 5 }, - { 4, "82 P", (int64_t)82*1024*1024*1024*1024*1024L, 0, 5 }, - { 5, "-82 P", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 5 }, - { 4, "81 P", (int64_t)81*1024*1024*1024*1024*1024L, 0, 5 }, - { 5, "-81 P", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 5 }, + /* Requires buflen >= 6 */ + { 3, "8 E", INT64_MAX, 0, 6, 6 }, + { 4, "-8 E", -INT64_MAX, 0, 6, 6 }, + { 3, "0 E", (int64_t)92*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 3, "0 E", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 3, "0 E", (int64_t)81*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 3, "0 E", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 6, 6 }, + { 4, "92 P", (int64_t)92*1024*1024*1024*1024*1024L, 0, 5, 6 }, + { 5, "-92 P", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 5, 6 }, + { 4, "82 P", (int64_t)82*1024*1024*1024*1024*1024L, 0, 5, 6 }, + { 5, "-82 P", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 5, 6 }, + { 4, "81 P", (int64_t)81*1024*1024*1024*1024*1024L, 0, 5, 6 }, + { 5, "-81 P", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 5, 6 }, /* Explicit scale, divisor 1000 */ - { 3, "9 E", INT64_MAX, HN_DIVISOR_1000, 6 }, - { 4, "-9 E", -INT64_MAX, HN_DIVISOR_1000, 6 }, - { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, - { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, - { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, - { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6 }, - { 4, "92 P", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, - { 5, "-92 P", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, - { 4, "91 P", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, - { 5, "-91 P", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5 }, + { 3, "9 E", INT64_MAX, HN_DIVISOR_1000, 6, 6 }, + { 4, "-9 E", -INT64_MAX, HN_DIVISOR_1000, 6, 6 }, + { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6, 6 }, + { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6, 6 }, + { 3, "0 E", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6, 6 }, + { 3, "0 E", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 6, 6 }, + { 4, "92 P", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5, 6 }, + { 5, "-92 P", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5, 6 }, + { 4, "91 P", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5, 6 }, + { 5, "-91 P", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 5, 6 }, /* Autoscale, divisor 1024 */ - { 3, "8 E", INT64_MAX, 0, HN_AUTOSCALE }, - { 4, "-8 E", -INT64_MAX, 0, HN_AUTOSCALE }, - { 4, "92 P", (int64_t)92*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 5, "-92 P", -(int64_t)92*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 4, "82 P", (int64_t)82*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 5, "-82 P", -(int64_t)82*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 4, "81 P", (int64_t)81*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, - { 5, "-81 P", -(int64_t)81*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE }, + { 3, "8 E", INT64_MAX, 0, HN_AUTOSCALE, 6 }, + { 4, "-8 E", -INT64_MAX, 0, HN_AUTOSCALE, 6 }, + { 4, "92 P", (int64_t)92*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, + { 5, "-92 P", -(int64_t)92*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, + { 4, "82 P", (int64_t)82*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, + { 5, "-82 P", -(int64_t)82*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, + { 4, "81 P", (int64_t)81*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, + { 5, "-81 P", -(int64_t)81*1024*1024*1024*1024*1024L, 0, HN_AUTOSCALE, 6 }, /* Autoscale, divisor 1000 */ - { 3, "9 E", INT64_MAX, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 4, "-9 E", -INT64_MAX, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 4, "92 P", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "-92 P", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 4, "91 P", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "-91 P", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE }, + { 3, "9 E", INT64_MAX, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 4, "-9 E", -INT64_MAX, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 4, "92 P", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "-92 P", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 4, "91 P", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "-91 P", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, /* 0 scale, divisor 1024 */ - { 12, "skdj", INT64_MAX, 0, 0 }, - { 21, "-9223", -INT64_MAX, 0, 0 }, - { 19, "10358", (int64_t)92*1024*1024*1024*1024*1024L, 0, 0 }, - { 20, "-1035", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 0 }, - { 18, "92323", (int64_t)82*1024*1024*1024*1024*1024L, 0, 0 }, - { 19, "-9232", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 0 }, - { 18, "91197", (int64_t)81*1024*1024*1024*1024*1024L, 0, 0 }, - { 19, "-9119", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 0 }, + { 12, "skdj", INT64_MAX, 0, 0, 6 }, + { 21, "-9223", -INT64_MAX, 0, 0, 6 }, + { 19, "10358", (int64_t)92*1024*1024*1024*1024*1024L, 0, 0, 6 }, + { 20, "-1035", -(int64_t)92*1024*1024*1024*1024*1024L, 0, 0, 6 }, + { 18, "92323", (int64_t)82*1024*1024*1024*1024*1024L, 0, 0, 6 }, + { 19, "-9232", -(int64_t)82*1024*1024*1024*1024*1024L, 0, 0, 6 }, + { 18, "91197", (int64_t)81*1024*1024*1024*1024*1024L, 0, 0, 6 }, + { 19, "-9119", -(int64_t)81*1024*1024*1024*1024*1024L, 0, 0, 6 }, /* 0 scale, divisor 1000 */ /* XXX - why does this fail? */ - { -1, "", INT64_MAX, HN_DIVISOR_1000, 0 }, - { 21, "-9223", -INT64_MAX, HN_DIVISOR_1000, 0 }, - { 19, "10358", (int64_t)92*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, - { 20, "-1035", -(int64_t)92*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, - { 18, "92323", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, - { 19, "-9232", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, + { -1, "", INT64_MAX, HN_DIVISOR_1000, 0, 6 }, + { 21, "-9223", -INT64_MAX, HN_DIVISOR_1000, 0, 6 }, + { 19, "10358", (int64_t)92*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, + { 20, "-1035", -(int64_t)92*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, + { 18, "92323", (int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, + { 19, "-9232", -(int64_t)82*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, /* Expected to pass */ - { 18, "91197", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, - { 19, "-9119", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0 }, + { 18, "91197", (int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, + { 19, "-9119", -(int64_t)81*1024*1024*1024*1024*1024L, HN_DIVISOR_1000, 0, 6 }, /* Need to implement tests for GETSCALE */ -/* { ?, "", (int64_t)0L, HN_DIVISOR_1000, HN_GETSCALE }, +/* { ?, "", (int64_t)0L, HN_DIVISOR_1000, HN_GETSCALE, 6 }, ... */ /* Tests for HN_DECIMAL */ /* Positive, Autoscale */ - { 5, "500 k", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "994 k", (int64_t)994*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "995 k", (int64_t)995*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "999 k", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "1.0 M", (int64_t)1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "1.5 M", (int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "1.9 M", (int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "2.0 M", (int64_t)1950*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "9.9 M", (int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 4, "10 M", (int64_t)9950*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "500 M", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "994 M", (int64_t)994*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "995 M", (int64_t)995*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "999 M", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "500 k", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "994 k", (int64_t)994*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "995 k", (int64_t)995*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "999 k", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "1.0 M", (int64_t)1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "1.5 M", (int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "1.9 M", (int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "2.0 M", (int64_t)1950*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "9.9 M", (int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 4, "10 M", (int64_t)9950*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "500 M", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "994 M", (int64_t)994*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "995 M", (int64_t)995*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "999 M", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, - { 5, "500 K", (int64_t)500*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "994 K", (int64_t)994*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "995 K", (int64_t)995*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "999 K", (int64_t)999*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.0 M", (int64_t)1000*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.0 M", (int64_t)1018*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.0 M", (int64_t)1019*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.5 M", (int64_t)1536*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.9 M", (int64_t)1996*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "2.0 M", (int64_t)1997*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "2.0 M", (int64_t)2047*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "2.0 M", (int64_t)2048*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "2.0 M", (int64_t)2099*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "2.1 M", (int64_t)2100*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "9.9 M", (int64_t)10188*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "500 K", (int64_t)500*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "994 K", (int64_t)994*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "995 K", (int64_t)995*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "999 K", (int64_t)999*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.0 M", (int64_t)1000*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.0 M", (int64_t)1018*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.0 M", (int64_t)1019*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.5 M", (int64_t)1536*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.9 M", (int64_t)1996*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "2.0 M", (int64_t)1997*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "2.0 M", (int64_t)2047*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "2.0 M", (int64_t)2048*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "2.0 M", (int64_t)2099*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "2.1 M", (int64_t)2100*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "9.9 M", (int64_t)10188*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, /* XXX - shouldn't the following two be "10. M"? */ - { 4, "10 M", (int64_t)10189*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 4, "10 M", (int64_t)10240*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "500 M", (int64_t)500*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "994 M", (int64_t)994*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "995 M", (int64_t)995*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "999 M", (int64_t)999*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.0 G", (int64_t)1000*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "1.0 G", (int64_t)1023*1024*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 4, "10 M", (int64_t)10189*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 4, "10 M", (int64_t)10240*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "500 M", (int64_t)500*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "994 M", (int64_t)994*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "995 M", (int64_t)995*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "999 M", (int64_t)999*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.0 G", (int64_t)1000*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "1.0 G", (int64_t)1023*1024*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, /* Negative, Autoscale - should pass */ - { 6, "-1.5 ", -(int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 6, "-1.9 ", -(int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 6, "-9.9 ", -(int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 6, "-1.5 ", -(int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 6, "-1.9 ", -(int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 6, "-9.9 ", -(int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, - { 6, "-1.5 ", -(int64_t)1536*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 6, "-1.9 ", -(int64_t)1949*1024L, HN_DECIMAL, HN_AUTOSCALE }, - { 6, "-9.7 ", -(int64_t)9949*1024L, HN_DECIMAL, HN_AUTOSCALE }, + { 6, "-1.5 ", -(int64_t)1536*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 6, "-1.9 ", -(int64_t)1949*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 6, "-9.7 ", -(int64_t)9949*1024L, HN_DECIMAL, HN_AUTOSCALE, 6 }, /* Positive/negative, at maximum scale */ - { 5, "500 P", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "1.9 E", (int64_t)1949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "8.9 E", (int64_t)8949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE }, - { 5, "9.2 E", INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 5, "500 P", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "1.9 E", (int64_t)1949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "8.9 E", (int64_t)8949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 5, "9.2 E", INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, /* Negatives work with latest rev only: */ - { 6, "-9.2 ", -INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, - { 6, "-8.9 ", -(int64_t)8949*1000*1000*1000*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE }, + { 6, "-9.2 ", -INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, + { 6, "-8.9 ", -(int64_t)8949*1000*1000*1000*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, HN_AUTOSCALE, 6 }, - { 5, "8.0 E", INT64_MAX, HN_DECIMAL, HN_AUTOSCALE }, - { 5, "7.9 E", INT64_MAX-(int64_t)100*1024*1024*1024*1024*1024LL, HN_DECIMAL, HN_AUTOSCALE }, - { 6, "-8.0 ", -INT64_MAX, HN_DECIMAL, HN_AUTOSCALE }, - { 6, "-7.9 ", -INT64_MAX+(int64_t)100*1024*1024*1024*1024*1024LL, HN_DECIMAL, HN_AUTOSCALE }, + { 5, "8.0 E", INT64_MAX, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 5, "7.9 E", INT64_MAX-(int64_t)100*1024*1024*1024*1024*1024LL, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 6, "-8.0 ", -INT64_MAX, HN_DECIMAL, HN_AUTOSCALE, 6 }, + { 6, "-7.9 ", -INT64_MAX+(int64_t)100*1024*1024*1024*1024*1024LL, HN_DECIMAL, HN_AUTOSCALE, 6 }, /* Positive, Fixed scales */ - { 5, "500 k", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, - { 5, "0.5 M", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "949 k", (int64_t)949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, - { 5, "0.9 M", (int64_t)949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "950 k", (int64_t)950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, - { 5, "1.0 M", (int64_t)950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "999 k", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1 }, - { 5, "1.0 M", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "1.5 M", (int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "1.9 M", (int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "2.0 M", (int64_t)1950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "9.9 M", (int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 4, "10 M", (int64_t)9950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "500 M", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "0.5 G", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 3 }, - { 5, "999 M", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2 }, - { 5, "1.0 G", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 3 }, + { 5, "500 k", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1, 6 }, + { 5, "0.5 M", (int64_t)500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "949 k", (int64_t)949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1, 6 }, + { 5, "0.9 M", (int64_t)949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "950 k", (int64_t)950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1, 6 }, + { 5, "1.0 M", (int64_t)950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "999 k", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, 1, 6 }, + { 5, "1.0 M", (int64_t)999*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "1.5 M", (int64_t)1500*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "1.9 M", (int64_t)1949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "2.0 M", (int64_t)1950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "9.9 M", (int64_t)9949*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 4, "10 M", (int64_t)9950*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "500 M", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "0.5 G", (int64_t)500*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 3, 6 }, + { 5, "999 M", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 2, 6 }, + { 5, "1.0 G", (int64_t)999*1000*1000L, HN_DECIMAL|HN_DIVISOR_1000, 3, 6 }, /* Positive/negative, at maximum scale */ - { 5, "500 P", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 5 }, - { 5, "1.0 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 5, "1.9 E", (int64_t)1949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 5, "8.9 E", (int64_t)8949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6 }, - { 5, "9.2 E", INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, 6 }, + { 5, "500 P", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 5, 6 }, + { 5, "1.0 E", (int64_t)500*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 6 }, + { 5, "1.9 E", (int64_t)1949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 6 }, + { 5, "8.9 E", (int64_t)8949*1000*1000*1000*1000*1000L, HN_DIVISOR_1000, 6, 6 }, + { 5, "9.2 E", INT64_MAX, HN_DECIMAL|HN_DIVISOR_1000, 6, 6 }, /* HN_DECIMAL + binary + fixed scale cases not completed */ - { 5, "512 K", (int64_t)512*1024L, HN_DECIMAL, 1 }, - { 5, "0.5 M", (int64_t)512*1024L, HN_DECIMAL, 2 }, + { 5, "512 K", (int64_t)512*1024L, HN_DECIMAL, 1, 6 }, + { 5, "0.5 M", (int64_t)512*1024L, HN_DECIMAL, 2, 6 }, /* Negative, Fixed scales */ /* Not yet added, but should work with latest rev */ @@ -439,9 +443,9 @@ static struct { } flags[] = { { HN_AUTOSCALE, "HN_AUTOSCALE" }, { HN_GETSCALE, "HN_GETSCALE" }, - { HN_DIVISOR_1000, "HN_DIVISOR_1000"}, - { HN_B, "HN_B"}, - { HN_DECIMAL, "HN_DECIMAL"}, + { HN_DIVISOR_1000, "HN_DIVISOR_1000" }, + { HN_B, "HN_B" }, + { HN_DECIMAL, "HN_DECIMAL" }, }; static const char *separator = "|"; @@ -496,13 +500,14 @@ main(int argc, char * const argv[]) { char *buf; char *flag_str, *scale_str; - size_t buflen, errcnt, i, skipped, tested; + size_t blen, buflen, errcnt, i, skipped, tested; int r; int includeNegScale; int includeExabyteTests; int verbose; - buflen = 4; + buf = NULL; + buflen = 0; includeNegScale = 0; includeExabyteTests = 0; verbose = 0; @@ -510,7 +515,6 @@ main(int argc, char * const argv[]) read_options(argc, argv, &buflen, &includeNegScale, &includeExabyteTests, &verbose); - buf = malloc(buflen); errcnt = 0; tested = 0; skipped = 0; @@ -520,16 +524,8 @@ main(int argc, char * const argv[]) printf("1..%zu\n", nitems(test_args)); for (i = 0; i < nitems(test_args); i++) { - /* KLUDGE */ - if (test_args[i].num == INT64_MAX && buflen == 4) { - /* Start final tests which require buffer of 6 */ - free(buf); - buflen = 6; - buf = malloc(buflen); - if (verbose) - printf("Buffer length increased to %zu\n", - buflen); - } + blen = (buflen > 0) ? buflen : test_args[i].buflen; + buf = realloc(buf, blen); if (test_args[i].scale < 0 && ! includeNegScale) { skipped++; @@ -542,7 +538,7 @@ main(int argc, char * const argv[]) continue; } - r = humanize_number(buf, buflen, test_args[i].num, "", + r = humanize_number(buf, blen, test_args[i].num, "", test_args[i].scale, test_args[i].flags); flag_str = str_flags(test_args[i].flags, "[no flags]"); scale_str = str_scale(test_args[i].scale); @@ -553,7 +549,7 @@ main(int argc, char * const argv[]) "buflen: %zu, got: %d + \"%s\", " "expected %d + \"%s\"; num = %jd, " "scale = %s, flags= %s.\n", - i, buflen, r, buf, test_args[i].retval, + i, blen, r, buf, test_args[i].retval, test_args[i].res, (intmax_t)test_args[i].num, scale_str, flag_str); @@ -565,10 +561,10 @@ main(int argc, char * const argv[]) if (verbose) printf("result mismatch on index %zu, got: " "\"%s\", expected \"%s\"; num = %jd, " - "scale = %s, flags= %s.\n", + "buflen: %zu, scale = %s, flags= %s.\n", i, buf, test_args[i].res, (intmax_t)test_args[i].num, - scale_str, flag_str); + blen, scale_str, flag_str); else printf("not ok %zu # buf \"%s\" != \"%s\"\n", i + 1, buf, test_args[i].res); @@ -577,15 +573,15 @@ main(int argc, char * const argv[]) if (verbose) printf("successful result on index %zu, " "returned %d, got: \"%s\"; num = %jd, " - "scale = %s, flags= %s.\n", - i, r, buf, - (intmax_t)test_args[i].num, - scale_str, flag_str); + "buflen = %zd, scale = %s, flags= %s.\n", + i, r, buf, (intmax_t)test_args[i].num, + blen, scale_str, flag_str); else printf("ok %zu\n", i + 1); } tested++; } + free(buf); if (verbose) printf("total errors: %zu/%zu tests, %zu skipped\n", errcnt, diff --git a/lib/msun/src/catrig.c b/lib/msun/src/catrig.c index b258a3346a5..6ca35af15ff 100644 --- a/lib/msun/src/catrig.c +++ b/lib/msun/src/catrig.c @@ -611,7 +611,7 @@ catanh(double complex z) if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) { /* * z = 0 was filtered out above. All other cases must raise - * inexact, but this is the only only that needs to do it + * inexact, but this is the only case that needs to do it * explicitly. */ raise_inexact(); diff --git a/libexec/dma/dmagent/mailer.conf b/libexec/dma/dmagent/mailer.conf index 53f42c251ce..20ebf5cb673 100644 --- a/libexec/dma/dmagent/mailer.conf +++ b/libexec/dma/dmagent/mailer.conf @@ -1,5 +1,4 @@ # $FreeBSD$ sendmail /usr/libexec/dma -send-mail /usr/libexec/dma mailq /usr/libexec/dma diff --git a/libexec/rpc.sprayd/rpc.sprayd.8 b/libexec/rpc.sprayd/rpc.sprayd.8 index 8840043e5ed..ea19442a4fa 100644 --- a/libexec/rpc.sprayd/rpc.sprayd.8 +++ b/libexec/rpc.sprayd/rpc.sprayd.8 @@ -1,3 +1,4 @@ +.\" $NetBSD: rpc.sprayd.8,v 1.10 2009/10/21 01:07:46 snj Exp $ .\" .\" Copyright (c) 1994 Christos Zoulas .\" All rights reserved. @@ -10,11 +11,6 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Christos Zoulas. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -29,11 +25,12 @@ .\" .\" $FreeBSD$ .\" -.Dd June 22, 1994 +.Dd December 27, 2017 .Dt RPC.SPRAYD 8 .Os .Sh NAME -.Nm rpc.sprayd +.Nm rpc.sprayd , +.Nm sprayd .Nd spray server .Sh SYNOPSIS .Nm /usr/libexec/rpc.sprayd diff --git a/libexec/rpc.sprayd/sprayd.c b/libexec/rpc.sprayd/sprayd.c index dd71f6492ce..0456be67bd7 100644 --- a/libexec/rpc.sprayd/sprayd.c +++ b/libexec/rpc.sprayd/sprayd.c @@ -1,5 +1,7 @@ +/* $NetBSD: sprayd.c,v 1.15 2009/10/21 01:07:46 snj Exp $ */ + /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 1994 Christos Zoulas * All rights reserved. @@ -12,11 +14,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christos Zoulas. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -64,7 +61,7 @@ static int from_inetd = 1; void cleanup(int sig __unused) { - (void) rpcb_unset(SPRAYPROG, SPRAYVERS, NULL); + (void)rpcb_unset(SPRAYPROG, SPRAYVERS, NULL); exit(0); } @@ -93,17 +90,17 @@ main(int argc, char *argv[]) if (!from_inetd) { daemon(0, 0); - (void) rpcb_unset(SPRAYPROG, SPRAYVERS, NULL); + (void)rpcb_unset(SPRAYPROG, SPRAYVERS, NULL); - (void) signal(SIGINT, cleanup); - (void) signal(SIGTERM, cleanup); - (void) signal(SIGHUP, cleanup); + (void)signal(SIGINT, cleanup); + (void)signal(SIGTERM, cleanup); + (void)signal(SIGHUP, cleanup); } else { - (void) signal(SIGALRM, die); + (void)signal(SIGALRM, die); alarm(TIMEOUT); } - openlog("rpc.sprayd", LOG_CONS|LOG_PID, LOG_DAEMON); + openlog("rpc.sprayd", LOG_PID, LOG_DAEMON); if (from_inetd) { transp = svc_tli_create(0, NULL, NULL, 0, 0); @@ -120,7 +117,7 @@ main(int argc, char *argv[]) syslog(LOG_ERR, "unable to register (SPRAYPROG, SPRAYVERS, %s)", (!from_inetd)?"udp":"(inetd)"); - return 1; + exit(1); } svc_run(); @@ -138,7 +135,7 @@ spray_service(struct svc_req *rqstp, SVCXPRT *transp) switch (rqstp->rq_proc) { case SPRAYPROC_CLEAR: scum.counter = 0; - (void) gettimeofday(&clear, 0); + (void)gettimeofday(&clear, 0); /*FALLTHROUGH*/ case NULLPROC: @@ -150,7 +147,7 @@ spray_service(struct svc_req *rqstp, SVCXPRT *transp) return; case SPRAYPROC_GET: - (void) gettimeofday(&get, 0); + (void)gettimeofday(&get, 0); timersub(&get, &clear, &get); scum.clock.sec = get.tv_sec; scum.clock.usec = get.tv_usec; @@ -163,6 +160,6 @@ spray_service(struct svc_req *rqstp, SVCXPRT *transp) if (!svc_sendreply(transp, (xdrproc_t)xdr_spraycumul, &scum)) { svcerr_systemerr(transp); - syslog(LOG_ERR, "bad svc_sendreply"); + syslog(LOG_WARNING, "bad svc_sendreply"); } } diff --git a/sbin/ccdconfig/ccdconfig.8 b/sbin/ccdconfig/ccdconfig.8 index 27233ca445f..392b9e9aec7 100644 --- a/sbin/ccdconfig/ccdconfig.8 +++ b/sbin/ccdconfig/ccdconfig.8 @@ -1,8 +1,11 @@ -.\" $NetBSD: ccdconfig.8,v 1.1.2.1 1995/11/11 02:43:33 thorpej Exp $ +.\" $NetBSD: ccdconfig.8,v 1.4 1996/02/28 01:01:17 thorpej Exp $ .\" -.\" Copyright (c) 1995 Jason R. Thorpe. +.\" Copyright (c) 1996 The NetBSD Foundation, Inc. .\" All rights reserved. .\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Jason R. Thorpe. +.\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: @@ -11,8 +14,13 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sbin/ccdconfig/ccdconfig.c b/sbin/ccdconfig/ccdconfig.c index b47331cee39..69dccffaafd 100644 --- a/sbin/ccdconfig/ccdconfig.c +++ b/sbin/ccdconfig/ccdconfig.c @@ -1,10 +1,15 @@ +/* $NetBSD: ccdconfig.c,v 1.6 1996/05/16 07:11:18 thorpej Exp $ */ + /*- * SPDX-License-Identifier: BSD-4-Clause * * Copyright (c) 2003 Poul-Henning Kamp - * Copyright (c) 1995 Jason R. Thorpe. + * Copyright (c) 1996 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -15,22 +20,23 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project - * by Jason R. Thorpe. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #include diff --git a/sbin/ccdconfig/pathnames.h b/sbin/ccdconfig/pathnames.h index 1622df8995d..0b67c6dc800 100644 --- a/sbin/ccdconfig/pathnames.h +++ b/sbin/ccdconfig/pathnames.h @@ -1,11 +1,14 @@ -/* $NetBSD: pathnames.h,v 1.1 1995/08/17 16:37:20 thorpej Exp $ */ +/* $NetBSD: pathnames.h,v 1.4 2008/04/28 20:23:07 martin Exp $ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * - * Copyright (c) 1995 Jason R. Thorpe. + * Copyright (c) 1996 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -14,24 +17,18 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project - * by Jason R. Thorpe. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ diff --git a/sbin/devfs/rule.c b/sbin/devfs/rule.c index cd868b6f4db..0bfc7ffaf3c 100644 --- a/sbin/devfs/rule.c +++ b/sbin/devfs/rule.c @@ -267,7 +267,7 @@ ruleset_main(int ac, char **av) * differs from the other rulespec_in*() routines in that it also * calls ioctl() for the rules, since it is impractical (and not very * useful) to return a list (or array) of rules, just so the caller - * can call call ioctl() for each of them. + * can call ioctl() for each of them. */ static void rulespec_infp(FILE *fp, unsigned long request, devfs_rsnum rsnum) diff --git a/sbin/dump/dump.h b/sbin/dump/dump.h index f935fab26b8..7aeb3a90d73 100644 --- a/sbin/dump/dump.h +++ b/sbin/dump/dump.h @@ -108,7 +108,7 @@ int mapfiles(ino_t maxino, long *tapesize); int mapdirs(ino_t maxino, long *tapesize); /* file dumping routines */ -void bread(ufs2_daddr_t blkno, char *buf, int size); +void blkread(ufs2_daddr_t blkno, char *buf, int size); ssize_t cread(int fd, void *buf, size_t nbytes, off_t offset); void dumpino(union dinode *dp, ino_t ino); void dumpmap(char *map, int type, ino_t ino); @@ -127,7 +127,7 @@ void dumpabort(int signo) __dead2; void dump_getfstab(void); char *rawname(char *cp); -union dinode *getino(ino_t inum, int *mode); +union dinode *getinode(ino_t inum, int *mode); /* rdump routines */ #ifdef RDUMP diff --git a/sbin/dump/main.c b/sbin/dump/main.c index 91179dd5448..167812bce7d 100644 --- a/sbin/dump/main.c +++ b/sbin/dump/main.c @@ -439,8 +439,8 @@ main(int argc, char *argv[]) sync(); sblock = (struct fs *)sblock_buf; for (i = 0; sblock_try[i] != -1; i++) { - sblock->fs_fsize = SBLOCKSIZE; /* needed in bread */ - bread(sblock_try[i] >> dev_bshift, (char *) sblock, SBLOCKSIZE); + sblock->fs_fsize = SBLOCKSIZE; /* needed in blkread */ + blkread(sblock_try[i]>>dev_bshift, (char *) sblock, SBLOCKSIZE); if ((sblock->fs_magic == FS_UFS1_MAGIC || (sblock->fs_magic == FS_UFS2_MAGIC && sblock->fs_sblockloc == sblock_try[i])) && @@ -556,7 +556,7 @@ main(int argc, char *argv[]) /* * Skip directory inodes deleted and maybe reallocated */ - dp = getino(ino, &mode); + dp = getinode(ino, &mode); if (mode != IFDIR) continue; (void)dumpino(dp, ino); @@ -575,7 +575,7 @@ main(int argc, char *argv[]) /* * Skip inodes deleted and reallocated as directories. */ - dp = getino(ino, &mode); + dp = getinode(ino, &mode); if (mode == IFDIR) continue; (void)dumpino(dp, ino); diff --git a/sbin/dump/tape.c b/sbin/dump/tape.c index 2bddb40bffc..845a2660dad 100644 --- a/sbin/dump/tape.c +++ b/sbin/dump/tape.c @@ -786,7 +786,7 @@ doslave(int cmd, int slave_number) for (trecno = 0; trecno < ntrec; trecno += p->count, p += p->count) { if (p->dblk) { - bread(p->dblk, slp->tblock[trecno], + blkread(p->dblk, slp->tblock[trecno], p->count * TP_BSIZE); } else { if (p->count != 1 || atomic(read, cmd, diff --git a/sbin/dump/traverse.c b/sbin/dump/traverse.c index c501f985521..5538133e381 100644 --- a/sbin/dump/traverse.c +++ b/sbin/dump/traverse.c @@ -162,7 +162,7 @@ mapfiles(ino_t maxino, long *tapesize) quit("mapfiles: cannot allocate memory.\n"); for (cg = 0; cg < sblock->fs_ncg; cg++) { ino = cg * sblock->fs_ipg; - bread(fsbtodb(sblock, cgtod(sblock, cg)), (char *)cgp, + blkread(fsbtodb(sblock, cgtod(sblock, cg)), (char *)cgp, sblock->fs_cgsize); if (sblock->fs_magic == FS_UFS2_MAGIC) inosused = cgp->cg_initediblk; @@ -194,7 +194,7 @@ mapfiles(ino_t maxino, long *tapesize) } for (i = 0; i < inosused; i++, ino++) { if (ino < UFS_ROOTINO || - (dp = getino(ino, &mode)) == NULL || + (dp = getinode(ino, &mode)) == NULL || (mode & IFMT) == 0) continue; if (ino >= maxino) { @@ -276,7 +276,7 @@ mapdirs(ino_t maxino, long *tapesize) nodump = !nonodump && (TSTINO(ino, usedinomap) == 0); if ((isdir & 1) == 0 || (TSTINO(ino, dumpinomap) && !nodump)) continue; - dp = getino(ino, &i); + dp = getinode(ino, &i); /* * inode buf may change in searchdir(). */ @@ -342,7 +342,7 @@ dirindir( int ret = 0; int i; - bread(fsbtodb(sblock, blkno), (char *)&idblk, (int)sblock->fs_bsize); + blkread(fsbtodb(sblock, blkno), (char *)&idblk, (int)sblock->fs_bsize); if (ind_level <= 0) { for (i = 0; *filesize > 0 && i < NINDIR(sblock); i++) { if (sblock->fs_magic == FS_UFS1_MAGIC) @@ -395,7 +395,7 @@ searchdir( if (dblk == NULL && (dblk = malloc(sblock->fs_bsize)) == NULL) quit("searchdir: cannot allocate indirect memory.\n"); - bread(fsbtodb(sblock, blkno), dblk, (int)size); + blkread(fsbtodb(sblock, blkno), dblk, (int)size); if (filesize < size) size = filesize; for (loc = 0; loc < size; ) { @@ -420,7 +420,7 @@ searchdir( continue; } if (nodump) { - ip = getino(dp->d_ino, &mode); + ip = getinode(dp->d_ino, &mode); if (TSTINO(dp->d_ino, dumpinomap)) { CLRINO(dp->d_ino, dumpinomap); *tapesize -= blockest(ip); @@ -591,7 +591,7 @@ dmpindir(union dinode *dp, ino_t ino, ufs2_daddr_t blk, int ind_level, int i, cnt, last; if (blk != 0) - bread(fsbtodb(sblock, blk), (char *)&idblk, + blkread(fsbtodb(sblock, blk), (char *)&idblk, (int)sblock->fs_bsize); else memset(&idblk, 0, sblock->fs_bsize); @@ -871,7 +871,7 @@ writeheader(ino_t ino) } union dinode * -getino(ino_t inum, int *modep) +getinode(ino_t inum, int *modep) { static ino_t minino, maxino; static caddr_t inoblock; @@ -883,7 +883,7 @@ getino(ino_t inum, int *modep) curino = inum; if (inum >= minino && inum < maxino) goto gotit; - bread(fsbtodb(sblock, ino_to_fsba(sblock, inum)), inoblock, + blkread(fsbtodb(sblock, ino_to_fsba(sblock, inum)), inoblock, (int)sblock->fs_bsize); minino = inum - (inum % INOPB(sblock)); maxino = minino + INOPB(sblock); @@ -908,7 +908,7 @@ int breaderrors = 0; #define BREADEMAX 32 void -bread(ufs2_daddr_t blkno, char *buf, int size) +blkread(ufs2_daddr_t blkno, char *buf, int size) { int secsize, bytes, resid, xfer, base, cnt, i; static char *tmpbuf; diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c index a7dbfcb690c..afb27c2bccc 100644 --- a/sbin/fsdb/fsdb.c +++ b/sbin/fsdb/fsdb.c @@ -565,6 +565,10 @@ CMDFUNCSTART(findblk) end: curinum = ocurrent; curinode = ginode(curinum); + if (is_ufs2) + free(wantedblk64); + else + free(wantedblk32); return 0; } diff --git a/sbin/ipfw/ipfw.8 b/sbin/ipfw/ipfw.8 index 5f17d17759f..bcdc0bc6ba9 100644 --- a/sbin/ipfw/ipfw.8 +++ b/sbin/ipfw/ipfw.8 @@ -3020,7 +3020,7 @@ supports in-kernel IPv6/IPv4 network address and protocol translation. Stateful NAT64 translation allows IPv6-only clients to contact IPv4 servers using unicast TCP, UDP or ICMP protocols. One or more IPv4 addresses assigned to a stateful NAT64 translator are shared -among serveral IPv6-only clients. +among several IPv6-only clients. When stateful NAT64 is used in conjunction with DNS64, no changes are usually required in the IPv6 client or the IPv4 server. The kernel module diff --git a/sbin/newfs_msdos/mkfs_msdos.c b/sbin/newfs_msdos/mkfs_msdos.c index 5a6406ce422..9459db65f04 100644 --- a/sbin/newfs_msdos/mkfs_msdos.c +++ b/sbin/newfs_msdos/mkfs_msdos.c @@ -247,6 +247,7 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op) img = NULL; rv = -1; + fd = fd1 = -1; if (o.block_size && o.sectors_per_cluster) { warnx("Cannot specify both block size and sectors per cluster"); @@ -716,6 +717,8 @@ mkfs_msdos(const char *fname, const char *dtype, const struct msdos_options *op) rv = 0; done: free(img); + close(fd); + close(fd1); return rv; } diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c index 9586e192999..5b4c67de662 100644 --- a/sbin/pfctl/pfctl.c +++ b/sbin/pfctl/pfctl.c @@ -1510,6 +1510,7 @@ pfctl_rules(int dev, char *filename, int opts, int optimize, if (pfctl_trans(dev, t, DIOCXCOMMIT, osize)) ERR("DIOCXCOMMIT"); } + free(path); return (0); _error: @@ -1519,6 +1520,7 @@ pfctl_rules(int dev, char *filename, int opts, int optimize, err(1, "DIOCXROLLBACK"); exit(1); } else { /* sub ruleset */ + free(path); return (-1); } diff --git a/sbin/routed/main.c b/sbin/routed/main.c index 45b15065304..c4f9e56065e 100644 --- a/sbin/routed/main.c +++ b/sbin/routed/main.c @@ -667,6 +667,7 @@ get_rip_sock(naddr addr, if (bind(s, (struct sockaddr *)&rsin, sizeof(rsin)) < 0) { if (serious) BADERR(errno != EADDRINUSE, "bind(rip_sock)"); + close(s); return -1; } fix_sock(s,"rip_sock"); diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile index 9496d0988c2..dc74e1ddbcb 100644 --- a/share/man/man4/Makefile +++ b/share/man/man4/Makefile @@ -70,6 +70,9 @@ MAN= aac.4 \ audit.4 \ auditpipe.4 \ aue.4 \ + ${_aw_gpio.4} \ + ${_aw_mmc.4} \ + ${_aw_rtc.4} \ axe.4 \ axge.4 \ bce.4 \ @@ -756,6 +759,12 @@ MLINKS+=xl.4 if_xl.4 _armv8crypto.4= armv8crypto.4 .endif +.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "aarch64" +_aw_gpio.4= aw_gpio.4 +_aw_mmc.4= aw_mmc.4 +_aw_rtc.4= aw_rtc.4 +.endif + .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" _acpi_asus.4= acpi_asus.4 _acpi_asus_wmi.4= acpi_asus_wmi.4 diff --git a/share/man/man4/aw_gpio.4 b/share/man/man4/aw_gpio.4 new file mode 100644 index 00000000000..b5aff709587 --- /dev/null +++ b/share/man/man4/aw_gpio.4 @@ -0,0 +1,102 @@ +.\"- +.\" Copyright (c) 2017 Emmanuel Vadot +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd Dec 25, 2017 +.Dt AW_GPIO 4 +.Os +.Sh NAME +.Nm aw_gpio +.Nd driver for the GPIO and pin muxing functionalities on Allwinner SoC +.Sh SYNOPSIS +.Cd "device gpio" +.Cd "options SOC_ALLWINNER_A10" +.Cd "options SOC_ALLWINNER_A13" +.Cd "options SOC_ALLWINNER_A20" +.Cd "options SOC_ALLWINNER_A31" +.Cd "options SOC_ALLWINNER_A31S" +.Cd "options SOC_ALLWINNER_A33" +.Cd "options SOC_ALLWINNER_A83T" +.Cd "options SOC_ALLWINNER_H2PLUS" +.Cd "options SOC_ALLWINNER_H3" +.Cd "options SOC_ALLWINNER_A64" +.Cd "options SOC_ALLWINNER_H5" +.Sh DESCRIPTION +The +.Nm +device driver provides support for the Allwinner pin muxing and GPIO on +Allwinner SoCs. +.Sh HARDWARE +The current version of the +.Nm +driver supports the GPIO/pinmuxing controller with one of the following +compatible strings : +.Pp +.Bl -bullet -compact +.It +allwinner,sun4i-a10-pinctrl +.It +allwinner,sun5i-a13-pinctrl +.It +allwinner,sun7i-a20-pinctrl +.It +allwinner,sun6i-a31-pinctrl +.It +allwinner,sun6i-a31s-pinctrl +.It +allwinner,sun6i-a31-r-pinctrl +.It +allwinner,sun6i-a33-pinctrl +.It +allwinner,sun8i-a83t-pinctrl +.It +allwinner,sun8i-a83t-r-pinctrl +.It +allwinner,sun8i-h3-pinctrl +.It +allwinner,sun50i-h5-pinctrl +.It +allwinner,sun8i-h3-r-pinctrl +.It +allwinner,sun50i-a64-pinctrl +.It +allwinner,sun50i-a64-r-pinctrl +.El +.Sh SEE ALSO +.Xr fdt 4 , +.Xr gpio 4 +.Sh HISTORY +The +.Nm +device driver first appeared in +.Fx 10.0 . +.Sh AUTHORS +The +.Nm +device driver was originally written by +.An Ganbold Tsagaankhuu Aq Mt ganbold@freebsd.org . +This manual page was written by +.An Emmanuel Vadot Aq Mt manu@freebsd.org . diff --git a/share/man/man4/aw_mmc.4 b/share/man/man4/aw_mmc.4 new file mode 100644 index 00000000000..f18431779b8 --- /dev/null +++ b/share/man/man4/aw_mmc.4 @@ -0,0 +1,76 @@ +.\"- +.\" Copyright (c) 2017 Emmanuel Vadot +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd Dec 25, 2017 +.Dt AW_MMC 4 +.Os +.Sh NAME +.Nm aw_mmc +.Nd driver for the SD/MMC controller in Allwinner SoC +.Sh SYNOPSIS +.Cd "device mmc" +.Sh DESCRIPTION +The +.Nm +device driver provides support for the Allwinner SD/MMC host controller. +.Sh HARDWARE +The current version of the +.Nm +driver supports the SD/MMC controller with one of the following compatible strings : +.Pp +.Bl -bullet -compact +.It +allwinner,sun4i-a10-mmc +.It +allwinner,sun5i-a13-mmc +.It +allwinner,sun7i-a20-mmc +.It +allwinner,sun50i-a64-mmc +.El +.Sh SYSCTL VARIABLES +The following read-only variables are available via +.Xr sysctl 8 : +.Bl -tag -width indent +.It Va dev.aw_mmc.req_timeout +Request timeout in seconds (default: 10) . +.El +.Sh SEE ALSO +.Xr fdt 4 , +.Xr mmc 4 +.Sh HISTORY +The +.Nm +device driver first appeared in +.Fx 10.0 . +.Sh AUTHORS +The +.Nm +device driver was originally written by +.An Alexander Fedorov Aq Mt alexander.fedorov@rtlservice.com . +Later work and this manual page was done by +.An Emmanuel Vadot Aq Mt manu@freebsd.org . diff --git a/share/man/man4/aw_rtc.4 b/share/man/man4/aw_rtc.4 new file mode 100644 index 00000000000..fb8d460e1c3 --- /dev/null +++ b/share/man/man4/aw_rtc.4 @@ -0,0 +1,63 @@ +.\"- +.\" Copyright (c) 2017 Emmanuel Vadot +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd Dec 25, 2017 +.Dt AW_RTC 4 +.Os +.Sh NAME +.Nm aw_rtc +.Nd driver for the RTC controller in Allwinner SoC +.Sh DESCRIPTION +The +.Nm +device driver provides support for the Allwinner RTC controller. +.Sh HARDWARE +The current version of the +.Nm +driver supports the RTC controller with one of the following compatible +strings : +.Pp +.Bl -bullet -compact +.It +allwinner,sun4i-a10-rtc +.It +allwinner,sun7i-a20-rtc +.It +allwinner,sun6i-a31-rtc +.El +.Sh HISTORY +The +.Nm +device driver first appeared in +.Fx 11.0 . +.Sh AUTHORS +The +.Nm +device driver was written by +.An Vladimir Belian Aq Mt fate10@gmail.com . +This manual page was written by +.An Emmanuel Vadot Aq Mt manu@freebsd.org . diff --git a/share/man/man4/ip.4 b/share/man/man4/ip.4 index 98b7a6ae27a..d9ee8175ac3 100644 --- a/share/man/man4/ip.4 +++ b/share/man/man4/ip.4 @@ -224,7 +224,7 @@ or the socket should be bound to a local address and the address supplied with .Dv IP_SENDSRCADDR should be .Dv INADDR_ANY . -In the latter case bound address is overriden via generic source address +In the latter case bound address is overridden via generic source address selection logic, which would choose IP address of interface closest to destination. .Pp diff --git a/share/man/man4/lm75.4 b/share/man/man4/lm75.4 index d137eb063a6..75f6907bda7 100644 --- a/share/man/man4/lm75.4 +++ b/share/man/man4/lm75.4 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 11, 2014 +.Dd December 26, 2017 .Dt LM75 4 .Os .Sh NAME @@ -122,7 +122,7 @@ clones may not work reliably. .Pp On a .Xr device.hints 5 -based system, like +based system, such as .Li MIPS , these values are configurable for .Nm : @@ -140,31 +140,28 @@ i2c address on the .Pp On a .Xr FDT 4 -based system, like +based system, such as .Li ARM , the DTS part for a .Nm device usually looks like: .Bd -literal i2c { - + /* Properties describing the controller appear here. */ ... - - lm750 { + lm750@49 { compatible = "national,lm75"; - i2c-address = <0x49>; + reg = <0x49>; }; }; .Ed .Pp Where: -.Bl -tag -width ".Va i2c-address" +.Bl -tag -width ".Va compatible" .It Va compatible Should always be set to "national,lm75". -.It Va i2c-address -The -.Va i2c-address -property indicates which i2c address the +.It Va reg +Indicates which 7-bit i2c address the .Nm is wired at. .Nm diff --git a/share/man/man4/md.4 b/share/man/man4/md.4 index ec734a913c1..7c26fa61974 100644 --- a/share/man/man4/md.4 +++ b/share/man/man4/md.4 @@ -7,7 +7,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 7, 2017 +.Dd December 26, 2017 .Dt MD 4 .Os .Sh NAME @@ -93,6 +93,47 @@ disk found in the .Xr mdconfig 8 man page. Other tools will also create these images, such as NanoBSD. +.Sh ARM KERNEL OPTIONS +On armv6 and armv7 architectures, an MD_ROOT image larger than +approximately 55 MiB may require building a custom kernel using +several tuning options related to kernel memory usage. +.Bl -tag -width indent +.It Cd options LOCORE_MAP_MB= +This configures how much memory is mapped for the kernel during +the early initialization stages. +The value must be at least as large as the kernel plus all preloaded +modules, including the root image. +There is no downside to setting this value too large, as long +as it does not exceed the amount of physical memory. +The default is 64 MiB. +.It Cd options NKPT2PG= +This configures the number of kernel L2 page table pages to +preallocate during kernel initialization. +Each L2 page can map 4 MiB of kernel space. +The value must be large enough to map the kernel plus all preloaded +modules, including the root image. +The default value is 32, which is sufficient to map 128 MiB. +.It Cd options VM_KMEM_SIZE_SCALE= +This configures the amount of kernel virtual address (KVA) space to +dedicate to the kmem_arena map. +The value is the ratio of physical to virtual pages. +The default value of 3 allocates a page of KVA for each 3 pages +of physical ram in the system. + +The kernel and modules, including the root image, also consume KVA. +The combination of a large root image and the default scaling +may preallocate so much KVA to kmem_arena that there is not enough +remaining address space to allocate kernel stacks, IO buffers, +and other resources that are not part of kmem_arena. +Overallocating kmem_arena space is likely to manifest as failure to +launch userland processes with "cannot allocate kernel stack" messages. + +Setting the value too high may result in kernel failure to allocate +memory because kmem_arena is too small, and the failure may require +significant runtime to manifest. +Empirically, a value of 5 works well for a 200 MiB root image on +a system with 2 GiB of physical ram. +.El .Sh SEE ALSO .Xr gpart 8 , .Xr loader 8 , diff --git a/share/man/man4/nand.4 b/share/man/man4/nand.4 index 2b5adb00270..5c868a1151e 100644 --- a/share/man/man4/nand.4 +++ b/share/man/man4/nand.4 @@ -41,7 +41,7 @@ The .Fx .Nm framework consists of a set of interfaces that aim to provide an extensible, -object oriented environement for NAND controllers and NAND Flash memory chips +object oriented environment for NAND controllers and NAND Flash memory chips from various hardware vendors, and to allow for uniform and flexible management of the NAND devices. It comprises of the following major components: diff --git a/share/man/man5/mailer.conf.5 b/share/man/man5/mailer.conf.5 index 476bb77d759..c57dab0e067 100644 --- a/share/man/man5/mailer.conf.5 +++ b/share/man/man5/mailer.conf.5 @@ -31,7 +31,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 18, 2016 +.Dd December 26, 2017 .Dt MAILER.CONF 5 .Os .Sh NAME @@ -96,7 +96,6 @@ program: # Execute the "real" sendmail program located in # /usr/libexec/sendmail/sendmail sendmail /usr/libexec/sendmail/sendmail -send-mail /usr/libexec/sendmail/sendmail mailq /usr/libexec/sendmail/sendmail newaliases /usr/libexec/sendmail/sendmail .Ed @@ -109,7 +108,6 @@ to replace .Bd -literal -offset indent # Emulate sendmail using postfix sendmail /usr/local/sbin/sendmail -send-mail /usr/local/sbin/sendmail mailq /usr/local/sbin/sendmail newaliases /usr/local/sbin/sendmail .Ed @@ -122,7 +120,6 @@ to replace .Bd -literal -offset indent # Emulate sendmail using exim sendmail /usr/local/sbin/exim -send-mail /usr/local/sbin/exim mailq /usr/local/sbin/exim -bp newaliases /usr/bin/true rmail /usr/local/sbin/exim -i -oee @@ -136,7 +133,6 @@ to replace .Bd -literal -offset indent # Send outgoing mail to a smart relay using mini_sendmail sendmail /usr/local/bin/mini_sendmail -srelayhost -send-mail /usr/local/bin/mini_sendmail -srelayhost .Ed .Pp Using @@ -146,7 +142,6 @@ to replace .Bd -literal -offset indent # Execute dma instead of sendmail sendmail /usr/libexec/dma -send-mail /usr/libexec/dma mailq /usr/libexec/dma newaliases /usr/libexec/dma rmail /usr/libexec/dma diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index f80dea91acc..11d683a21ae 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -989,7 +989,7 @@ is set to the list of instances that should be started at system boot time. If .Va pflog_instances -is set, for each whitespace-seperated +is set, for each whitespace-separated .Ar element in the list, .Ao Ar element Ac Ns Va _dev @@ -1031,7 +1031,7 @@ If multiple instances of .Xr ftp-proxy 8 are desired at boot time, .Va ftpproxy_instances -should contain a whitespace-seperated list of instance names. +should contain a whitespace-separated list of instance names. For each .Ar element in the list, a variable named diff --git a/share/man/man9/iflibdd.9 b/share/man/man9/iflibdd.9 index 86e095ba829..d5cd33cc435 100644 --- a/share/man/man9/iflibdd.9 +++ b/share/man/man9/iflibdd.9 @@ -179,7 +179,7 @@ .Fc .Sh FUNCTIONS The above named functions are device dependent configuration functions. -These routines are registerd with iflib by the driver and are called from the +These routines are registered with iflib by the driver and are called from the corresponding iflib function to configure device specific functions and registers. .Ss Device Dependent Functions diff --git a/share/man/man9/iflibtxrx.9 b/share/man/man9/iflibtxrx.9 index bba793139c4..4a93e23121e 100644 --- a/share/man/man9/iflibtxrx.9 +++ b/share/man/man9/iflibtxrx.9 @@ -190,7 +190,7 @@ event. .Sh FUNCTIONS All function calls are associated exclusively with either packet transmission or receipt. -The void *sc passed as the first arguement to all of the following functions +The void *sc passed as the first argument to all of the following functions represents the driver's softc. .Ss Transmit Packet Functions .Bl -ohang -offset indent diff --git a/share/man/man9/uio.9 b/share/man/man9/uio.9 index 51cf8cf5182..c17520da981 100644 --- a/share/man/man9/uio.9 +++ b/share/man/man9/uio.9 @@ -149,7 +149,7 @@ transfers when the request partially overlaps the buffer. When .Va uio_offset is greater than or equal to the buffer size, the result is success -with no bytes transfered, effectively signaling EOF. +with no bytes transferred, effectively signaling EOF. .Sh RETURN VALUES On success .Fn uiomove , diff --git a/share/misc/bsd-family-tree b/share/misc/bsd-family-tree index b7e7becbafd..d35654d68f4 100644 --- a/share/misc/bsd-family-tree +++ b/share/misc/bsd-family-tree @@ -290,6 +290,9 @@ FreeBSD 5.2 | | | | | | | | | | | | | | | | | | | NetBSD | | | | | | | | 6.0.5 | | + | | | | | | | | | + | | | | | | NetBSD | | + | | | | | | 6.0.6 | | | | | | | | | | | | | | | |`-NetBSD 6.1 | | | | FreeBSD | | | | | @@ -357,15 +360,23 @@ FreeBSD 5.2 | | | | | FreeBSD | | | | DragonFly 5.0.0 | 11.1 FreeBSD | | | | | | 10.4 | | OpenBSD 6.2 DragonFly 5.0.1 - | | | | | | - | | | | | DragonFly 5.0.2 - | | | | | | - | | | | | | - | v | | | | - | | | | | -FreeBSD 12 -current | NetBSD -current OpenBSD -current DragonFly -current - | | | | | - v v v v v + | | | v | | | + | | | | | DragonFly 5.0.2 + | | | | | | + | | FreeBSD | | | + | | 10-stable | | | + | FreeBSD \ | | | + | 11-stable \ | | | + | / `| | | | + | HardenedBSD | | | | + | 11-stable HardenedBSD | | | + | 10-stable | | | + | | | | + | | | | + | | | | +FreeBSD 12 -current NetBSD -current OpenBSD -current DragonFly -current + | | | | + v v v v Time ---------------- @@ -695,6 +706,7 @@ DragonFly 3.8.1 2014-06-16 [DFB] DragonFly 3.6.3 2014-06-17 [DFB] FreeBSD 9.3 2014-07-05 [FBD] DragonFly 3.8.2 2014-08-08 [DFB] +NetBSD 6.0.6 2014-09-22 [NDB] NetBSD 6.1.5 2014-09-22 [NBD] Mac OS X 10.10 2014-10-16 [APL] OpenBSD 5.6 2014-11-01 [OBD] diff --git a/share/misc/pci_vendors b/share/misc/pci_vendors index 6b8211d91cf..abf11342e3a 100644 --- a/share/misc/pci_vendors +++ b/share/misc/pci_vendors @@ -3,8 +3,8 @@ # # List of PCI ID's # -# Version: 2017.12.06 -# Date: 2017-12-06 03:15:02 +# Version: 2017.12.20 +# Date: 2017-12-20 03:15:01 # # Maintained by Albert Pool, Martin Mares, and other volunteers from # the PCI ID Project at http://pci-ids.ucw.cz/. @@ -586,6 +586,7 @@ 0096 SAS3004 PCI-Express Fusion-MPT SAS-3 0097 SAS3008 PCI-Express Fusion-MPT SAS-3 1000 3090 SAS9311-8i + 1000 30a0 SAS9300-8e 1000 30e0 SAS9300-8i 1000 3130 SAS 9300-16i 1028 1f45 HBA330 Adapter @@ -2508,6 +2509,7 @@ 6842 Thames LE [Radeon HD 7000M Series] 6843 Thames [Radeon HD 7670M] 6861 Vega 10 XT [Radeon PRO WX 9100] + 6862 Vega 10 XT [Radeon PRO SSG] 6863 Vega 10 XTX [Radeon Vega Frontier Edition] 687f Vega 10 XT [Radeon RX Vega 64] 6888 Cypress XT [FirePro V8800] @@ -4043,6 +4045,11 @@ 1423 Family 15h (Models 30h-3fh) I/O Memory Management Unit 1424 Family 15h (Models 30h-3fh) Processor Root Port 1426 Family 15h (Models 30h-3fh) Processor Root Port + 142e Liverpool Processor Function 0 + 142f Liverpool Processor Function 1 + 1430 Liverpool Processor Function 2 + 1431 Liverpool Processor Function 3 + 1432 Liverpool Processor Function 4 1436 Liverpool Processor Root Complex 1437 Liverpool I/O Memory Management Unit 1438 Liverpool Processor Root Port @@ -5652,6 +5659,22 @@ 90a3 Aeolia Memory (DDR3/SPM) 90a4 Aeolia USB 3.0 xHCI Host Controller 90bc SxS Pro+ memory card + 90c8 Belize ACPI + 90c9 Belize Ethernet Controller + 90ca Belize SATA AHCI Controller + 90cb Belize SD/MMC Host Controller + 90cc Belize PCI Express Glue and Miscellaneous Devices + 90cd Belize DMA Controller + 90ce Belize Memory (DDR3/SPM) + 90cf Belize USB 3.0 xHCI Host Controller + 90d7 Baikal ACPI + 90d8 Baikal Ethernet Controller + 90d9 Baikal SATA AHCI Controller + 90da Baikal SD/MMC Host Controller + 90db Baikal PCI Express Glue and Miscellaneous Devices + 90dc Baikal DMA Controller + 90dd Baikal Memory (DDR3/SPM) + 90de Baikal USB 3.0 xHCI Host Controller 104e Oak Technology, Inc 0017 OTI-64017 0107 OTI-107 [Spitfire] @@ -10836,11 +10859,12 @@ 13d8 GM204M [GeForce GTX 970M] 13d9 GM204M [GeForce GTX 965M] 13da GM204M [GeForce GTX 980 Mobile] - 13e7 GM204 [GeForce GTX 980 Engineering Sample] + 13e7 GM204GL [GeForce GTX 980 Engineering Sample] 13f0 GM204GL [Quadro M5000] 13f1 GM204GL [Quadro M4000] 13f2 GM204GL [Tesla M60] 13f3 GM204GL [Tesla M6] + 10de 1184 GRID M6-8Q 13f8 GM204GLM [Quadro M5000M / M5000 SE] 13f9 GM204GLM [Quadro M4000M] 13fa GM204GLM [Quadro M3000M] @@ -10939,7 +10963,7 @@ 1cb3 GP107GL [Quadro P400] 1d01 GP108 [GeForce GT 1030] 1d10 GP108M [GeForce MX150] - 1d81 GV100 + 1d81 GV100 [TITAN V] 1db1 GV100 [Tesla V100 SXM2] 1db4 GV100 [Tesla V100 PCIe] 10df Emulex Corporation @@ -15644,6 +15668,7 @@ 0252 XR17V252 Dual UART PCI controller 0254 XR17V254 Quad UART PCI controller 0258 XR17V258 Octal UART PCI controller + 0352 XR17V3521 Dual PCIe UART 13a9 Siemens Medical Systems, Ultrasound Group 13aa Broadband Networks Inc 13ab Arcom Control Systems Ltd @@ -18255,6 +18280,8 @@ 1556 PLDA 1100 PCI Express Core Reference Design 110f PCI Express Core Reference Design Virtual Function + 1110 XpressRich Reference Design + 1113 XpressSwitch 1557 MEDIASTAR Co Ltd 1558 CLEVO/KAPOK Computer 1559 SI LOGIC Ltd @@ -18410,6 +18437,7 @@ 020b MT27710 Family [ConnectX-4 Lx Flash Recovery] 020d MT28800 Family [ConnectX-5 Flash Recovery] 020f MT28908A0 Family [ConnectX-6 Flash Recovery] + 0210 MT28908A0 Family [ConnectX-6 Secure Flash Recovery] 0211 MT416842 Family [BlueField SoC Flash Recovery] # reserved for RM#105916 024e MT53100 [Spectrum-2, Flash recovery mode] @@ -18474,6 +18502,7 @@ 15b3 0050 ConnectX-4 100 GbE Dual Port QSFP28 Adapter 1014 MT27700 Family [ConnectX-4 Virtual Function] 1015 MT27710 Family [ConnectX-4 Lx] + 15b3 0004 ConnectX-4 Lx Stand-up dual-port 10GbE MCX4121A-XCAT 15b3 0005 Mellanox Technologies ConnectX-4 Lx Stand-up single-port 40GbE MCX4131A-BCAT 15b3 0016 ConnectX-4 Lx 25 GbE Dual Port SFP28 Adapter 15b3 0020 MCX4411A-ACQN, ConnectX-4 Lx EN OCP, 1x25Gb @@ -18531,6 +18560,7 @@ 7121 NPS-600 configuration and management interface 7122 NPS-600 network interface PF 7123 NPS-600 network interface VF + 8200 Innova-2 FPGA a2d0 MT416842 BlueField SoC Crypto enabled a2d1 MT416842 BlueField SoC Crypto disabled a2d2 MT416842 BlueField integrated ConnectX-5 network controller @@ -18567,6 +18597,7 @@ 0015 ZBox 15b7 Sandisk Corp 2001 Skyhawk Series NVME SSD + 5001 WD Black NVMe SSD 15b8 ADDI-DATA GmbH 1001 APCI1516 SP controller (16 digi outputs) 1003 APCI1032 SP controller (32 digi inputs w/ opto coupler) @@ -18715,6 +18746,11 @@ 1006 Format synchronizer, model 10500 1007 Format synchronizer, model 21000 2002 Fast Universal Data Output + 3100 IO31000 Frame Synchronizer and I/O + 3200 IO32000 Frame Synchronizer and I/O + 4002 High Rate Demodulator + 5001 High Rate FEC + 6001 High Rate Demodulator and FEC 1631 Packard Bell B.V. 1638 Standard Microsystems Corp [SMC] 1100 SMC2602W EZConnect / Addtron AWA-100 / Eumitcom PCI WL11000 @@ -20072,11 +20108,15 @@ 1924 8019 SFN8542-R2 8000 Series 10/40G Adapter 1924 801a SFN8722-R1 8000 Series OCP 10G Adapter 1924 801b SFN8522-R3 8000 Series 10G Adapter + 0b03 SFC9250 10/25/40/50/100G Ethernet Controller + 1924 801d x2522-R1 2000 Series 10/25G Adapter + 1924 801e x2542-R1 2000 Series 40/100G Adapter 1803 SFC9020 10G Ethernet Controller (Virtual Function) 1813 SFL9021 10GBASE-T Ethernet Controller (Virtual Function) 1903 SFC9120 10G Ethernet Controller (Virtual Function) 1923 SFC9140 10/40G Ethernet Controller (Virtual Function) 1a03 SFC9220 10/40G Ethernet Controller (Virtual Function) + 1b03 SFC9250 10/25/40/50/100G Ethernet Controller (Virtual Function) 6703 SFC4000 rev A iSCSI/Onload [Solarstorm] 10b8 0102 SMC10GPCIe-10BT (A2) [TigerCard] 10b8 0103 SMC10GPCIe-10BT (A3) [TigerCard] @@ -20945,6 +20985,7 @@ 1d7c Aerotech, Inc. 1d87 Fuzhou Rockchip Electronics Co., Ltd 1d8f Enyx +1d94 Chengdu Higon IC Design Co.Ltd 1d95 Graphcore Ltd 1da1 Teko Telecom S.r.l. 1da2 Sapphire Technology Limited @@ -23661,8 +23702,9 @@ 15c7 Ethernet Connection X553 1GbE 15c8 Ethernet Connection X553/X557-AT 10GBASE-T 15ce Ethernet Connection X553 10 GbE SFP+ - 15d0 Ethernet SDI Adapter FM10420-100GbE-QDA2 + 15d0 Ethernet SDI Adapter 8086 0001 Ethernet SDI Adapter FM10420-100GbE-QDA2 + 8086 0002 Ethernet SDI Adapter FM10840-MTP2 15d1 Ethernet Controller 10G X550T 8086 0002 Ethernet Converged Network Adapter X550-T1 8086 001b Ethernet Server Adapter X550-T1 for OCP @@ -23687,6 +23729,14 @@ 15e3 Ethernet Connection (5) I219-LM 15e4 Ethernet Connection X553 1GbE 15e5 Ethernet Connection X553 1GbE + 15e7 JHL7540 Thunderbolt 3 Bridge [Titan Ridge 2C 2018] + 15e8 JHL7540 Thunderbolt 3 NHI [Titan Ridge 2C 2018] + 15e9 JHL7540 Thunderbolt 3 USB Controller [Titan Ridge 2C 2018] + 15ea JHL7540 Thunderbolt 3 Bridge [Titan Ridge 4C 2018] + 15eb JHL7540 Thunderbolt 3 NHI [Titan Ridge 4C 2018] + 15ec JHL7540 Thunderbolt 3 USB Controller [Titan Ridge 4C 2018] + 15ef JHL7540 Thunderbolt 3 Bridge [Titan Ridge DD 2018] + 15f0 JHL7540 Thunderbolt 3 USB Controller [Titan Ridge DD 2018] 1600 Broadwell-U Host Bridge -OPI 1601 Broadwell-U PCI Express x16 Controller 1602 Broadwell-U Integrated Graphics @@ -24113,6 +24163,7 @@ 144d c652 NP300E5C series laptop 1849 1e2d Motherboard 1e31 7 Series/C210 Series Chipset Family USB xHCI Host Controller + 103c 179b Elitebook 8470p 103c 17ab ProBook 6570b 1043 108d VivoBook X202EV 1043 1477 N56VZ @@ -25486,6 +25537,12 @@ 103c 31fe ProLiant DL140 G3 15d9 8680 X7DVL-E-O motherboard 15d9 9680 X7DBN Motherboard + 2700 Optane SSD 900P Series + 8086 3900 900P Series [Add-in Card] + 8086 3901 900P Series [2.5" SFF] + 2701 Optane DC P4800X Series SSD + 8086 3904 DC P4800X Series [Add-in Card] + 8086 3905 DC P4800X Series [2.5" SFF] 2770 82945G/GZ/P/PL Memory Controller Hub 1028 01ad OptiPlex GX620 103c 2a3b Pavilion A1512X @@ -29020,6 +29077,11 @@ 103c 0701 Smart Array P204i-b SR Gen10 103c 1100 Smart Array P816i-a SR Gen10 103c 1101 Smart Array P416ie-m SR G10 + 152d 8a22 QS-8204-8i + 152d 8a23 QS-8238-16i + 152d 8a24 QS-8236-16i + 152d 8a36 QS-8240-24i + 152d 8a37 QS-8242-24i 9005 0800 SmartRAID 3154-8i 9005 0801 SmartRAID 3152-8i 9005 0802 SmartRAID 3151-4i diff --git a/stand/fdt/fdt_loader_cmd.c b/stand/fdt/fdt_loader_cmd.c index a463631301c..a21a99895ea 100644 --- a/stand/fdt/fdt_loader_cmd.c +++ b/stand/fdt/fdt_loader_cmd.c @@ -281,14 +281,12 @@ fdt_load_dtb_file(const char * filename) static int fdt_load_dtb_overlay(const char * filename) { - struct preloaded_file *bfp, *oldbfp; + struct preloaded_file *bfp; struct fdt_header header; int err; debugf("fdt_load_dtb_overlay(%s)\n", filename); - oldbfp = file_findfile(filename, "dtbo"); - /* Attempt to load and validate a new dtb from a file. */ if ((bfp = file_loadraw(filename, "dtbo", 1)) == NULL) { printf("failed to load file '%s'\n", filename); @@ -310,10 +308,6 @@ fdt_load_dtb_overlay(const char * filename) return (1); } - /* A new dtb was validated, discard any previous file. */ - if (oldbfp) - file_discard(oldbfp); - return (0); } diff --git a/stand/fdt/fdt_overlay.c b/stand/fdt/fdt_overlay.c index 9f77e866600..e49c5d586e2 100644 --- a/stand/fdt/fdt_overlay.c +++ b/stand/fdt/fdt_overlay.c @@ -324,10 +324,16 @@ fdt_overlay_do_fixups(void *main_fdtp, void *overlay_fdtp) main_symbols_o = fdt_path_offset(main_fdtp, "/__symbols__"); overlay_fixups_o = fdt_path_offset(overlay_fdtp, "/__fixups__"); - if (main_symbols_o < 0) + if (main_symbols_o < 0) { + if (main_symbols_o == -FDT_ERR_NOTFOUND) + return (0); return (-1); - if (overlay_fixups_o < 0) + } + if (overlay_fixups_o < 0) { + if (overlay_fixups_o == -FDT_ERR_NOTFOUND) + return (0); return (-1); + } for (fixup_prop_o = fdt_first_property_offset(overlay_fdtp, overlay_fixups_o); fixup_prop_o >= 0; diff --git a/sys/amd64/amd64/support.S b/sys/amd64/amd64/support.S index 522428ce918..2d8b7b18b25 100644 --- a/sys/amd64/amd64/support.S +++ b/sys/amd64/amd64/support.S @@ -596,7 +596,7 @@ END(subyte) * copyinstr(from, to, maxlen, int *lencopied) - MP SAFE * %rdi, %rsi, %rdx, %rcx * - * copy a string from from to to, stop when a 0 character is reached. + * copy a string from 'from' to 'to', stop when a 0 character is reached. * return ENAMETOOLONG if string is longer than maxlen, and * EFAULT on protection violations. If lencopied is non-zero, * return the actual length in *lencopied. diff --git a/sys/arm/allwinner/a10/a10_intc.c b/sys/arm/allwinner/a10/a10_intc.c index 996d28a950d..d865e491070 100644 --- a/sys/arm/allwinner/a10/a10_intc.c +++ b/sys/arm/allwinner/a10/a10_intc.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2012 Ganbold Tsagaankhuu - * Copyright (c) 2016 Emmanuel Vadot + * Copyright (c) 2016 Emmanuel Vadot * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/arm/allwinner/a10_mmc.c b/sys/arm/allwinner/a10_mmc.c deleted file mode 100644 index ff617b5f2d6..00000000000 --- a/sys/arm/allwinner/a10_mmc.c +++ /dev/null @@ -1,922 +0,0 @@ -/*- - * Copyright (c) 2013 Alexander Fedorov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include - -#include -#include -#include - -#define A10_MMC_MEMRES 0 -#define A10_MMC_IRQRES 1 -#define A10_MMC_RESSZ 2 -#define A10_MMC_DMA_SEGS ((MAXPHYS / PAGE_SIZE) + 1) -#define A10_MMC_DMA_MAX_SIZE 0x2000 -#define A10_MMC_DMA_FTRGLEVEL 0x20070008 -#define A10_MMC_RESET_RETRY 1000 - -#define CARD_ID_FREQUENCY 400000 - -static struct ofw_compat_data compat_data[] = { - {"allwinner,sun4i-a10-mmc", 1}, - {"allwinner,sun5i-a13-mmc", 1}, - {"allwinner,sun7i-a20-mmc", 1}, - {"allwinner,sun50i-a64-mmc", 1}, - {NULL, 0} -}; - -struct a10_mmc_softc { - device_t a10_dev; - clk_t a10_clk_ahb; - clk_t a10_clk_mmc; - hwreset_t a10_rst_ahb; - int a10_bus_busy; - int a10_resid; - int a10_timeout; - struct callout a10_timeoutc; - struct mmc_host a10_host; - struct mmc_request * a10_req; - struct mtx a10_mtx; - struct resource * a10_res[A10_MMC_RESSZ]; - uint32_t a10_intr; - uint32_t a10_intr_wait; - void * a10_intrhand; - - /* Fields required for DMA access. */ - bus_addr_t a10_dma_desc_phys; - bus_dmamap_t a10_dma_map; - bus_dma_tag_t a10_dma_tag; - void * a10_dma_desc; - bus_dmamap_t a10_dma_buf_map; - bus_dma_tag_t a10_dma_buf_tag; - int a10_dma_map_err; -}; - -static struct resource_spec a10_mmc_res_spec[] = { - { SYS_RES_MEMORY, 0, RF_ACTIVE }, - { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE }, - { -1, 0, 0 } -}; - -static int a10_mmc_probe(device_t); -static int a10_mmc_attach(device_t); -static int a10_mmc_detach(device_t); -static int a10_mmc_setup_dma(struct a10_mmc_softc *); -static int a10_mmc_reset(struct a10_mmc_softc *); -static void a10_mmc_intr(void *); -static int a10_mmc_update_clock(struct a10_mmc_softc *, uint32_t); - -static int a10_mmc_update_ios(device_t, device_t); -static int a10_mmc_request(device_t, device_t, struct mmc_request *); -static int a10_mmc_get_ro(device_t, device_t); -static int a10_mmc_acquire_host(device_t, device_t); -static int a10_mmc_release_host(device_t, device_t); - -#define A10_MMC_LOCK(_sc) mtx_lock(&(_sc)->a10_mtx) -#define A10_MMC_UNLOCK(_sc) mtx_unlock(&(_sc)->a10_mtx) -#define A10_MMC_READ_4(_sc, _reg) \ - bus_read_4((_sc)->a10_res[A10_MMC_MEMRES], _reg) -#define A10_MMC_WRITE_4(_sc, _reg, _value) \ - bus_write_4((_sc)->a10_res[A10_MMC_MEMRES], _reg, _value) - -static int -a10_mmc_probe(device_t dev) -{ - - if (!ofw_bus_status_okay(dev)) - return (ENXIO); - if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) - return (ENXIO); - - device_set_desc(dev, "Allwinner Integrated MMC/SD controller"); - - return (BUS_PROBE_DEFAULT); -} - -static int -a10_mmc_attach(device_t dev) -{ - device_t child; - struct a10_mmc_softc *sc; - struct sysctl_ctx_list *ctx; - struct sysctl_oid_list *tree; - uint32_t bus_width; - phandle_t node; - int error; - - node = ofw_bus_get_node(dev); - sc = device_get_softc(dev); - sc->a10_dev = dev; - sc->a10_req = NULL; - if (bus_alloc_resources(dev, a10_mmc_res_spec, sc->a10_res) != 0) { - device_printf(dev, "cannot allocate device resources\n"); - return (ENXIO); - } - if (bus_setup_intr(dev, sc->a10_res[A10_MMC_IRQRES], - INTR_TYPE_MISC | INTR_MPSAFE, NULL, a10_mmc_intr, sc, - &sc->a10_intrhand)) { - bus_release_resources(dev, a10_mmc_res_spec, sc->a10_res); - device_printf(dev, "cannot setup interrupt handler\n"); - return (ENXIO); - } - mtx_init(&sc->a10_mtx, device_get_nameunit(sc->a10_dev), "a10_mmc", - MTX_DEF); - callout_init_mtx(&sc->a10_timeoutc, &sc->a10_mtx, 0); - - /* De-assert reset */ - if (hwreset_get_by_ofw_name(dev, 0, "ahb", &sc->a10_rst_ahb) == 0) { - error = hwreset_deassert(sc->a10_rst_ahb); - if (error != 0) { - device_printf(dev, "cannot de-assert reset\n"); - goto fail; - } - } - - /* Activate the module clock. */ - error = clk_get_by_ofw_name(dev, 0, "ahb", &sc->a10_clk_ahb); - if (error != 0) { - device_printf(dev, "cannot get ahb clock\n"); - goto fail; - } - error = clk_enable(sc->a10_clk_ahb); - if (error != 0) { - device_printf(dev, "cannot enable ahb clock\n"); - goto fail; - } - error = clk_get_by_ofw_name(dev, 0, "mmc", &sc->a10_clk_mmc); - if (error != 0) { - device_printf(dev, "cannot get mmc clock\n"); - goto fail; - } - error = clk_set_freq(sc->a10_clk_mmc, CARD_ID_FREQUENCY, - CLK_SET_ROUND_DOWN); - if (error != 0) { - device_printf(dev, "cannot init mmc clock\n"); - goto fail; - } - error = clk_enable(sc->a10_clk_mmc); - if (error != 0) { - device_printf(dev, "cannot enable mmc clock\n"); - goto fail; - } - - sc->a10_timeout = 10; - ctx = device_get_sysctl_ctx(dev); - tree = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); - SYSCTL_ADD_INT(ctx, tree, OID_AUTO, "req_timeout", CTLFLAG_RW, - &sc->a10_timeout, 0, "Request timeout in seconds"); - - /* Hardware reset */ - A10_MMC_WRITE_4(sc, A10_MMC_HWRST, 1); - DELAY(100); - A10_MMC_WRITE_4(sc, A10_MMC_HWRST, 0); - DELAY(500); - - /* Soft Reset controller. */ - if (a10_mmc_reset(sc) != 0) { - device_printf(dev, "cannot reset the controller\n"); - goto fail; - } - - if (a10_mmc_setup_dma(sc) != 0) { - device_printf(sc->a10_dev, "Couldn't setup DMA!\n"); - goto fail; - } - - if (OF_getencprop(node, "bus-width", &bus_width, sizeof(uint32_t)) <= 0) - bus_width = 4; - - sc->a10_host.f_min = 400000; - sc->a10_host.f_max = 52000000; - sc->a10_host.host_ocr = MMC_OCR_320_330 | MMC_OCR_330_340; - sc->a10_host.mode = mode_sd; - sc->a10_host.caps = MMC_CAP_HSPEED; - if (bus_width >= 4) - sc->a10_host.caps |= MMC_CAP_4_BIT_DATA; - if (bus_width >= 8) - sc->a10_host.caps |= MMC_CAP_8_BIT_DATA; - - child = device_add_child(dev, "mmc", -1); - if (child == NULL) { - device_printf(dev, "attaching MMC bus failed!\n"); - goto fail; - } - if (device_probe_and_attach(child) != 0) { - device_printf(dev, "attaching MMC child failed!\n"); - device_delete_child(dev, child); - goto fail; - } - - return (0); - -fail: - callout_drain(&sc->a10_timeoutc); - mtx_destroy(&sc->a10_mtx); - bus_teardown_intr(dev, sc->a10_res[A10_MMC_IRQRES], sc->a10_intrhand); - bus_release_resources(dev, a10_mmc_res_spec, sc->a10_res); - - return (ENXIO); -} - -static int -a10_mmc_detach(device_t dev) -{ - - return (EBUSY); -} - -static void -a10_dma_desc_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int err) -{ - struct a10_mmc_softc *sc; - - sc = (struct a10_mmc_softc *)arg; - if (err) { - sc->a10_dma_map_err = err; - return; - } - sc->a10_dma_desc_phys = segs[0].ds_addr; -} - -static int -a10_mmc_setup_dma(struct a10_mmc_softc *sc) -{ - int dma_desc_size, error; - - /* Allocate the DMA descriptor memory. */ - dma_desc_size = sizeof(struct a10_mmc_dma_desc) * A10_MMC_DMA_SEGS; - error = bus_dma_tag_create(bus_get_dma_tag(sc->a10_dev), - A10_MMC_DMA_ALIGN, 0, - BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, - dma_desc_size, 1, dma_desc_size, 0, NULL, NULL, &sc->a10_dma_tag); - if (error) - return (error); - error = bus_dmamem_alloc(sc->a10_dma_tag, &sc->a10_dma_desc, - BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->a10_dma_map); - if (error) - return (error); - - error = bus_dmamap_load(sc->a10_dma_tag, sc->a10_dma_map, - sc->a10_dma_desc, dma_desc_size, a10_dma_desc_cb, sc, 0); - if (error) - return (error); - if (sc->a10_dma_map_err) - return (sc->a10_dma_map_err); - - /* Create the DMA map for data transfers. */ - error = bus_dma_tag_create(bus_get_dma_tag(sc->a10_dev), - A10_MMC_DMA_ALIGN, 0, - BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, - A10_MMC_DMA_MAX_SIZE * A10_MMC_DMA_SEGS, A10_MMC_DMA_SEGS, - A10_MMC_DMA_MAX_SIZE, BUS_DMA_ALLOCNOW, NULL, NULL, - &sc->a10_dma_buf_tag); - if (error) - return (error); - error = bus_dmamap_create(sc->a10_dma_buf_tag, 0, - &sc->a10_dma_buf_map); - if (error) - return (error); - - return (0); -} - -static void -a10_dma_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int err) -{ - int i; - struct a10_mmc_dma_desc *dma_desc; - struct a10_mmc_softc *sc; - - sc = (struct a10_mmc_softc *)arg; - sc->a10_dma_map_err = err; - - if (err) - return; - - dma_desc = sc->a10_dma_desc; - for (i = 0; i < nsegs; i++) { - dma_desc[i].buf_size = segs[i].ds_len; - dma_desc[i].buf_addr = segs[i].ds_addr; - dma_desc[i].config = A10_MMC_DMA_CONFIG_CH | - A10_MMC_DMA_CONFIG_OWN; - if (i == 0) - dma_desc[i].config |= A10_MMC_DMA_CONFIG_FD; - if (i < (nsegs - 1)) { - dma_desc[i].config |= A10_MMC_DMA_CONFIG_DIC; - dma_desc[i].next = sc->a10_dma_desc_phys + - ((i + 1) * sizeof(struct a10_mmc_dma_desc)); - } else { - dma_desc[i].config |= A10_MMC_DMA_CONFIG_LD | - A10_MMC_DMA_CONFIG_ER; - dma_desc[i].next = 0; - } - } -} - -static int -a10_mmc_prepare_dma(struct a10_mmc_softc *sc) -{ - bus_dmasync_op_t sync_op; - int error; - struct mmc_command *cmd; - uint32_t val; - - cmd = sc->a10_req->cmd; - if (cmd->data->len > A10_MMC_DMA_MAX_SIZE * A10_MMC_DMA_SEGS) - return (EFBIG); - error = bus_dmamap_load(sc->a10_dma_buf_tag, sc->a10_dma_buf_map, - cmd->data->data, cmd->data->len, a10_dma_cb, sc, 0); - if (error) - return (error); - if (sc->a10_dma_map_err) - return (sc->a10_dma_map_err); - - if (cmd->data->flags & MMC_DATA_WRITE) - sync_op = BUS_DMASYNC_PREWRITE; - else - sync_op = BUS_DMASYNC_PREREAD; - bus_dmamap_sync(sc->a10_dma_buf_tag, sc->a10_dma_buf_map, sync_op); - bus_dmamap_sync(sc->a10_dma_tag, sc->a10_dma_map, BUS_DMASYNC_PREWRITE); - - /* Enable DMA */ - val = A10_MMC_READ_4(sc, A10_MMC_GCTL); - val &= ~A10_MMC_CTRL_FIFO_AC_MOD; - val |= A10_MMC_CTRL_DMA_ENB; - A10_MMC_WRITE_4(sc, A10_MMC_GCTL, val); - - /* Reset DMA */ - val |= A10_MMC_CTRL_DMA_RST; - A10_MMC_WRITE_4(sc, A10_MMC_GCTL, val); - - A10_MMC_WRITE_4(sc, A10_MMC_DMAC, A10_MMC_DMAC_IDMAC_SOFT_RST); - A10_MMC_WRITE_4(sc, A10_MMC_DMAC, - A10_MMC_DMAC_IDMAC_IDMA_ON | A10_MMC_DMAC_IDMAC_FIX_BURST); - - /* Enable RX or TX DMA interrupt */ - if (cmd->data->flags & MMC_DATA_WRITE) - val |= A10_MMC_IDST_TX_INT; - else - val |= A10_MMC_IDST_RX_INT; - A10_MMC_WRITE_4(sc, A10_MMC_IDIE, val); - - /* Set DMA descritptor list address */ - A10_MMC_WRITE_4(sc, A10_MMC_DLBA, sc->a10_dma_desc_phys); - - /* FIFO trigger level */ - A10_MMC_WRITE_4(sc, A10_MMC_FWLR, A10_MMC_DMA_FTRGLEVEL); - - return (0); -} - -static int -a10_mmc_reset(struct a10_mmc_softc *sc) -{ - int timeout; - - A10_MMC_WRITE_4(sc, A10_MMC_GCTL, A10_MMC_RESET); - timeout = 1000; - while (--timeout > 0) { - if ((A10_MMC_READ_4(sc, A10_MMC_GCTL) & A10_MMC_RESET) == 0) - break; - DELAY(100); - } - if (timeout == 0) - return (ETIMEDOUT); - - /* Set the timeout. */ - A10_MMC_WRITE_4(sc, A10_MMC_TMOR, - A10_MMC_TMOR_DTO_LMT_SHIFT(A10_MMC_TMOR_DTO_LMT_MASK) | - A10_MMC_TMOR_RTO_LMT_SHIFT(A10_MMC_TMOR_RTO_LMT_MASK)); - - /* Clear pending interrupts. */ - A10_MMC_WRITE_4(sc, A10_MMC_RISR, 0xffffffff); - A10_MMC_WRITE_4(sc, A10_MMC_IDST, 0xffffffff); - /* Unmask interrupts. */ - A10_MMC_WRITE_4(sc, A10_MMC_IMKR, - A10_MMC_INT_CMD_DONE | A10_MMC_INT_ERR_BIT | - A10_MMC_INT_DATA_OVER | A10_MMC_INT_AUTO_STOP_DONE); - /* Enable interrupts and AHB access. */ - A10_MMC_WRITE_4(sc, A10_MMC_GCTL, - A10_MMC_READ_4(sc, A10_MMC_GCTL) | A10_MMC_CTRL_INT_ENB); - - return (0); -} - -static void -a10_mmc_req_done(struct a10_mmc_softc *sc) -{ - struct mmc_command *cmd; - struct mmc_request *req; - uint32_t val, mask; - int retry; - - cmd = sc->a10_req->cmd; - if (cmd->error != MMC_ERR_NONE) { - /* Reset the FIFO and DMA engines. */ - mask = A10_MMC_CTRL_FIFO_RST | A10_MMC_CTRL_DMA_RST; - val = A10_MMC_READ_4(sc, A10_MMC_GCTL); - A10_MMC_WRITE_4(sc, A10_MMC_GCTL, val | mask); - - retry = A10_MMC_RESET_RETRY; - while (--retry > 0) { - val = A10_MMC_READ_4(sc, A10_MMC_GCTL); - if ((val & mask) == 0) - break; - DELAY(10); - } - if (retry == 0) - device_printf(sc->a10_dev, - "timeout resetting DMA/FIFO\n"); - a10_mmc_update_clock(sc, 1); - } - - req = sc->a10_req; - callout_stop(&sc->a10_timeoutc); - sc->a10_req = NULL; - sc->a10_intr = 0; - sc->a10_resid = 0; - sc->a10_dma_map_err = 0; - sc->a10_intr_wait = 0; - req->done(req); -} - -static void -a10_mmc_req_ok(struct a10_mmc_softc *sc) -{ - int timeout; - struct mmc_command *cmd; - uint32_t status; - - timeout = 1000; - while (--timeout > 0) { - status = A10_MMC_READ_4(sc, A10_MMC_STAR); - if ((status & A10_MMC_STAR_CARD_BUSY) == 0) - break; - DELAY(1000); - } - cmd = sc->a10_req->cmd; - if (timeout == 0) { - cmd->error = MMC_ERR_FAILED; - a10_mmc_req_done(sc); - return; - } - if (cmd->flags & MMC_RSP_PRESENT) { - if (cmd->flags & MMC_RSP_136) { - cmd->resp[0] = A10_MMC_READ_4(sc, A10_MMC_RESP3); - cmd->resp[1] = A10_MMC_READ_4(sc, A10_MMC_RESP2); - cmd->resp[2] = A10_MMC_READ_4(sc, A10_MMC_RESP1); - cmd->resp[3] = A10_MMC_READ_4(sc, A10_MMC_RESP0); - } else - cmd->resp[0] = A10_MMC_READ_4(sc, A10_MMC_RESP0); - } - /* All data has been transferred ? */ - if (cmd->data != NULL && (sc->a10_resid << 2) < cmd->data->len) - cmd->error = MMC_ERR_FAILED; - a10_mmc_req_done(sc); -} - -static void -a10_mmc_timeout(void *arg) -{ - struct a10_mmc_softc *sc; - - sc = (struct a10_mmc_softc *)arg; - if (sc->a10_req != NULL) { - device_printf(sc->a10_dev, "controller timeout\n"); - sc->a10_req->cmd->error = MMC_ERR_TIMEOUT; - a10_mmc_req_done(sc); - } else - device_printf(sc->a10_dev, - "Spurious timeout - no active request\n"); -} - -static void -a10_mmc_intr(void *arg) -{ - bus_dmasync_op_t sync_op; - struct a10_mmc_softc *sc; - struct mmc_data *data; - uint32_t idst, imask, rint; - - sc = (struct a10_mmc_softc *)arg; - A10_MMC_LOCK(sc); - rint = A10_MMC_READ_4(sc, A10_MMC_RISR); - idst = A10_MMC_READ_4(sc, A10_MMC_IDST); - imask = A10_MMC_READ_4(sc, A10_MMC_IMKR); - if (idst == 0 && imask == 0 && rint == 0) { - A10_MMC_UNLOCK(sc); - return; - } -#ifdef DEBUG - device_printf(sc->a10_dev, "idst: %#x, imask: %#x, rint: %#x\n", - idst, imask, rint); -#endif - if (sc->a10_req == NULL) { - device_printf(sc->a10_dev, - "Spurious interrupt - no active request, rint: 0x%08X\n", - rint); - goto end; - } - if (rint & A10_MMC_INT_ERR_BIT) { - device_printf(sc->a10_dev, "error rint: 0x%08X\n", rint); - if (rint & A10_MMC_INT_RESP_TIMEOUT) - sc->a10_req->cmd->error = MMC_ERR_TIMEOUT; - else - sc->a10_req->cmd->error = MMC_ERR_FAILED; - a10_mmc_req_done(sc); - goto end; - } - if (idst & A10_MMC_IDST_ERROR) { - device_printf(sc->a10_dev, "error idst: 0x%08x\n", idst); - sc->a10_req->cmd->error = MMC_ERR_FAILED; - a10_mmc_req_done(sc); - goto end; - } - - sc->a10_intr |= rint; - data = sc->a10_req->cmd->data; - if (data != NULL && (idst & A10_MMC_IDST_COMPLETE) != 0) { - if (data->flags & MMC_DATA_WRITE) - sync_op = BUS_DMASYNC_POSTWRITE; - else - sync_op = BUS_DMASYNC_POSTREAD; - bus_dmamap_sync(sc->a10_dma_buf_tag, sc->a10_dma_buf_map, - sync_op); - bus_dmamap_sync(sc->a10_dma_tag, sc->a10_dma_map, - BUS_DMASYNC_POSTWRITE); - bus_dmamap_unload(sc->a10_dma_buf_tag, sc->a10_dma_buf_map); - sc->a10_resid = data->len >> 2; - } - if ((sc->a10_intr & sc->a10_intr_wait) == sc->a10_intr_wait) - a10_mmc_req_ok(sc); - -end: - A10_MMC_WRITE_4(sc, A10_MMC_IDST, idst); - A10_MMC_WRITE_4(sc, A10_MMC_RISR, rint); - A10_MMC_UNLOCK(sc); -} - -static int -a10_mmc_request(device_t bus, device_t child, struct mmc_request *req) -{ - int blksz; - struct a10_mmc_softc *sc; - struct mmc_command *cmd; - uint32_t cmdreg; - int err; - - sc = device_get_softc(bus); - A10_MMC_LOCK(sc); - if (sc->a10_req) { - A10_MMC_UNLOCK(sc); - return (EBUSY); - } - sc->a10_req = req; - cmd = req->cmd; - cmdreg = A10_MMC_CMDR_LOAD; - if (cmd->opcode == MMC_GO_IDLE_STATE) - cmdreg |= A10_MMC_CMDR_SEND_INIT_SEQ; - if (cmd->flags & MMC_RSP_PRESENT) - cmdreg |= A10_MMC_CMDR_RESP_RCV; - if (cmd->flags & MMC_RSP_136) - cmdreg |= A10_MMC_CMDR_LONG_RESP; - if (cmd->flags & MMC_RSP_CRC) - cmdreg |= A10_MMC_CMDR_CHK_RESP_CRC; - - sc->a10_intr = 0; - sc->a10_resid = 0; - sc->a10_intr_wait = A10_MMC_INT_CMD_DONE; - cmd->error = MMC_ERR_NONE; - if (cmd->data != NULL) { - sc->a10_intr_wait |= A10_MMC_INT_DATA_OVER; - cmdreg |= A10_MMC_CMDR_DATA_TRANS | A10_MMC_CMDR_WAIT_PRE_OVER; - if (cmd->data->flags & MMC_DATA_MULTI) { - cmdreg |= A10_MMC_CMDR_STOP_CMD_FLAG; - sc->a10_intr_wait |= A10_MMC_INT_AUTO_STOP_DONE; - } - if (cmd->data->flags & MMC_DATA_WRITE) - cmdreg |= A10_MMC_CMDR_DIR_WRITE; - blksz = min(cmd->data->len, MMC_SECTOR_SIZE); - A10_MMC_WRITE_4(sc, A10_MMC_BKSR, blksz); - A10_MMC_WRITE_4(sc, A10_MMC_BYCR, cmd->data->len); - - err = a10_mmc_prepare_dma(sc); - if (err != 0) - device_printf(sc->a10_dev, "prepare_dma failed: %d\n", err); - } - - A10_MMC_WRITE_4(sc, A10_MMC_CAGR, cmd->arg); - A10_MMC_WRITE_4(sc, A10_MMC_CMDR, cmdreg | cmd->opcode); - callout_reset(&sc->a10_timeoutc, sc->a10_timeout * hz, - a10_mmc_timeout, sc); - A10_MMC_UNLOCK(sc); - - return (0); -} - -static int -a10_mmc_read_ivar(device_t bus, device_t child, int which, - uintptr_t *result) -{ - struct a10_mmc_softc *sc; - - sc = device_get_softc(bus); - switch (which) { - default: - return (EINVAL); - case MMCBR_IVAR_BUS_MODE: - *(int *)result = sc->a10_host.ios.bus_mode; - break; - case MMCBR_IVAR_BUS_WIDTH: - *(int *)result = sc->a10_host.ios.bus_width; - break; - case MMCBR_IVAR_CHIP_SELECT: - *(int *)result = sc->a10_host.ios.chip_select; - break; - case MMCBR_IVAR_CLOCK: - *(int *)result = sc->a10_host.ios.clock; - break; - case MMCBR_IVAR_F_MIN: - *(int *)result = sc->a10_host.f_min; - break; - case MMCBR_IVAR_F_MAX: - *(int *)result = sc->a10_host.f_max; - break; - case MMCBR_IVAR_HOST_OCR: - *(int *)result = sc->a10_host.host_ocr; - break; - case MMCBR_IVAR_MODE: - *(int *)result = sc->a10_host.mode; - break; - case MMCBR_IVAR_OCR: - *(int *)result = sc->a10_host.ocr; - break; - case MMCBR_IVAR_POWER_MODE: - *(int *)result = sc->a10_host.ios.power_mode; - break; - case MMCBR_IVAR_VDD: - *(int *)result = sc->a10_host.ios.vdd; - break; - case MMCBR_IVAR_CAPS: - *(int *)result = sc->a10_host.caps; - break; - case MMCBR_IVAR_MAX_DATA: - *(int *)result = 65535; - break; - } - - return (0); -} - -static int -a10_mmc_write_ivar(device_t bus, device_t child, int which, - uintptr_t value) -{ - struct a10_mmc_softc *sc; - - sc = device_get_softc(bus); - switch (which) { - default: - return (EINVAL); - case MMCBR_IVAR_BUS_MODE: - sc->a10_host.ios.bus_mode = value; - break; - case MMCBR_IVAR_BUS_WIDTH: - sc->a10_host.ios.bus_width = value; - break; - case MMCBR_IVAR_CHIP_SELECT: - sc->a10_host.ios.chip_select = value; - break; - case MMCBR_IVAR_CLOCK: - sc->a10_host.ios.clock = value; - break; - case MMCBR_IVAR_MODE: - sc->a10_host.mode = value; - break; - case MMCBR_IVAR_OCR: - sc->a10_host.ocr = value; - break; - case MMCBR_IVAR_POWER_MODE: - sc->a10_host.ios.power_mode = value; - break; - case MMCBR_IVAR_VDD: - sc->a10_host.ios.vdd = value; - break; - /* These are read-only */ - case MMCBR_IVAR_CAPS: - case MMCBR_IVAR_HOST_OCR: - case MMCBR_IVAR_F_MIN: - case MMCBR_IVAR_F_MAX: - case MMCBR_IVAR_MAX_DATA: - return (EINVAL); - } - - return (0); -} - -static int -a10_mmc_update_clock(struct a10_mmc_softc *sc, uint32_t clkon) -{ - uint32_t cmdreg; - int retry; - uint32_t ckcr; - - ckcr = A10_MMC_READ_4(sc, A10_MMC_CKCR); - ckcr &= ~(A10_MMC_CKCR_CCLK_ENB | A10_MMC_CKCR_CCLK_CTRL); - - if (clkon) - ckcr |= A10_MMC_CKCR_CCLK_ENB; - - A10_MMC_WRITE_4(sc, A10_MMC_CKCR, ckcr); - - cmdreg = A10_MMC_CMDR_LOAD | A10_MMC_CMDR_PRG_CLK | - A10_MMC_CMDR_WAIT_PRE_OVER; - A10_MMC_WRITE_4(sc, A10_MMC_CMDR, cmdreg); - retry = 0xfffff; - while (--retry > 0) { - if ((A10_MMC_READ_4(sc, A10_MMC_CMDR) & A10_MMC_CMDR_LOAD) == 0) { - A10_MMC_WRITE_4(sc, A10_MMC_RISR, 0xffffffff); - return (0); - } - DELAY(10); - } - A10_MMC_WRITE_4(sc, A10_MMC_RISR, 0xffffffff); - device_printf(sc->a10_dev, "timeout updating clock\n"); - - return (ETIMEDOUT); -} - -static int -a10_mmc_update_ios(device_t bus, device_t child) -{ - int error; - struct a10_mmc_softc *sc; - struct mmc_ios *ios; - uint32_t ckcr; - - sc = device_get_softc(bus); - - ios = &sc->a10_host.ios; - - /* Set the bus width. */ - switch (ios->bus_width) { - case bus_width_1: - A10_MMC_WRITE_4(sc, A10_MMC_BWDR, A10_MMC_BWDR1); - break; - case bus_width_4: - A10_MMC_WRITE_4(sc, A10_MMC_BWDR, A10_MMC_BWDR4); - break; - case bus_width_8: - A10_MMC_WRITE_4(sc, A10_MMC_BWDR, A10_MMC_BWDR8); - break; - } - - if (ios->clock) { - - /* Disable clock */ - error = a10_mmc_update_clock(sc, 0); - if (error != 0) - return (error); - - /* Reset the divider. */ - ckcr = A10_MMC_READ_4(sc, A10_MMC_CKCR); - ckcr &= ~A10_MMC_CKCR_CCLK_DIV; - A10_MMC_WRITE_4(sc, A10_MMC_CKCR, ckcr); - - /* Set the MMC clock. */ - error = clk_set_freq(sc->a10_clk_mmc, ios->clock, - CLK_SET_ROUND_DOWN); - if (error != 0) { - device_printf(sc->a10_dev, - "failed to set frequency to %u Hz: %d\n", - ios->clock, error); - return (error); - } - - /* Enable clock. */ - error = a10_mmc_update_clock(sc, 1); - if (error != 0) - return (error); - } - - - return (0); -} - -static int -a10_mmc_get_ro(device_t bus, device_t child) -{ - - return (0); -} - -static int -a10_mmc_acquire_host(device_t bus, device_t child) -{ - struct a10_mmc_softc *sc; - int error; - - sc = device_get_softc(bus); - A10_MMC_LOCK(sc); - while (sc->a10_bus_busy) { - error = msleep(sc, &sc->a10_mtx, PCATCH, "mmchw", 0); - if (error != 0) { - A10_MMC_UNLOCK(sc); - return (error); - } - } - sc->a10_bus_busy++; - A10_MMC_UNLOCK(sc); - - return (0); -} - -static int -a10_mmc_release_host(device_t bus, device_t child) -{ - struct a10_mmc_softc *sc; - - sc = device_get_softc(bus); - A10_MMC_LOCK(sc); - sc->a10_bus_busy--; - wakeup(sc); - A10_MMC_UNLOCK(sc); - - return (0); -} - -static device_method_t a10_mmc_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, a10_mmc_probe), - DEVMETHOD(device_attach, a10_mmc_attach), - DEVMETHOD(device_detach, a10_mmc_detach), - - /* Bus interface */ - DEVMETHOD(bus_read_ivar, a10_mmc_read_ivar), - DEVMETHOD(bus_write_ivar, a10_mmc_write_ivar), - - /* MMC bridge interface */ - DEVMETHOD(mmcbr_update_ios, a10_mmc_update_ios), - DEVMETHOD(mmcbr_request, a10_mmc_request), - DEVMETHOD(mmcbr_get_ro, a10_mmc_get_ro), - DEVMETHOD(mmcbr_acquire_host, a10_mmc_acquire_host), - DEVMETHOD(mmcbr_release_host, a10_mmc_release_host), - - DEVMETHOD_END -}; - -static devclass_t a10_mmc_devclass; - -static driver_t a10_mmc_driver = { - "a10_mmc", - a10_mmc_methods, - sizeof(struct a10_mmc_softc), -}; - -DRIVER_MODULE(a10_mmc, simplebus, a10_mmc_driver, a10_mmc_devclass, NULL, - NULL); -MMC_DECLARE_BRIDGE(a10_mmc); diff --git a/sys/arm/allwinner/a10_mmc.h b/sys/arm/allwinner/a10_mmc.h deleted file mode 100644 index 85f0374b60e..00000000000 --- a/sys/arm/allwinner/a10_mmc.h +++ /dev/null @@ -1,204 +0,0 @@ -/*- - * Copyright (c) 2013 Alexander Fedorov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _A10_MMC_H_ -#define _A10_MMC_H_ - -#define A10_MMC_GCTL 0x00 /* Control Register */ -#define A10_MMC_CKCR 0x04 /* Clock Control Register */ -#define A10_MMC_TMOR 0x08 /* Timeout Register */ -#define A10_MMC_BWDR 0x0C /* Bus Width Register */ -#define A10_MMC_BKSR 0x10 /* Block Size Register */ -#define A10_MMC_BYCR 0x14 /* Byte Count Register */ -#define A10_MMC_CMDR 0x18 /* Command Register */ -#define A10_MMC_CAGR 0x1C /* Argument Register */ -#define A10_MMC_RESP0 0x20 /* Response Register 0 */ -#define A10_MMC_RESP1 0x24 /* Response Register 1 */ -#define A10_MMC_RESP2 0x28 /* Response Register 2 */ -#define A10_MMC_RESP3 0x2C /* Response Register 3 */ -#define A10_MMC_IMKR 0x30 /* Interrupt Mask Register */ -#define A10_MMC_MISR 0x34 /* Masked Interrupt Status Register */ -#define A10_MMC_RISR 0x38 /* Raw Interrupt Status Register */ -#define A10_MMC_STAR 0x3C /* Status Register */ -#define A10_MMC_FWLR 0x40 /* FIFO Threshold Watermark Register */ -#define A10_MMC_FUNS 0x44 /* Function Select Register */ -#define A10_MMC_HWRST 0x78 /* Hardware reset (not documented) */ -#define A10_MMC_DMAC 0x80 /* IDMAC Control Register */ -#define A10_MMC_DLBA 0x84 /* IDMAC Desc List Base Address Reg */ -#define A10_MMC_IDST 0x88 /* IDMAC Status Register */ -#define A10_MMC_IDIE 0x8C /* IDMAC Interrupt Enable Register */ -#define A10_MMC_FIFO 0x100 /* FIFO Access Address (A10/A20) */ -#define A31_MMC_FIFO 0x200 /* FIFO Access Address (A31) */ - -/* A10_MMC_GCTL */ -#define A10_MMC_CTRL_SOFT_RST (1U << 0) -#define A10_MMC_CTRL_FIFO_RST (1U << 1) -#define A10_MMC_CTRL_DMA_RST (1U << 2) -#define A10_MMC_CTRL_INT_ENB (1U << 4) -#define A10_MMC_CTRL_DMA_ENB (1U << 5) -#define A10_MMC_CTRL_CD_DBC_ENB (1U << 8) -#define A10_MMC_CTRL_DDR_MOD_SEL (1U << 10) -#define A10_MMC_CTRL_FIFO_AC_MOD (1U << 31) -#define A10_MMC_RESET \ - (A10_MMC_CTRL_SOFT_RST | A10_MMC_CTRL_FIFO_RST | A10_MMC_CTRL_DMA_RST) - -/* A10_MMC_CKCR */ -#define A10_MMC_CKCR_CCLK_ENB (1U << 16) -#define A10_MMC_CKCR_CCLK_CTRL (1U << 17) -#define A10_MMC_CKCR_CCLK_DIV 0xff - -/* A10_MMC_TMOR */ -#define A10_MMC_TMOR_RTO_LMT_SHIFT(x) x /* Response timeout limit */ -#define A10_MMC_TMOR_RTO_LMT_MASK 0xff -#define A10_MMC_TMOR_DTO_LMT_SHIFT(x) (x << 8) /* Data timeout limit */ -#define A10_MMC_TMOR_DTO_LMT_MASK 0xffffff - -/* A10_MMC_BWDR */ -#define A10_MMC_BWDR1 0 -#define A10_MMC_BWDR4 1 -#define A10_MMC_BWDR8 2 - -/* A10_MMC_CMDR */ -#define A10_MMC_CMDR_RESP_RCV (1U << 6) -#define A10_MMC_CMDR_LONG_RESP (1U << 7) -#define A10_MMC_CMDR_CHK_RESP_CRC (1U << 8) -#define A10_MMC_CMDR_DATA_TRANS (1U << 9) -#define A10_MMC_CMDR_DIR_WRITE (1U << 10) -#define A10_MMC_CMDR_TRANS_MODE_STREAM (1U << 11) -#define A10_MMC_CMDR_STOP_CMD_FLAG (1U << 12) -#define A10_MMC_CMDR_WAIT_PRE_OVER (1U << 13) -#define A10_MMC_CMDR_STOP_ABT_CMD (1U << 14) -#define A10_MMC_CMDR_SEND_INIT_SEQ (1U << 15) -#define A10_MMC_CMDR_PRG_CLK (1U << 21) -#define A10_MMC_CMDR_RD_CEDATA_DEV (1U << 22) -#define A10_MMC_CMDR_CCS_EXP (1U << 23) -#define A10_MMC_CMDR_BOOT_MOD_SHIFT 24 -#define A10_MMC_CMDR_BOOT_MOD_NORMAL 0 -#define A10_MMC_CMDR_BOOT_MOD_MANDATORY 1 -#define A10_MMC_CMDR_BOOT_MOD_ALT 2 -#define A10_MMC_CMDR_EXP_BOOT_ACK (1U << 26) -#define A10_MMC_CMDR_BOOT_ABT (1U << 27) -#define A10_MMC_CMDR_VOL_SW (1U << 28) -#define A10_MMC_CMDR_LOAD (1U << 31) - -/* A10_MMC_IMKR and A10_MMC_RISR */ -#define A10_MMC_INT_RESP_ERR (1U << 1) -#define A10_MMC_INT_CMD_DONE (1U << 2) -#define A10_MMC_INT_DATA_OVER (1U << 3) -#define A10_MMC_INT_TX_DATA_REQ (1U << 4) -#define A10_MMC_INT_RX_DATA_REQ (1U << 5) -#define A10_MMC_INT_RESP_CRC_ERR (1U << 6) -#define A10_MMC_INT_DATA_CRC_ERR (1U << 7) -#define A10_MMC_INT_RESP_TIMEOUT (1U << 8) -#define A10_MMC_INT_BOOT_ACK_RECV (1U << 8) -#define A10_MMC_INT_DATA_TIMEOUT (1U << 9) -#define A10_MMC_INT_BOOT_START (1U << 9) -#define A10_MMC_INT_DATA_STARVE (1U << 10) -#define A10_MMC_INT_VOL_CHG_DONE (1U << 10) -#define A10_MMC_INT_FIFO_RUN_ERR (1U << 11) -#define A10_MMC_INT_CMD_BUSY (1U << 12) -#define A10_MMC_INT_DATA_START_ERR (1U << 13) -#define A10_MMC_INT_AUTO_STOP_DONE (1U << 14) -#define A10_MMC_INT_DATA_END_BIT_ERR (1U << 15) -#define A10_MMC_INT_SDIO (1U << 16) -#define A10_MMC_INT_CARD_INSERT (1U << 30) -#define A10_MMC_INT_CARD_REMOVE (1U << 31) -#define A10_MMC_INT_ERR_BIT \ - (A10_MMC_INT_RESP_ERR | A10_MMC_INT_RESP_CRC_ERR | \ - A10_MMC_INT_DATA_CRC_ERR | A10_MMC_INT_RESP_TIMEOUT | \ - A10_MMC_INT_FIFO_RUN_ERR | A10_MMC_INT_CMD_BUSY | \ - A10_MMC_INT_DATA_START_ERR | A10_MMC_INT_DATA_END_BIT_ERR) - -/* A10_MMC_STAR */ -#define A10_MMC_STAR_FIFO_RX_LEVEL (1U << 0) -#define A10_MMC_STAR_FIFO_TX_LEVEL (1U << 1) -#define A10_MMC_STAR_FIFO_EMPTY (1U << 2) -#define A10_MMC_STAR_FIFO_FULL (1U << 3) -#define A10_MMC_STAR_CARD_PRESENT (1U << 8) -#define A10_MMC_STAR_CARD_BUSY (1U << 9) -#define A10_MMC_STAR_FSM_BUSY (1U << 10) -#define A10_MMC_STAR_DMA_REQ (1U << 31) - -/* A10_MMC_FUNS */ -#define A10_MMC_CE_ATA_ON (0xceaaU << 16) -#define A10_MMC_SEND_IRQ_RESP (1U << 0) -#define A10_MMC_SDIO_RD_WAIT (1U << 1) -#define A10_MMC_ABT_RD_DATA (1U << 2) -#define A10_MMC_SEND_CC_SD (1U << 8) -#define A10_MMC_SEND_AUTOSTOP_CC_SD (1U << 9) -#define A10_MMC_CE_ATA_DEV_INT_ENB (1U << 10) - -/* IDMA CONTROLLER BUS MOD BIT FIELD */ -#define A10_MMC_DMAC_IDMAC_SOFT_RST (1U << 0) -#define A10_MMC_DMAC_IDMAC_FIX_BURST (1U << 1) -#define A10_MMC_DMAC_IDMAC_IDMA_ON (1U << 7) -#define A10_MMC_DMAC_IDMAC_REFETCH_DES (1U << 31) - -/* A10_MMC_IDST */ -#define A10_MMC_IDST_TX_INT (1U << 0) -#define A10_MMC_IDST_RX_INT (1U << 1) -#define A10_MMC_IDST_FATAL_BERR_INT (1U << 2) -#define A10_MMC_IDST_DES_UNAVL_INT (1U << 4) -#define A10_MMC_IDST_ERR_FLAG_SUM (1U << 5) -#define A10_MMC_IDST_NOR_INT_SUM (1U << 8) -#define A10_MMC_IDST_ABN_INT_SUM (1U << 9) -#define A10_MMC_IDST_HOST_ABT_INTX (1U << 10) -#define A10_MMC_IDST_HOST_ABT_INRX (1U << 10) -#define A10_MMC_IDST_IDLE (0U << 13) -#define A10_MMC_IDST_SUSPEND (1U << 13) -#define A10_MMC_IDST_DESC_RD (2U << 13) -#define A10_MMC_IDST_DESC_CHECK (3U << 13) -#define A10_MMC_IDST_RD_REQ_WAIT (4U << 13) -#define A10_MMC_IDST_WR_REQ_WAIT (5U << 13) -#define A10_MMC_IDST_RD (6U << 13) -#define A10_MMC_IDST_WR (7U << 13) -#define A10_MMC_IDST_DESC_CLOSE (8U << 13) -#define A10_MMC_IDST_ERROR \ - (A10_MMC_IDST_FATAL_BERR_INT | A10_MMC_IDST_ERR_FLAG_SUM | \ - A10_MMC_IDST_DES_UNAVL_INT | A10_MMC_IDST_ABN_INT_SUM) -#define A10_MMC_IDST_COMPLETE \ - (A10_MMC_IDST_TX_INT | A10_MMC_IDST_RX_INT) - -/* The DMA descriptor table. */ -struct a10_mmc_dma_desc { - uint32_t config; -#define A10_MMC_DMA_CONFIG_DIC (1U << 1) /* Disable Interrupt Completion */ -#define A10_MMC_DMA_CONFIG_LD (1U << 2) /* Last DES */ -#define A10_MMC_DMA_CONFIG_FD (1U << 3) /* First DES */ -#define A10_MMC_DMA_CONFIG_CH (1U << 4) /* CHAIN MOD */ -#define A10_MMC_DMA_CONFIG_ER (1U << 5) /* End of Ring (undocumented register) */ -#define A10_MMC_DMA_CONFIG_CES (1U << 30) /* Card Error Summary */ -#define A10_MMC_DMA_CONFIG_OWN (1U << 31) /* DES Own Flag */ - uint32_t buf_size; - uint32_t buf_addr; - uint32_t next; -}; - -#define A10_MMC_DMA_ALIGN 4 - -#endif /* _A10_MMC_H_ */ diff --git a/sys/arm/allwinner/allwinner_pinctrl.h b/sys/arm/allwinner/allwinner_pinctrl.h index b8a6c96d238..bc05a2774a3 100644 --- a/sys/arm/allwinner/allwinner_pinctrl.h +++ b/sys/arm/allwinner/allwinner_pinctrl.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2016 Emmanuel Vadot + * Copyright (c) 2016 Emmanuel Vadot * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/arm/allwinner/aw_console.c b/sys/arm/allwinner/aw_console.c deleted file mode 100644 index cf09bfba278..00000000000 --- a/sys/arm/allwinner/aw_console.c +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * Copyright (c) 2012 Ganbold Tsagaankhuu - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* Simple UART console driver for Allwinner A10 */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include - -#ifndef A10_UART_BASE -#define A10_UART_BASE 0xe1c28000 /* UART0 */ -#endif - -#define REG_SHIFT 2 - -#define UART_DLL 0 /* Out: Divisor Latch Low */ -#define UART_DLM 1 /* Out: Divisor Latch High */ -#define UART_FCR 2 /* Out: FIFO Control Register */ -#define UART_LCR 3 /* Out: Line Control Register */ -#define UART_MCR 4 /* Out: Modem Control Register */ -#define UART_LSR 5 /* In: Line Status Register */ -#define UART_LSR_THRE 0x20 /* Transmit-hold-register empty */ -#define UART_LSR_DR 0x01 /* Receiver data ready */ -#define UART_MSR 6 /* In: Modem Status Register */ -#define UART_SCR 7 /* I/O: Scratch Register */ - -static uint32_t -uart_getreg(uint32_t *bas) -{ - return *((volatile uint32_t *)(bas)) & 0xff; -} - -static void -uart_setreg(uint32_t *bas, uint32_t val) -{ - *((volatile uint32_t *)(bas)) = val; -} - -static int -ub_getc(void) -{ - while ((uart_getreg((uint32_t *)(A10_UART_BASE + - (UART_LSR << REG_SHIFT))) & UART_LSR_DR) == 0); - __asm __volatile("nop"); - - return (uart_getreg((uint32_t *)A10_UART_BASE) & 0xff); -} - -static void -ub_putc(unsigned char c) -{ - if (c == '\n') - ub_putc('\r'); - - while ((uart_getreg((uint32_t *)(A10_UART_BASE + - (UART_LSR << REG_SHIFT))) & UART_LSR_THRE) == 0) - __asm __volatile("nop"); - - uart_setreg((uint32_t *)A10_UART_BASE, c); -} - -static cn_probe_t uart_cnprobe; -static cn_init_t uart_cninit; -static cn_term_t uart_cnterm; -static cn_getc_t uart_cngetc; -static cn_putc_t uart_cnputc; -static cn_grab_t uart_cngrab; -static cn_ungrab_t uart_cnungrab; - -static void -uart_cngrab(struct consdev *cp) -{ -} - -static void -uart_cnungrab(struct consdev *cp) -{ -} - - -static void -uart_cnprobe(struct consdev *cp) -{ - sprintf(cp->cn_name, "uart"); - cp->cn_pri = CN_NORMAL; -} - -static void -uart_cninit(struct consdev *cp) -{ - uart_setreg((uint32_t *)(A10_UART_BASE + - (UART_FCR << REG_SHIFT)), 0x06); -} - -void -uart_cnputc(struct consdev *cp, int c) -{ - ub_putc(c); -} - -int -uart_cngetc(struct consdev * cp) -{ - return ub_getc(); -} - -static void -uart_cnterm(struct consdev * cp) -{ -} - -CONSOLE_DRIVER(uart); - diff --git a/sys/arm/allwinner/a10_gpio.c b/sys/arm/allwinner/aw_gpio.c similarity index 68% rename from sys/arm/allwinner/a10_gpio.c rename to sys/arm/allwinner/aw_gpio.c index d2e47cb1d38..b43654b82ad 100644 --- a/sys/arm/allwinner/a10_gpio.c +++ b/sys/arm/allwinner/aw_gpio.c @@ -62,15 +62,15 @@ __FBSDID("$FreeBSD$"); #include "gpio_if.h" -#define A10_GPIO_DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | \ +#define AW_GPIO_DEFAULT_CAPS (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | \ GPIO_PIN_PULLUP | GPIO_PIN_PULLDOWN) -#define A10_GPIO_NONE 0 -#define A10_GPIO_PULLUP 1 -#define A10_GPIO_PULLDOWN 2 +#define AW_GPIO_NONE 0 +#define AW_GPIO_PULLUP 1 +#define AW_GPIO_PULLDOWN 2 -#define A10_GPIO_INPUT 0 -#define A10_GPIO_OUTPUT 1 +#define AW_GPIO_INPUT 0 +#define AW_GPIO_OUTPUT 1 #define AW_GPIO_DRV_MASK 0x3 #define AW_GPIO_PUD_MASK 0x3 @@ -78,7 +78,7 @@ __FBSDID("$FreeBSD$"); #define AW_PINCTRL 1 #define AW_R_PINCTRL 2 -/* Defined in a10_padconf.c */ +/* Defined in aw_padconf.c */ #ifdef SOC_ALLWINNER_A10 extern const struct allwinner_padconf a10_padconf; #endif @@ -173,7 +173,7 @@ struct clk_list { clk_t clk; }; -struct a10_gpio_softc { +struct aw_gpio_softc { device_t sc_dev; device_t sc_busdev; struct mtx sc_mtx; @@ -186,46 +186,46 @@ struct a10_gpio_softc { TAILQ_HEAD(, clk_list) clk_list; }; -#define A10_GPIO_LOCK(_sc) mtx_lock_spin(&(_sc)->sc_mtx) -#define A10_GPIO_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->sc_mtx) -#define A10_GPIO_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED) +#define AW_GPIO_LOCK(_sc) mtx_lock_spin(&(_sc)->sc_mtx) +#define AW_GPIO_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->sc_mtx) +#define AW_GPIO_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->sc_mtx, MA_OWNED) -#define A10_GPIO_GP_CFG(_bank, _idx) 0x00 + ((_bank) * 0x24) + ((_idx) << 2) -#define A10_GPIO_GP_DAT(_bank) 0x10 + ((_bank) * 0x24) -#define A10_GPIO_GP_DRV(_bank, _idx) 0x14 + ((_bank) * 0x24) + ((_idx) << 2) -#define A10_GPIO_GP_PUL(_bank, _idx) 0x1c + ((_bank) * 0x24) + ((_idx) << 2) +#define AW_GPIO_GP_CFG(_bank, _idx) 0x00 + ((_bank) * 0x24) + ((_idx) << 2) +#define AW_GPIO_GP_DAT(_bank) 0x10 + ((_bank) * 0x24) +#define AW_GPIO_GP_DRV(_bank, _idx) 0x14 + ((_bank) * 0x24) + ((_idx) << 2) +#define AW_GPIO_GP_PUL(_bank, _idx) 0x1c + ((_bank) * 0x24) + ((_idx) << 2) -#define A10_GPIO_GP_INT_CFG0 0x200 -#define A10_GPIO_GP_INT_CFG1 0x204 -#define A10_GPIO_GP_INT_CFG2 0x208 -#define A10_GPIO_GP_INT_CFG3 0x20c +#define AW_GPIO_GP_INT_CFG0 0x200 +#define AW_GPIO_GP_INT_CFG1 0x204 +#define AW_GPIO_GP_INT_CFG2 0x208 +#define AW_GPIO_GP_INT_CFG3 0x20c -#define A10_GPIO_GP_INT_CTL 0x210 -#define A10_GPIO_GP_INT_STA 0x214 -#define A10_GPIO_GP_INT_DEB 0x218 +#define AW_GPIO_GP_INT_CTL 0x210 +#define AW_GPIO_GP_INT_STA 0x214 +#define AW_GPIO_GP_INT_DEB 0x218 -static char *a10_gpio_parse_function(phandle_t node); -static const char **a10_gpio_parse_pins(phandle_t node, int *pins_nb); -static uint32_t a10_gpio_parse_bias(phandle_t node); -static int a10_gpio_parse_drive_strength(phandle_t node, uint32_t *drive); +static char *aw_gpio_parse_function(phandle_t node); +static const char **aw_gpio_parse_pins(phandle_t node, int *pins_nb); +static uint32_t aw_gpio_parse_bias(phandle_t node); +static int aw_gpio_parse_drive_strength(phandle_t node, uint32_t *drive); -static int a10_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *value); -static int a10_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value); -static int a10_gpio_pin_get_locked(struct a10_gpio_softc *sc, uint32_t pin, unsigned int *value); -static int a10_gpio_pin_set_locked(struct a10_gpio_softc *sc, uint32_t pin, unsigned int value); +static int aw_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *value); +static int aw_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value); +static int aw_gpio_pin_get_locked(struct aw_gpio_softc *sc, uint32_t pin, unsigned int *value); +static int aw_gpio_pin_set_locked(struct aw_gpio_softc *sc, uint32_t pin, unsigned int value); -#define A10_GPIO_WRITE(_sc, _off, _val) \ +#define AW_GPIO_WRITE(_sc, _off, _val) \ bus_space_write_4(_sc->sc_bst, _sc->sc_bsh, _off, _val) -#define A10_GPIO_READ(_sc, _off) \ +#define AW_GPIO_READ(_sc, _off) \ bus_space_read_4(_sc->sc_bst, _sc->sc_bsh, _off) static uint32_t -a10_gpio_get_function(struct a10_gpio_softc *sc, uint32_t pin) +aw_gpio_get_function(struct aw_gpio_softc *sc, uint32_t pin) { uint32_t bank, func, offset; /* Must be called with lock held. */ - A10_GPIO_LOCK_ASSERT(sc); + AW_GPIO_LOCK_ASSERT(sc); if (pin > sc->padconf->npins) return (0); @@ -233,13 +233,13 @@ a10_gpio_get_function(struct a10_gpio_softc *sc, uint32_t pin) pin = sc->padconf->pins[pin].pin; offset = ((pin & 0x07) << 2); - func = A10_GPIO_READ(sc, A10_GPIO_GP_CFG(bank, pin >> 3)); + func = AW_GPIO_READ(sc, AW_GPIO_GP_CFG(bank, pin >> 3)); return ((func >> offset) & 0x7); } static int -a10_gpio_set_function(struct a10_gpio_softc *sc, uint32_t pin, uint32_t f) +aw_gpio_set_function(struct aw_gpio_softc *sc, uint32_t pin, uint32_t f) { uint32_t bank, data, offset; @@ -248,127 +248,127 @@ a10_gpio_set_function(struct a10_gpio_softc *sc, uint32_t pin, uint32_t f) return (EINVAL); /* Must be called with lock held. */ - A10_GPIO_LOCK_ASSERT(sc); + AW_GPIO_LOCK_ASSERT(sc); bank = sc->padconf->pins[pin].port; pin = sc->padconf->pins[pin].pin; offset = ((pin & 0x07) << 2); - data = A10_GPIO_READ(sc, A10_GPIO_GP_CFG(bank, pin >> 3)); + data = AW_GPIO_READ(sc, AW_GPIO_GP_CFG(bank, pin >> 3)); data &= ~(7 << offset); data |= (f << offset); - A10_GPIO_WRITE(sc, A10_GPIO_GP_CFG(bank, pin >> 3), data); + AW_GPIO_WRITE(sc, AW_GPIO_GP_CFG(bank, pin >> 3), data); return (0); } static uint32_t -a10_gpio_get_pud(struct a10_gpio_softc *sc, uint32_t pin) +aw_gpio_get_pud(struct aw_gpio_softc *sc, uint32_t pin) { uint32_t bank, offset, val; /* Must be called with lock held. */ - A10_GPIO_LOCK_ASSERT(sc); + AW_GPIO_LOCK_ASSERT(sc); bank = sc->padconf->pins[pin].port; pin = sc->padconf->pins[pin].pin; offset = ((pin & 0x0f) << 1); - val = A10_GPIO_READ(sc, A10_GPIO_GP_PUL(bank, pin >> 4)); + val = AW_GPIO_READ(sc, AW_GPIO_GP_PUL(bank, pin >> 4)); return ((val >> offset) & AW_GPIO_PUD_MASK); } static void -a10_gpio_set_pud(struct a10_gpio_softc *sc, uint32_t pin, uint32_t state) +aw_gpio_set_pud(struct aw_gpio_softc *sc, uint32_t pin, uint32_t state) { uint32_t bank, offset, val; - if (a10_gpio_get_pud(sc, pin) == state) + if (aw_gpio_get_pud(sc, pin) == state) return; /* Must be called with lock held. */ - A10_GPIO_LOCK_ASSERT(sc); + AW_GPIO_LOCK_ASSERT(sc); bank = sc->padconf->pins[pin].port; pin = sc->padconf->pins[pin].pin; offset = ((pin & 0x0f) << 1); - val = A10_GPIO_READ(sc, A10_GPIO_GP_PUL(bank, pin >> 4)); + val = AW_GPIO_READ(sc, AW_GPIO_GP_PUL(bank, pin >> 4)); val &= ~(AW_GPIO_PUD_MASK << offset); val |= (state << offset); - A10_GPIO_WRITE(sc, A10_GPIO_GP_PUL(bank, pin >> 4), val); + AW_GPIO_WRITE(sc, AW_GPIO_GP_PUL(bank, pin >> 4), val); } static uint32_t -a10_gpio_get_drv(struct a10_gpio_softc *sc, uint32_t pin) +aw_gpio_get_drv(struct aw_gpio_softc *sc, uint32_t pin) { uint32_t bank, offset, val; /* Must be called with lock held. */ - A10_GPIO_LOCK_ASSERT(sc); + AW_GPIO_LOCK_ASSERT(sc); bank = sc->padconf->pins[pin].port; pin = sc->padconf->pins[pin].pin; offset = ((pin & 0x0f) << 1); - val = A10_GPIO_READ(sc, A10_GPIO_GP_DRV(bank, pin >> 4)); + val = AW_GPIO_READ(sc, AW_GPIO_GP_DRV(bank, pin >> 4)); return ((val >> offset) & AW_GPIO_DRV_MASK); } static void -a10_gpio_set_drv(struct a10_gpio_softc *sc, uint32_t pin, uint32_t drive) +aw_gpio_set_drv(struct aw_gpio_softc *sc, uint32_t pin, uint32_t drive) { uint32_t bank, offset, val; - if (a10_gpio_get_drv(sc, pin) == drive) + if (aw_gpio_get_drv(sc, pin) == drive) return; /* Must be called with lock held. */ - A10_GPIO_LOCK_ASSERT(sc); + AW_GPIO_LOCK_ASSERT(sc); bank = sc->padconf->pins[pin].port; pin = sc->padconf->pins[pin].pin; offset = ((pin & 0x0f) << 1); - val = A10_GPIO_READ(sc, A10_GPIO_GP_DRV(bank, pin >> 4)); + val = AW_GPIO_READ(sc, AW_GPIO_GP_DRV(bank, pin >> 4)); val &= ~(AW_GPIO_DRV_MASK << offset); val |= (drive << offset); - A10_GPIO_WRITE(sc, A10_GPIO_GP_DRV(bank, pin >> 4), val); + AW_GPIO_WRITE(sc, AW_GPIO_GP_DRV(bank, pin >> 4), val); } static int -a10_gpio_pin_configure(struct a10_gpio_softc *sc, uint32_t pin, uint32_t flags) +aw_gpio_pin_configure(struct aw_gpio_softc *sc, uint32_t pin, uint32_t flags) { u_int val; int err = 0; /* Must be called with lock held. */ - A10_GPIO_LOCK_ASSERT(sc); + AW_GPIO_LOCK_ASSERT(sc); if (pin > sc->padconf->npins) return (EINVAL); /* Manage input/output. */ if (flags & GPIO_PIN_INPUT) { - err = a10_gpio_set_function(sc, pin, A10_GPIO_INPUT); + err = aw_gpio_set_function(sc, pin, AW_GPIO_INPUT); } else if ((flags & GPIO_PIN_OUTPUT) && - a10_gpio_get_function(sc, pin) != A10_GPIO_OUTPUT) { + aw_gpio_get_function(sc, pin) != AW_GPIO_OUTPUT) { if (flags & GPIO_PIN_PRESET_LOW) { - a10_gpio_pin_set_locked(sc, pin, 0); + aw_gpio_pin_set_locked(sc, pin, 0); } else if (flags & GPIO_PIN_PRESET_HIGH) { - a10_gpio_pin_set_locked(sc, pin, 1); + aw_gpio_pin_set_locked(sc, pin, 1); } else { /* Read the pin and preset output to current state. */ - err = a10_gpio_set_function(sc, pin, A10_GPIO_INPUT); + err = aw_gpio_set_function(sc, pin, AW_GPIO_INPUT); if (err == 0) { - a10_gpio_pin_get_locked(sc, pin, &val); - a10_gpio_pin_set_locked(sc, pin, val); + aw_gpio_pin_get_locked(sc, pin, &val); + aw_gpio_pin_set_locked(sc, pin, val); } } if (err == 0) - err = a10_gpio_set_function(sc, pin, A10_GPIO_OUTPUT); + err = aw_gpio_set_function(sc, pin, AW_GPIO_OUTPUT); } if (err) @@ -376,19 +376,19 @@ a10_gpio_pin_configure(struct a10_gpio_softc *sc, uint32_t pin, uint32_t flags) /* Manage Pull-up/pull-down. */ if (flags & GPIO_PIN_PULLUP) - a10_gpio_set_pud(sc, pin, A10_GPIO_PULLUP); + aw_gpio_set_pud(sc, pin, AW_GPIO_PULLUP); else if (flags & GPIO_PIN_PULLDOWN) - a10_gpio_set_pud(sc, pin, A10_GPIO_PULLDOWN); + aw_gpio_set_pud(sc, pin, AW_GPIO_PULLDOWN); else - a10_gpio_set_pud(sc, pin, A10_GPIO_NONE); + aw_gpio_set_pud(sc, pin, AW_GPIO_NONE); return (0); } static device_t -a10_gpio_get_bus(device_t dev) +aw_gpio_get_bus(device_t dev) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; sc = device_get_softc(dev); @@ -396,9 +396,9 @@ a10_gpio_get_bus(device_t dev) } static int -a10_gpio_pin_max(device_t dev, int *maxpin) +aw_gpio_pin_max(device_t dev, int *maxpin) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; sc = device_get_softc(dev); @@ -407,23 +407,23 @@ a10_gpio_pin_max(device_t dev, int *maxpin) } static int -a10_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps) +aw_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; sc = device_get_softc(dev); if (pin >= sc->padconf->npins) return (EINVAL); - *caps = A10_GPIO_DEFAULT_CAPS; + *caps = AW_GPIO_DEFAULT_CAPS; return (0); } static int -a10_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) +aw_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; uint32_t func; uint32_t pud; @@ -431,13 +431,13 @@ a10_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) if (pin >= sc->padconf->npins) return (EINVAL); - A10_GPIO_LOCK(sc); - func = a10_gpio_get_function(sc, pin); + AW_GPIO_LOCK(sc); + func = aw_gpio_get_function(sc, pin); switch (func) { - case A10_GPIO_INPUT: + case AW_GPIO_INPUT: *flags = GPIO_PIN_INPUT; break; - case A10_GPIO_OUTPUT: + case AW_GPIO_OUTPUT: *flags = GPIO_PIN_OUTPUT; break; default: @@ -445,27 +445,27 @@ a10_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) break; } - pud = a10_gpio_get_pud(sc, pin); + pud = aw_gpio_get_pud(sc, pin); switch (pud) { - case A10_GPIO_PULLDOWN: + case AW_GPIO_PULLDOWN: *flags |= GPIO_PIN_PULLDOWN; break; - case A10_GPIO_PULLUP: + case AW_GPIO_PULLUP: *flags |= GPIO_PIN_PULLUP; break; default: break; } - A10_GPIO_UNLOCK(sc); + AW_GPIO_UNLOCK(sc); return (0); } static int -a10_gpio_pin_getname(device_t dev, uint32_t pin, char *name) +aw_gpio_pin_getname(device_t dev, uint32_t pin, char *name) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; sc = device_get_softc(dev); if (pin >= sc->padconf->npins) @@ -479,29 +479,29 @@ a10_gpio_pin_getname(device_t dev, uint32_t pin, char *name) } static int -a10_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) +aw_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; int err; sc = device_get_softc(dev); if (pin > sc->padconf->npins) return (EINVAL); - A10_GPIO_LOCK(sc); - err = a10_gpio_pin_configure(sc, pin, flags); - A10_GPIO_UNLOCK(sc); + AW_GPIO_LOCK(sc); + err = aw_gpio_pin_configure(sc, pin, flags); + AW_GPIO_UNLOCK(sc); return (err); } static int -a10_gpio_pin_set_locked(struct a10_gpio_softc *sc, uint32_t pin, +aw_gpio_pin_set_locked(struct aw_gpio_softc *sc, uint32_t pin, unsigned int value) { uint32_t bank, data; - A10_GPIO_LOCK_ASSERT(sc); + AW_GPIO_LOCK_ASSERT(sc); if (pin > sc->padconf->npins) return (EINVAL); @@ -509,38 +509,38 @@ a10_gpio_pin_set_locked(struct a10_gpio_softc *sc, uint32_t pin, bank = sc->padconf->pins[pin].port; pin = sc->padconf->pins[pin].pin; - data = A10_GPIO_READ(sc, A10_GPIO_GP_DAT(bank)); + data = AW_GPIO_READ(sc, AW_GPIO_GP_DAT(bank)); if (value) data |= (1 << pin); else data &= ~(1 << pin); - A10_GPIO_WRITE(sc, A10_GPIO_GP_DAT(bank), data); + AW_GPIO_WRITE(sc, AW_GPIO_GP_DAT(bank), data); return (0); } static int -a10_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value) +aw_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; int ret; sc = device_get_softc(dev); - A10_GPIO_LOCK(sc); - ret = a10_gpio_pin_set_locked(sc, pin, value); - A10_GPIO_UNLOCK(sc); + AW_GPIO_LOCK(sc); + ret = aw_gpio_pin_set_locked(sc, pin, value); + AW_GPIO_UNLOCK(sc); return (ret); } static int -a10_gpio_pin_get_locked(struct a10_gpio_softc *sc,uint32_t pin, +aw_gpio_pin_get_locked(struct aw_gpio_softc *sc,uint32_t pin, unsigned int *val) { uint32_t bank, reg_data; - A10_GPIO_LOCK_ASSERT(sc); + AW_GPIO_LOCK_ASSERT(sc); if (pin > sc->padconf->npins) return (EINVAL); @@ -548,14 +548,14 @@ a10_gpio_pin_get_locked(struct a10_gpio_softc *sc,uint32_t pin, bank = sc->padconf->pins[pin].port; pin = sc->padconf->pins[pin].pin; - reg_data = A10_GPIO_READ(sc, A10_GPIO_GP_DAT(bank)); + reg_data = AW_GPIO_READ(sc, AW_GPIO_GP_DAT(bank)); *val = (reg_data & (1 << pin)) ? 1 : 0; return (0); } static char * -a10_gpio_parse_function(phandle_t node) +aw_gpio_parse_function(phandle_t node) { char *function; @@ -570,7 +570,7 @@ a10_gpio_parse_function(phandle_t node) } static const char ** -a10_gpio_parse_pins(phandle_t node, int *pins_nb) +aw_gpio_parse_pins(phandle_t node, int *pins_nb) { const char **pinlist; @@ -587,7 +587,7 @@ a10_gpio_parse_pins(phandle_t node, int *pins_nb) } static uint32_t -a10_gpio_parse_bias(phandle_t node) +aw_gpio_parse_bias(phandle_t node) { uint32_t bias; @@ -596,17 +596,17 @@ a10_gpio_parse_bias(phandle_t node) if (OF_getencprop(node, "allwinner,pull", &bias, sizeof(bias)) != -1) return (bias); if (OF_hasprop(node, "bias-disable")) - return (A10_GPIO_NONE); + return (AW_GPIO_NONE); if (OF_hasprop(node, "bias-pull-up")) - return (A10_GPIO_PULLUP); + return (AW_GPIO_PULLUP); if (OF_hasprop(node, "bias-pull-down")) - return (A10_GPIO_PULLDOWN); + return (AW_GPIO_PULLDOWN); - return (A10_GPIO_NONE); + return (AW_GPIO_NONE); } static int -a10_gpio_parse_drive_strength(phandle_t node, uint32_t *drive) +aw_gpio_parse_drive_strength(phandle_t node, uint32_t *drive) { uint32_t drive_str; @@ -624,24 +624,24 @@ a10_gpio_parse_drive_strength(phandle_t node, uint32_t *drive) } static int -a10_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val) +aw_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; int ret; sc = device_get_softc(dev); - A10_GPIO_LOCK(sc); - ret = a10_gpio_pin_get_locked(sc, pin, val); - A10_GPIO_UNLOCK(sc); + AW_GPIO_LOCK(sc); + ret = aw_gpio_pin_get_locked(sc, pin, val); + AW_GPIO_UNLOCK(sc); return (ret); } static int -a10_gpio_pin_toggle(device_t dev, uint32_t pin) +aw_gpio_pin_toggle(device_t dev, uint32_t pin) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; uint32_t bank, data; sc = device_get_softc(dev); @@ -651,23 +651,23 @@ a10_gpio_pin_toggle(device_t dev, uint32_t pin) bank = sc->padconf->pins[pin].port; pin = sc->padconf->pins[pin].pin; - A10_GPIO_LOCK(sc); - data = A10_GPIO_READ(sc, A10_GPIO_GP_DAT(bank)); + AW_GPIO_LOCK(sc); + data = AW_GPIO_READ(sc, AW_GPIO_GP_DAT(bank)); if (data & (1 << pin)) data &= ~(1 << pin); else data |= (1 << pin); - A10_GPIO_WRITE(sc, A10_GPIO_GP_DAT(bank), data); - A10_GPIO_UNLOCK(sc); + AW_GPIO_WRITE(sc, AW_GPIO_GP_DAT(bank), data); + AW_GPIO_UNLOCK(sc); return (0); } static int -a10_gpio_pin_access_32(device_t dev, uint32_t first_pin, uint32_t clear_pins, +aw_gpio_pin_access_32(device_t dev, uint32_t first_pin, uint32_t clear_pins, uint32_t change_pins, uint32_t *orig_pins) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; uint32_t bank, data, pin; sc = device_get_softc(dev); @@ -685,12 +685,12 @@ a10_gpio_pin_access_32(device_t dev, uint32_t first_pin, uint32_t clear_pins, if (pin != 0) return (EINVAL); - A10_GPIO_LOCK(sc); - data = A10_GPIO_READ(sc, A10_GPIO_GP_DAT(bank)); + AW_GPIO_LOCK(sc); + data = AW_GPIO_READ(sc, AW_GPIO_GP_DAT(bank)); if ((clear_pins | change_pins) != 0) - A10_GPIO_WRITE(sc, A10_GPIO_GP_DAT(bank), + AW_GPIO_WRITE(sc, AW_GPIO_GP_DAT(bank), (data & ~clear_pins) ^ change_pins); - A10_GPIO_UNLOCK(sc); + AW_GPIO_UNLOCK(sc); if (orig_pins != NULL) *orig_pins = data; @@ -699,10 +699,10 @@ a10_gpio_pin_access_32(device_t dev, uint32_t first_pin, uint32_t clear_pins, } static int -a10_gpio_pin_config_32(device_t dev, uint32_t first_pin, uint32_t num_pins, +aw_gpio_pin_config_32(device_t dev, uint32_t first_pin, uint32_t num_pins, uint32_t *pin_flags) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; uint32_t bank, pin; int err; @@ -724,14 +724,14 @@ a10_gpio_pin_config_32(device_t dev, uint32_t first_pin, uint32_t num_pins, */ for (err = 0, pin = first_pin; err == 0 && pin < num_pins; ++pin) { if (pin_flags[pin] & (GPIO_PIN_INPUT | GPIO_PIN_OUTPUT)) - err = a10_gpio_pin_configure(sc, pin, pin_flags[pin]); + err = aw_gpio_pin_configure(sc, pin, pin_flags[pin]); } return (err); } static int -aw_find_pinnum_by_name(struct a10_gpio_softc *sc, const char *pinname) +aw_find_pinnum_by_name(struct aw_gpio_softc *sc, const char *pinname) { int i; @@ -743,7 +743,7 @@ aw_find_pinnum_by_name(struct a10_gpio_softc *sc, const char *pinname) } static int -aw_find_pin_func(struct a10_gpio_softc *sc, int pin, const char *func) +aw_find_pin_func(struct aw_gpio_softc *sc, int pin, const char *func) { int i; @@ -758,7 +758,7 @@ aw_find_pin_func(struct a10_gpio_softc *sc, int pin, const char *func) static int aw_fdt_configure_pins(device_t dev, phandle_t cfgxref) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; phandle_t node; const char **pinlist = NULL; char *pin_function = NULL; @@ -772,20 +772,20 @@ aw_fdt_configure_pins(device_t dev, phandle_t cfgxref) set_drive = false; /* Getting all prop for configuring pins */ - pinlist = a10_gpio_parse_pins(node, &pins_nb); + pinlist = aw_gpio_parse_pins(node, &pins_nb); if (pinlist == NULL) return (ENOENT); - pin_function = a10_gpio_parse_function(node); + pin_function = aw_gpio_parse_function(node); if (pin_function == NULL) { ret = ENOENT; goto out; } - if (a10_gpio_parse_drive_strength(node, &pin_drive) == 0) + if (aw_gpio_parse_drive_strength(node, &pin_drive) == 0) set_drive = true; - pin_pull = a10_gpio_parse_bias(node); + pin_pull = aw_gpio_parse_bias(node); /* Configure each pin to the correct function, drive and pull */ for (i = 0; i < pins_nb; i++) { @@ -800,16 +800,16 @@ aw_fdt_configure_pins(device_t dev, phandle_t cfgxref) goto out; } - A10_GPIO_LOCK(sc); + AW_GPIO_LOCK(sc); - if (a10_gpio_get_function(sc, pin_num) != pin_func) - a10_gpio_set_function(sc, pin_num, pin_func); + if (aw_gpio_get_function(sc, pin_num) != pin_func) + aw_gpio_set_function(sc, pin_num, pin_func); if (set_drive) - a10_gpio_set_drv(sc, pin_num, pin_drive); - if (pin_pull != A10_GPIO_NONE) - a10_gpio_set_pud(sc, pin_num, pin_pull); + aw_gpio_set_drv(sc, pin_num, pin_drive); + if (pin_pull != AW_GPIO_NONE) + aw_gpio_set_pud(sc, pin_num, pin_pull); - A10_GPIO_UNLOCK(sc); + AW_GPIO_UNLOCK(sc); } out: @@ -819,7 +819,7 @@ aw_fdt_configure_pins(device_t dev, phandle_t cfgxref) } static int -a10_gpio_probe(device_t dev) +aw_gpio_probe(device_t dev) { if (!ofw_bus_status_okay(dev)) @@ -833,11 +833,11 @@ a10_gpio_probe(device_t dev) } static int -a10_gpio_attach(device_t dev) +aw_gpio_attach(device_t dev) { int rid, error; phandle_t gpio; - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; struct clk_list *clkp, *clkp_tmp; clk_t clk; hwreset_t rst = NULL; @@ -846,7 +846,7 @@ a10_gpio_attach(device_t dev) sc = device_get_softc(dev); sc->sc_dev = dev; - mtx_init(&sc->sc_mtx, "a10 gpio", "gpio", MTX_SPIN); + mtx_init(&sc->sc_mtx, "aw gpio", "gpio", MTX_SPIN); rid = 0; sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, @@ -951,14 +951,14 @@ a10_gpio_attach(device_t dev) } static int -a10_gpio_detach(device_t dev) +aw_gpio_detach(device_t dev) { return (EBUSY); } static phandle_t -a10_gpio_get_node(device_t dev, device_t bus) +aw_gpio_get_node(device_t dev, device_t bus) { /* We only have one child, the GPIO bus, which needs our own node. */ @@ -966,10 +966,10 @@ a10_gpio_get_node(device_t dev, device_t bus) } static int -a10_gpio_map_gpios(device_t bus, phandle_t dev, phandle_t gparent, int gcells, +aw_gpio_map_gpios(device_t bus, phandle_t dev, phandle_t gparent, int gcells, pcell_t *gpios, uint32_t *pin, uint32_t *flags) { - struct a10_gpio_softc *sc; + struct aw_gpio_softc *sc; int i; sc = device_get_softc(bus); @@ -986,28 +986,28 @@ a10_gpio_map_gpios(device_t bus, phandle_t dev, phandle_t gparent, int gcells, return (0); } -static device_method_t a10_gpio_methods[] = { +static device_method_t aw_gpio_methods[] = { /* Device interface */ - DEVMETHOD(device_probe, a10_gpio_probe), - DEVMETHOD(device_attach, a10_gpio_attach), - DEVMETHOD(device_detach, a10_gpio_detach), + DEVMETHOD(device_probe, aw_gpio_probe), + DEVMETHOD(device_attach, aw_gpio_attach), + DEVMETHOD(device_detach, aw_gpio_detach), /* GPIO protocol */ - DEVMETHOD(gpio_get_bus, a10_gpio_get_bus), - DEVMETHOD(gpio_pin_max, a10_gpio_pin_max), - DEVMETHOD(gpio_pin_getname, a10_gpio_pin_getname), - DEVMETHOD(gpio_pin_getflags, a10_gpio_pin_getflags), - DEVMETHOD(gpio_pin_getcaps, a10_gpio_pin_getcaps), - DEVMETHOD(gpio_pin_setflags, a10_gpio_pin_setflags), - DEVMETHOD(gpio_pin_get, a10_gpio_pin_get), - DEVMETHOD(gpio_pin_set, a10_gpio_pin_set), - DEVMETHOD(gpio_pin_toggle, a10_gpio_pin_toggle), - DEVMETHOD(gpio_pin_access_32, a10_gpio_pin_access_32), - DEVMETHOD(gpio_pin_config_32, a10_gpio_pin_config_32), - DEVMETHOD(gpio_map_gpios, a10_gpio_map_gpios), + DEVMETHOD(gpio_get_bus, aw_gpio_get_bus), + DEVMETHOD(gpio_pin_max, aw_gpio_pin_max), + DEVMETHOD(gpio_pin_getname, aw_gpio_pin_getname), + DEVMETHOD(gpio_pin_getflags, aw_gpio_pin_getflags), + DEVMETHOD(gpio_pin_getcaps, aw_gpio_pin_getcaps), + DEVMETHOD(gpio_pin_setflags, aw_gpio_pin_setflags), + DEVMETHOD(gpio_pin_get, aw_gpio_pin_get), + DEVMETHOD(gpio_pin_set, aw_gpio_pin_set), + DEVMETHOD(gpio_pin_toggle, aw_gpio_pin_toggle), + DEVMETHOD(gpio_pin_access_32, aw_gpio_pin_access_32), + DEVMETHOD(gpio_pin_config_32, aw_gpio_pin_config_32), + DEVMETHOD(gpio_map_gpios, aw_gpio_map_gpios), /* ofw_bus interface */ - DEVMETHOD(ofw_bus_get_node, a10_gpio_get_node), + DEVMETHOD(ofw_bus_get_node, aw_gpio_get_node), /* fdt_pinctrl interface */ DEVMETHOD(fdt_pinctrl_configure,aw_fdt_configure_pins), @@ -1015,13 +1015,13 @@ static device_method_t a10_gpio_methods[] = { DEVMETHOD_END }; -static devclass_t a10_gpio_devclass; +static devclass_t aw_gpio_devclass; -static driver_t a10_gpio_driver = { +static driver_t aw_gpio_driver = { "gpio", - a10_gpio_methods, - sizeof(struct a10_gpio_softc), + aw_gpio_methods, + sizeof(struct aw_gpio_softc), }; -EARLY_DRIVER_MODULE(a10_gpio, simplebus, a10_gpio_driver, a10_gpio_devclass, 0, 0, +EARLY_DRIVER_MODULE(aw_gpio, simplebus, aw_gpio_driver, aw_gpio_devclass, 0, 0, BUS_PASS_INTERRUPT + BUS_PASS_ORDER_LATE); diff --git a/sys/arm/allwinner/aw_mmc.c b/sys/arm/allwinner/aw_mmc.c new file mode 100644 index 00000000000..c218dc44852 --- /dev/null +++ b/sys/arm/allwinner/aw_mmc.c @@ -0,0 +1,922 @@ +/*- + * Copyright (c) 2013 Alexander Fedorov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include +#include +#include + +#define AW_MMC_MEMRES 0 +#define AW_MMC_IRQRES 1 +#define AW_MMC_RESSZ 2 +#define AW_MMC_DMA_SEGS ((MAXPHYS / PAGE_SIZE) + 1) +#define AW_MMC_DMA_MAX_SIZE 0x2000 +#define AW_MMC_DMA_FTRGLEVEL 0x20070008 +#define AW_MMC_RESET_RETRY 1000 + +#define CARD_ID_FREQUENCY 400000 + +static struct ofw_compat_data compat_data[] = { + {"allwinner,sun4i-a10-mmc", 1}, + {"allwinner,sun5i-a13-mmc", 1}, + {"allwinner,sun7i-a20-mmc", 1}, + {"allwinner,sun50i-a64-mmc", 1}, + {NULL, 0} +}; + +struct aw_mmc_softc { + device_t aw_dev; + clk_t aw_clk_ahb; + clk_t aw_clk_mmc; + hwreset_t aw_rst_ahb; + int aw_bus_busy; + int aw_resid; + int aw_timeout; + struct callout aw_timeoutc; + struct mmc_host aw_host; + struct mmc_request * aw_req; + struct mtx aw_mtx; + struct resource * aw_res[AW_MMC_RESSZ]; + uint32_t aw_intr; + uint32_t aw_intr_wait; + void * aw_intrhand; + + /* Fields required for DMA access. */ + bus_addr_t aw_dma_desc_phys; + bus_dmamap_t aw_dma_map; + bus_dma_tag_t aw_dma_tag; + void * aw_dma_desc; + bus_dmamap_t aw_dma_buf_map; + bus_dma_tag_t aw_dma_buf_tag; + int aw_dma_map_err; +}; + +static struct resource_spec aw_mmc_res_spec[] = { + { SYS_RES_MEMORY, 0, RF_ACTIVE }, + { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE }, + { -1, 0, 0 } +}; + +static int aw_mmc_probe(device_t); +static int aw_mmc_attach(device_t); +static int aw_mmc_detach(device_t); +static int aw_mmc_setup_dma(struct aw_mmc_softc *); +static int aw_mmc_reset(struct aw_mmc_softc *); +static void aw_mmc_intr(void *); +static int aw_mmc_update_clock(struct aw_mmc_softc *, uint32_t); + +static int aw_mmc_update_ios(device_t, device_t); +static int aw_mmc_request(device_t, device_t, struct mmc_request *); +static int aw_mmc_get_ro(device_t, device_t); +static int aw_mmc_acquire_host(device_t, device_t); +static int aw_mmc_release_host(device_t, device_t); + +#define AW_MMC_LOCK(_sc) mtx_lock(&(_sc)->aw_mtx) +#define AW_MMC_UNLOCK(_sc) mtx_unlock(&(_sc)->aw_mtx) +#define AW_MMC_READ_4(_sc, _reg) \ + bus_read_4((_sc)->aw_res[AW_MMC_MEMRES], _reg) +#define AW_MMC_WRITE_4(_sc, _reg, _value) \ + bus_write_4((_sc)->aw_res[AW_MMC_MEMRES], _reg, _value) + +static int +aw_mmc_probe(device_t dev) +{ + + if (!ofw_bus_status_okay(dev)) + return (ENXIO); + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) + return (ENXIO); + + device_set_desc(dev, "Allwinner Integrated MMC/SD controller"); + + return (BUS_PROBE_DEFAULT); +} + +static int +aw_mmc_attach(device_t dev) +{ + device_t child; + struct aw_mmc_softc *sc; + struct sysctl_ctx_list *ctx; + struct sysctl_oid_list *tree; + uint32_t bus_width; + phandle_t node; + int error; + + node = ofw_bus_get_node(dev); + sc = device_get_softc(dev); + sc->aw_dev = dev; + sc->aw_req = NULL; + if (bus_alloc_resources(dev, aw_mmc_res_spec, sc->aw_res) != 0) { + device_printf(dev, "cannot allocate device resources\n"); + return (ENXIO); + } + if (bus_setup_intr(dev, sc->aw_res[AW_MMC_IRQRES], + INTR_TYPE_MISC | INTR_MPSAFE, NULL, aw_mmc_intr, sc, + &sc->aw_intrhand)) { + bus_release_resources(dev, aw_mmc_res_spec, sc->aw_res); + device_printf(dev, "cannot setup interrupt handler\n"); + return (ENXIO); + } + mtx_init(&sc->aw_mtx, device_get_nameunit(sc->aw_dev), "aw_mmc", + MTX_DEF); + callout_init_mtx(&sc->aw_timeoutc, &sc->aw_mtx, 0); + + /* De-assert reset */ + if (hwreset_get_by_ofw_name(dev, 0, "ahb", &sc->aw_rst_ahb) == 0) { + error = hwreset_deassert(sc->aw_rst_ahb); + if (error != 0) { + device_printf(dev, "cannot de-assert reset\n"); + goto fail; + } + } + + /* Activate the module clock. */ + error = clk_get_by_ofw_name(dev, 0, "ahb", &sc->aw_clk_ahb); + if (error != 0) { + device_printf(dev, "cannot get ahb clock\n"); + goto fail; + } + error = clk_enable(sc->aw_clk_ahb); + if (error != 0) { + device_printf(dev, "cannot enable ahb clock\n"); + goto fail; + } + error = clk_get_by_ofw_name(dev, 0, "mmc", &sc->aw_clk_mmc); + if (error != 0) { + device_printf(dev, "cannot get mmc clock\n"); + goto fail; + } + error = clk_set_freq(sc->aw_clk_mmc, CARD_ID_FREQUENCY, + CLK_SET_ROUND_DOWN); + if (error != 0) { + device_printf(dev, "cannot init mmc clock\n"); + goto fail; + } + error = clk_enable(sc->aw_clk_mmc); + if (error != 0) { + device_printf(dev, "cannot enable mmc clock\n"); + goto fail; + } + + sc->aw_timeout = 10; + ctx = device_get_sysctl_ctx(dev); + tree = SYSCTL_CHILDREN(device_get_sysctl_tree(dev)); + SYSCTL_ADD_INT(ctx, tree, OID_AUTO, "req_timeout", CTLFLAG_RW, + &sc->aw_timeout, 0, "Request timeout in seconds"); + + /* Hardware reset */ + AW_MMC_WRITE_4(sc, AW_MMC_HWRST, 1); + DELAY(100); + AW_MMC_WRITE_4(sc, AW_MMC_HWRST, 0); + DELAY(500); + + /* Soft Reset controller. */ + if (aw_mmc_reset(sc) != 0) { + device_printf(dev, "cannot reset the controller\n"); + goto fail; + } + + if (aw_mmc_setup_dma(sc) != 0) { + device_printf(sc->aw_dev, "Couldn't setup DMA!\n"); + goto fail; + } + + if (OF_getencprop(node, "bus-width", &bus_width, sizeof(uint32_t)) <= 0) + bus_width = 4; + + sc->aw_host.f_min = 400000; + sc->aw_host.f_max = 52000000; + sc->aw_host.host_ocr = MMC_OCR_320_330 | MMC_OCR_330_340; + sc->aw_host.mode = mode_sd; + sc->aw_host.caps = MMC_CAP_HSPEED; + if (bus_width >= 4) + sc->aw_host.caps |= MMC_CAP_4_BIT_DATA; + if (bus_width >= 8) + sc->aw_host.caps |= MMC_CAP_8_BIT_DATA; + + child = device_add_child(dev, "mmc", -1); + if (child == NULL) { + device_printf(dev, "attaching MMC bus failed!\n"); + goto fail; + } + if (device_probe_and_attach(child) != 0) { + device_printf(dev, "attaching MMC child failed!\n"); + device_delete_child(dev, child); + goto fail; + } + + return (0); + +fail: + callout_drain(&sc->aw_timeoutc); + mtx_destroy(&sc->aw_mtx); + bus_teardown_intr(dev, sc->aw_res[AW_MMC_IRQRES], sc->aw_intrhand); + bus_release_resources(dev, aw_mmc_res_spec, sc->aw_res); + + return (ENXIO); +} + +static int +aw_mmc_detach(device_t dev) +{ + + return (EBUSY); +} + +static void +aw_dma_desc_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int err) +{ + struct aw_mmc_softc *sc; + + sc = (struct aw_mmc_softc *)arg; + if (err) { + sc->aw_dma_map_err = err; + return; + } + sc->aw_dma_desc_phys = segs[0].ds_addr; +} + +static int +aw_mmc_setup_dma(struct aw_mmc_softc *sc) +{ + int dma_desc_size, error; + + /* Allocate the DMA descriptor memory. */ + dma_desc_size = sizeof(struct aw_mmc_dma_desc) * AW_MMC_DMA_SEGS; + error = bus_dma_tag_create(bus_get_dma_tag(sc->aw_dev), + AW_MMC_DMA_ALIGN, 0, + BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, + dma_desc_size, 1, dma_desc_size, 0, NULL, NULL, &sc->aw_dma_tag); + if (error) + return (error); + error = bus_dmamem_alloc(sc->aw_dma_tag, &sc->aw_dma_desc, + BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->aw_dma_map); + if (error) + return (error); + + error = bus_dmamap_load(sc->aw_dma_tag, sc->aw_dma_map, + sc->aw_dma_desc, dma_desc_size, aw_dma_desc_cb, sc, 0); + if (error) + return (error); + if (sc->aw_dma_map_err) + return (sc->aw_dma_map_err); + + /* Create the DMA map for data transfers. */ + error = bus_dma_tag_create(bus_get_dma_tag(sc->aw_dev), + AW_MMC_DMA_ALIGN, 0, + BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, + AW_MMC_DMA_MAX_SIZE * AW_MMC_DMA_SEGS, AW_MMC_DMA_SEGS, + AW_MMC_DMA_MAX_SIZE, BUS_DMA_ALLOCNOW, NULL, NULL, + &sc->aw_dma_buf_tag); + if (error) + return (error); + error = bus_dmamap_create(sc->aw_dma_buf_tag, 0, + &sc->aw_dma_buf_map); + if (error) + return (error); + + return (0); +} + +static void +aw_dma_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int err) +{ + int i; + struct aw_mmc_dma_desc *dma_desc; + struct aw_mmc_softc *sc; + + sc = (struct aw_mmc_softc *)arg; + sc->aw_dma_map_err = err; + + if (err) + return; + + dma_desc = sc->aw_dma_desc; + for (i = 0; i < nsegs; i++) { + dma_desc[i].buf_size = segs[i].ds_len; + dma_desc[i].buf_addr = segs[i].ds_addr; + dma_desc[i].config = AW_MMC_DMA_CONFIG_CH | + AW_MMC_DMA_CONFIG_OWN; + if (i == 0) + dma_desc[i].config |= AW_MMC_DMA_CONFIG_FD; + if (i < (nsegs - 1)) { + dma_desc[i].config |= AW_MMC_DMA_CONFIG_DIC; + dma_desc[i].next = sc->aw_dma_desc_phys + + ((i + 1) * sizeof(struct aw_mmc_dma_desc)); + } else { + dma_desc[i].config |= AW_MMC_DMA_CONFIG_LD | + AW_MMC_DMA_CONFIG_ER; + dma_desc[i].next = 0; + } + } +} + +static int +aw_mmc_prepare_dma(struct aw_mmc_softc *sc) +{ + bus_dmasync_op_t sync_op; + int error; + struct mmc_command *cmd; + uint32_t val; + + cmd = sc->aw_req->cmd; + if (cmd->data->len > AW_MMC_DMA_MAX_SIZE * AW_MMC_DMA_SEGS) + return (EFBIG); + error = bus_dmamap_load(sc->aw_dma_buf_tag, sc->aw_dma_buf_map, + cmd->data->data, cmd->data->len, aw_dma_cb, sc, 0); + if (error) + return (error); + if (sc->aw_dma_map_err) + return (sc->aw_dma_map_err); + + if (cmd->data->flags & MMC_DATA_WRITE) + sync_op = BUS_DMASYNC_PREWRITE; + else + sync_op = BUS_DMASYNC_PREREAD; + bus_dmamap_sync(sc->aw_dma_buf_tag, sc->aw_dma_buf_map, sync_op); + bus_dmamap_sync(sc->aw_dma_tag, sc->aw_dma_map, BUS_DMASYNC_PREWRITE); + + /* Enable DMA */ + val = AW_MMC_READ_4(sc, AW_MMC_GCTL); + val &= ~AW_MMC_CTRL_FIFO_AC_MOD; + val |= AW_MMC_CTRL_DMA_ENB; + AW_MMC_WRITE_4(sc, AW_MMC_GCTL, val); + + /* Reset DMA */ + val |= AW_MMC_CTRL_DMA_RST; + AW_MMC_WRITE_4(sc, AW_MMC_GCTL, val); + + AW_MMC_WRITE_4(sc, AW_MMC_DMAC, AW_MMC_DMAC_IDMAC_SOFT_RST); + AW_MMC_WRITE_4(sc, AW_MMC_DMAC, + AW_MMC_DMAC_IDMAC_IDMA_ON | AW_MMC_DMAC_IDMAC_FIX_BURST); + + /* Enable RX or TX DMA interrupt */ + if (cmd->data->flags & MMC_DATA_WRITE) + val |= AW_MMC_IDST_TX_INT; + else + val |= AW_MMC_IDST_RX_INT; + AW_MMC_WRITE_4(sc, AW_MMC_IDIE, val); + + /* Set DMA descritptor list address */ + AW_MMC_WRITE_4(sc, AW_MMC_DLBA, sc->aw_dma_desc_phys); + + /* FIFO trigger level */ + AW_MMC_WRITE_4(sc, AW_MMC_FWLR, AW_MMC_DMA_FTRGLEVEL); + + return (0); +} + +static int +aw_mmc_reset(struct aw_mmc_softc *sc) +{ + int timeout; + + AW_MMC_WRITE_4(sc, AW_MMC_GCTL, AW_MMC_RESET); + timeout = 1000; + while (--timeout > 0) { + if ((AW_MMC_READ_4(sc, AW_MMC_GCTL) & AW_MMC_RESET) == 0) + break; + DELAY(100); + } + if (timeout == 0) + return (ETIMEDOUT); + + /* Set the timeout. */ + AW_MMC_WRITE_4(sc, AW_MMC_TMOR, + AW_MMC_TMOR_DTO_LMT_SHIFT(AW_MMC_TMOR_DTO_LMT_MASK) | + AW_MMC_TMOR_RTO_LMT_SHIFT(AW_MMC_TMOR_RTO_LMT_MASK)); + + /* Clear pending interrupts. */ + AW_MMC_WRITE_4(sc, AW_MMC_RISR, 0xffffffff); + AW_MMC_WRITE_4(sc, AW_MMC_IDST, 0xffffffff); + /* Unmask interrupts. */ + AW_MMC_WRITE_4(sc, AW_MMC_IMKR, + AW_MMC_INT_CMD_DONE | AW_MMC_INT_ERR_BIT | + AW_MMC_INT_DATA_OVER | AW_MMC_INT_AUTO_STOP_DONE); + /* Enable interrupts and AHB access. */ + AW_MMC_WRITE_4(sc, AW_MMC_GCTL, + AW_MMC_READ_4(sc, AW_MMC_GCTL) | AW_MMC_CTRL_INT_ENB); + + return (0); +} + +static void +aw_mmc_req_done(struct aw_mmc_softc *sc) +{ + struct mmc_command *cmd; + struct mmc_request *req; + uint32_t val, mask; + int retry; + + cmd = sc->aw_req->cmd; + if (cmd->error != MMC_ERR_NONE) { + /* Reset the FIFO and DMA engines. */ + mask = AW_MMC_CTRL_FIFO_RST | AW_MMC_CTRL_DMA_RST; + val = AW_MMC_READ_4(sc, AW_MMC_GCTL); + AW_MMC_WRITE_4(sc, AW_MMC_GCTL, val | mask); + + retry = AW_MMC_RESET_RETRY; + while (--retry > 0) { + val = AW_MMC_READ_4(sc, AW_MMC_GCTL); + if ((val & mask) == 0) + break; + DELAY(10); + } + if (retry == 0) + device_printf(sc->aw_dev, + "timeout resetting DMA/FIFO\n"); + aw_mmc_update_clock(sc, 1); + } + + req = sc->aw_req; + callout_stop(&sc->aw_timeoutc); + sc->aw_req = NULL; + sc->aw_intr = 0; + sc->aw_resid = 0; + sc->aw_dma_map_err = 0; + sc->aw_intr_wait = 0; + req->done(req); +} + +static void +aw_mmc_req_ok(struct aw_mmc_softc *sc) +{ + int timeout; + struct mmc_command *cmd; + uint32_t status; + + timeout = 1000; + while (--timeout > 0) { + status = AW_MMC_READ_4(sc, AW_MMC_STAR); + if ((status & AW_MMC_STAR_CARD_BUSY) == 0) + break; + DELAY(1000); + } + cmd = sc->aw_req->cmd; + if (timeout == 0) { + cmd->error = MMC_ERR_FAILED; + aw_mmc_req_done(sc); + return; + } + if (cmd->flags & MMC_RSP_PRESENT) { + if (cmd->flags & MMC_RSP_136) { + cmd->resp[0] = AW_MMC_READ_4(sc, AW_MMC_RESP3); + cmd->resp[1] = AW_MMC_READ_4(sc, AW_MMC_RESP2); + cmd->resp[2] = AW_MMC_READ_4(sc, AW_MMC_RESP1); + cmd->resp[3] = AW_MMC_READ_4(sc, AW_MMC_RESP0); + } else + cmd->resp[0] = AW_MMC_READ_4(sc, AW_MMC_RESP0); + } + /* All data has been transferred ? */ + if (cmd->data != NULL && (sc->aw_resid << 2) < cmd->data->len) + cmd->error = MMC_ERR_FAILED; + aw_mmc_req_done(sc); +} + +static void +aw_mmc_timeout(void *arg) +{ + struct aw_mmc_softc *sc; + + sc = (struct aw_mmc_softc *)arg; + if (sc->aw_req != NULL) { + device_printf(sc->aw_dev, "controller timeout\n"); + sc->aw_req->cmd->error = MMC_ERR_TIMEOUT; + aw_mmc_req_done(sc); + } else + device_printf(sc->aw_dev, + "Spurious timeout - no active request\n"); +} + +static void +aw_mmc_intr(void *arg) +{ + bus_dmasync_op_t sync_op; + struct aw_mmc_softc *sc; + struct mmc_data *data; + uint32_t idst, imask, rint; + + sc = (struct aw_mmc_softc *)arg; + AW_MMC_LOCK(sc); + rint = AW_MMC_READ_4(sc, AW_MMC_RISR); + idst = AW_MMC_READ_4(sc, AW_MMC_IDST); + imask = AW_MMC_READ_4(sc, AW_MMC_IMKR); + if (idst == 0 && imask == 0 && rint == 0) { + AW_MMC_UNLOCK(sc); + return; + } +#ifdef DEBUG + device_printf(sc->aw_dev, "idst: %#x, imask: %#x, rint: %#x\n", + idst, imask, rint); +#endif + if (sc->aw_req == NULL) { + device_printf(sc->aw_dev, + "Spurious interrupt - no active request, rint: 0x%08X\n", + rint); + goto end; + } + if (rint & AW_MMC_INT_ERR_BIT) { + device_printf(sc->aw_dev, "error rint: 0x%08X\n", rint); + if (rint & AW_MMC_INT_RESP_TIMEOUT) + sc->aw_req->cmd->error = MMC_ERR_TIMEOUT; + else + sc->aw_req->cmd->error = MMC_ERR_FAILED; + aw_mmc_req_done(sc); + goto end; + } + if (idst & AW_MMC_IDST_ERROR) { + device_printf(sc->aw_dev, "error idst: 0x%08x\n", idst); + sc->aw_req->cmd->error = MMC_ERR_FAILED; + aw_mmc_req_done(sc); + goto end; + } + + sc->aw_intr |= rint; + data = sc->aw_req->cmd->data; + if (data != NULL && (idst & AW_MMC_IDST_COMPLETE) != 0) { + if (data->flags & MMC_DATA_WRITE) + sync_op = BUS_DMASYNC_POSTWRITE; + else + sync_op = BUS_DMASYNC_POSTREAD; + bus_dmamap_sync(sc->aw_dma_buf_tag, sc->aw_dma_buf_map, + sync_op); + bus_dmamap_sync(sc->aw_dma_tag, sc->aw_dma_map, + BUS_DMASYNC_POSTWRITE); + bus_dmamap_unload(sc->aw_dma_buf_tag, sc->aw_dma_buf_map); + sc->aw_resid = data->len >> 2; + } + if ((sc->aw_intr & sc->aw_intr_wait) == sc->aw_intr_wait) + aw_mmc_req_ok(sc); + +end: + AW_MMC_WRITE_4(sc, AW_MMC_IDST, idst); + AW_MMC_WRITE_4(sc, AW_MMC_RISR, rint); + AW_MMC_UNLOCK(sc); +} + +static int +aw_mmc_request(device_t bus, device_t child, struct mmc_request *req) +{ + int blksz; + struct aw_mmc_softc *sc; + struct mmc_command *cmd; + uint32_t cmdreg; + int err; + + sc = device_get_softc(bus); + AW_MMC_LOCK(sc); + if (sc->aw_req) { + AW_MMC_UNLOCK(sc); + return (EBUSY); + } + sc->aw_req = req; + cmd = req->cmd; + cmdreg = AW_MMC_CMDR_LOAD; + if (cmd->opcode == MMC_GO_IDLE_STATE) + cmdreg |= AW_MMC_CMDR_SEND_INIT_SEQ; + if (cmd->flags & MMC_RSP_PRESENT) + cmdreg |= AW_MMC_CMDR_RESP_RCV; + if (cmd->flags & MMC_RSP_136) + cmdreg |= AW_MMC_CMDR_LONG_RESP; + if (cmd->flags & MMC_RSP_CRC) + cmdreg |= AW_MMC_CMDR_CHK_RESP_CRC; + + sc->aw_intr = 0; + sc->aw_resid = 0; + sc->aw_intr_wait = AW_MMC_INT_CMD_DONE; + cmd->error = MMC_ERR_NONE; + if (cmd->data != NULL) { + sc->aw_intr_wait |= AW_MMC_INT_DATA_OVER; + cmdreg |= AW_MMC_CMDR_DATA_TRANS | AW_MMC_CMDR_WAIT_PRE_OVER; + if (cmd->data->flags & MMC_DATA_MULTI) { + cmdreg |= AW_MMC_CMDR_STOP_CMD_FLAG; + sc->aw_intr_wait |= AW_MMC_INT_AUTO_STOP_DONE; + } + if (cmd->data->flags & MMC_DATA_WRITE) + cmdreg |= AW_MMC_CMDR_DIR_WRITE; + blksz = min(cmd->data->len, MMC_SECTOR_SIZE); + AW_MMC_WRITE_4(sc, AW_MMC_BKSR, blksz); + AW_MMC_WRITE_4(sc, AW_MMC_BYCR, cmd->data->len); + + err = aw_mmc_prepare_dma(sc); + if (err != 0) + device_printf(sc->aw_dev, "prepare_dma failed: %d\n", err); + } + + AW_MMC_WRITE_4(sc, AW_MMC_CAGR, cmd->arg); + AW_MMC_WRITE_4(sc, AW_MMC_CMDR, cmdreg | cmd->opcode); + callout_reset(&sc->aw_timeoutc, sc->aw_timeout * hz, + aw_mmc_timeout, sc); + AW_MMC_UNLOCK(sc); + + return (0); +} + +static int +aw_mmc_read_ivar(device_t bus, device_t child, int which, + uintptr_t *result) +{ + struct aw_mmc_softc *sc; + + sc = device_get_softc(bus); + switch (which) { + default: + return (EINVAL); + case MMCBR_IVAR_BUS_MODE: + *(int *)result = sc->aw_host.ios.bus_mode; + break; + case MMCBR_IVAR_BUS_WIDTH: + *(int *)result = sc->aw_host.ios.bus_width; + break; + case MMCBR_IVAR_CHIP_SELECT: + *(int *)result = sc->aw_host.ios.chip_select; + break; + case MMCBR_IVAR_CLOCK: + *(int *)result = sc->aw_host.ios.clock; + break; + case MMCBR_IVAR_F_MIN: + *(int *)result = sc->aw_host.f_min; + break; + case MMCBR_IVAR_F_MAX: + *(int *)result = sc->aw_host.f_max; + break; + case MMCBR_IVAR_HOST_OCR: + *(int *)result = sc->aw_host.host_ocr; + break; + case MMCBR_IVAR_MODE: + *(int *)result = sc->aw_host.mode; + break; + case MMCBR_IVAR_OCR: + *(int *)result = sc->aw_host.ocr; + break; + case MMCBR_IVAR_POWER_MODE: + *(int *)result = sc->aw_host.ios.power_mode; + break; + case MMCBR_IVAR_VDD: + *(int *)result = sc->aw_host.ios.vdd; + break; + case MMCBR_IVAR_CAPS: + *(int *)result = sc->aw_host.caps; + break; + case MMCBR_IVAR_MAX_DATA: + *(int *)result = 65535; + break; + } + + return (0); +} + +static int +aw_mmc_write_ivar(device_t bus, device_t child, int which, + uintptr_t value) +{ + struct aw_mmc_softc *sc; + + sc = device_get_softc(bus); + switch (which) { + default: + return (EINVAL); + case MMCBR_IVAR_BUS_MODE: + sc->aw_host.ios.bus_mode = value; + break; + case MMCBR_IVAR_BUS_WIDTH: + sc->aw_host.ios.bus_width = value; + break; + case MMCBR_IVAR_CHIP_SELECT: + sc->aw_host.ios.chip_select = value; + break; + case MMCBR_IVAR_CLOCK: + sc->aw_host.ios.clock = value; + break; + case MMCBR_IVAR_MODE: + sc->aw_host.mode = value; + break; + case MMCBR_IVAR_OCR: + sc->aw_host.ocr = value; + break; + case MMCBR_IVAR_POWER_MODE: + sc->aw_host.ios.power_mode = value; + break; + case MMCBR_IVAR_VDD: + sc->aw_host.ios.vdd = value; + break; + /* These are read-only */ + case MMCBR_IVAR_CAPS: + case MMCBR_IVAR_HOST_OCR: + case MMCBR_IVAR_F_MIN: + case MMCBR_IVAR_F_MAX: + case MMCBR_IVAR_MAX_DATA: + return (EINVAL); + } + + return (0); +} + +static int +aw_mmc_update_clock(struct aw_mmc_softc *sc, uint32_t clkon) +{ + uint32_t cmdreg; + int retry; + uint32_t ckcr; + + ckcr = AW_MMC_READ_4(sc, AW_MMC_CKCR); + ckcr &= ~(AW_MMC_CKCR_CCLK_ENB | AW_MMC_CKCR_CCLK_CTRL); + + if (clkon) + ckcr |= AW_MMC_CKCR_CCLK_ENB; + + AW_MMC_WRITE_4(sc, AW_MMC_CKCR, ckcr); + + cmdreg = AW_MMC_CMDR_LOAD | AW_MMC_CMDR_PRG_CLK | + AW_MMC_CMDR_WAIT_PRE_OVER; + AW_MMC_WRITE_4(sc, AW_MMC_CMDR, cmdreg); + retry = 0xfffff; + while (--retry > 0) { + if ((AW_MMC_READ_4(sc, AW_MMC_CMDR) & AW_MMC_CMDR_LOAD) == 0) { + AW_MMC_WRITE_4(sc, AW_MMC_RISR, 0xffffffff); + return (0); + } + DELAY(10); + } + AW_MMC_WRITE_4(sc, AW_MMC_RISR, 0xffffffff); + device_printf(sc->aw_dev, "timeout updating clock\n"); + + return (ETIMEDOUT); +} + +static int +aw_mmc_update_ios(device_t bus, device_t child) +{ + int error; + struct aw_mmc_softc *sc; + struct mmc_ios *ios; + uint32_t ckcr; + + sc = device_get_softc(bus); + + ios = &sc->aw_host.ios; + + /* Set the bus width. */ + switch (ios->bus_width) { + case bus_width_1: + AW_MMC_WRITE_4(sc, AW_MMC_BWDR, AW_MMC_BWDR1); + break; + case bus_width_4: + AW_MMC_WRITE_4(sc, AW_MMC_BWDR, AW_MMC_BWDR4); + break; + case bus_width_8: + AW_MMC_WRITE_4(sc, AW_MMC_BWDR, AW_MMC_BWDR8); + break; + } + + if (ios->clock) { + + /* Disable clock */ + error = aw_mmc_update_clock(sc, 0); + if (error != 0) + return (error); + + /* Reset the divider. */ + ckcr = AW_MMC_READ_4(sc, AW_MMC_CKCR); + ckcr &= ~AW_MMC_CKCR_CCLK_DIV; + AW_MMC_WRITE_4(sc, AW_MMC_CKCR, ckcr); + + /* Set the MMC clock. */ + error = clk_set_freq(sc->aw_clk_mmc, ios->clock, + CLK_SET_ROUND_DOWN); + if (error != 0) { + device_printf(sc->aw_dev, + "failed to set frequency to %u Hz: %d\n", + ios->clock, error); + return (error); + } + + /* Enable clock. */ + error = aw_mmc_update_clock(sc, 1); + if (error != 0) + return (error); + } + + + return (0); +} + +static int +aw_mmc_get_ro(device_t bus, device_t child) +{ + + return (0); +} + +static int +aw_mmc_acquire_host(device_t bus, device_t child) +{ + struct aw_mmc_softc *sc; + int error; + + sc = device_get_softc(bus); + AW_MMC_LOCK(sc); + while (sc->aw_bus_busy) { + error = msleep(sc, &sc->aw_mtx, PCATCH, "mmchw", 0); + if (error != 0) { + AW_MMC_UNLOCK(sc); + return (error); + } + } + sc->aw_bus_busy++; + AW_MMC_UNLOCK(sc); + + return (0); +} + +static int +aw_mmc_release_host(device_t bus, device_t child) +{ + struct aw_mmc_softc *sc; + + sc = device_get_softc(bus); + AW_MMC_LOCK(sc); + sc->aw_bus_busy--; + wakeup(sc); + AW_MMC_UNLOCK(sc); + + return (0); +} + +static device_method_t aw_mmc_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, aw_mmc_probe), + DEVMETHOD(device_attach, aw_mmc_attach), + DEVMETHOD(device_detach, aw_mmc_detach), + + /* Bus interface */ + DEVMETHOD(bus_read_ivar, aw_mmc_read_ivar), + DEVMETHOD(bus_write_ivar, aw_mmc_write_ivar), + + /* MMC bridge interface */ + DEVMETHOD(mmcbr_update_ios, aw_mmc_update_ios), + DEVMETHOD(mmcbr_request, aw_mmc_request), + DEVMETHOD(mmcbr_get_ro, aw_mmc_get_ro), + DEVMETHOD(mmcbr_acquire_host, aw_mmc_acquire_host), + DEVMETHOD(mmcbr_release_host, aw_mmc_release_host), + + DEVMETHOD_END +}; + +static devclass_t aw_mmc_devclass; + +static driver_t aw_mmc_driver = { + "aw_mmc", + aw_mmc_methods, + sizeof(struct aw_mmc_softc), +}; + +DRIVER_MODULE(aw_mmc, simplebus, aw_mmc_driver, aw_mmc_devclass, NULL, + NULL); +MMC_DECLARE_BRIDGE(aw_mmc); diff --git a/sys/arm/allwinner/aw_mmc.h b/sys/arm/allwinner/aw_mmc.h new file mode 100644 index 00000000000..16b3099c500 --- /dev/null +++ b/sys/arm/allwinner/aw_mmc.h @@ -0,0 +1,204 @@ +/*- + * Copyright (c) 2013 Alexander Fedorov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _AW_MMC_H_ +#define _AW_MMC_H_ + +#define AW_MMC_GCTL 0x00 /* Control Register */ +#define AW_MMC_CKCR 0x04 /* Clock Control Register */ +#define AW_MMC_TMOR 0x08 /* Timeout Register */ +#define AW_MMC_BWDR 0x0C /* Bus Width Register */ +#define AW_MMC_BKSR 0x10 /* Block Size Register */ +#define AW_MMC_BYCR 0x14 /* Byte Count Register */ +#define AW_MMC_CMDR 0x18 /* Command Register */ +#define AW_MMC_CAGR 0x1C /* Argument Register */ +#define AW_MMC_RESP0 0x20 /* Response Register 0 */ +#define AW_MMC_RESP1 0x24 /* Response Register 1 */ +#define AW_MMC_RESP2 0x28 /* Response Register 2 */ +#define AW_MMC_RESP3 0x2C /* Response Register 3 */ +#define AW_MMC_IMKR 0x30 /* Interrupt Mask Register */ +#define AW_MMC_MISR 0x34 /* Masked Interrupt Status Register */ +#define AW_MMC_RISR 0x38 /* Raw Interrupt Status Register */ +#define AW_MMC_STAR 0x3C /* Status Register */ +#define AW_MMC_FWLR 0x40 /* FIFO Threshold Watermark Register */ +#define AW_MMC_FUNS 0x44 /* Function Select Register */ +#define AW_MMC_HWRST 0x78 /* Hardware reset (not documented) */ +#define AW_MMC_DMAC 0x80 /* IDMAC Control Register */ +#define AW_MMC_DLBA 0x84 /* IDMAC Desc List Base Address Reg */ +#define AW_MMC_IDST 0x88 /* IDMAC Status Register */ +#define AW_MMC_IDIE 0x8C /* IDMAC Interrupt Enable Register */ +#define AW_MMC_FIFO 0x100 /* FIFO Access Address (A10/A20) */ +#define A31_MMC_FIFO 0x200 /* FIFO Access Address (A31) */ + +/* AW_MMC_GCTL */ +#define AW_MMC_CTRL_SOFT_RST (1U << 0) +#define AW_MMC_CTRL_FIFO_RST (1U << 1) +#define AW_MMC_CTRL_DMA_RST (1U << 2) +#define AW_MMC_CTRL_INT_ENB (1U << 4) +#define AW_MMC_CTRL_DMA_ENB (1U << 5) +#define AW_MMC_CTRL_CD_DBC_ENB (1U << 8) +#define AW_MMC_CTRL_DDR_MOD_SEL (1U << 10) +#define AW_MMC_CTRL_FIFO_AC_MOD (1U << 31) +#define AW_MMC_RESET \ + (AW_MMC_CTRL_SOFT_RST | AW_MMC_CTRL_FIFO_RST | AW_MMC_CTRL_DMA_RST) + +/* AW_MMC_CKCR */ +#define AW_MMC_CKCR_CCLK_ENB (1U << 16) +#define AW_MMC_CKCR_CCLK_CTRL (1U << 17) +#define AW_MMC_CKCR_CCLK_DIV 0xff + +/* AW_MMC_TMOR */ +#define AW_MMC_TMOR_RTO_LMT_SHIFT(x) x /* Response timeout limit */ +#define AW_MMC_TMOR_RTO_LMT_MASK 0xff +#define AW_MMC_TMOR_DTO_LMT_SHIFT(x) (x << 8) /* Data timeout limit */ +#define AW_MMC_TMOR_DTO_LMT_MASK 0xffffff + +/* AW_MMC_BWDR */ +#define AW_MMC_BWDR1 0 +#define AW_MMC_BWDR4 1 +#define AW_MMC_BWDR8 2 + +/* AW_MMC_CMDR */ +#define AW_MMC_CMDR_RESP_RCV (1U << 6) +#define AW_MMC_CMDR_LONG_RESP (1U << 7) +#define AW_MMC_CMDR_CHK_RESP_CRC (1U << 8) +#define AW_MMC_CMDR_DATA_TRANS (1U << 9) +#define AW_MMC_CMDR_DIR_WRITE (1U << 10) +#define AW_MMC_CMDR_TRANS_MODE_STREAM (1U << 11) +#define AW_MMC_CMDR_STOP_CMD_FLAG (1U << 12) +#define AW_MMC_CMDR_WAIT_PRE_OVER (1U << 13) +#define AW_MMC_CMDR_STOP_ABT_CMD (1U << 14) +#define AW_MMC_CMDR_SEND_INIT_SEQ (1U << 15) +#define AW_MMC_CMDR_PRG_CLK (1U << 21) +#define AW_MMC_CMDR_RD_CEDATA_DEV (1U << 22) +#define AW_MMC_CMDR_CCS_EXP (1U << 23) +#define AW_MMC_CMDR_BOOT_MOD_SHIFT 24 +#define AW_MMC_CMDR_BOOT_MOD_NORMAL 0 +#define AW_MMC_CMDR_BOOT_MOD_MANDATORY 1 +#define AW_MMC_CMDR_BOOT_MOD_ALT 2 +#define AW_MMC_CMDR_EXP_BOOT_ACK (1U << 26) +#define AW_MMC_CMDR_BOOT_ABT (1U << 27) +#define AW_MMC_CMDR_VOL_SW (1U << 28) +#define AW_MMC_CMDR_LOAD (1U << 31) + +/* AW_MMC_IMKR and AW_MMC_RISR */ +#define AW_MMC_INT_RESP_ERR (1U << 1) +#define AW_MMC_INT_CMD_DONE (1U << 2) +#define AW_MMC_INT_DATA_OVER (1U << 3) +#define AW_MMC_INT_TX_DATA_REQ (1U << 4) +#define AW_MMC_INT_RX_DATA_REQ (1U << 5) +#define AW_MMC_INT_RESP_CRC_ERR (1U << 6) +#define AW_MMC_INT_DATA_CRC_ERR (1U << 7) +#define AW_MMC_INT_RESP_TIMEOUT (1U << 8) +#define AW_MMC_INT_BOOT_ACK_RECV (1U << 8) +#define AW_MMC_INT_DATA_TIMEOUT (1U << 9) +#define AW_MMC_INT_BOOT_START (1U << 9) +#define AW_MMC_INT_DATA_STARVE (1U << 10) +#define AW_MMC_INT_VOL_CHG_DONE (1U << 10) +#define AW_MMC_INT_FIFO_RUN_ERR (1U << 11) +#define AW_MMC_INT_CMD_BUSY (1U << 12) +#define AW_MMC_INT_DATA_START_ERR (1U << 13) +#define AW_MMC_INT_AUTO_STOP_DONE (1U << 14) +#define AW_MMC_INT_DATA_END_BIT_ERR (1U << 15) +#define AW_MMC_INT_SDIO (1U << 16) +#define AW_MMC_INT_CARD_INSERT (1U << 30) +#define AW_MMC_INT_CARD_REMOVE (1U << 31) +#define AW_MMC_INT_ERR_BIT \ + (AW_MMC_INT_RESP_ERR | AW_MMC_INT_RESP_CRC_ERR | \ + AW_MMC_INT_DATA_CRC_ERR | AW_MMC_INT_RESP_TIMEOUT | \ + AW_MMC_INT_FIFO_RUN_ERR | AW_MMC_INT_CMD_BUSY | \ + AW_MMC_INT_DATA_START_ERR | AW_MMC_INT_DATA_END_BIT_ERR) + +/* AW_MMC_STAR */ +#define AW_MMC_STAR_FIFO_RX_LEVEL (1U << 0) +#define AW_MMC_STAR_FIFO_TX_LEVEL (1U << 1) +#define AW_MMC_STAR_FIFO_EMPTY (1U << 2) +#define AW_MMC_STAR_FIFO_FULL (1U << 3) +#define AW_MMC_STAR_CARD_PRESENT (1U << 8) +#define AW_MMC_STAR_CARD_BUSY (1U << 9) +#define AW_MMC_STAR_FSM_BUSY (1U << 10) +#define AW_MMC_STAR_DMA_REQ (1U << 31) + +/* AW_MMC_FUNS */ +#define AW_MMC_CE_ATA_ON (0xceaaU << 16) +#define AW_MMC_SEND_IRQ_RESP (1U << 0) +#define AW_MMC_SDIO_RD_WAIT (1U << 1) +#define AW_MMC_ABT_RD_DATA (1U << 2) +#define AW_MMC_SEND_CC_SD (1U << 8) +#define AW_MMC_SEND_AUTOSTOP_CC_SD (1U << 9) +#define AW_MMC_CE_ATA_DEV_INT_ENB (1U << 10) + +/* IDMA CONTROLLER BUS MOD BIT FIELD */ +#define AW_MMC_DMAC_IDMAC_SOFT_RST (1U << 0) +#define AW_MMC_DMAC_IDMAC_FIX_BURST (1U << 1) +#define AW_MMC_DMAC_IDMAC_IDMA_ON (1U << 7) +#define AW_MMC_DMAC_IDMAC_REFETCH_DES (1U << 31) + +/* AW_MMC_IDST */ +#define AW_MMC_IDST_TX_INT (1U << 0) +#define AW_MMC_IDST_RX_INT (1U << 1) +#define AW_MMC_IDST_FATAL_BERR_INT (1U << 2) +#define AW_MMC_IDST_DES_UNAVL_INT (1U << 4) +#define AW_MMC_IDST_ERR_FLAG_SUM (1U << 5) +#define AW_MMC_IDST_NOR_INT_SUM (1U << 8) +#define AW_MMC_IDST_ABN_INT_SUM (1U << 9) +#define AW_MMC_IDST_HOST_ABT_INTX (1U << 10) +#define AW_MMC_IDST_HOST_ABT_INRX (1U << 10) +#define AW_MMC_IDST_IDLE (0U << 13) +#define AW_MMC_IDST_SUSPEND (1U << 13) +#define AW_MMC_IDST_DESC_RD (2U << 13) +#define AW_MMC_IDST_DESC_CHECK (3U << 13) +#define AW_MMC_IDST_RD_REQ_WAIT (4U << 13) +#define AW_MMC_IDST_WR_REQ_WAIT (5U << 13) +#define AW_MMC_IDST_RD (6U << 13) +#define AW_MMC_IDST_WR (7U << 13) +#define AW_MMC_IDST_DESC_CLOSE (8U << 13) +#define AW_MMC_IDST_ERROR \ + (AW_MMC_IDST_FATAL_BERR_INT | AW_MMC_IDST_ERR_FLAG_SUM | \ + AW_MMC_IDST_DES_UNAVL_INT | AW_MMC_IDST_ABN_INT_SUM) +#define AW_MMC_IDST_COMPLETE \ + (AW_MMC_IDST_TX_INT | AW_MMC_IDST_RX_INT) + +/* The DMA descriptor table. */ +struct aw_mmc_dma_desc { + uint32_t config; +#define AW_MMC_DMA_CONFIG_DIC (1U << 1) /* Disable Interrupt Completion */ +#define AW_MMC_DMA_CONFIG_LD (1U << 2) /* Last DES */ +#define AW_MMC_DMA_CONFIG_FD (1U << 3) /* First DES */ +#define AW_MMC_DMA_CONFIG_CH (1U << 4) /* CHAIN MOD */ +#define AW_MMC_DMA_CONFIG_ER (1U << 5) /* End of Ring (undocumented register) */ +#define AW_MMC_DMA_CONFIG_CES (1U << 30) /* Card Error Summary */ +#define AW_MMC_DMA_CONFIG_OWN (1U << 31) /* DES Own Flag */ + uint32_t buf_size; + uint32_t buf_addr; + uint32_t next; +}; + +#define AW_MMC_DMA_ALIGN 4 + +#endif /* _AW_MMC_H_ */ diff --git a/sys/arm/allwinner/aw_mp.c b/sys/arm/allwinner/aw_mp.c index 3bea7602dd4..df798443a44 100644 --- a/sys/arm/allwinner/aw_mp.c +++ b/sys/arm/allwinner/aw_mp.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2014 Ganbold Tsagaankhuu - * Copyright (c) 2016 Emmanuel Vadot + * Copyright (c) 2016 Emmanuel Vadot * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/arm/allwinner/aw_mp.h b/sys/arm/allwinner/aw_mp.h index 9ca92d49478..1c9046e3303 100644 --- a/sys/arm/allwinner/aw_mp.h +++ b/sys/arm/allwinner/aw_mp.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2016 Emmanuel Vadot + * Copyright (c) 2016 Emmanuel Vadot * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/arm/allwinner/aw_wdog.c b/sys/arm/allwinner/aw_wdog.c index 8ca9b7d3415..2510076f03b 100644 --- a/sys/arm/allwinner/aw_wdog.c +++ b/sys/arm/allwinner/aw_wdog.c @@ -1,6 +1,6 @@ /*- * Copyright (c) 2013 Oleksandr Tymoshenko - * Copyright (c) 2016 Emmanuel Vadot + * Copyright (c) 2016 Emmanuel Vadot * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -115,9 +115,6 @@ static void aw_wdog_shutdown_fn(void *, int); static int aw_wdog_probe(device_t dev) { - struct aw_wdog_softc *sc; - - sc = device_get_softc(dev); if (!ofw_bus_status_okay(dev)) return (ENXIO); diff --git a/sys/arm/allwinner/axp81x.c b/sys/arm/allwinner/axp81x.c index 9693b1007ce..31942e88d91 100644 --- a/sys/arm/allwinner/axp81x.c +++ b/sys/arm/allwinner/axp81x.c @@ -352,13 +352,11 @@ axp81x_shutdown(void *devp, int howto) static void axp81x_intr(void *arg) { - struct axp81x_softc *sc; device_t dev; uint8_t val; int error; dev = arg; - sc = device_get_softc(dev); error = axp81x_read(dev, AXP_IRQSTAT5, &val, 1); if (error != 0) diff --git a/sys/arm/allwinner/clk/aw_pll.c b/sys/arm/allwinner/clk/aw_pll.c index fadc13def6f..254d101918f 100644 --- a/sys/arm/allwinner/clk/aw_pll.c +++ b/sys/arm/allwinner/clk/aw_pll.c @@ -865,7 +865,7 @@ h3_pll1_set_freq(struct aw_pll_sc *sc, uint64_t fin, uint64_t *fout, int flags) { struct aw_pll_factor *f; - uint32_t val, n, k, m, p; + uint32_t val, m, p; int i; f = NULL; @@ -884,8 +884,6 @@ h3_pll1_set_freq(struct aw_pll_sc *sc, uint64_t fin, uint64_t *fout, DEVICE_LOCK(sc); PLL_READ(sc, &val); - n = (val & A23_PLL1_FACTOR_N) >> A23_PLL1_FACTOR_N_SHIFT; - k = (val & A23_PLL1_FACTOR_K) >> A23_PLL1_FACTOR_K_SHIFT; m = (val & A23_PLL1_FACTOR_M) >> A23_PLL1_FACTOR_M_SHIFT; p = (val & A23_PLL1_FACTOR_P) >> A23_PLL1_FACTOR_P_SHIFT; diff --git a/sys/arm/allwinner/files.allwinner b/sys/arm/allwinner/files.allwinner index a1cbaf66529..e62db3cedd2 100644 --- a/sys/arm/allwinner/files.allwinner +++ b/sys/arm/allwinner/files.allwinner @@ -6,18 +6,18 @@ arm/allwinner/a10_codec.c optional sound arm/allwinner/a10_dmac.c standard arm/allwinner/a31_dmac.c standard arm/allwinner/a10_ehci.c optional ehci -arm/allwinner/aw_usbphy.c optional ehci -arm/allwinner/a10_gpio.c optional gpio -arm/allwinner/a10_mmc.c optional mmc arm/allwinner/a10_sramc.c standard -arm/allwinner/aw_nmi.c optional intrng +arm/allwinner/aw_gpio.c optional gpio arm/allwinner/aw_if_dwc.c optional dwc +arm/allwinner/aw_machdep.c standard +arm/allwinner/aw_mmc.c optional mmc +arm/allwinner/aw_mp.c optional smp +arm/allwinner/aw_nmi.c optional intrng arm/allwinner/aw_rsb.c optional rsb | p2wi arm/allwinner/aw_rtc.c standard arm/allwinner/aw_ts.c standard +arm/allwinner/aw_usbphy.c optional ehci | ohci arm/allwinner/aw_wdog.c standard -arm/allwinner/aw_machdep.c standard -arm/allwinner/aw_mp.c optional smp arm/allwinner/axp209.c optional axp209 arm/allwinner/axp81x.c optional axp81x arm/allwinner/if_awg.c optional awg @@ -30,12 +30,10 @@ arm/allwinner/aw_sid.c standard arm/allwinner/aw_thermal.c standard dev/iicbus/sy8106a.c optional sy8106a arm/allwinner/aw_cir.c optional aw_cir evdev -#arm/allwinner/aw_console.c standard arm/allwinner/a10_fb.c optional vt arm/allwinner/a10_hdmi.c optional hdmi arm/allwinner/a10_hdmiaudio.c optional hdmi sound -dev/hdmi/hdmi_if.m optional hdmi arm/allwinner/aw_reset.c standard arm/allwinner/aw_ccu.c standard diff --git a/sys/arm/allwinner/if_awg.c b/sys/arm/allwinner/if_awg.c index 81aca029082..9b233956f24 100644 --- a/sys/arm/allwinner/if_awg.c +++ b/sys/arm/allwinner/if_awg.c @@ -1177,7 +1177,7 @@ awg_setup_phy(device_t dev) if (sc->res[_RES_SYSCON] != NULL) { reg = bus_read_4(sc->res[_RES_SYSCON], 0); reg &= ~(EMAC_CLK_PIT | EMAC_CLK_SRC | EMAC_CLK_RMII_EN); - if (strcmp(phy_type, "rgmii") == 0) + if (strncmp(phy_type, "rgmii", 5) == 0) reg |= EMAC_CLK_PIT_RGMII | EMAC_CLK_SRC_RGMII; else if (strcmp(phy_type, "rmii") == 0) reg |= EMAC_CLK_RMII_EN; @@ -1217,7 +1217,7 @@ awg_setup_phy(device_t dev) device_printf(dev, "EMAC clock: 0x%08x\n", reg); bus_write_4(sc->res[_RES_SYSCON], 0, reg); } else { - if (strcmp(phy_type, "rgmii") == 0) + if (strncmp(phy_type, "rgmii", 5) == 0) tx_parent_name = "emac_int_tx"; else tx_parent_name = "mii_phy_tx"; @@ -1266,12 +1266,10 @@ awg_setup_extres(device_t dev) hwreset_t rst_ahb, rst_ephy; clk_t clk_ahb, clk_ephy; regulator_t reg; - phandle_t node; uint64_t freq; int error, div; sc = device_get_softc(dev); - node = ofw_bus_get_node(dev); rst_ahb = rst_ephy = NULL; clk_ahb = clk_ephy = NULL; reg = NULL; @@ -1713,13 +1711,11 @@ awg_attach(device_t dev) { uint8_t eaddr[ETHER_ADDR_LEN]; struct awg_softc *sc; - phandle_t node; int error; sc = device_get_softc(dev); sc->dev = dev; sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; - node = ofw_bus_get_node(dev); if (bus_alloc_resources(dev, awg_spec, sc->res) != 0) { device_printf(dev, "cannot allocate resources for device\n"); diff --git a/sys/arm/arm/genassym.c b/sys/arm/arm/genassym.c index 7132423686d..ab7ec0f6636 100644 --- a/sys/arm/arm/genassym.c +++ b/sys/arm/arm/genassym.c @@ -161,3 +161,12 @@ ASSYM(DCACHE_LINE_SIZE, offsetof(struct cpuinfo, dcache_line_size)); ASSYM(DCACHE_LINE_MASK, offsetof(struct cpuinfo, dcache_line_mask)); ASSYM(ICACHE_LINE_SIZE, offsetof(struct cpuinfo, icache_line_size)); ASSYM(ICACHE_LINE_MASK, offsetof(struct cpuinfo, icache_line_mask)); + +/* + * Emit the LOCORE_MAP_MB option as a #define only if the option was set. + */ +#include "opt_locore.h" + +#ifdef LOCORE_MAP_MB +ASSYM(LOCORE_MAP_MB, LOCORE_MAP_MB); +#endif diff --git a/sys/arm/arm/gic.c b/sys/arm/arm/gic.c index 912c6a5b17f..5987186b20d 100644 --- a/sys/arm/arm/gic.c +++ b/sys/arm/arm/gic.c @@ -1384,11 +1384,9 @@ int arm_gicv2m_attach(device_t dev) { struct arm_gicv2m_softc *sc; - struct arm_gic_softc *psc; uint32_t typer; int rid; - psc = device_get_softc(device_get_parent(dev)); sc = device_get_softc(dev); rid = 0; diff --git a/sys/arm/arm/locore-v6.S b/sys/arm/arm/locore-v6.S index ef96c61a8fe..04858426ba3 100644 --- a/sys/arm/arm/locore-v6.S +++ b/sys/arm/arm/locore-v6.S @@ -38,6 +38,11 @@ __FBSDID("$FreeBSD$"); +/* We map 64MB of kernel unless overridden in assym.s by the kernel option. */ +#ifndef LOCORE_MAP_MB +#define LOCORE_MAP_MB 64 +#endif + #if __ARM_ARCH >= 7 #if defined(__ARM_ARCH_7VE__) || defined(__clang__) /* @@ -176,12 +181,13 @@ ASENTRY_NP(_start) bl build_pagetables /* - * Next we do 64MiB starting at the physical load address, mapped to - * the VA the kernel is linked for. + * Next we map the kernel starting at the physical load address, mapped + * to the VA the kernel is linked for. The default size we map is 64MiB + * but it can be overridden with a kernel option. */ mov r1, r5 ldr r2, =(KERNVIRTADDR) - mov r3, #64 + ldr r3, =(LOCORE_MAP_MB) bl build_pagetables /* Create a device mapping for early_printf if specified. */ diff --git a/sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c b/sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c index 52f3651ee67..d890683c83e 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_cpufreq.c @@ -1386,9 +1386,6 @@ bcm2835_cpufreq_attach(device_t dev) static int bcm2835_cpufreq_detach(device_t dev) { - struct bcm2835_cpufreq_softc *sc; - - sc = device_get_softc(dev); sema_destroy(&vc_sema); @@ -1400,7 +1397,10 @@ bcm2835_cpufreq_set(device_t dev, const struct cf_setting *cf) { struct bcm2835_cpufreq_softc *sc; uint32_t rate_hz, rem; - int cur_freq, resp_freq, arm_freq, min_freq, core_freq; + int resp_freq, arm_freq, min_freq, core_freq; +#ifdef DEBUG + int cur_freq; +#endif if (cf == NULL || cf->freq < 0) return (EINVAL); @@ -1425,8 +1425,10 @@ bcm2835_cpufreq_set(device_t dev, const struct cf_setting *cf) /* set new value and verify it */ VC_LOCK(sc); +#ifdef DEBUG cur_freq = bcm2835_cpufreq_get_clock_rate(sc, BCM2835_MBOX_CLOCK_ID_ARM); +#endif resp_freq = bcm2835_cpufreq_set_clock_rate(sc, BCM2835_MBOX_CLOCK_ID_ARM, rate_hz); DELAY(TRANSITION_LATENCY); diff --git a/sys/arm/broadcom/bcm2835/bcm2835_gpio.c b/sys/arm/broadcom/bcm2835/bcm2835_gpio.c index 23328ac6bc4..fbe0ac2561c 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_gpio.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_gpio.c @@ -1017,7 +1017,7 @@ bcm_gpio_pic_map_fdt(struct bcm_gpio_softc *sc, struct intr_map_data_fdt *daf, u_int *irqp, uint32_t *modep) { u_int irq; - uint32_t mode, bank; + uint32_t mode; /* * The first cell is the interrupt number. @@ -1036,7 +1036,6 @@ bcm_gpio_pic_map_fdt(struct bcm_gpio_softc *sc, struct intr_map_data_fdt *daf, return (EINVAL); /* Only reasonable modes are supported. */ - bank = BCM_GPIO_BANK(irq); if (daf->cells[1] == 1) mode = GPIO_INTR_EDGE_RISING; else if (daf->cells[1] == 2) diff --git a/sys/arm/broadcom/bcm2835/bcm2835_mbox.c b/sys/arm/broadcom/bcm2835/bcm2835_mbox.c index f3b5363268e..0546264c3c8 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_mbox.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_mbox.c @@ -103,14 +103,18 @@ static struct ofw_compat_data compat_data[] = { static int bcm_mbox_read_msg(struct bcm_mbox_softc *sc, int *ochan) { +#ifdef DEBUG uint32_t data; +#endif uint32_t msg; int chan; msg = mbox_read_4(sc, REG_READ); dprintf("bcm_mbox_intr: raw data %08x\n", msg); chan = MBOX_CHAN(msg); +#ifdef DEBUG data = MBOX_DATA(msg); +#endif if (sc->msg[chan]) { printf("bcm_mbox_intr: channel %d oveflow\n", chan); return (1); diff --git a/sys/arm/freescale/imx/files.imx6 b/sys/arm/freescale/imx/files.imx6 index 36bbe80e808..7819d3b7b23 100644 --- a/sys/arm/freescale/imx/files.imx6 +++ b/sys/arm/freescale/imx/files.imx6 @@ -27,7 +27,6 @@ arm/freescale/imx/imx6_audmux.c optional sound arm/freescale/imx/imx6_ssi.c optional sound arm/freescale/imx/imx6_ahci.c optional ahci -dev/hdmi/hdmi_if.m optional hdmi dev/hdmi/dwc_hdmi.c optional hdmi arm/freescale/imx/imx6_hdmi.c optional hdmi diff --git a/sys/arm/include/stdarg.h b/sys/arm/include/stdarg.h index a77fb333414..acb526429ac 100644 --- a/sys/arm/include/stdarg.h +++ b/sys/arm/include/stdarg.h @@ -1,9 +1,7 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2002 David E. O'Brien. All rights reserved. - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. + * Copyright (c) 2017 Poul-Henning Kamp. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -13,14 +11,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -29,55 +24,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)stdarg.h 8.1 (Berkeley) 6/10/93 * $FreeBSD$ */ #ifndef _MACHINE_STDARG_H_ #define _MACHINE_STDARG_H_ -#include -#include +#include -#ifndef _VA_LIST_DECLARED -#define _VA_LIST_DECLARED -typedef __va_list va_list; +#ifndef va_start + #error this file needs to be ported to your compiler #endif -#ifdef __GNUCLIKE_BUILTIN_STDARG - -#define va_start(ap, last) \ - __builtin_va_start((ap), (last)) - -#define va_arg(ap, type) \ - __builtin_va_arg((ap), type) - -#if __ISO_C_VISIBLE >= 1999 -#define va_copy(dest, src) \ - __builtin_va_copy((dest), (src)) -#endif - -#define va_end(ap) \ - __builtin_va_end(ap) - -#else /* !__GNUCLIKE_BUILTIN_STDARG */ - -#define __va_size(type) \ - (((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int)) - -#ifdef __GNUCLIKE_BUILTIN_NEXT_ARG -#define va_start(ap, last) \ - ((ap) = (va_list)__builtin_next_arg(last)) -#else /* !__GNUCLIKE_BUILTIN_NEXT_ARG */ -#define va_start(ap, last) \ - ((ap) = (va_list)&(last) + __va_size(last)) -#endif /* __GNUCLIKE_BUILTIN_NEXT_ARG */ - -#define va_arg(ap, type) \ - (*(type *)((ap) += __va_size(type), (ap) - __va_size(type))) - -#define va_end(ap) - -#endif /* __GNUCLIKE_BUILTIN_STDARG */ - #endif /* !_MACHINE_STDARG_H_ */ diff --git a/sys/arm/xscale/ixp425/ixdp425_pci.c b/sys/arm/xscale/ixp425/ixdp425_pci.c index e693dc47f5c..14b91784ce7 100644 --- a/sys/arm/xscale/ixp425/ixdp425_pci.c +++ b/sys/arm/xscale/ixp425/ixdp425_pci.c @@ -1,6 +1,6 @@ -/* $NetBSD: ixdp425_pci.c,v 1.5 2005/12/11 12:17:09 christos Exp $ */ +/* $NetBSD: ixdp425_pci.c,v 1.6 2009/10/21 14:15:51 rmind Exp $ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2003 * Ichiro FUKUHARA . @@ -14,12 +14,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Ichiro FUKUHARA. - * 4. The name of the company nor the name of the author may be used to - * endorse or promote products derived from this software without specific - * prior written permission. * * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sys/arm/xscale/ixp425/ixdp425reg.h b/sys/arm/xscale/ixp425/ixdp425reg.h index e07af7a1bd8..a27066238fa 100644 --- a/sys/arm/xscale/ixp425/ixdp425reg.h +++ b/sys/arm/xscale/ixp425/ixdp425reg.h @@ -1,6 +1,6 @@ -/* $NetBSD: ixdp425reg.h,v 1.6 2005/12/11 12:17:09 christos Exp $ */ +/* $NetBSD: ixdp425reg.h,v 1.7 2009/10/21 14:15:51 rmind Exp $ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2003 * Ichiro FUKUHARA . @@ -14,12 +14,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Ichiro FUKUHARA. - * 4. The name of the company nor the name of the author may be used to - * endorse or promote products derived from this software without specific - * prior written permission. * * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sys/arm/xscale/ixp425/ixp425.c b/sys/arm/xscale/ixp425/ixp425.c index 96d67555f49..8b7110a7063 100644 --- a/sys/arm/xscale/ixp425/ixp425.c +++ b/sys/arm/xscale/ixp425/ixp425.c @@ -1,7 +1,7 @@ -/* $NetBSD: ixp425.c,v 1.10 2005/12/11 12:16:51 christos Exp $ */ +/* $NetBSD: ixp425.c,v 1.13 2009/10/21 14:15:50 rmind Exp $ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2003 * Ichiro FUKUHARA . @@ -15,12 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Ichiro FUKUHARA. - * 4. The name of the company nor the name of the author may be used to - * endorse or promote products derived from this software without specific - * prior written permission. * * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sys/arm/xscale/ixp425/ixp425_npe.c b/sys/arm/xscale/ixp425/ixp425_npe.c index 8a2b941a211..a699c6ad3f8 100644 --- a/sys/arm/xscale/ixp425/ixp425_npe.c +++ b/sys/arm/xscale/ixp425/ixp425_npe.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause) * * Copyright (c) 2006-2008 Sam Leffler, Errno Consulting * All rights reserved. diff --git a/sys/arm/xscale/ixp425/ixp425_npereg.h b/sys/arm/xscale/ixp425/ixp425_npereg.h index 40e68e6fb54..cb9e6a4ef14 100644 --- a/sys/arm/xscale/ixp425/ixp425_npereg.h +++ b/sys/arm/xscale/ixp425/ixp425_npereg.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause) * * Copyright (c) 2006 Sam Leffler, Errno Consulting * All rights reserved. diff --git a/sys/arm/xscale/ixp425/ixp425_pci.c b/sys/arm/xscale/ixp425/ixp425_pci.c index 9fb49b73ba4..9811bd8feb2 100644 --- a/sys/arm/xscale/ixp425/ixp425_pci.c +++ b/sys/arm/xscale/ixp425/ixp425_pci.c @@ -1,7 +1,7 @@ -/* $NetBSD: ixp425_pci.c,v 1.5 2006/04/10 03:36:03 simonb Exp $ */ +/* $NetBSD: ixp425_pci.c,v 1.6 2009/10/21 14:15:50 rmind Exp $ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2003 * Ichiro FUKUHARA . @@ -15,12 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Ichiro FUKUHARA. - * 4. The name of the company nor the name of the author may be used to - * endorse or promote products derived from this software without specific - * prior written permission. * * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sys/arm/xscale/ixp425/ixp425_pci_space.c b/sys/arm/xscale/ixp425/ixp425_pci_space.c index 0aae0de01d2..d1680dc22f6 100644 --- a/sys/arm/xscale/ixp425/ixp425_pci_space.c +++ b/sys/arm/xscale/ixp425/ixp425_pci_space.c @@ -1,7 +1,7 @@ -/* $NetBSD: ixp425_pci_space.c,v 1.6 2006/04/10 03:36:03 simonb Exp $ */ +/* $NetBSD: ixp425_pci_space.c,v 1.7 2009/10/21 14:15:51 rmind Exp $ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2003 * Ichiro FUKUHARA . @@ -15,12 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Ichiro FUKUHARA. - * 4. The name of the company nor the name of the author may be used to - * endorse or promote products derived from this software without specific - * prior written permission. * * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sys/arm/xscale/ixp425/ixp425_space.c b/sys/arm/xscale/ixp425/ixp425_space.c index 05db437f132..1dcc545ea22 100644 --- a/sys/arm/xscale/ixp425/ixp425_space.c +++ b/sys/arm/xscale/ixp425/ixp425_space.c @@ -1,7 +1,7 @@ -/* $NetBSD: ixp425_space.c,v 1.6 2006/04/10 03:36:03 simonb Exp $ */ +/* $NetBSD: ixp425_space.c,v 1.7 2009/10/21 14:15:51 rmind Exp $ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2003 * Ichiro FUKUHARA . @@ -15,12 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Ichiro FUKUHARA. - * 4. The name of the company nor the name of the author may be used to - * endorse or promote products derived from this software without specific - * prior written permission. * * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sys/arm/xscale/ixp425/ixp425_timer.c b/sys/arm/xscale/ixp425/ixp425_timer.c index 186fdfd5625..b9122c1932a 100644 --- a/sys/arm/xscale/ixp425/ixp425_timer.c +++ b/sys/arm/xscale/ixp425/ixp425_timer.c @@ -1,7 +1,7 @@ -/* $NetBSD: ixp425_timer.c,v 1.11 2006/04/10 03:36:03 simonb Exp $ */ +/* $NetBSD: ixp425_timer.c,v 1.15 2009/10/21 14:15:51 rmind Exp $ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2003 * Ichiro FUKUHARA . @@ -15,12 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Ichiro FUKUHARA. - * 4. The name of the company nor the name of the author may be used to - * endorse or promote products derived from this software without specific - * prior written permission. * * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sys/arm/xscale/ixp425/ixp425reg.h b/sys/arm/xscale/ixp425/ixp425reg.h index 4f3b258a309..14a3c9aab22 100644 --- a/sys/arm/xscale/ixp425/ixp425reg.h +++ b/sys/arm/xscale/ixp425/ixp425reg.h @@ -1,6 +1,6 @@ -/* $NetBSD: ixp425reg.h,v 1.19 2005/12/11 12:16:51 christos Exp $ */ +/* $NetBSD: ixp425reg.h,v 1.21 2009/10/21 14:15:51 rmind Exp $ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2003 * Ichiro FUKUHARA . @@ -14,12 +14,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Ichiro FUKUHARA. - * 4. The name of the company nor the name of the author may be used to - * endorse or promote products derived from this software without specific - * prior written permission. * * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sys/arm/xscale/ixp425/ixp425var.h b/sys/arm/xscale/ixp425/ixp425var.h index 7aa3d4db676..27d38c15dbf 100644 --- a/sys/arm/xscale/ixp425/ixp425var.h +++ b/sys/arm/xscale/ixp425/ixp425var.h @@ -1,7 +1,7 @@ -/* $NetBSD: ixp425var.h,v 1.10 2006/04/10 03:36:03 simonb Exp $ */ +/* $NetBSD: ixp425var.h,v 1.12 2009/10/21 14:15:51 rmind Exp $ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * * Copyright (c) 2003 * Ichiro FUKUHARA . @@ -15,12 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Ichiro FUKUHARA. - * 4. The name of the company nor the name of the author may be used to - * endorse or promote products derived from this software without specific - * prior written permission. * * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sys/arm64/arm64/gic_v3.c b/sys/arm64/arm64/gic_v3.c index e07dad15b99..924cf8ce936 100644 --- a/sys/arm64/arm64/gic_v3.c +++ b/sys/arm64/arm64/gic_v3.c @@ -408,9 +408,7 @@ arm_gic_v3_intr(void *arg) struct intr_pic *pic; uint64_t active_irq; struct trapframe *tf; - bool first; - first = true; pic = sc->gic_pic; while (1) { diff --git a/sys/arm64/arm64/gicv3_its.c b/sys/arm64/arm64/gicv3_its.c index 0191003e4d1..e365e678f0c 100644 --- a/sys/arm64/arm64/gicv3_its.c +++ b/sys/arm64/arm64/gicv3_its.c @@ -1105,12 +1105,10 @@ static int gicv3_its_release_msi(device_t dev, device_t child, int count, struct intr_irqsrc **isrc) { - struct gicv3_its_softc *sc; struct gicv3_its_irqsrc *girq; struct its_dev *its_dev; int i; - sc = device_get_softc(dev); its_dev = its_device_find(dev, child); KASSERT(its_dev != NULL, @@ -1165,11 +1163,9 @@ gicv3_its_alloc_msix(device_t dev, device_t child, device_t *pic, static int gicv3_its_release_msix(device_t dev, device_t child, struct intr_irqsrc *isrc) { - struct gicv3_its_softc *sc; struct gicv3_its_irqsrc *girq; struct its_dev *its_dev; - sc = device_get_softc(dev); its_dev = its_device_find(dev, child); KASSERT(its_dev != NULL, @@ -1405,9 +1401,7 @@ its_cmd_prepare(struct its_cmd *cmd, struct its_cmd_desc *desc) uint64_t target; uint8_t cmd_type; u_int size; - boolean_t error; - error = FALSE; cmd_type = desc->cmd_type; target = ITS_TARGET_NONE; diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c index 99938499eaa..157081d68dd 100644 --- a/sys/arm64/arm64/machdep.c +++ b/sys/arm64/arm64/machdep.c @@ -630,14 +630,13 @@ sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) struct sigframe *fp, frame; struct sigacts *psp; struct sysentvec *sysent; - int code, onstack, sig; + int onstack, sig; td = curthread; p = td->td_proc; PROC_LOCK_ASSERT(p, MA_OWNED); sig = ksi->ksi_signo; - code = ksi->ksi_code; psp = p->p_sigacts; mtx_assert(&psp->ps_mtx, MA_OWNED); diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c index f4831b5c34b..76b07e73090 100644 --- a/sys/arm64/arm64/pmap.c +++ b/sys/arm64/arm64/pmap.c @@ -621,7 +621,7 @@ pmap_bootstrap_l2(vm_offset_t l1pt, vm_offset_t va, vm_offset_t l2_start) static vm_offset_t pmap_bootstrap_l3(vm_offset_t l1pt, vm_offset_t va, vm_offset_t l3_start) { - vm_offset_t l2pt, l3pt; + vm_offset_t l3pt; vm_paddr_t pa; pd_entry_t *l2; u_int l2_slot; @@ -630,7 +630,6 @@ pmap_bootstrap_l3(vm_offset_t l1pt, vm_offset_t va, vm_offset_t l3_start) l2 = pmap_l2(kernel_pmap, va); l2 = (pd_entry_t *)rounddown2((uintptr_t)l2, PAGE_SIZE); - l2pt = (vm_offset_t)l2; l2_slot = pmap_l2_index(va); l3pt = l3_start; diff --git a/sys/arm64/include/stdarg.h b/sys/arm64/include/stdarg.h index 49811be0856..acb526429ac 100644 --- a/sys/arm64/include/stdarg.h +++ b/sys/arm64/include/stdarg.h @@ -1,7 +1,7 @@ /*- - * Copyright (c) 2002 David E. O'Brien. All rights reserved. - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2017 Poul-Henning Kamp. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -11,14 +11,11 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -27,41 +24,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)stdarg.h 8.1 (Berkeley) 6/10/93 * $FreeBSD$ */ #ifndef _MACHINE_STDARG_H_ #define _MACHINE_STDARG_H_ -#include -#include +#include -#ifndef _VA_LIST_DECLARED -#define _VA_LIST_DECLARED -typedef __va_list va_list; +#ifndef va_start + #error this file needs to be ported to your compiler #endif -#ifdef __GNUCLIKE_BUILTIN_STDARG - -#define va_start(ap, last) \ - __builtin_va_start((ap), (last)) - -#define va_arg(ap, type) \ - __builtin_va_arg((ap), type) - -#if __ISO_C_VISIBLE >= 1999 -#define va_copy(dest, src) \ - __builtin_va_copy((dest), (src)) -#endif - -#define va_end(ap) \ - __builtin_va_end(ap) - -#else /* !__GNUCLIKE_BUILTIN_STDARG */ - -#error no support for your compiler - -#endif /* __GNUCLIKE_BUILTIN_STDARG */ - #endif /* !_MACHINE_STDARG_H_ */ diff --git a/sys/cam/ata/ata_da.c b/sys/cam/ata/ata_da.c index 21a7f60a7d9..4e75bc5e2fd 100644 --- a/sys/cam/ata/ata_da.c +++ b/sys/cam/ata/ata_da.c @@ -2631,10 +2631,8 @@ adaprobedone(struct cam_periph *periph, union ccb *ccb) static void adazonedone(struct cam_periph *periph, union ccb *ccb) { - struct ada_softc *softc; struct bio *bp; - softc = periph->softc; bp = (struct bio *)ccb->ccb_h.ccb_bp; switch (bp->bio_zone.zone_cmd) { @@ -2649,7 +2647,7 @@ adazonedone(struct cam_periph *periph, union ccb *ccb) struct scsi_report_zones_hdr *hdr; struct scsi_report_zones_desc *desc; struct disk_zone_rep_entry *entry; - uint32_t num_alloced, hdr_len, num_avail; + uint32_t hdr_len, num_avail; uint32_t num_to_fill, i; rep = &bp->bio_zone.zone_params.report; @@ -2664,7 +2662,6 @@ adazonedone(struct cam_periph *periph, union ccb *ccb) * be different than the amount of data transferred to * the user. */ - num_alloced = rep->entries_allocated; hdr = (struct scsi_report_zones_hdr *)ccb->ataio.data_ptr; if (avail_len < sizeof(*hdr)) { /* diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index 87881ff8553..1e1343d4c0a 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -13352,8 +13352,8 @@ ctl_work_thread(void *arg) * We handle the queues in this order: * - ISC * - done queue (to free up resources, unblock other commands) - * - RtR queue * - incoming queue + * - RtR queue * * If those queues are empty, we break out of the loop and * go to sleep. diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index ac70ae4f9bb..16085cf8390 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -1525,7 +1525,6 @@ daclose(struct disk *dp) struct cam_periph *periph; struct da_softc *softc; union ccb *ccb; - int error; periph = (struct cam_periph *)dp->d_drv1; softc = (struct da_softc *)periph->softc; @@ -1544,7 +1543,7 @@ daclose(struct disk *dp) /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG, /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE, 5 * 60 * 1000); - error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0, + cam_periph_runccb(ccb, daerror, /*cam_flags*/0, /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR, softc->disk->d_devstat); softc->flags &= ~DA_FLAG_DIRTY; @@ -2311,7 +2310,7 @@ dadeletemethodsysctl(SYSCTL_HANDLER_ARGS) char buf[16]; const char *p; struct da_softc *softc; - int i, error, methods, value; + int i, error, value; softc = (struct da_softc *)arg1; @@ -2324,7 +2323,6 @@ dadeletemethodsysctl(SYSCTL_HANDLER_ARGS) error = sysctl_handle_string(oidp, buf, sizeof(buf), req); if (error != 0 || req->newptr == NULL) return (error); - methods = softc->delete_available | (1 << DA_DELETE_DISABLE); for (i = 0; i <= DA_DELETE_MAX; i++) { if (strcmp(buf, da_delete_method_names[i]) == 0) break; @@ -3970,7 +3968,7 @@ dazonedone(struct cam_periph *periph, union ccb *ccb) struct scsi_report_zones_hdr *hdr; struct scsi_report_zones_desc *desc; struct disk_zone_rep_entry *entry; - uint32_t num_alloced, hdr_len, num_avail; + uint32_t hdr_len, num_avail; uint32_t num_to_fill, i; int ata; @@ -3987,7 +3985,6 @@ dazonedone(struct cam_periph *periph, union ccb *ccb) * the user. */ bp->bio_resid = ccb->csio.resid; - num_alloced = rep->entries_allocated; hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr; if (avail_len < sizeof(*hdr)) { /* diff --git a/sys/cam/scsi/scsi_pass.c b/sys/cam/scsi/scsi_pass.c index 1e8eeb4b69b..160f6b11886 100644 --- a/sys/cam/scsi/scsi_pass.c +++ b/sys/cam/scsi/scsi_pass.c @@ -1699,13 +1699,11 @@ static int passmemdone(struct cam_periph *periph, struct pass_io_req *io_req) { struct pass_softc *softc; - union ccb *ccb; int error; int i; error = 0; softc = (struct pass_softc *)periph->softc; - ccb = &io_req->ccb; switch (io_req->data_flags) { case CAM_DATA_VADDR: diff --git a/sys/conf/files b/sys/conf/files index c6f57082743..0073ce28dd4 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -4255,7 +4255,7 @@ netinet/sctp_asconf.c optional inet sctp | inet6 sctp netinet/sctp_auth.c optional inet sctp | inet6 sctp netinet/sctp_bsd_addr.c optional inet sctp | inet6 sctp netinet/sctp_cc_functions.c optional inet sctp | inet6 sctp -netinet/sctp_crc32.c optional inet sctp | inet6 sctp +netinet/sctp_crc32.c optional inet | inet6 netinet/sctp_indata.c optional inet sctp | inet6 sctp netinet/sctp_input.c optional inet sctp | inet6 sctp netinet/sctp_output.c optional inet sctp | inet6 sctp diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 index 3b6474d1196..3e35a8ccb44 100644 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -24,8 +24,8 @@ cloudabi64_vdso_blob.o optional compat_cloudabi64 \ clean "cloudabi64_vdso_blob.o" # arm/allwinner/a10_ehci.c optional ehci aw_ehci fdt -arm/allwinner/a10_gpio.c optional gpio aw_gpio fdt -arm/allwinner/a10_mmc.c optional mmc aw_mmc fdt +arm/allwinner/aw_gpio.c optional gpio aw_gpio fdt +arm/allwinner/aw_mmc.c optional mmc aw_mmc fdt arm/allwinner/a64/a64_padconf.c optional soc_allwinner_a64 fdt arm/allwinner/a64/a64_r_padconf.c optional soc_allwinner_a64 fdt arm/allwinner/h3/h3_padconf.c optional soc_allwinner_h5 fdt diff --git a/sys/conf/files.i386 b/sys/conf/files.i386 index 32e6aa426b4..eb44f439e2c 100644 --- a/sys/conf/files.i386 +++ b/sys/conf/files.i386 @@ -518,7 +518,7 @@ i386/ibcs2/ibcs2_util.c optional ibcs2 i386/ibcs2/ibcs2_xenix.c optional ibcs2 i386/ibcs2/ibcs2_xenix_sysent.c optional ibcs2 i386/ibcs2/imgact_coff.c optional ibcs2 -i386/isa/elink.c optional ep | ie +i386/isa/elink.c optional ep i386/isa/npx.c standard i386/isa/pmtimer.c optional pmtimer i386/isa/prof_machdep.c optional profiling-routine diff --git a/sys/conf/files.powerpc b/sys/conf/files.powerpc index 932a2ae80c3..941c1f31e11 100644 --- a/sys/conf/files.powerpc +++ b/sys/conf/files.powerpc @@ -158,7 +158,6 @@ powerpc/ofw/ofw_real.c optional aim powerpc/ofw/ofw_syscons.c optional sc aim powerpc/ofw/ofwcall32.S optional aim powerpc powerpc/ofw/ofwcall64.S optional aim powerpc64 -powerpc/ofw/ofwmagic.S optional aim powerpc/ofw/openpic_ofw.c optional aim | fdt powerpc/ofw/rtas.c optional aim powerpc/powermac/ata_kauai.c optional powermac ata | powermac atamacio diff --git a/sys/conf/options.arm b/sys/conf/options.arm index 91ca74b8edb..3f91b2896e5 100644 --- a/sys/conf/options.arm +++ b/sys/conf/options.arm @@ -35,6 +35,7 @@ KERNBASE opt_global.h KERNVIRTADDR opt_global.h LINUX_BOOT_ABI opt_global.h LOADERRAMADDR opt_global.h +LOCORE_MAP_MB opt_locore.h NKPT2PG opt_pmap.h PHYSADDR opt_global.h PLATFORM opt_global.h diff --git a/sys/dev/al_eth/al_eth.c b/sys/dev/al_eth/al_eth.c index 79523fd189c..211e55c40fd 100644 --- a/sys/dev/al_eth/al_eth.c +++ b/sys/dev/al_eth/al_eth.c @@ -272,7 +272,6 @@ al_probe(device_t dev) static int al_attach(device_t dev) { - struct al_eth_lm_context *lm_context; struct al_eth_adapter *adapter; struct sysctl_oid_list *child; struct sysctl_ctx_list *ctx; @@ -305,8 +304,6 @@ al_attach(device_t dev) g_adapters[g_adapters_count] = adapter; - lm_context = &adapter->lm_context; - bar_udma = PCIR_BAR(AL_ETH_UDMA_BAR); adapter->udma_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &bar_udma, RF_ACTIVE); diff --git a/sys/dev/ath/if_ath.c b/sys/dev/ath/if_ath.c index cc7bb84945a..81046b5b31d 100644 --- a/sys/dev/ath/if_ath.c +++ b/sys/dev/ath/if_ath.c @@ -1081,7 +1081,7 @@ ath_attach(u_int16_t devid, struct ath_softc *sc) sc->sc_txq_node_psq_maxdepth = 16; /* - * Default the maximum queue to to 1/4'th the TX buffers, or + * Default the maximum queue to 1/4'th the TX buffers, or * 64, whichever is smaller. */ sc->sc_txq_node_maxdepth = MIN(64, ath_txbuf / 4); diff --git a/sys/dev/axgbe/xgbe-drv.c b/sys/dev/axgbe/xgbe-drv.c index 32a6cfe239c..81f8f30b927 100644 --- a/sys/dev/axgbe/xgbe-drv.c +++ b/sys/dev/axgbe/xgbe-drv.c @@ -954,7 +954,7 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget) struct xgbe_packet_data *packet; struct ifnet *ifp = pdata->netdev; struct mbuf *m; - unsigned int incomplete, context_next, context; + unsigned int incomplete, context_next; unsigned int received = 0; int packet_count = 0; @@ -992,9 +992,6 @@ static int xgbe_rx_poll(struct xgbe_channel *channel, int budget) context_next = XGMAC_GET_BITS(packet->attributes, RX_PACKET_ATTRIBUTES, CONTEXT_NEXT); - context = XGMAC_GET_BITS(packet->attributes, - RX_PACKET_ATTRIBUTES, - CONTEXT); /* Earlier error, just drain the remaining data */ if (incomplete || context_next) { diff --git a/sys/dev/axgbe/xgbe-mdio.c b/sys/dev/axgbe/xgbe-mdio.c index 6967d54da52..850a58e0410 100644 --- a/sys/dev/axgbe/xgbe-mdio.c +++ b/sys/dev/axgbe/xgbe-mdio.c @@ -752,36 +752,30 @@ static void xgbe_an_init(struct xgbe_prv_data *pdata) static void xgbe_phy_adjust_link(struct xgbe_prv_data *pdata) { - int new_state = 0; if (pdata->phy.link) { /* Flow control support */ pdata->pause_autoneg = pdata->phy.pause_autoneg; if (pdata->tx_pause != pdata->phy.tx_pause) { - new_state = 1; pdata->hw_if.config_tx_flow_control(pdata); pdata->tx_pause = pdata->phy.tx_pause; } if (pdata->rx_pause != pdata->phy.rx_pause) { - new_state = 1; pdata->hw_if.config_rx_flow_control(pdata); pdata->rx_pause = pdata->phy.rx_pause; } /* Speed support */ if (pdata->phy_speed != pdata->phy.speed) { - new_state = 1; pdata->phy_speed = pdata->phy.speed; } if (pdata->phy_link != pdata->phy.link) { - new_state = 1; pdata->phy_link = pdata->phy.link; } } else if (pdata->phy_link) { - new_state = 1; pdata->phy_link = 0; pdata->phy_speed = SPEED_UNKNOWN; } diff --git a/sys/dev/bhnd/nvram/bhnd_nvram_store_subr.c b/sys/dev/bhnd/nvram/bhnd_nvram_store_subr.c index 7230c91d243..730b9d51da4 100644 --- a/sys/dev/bhnd/nvram/bhnd_nvram_store_subr.c +++ b/sys/dev/bhnd/nvram/bhnd_nvram_store_subr.c @@ -748,7 +748,7 @@ bhnd_nvstore_var_register_path(struct bhnd_nvram_store *sc, } /** - * Resolve the device path entry referenced referenced by @p info. + * Resolve the device path entry referenced by @p info. * * @param sc The NVRAM store to be updated. * @param info Variable name information descriptor containing diff --git a/sys/dev/cadence/if_cgem.c b/sys/dev/cadence/if_cgem.c index 05dac8c0fc6..a7010b5ac11 100644 --- a/sys/dev/cadence/if_cgem.c +++ b/sys/dev/cadence/if_cgem.c @@ -811,7 +811,7 @@ cgem_start_locked(if_t ifp) WR4(sc, CGEM_NET_CTRL, sc->net_ctl_shadow | CGEM_NET_CTRL_START_TX); - /* If there is a BPF listener, bounce a copy to to him. */ + /* If there is a BPF listener, bounce a copy to him. */ ETHER_BPF_MTAP(ifp, m); } } diff --git a/sys/dev/cesa/cesa.h b/sys/dev/cesa/cesa.h index 3b87e8d7f21..57a114599f0 100644 --- a/sys/dev/cesa/cesa.h +++ b/sys/dev/cesa/cesa.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-4-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (C) 2009-2011 Semihalf. * All rights reserved. diff --git a/sys/dev/cxgbe/iw_cxgbe/cm.c b/sys/dev/cxgbe/iw_cxgbe/cm.c index a38e4db6699..ce42a90ad59 100644 --- a/sys/dev/cxgbe/iw_cxgbe/cm.c +++ b/sys/dev/cxgbe/iw_cxgbe/cm.c @@ -339,23 +339,27 @@ find_real_listen_ep(struct c4iw_listen_ep *master_lep, struct socket *so) { struct adapter *adap = NULL; struct c4iw_listen_ep *lep = NULL; - struct sockaddr_storage remote = { 0 }; - struct ifnet *new_conn_ifp = NULL; + struct ifnet *ifp = NULL, *hw_ifp = NULL; struct listen_port_info *port_info = NULL; - int err = 0, i = 0, - found_portinfo = 0, found_lep = 0; + int i = 0, found_portinfo = 0, found_lep = 0; uint16_t port; - /* STEP 1: get 'ifnet' based on socket's remote address */ - GET_REMOTE_ADDR(&remote, so); - - err = get_ifnet_from_raddr(&remote, &new_conn_ifp); - if (err) { - CTR4(KTR_IW_CXGBE, "%s: Failed to get ifnet, sock %p, " - "master_lep %p err %d", - __func__, so, master_lep, err); - return (NULL); - } + /* + * STEP 1: Figure out 'ifp' of the physical interface, not pseudo + * interfaces like vlan, lagg, etc.. + * TBD: lagg support, lagg + vlan support. + */ + ifp = TOEPCB(so)->l2te->ifp; + if (ifp->if_type == IFT_L2VLAN) { + hw_ifp = VLAN_TRUNKDEV(ifp); + if (hw_ifp == NULL) { + CTR4(KTR_IW_CXGBE, "%s: Failed to get parent ifnet of " + "vlan ifnet %p, sock %p, master_lep %p", + __func__, ifp, so, master_lep); + return (NULL); + } + } else + hw_ifp = ifp; /* STEP 2: Find 'port_info' with listener local port address. */ port = (master_lep->com.local_addr.ss_family == AF_INET) ? @@ -379,7 +383,7 @@ find_real_listen_ep(struct c4iw_listen_ep *master_lep, struct socket *so) list_for_each_entry(lep, &port_info->lep_list, listen_ep_list) { adap = lep->com.dev->rdev.adap; for_each_port(adap, i) { - if (new_conn_ifp == adap->port[i]->vi[0].ifp) { + if (hw_ifp == adap->port[i]->vi[0].ifp) { found_lep =1; goto out; } diff --git a/sys/dev/cxgbe/t4_sge.c b/sys/dev/cxgbe/t4_sge.c index 51a53a85d3f..f8a9f8bc690 100644 --- a/sys/dev/cxgbe/t4_sge.c +++ b/sys/dev/cxgbe/t4_sge.c @@ -198,6 +198,8 @@ static int free_ring(struct adapter *, bus_dma_tag_t, bus_dmamap_t, bus_addr_t, static int alloc_iq_fl(struct vi_info *, struct sge_iq *, struct sge_fl *, int, int); static int free_iq_fl(struct vi_info *, struct sge_iq *, struct sge_fl *); +static void add_iq_sysctls(struct sysctl_ctx_list *, struct sysctl_oid *, + struct sge_iq *); static void add_fl_sysctls(struct adapter *, struct sysctl_ctx_list *, struct sysctl_oid *, struct sge_fl *); static int alloc_fwq(struct adapter *); @@ -2823,6 +2825,27 @@ free_iq_fl(struct vi_info *vi, struct sge_iq *iq, struct sge_fl *fl) return (0); } +static void +add_iq_sysctls(struct sysctl_ctx_list *ctx, struct sysctl_oid *oid, + struct sge_iq *iq) +{ + struct sysctl_oid_list *children = SYSCTL_CHILDREN(oid); + + SYSCTL_ADD_UAUTO(ctx, children, OID_AUTO, "ba", CTLFLAG_RD, &iq->ba, + "bus address of descriptor ring"); + SYSCTL_ADD_INT(ctx, children, OID_AUTO, "dmalen", CTLFLAG_RD, NULL, + iq->qsize * IQ_ESIZE, "descriptor ring size in bytes"); + SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "abs_id", + CTLTYPE_INT | CTLFLAG_RD, &iq->abs_id, 0, sysctl_uint16, "I", + "absolute id of the queue"); + SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cntxt_id", + CTLTYPE_INT | CTLFLAG_RD, &iq->cntxt_id, 0, sysctl_uint16, "I", + "SGE context id of the queue"); + SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "cidx", + CTLTYPE_INT | CTLFLAG_RD, &iq->cidx, 0, sysctl_uint16, "I", + "consumer index"); +} + static void add_fl_sysctls(struct adapter *sc, struct sysctl_ctx_list *ctx, struct sysctl_oid *oid, struct sge_fl *fl) @@ -2890,21 +2913,7 @@ alloc_fwq(struct adapter *sc) oid = SYSCTL_ADD_NODE(&sc->ctx, children, OID_AUTO, "fwq", CTLFLAG_RD, NULL, "firmware event queue"); - children = SYSCTL_CHILDREN(oid); - - SYSCTL_ADD_UAUTO(&sc->ctx, children, OID_AUTO, "ba", CTLFLAG_RD, - &fwq->ba, "bus address of descriptor ring"); - SYSCTL_ADD_INT(&sc->ctx, children, OID_AUTO, "dmalen", CTLFLAG_RD, NULL, - fwq->qsize * IQ_ESIZE, "descriptor ring size in bytes"); - SYSCTL_ADD_PROC(&sc->ctx, children, OID_AUTO, "abs_id", - CTLTYPE_INT | CTLFLAG_RD, &fwq->abs_id, 0, sysctl_uint16, "I", - "absolute id of the queue"); - SYSCTL_ADD_PROC(&sc->ctx, children, OID_AUTO, "cntxt_id", - CTLTYPE_INT | CTLFLAG_RD, &fwq->cntxt_id, 0, sysctl_uint16, "I", - "SGE context id of the queue"); - SYSCTL_ADD_PROC(&sc->ctx, children, OID_AUTO, "cidx", - CTLTYPE_INT | CTLFLAG_RD, &fwq->cidx, 0, sysctl_uint16, "I", - "consumer index"); + add_iq_sysctls(&sc->ctx, oid, fwq); return (0); } @@ -3007,19 +3016,7 @@ alloc_rxq(struct vi_info *vi, struct sge_rxq *rxq, int intr_idx, int idx, NULL, "rx queue"); children = SYSCTL_CHILDREN(oid); - SYSCTL_ADD_UAUTO(&vi->ctx, children, OID_AUTO, "ba", CTLFLAG_RD, - &rxq->iq.ba, "bus address of descriptor ring"); - SYSCTL_ADD_INT(&vi->ctx, children, OID_AUTO, "dmalen", CTLFLAG_RD, NULL, - rxq->iq.qsize * IQ_ESIZE, "descriptor ring size in bytes"); - SYSCTL_ADD_PROC(&vi->ctx, children, OID_AUTO, "abs_id", - CTLTYPE_INT | CTLFLAG_RD, &rxq->iq.abs_id, 0, sysctl_uint16, "I", - "absolute id of the queue"); - SYSCTL_ADD_PROC(&vi->ctx, children, OID_AUTO, "cntxt_id", - CTLTYPE_INT | CTLFLAG_RD, &rxq->iq.cntxt_id, 0, sysctl_uint16, "I", - "SGE context id of the queue"); - SYSCTL_ADD_PROC(&vi->ctx, children, OID_AUTO, "cidx", - CTLTYPE_INT | CTLFLAG_RD, &rxq->iq.cidx, 0, sysctl_uint16, "I", - "consumer index"); + add_iq_sysctls(&vi->ctx, oid, &rxq->iq); #if defined(INET) || defined(INET6) SYSCTL_ADD_U64(&vi->ctx, children, OID_AUTO, "lro_queued", CTLFLAG_RD, &rxq->lro.lro_queued, 0, NULL); @@ -3075,22 +3072,7 @@ alloc_ofld_rxq(struct vi_info *vi, struct sge_ofld_rxq *ofld_rxq, snprintf(name, sizeof(name), "%d", idx); oid = SYSCTL_ADD_NODE(&vi->ctx, children, OID_AUTO, name, CTLFLAG_RD, NULL, "rx queue"); - children = SYSCTL_CHILDREN(oid); - - SYSCTL_ADD_UAUTO(&vi->ctx, children, OID_AUTO, "ba", CTLFLAG_RD, - &ofld_rxq->iq.ba, "bus address of descriptor ring"); - SYSCTL_ADD_INT(&vi->ctx, children, OID_AUTO, "dmalen", CTLFLAG_RD, NULL, - ofld_rxq->iq.qsize * IQ_ESIZE, "descriptor ring size in bytes"); - SYSCTL_ADD_PROC(&vi->ctx, children, OID_AUTO, "abs_id", - CTLTYPE_INT | CTLFLAG_RD, &ofld_rxq->iq.abs_id, 0, sysctl_uint16, - "I", "absolute id of the queue"); - SYSCTL_ADD_PROC(&vi->ctx, children, OID_AUTO, "cntxt_id", - CTLTYPE_INT | CTLFLAG_RD, &ofld_rxq->iq.cntxt_id, 0, sysctl_uint16, - "I", "SGE context id of the queue"); - SYSCTL_ADD_PROC(&vi->ctx, children, OID_AUTO, "cidx", - CTLTYPE_INT | CTLFLAG_RD, &ofld_rxq->iq.cidx, 0, sysctl_uint16, "I", - "consumer index"); - + add_iq_sysctls(&vi->ctx, oid, &ofld_rxq->iq); add_fl_sysctls(pi->adapter, &vi->ctx, oid, &ofld_rxq->fl); return (rc); diff --git a/sys/dev/de/if_de.c b/sys/dev/de/if_de.c index 753c82a6f5a..0393bc5d1e8 100644 --- a/sys/dev/de/if_de.c +++ b/sys/dev/de/if_de.c @@ -3920,7 +3920,7 @@ tulip_txput(tulip_softc_t * const sc, struct mbuf *m) * a bit reminiscent of going on the Ark two by two * since each descriptor for the TULIP can describe * two buffers. So we advance through packet filling - * each of the two entries at a time to to fill each + * each of the two entries at a time to fill each * descriptor. Clear the first and last segment bits * in each descriptor (actually just clear everything * but the end-of-ring or chain bits) to make sure diff --git a/sys/dev/drm/mga_state.c b/sys/dev/drm/mga_state.c index 4d901975183..1a0832a806b 100644 --- a/sys/dev/drm/mga_state.c +++ b/sys/dev/drm/mga_state.c @@ -258,7 +258,7 @@ static __inline__ void mga_g200_emit_pipe(drm_mga_private_t * dev_priv) MGA_WR42, 0x0000ffff, MGA_WR60, 0x0000ffff); - /* Padding required to to hardware bug. + /* Padding required due to hardware bug. */ DMA_BLOCK(MGA_DMAPAD, 0xffffffff, MGA_DMAPAD, 0xffffffff, @@ -340,7 +340,7 @@ static __inline__ void mga_g400_emit_pipe(drm_mga_private_t * dev_priv) MGA_WR52, MGA_G400_WR_MAGIC, /* tex1 width */ MGA_WR60, MGA_G400_WR_MAGIC); /* tex1 height */ - /* Padding required to to hardware bug */ + /* Padding required due to hardware bug */ DMA_BLOCK(MGA_DMAPAD, 0xffffffff, MGA_DMAPAD, 0xffffffff, MGA_DMAPAD, 0xffffffff, diff --git a/sys/dev/e1000/e1000_82543.c b/sys/dev/e1000/e1000_82543.c index c7a676cd49c..48ad49294f3 100644 --- a/sys/dev/e1000/e1000_82543.c +++ b/sys/dev/e1000/e1000_82543.c @@ -1310,7 +1310,7 @@ static s32 e1000_check_for_copper_link_82543(struct e1000_hw *hw) * turn it on. For compatibility with a TBI link * partner, we will store bad packets. Some * frames have an additional byte on the end and - * will look like CRC errors to to the hardware. + * will look like CRC errors to the hardware. */ if (!e1000_tbi_sbp_enabled_82543(hw)) { e1000_set_tbi_sbp_82543(hw, TRUE); diff --git a/sys/dev/e1000/e1000_api.c b/sys/dev/e1000/e1000_api.c index cd82607c243..26f4a64e561 100644 --- a/sys/dev/e1000/e1000_api.c +++ b/sys/dev/e1000/e1000_api.c @@ -311,6 +311,16 @@ s32 e1000_set_mac_type(struct e1000_hw *hw) case E1000_DEV_ID_PCH_SPT_I219_V5: mac->type = e1000_pch_spt; break; + case E1000_DEV_ID_PCH_CNP_I219_LM6: + case E1000_DEV_ID_PCH_CNP_I219_V6: + case E1000_DEV_ID_PCH_CNP_I219_LM7: + case E1000_DEV_ID_PCH_CNP_I219_V7: + case E1000_DEV_ID_PCH_ICP_I219_LM8: + case E1000_DEV_ID_PCH_ICP_I219_V8: + case E1000_DEV_ID_PCH_ICP_I219_LM9: + case E1000_DEV_ID_PCH_ICP_I219_V9: + mac->type = e1000_pch_cnp; + break; case E1000_DEV_ID_82575EB_COPPER: case E1000_DEV_ID_82575EB_FIBER_SERDES: case E1000_DEV_ID_82575GB_QUAD_COPPER: @@ -462,6 +472,7 @@ s32 e1000_setup_init_funcs(struct e1000_hw *hw, bool init_device) case e1000_pch2lan: case e1000_pch_lpt: case e1000_pch_spt: + case e1000_pch_cnp: e1000_init_function_pointers_ich8lan(hw); break; case e1000_82575: diff --git a/sys/dev/e1000/e1000_hw.h b/sys/dev/e1000/e1000_hw.h index 82e783fe93e..2c17a0226b3 100644 --- a/sys/dev/e1000/e1000_hw.h +++ b/sys/dev/e1000/e1000_hw.h @@ -147,6 +147,14 @@ struct e1000_hw; #define E1000_DEV_ID_PCH_SPT_I219_V4 0x15D8 #define E1000_DEV_ID_PCH_SPT_I219_LM5 0x15E3 #define E1000_DEV_ID_PCH_SPT_I219_V5 0x15D6 +#define E1000_DEV_ID_PCH_CNP_I219_LM6 0x15BD +#define E1000_DEV_ID_PCH_CNP_I219_V6 0x15BE +#define E1000_DEV_ID_PCH_CNP_I219_LM7 0x15BB +#define E1000_DEV_ID_PCH_CNP_I219_V7 0x15BC +#define E1000_DEV_ID_PCH_ICP_I219_LM8 0x15DF +#define E1000_DEV_ID_PCH_ICP_I219_V8 0x15E0 +#define E1000_DEV_ID_PCH_ICP_I219_LM9 0x15E1 +#define E1000_DEV_ID_PCH_ICP_I219_V9 0x15E2 #define E1000_DEV_ID_82576 0x10C9 #define E1000_DEV_ID_82576_FIBER 0x10E6 #define E1000_DEV_ID_82576_SERDES 0x10E7 @@ -233,6 +241,7 @@ enum e1000_mac_type { e1000_pch2lan, e1000_pch_lpt, e1000_pch_spt, + e1000_pch_cnp, e1000_82575, e1000_82576, e1000_82580, diff --git a/sys/dev/e1000/e1000_ich8lan.c b/sys/dev/e1000/e1000_ich8lan.c index 7c4ba24b90e..43241ff7b9e 100644 --- a/sys/dev/e1000/e1000_ich8lan.c +++ b/sys/dev/e1000/e1000_ich8lan.c @@ -345,6 +345,7 @@ static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw) switch (hw->mac.type) { case e1000_pch_lpt: case e1000_pch_spt: + case e1000_pch_cnp: if (e1000_phy_is_accessible_pchlan(hw)) break; @@ -493,6 +494,7 @@ static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw) case e1000_pch2lan: case e1000_pch_lpt: case e1000_pch_spt: + case e1000_pch_cnp: /* In case the PHY needs to be in mdio slow mode, * set slow mode and try to get the PHY id again. */ @@ -794,6 +796,7 @@ static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw) /* fall-through */ case e1000_pch_lpt: case e1000_pch_spt: + case e1000_pch_cnp: /* multicast address update for pch2 */ mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_pch2lan; @@ -1831,6 +1834,7 @@ void e1000_init_function_pointers_ich8lan(struct e1000_hw *hw) case e1000_pch2lan: case e1000_pch_lpt: case e1000_pch_spt: + case e1000_pch_cnp: hw->phy.ops.init_params = e1000_init_phy_params_pchlan; break; default: @@ -2295,6 +2299,7 @@ static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw) case e1000_pch2lan: case e1000_pch_lpt: case e1000_pch_spt: + case e1000_pch_cnp: sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M; break; default: @@ -2655,6 +2660,8 @@ static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw) e1000_phy_sw_reset_generic(hw); ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, 0x3140); + if (ret_val) + return ret_val; } } @@ -3412,6 +3419,7 @@ static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank) switch (hw->mac.type) { case e1000_pch_spt: + case e1000_pch_cnp: bank1_offset = nvm->flash_bank_size; act_offset = E1000_ICH_NVM_SIG_WORD; @@ -4387,6 +4395,7 @@ static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw) switch (hw->mac.type) { case e1000_pch_lpt: case e1000_pch_spt: + case e1000_pch_cnp: word = NVM_COMPAT; valid_csum_mask = NVM_COMPAT_VALID_CSUM; break; diff --git a/sys/dev/e1000/e1000_ich8lan.h b/sys/dev/e1000/e1000_ich8lan.h index d61f4df8ca6..db37aab7a35 100644 --- a/sys/dev/e1000/e1000_ich8lan.h +++ b/sys/dev/e1000/e1000_ich8lan.h @@ -124,7 +124,8 @@ #define NVM_SIZE_MULTIPLIER 4096 /*multiplier for NVMS field*/ #define E1000_FLASH_BASE_ADDR 0xE000 /*offset of NVM access regs*/ #define E1000_CTRL_EXT_NVMVS 0x3 /*NVM valid sector */ -#define E1000_TARC0_CB_MULTIQ_3_REQ (1 << 28 | 1 << 29) +#define E1000_TARC0_CB_MULTIQ_3_REQ 0x30000000 +#define E1000_TARC0_CB_MULTIQ_2_REQ 0x20000000 #define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL #define E1000_ICH_RAR_ENTRIES 7 diff --git a/sys/dev/e1000/if_em.c b/sys/dev/e1000/if_em.c index f8e6ed00f8c..ee6eeed61e0 100644 --- a/sys/dev/e1000/if_em.c +++ b/sys/dev/e1000/if_em.c @@ -166,6 +166,14 @@ static pci_vendor_info_t em_vendor_info_array[] = PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_V4, "Intel(R) PRO/1000 Network Connection"), PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_LM5, "Intel(R) PRO/1000 Network Connection"), PVID(0x8086, E1000_DEV_ID_PCH_SPT_I219_V5, "Intel(R) PRO/1000 Network Connection"), + PVID(0x8086, E1000_DEV_ID_PCH_CNP_I219_LM6, "Intel(R) PRO/1000 Network Connection"), + PVID(0x8086, E1000_DEV_ID_PCH_CNP_I219_V6, "Intel(R) PRO/1000 Network Connection"), + PVID(0x8086, E1000_DEV_ID_PCH_CNP_I219_LM7, "Intel(R) PRO/1000 Network Connection"), + PVID(0x8086, E1000_DEV_ID_PCH_CNP_I219_V7, "Intel(R) PRO/1000 Network Connection"), + PVID(0x8086, E1000_DEV_ID_PCH_ICP_I219_LM8, "Intel(R) PRO/1000 Network Connection"), + PVID(0x8086, E1000_DEV_ID_PCH_ICP_I219_V8, "Intel(R) PRO/1000 Network Connection"), + PVID(0x8086, E1000_DEV_ID_PCH_ICP_I219_LM9, "Intel(R) PRO/1000 Network Connection"), + PVID(0x8086, E1000_DEV_ID_PCH_ICP_I219_V9, "Intel(R) PRO/1000 Network Connection"), /* required last entry */ PVID_END }; @@ -862,7 +870,7 @@ em_if_attach_pre(if_ctx_t ctx) ** so use the same tag and an offset handle for the ** FLASH read/write macros in the shared code. */ - else if (hw->mac.type == e1000_pch_spt) { + else if (hw->mac.type >= e1000_pch_spt) { adapter->osdep.flash_bus_space_tag = adapter->osdep.mem_bus_space_tag; adapter->osdep.flash_bus_space_handle = @@ -1132,6 +1140,7 @@ em_if_mtu_set(if_ctx_t ctx, uint32_t mtu) case e1000_pch2lan: case e1000_pch_lpt: case e1000_pch_spt: + case e1000_pch_cnp: case e1000_82574: case e1000_82583: case e1000_80003es2lan: @@ -2416,6 +2425,7 @@ em_reset(if_ctx_t ctx) case e1000_pch2lan: case e1000_pch_lpt: case e1000_pch_spt: + case e1000_pch_cnp: pba = E1000_PBA_26K; break; case e1000_82575: @@ -2524,6 +2534,7 @@ em_reset(if_ctx_t ctx) case e1000_pch2lan: case e1000_pch_lpt: case e1000_pch_spt: + case e1000_pch_cnp: hw->fc.high_water = 0x5C20; hw->fc.low_water = 0x5048; hw->fc.pause_time = 0x0650; @@ -3054,13 +3065,16 @@ em_initialize_transmit_unit(if_ctx_t ctx) /* This write will effectively turn on the transmit unit. */ E1000_WRITE_REG(&adapter->hw, E1000_TCTL, tctl); + /* SPT and KBL errata workarounds */ if (hw->mac.type == e1000_pch_spt) { u32 reg; reg = E1000_READ_REG(hw, E1000_IOSFPC); reg |= E1000_RCTL_RDMTS_HEX; E1000_WRITE_REG(hw, E1000_IOSFPC, reg); + /* i218-i219 Specification Update 1.5.4.4 */ reg = E1000_READ_REG(hw, E1000_TARC(0)); - reg |= E1000_TARC0_CB_MULTIQ_3_REQ; + reg &= E1000_TARC0_CB_MULTIQ_3_REQ; + reg |= E1000_TARC0_CB_MULTIQ_2_REQ; E1000_WRITE_REG(hw, E1000_TARC(0), reg); } } diff --git a/sys/dev/e1000/igb_txrx.c b/sys/dev/e1000/igb_txrx.c index 8a56c64b6c1..1a2f7fbbd41 100644 --- a/sys/dev/e1000/igb_txrx.c +++ b/sys/dev/e1000/igb_txrx.c @@ -237,7 +237,7 @@ igb_isc_txd_encap(void *arg, if_pkt_info_t pi) int nsegs = pi->ipi_nsegs; bus_dma_segment_t *segs = pi->ipi_segs; union e1000_adv_tx_desc *txd = NULL; - int i, j, first, pidx_last; + int i, j, pidx_last; u32 olinfo_status, cmd_type_len, txd_flags; qidx_t ntxd; @@ -249,7 +249,7 @@ igb_isc_txd_encap(void *arg, if_pkt_info_t pi) if (pi->ipi_mflags & M_VLANTAG) cmd_type_len |= E1000_ADVTXD_DCMD_VLE; - first = i = pi->ipi_pidx; + i = pi->ipi_pidx; ntxd = scctx->isc_ntxd[0]; txd_flags = pi->ipi_flags & IPI_TX_INTR ? E1000_ADVTXD_DCMD_RS : 0; /* Consume the first descriptor */ diff --git a/sys/dev/extres/clk/clk_bus.c b/sys/dev/extres/clk/clk_bus.c index e475736a901..e083ed0595d 100644 --- a/sys/dev/extres/clk/clk_bus.c +++ b/sys/dev/extres/clk/clk_bus.c @@ -60,11 +60,9 @@ ofw_clkbus_probe(device_t dev) static int ofw_clkbus_attach(device_t dev) { - struct ofw_clkbus_softc *sc; phandle_t node, child; device_t cdev; - sc = device_get_softc(dev); node = ofw_bus_get_node(dev); simplebus_init(dev, node); diff --git a/sys/dev/extres/regulator/regulator_bus.c b/sys/dev/extres/regulator/regulator_bus.c index 5e7f4c92d0e..bac88904a54 100644 --- a/sys/dev/extres/regulator/regulator_bus.c +++ b/sys/dev/extres/regulator/regulator_bus.c @@ -58,10 +58,8 @@ ofw_regulator_bus_probe(device_t dev) static int ofw_regulator_bus_attach(device_t dev) { - struct ofw_regulator_bus_softc *sc; phandle_t node, child; - sc = device_get_softc(dev); node = ofw_bus_get_node(dev); simplebus_init(dev, node); diff --git a/sys/dev/extres/syscon/syscon.c b/sys/dev/extres/syscon/syscon.c index 8bb3e14b700..8c2d7664952 100644 --- a/sys/dev/extres/syscon/syscon.c +++ b/sys/dev/extres/syscon/syscon.c @@ -33,153 +33,223 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_platform.h" + #include #include #include #include +#include +#include #include #include +#include +#include #include +#ifdef FDT #include #include +#endif #include "syscon_if.h" +#include "syscon.h" -#define SYSCON_LOCK(_sc) mtx_lock(&(_sc)->mtx) -#define SYSCON_UNLOCK(_sc) mtx_unlock(&(_sc)->mtx) -#define SYSCON_LOCK_INIT(_sc) mtx_init(&(_sc)->mtx, \ - device_get_nameunit((_sc)->dev), "syscon", MTX_DEF) -#define SYSCON_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->mtx); -#define SYSCON_ASSERT_LOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_OWNED); -#define SYSCON_ASSERT_UNLOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_NOTOWNED); +/* + * Syscon interface details + */ +typedef TAILQ_HEAD(syscon_list, syscon) syscon_list_t; -struct syscon_softc { - device_t dev; - struct resource *mem_res; - struct mtx mtx; +/* + * Declarations + */ +static int syscon_method_init(struct syscon *syscon); +static int syscon_method_uninit(struct syscon *syscon); + +MALLOC_DEFINE(M_SYSCON, "syscon", "Syscon driver"); + +static syscon_list_t syscon_list = TAILQ_HEAD_INITIALIZER(syscon_list); +static struct sx syscon_topo_lock; +SX_SYSINIT(syscon_topology, &syscon_topo_lock, "Syscon topology lock"); + +/* + * Syscon methods. + */ +static syscon_method_t syscon_methods[] = { + SYSCONMETHOD(syscon_init, syscon_method_init), + SYSCONMETHOD(syscon_uninit, syscon_method_uninit), + + SYSCONMETHOD_END +}; +DEFINE_CLASS_0(syscon, syscon_class, syscon_methods, 0); + +#define SYSCON_TOPO_SLOCK() sx_slock(&syscon_topo_lock) +#define SYSCON_TOPO_XLOCK() sx_xlock(&syscon_topo_lock) +#define SYSCON_TOPO_UNLOCK() sx_unlock(&syscon_topo_lock) +#define SYSCON_TOPO_ASSERT() sx_assert(&syscon_topo_lock, SA_LOCKED) +#define SYSCON_TOPO_XASSERT() sx_assert(&syscon_topo_lock, SA_XLOCKED) + +/* + * Default syscon methods for base class. + */ +static int +syscon_method_init(struct syscon *syscon) +{ + + return (0); }; -static struct ofw_compat_data compat_data[] = { - {"syscon", 1}, - {NULL, 0} +static int +syscon_method_uninit(struct syscon *syscon) +{ + + return (0); }; -static uint32_t -syscon_read_4(device_t dev, device_t consumer, bus_size_t offset) +void * +syscon_get_softc(struct syscon *syscon) { - struct syscon_softc *sc; - uint32_t val; - sc = device_get_softc(dev); + return (syscon->softc); +}; - SYSCON_LOCK(sc); - val = bus_read_4(sc->mem_res, offset); - SYSCON_UNLOCK(sc); - return (val); +/* + * Create and initialize syscon object, but do not register it. + */ +struct syscon * +syscon_create(device_t pdev, syscon_class_t syscon_class) +{ + struct syscon *syscon; + + /* Create object and initialize it. */ + syscon = malloc(sizeof(struct syscon), M_SYSCON, + M_WAITOK | M_ZERO); + kobj_init((kobj_t)syscon, (kobj_class_t)syscon_class); + + /* Allocate softc if required. */ + if (syscon_class->size > 0) + syscon->softc = malloc(syscon_class->size, M_SYSCON, + M_WAITOK | M_ZERO); + + /* Rest of init. */ + syscon->pdev = pdev; + return (syscon); } -static void -syscon_write_4(device_t dev, device_t consumer, bus_size_t offset, uint32_t val) +/* Register syscon object. */ +struct syscon * +syscon_register(struct syscon *syscon) { - struct syscon_softc *sc; + int rv; - sc = device_get_softc(dev); +#ifdef FDT + if (syscon->ofw_node <= 0) + syscon->ofw_node = ofw_bus_get_node(syscon->pdev); + if (syscon->ofw_node <= 0) + return (NULL); +#endif - SYSCON_LOCK(sc); - bus_write_4(sc->mem_res, offset, val); - SYSCON_UNLOCK(sc); -} - -static void -syscon_modify_4(device_t dev, device_t consumer, bus_size_t offset, - uint32_t clear_bits, uint32_t set_bits) -{ - struct syscon_softc *sc; - uint32_t val; - - sc = device_get_softc(dev); - - SYSCON_LOCK(sc); - val = bus_read_4(sc->mem_res, offset); - val &= ~clear_bits; - val |= set_bits; - bus_write_4(sc->mem_res, offset, val); - SYSCON_UNLOCK(sc); -} - -static int -syscon_probe(device_t dev) -{ - - if (!ofw_bus_status_okay(dev)) - return (ENXIO); - if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) - return (ENXIO); - - device_set_desc(dev, "syscon"); - return (BUS_PROBE_GENERIC); -} - -static int -syscon_attach(device_t dev) -{ - struct syscon_softc *sc; - int rid; - phandle_t node; - - sc = device_get_softc(dev); - sc->dev = dev; - node = ofw_bus_get_node(sc->dev); - - SYSCON_LOCK_INIT(sc); - - rid = 0; - sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, - RF_ACTIVE); - if (sc->mem_res == NULL) { - device_printf(dev, "Cannot allocate memory resource\n"); - return (ENXIO); + rv = SYSCON_INIT(syscon); + if (rv != 0) { + printf("SYSCON_INIT failed: %d\n", rv); + return (NULL); } - OF_device_register_xref(OF_xref_from_node(node), dev); - - return (0); +#ifdef FDT + OF_device_register_xref(OF_xref_from_node(syscon->ofw_node), + syscon->pdev); +#endif + SYSCON_TOPO_XLOCK(); + TAILQ_INSERT_TAIL(&syscon_list, syscon, syscon_link); + SYSCON_TOPO_UNLOCK(); + return (syscon); } -static int -syscon_detach(device_t dev) +int +syscon_unregister(struct syscon *syscon) { - struct syscon_softc *sc; - sc = device_get_softc(dev); - - OF_device_register_xref(OF_xref_from_device(dev), NULL); - - SYSCON_LOCK_DESTROY(sc); - if (sc->mem_res != NULL) - bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res); - return (0); + SYSCON_TOPO_XLOCK(); + TAILQ_REMOVE(&syscon_list, syscon, syscon_link); + SYSCON_TOPO_UNLOCK(); +#ifdef FDT + OF_device_register_xref(OF_xref_from_node(syscon->ofw_node), NULL); +#endif + return (SYSCON_UNINIT(syscon)); } -static device_method_t syscon_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, syscon_probe), - DEVMETHOD(device_attach, syscon_attach), - DEVMETHOD(device_detach, syscon_detach), +/** + * Provider methods + */ +#ifdef FDT +static struct syscon * +syscon_find_by_ofw_node(phandle_t node) +{ + struct syscon *entry; - /* Syscon interface */ - DEVMETHOD(syscon_read_4, syscon_read_4), - DEVMETHOD(syscon_write_4, syscon_write_4), - DEVMETHOD(syscon_modify_4, syscon_modify_4), + SYSCON_TOPO_ASSERT(); - DEVMETHOD_END -}; + TAILQ_FOREACH(entry, &syscon_list, syscon_link) { + if (entry->ofw_node == node) + return (entry); + } -DEFINE_CLASS_0(syscon, syscon_driver, syscon_methods, - sizeof(struct syscon_softc)); -static devclass_t syscon_devclass; -EARLY_DRIVER_MODULE(syscon, simplebus, syscon_driver, syscon_devclass, 0, 0, - BUS_PASS_BUS + BUS_PASS_ORDER_LATE); -MODULE_VERSION(syscon, 1); + return (NULL); +} + +struct syscon * +syscon_create_ofw_node(device_t pdev, syscon_class_t syscon_class, + phandle_t node) +{ + struct syscon *syscon; + + syscon = syscon_create(pdev, syscon_class); + if (syscon == NULL) + return (NULL); + syscon->ofw_node = node; + if (syscon_register(syscon) == NULL) + return (NULL); + return (syscon); +} + +phandle_t +syscon_get_ofw_node(struct syscon *syscon) +{ + + return (syscon->ofw_node); +} + +int +syscon_get_by_ofw_property(device_t cdev, phandle_t cnode, char *name, + struct syscon **syscon) +{ + pcell_t *cells; + int ncells; + + if (cnode <= 0) + cnode = ofw_bus_get_node(cdev); + if (cnode <= 0) { + device_printf(cdev, + "%s called on not ofw based device\n", __func__); + return (ENXIO); + } + ncells = OF_getencprop_alloc(cnode, name, sizeof(pcell_t), + (void **)&cells); + if (ncells < 1) + return (ENXIO); + + /* Translate to syscon node. */ + SYSCON_TOPO_SLOCK(); + *syscon = syscon_find_by_ofw_node(OF_node_from_xref(cells[0])); + if (*syscon == NULL) { + SYSCON_TOPO_UNLOCK(); + device_printf(cdev, "Failed to find syscon node\n"); + OF_prop_free(cells); + return (ENODEV); + } + SYSCON_TOPO_UNLOCK(); + OF_prop_free(cells); + return (0); +} +#endif diff --git a/sys/dev/fdt/fdt_common.c b/sys/dev/fdt/fdt_common.c index d163cac3e67..be7dd218e5f 100644 --- a/sys/dev/fdt/fdt_common.c +++ b/sys/dev/fdt/fdt_common.c @@ -155,7 +155,7 @@ fdt_get_range(phandle_t node, int range_id, u_long *base, u_long *size) pcell_t ranges[FDT_RANGES_SIZE], *rangesptr; pcell_t addr_cells, size_cells, par_addr_cells; u_long par_bus_addr, pbase, psize; - int err, len, tuple_size, tuples; + int err, len; if ((fdt_addrsize_cells(node, &addr_cells, &size_cells)) != 0) return (ENXIO); @@ -181,10 +181,6 @@ fdt_get_range(phandle_t node, int range_id, u_long *base, u_long *size) if (OF_getprop(node, "ranges", ranges, sizeof(ranges)) <= 0) return (EINVAL); - tuple_size = sizeof(pcell_t) * (addr_cells + par_addr_cells + - size_cells); - tuples = len / tuple_size; - if (par_addr_cells > 2 || addr_cells > 2 || size_cells > 2) return (ERANGE); @@ -600,11 +596,9 @@ fdt_get_reserved_regions(struct mem_region *mr, int *mrcnt) pcell_t reserve[FDT_REG_CELLS * FDT_MEM_REGIONS]; pcell_t *reservep; phandle_t memory, root; - uint32_t memory_size; int addr_cells, size_cells; - int i, max_size, res_len, rv, tuple_size, tuples; + int i, res_len, rv, tuple_size, tuples; - max_size = sizeof(reserve); root = OF_finddevice("/"); memory = OF_finddevice("/memory"); if (memory == -1) { @@ -634,7 +628,6 @@ fdt_get_reserved_regions(struct mem_region *mr, int *mrcnt) goto out; } - memory_size = 0; tuples = res_len / tuple_size; reservep = (pcell_t *)&reserve; for (i = 0; i < tuples; i++) { @@ -662,9 +655,8 @@ fdt_get_mem_regions(struct mem_region *mr, int *mrcnt, uint64_t *memsize) phandle_t memory; uint64_t memory_size; int addr_cells, size_cells; - int i, max_size, reg_len, rv, tuple_size, tuples; + int i, reg_len, rv, tuple_size, tuples; - max_size = sizeof(reg); memory = OF_finddevice("/memory"); if (memory == -1) { rv = ENXIO; diff --git a/sys/dev/iicbus/twsi/a10_twsi.c b/sys/dev/iicbus/twsi/a10_twsi.c index b468f088531..8822aea94e8 100644 --- a/sys/dev/iicbus/twsi/a10_twsi.c +++ b/sys/dev/iicbus/twsi/a10_twsi.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2016 Emmanuel Vadot + * Copyright (c) 2016 Emmanuel Vadot * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/isci/scil/scic_sds_remote_node_context.c b/sys/dev/isci/scil/scic_sds_remote_node_context.c index ba3ce38eea7..8d3698a9a09 100644 --- a/sys/dev/isci/scil/scic_sds_remote_node_context.c +++ b/sys/dev/isci/scil/scic_sds_remote_node_context.c @@ -899,7 +899,7 @@ SCI_STATUS scic_sds_remote_node_context_tx_suspended_state_resume_handler( * * @param[in] this_rnc The remote node context which is to receive the task * request. -* @param[in] the_request The task request to be transmitted to to the remote +* @param[in] the_request The task request to be transmitted to the remote * target device. * * @return SCI_STATUS diff --git a/sys/dev/isci/scil/scif_sas_controller.c b/sys/dev/isci/scil/scif_sas_controller.c index ca847d2b0af..b3987984afa 100644 --- a/sys/dev/isci/scil/scif_sas_controller.c +++ b/sys/dev/isci/scil/scif_sas_controller.c @@ -913,7 +913,7 @@ void scif_sas_controller_free_internal_request( fw_controller, fw_internal_request_buffer )); - //return the memory to to pool. + //return the memory to the pool. if( !sci_pool_full(fw_controller->internal_request_memory_pool) ) { sci_pool_put( diff --git a/sys/dev/iwm/if_iwmreg.h b/sys/dev/iwm/if_iwmreg.h index f79c5488674..22a669ffb86 100644 --- a/sys/dev/iwm/if_iwmreg.h +++ b/sys/dev/iwm/if_iwmreg.h @@ -3734,7 +3734,7 @@ struct iwm_uapsd_misbehaving_ap_notif { * beacon filtering; beacons will not be forced to be sent to driver * regardless of whether its temperature has been changed. * @bf_enable_beacon_filter: 1, beacon filtering is enabled; 0, disabled. - * @bf_filter_escape_timer: Send beacons to to driver if no beacons were passed + * @bf_filter_escape_timer: Send beacons to the driver if no beacons were passed * for a specific period of time. Units: Beacons. * @ba_escape_timer: Fully receive and parse beacon if no beacons were passed * for a longer period of time then this escape-timeout. Units: Beacons. diff --git a/sys/dev/mii/rdcphy.c b/sys/dev/mii/rdcphy.c index c03cf550eec..d7fa8ced4fd 100644 --- a/sys/dev/mii/rdcphy.c +++ b/sys/dev/mii/rdcphy.c @@ -185,11 +185,9 @@ static void rdcphy_status(struct mii_softc *sc) { struct mii_data *mii; - struct ifmedia_entry *ife; int bmsr, bmcr, physts; mii = sc->mii_pdata; - ife = mii->mii_media.ifm_cur; mii->mii_media_status = IFM_AVALID; mii->mii_media_active = IFM_ETHER; diff --git a/sys/dev/mmc/host/dwmmc.c b/sys/dev/mmc/host/dwmmc.c index cb374a0e240..80e71968618 100644 --- a/sys/dev/mmc/host/dwmmc.c +++ b/sys/dev/mmc/host/dwmmc.c @@ -751,12 +751,10 @@ static int dma_prepare(struct dwmmc_softc *sc, struct mmc_command *cmd) { struct mmc_data *data; - int len; int err; int reg; data = cmd->data; - len = data->len; reg = READ4(sc, SDMMC_INTMASK); reg &= ~(SDMMC_INTMASK_TXDR | SDMMC_INTMASK_RXDR); diff --git a/sys/dev/mmc/mmc.c b/sys/dev/mmc/mmc.c index b8ddb48f84e..4c46158b877 100644 --- a/sys/dev/mmc/mmc.c +++ b/sys/dev/mmc/mmc.c @@ -1559,17 +1559,14 @@ mmc_host_timing(device_t dev, enum mmc_bus_timing timing) static void mmc_log_card(device_t dev, struct mmc_ivars *ivar, int newcard) { - enum mmc_bus_timing max_timing, timing; + enum mmc_bus_timing timing; device_printf(dev, "Card at relative address 0x%04x%s:\n", ivar->rca, newcard ? " added" : ""); device_printf(dev, " card: %s\n", ivar->card_id_string); - max_timing = bus_timing_normal; for (timing = bus_timing_max; timing > bus_timing_normal; timing--) { - if (isset(&ivar->timings, timing)) { - max_timing = timing; + if (isset(&ivar->timings, timing)) break; - } } device_printf(dev, " quirks: %b\n", ivar->quirks, MMC_QUIRKS_FMT); device_printf(dev, " bus: %ubit, %uMHz (%s timing)\n", diff --git a/sys/dev/mmc/mmcsd.c b/sys/dev/mmc/mmcsd.c index 03ec0fc0dc9..530dd27a43b 100644 --- a/sys/dev/mmc/mmcsd.c +++ b/sys/dev/mmc/mmcsd.c @@ -755,11 +755,9 @@ mmcsd_close(struct disk *dp __unused) static void mmcsd_strategy(struct bio *bp) { - struct mmcsd_softc *sc; struct mmcsd_part *part; part = bp->bio_disk->d_drv1; - sc = part->sc; MMCSD_DISK_LOCK(part); if (part->running > 0 || part->suspend > 0) { bioq_disksort(&part->bio_queue, bp); diff --git a/sys/dev/mvs/mvs_pci.c b/sys/dev/mvs/mvs_pci.c index 5bae834bc6f..cd6afce40f5 100644 --- a/sys/dev/mvs/mvs_pci.c +++ b/sys/dev/mvs/mvs_pci.c @@ -338,7 +338,7 @@ mvs_intr(void *data) ic = ATA_INL(ctlr->r_mem, CHIP_MIC); if (ctlr->msi) { - /* We have to to mask MSI during processing. */ + /* We have to mask MSI during processing. */ mtx_lock(&ctlr->mtx); ATA_OUTL(ctlr->r_mem, CHIP_MIM, 0); ctlr->msia = 1; /* Deny MIM update during processing. */ diff --git a/sys/dev/mwl/if_mwl.c b/sys/dev/mwl/if_mwl.c index 87b08747277..f607195fa20 100644 --- a/sys/dev/mwl/if_mwl.c +++ b/sys/dev/mwl/if_mwl.c @@ -1239,7 +1239,7 @@ mwl_reset_vap(struct ieee80211vap *vap, int state) /* * Reset the hardware w/o losing operational state. - * Used to to reset or reload hardware state for a vap. + * Used to reset or reload hardware state for a vap. */ static int mwl_reset(struct ieee80211vap *vap, u_long cmd) diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c index c9e0a5f3451..957520bd977 100644 --- a/sys/dev/ofw/ofw_bus_subr.c +++ b/sys/dev/ofw/ofw_bus_subr.c @@ -386,9 +386,8 @@ ofw_bus_search_intrmap(void *intr, int intrsz, void *regs, int physsz, uint8_t *mptr; pcell_t paddrsz; pcell_t pintrsz; - int i, rsz, tsz; + int i, tsz; - rsz = -1; if (imapmsk != NULL) { for (i = 0; i < physsz; i++) ref[i] = uiregs[i] & uiimapmsk[i]; @@ -445,7 +444,7 @@ ofw_bus_msimap(phandle_t node, uint16_t pci_rid, phandle_t *msi_parent, { pcell_t *map, mask, msi_base, rid_base, rid_length; ssize_t len; - uint32_t masked_rid, rid; + uint32_t masked_rid; int err, i; /* TODO: This should be OF_searchprop_alloc if we had it */ @@ -462,7 +461,6 @@ ofw_bus_msimap(phandle_t node, uint16_t pci_rid, phandle_t *msi_parent, } err = ENOENT; - rid = 0; mask = 0xffffffff; OF_getencprop(node, "msi-map-mask", &mask, sizeof(mask)); diff --git a/sys/dev/ofw/ofwpci.c b/sys/dev/ofw/ofwpci.c index 7b52704b79c..7ebfe4ab86a 100644 --- a/sys/dev/ofw/ofwpci.c +++ b/sys/dev/ofw/ofwpci.c @@ -558,11 +558,8 @@ static int ofw_pci_deactivate_resource(device_t bus, device_t child, int type, int rid, struct resource *res) { - struct ofw_pci_softc *sc; vm_size_t psize; - sc = device_get_softc(bus); - if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY) { return (bus_generic_deactivate_resource(bus, child, type, rid, res)); diff --git a/sys/dev/pccard/pccardvar.h b/sys/dev/pccard/pccardvar.h index 573c5ec3f4a..5138c243f5b 100644 --- a/sys/dev/pccard/pccardvar.h +++ b/sys/dev/pccard/pccardvar.h @@ -89,15 +89,14 @@ struct pccard_product { /** * Note: There's no cis3 or cis4 reported for NOMATCH / pnpinfo events for - * pccard It's unclear if we actually need that for automatic loading or - * not. These stirngs are informative, according to the standard. Some Linux - * drivers match on them, for example. However, FreeBSD's hardware probing is a - * little different than Linux so it turns out we don't need them. Some cards - * use CIS3 or CIS4 for a textual representation of the MAC address. In short, - * they aren't needed even though our friends in Linux have them. It is my + * pccard. It's unclear if we actually need that for automatic loading or + * not. These strings are informative, according to the standard. Some Linux + * drivers match on them, for example. However, FreeBSD's hardware probing is a + * little different than Linux, so it turns out we don't need them. Some cards + * use CIS3 or CIS4 for a textual representation of the MAC address. In short, * belief that all the entries in Linux don't actually need to be separate there - * either, but it's hard to eliminate them and retest on old, possibly rare, - * hardware so they persist. Despite years of collecting ~300 different PC Cards + * either, but they persist since it's hard to eliminate them and retest on old, + * possibly rare, hardware. Despite years of collecting ~300 different PC Cards * off E-Bay, I've not been able to find any that need CIS3/CIS4 to select which * device attaches. */ @@ -111,7 +110,7 @@ typedef int (*pccard_product_match_fn) (device_t dev, #include "card_if.h" /* - * make this inline so that we don't have to worry about dangling references + * Make this inline so that we don't have to worry about dangling references * to it in the modules or the code. */ static inline const struct pccard_product * diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 42cb89547c7..fb2989aa4d1 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -3980,7 +3980,6 @@ pci_rescan_method(device_t dev) { #define REG(n, w) PCIB_READ_CONFIG(pcib, busno, s, f, n, w) device_t pcib = device_get_parent(dev); - struct pci_softc *sc; device_t child, *devlist, *unchanged; int devcount, error, i, j, maxslots, oldcount; int busno, domain, s, f, pcifunchigh; @@ -4000,7 +3999,6 @@ pci_rescan_method(device_t dev) } else unchanged = NULL; - sc = device_get_softc(dev); domain = pcib_get_domain(dev); busno = pcib_get_bus(dev); maxslots = PCIB_MAXSLOTS(pcib); @@ -4077,12 +4075,10 @@ device_t pci_add_iov_child(device_t bus, device_t pf, uint16_t rid, uint16_t vid, uint16_t did) { - struct pci_devinfo *pf_dinfo, *vf_dinfo; + struct pci_devinfo *vf_dinfo; device_t pcib; int busno, slot, func; - pf_dinfo = device_get_ivars(pf); - pcib = device_get_parent(bus); PCIB_DECODE_RID(pcib, rid, &busno, &slot, &func); diff --git a/sys/dev/pci/pci_pci.c b/sys/dev/pci/pci_pci.c index 939ff4f0abe..be5b56bc578 100644 --- a/sys/dev/pci/pci_pci.c +++ b/sys/dev/pci/pci_pci.c @@ -1241,10 +1241,8 @@ static void pcib_pcie_ab_timeout(void *arg) { struct pcib_softc *sc; - device_t dev; sc = arg; - dev = sc->dev; mtx_assert(&Giant, MA_OWNED); if (sc->flags & PCIB_DETACH_PENDING) { sc->flags |= PCIB_DETACHING; @@ -1484,16 +1482,14 @@ pcib_cfg_save(struct pcib_softc *sc) static void pcib_cfg_restore(struct pcib_softc *sc) { - device_t dev; #ifndef NEW_PCIB uint16_t command; #endif - dev = sc->dev; #ifdef NEW_PCIB pcib_write_windows(sc, WIN_IO | WIN_MEM | WIN_PMEM); #else - command = pci_read_config(dev, PCIR_COMMAND, 2); + command = pci_read_config(sc->dev, PCIR_COMMAND, 2); if (command & PCIM_CMD_PORTEN) pcib_set_io_decode(sc); if (command & PCIM_CMD_MEMEN) diff --git a/sys/dev/sdhci/sdhci.c b/sys/dev/sdhci/sdhci.c index e174359cfea..c55fe4eb959 100644 --- a/sys/dev/sdhci/sdhci.c +++ b/sys/dev/sdhci/sdhci.c @@ -301,7 +301,7 @@ sdhci_init(struct sdhci_slot *slot) slot->intmask |= SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT; } - WR4(slot, SDHCI_INT_ENABLE, slot->intmask | sdhci_tuning_intmask(slot)); + WR4(slot, SDHCI_INT_ENABLE, slot->intmask); WR4(slot, SDHCI_SIGNAL_ENABLE, slot->intmask); } @@ -654,6 +654,7 @@ sdhci_card_task(void *arg, int pending __unused) xpt_rescan(ccb); #else slot->intmask &= ~sdhci_tuning_intmask(slot); + WR4(slot, SDHCI_INT_ENABLE, slot->intmask); WR4(slot, SDHCI_SIGNAL_ENABLE, slot->intmask); slot->opt &= ~SDHCI_TUNING_ENABLED; SDHCI_UNLOCK(slot); @@ -1338,6 +1339,7 @@ sdhci_generic_tune(device_t brdev __unused, device_t reqdev, bool hs400) if (err == 0) { slot->opt |= SDHCI_TUNING_ENABLED; slot->intmask |= sdhci_tuning_intmask(slot); + WR4(slot, SDHCI_INT_ENABLE, slot->intmask); WR4(slot, SDHCI_SIGNAL_ENABLE, slot->intmask); if (slot->retune_ticks) { callout_reset(&slot->retune_callout, slot->retune_ticks, @@ -1406,6 +1408,7 @@ sdhci_exec_tuning(struct sdhci_slot *slot, bool reset) */ intmask = slot->intmask; slot->intmask = SDHCI_INT_DATA_AVAIL; + WR4(slot, SDHCI_INT_ENABLE, SDHCI_INT_DATA_AVAIL); WR4(slot, SDHCI_SIGNAL_ENABLE, SDHCI_INT_DATA_AVAIL); hostctrl2 = RD2(slot, SDHCI_HOST_CONTROL2); @@ -1438,6 +1441,7 @@ sdhci_exec_tuning(struct sdhci_slot *slot, bool reset) slot->opt = opt; slot->intmask = intmask; + WR4(slot, SDHCI_INT_ENABLE, intmask); WR4(slot, SDHCI_SIGNAL_ENABLE, intmask); if ((hostctrl2 & (SDHCI_CTRL2_EXEC_TUNING | diff --git a/sys/dev/sdhci/sdhci_pci.c b/sys/dev/sdhci/sdhci_pci.c index e6d0a37ddfe..0310b2e2888 100644 --- a/sys/dev/sdhci/sdhci_pci.c +++ b/sys/dev/sdhci/sdhci_pci.c @@ -122,6 +122,12 @@ static const struct sdhci_device { SDHCI_QUIRK_MMC_DDR52 | SDHCI_QUIRK_CAPS_BIT63_FOR_MMC_HS400 | SDHCI_QUIRK_PRESET_VALUE_BROKEN }, + { 0x19db8086, 0xffff, "Intel Denverton eMMC 5.0 Controller", + SDHCI_QUIRK_INTEL_POWER_UP_RESET | + SDHCI_QUIRK_WAIT_WHILE_BUSY | + SDHCI_QUIRK_MMC_DDR52 | + SDHCI_QUIRK_CAPS_BIT63_FOR_MMC_HS400 | + SDHCI_QUIRK_PRESET_VALUE_BROKEN }, { 0x22948086, 0xffff, "Intel Braswell eMMC 4.5.1 Controller", SDHCI_QUIRK_DATA_TIMEOUT_1MHZ | SDHCI_QUIRK_INTEL_POWER_UP_RESET | diff --git a/sys/dev/sfxge/common/siena_nvram.c b/sys/dev/sfxge/common/siena_nvram.c index e65ed7c6b1f..28262c9b5ca 100644 --- a/sys/dev/sfxge/common/siena_nvram.c +++ b/sys/dev/sfxge/common/siena_nvram.c @@ -527,7 +527,7 @@ siena_nvram_partn_get_version( : MC_CMD_NVRAM_TYPE_DYNAMIC_CFG_PORT1; /* * Ingore missing partitions on port 2, assuming they're due - * to to running on a single port part. + * to running on a single port part. */ if ((1 << dcfg_partn) & ~enp->en_u.siena.enu_partn_mask) { if (entry->port == 2) diff --git a/sys/dev/sio/sio.c b/sys/dev/sio/sio.c index 4fd5fbe6ffd..7406ad46391 100644 --- a/sys/dev/sio/sio.c +++ b/sys/dev/sio/sio.c @@ -592,7 +592,7 @@ sioprobe(dev, xrid, rclk, noprobe) * junk after a (very fast) soft reboot and (apparently) after * master reset. * XXX what about the UART bug avoided by waiting in comparam()? - * We don't want to to wait long enough to drain at 2 bps. + * We don't want to wait long enough to drain at 2 bps. */ if (iobase == siocniobase) DELAY((16 + 1) * 1000000 / (comdefaultrate / 10)); diff --git a/sys/dev/smc/if_smc_fdt.c b/sys/dev/smc/if_smc_fdt.c index d010f93723c..baca0bd6113 100644 --- a/sys/dev/smc/if_smc_fdt.c +++ b/sys/dev/smc/if_smc_fdt.c @@ -84,17 +84,8 @@ smc_fdt_probe(device_t dev) static int smc_fdt_attach(device_t dev) { - int err; - struct smc_softc *sc; - sc = device_get_softc(dev); - - err = smc_attach(dev); - if (err) { - return (err); - } - - return (0); + return smc_attach(dev); } static int diff --git a/sys/dev/sound/isa/mss.h b/sys/dev/sound/isa/mss.h index 5d7d6e02bd3..8917214ccbf 100644 --- a/sys/dev/sound/isa/mss.h +++ b/sys/dev/sound/isa/mss.h @@ -183,7 +183,7 @@ typedef struct mixer_def mixer_tab[32][2]; * The AD1848 codec has generic input lines called Line, Aux1 and Aux2. * Soundcard manufacturers have connected actual inputs (CD, synth, line, * etc) to these inputs in different order. Therefore it's difficult - * to assign mixer channels to to these inputs correctly. The following + * to assign mixer channels to these inputs correctly. The following * contains two alternative mappings. The first one is for GUS MAX and * the second is just a generic one (line1, line2 and line3). * (Actually this is not a mapping but rather some kind of interleaving diff --git a/sys/dev/spibus/ofw_spibus.c b/sys/dev/spibus/ofw_spibus.c index c968b77748f..bac64c0c78d 100644 --- a/sys/dev/spibus/ofw_spibus.c +++ b/sys/dev/spibus/ofw_spibus.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-4-Clause-FreeBSD + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2009, Nathan Whitehorn * Copyright (c) 2013 The FreeBSD Foundation diff --git a/sys/dev/syscons/scvgarndr.c b/sys/dev/syscons/scvgarndr.c index 76421208054..f7b66bbf76f 100644 --- a/sys/dev/syscons/scvgarndr.c +++ b/sys/dev/syscons/scvgarndr.c @@ -682,7 +682,7 @@ draw_txtmouse(scr_stat *scp, int x, int y) } else #endif /* SC_ALT_MOUSE_IMAGE */ { - /* Red, magenta and brown are mapped to green to to keep it readable */ + /* Red, magenta and brown are mapped to green to keep it readable */ static const int col_conv[16] = { 6, 6, 6, 6, 2, 2, 2, 6, 14, 14, 14, 14, 10, 10, 10, 14 }; diff --git a/sys/dev/txp/if_txp.c b/sys/dev/txp/if_txp.c index f4031bf47cc..cb8140e39e1 100644 --- a/sys/dev/txp/if_txp.c +++ b/sys/dev/txp/if_txp.c @@ -373,7 +373,7 @@ txp_attach(device_t dev) * diagnose sleep image specific issues. */ rsp = NULL; - if (txp_ext_command(sc, TXP_CMD_READ_VERSION, 0, 0, 0, NULL, 0, + if (txp_ext_command(sc, TXP_CMD_VERSIONS_READ, 0, 0, 0, NULL, 0, &rsp, TXP_CMD_WAIT)) { device_printf(dev, "can not read sleep image version\n"); error = ENXIO; diff --git a/sys/dev/txp/if_txpreg.h b/sys/dev/txp/if_txpreg.h index 9ad924ec6dd..a94a31769ad 100644 --- a/sys/dev/txp/if_txpreg.h +++ b/sys/dev/txp/if_txpreg.h @@ -1,8 +1,8 @@ -/* $OpenBSD: if_txpreg.h,v 1.30 2001/06/23 04:18:02 jason Exp $ */ +/* $OpenBSD: if_txpreg.h,v 1.35 2003/06/04 19:36:33 deraadt Exp $ */ /* $FreeBSD$ */ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2001 Aaron Campbell . * All rights reserved. @@ -15,11 +15,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Aaron Campbell. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -166,7 +161,7 @@ #define TXP_CMD_FILTER_TABLE_MODE_WRITE 0x3d #define TXP_CMD_FILTER_TCL_WRITE 0x3e #define TXP_CMD_FILTER_TBL_READ 0x3f -#define TXP_CMD_READ_VERSION 0x43 +#define TXP_CMD_VERSIONS_READ 0x43 #define TXP_CMD_FILTER_DEFINE 0x45 #define TXP_CMD_ADD_WAKEUP_PKT 0x46 #define TXP_CMD_ADD_SLEEP_PKT 0x47 @@ -384,6 +379,7 @@ struct txp_frag_desc { #define FRAG_FLAGS_TYPE_OPT 0x03 /* type: options */ #define FRAG_FLAGS_TYPE_RX 0x04 /* type: command */ #define FRAG_FLAGS_TYPE_RESP 0x05 /* type: response */ +#define FRAG_FLAGS_VALID 0x80 /* valid descriptor */ struct txp_opt_desc { uint8_t opt_desctype:3, diff --git a/sys/dev/uart/uart_bus_acpi.c b/sys/dev/uart/uart_bus_acpi.c index b1bb55a3410..88b1480064f 100644 --- a/sys/dev/uart/uart_bus_acpi.c +++ b/sys/dev/uart/uart_bus_acpi.c @@ -104,13 +104,11 @@ static int uart_acpi_probe(device_t dev) { struct uart_softc *sc; - device_t parent; - parent = device_get_parent(dev); sc = device_get_softc(dev); #if defined(__i386__) || defined(__amd64__) - if (!ISA_PNP_PROBE(parent, dev, acpi_ns8250_ids)) { + if (!ISA_PNP_PROBE(device_get_parent(dev), dev, acpi_ns8250_ids)) { sc->sc_class = &uart_ns8250_class; return (uart_bus_probe(dev, 0, 0, 0, 0, 0)); } diff --git a/sys/dev/uart/uart_dev_pl011.c b/sys/dev/uart/uart_dev_pl011.c index 7568327d875..3f232d5f6e8 100644 --- a/sys/dev/uart/uart_dev_pl011.c +++ b/sys/dev/uart/uart_dev_pl011.c @@ -381,10 +381,8 @@ uart_pl011_bus_getsig(struct uart_softc *sc) static int uart_pl011_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) { - struct uart_bas *bas; int error; - bas = &sc->sc_bas; error = 0; uart_lock(sc->sc_hwmtx); switch (request) { diff --git a/sys/dev/uart/uart_dev_snps.c b/sys/dev/uart/uart_dev_snps.c index e83e7518284..a29b805ea9c 100644 --- a/sys/dev/uart/uart_dev_snps.c +++ b/sys/dev/uart/uart_dev_snps.c @@ -110,9 +110,7 @@ UART_FDT_CLASS(compat_data); static int snps_get_clocks(device_t dev, clk_t *baudclk, clk_t *apb_pclk) { - struct snps_softc *sc; - sc = device_get_softc(dev); *baudclk = NULL; *apb_pclk = NULL; diff --git a/sys/dev/usb/controller/dwc_otg_fdt.c b/sys/dev/usb/controller/dwc_otg_fdt.c index b33184c9721..c333aa98add 100644 --- a/sys/dev/usb/controller/dwc_otg_fdt.c +++ b/sys/dev/usb/controller/dwc_otg_fdt.c @@ -170,7 +170,6 @@ int dwc_otg_detach(device_t dev) { struct dwc_otg_fdt_softc *sc = device_get_softc(dev); - int err; /* during module unload there are lots of children leftover */ device_delete_children(dev); @@ -181,7 +180,7 @@ dwc_otg_detach(device_t dev) */ dwc_otg_uninit(&sc->sc_otg); - err = bus_teardown_intr(dev, sc->sc_otg.sc_irq_res, + bus_teardown_intr(dev, sc->sc_otg.sc_irq_res, sc->sc_otg.sc_intr_hdl); sc->sc_otg.sc_intr_hdl = NULL; } diff --git a/sys/dev/usb/controller/ehci.c b/sys/dev/usb/controller/ehci.c index 4229d96ab20..aa1f9b31b4d 100644 --- a/sys/dev/usb/controller/ehci.c +++ b/sys/dev/usb/controller/ehci.c @@ -1194,9 +1194,7 @@ ehci_non_isoc_done_sub(struct usb_xfer *xfer) static void ehci_non_isoc_done(struct usb_xfer *xfer) { - ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus); ehci_qh_t *qh; - uint32_t status; usb_error_t err = 0; DPRINTFN(13, "xfer=%p endpoint=%p transfer done\n", @@ -1216,8 +1214,6 @@ ehci_non_isoc_done(struct usb_xfer *xfer) usb_pc_cpu_invalidate(qh->page_cache); - status = hc32toh(sc, qh->qh_qtd.qtd_status); - /* reset scanner */ xfer->td_transfer_cache = xfer->td_transfer_first; diff --git a/sys/dev/usb/controller/ohci.c b/sys/dev/usb/controller/ohci.c index ae9ae4488b8..dffa3676cb7 100644 --- a/sys/dev/usb/controller/ohci.c +++ b/sys/dev/usb/controller/ohci.c @@ -2385,7 +2385,6 @@ ohci_xfer_setup(struct usb_setup_params *parm) { struct usb_page_search page_info; struct usb_page_cache *pc; - ohci_softc_t *sc; struct usb_xfer *xfer; void *last_obj; uint32_t ntd; @@ -2393,7 +2392,6 @@ ohci_xfer_setup(struct usb_setup_params *parm) uint32_t nqh; uint32_t n; - sc = OHCI_BUS2SC(parm->udev->bus); xfer = parm->curr_xfer; parm->hc_max_packet_size = 0x500; diff --git a/sys/dev/usb/controller/xhci.c b/sys/dev/usb/controller/xhci.c index 12ecdefffd8..ac4916700e1 100644 --- a/sys/dev/usb/controller/xhci.c +++ b/sys/dev/usb/controller/xhci.c @@ -3714,13 +3714,11 @@ xhci_xfer_setup(struct usb_setup_params *parm) { struct usb_page_search page_info; struct usb_page_cache *pc; - struct xhci_softc *sc; struct usb_xfer *xfer; void *last_obj; uint32_t ntd; uint32_t n; - sc = XHCI_BUS2SC(parm->udev->bus); xfer = parm->curr_xfer; /* diff --git a/sys/dev/usb/storage/umass.c b/sys/dev/usb/storage/umass.c index 3dd3bfa4b3d..cfd2ba174b4 100644 --- a/sys/dev/usb/storage/umass.c +++ b/sys/dev/usb/storage/umass.c @@ -1089,7 +1089,6 @@ static void umass_init_shuttle(struct umass_softc *sc) { struct usb_device_request req; - usb_error_t err; uint8_t status[2] = {0, 0}; /* @@ -1102,7 +1101,7 @@ umass_init_shuttle(struct umass_softc *sc) req.wIndex[0] = sc->sc_iface_no; req.wIndex[1] = 0; USETW(req.wLength, sizeof(status)); - err = usbd_do_request(sc->sc_udev, NULL, &req, &status); + usbd_do_request(sc->sc_udev, NULL, &req, &status); DPRINTF(sc, UDMASS_GEN, "Shuttle init returned 0x%02x%02x\n", status[0], status[1]); diff --git a/sys/dev/usb/usb_dev.c b/sys/dev/usb/usb_dev.c index 206d0ec3c71..72c75dcd246 100644 --- a/sys/dev/usb/usb_dev.c +++ b/sys/dev/usb/usb_dev.c @@ -878,7 +878,7 @@ usb_open(struct cdev *dev, int fflags, int devtype, struct thread *td) struct usb_fs_privdata* pd = (struct usb_fs_privdata*)dev->si_drv1; struct usb_cdev_refdata refs; struct usb_cdev_privdata *cpd; - int err, ep; + int err; DPRINTFN(2, "%s fflags=0x%08x\n", devtoname(dev), fflags); @@ -890,7 +890,6 @@ usb_open(struct cdev *dev, int fflags, int devtype, struct thread *td) } cpd = malloc(sizeof(*cpd), M_USBDEV, M_WAITOK | M_ZERO); - ep = cpd->ep_addr = pd->ep_addr; usb_loc_fill(pd, cpd); err = usb_ref_device(cpd, &refs, 1); @@ -1412,8 +1411,6 @@ usb_read(struct cdev *dev, struct uio *uio, int ioflag) struct usb_cdev_privdata* cpd; struct usb_fifo *f; struct usb_mbuf *m; - int fflags; - int resid; int io_len; int err; uint8_t tr_data = 0; @@ -1426,8 +1423,6 @@ usb_read(struct cdev *dev, struct uio *uio, int ioflag) if (err) return (ENXIO); - fflags = cpd->fflags; - f = refs.rxfifo; if (f == NULL) { /* should not happen */ @@ -1435,8 +1430,6 @@ usb_read(struct cdev *dev, struct uio *uio, int ioflag) return (EPERM); } - resid = uio->uio_resid; - mtx_lock(f->priv_mtx); /* check for permanent read error */ @@ -1536,8 +1529,6 @@ usb_write(struct cdev *dev, struct uio *uio, int ioflag) struct usb_fifo *f; struct usb_mbuf *m; uint8_t *pdata; - int fflags; - int resid; int io_len; int err; uint8_t tr_data = 0; @@ -1552,15 +1543,12 @@ usb_write(struct cdev *dev, struct uio *uio, int ioflag) if (err) return (ENXIO); - fflags = cpd->fflags; - f = refs.txfifo; if (f == NULL) { /* should not happen */ usb_unref_device(cpd, &refs); return (EPERM); } - resid = uio->uio_resid; mtx_lock(f->priv_mtx); diff --git a/sys/dev/vnic/nic_main.c b/sys/dev/vnic/nic_main.c index 9391e6a702b..8e6aa60f6ca 100644 --- a/sys/dev/vnic/nic_main.c +++ b/sys/dev/vnic/nic_main.c @@ -761,9 +761,6 @@ static void nic_send_rss_size(struct nicpf *nic, int vf) { union nic_mbx mbx = {}; - uint64_t *msg; - - msg = (uint64_t *)&mbx; mbx.rss_size.msg = NIC_MBOX_MSG_RSS_SIZE; mbx.rss_size.ind_tbl_size = nic->rss_ind_tbl_size; diff --git a/sys/dev/vnic/nicvf_main.c b/sys/dev/vnic/nicvf_main.c index 5e6cf9e6884..19ea5bcdb7e 100644 --- a/sys/dev/vnic/nicvf_main.c +++ b/sys/dev/vnic/nicvf_main.c @@ -425,7 +425,6 @@ nicvf_if_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) struct nicvf *nic; struct rcv_queue *rq; struct ifreq *ifr; - uint32_t flags; int mask, err; int rq_idx; #if defined(INET) || defined(INET6) @@ -482,7 +481,6 @@ nicvf_if_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) NICVF_CORE_LOCK(nic); if (if_getflags(ifp) & IFF_UP) { if (if_getdrvflags(ifp) & IFF_DRV_RUNNING) { - flags = if_getflags(ifp) ^ nic->if_flags; if ((nic->if_flags & if_getflags(ifp)) & IFF_PROMISC) { /* Change promiscous mode */ diff --git a/sys/dev/vnic/nicvf_queues.c b/sys/dev/vnic/nicvf_queues.c index 7a1dda8f357..d469067c1cf 100644 --- a/sys/dev/vnic/nicvf_queues.c +++ b/sys/dev/vnic/nicvf_queues.c @@ -1714,13 +1714,12 @@ nicvf_sq_disable(struct nicvf *nic, int qidx) static void nicvf_sq_free_used_descs(struct nicvf *nic, struct snd_queue *sq, int qidx) { - uint64_t head, tail; + uint64_t head; struct snd_buff *snd_buff; struct sq_hdr_subdesc *hdr; NICVF_TX_LOCK(sq); head = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_HEAD, qidx) >> 4; - tail = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_TAIL, qidx) >> 4; while (sq->head != head) { hdr = (struct sq_hdr_subdesc *)GET_SQ_DESC(sq, sq->head); if (hdr->subdesc_type != SQ_DESC_TYPE_HEADER) { diff --git a/sys/fs/cd9660/cd9660_vfsops.c b/sys/fs/cd9660/cd9660_vfsops.c index 5d0e8348a3f..a5a2ec65659 100644 --- a/sys/fs/cd9660/cd9660_vfsops.c +++ b/sys/fs/cd9660/cd9660_vfsops.c @@ -680,7 +680,6 @@ cd9660_vget_internal(mp, ino, flags, vpp, relocated, isodir) struct iso_node *ip; struct buf *bp; struct vnode *vp; - struct cdev *dev; int error; struct thread *td; @@ -707,7 +706,6 @@ cd9660_vget_internal(mp, ino, flags, vpp, relocated, isodir) */ imp = VFSTOISOFS(mp); - dev = imp->im_dev; /* Allocate a new vnode/iso_node. */ if ((error = getnewvnode("isofs", mp, &cd9660_vnodeops, &vp)) != 0) { diff --git a/sys/fs/nfs/nfs_commonkrpc.c b/sys/fs/nfs/nfs_commonkrpc.c index a2915fbff02..f5aee810173 100644 --- a/sys/fs/nfs/nfs_commonkrpc.c +++ b/sys/fs/nfs/nfs_commonkrpc.c @@ -493,7 +493,7 @@ newnfs_request(struct nfsrv_descript *nd, struct nfsmount *nmp, uint32_t retseq, retval, slotseq, *tl; time_t waituntil; int i = 0, j = 0, opcnt, set_sigset = 0, slot; - int trycnt, error = 0, usegssname = 0, secflavour = AUTH_SYS; + int error = 0, usegssname = 0, secflavour = AUTH_SYS; int freeslot, maxslot, reterr, slotpos, timeo; u_int16_t procnum; u_int trylater_delay = 1; @@ -702,7 +702,6 @@ newnfs_request(struct nfsrv_descript *nd, struct nfsmount *nmp, } #endif } - trycnt = 0; freeslot = -1; /* Set to slot that needs to be free'd */ tryagain: slot = -1; /* Slot that needs a sequence# increment. */ @@ -1229,8 +1228,7 @@ newnfs_msleep(struct thread *td, void *ident, struct mtx *mtx, int priority, cha { sigset_t oldset; int error; - struct proc *p; - + if ((priority & PCATCH) == 0) return msleep(ident, mtx, priority, wmesg, timo); if (td == NULL) @@ -1238,7 +1236,6 @@ newnfs_msleep(struct thread *td, void *ident, struct mtx *mtx, int priority, cha newnfs_set_sigmask(td, &oldset); error = msleep(ident, mtx, priority, wmesg, timo); newnfs_restore_sigmask(td, &oldset); - p = td->td_proc; return (error); } diff --git a/sys/fs/nfs/nfs_commonsubs.c b/sys/fs/nfs/nfs_commonsubs.c index 1856b98d744..7d47a70ef89 100644 --- a/sys/fs/nfs/nfs_commonsubs.c +++ b/sys/fs/nfs/nfs_commonsubs.c @@ -487,7 +487,7 @@ nfsm_fhtom(struct nfsrv_descript *nd, u_int8_t *fhp, int size, int set_true) { u_int32_t *tl; u_int8_t *cp; - int fullsiz, rem, bytesize = 0; + int fullsiz, bytesize = 0; if (size == 0) size = NFSX_MYFH; @@ -504,7 +504,6 @@ nfsm_fhtom(struct nfsrv_descript *nd, u_int8_t *fhp, int size, int set_true) case ND_NFSV3: case ND_NFSV4: fullsiz = NFSM_RNDUP(size); - rem = fullsiz - size; if (set_true) { bytesize = 2 * NFSX_UNSIGNED + fullsiz; NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED); diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c index fc550171a43..db6c4a70788 100644 --- a/sys/fs/nfsclient/nfs_clrpcops.c +++ b/sys/fs/nfsclient/nfs_clrpcops.c @@ -5815,7 +5815,7 @@ nfsm_copym(struct mbuf *m, int off, int xfer) /* * Find a file layout that will handle the first bytes of the requested - * range and return the information from it needed to to the I/O operation. + * range and return the information from it needed to the I/O operation. */ int nfscl_findlayoutforio(struct nfscllayout *lyp, uint64_t off, uint32_t rwaccess, diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c index 8f4281accad..ff04cde0ac9 100644 --- a/sys/fs/nfsclient/nfs_clstate.c +++ b/sys/fs/nfsclient/nfs_clstate.c @@ -4116,7 +4116,6 @@ nfscl_relock(vnode_t vp, struct nfsclclient *clp, struct nfsmount *nmp, struct nfscllockowner *nlp; struct nfsfh *nfhp; u_int64_t off, len; - u_int32_t clidrev = 0; int error, newone, donelocally; off = lop->nfslo_first; @@ -4126,10 +4125,6 @@ nfscl_relock(vnode_t vp, struct nfsclclient *clp, struct nfsmount *nmp, lp->nfsl_openowner, &nlp, &newone, &donelocally); if (error || donelocally) return (error); - if (nmp->nm_clp != NULL) - clidrev = nmp->nm_clp->nfsc_clientidrev; - else - clidrev = 0; nfhp = VTONFS(vp)->n_fhp; error = nfscl_trylock(nmp, vp, nfhp->nfh_fh, nfhp->nfh_len, nlp, newone, 0, off, diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c index 81ab5665945..604ca1970c6 100644 --- a/sys/fs/nfsserver/nfs_nfsdport.c +++ b/sys/fs/nfsserver/nfs_nfsdport.c @@ -347,7 +347,7 @@ nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp, struct iovec aiov; struct uio auio; int lockleaf = (cnp->cn_flags & LOCKLEAF) != 0, linklen; - int error = 0, crossmnt; + int error = 0; char *cp; *retdirp = NULL; @@ -372,7 +372,6 @@ nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp, if (NFSVNO_EXRDONLY(exp)) cnp->cn_flags |= RDONLY; ndp->ni_segflg = UIO_SYSSPACE; - crossmnt = 1; if (nd->nd_flag & ND_PUBLOOKUP) { ndp->ni_loopcnt = 0; @@ -400,7 +399,6 @@ nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp, * the mount point, unless nfsrv_enable_crossmntpt is set. */ cnp->cn_flags |= NOCROSSMOUNT; - crossmnt = 0; } /* diff --git a/sys/fs/nfsserver/nfs_nfsdstate.c b/sys/fs/nfsserver/nfs_nfsdstate.c index 94c3cf4f05a..06d08518a19 100644 --- a/sys/fs/nfsserver/nfs_nfsdstate.c +++ b/sys/fs/nfsserver/nfs_nfsdstate.c @@ -3267,7 +3267,7 @@ APPLESTATIC int nfsrv_openupdate(vnode_t vp, struct nfsstate *new_stp, nfsquad_t clientid, nfsv4stateid_t *stateidp, struct nfsrv_descript *nd, NFSPROC_T *p) { - struct nfsstate *stp, *ownerstp; + struct nfsstate *stp; struct nfsclient *clp; struct nfslockfile *lfp; u_int32_t bits; @@ -3366,7 +3366,6 @@ nfsrv_openupdate(vnode_t vp, struct nfsstate *new_stp, nfsquad_t clientid, } NFSUNLOCKSTATE(); } else if (new_stp->ls_flags & NFSLCK_CLOSE) { - ownerstp = stp->ls_openowner; lfp = stp->ls_lfp; if (nfsrv_dolocallocks != 0 && !LIST_EMPTY(&stp->ls_open)) { /* Get the lf lock */ diff --git a/sys/fs/procfs/procfs_map.c b/sys/fs/procfs/procfs_map.c index f2fc2fa15d9..d6d6fe13d62 100644 --- a/sys/fs/procfs/procfs_map.c +++ b/sys/fs/procfs/procfs_map.c @@ -84,12 +84,17 @@ procfs_doprocmap(PFS_FILL_ARGS) vm_map_t map; vm_map_entry_t entry, tmp_entry; struct vnode *vp; - char *fullpath, *freepath; + char *fullpath, *freepath, *type; struct ucred *cred; - int error; + vm_object_t obj, tobj, lobj; + int error, privateresident, ref_count, resident, shadow_count, flags; + vm_offset_t e_start, e_end; + vm_eflags_t e_eflags; + vm_prot_t e_prot; unsigned int last_timestamp; + bool super; #ifdef COMPAT_FREEBSD32 - int wrap32 = 0; + bool wrap32; #endif PROC_LOCK(p); @@ -102,11 +107,12 @@ procfs_doprocmap(PFS_FILL_ARGS) return (EOPNOTSUPP); #ifdef COMPAT_FREEBSD32 - if (SV_CURPROC_FLAG(SV_ILP32)) { - if (!(SV_PROC_FLAG(p, SV_ILP32))) - return (EOPNOTSUPP); - wrap32 = 1; - } + wrap32 = false; + if (SV_CURPROC_FLAG(SV_ILP32)) { + if (!(SV_PROC_FLAG(p, SV_ILP32))) + return (EOPNOTSUPP); + wrap32 = true; + } #endif vm = vmspace_acquire_ref(p); @@ -116,14 +122,6 @@ procfs_doprocmap(PFS_FILL_ARGS) vm_map_lock_read(map); for (entry = map->header.next; entry != &map->header; entry = entry->next) { - vm_object_t obj, tobj, lobj; - int ref_count, shadow_count, flags; - vm_offset_t e_start, e_end, addr; - int resident, privateresident; - char *type; - vm_eflags_t e_eflags; - vm_prot_t e_prot; - if (entry->eflags & MAP_ENTRY_IS_SUB_MAP) continue; @@ -132,6 +130,7 @@ procfs_doprocmap(PFS_FILL_ARGS) e_start = entry->start; e_end = entry->end; privateresident = 0; + resident = 0; obj = entry->object.vm_object; if (obj != NULL) { VM_OBJECT_RLOCK(obj); @@ -140,21 +139,18 @@ procfs_doprocmap(PFS_FILL_ARGS) } cred = (entry->cred) ? entry->cred : (obj ? obj->cred : NULL); - resident = 0; - addr = entry->start; - while (addr < entry->end) { - if (pmap_extract(map->pmap, addr)) - resident++; - addr += PAGE_SIZE; - } - - for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) { + for (lobj = tobj = obj; tobj != NULL; + tobj = tobj->backing_object) { if (tobj != obj) VM_OBJECT_RLOCK(tobj); - if (lobj != obj) - VM_OBJECT_RUNLOCK(lobj); lobj = tobj; } + if (obj != NULL) + kern_proc_vmmap_resident(map, entry, &resident, &super); + for (tobj = obj; tobj != NULL; tobj = tobj->backing_object) { + if (tobj != obj && tobj != lobj) + VM_OBJECT_RUNLOCK(tobj); + } last_timestamp = map->timestamp; vm_map_unlock_read(map); diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c index 3bc2eb6f2d9..b74f9293ee8 100644 --- a/sys/geom/geom_subr.c +++ b/sys/geom/geom_subr.c @@ -876,7 +876,7 @@ int g_access(struct g_consumer *cp, int dcr, int dcw, int dce) { struct g_provider *pp; - int pr,pw,pe; + int pw, pe; int error; g_topology_assert(); @@ -907,7 +907,6 @@ g_access(struct g_consumer *cp, int dcr, int dcw, int dce) * Figure out what counts the provider would have had, if this * consumer had (r0w0e0) at this time. */ - pr = pp->acr - cp->acr; pw = pp->acw - cp->acw; pe = pp->ace - cp->ace; diff --git a/sys/geom/raid/g_raid.c b/sys/geom/raid/g_raid.c index f6d347e53ab..46748bba15c 100644 --- a/sys/geom/raid/g_raid.c +++ b/sys/geom/raid/g_raid.c @@ -955,7 +955,6 @@ g_raid_dirty(struct g_raid_volume *vol) void g_raid_tr_flush_common(struct g_raid_tr_object *tr, struct bio *bp) { - struct g_raid_softc *sc; struct g_raid_volume *vol; struct g_raid_subdisk *sd; struct bio_queue_head queue; @@ -963,7 +962,6 @@ g_raid_tr_flush_common(struct g_raid_tr_object *tr, struct bio *bp) int i; vol = tr->tro_volume; - sc = vol->v_softc; /* * Allocate all bios before sending any request, so we can return diff --git a/sys/geom/raid/md_ddf.c b/sys/geom/raid/md_ddf.c index 5b1c7f0b88d..05e24ed06e6 100644 --- a/sys/geom/raid/md_ddf.c +++ b/sys/geom/raid/md_ddf.c @@ -757,10 +757,8 @@ ddf_meta_create(struct g_raid_disk *disk, struct ddf_meta *sample) static void ddf_meta_copy(struct ddf_meta *dst, struct ddf_meta *src) { - struct ddf_header *hdr; u_int ss; - hdr = src->hdr; dst->bigendian = src->bigendian; ss = dst->sectorsize = src->sectorsize; dst->hdr = malloc(ss, M_MD_DDF, M_WAITOK); @@ -845,10 +843,8 @@ ddf_vol_meta_create(struct ddf_vol_meta *meta, struct ddf_meta *sample) { struct timespec ts; struct clocktime ct; - struct ddf_header *hdr; u_int ss, size; - hdr = sample->hdr; meta->bigendian = sample->bigendian; ss = meta->sectorsize = sample->sectorsize; meta->hdr = malloc(ss, M_MD_DDF, M_WAITOK); @@ -874,13 +870,11 @@ static void ddf_vol_meta_update(struct ddf_vol_meta *dst, struct ddf_meta *src, uint8_t *GUID, int started) { - struct ddf_header *hdr; struct ddf_vd_entry *vde; struct ddf_vdc_record *vdc; int vnew, bvnew, bvd, size; u_int ss; - hdr = src->hdr; vde = &src->vdr->entry[ddf_meta_find_vd(src, GUID)]; vdc = ddf_meta_find_vdc(src, GUID); if (GET8D(src, vdc->Secondary_Element_Count) == 1) @@ -1427,12 +1421,10 @@ static int g_raid_md_ddf_purge_volumes(struct g_raid_softc *sc) { struct g_raid_volume *vol, *tvol; - struct g_raid_md_ddf_pervolume *pv; int i, res; res = 0; TAILQ_FOREACH_SAFE(vol, &sc->sc_volumes, v_next, tvol) { - pv = vol->v_md_data; if (vol->v_stopping) continue; for (i = 0; i < vol->v_disks_count; i++) { @@ -1866,7 +1858,6 @@ g_raid_md_ddf_start(struct g_raid_volume *vol) struct g_raid_md_ddf_pervolume *pv; struct g_raid_md_ddf_object *mdi; struct ddf_vol_meta *vmeta; - struct ddf_vdc_record *vdc; uint64_t *val2; int i, j, bvd; @@ -1875,7 +1866,6 @@ g_raid_md_ddf_start(struct g_raid_volume *vol) mdi = (struct g_raid_md_ddf_object *)md; pv = vol->v_md_data; vmeta = &pv->pv_meta; - vdc = vmeta->vdc; vol->v_raid_level = GET8(vmeta, vdc->Primary_RAID_Level); vol->v_raid_level_qualifier = GET8(vmeta, vdc->RLQ); diff --git a/sys/geom/raid/md_promise.c b/sys/geom/raid/md_promise.c index ab5e6ccb631..edbcd074184 100644 --- a/sys/geom/raid/md_promise.c +++ b/sys/geom/raid/md_promise.c @@ -1100,7 +1100,7 @@ g_raid_md_taste_promise(struct g_raid_md_object *md, struct g_class *mp, struct g_provider *pp; struct g_raid_softc *sc; struct g_raid_disk *disk; - struct promise_raid_conf *meta, *metaarr[4]; + struct promise_raid_conf *metaarr[4]; struct g_raid_md_promise_perdisk *pd; struct g_geom *geom; int i, j, result, len, subdisks; @@ -1111,7 +1111,6 @@ g_raid_md_taste_promise(struct g_raid_md_object *md, struct g_class *mp, pp = cp->provider; /* Read metadata from device. */ - meta = NULL; g_topology_unlock(); vendor = 0xffff; len = sizeof(vendor); diff --git a/sys/geom/raid/tr_raid5.c b/sys/geom/raid/tr_raid5.c index 49c90da2a9e..3ff8f81cc3a 100644 --- a/sys/geom/raid/tr_raid5.c +++ b/sys/geom/raid/tr_raid5.c @@ -344,10 +344,8 @@ static void g_raid_tr_iostart_raid5(struct g_raid_tr_object *tr, struct bio *bp) { struct g_raid_volume *vol; - struct g_raid_tr_raid5_object *trs; vol = tr->tro_volume; - trs = (struct g_raid_tr_raid5_object *)tr; if (vol->v_state < G_RAID_VOLUME_S_SUBOPTIMAL) { g_raid_iodone(bp, EIO); return; diff --git a/sys/i386/conf/GENERIC b/sys/i386/conf/GENERIC index aab1d740d52..8f4991ab3b1 100644 --- a/sys/i386/conf/GENERIC +++ b/sys/i386/conf/GENERIC @@ -283,7 +283,6 @@ device ed # NE[12]000, SMC Ultra, 3c503, DS8390 cards device ex # Intel EtherExpress Pro/10 and Pro/10+ device ep # Etherlink III based cards device fe # Fujitsu MB8696x based cards -device ie # EtherExpress 8/16, 3C507, StarLAN 10 etc. device sn # SMC's 9000 series of Ethernet chips device xe # Xircom pccard Ethernet diff --git a/sys/i386/conf/NOTES b/sys/i386/conf/NOTES index 65c27d659f0..fca963d6ca6 100644 --- a/sys/i386/conf/NOTES +++ b/sys/i386/conf/NOTES @@ -528,8 +528,6 @@ hint.mse.0.irq="5" # ed: Western Digital and SMC 80xx; Novell NE1000 and NE2000; 3Com 3C503 # HP PC Lan+, various PC Card devices # (requires miibus) -# ie: AT&T StarLAN 10 and EN100; 3Com 3C507; unknown NI5210; -# Intel EtherExpress # ipw: Intel PRO/Wireless 2100 IEEE 802.11 adapter # iwi: Intel PRO/Wireless 2200BG/2225BG/2915ABG IEEE 802.11 adapters # Requires the iwi firmware module diff --git a/sys/i386/i386/support.s b/sys/i386/i386/support.s index 0c3949a6877..81a1786f5ff 100644 --- a/sys/i386/i386/support.s +++ b/sys/i386/i386/support.s @@ -556,7 +556,7 @@ END(subyte) /* * copyinstr(from, to, maxlen, int *lencopied) - MP SAFE * - * copy a string from from to to, stop when a 0 character is reached. + * copy a string from 'from' to 'to', stop when a 0 character is reached. * return ENAMETOOLONG if string is longer than maxlen, and * EFAULT on protection violations. If lencopied is non-zero, * return the actual length in *lencopied. diff --git a/sys/i386/isa/elink.c b/sys/i386/isa/elink.c index d226e8a71ac..852134d6c46 100644 --- a/sys/i386/isa/elink.c +++ b/sys/i386/isa/elink.c @@ -1,7 +1,9 @@ +/* $NetBSD: elink.c,v 1.6 1995/01/07 21:37:54 mycroft Exp $ */ + /*- * SPDX-License-Identifier: BSD-4-Clause * - * Copyright (c) 1994 Charles Hannum. All rights reserved. + * Copyright (c) 1994, 1995 Charles Hannum. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -46,9 +48,9 @@ __FBSDID("$FreeBSD$"); #include /* - * Issue a `global reset' to all cards. We have to be careful to do this only - * once during autoconfig, to prevent resetting boards that have already been - * configured. + * Issue a `global reset' to all cards, and reset the ID state machines. We + * have to be careful to do the global reset only once during autoconfig, to + * prevent resetting boards that have already been configured. */ void elink_reset() @@ -59,8 +61,8 @@ elink_reset() x = 1; outb(ELINK_ID_PORT, ELINK_RESET); } - outb(ELINK_ID_PORT, 0); - outb(ELINK_ID_PORT, 0); + outb(ELINK_ID_PORT, 0x00); + outb(ELINK_ID_PORT, 0x00); return; } diff --git a/sys/i386/isa/elink.h b/sys/i386/isa/elink.h index 9dc10473660..1a78bd41d34 100644 --- a/sys/i386/isa/elink.h +++ b/sys/i386/isa/elink.h @@ -1,3 +1,5 @@ +/* $NetBSD: elink.h,v 1.3 1994/10/27 04:17:11 cgd Exp $ */ + /*- * SPDX-License-Identifier: BSD-4-Clause * diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 0c0ccfda9f5..7334218be18 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -2280,9 +2280,9 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) CTASSERT(sizeof(struct kinfo_vmentry) == KINFO_VMENTRY_SIZE); #endif -static void +void kern_proc_vmmap_resident(vm_map_t map, vm_map_entry_t entry, - struct kinfo_vmentry *kve) + int *resident_count, bool *super) { vm_object_t obj, tobj; vm_page_t m, m_adv; @@ -2290,6 +2290,11 @@ kern_proc_vmmap_resident(vm_map_t map, vm_map_entry_t entry, vm_paddr_t locked_pa; vm_pindex_t pi, pi_adv, pindex; + *super = false; + *resident_count = 0; + if (vmmap_skip_res_cnt) + return; + locked_pa = 0; obj = entry->object.vm_object; addr = entry->start; @@ -2322,7 +2327,7 @@ kern_proc_vmmap_resident(vm_map_t map, vm_map_entry_t entry, (addr & (pagesizes[1] - 1)) == 0 && (pmap_mincore(map->pmap, addr, &locked_pa) & MINCORE_SUPER) != 0) { - kve->kve_flags |= KVME_FLAG_SUPER; + *super = true; pi_adv = atop(pagesizes[1]); } else { /* @@ -2334,7 +2339,7 @@ kern_proc_vmmap_resident(vm_map_t map, vm_map_entry_t entry, */ pi_adv = 1; } - kve->kve_resident += pi_adv; + *resident_count += pi_adv; next:; } PA_UNLOCK_COND(locked_pa); @@ -2358,6 +2363,7 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags) vm_offset_t addr; unsigned int last_timestamp; int error; + bool super; PROC_LOCK_ASSERT(p, MA_OWNED); @@ -2390,8 +2396,10 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags) if (obj->backing_object == NULL) kve->kve_private_resident = obj->resident_page_count; - if (!vmmap_skip_res_cnt) - kern_proc_vmmap_resident(map, entry, kve); + kern_proc_vmmap_resident(map, entry, + &kve->kve_resident, &super); + if (super) + kve->kve_flags |= KVME_FLAG_SUPER; for (tobj = obj; tobj != NULL; tobj = tobj->backing_object) { if (tobj != obj && tobj != lobj) @@ -3112,6 +3120,7 @@ resume_all_proc(void) cp = curproc; sx_xlock(&allproc_lock); +again: LIST_REMOVE(cp, p_list); LIST_INSERT_HEAD(&allproc, cp, p_list); for (;;) { @@ -3132,6 +3141,12 @@ resume_all_proc(void) PROC_UNLOCK(p); } } + /* Did the loop above missed any stopped process ? */ + LIST_FOREACH(p, &allproc, p_list) { + /* No need for proc lock. */ + if ((p->p_flag & P_TOTAL_STOP) != 0) + goto again; + } sx_xunlock(&allproc_lock); } diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 94ca9238094..8384ad99148 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -131,14 +131,12 @@ _sleep(void *ident, struct lock_object *lock, int priority, const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags) { struct thread *td; - struct proc *p; struct lock_class *class; uintptr_t lock_state; int catch, pri, rval, sleepq_flags; WITNESS_SAVE_DECL(lock_witness); td = curthread; - p = td->td_proc; #ifdef KTRACE if (KTRPOINT(td, KTR_CSW)) ktrcsw(1, 0, wmesg); @@ -177,7 +175,7 @@ _sleep(void *ident, struct lock_object *lock, int priority, sleepq_lock(ident); CTR5(KTR_PROC, "sleep: thread %ld (pid %ld, %s) on %s (%p)", - td->td_tid, p->p_pid, td->td_name, wmesg, ident); + td->td_tid, td->td_proc->p_pid, td->td_name, wmesg, ident); if (lock == &Giant.lock_object) mtx_assert(&Giant, MA_OWNED); @@ -235,12 +233,10 @@ msleep_spin_sbt(void *ident, struct mtx *mtx, const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags) { struct thread *td; - struct proc *p; int rval; WITNESS_SAVE_DECL(mtx); td = curthread; - p = td->td_proc; KASSERT(mtx != NULL, ("sleeping without a mutex")); KASSERT(ident != NULL, ("msleep_spin_sbt: NULL ident")); KASSERT(TD_IS_RUNNING(td), ("msleep_spin_sbt: curthread not running")); @@ -250,7 +246,7 @@ msleep_spin_sbt(void *ident, struct mtx *mtx, const char *wmesg, sleepq_lock(ident); CTR5(KTR_PROC, "msleep_spin: thread %ld (pid %ld, %s) on %s (%p)", - td->td_tid, p->p_pid, td->td_name, wmesg, ident); + td->td_tid, td->td_proc->p_pid, td->td_name, wmesg, ident); DROP_GIANT(); mtx_assert(mtx, MA_OWNED | MA_NOTRECURSED); diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c index f645ceb88d8..3977ab1e082 100644 --- a/sys/kern/link_elf.c +++ b/sys/kern/link_elf.c @@ -767,10 +767,8 @@ link_elf_load_file(linker_class_t cls, const char* filename, Elf_Phdr *segs[MAXSEGS]; int nsegs; Elf_Phdr *phdyn; - Elf_Phdr *phphdr; caddr_t mapbase; size_t mapsize; - Elf_Off base_offset; Elf_Addr base_vaddr; Elf_Addr base_vlimit; int error = 0; @@ -869,7 +867,6 @@ link_elf_load_file(linker_class_t cls, const char* filename, phlimit = phdr + hdr->e_phnum; nsegs = 0; phdyn = NULL; - phphdr = NULL; while (phdr < phlimit) { switch (phdr->p_type) { case PT_LOAD: @@ -885,10 +882,6 @@ link_elf_load_file(linker_class_t cls, const char* filename, ++nsegs; break; - case PT_PHDR: - phphdr = phdr; - break; - case PT_DYNAMIC: phdyn = phdr; break; @@ -916,7 +909,6 @@ link_elf_load_file(linker_class_t cls, const char* filename, * out our contiguous region, and to establish the base * address for relocation. */ - base_offset = trunc_page(segs[0]->p_offset); base_vaddr = trunc_page(segs[0]->p_vaddr); base_vlimit = round_page(segs[nsegs - 1]->p_vaddr + segs[nsegs - 1]->p_memsz); diff --git a/sys/kern/subr_msgbuf.c b/sys/kern/subr_msgbuf.c index 0231fe074d5..883cf2a78f6 100644 --- a/sys/kern/subr_msgbuf.c +++ b/sys/kern/subr_msgbuf.c @@ -187,11 +187,10 @@ msgbuf_addstr(struct msgbuf *mbp, int pri, char *str, int filter_cr) size_t len, prefix_len; char prefix[MAXPRIBUF]; char buf[32]; - int nl, i, j, needtime; + int i, j, needtime; len = strlen(str); prefix_len = 0; - nl = 0; /* If we have a zero-length string, no need to do anything. */ if (len == 0) diff --git a/sys/kern/subr_sleepqueue.c b/sys/kern/subr_sleepqueue.c index c2ad80fd254..48edcc359b8 100644 --- a/sys/kern/subr_sleepqueue.c +++ b/sys/kern/subr_sleepqueue.c @@ -1141,11 +1141,10 @@ sleepq_sbuf_print_stacks(struct sbuf *sb, void *wchan, int queue, struct stack **st; struct sbuf **td_infos; int i, stack_idx, error, stacks_to_allocate; - bool finished, partial_print; + bool finished; error = 0; finished = false; - partial_print = false; KASSERT(wchan != NULL, ("%s: invalid NULL wait channel", __func__)); MPASS((queue >= 0) && (queue < NR_SLEEPQS)); diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c index 4959cf3dc61..4f4716e58fa 100644 --- a/sys/kern/subr_witness.c +++ b/sys/kern/subr_witness.c @@ -1806,7 +1806,6 @@ static struct witness * enroll(const char *description, struct lock_class *lock_class) { struct witness *w; - struct witness_list *typelist; MPASS(description != NULL); @@ -1815,11 +1814,7 @@ enroll(const char *description, struct lock_class *lock_class) if ((lock_class->lc_flags & LC_SPINLOCK)) { if (witness_skipspin) return (NULL); - else - typelist = &w_spin; - } else if ((lock_class->lc_flags & LC_SLEEPLOCK)) { - typelist = &w_sleep; - } else { + } else if ((lock_class->lc_flags & LC_SLEEPLOCK) == 0) { kassert_panic("lock class %s is not sleep or spin", lock_class->lc_name); return (NULL); @@ -1865,14 +1860,11 @@ enroll(const char *description, struct lock_class *lock_class) static void depart(struct witness *w) { - struct witness_list *list; MPASS(w->w_refcount == 0); if (w->w_class->lc_flags & LC_SLEEPLOCK) { - list = &w_sleep; w_sleep_cnt--; } else { - list = &w_spin; w_spin_cnt--; } /* @@ -2546,7 +2538,6 @@ sbuf_print_witness_badstacks(struct sbuf *sb, size_t *oldidx) { struct witness_lock_order_data *data1, *data2, *tmp_data1, *tmp_data2; struct witness *tmp_w1, *tmp_w2, *w1, *w2; - u_int w_rmatrix1, w_rmatrix2; int generation, i, j; tmp_data1 = NULL; @@ -2616,8 +2607,6 @@ sbuf_print_witness_badstacks(struct sbuf *sb, size_t *oldidx) * spin lock. */ *tmp_w2 = *w2; - w_rmatrix1 = (unsigned int)w_rmatrix[i][j]; - w_rmatrix2 = (unsigned int)w_rmatrix[j][i]; if (data1) { stack_zero(&tmp_data1->wlod_stack); diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index e34c2a96683..817a0d71641 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -963,7 +963,6 @@ aio_schedule_fsync(void *context, int pending) bool aio_cancel_cleared(struct kaiocb *job) { - struct kaioinfo *ki; /* * The caller should hold the same queue lock held when @@ -971,7 +970,6 @@ aio_cancel_cleared(struct kaiocb *job) * ensuring this check sees an up-to-date value. However, * there is no way to assert that. */ - ki = job->userproc->p_aioinfo; return ((job->jobflags & KAIOCB_CLEARED) != 0); } @@ -1692,7 +1690,6 @@ aio_cancel_sync(struct kaiocb *job) int aio_queue_file(struct file *fp, struct kaiocb *job) { - struct aioliojob *lj; struct kaioinfo *ki; struct kaiocb *job2; struct vnode *vp; @@ -1700,7 +1697,6 @@ aio_queue_file(struct file *fp, struct kaiocb *job) int error, opcode; bool safe; - lj = job->lio; ki = job->userproc->p_aioinfo; opcode = job->uaiocb.aio_lio_opcode; if (opcode == LIO_SYNC) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index ed0a1942fe1..fae7e2d542e 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -349,7 +349,7 @@ PCTRIE_DEFINE(BUF, buf, b_lblkno, buf_trie_alloc, buf_trie_free); * * Reevaluate the following cap on the number of vnodes after the physical * memory size exceeds 512GB. In the limit, as the physical memory size - * grows, the ratio of the memory size in KB to to vnodes approaches 64:1. + * grows, the ratio of the memory size in KB to vnodes approaches 64:1. */ #ifndef MAXVNODES_MAX #define MAXVNODES_MAX (512 * 1024 * 1024 / 64) /* 8M */ @@ -1133,7 +1133,7 @@ static void vnlru_proc(void) { struct mount *mp, *nmp; - unsigned long ofreevnodes, onumvnodes; + unsigned long onumvnodes; int done, force, reclaim_nc_src, trigger, usevnodes; EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown, vnlruproc, @@ -1170,7 +1170,6 @@ vnlru_proc(void) } mtx_unlock(&vnode_free_list_mtx); done = 0; - ofreevnodes = freevnodes; onumvnodes = numvnodes; /* * Calculate parameters for recycling. These are the same diff --git a/sys/libkern/strstr.c b/sys/libkern/strstr.c index b7494f3235d..1454fbe0c70 100644 --- a/sys/libkern/strstr.c +++ b/sys/libkern/strstr.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. diff --git a/sys/mips/conf/BERI_SOCKIT b/sys/mips/conf/BERI_SOCKIT index c5405d38df9..c21d0dc7ac8 100644 --- a/sys/mips/conf/BERI_SOCKIT +++ b/sys/mips/conf/BERI_SOCKIT @@ -2,7 +2,7 @@ # BERI_SOCKIT -- Kernel for the SRI/Cambridge "BERI" (Bluespec Extensible # RISC Implementation) FPGA soft core, as configured in its Terasic SoCKit # reference configuration. This kernel configration must be further -# specialized to to include a root filesystem specification. +# specialized to include a root filesystem specification. # # $FreeBSD$ # diff --git a/sys/mips/conf/TP-WN1043ND b/sys/mips/conf/TP-WN1043ND index 7bf58f89c08..c3d2769ef84 100644 --- a/sys/mips/conf/TP-WN1043ND +++ b/sys/mips/conf/TP-WN1043ND @@ -18,6 +18,7 @@ hints "TP-WN1043ND.hints" options AR71XX_REALMEM=32*1024*1024 # i2c GPIO bus +device gpio device gpioiic device iicbb device iicbus @@ -27,6 +28,7 @@ device iic device etherswitch # RTL8366RB support +device mdio device rtl8366rb # read MSDOS formatted disks - USB diff --git a/sys/net/altq/altq_hfsc.h b/sys/net/altq/altq_hfsc.h index de5e89b8dd9..0a9fcf955f4 100644 --- a/sys/net/altq/altq_hfsc.h +++ b/sys/net/altq/altq_hfsc.h @@ -192,7 +192,7 @@ struct hfsc_class_stats { * representation. * the slope values are scaled to avoid overflow. * the inverse slope values as well as the y-projection of the 1st - * segment are kept in order to to avoid 64-bit divide operations + * segment are kept in order to avoid 64-bit divide operations * that are expensive on 32-bit architectures. * * note: Intel Pentium TSC never wraps around in several thousands of years. diff --git a/sys/net/bpf.c b/sys/net/bpf.c index e410e9a0f89..90718dd68d3 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -689,7 +689,7 @@ bpf_check_upgrade(u_long cmd, struct bpf_d *d, struct bpf_insn *fcode, int flen) * Check if cmd looks like snaplen setting from * pcap_bpf.c:pcap_open_live(). * Note we're not checking .k value here: - * while pcap_open_live() definitely sets to to non-zero value, + * while pcap_open_live() definitely sets to non-zero value, * we'd prefer to treat k=0 (deny ALL) case the same way: e.g. * do not consider upgrading immediately */ diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 455a507973e..8f280055da8 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -290,7 +290,6 @@ ether_output(struct ifnet *ifp, struct mbuf *m, int hlen; /* link layer header length */ uint32_t pflags; struct llentry *lle = NULL; - struct rtentry *rt0 = NULL; int addref = 0; phdr = NULL; @@ -320,7 +319,6 @@ ether_output(struct ifnet *ifp, struct mbuf *m, pflags = lle->r_flags; } } - rt0 = ro->ro_rt; } #ifdef MAC diff --git a/sys/net/if_gif.c b/sys/net/if_gif.c index 38c1182cd11..0d738c598be 100644 --- a/sys/net/if_gif.c +++ b/sys/net/if_gif.c @@ -520,7 +520,6 @@ gif_input(struct mbuf *m, struct ifnet *ifp, int proto, uint8_t ecn) struct ip6_hdr *ip6; uint32_t t; #endif - struct gif_softc *sc; struct ether_header *eh; struct ifnet *oldifp; int isr, n, af; @@ -530,7 +529,6 @@ gif_input(struct mbuf *m, struct ifnet *ifp, int proto, uint8_t ecn) m_freem(m); return; } - sc = ifp->if_softc; m->m_pkthdr.rcvif = ifp; m_clrprotoflags(m); switch (proto) { diff --git a/sys/net/iflib.c b/sys/net/iflib.c index 3decf974020..ba7d2547ed1 100644 --- a/sys/net/iflib.c +++ b/sys/net/iflib.c @@ -2635,7 +2635,7 @@ iflib_rxeof(iflib_rxq_t rxq, qidx_t budget) if ((m->m_pkthdr.csum_flags & (CSUM_L4_CALC|CSUM_L4_VALID)) == (CSUM_L4_CALC|CSUM_L4_VALID)) { if (lro_possible && tcp_lro_rx(&rxq->ifr_lc, m, 0) == 0) - continue; + continue; } } #endif @@ -5174,7 +5174,6 @@ iflib_irq_set_affinity(if_ctx_t ctx, int irq, iflib_intr_type_t type, int qid, if (cpuid > ctx->ifc_cpuid_highest) ctx->ifc_cpuid_highest = cpuid; #endif - MPASS(gtask->gt_taskqueue != NULL); return 0; } @@ -5348,10 +5347,10 @@ iflib_legacy_setup(if_ctx_t ctx, driver_filter_t filter, void *filter_arg, int * if ((err = _iflib_irq_alloc(ctx, irq, tqrid, iflib_fast_intr_ctx, NULL, info, name)) != 0) return (err); GROUPTASK_INIT(gtask, 0, fn, q); - taskqgroup_attach(tqg, gtask, q, tqrid, name); + taskqgroup_attach(tqg, gtask, q, rman_get_start(irq->ii_res), name); GROUPTASK_INIT(&txq->ift_task, 0, _task_fn_tx, txq); - taskqgroup_attach(qgroup_if_io_tqg, &txq->ift_task, txq, tqrid, "tx"); + taskqgroup_attach(qgroup_if_io_tqg, &txq->ift_task, txq, rman_get_start(irq->ii_res), "tx"); return (0); } diff --git a/sys/net80211/ieee80211_ht.c b/sys/net80211/ieee80211_ht.c index b01588b543c..7c742aa9e45 100644 --- a/sys/net80211/ieee80211_ht.c +++ b/sys/net80211/ieee80211_ht.c @@ -3354,7 +3354,7 @@ ieee80211_add_htinfo_body(uint8_t *frm, struct ieee80211_node *ni) } /* - * Add 802.11n HT information information element. + * Add 802.11n HT information element. */ uint8_t * ieee80211_add_htinfo(uint8_t *frm, struct ieee80211_node *ni) diff --git a/sys/net80211/ieee80211_scan_sta.c b/sys/net80211/ieee80211_scan_sta.c index a1b6b7b0bdc..c6a18bc8b38 100644 --- a/sys/net80211/ieee80211_scan_sta.c +++ b/sys/net80211/ieee80211_scan_sta.c @@ -119,7 +119,7 @@ static void sta_flush_table(struct sta_table *); /* * match_bss returns a bitmask describing if an entry is suitable * for use. If non-zero the entry was deemed not suitable and it's - * contents explains why. The following flags are or'd to to this + * contents explains why. The following flags are or'd to this * mask and can be used to figure out why the entry was rejected. */ #define MATCH_CHANNEL 0x00001 /* channel mismatch */ diff --git a/sys/netinet/icmp6.h b/sys/netinet/icmp6.h index b0ae67fe3f5..310684b8b47 100644 --- a/sys/netinet/icmp6.h +++ b/sys/netinet/icmp6.h @@ -628,7 +628,7 @@ struct icmp6stat { uint64_t icp6s_nd_badopt; /* bad ND options */ uint64_t icp6s_badns; /* bad neighbor solicitation */ uint64_t icp6s_badna; /* bad neighbor advertisement */ - uint64_t icp6s_badrs; /* bad router advertisement */ + uint64_t icp6s_badrs; /* bad router solicitation */ uint64_t icp6s_badra; /* bad router advertisement */ uint64_t icp6s_badredirect; /* bad redirect message */ }; diff --git a/sys/netinet/libalias/alias_sctp.c b/sys/netinet/libalias/alias_sctp.c index e85ffef91ad..08f9d302580 100644 --- a/sys/netinet/libalias/alias_sctp.c +++ b/sys/netinet/libalias/alias_sctp.c @@ -27,7 +27,7 @@ */ /* - * Alias_sctp forms part of the libalias kernel module to handle + * Alias_sctp forms part of the libalias kernel module to handle * Network Address Translation (NAT) for the SCTP protocol. * * This software was developed by David A. Hayes and Jason But @@ -39,13 +39,13 @@ * proposed by Jason But and Grenville Armitage: * http://caia.swin.edu.au/urp/sonata/ * - * + * * This project has been made possible in part by a grant from * the Cisco University Research Program Fund at Community * Foundation Silicon Valley. * */ -/** @mainpage +/** @mainpage * Alias_sctp is part of the SONATA (http://caia.swin.edu.au/urp/sonata) project * to develop and release a BSD licensed implementation of a Network Address * Translation (NAT) module that supports the Stream Control Transmission @@ -176,7 +176,7 @@ static void SctpAliasLog(const char *format, ...); * * Calls the higher level ShowAliasStats() in alias_db.c which logs all current * statistics about the libalias instance - including SCTP statistics - * + * * @param la Pointer to the libalias instance */ void SctpShowAliasStats(struct libalias *la); @@ -187,7 +187,7 @@ static MALLOC_DEFINE(M_SCTPNAT, "sctpnat", "sctp nat dbs"); /* Use kernel allocator. */ #ifdef _SYS_MALLOC_H_ #define sn_malloc(x) malloc(x, M_SCTPNAT, M_NOWAIT|M_ZERO) -#define sn_calloc(n,x) sn_malloc(x * n) +#define sn_calloc(n,x) sn_malloc((x) * (n)) #define sn_free(x) free(x, M_SCTPNAT) #endif// #ifdef _SYS_MALLOC_H_ @@ -261,7 +261,7 @@ static MALLOC_DEFINE(M_SCTPNAT, "sctpnat", "sctp nat dbs"); * Define various log levels and a macro to call specified log functions only if * the current log level (sysctl_log_level) matches the specified level @{ */ -#define SN_LOG_LOW 0 +#define SN_LOG_LOW 0 #define SN_LOG_EVENT 1 #define SN_LOG_INFO 2 #define SN_LOG_DETAIL 3 @@ -422,9 +422,9 @@ int sysctl_chg_loglevel(SYSCTL_HANDLER_ARGS) error = sysctl_handle_int(oidp, &level, 0, req); if (error) return (error); - sysctl_log_level = (level > SN_LOG_DEBUG_MAX)?(SN_LOG_DEBUG_MAX):(level); - sysctl_log_level = (level < SN_LOG_LOW)?(SN_LOG_LOW):(level); - + level = (level > SN_LOG_DEBUG_MAX) ? (SN_LOG_DEBUG_MAX) : (level); + level = (level < SN_LOG_LOW) ? (SN_LOG_LOW) : (level); + sysctl_log_level = level; return (0); } @@ -443,12 +443,11 @@ int sysctl_chg_timer(SYSCTL_HANDLER_ARGS) error = sysctl_handle_int(oidp, &timer, 0, req); if (error) return (error); - timer = (timer > SN_MAX_TIMER)?(SN_MAX_TIMER):(timer); + timer = (timer > SN_MAX_TIMER) ? (SN_MAX_TIMER) : (timer); - if (((u_int *)arg1) != &sysctl_holddown_timer) - { - timer = (timer < SN_MIN_TIMER)?(SN_MIN_TIMER):(timer); - } + if (((u_int *)arg1) != &sysctl_holddown_timer) { + timer = (timer < SN_MIN_TIMER) ? (SN_MIN_TIMER) : (timer); + } *(u_int *)arg1 = timer; @@ -472,11 +471,11 @@ int sysctl_chg_hashtable_size(SYSCTL_HANDLER_ARGS) error = sysctl_handle_int(oidp, &size, 0, req); if (error) return (error); - size = (size < SN_MIN_HASH_SIZE)?(SN_MIN_HASH_SIZE):((size > SN_MAX_HASH_SIZE)?(SN_MAX_HASH_SIZE):(size)); + size = (size < SN_MIN_HASH_SIZE) ? (SN_MIN_HASH_SIZE) : ((size > SN_MAX_HASH_SIZE) ? (SN_MAX_HASH_SIZE) : (size)); size |= 0x00000001; /* make odd */ - for(;(((size % 3) == 0) || ((size % 5) == 0) || ((size % 7) == 0) || ((size % 11) == 0)); size+=2); + for (;(((size % 3) == 0) || ((size % 5) == 0) || ((size % 7) == 0) || ((size % 11) == 0)); size+=2); sysctl_hashtable_size = size; return (0); @@ -485,7 +484,7 @@ int sysctl_chg_hashtable_size(SYSCTL_HANDLER_ARGS) /** @ingroup sysctl * @brief sysctl callback for changing net.inet.ip.alias.sctp.error_on_ootb * - * Updates the error_on_clash sysctl variable. + * Updates the error_on_clash sysctl variable. * If set to 0, no ErrorM will be sent if there is a look up table clash * If set to 1, an ErrorM is sent only to the local side * If set to 2, an ErrorM is sent to the local side and global side if there is @@ -540,16 +539,16 @@ int sysctl_chg_initialising_chunk_proc_limit(SYSCTL_HANDLER_ARGS) if (error) return (error); sysctl_initialising_chunk_proc_limit = (proclimit < 1) ? 1: proclimit; - sysctl_chunk_proc_limit = + sysctl_chunk_proc_limit = (sysctl_chunk_proc_limit < sysctl_initialising_chunk_proc_limit) ? sysctl_initialising_chunk_proc_limit : sysctl_chunk_proc_limit; - + return (0); } /** @ingroup sysctl * @brief sysctl callback for changing net.inet.ip.alias.sctp.chunk_proc_limit * - * Updates the chunk_proc_limit sysctl variable. + * Updates the chunk_proc_limit sysctl variable. * Number of chunks that should be processed to find key chunk: * >= initialising_chunk_proc_limit (A high value is a DoS risk) */ @@ -561,7 +560,7 @@ int sysctl_chg_chunk_proc_limit(SYSCTL_HANDLER_ARGS) error = sysctl_handle_int(oidp, &proclimit, 0, req); if (error) return (error); - sysctl_chunk_proc_limit = + sysctl_chunk_proc_limit = (proclimit < sysctl_initialising_chunk_proc_limit) ? sysctl_initialising_chunk_proc_limit : proclimit; return (0); @@ -571,7 +570,7 @@ int sysctl_chg_chunk_proc_limit(SYSCTL_HANDLER_ARGS) /** @ingroup sysctl * @brief sysctl callback for changing net.inet.ip.alias.sctp.param_proc_limit * - * Updates the param_proc_limit sysctl variable. + * Updates the param_proc_limit sysctl variable. * Number of parameters that should be processed to find key parameters: * > 1 (A high value is a DoS risk) */ @@ -583,7 +582,7 @@ int sysctl_chg_param_proc_limit(SYSCTL_HANDLER_ARGS) error = sysctl_handle_int(oidp, &proclimit, 0, req); if (error) return (error); - sysctl_param_proc_limit = + sysctl_param_proc_limit = (proclimit < 2) ? 2 : proclimit; return (0); @@ -614,9 +613,9 @@ int sysctl_chg_track_global_addresses(SYSCTL_HANDLER_ARGS) * CODE BEGINS HERE * ---------------------------------------------------------------------- */ -/** +/** * @brief Initialises the SCTP NAT Implementation - * + * * Creates the look-up tables and the timer queue and initialises all state * variables * @@ -650,7 +649,7 @@ void AliasSctpInit(struct libalias *la) la->sctpLinkCount = 0; } -/** +/** * @brief Cleans-up the SCTP NAT Implementation prior to unloading * * Removes all entries from the timer queue, freeing associations as it goes. @@ -705,7 +704,7 @@ void AliasSctpTerm(struct libalias *la) * @param la Pointer to the relevant libalias instance * @param pip Pointer to IP packet to process * @param direction SN_TO_LOCAL | SN_TO_GLOBAL - * + * * @return PKT_ALIAS_OK | PKT_ALIAS_IGNORE | PKT_ALIAS_ERROR */ int @@ -717,10 +716,10 @@ SctpAlias(struct libalias *la, struct ip *pip, int direction) if ((direction != SN_TO_LOCAL) && (direction != SN_TO_GLOBAL)) { SctpAliasLog("ERROR: Invalid direction\n"); - return(PKT_ALIAS_ERROR); + return (PKT_ALIAS_ERROR); } - sctp_CheckTimers(la); /* Check timers */ + sctp_CheckTimers(la); /* Check timers */ /* Parse the packet */ rtnval = sctp_PktParser(la, direction, pip, &msg, &assoc); //using *char (change to mbuf when get code from paolo) @@ -735,24 +734,24 @@ SctpAlias(struct libalias *la, struct ip *pip, int direction) } SN_LOG(SN_LOG_EVENT, logsctperror("SN_PARSE_ERROR", msg.sctp_hdr->v_tag, rtnval, direction)); - return(PKT_ALIAS_ERROR); + return (PKT_ALIAS_ERROR); case SN_PARSE_ERROR_PARTIALLOOKUP: if (sysctl_error_on_ootb > SN_LOCALandPARTIAL_ERROR_ON_OOTB) { SN_LOG(SN_LOG_EVENT, logsctperror("SN_PARSE_ERROR", msg.sctp_hdr->v_tag, rtnval, direction)); - return(PKT_ALIAS_ERROR); + return (PKT_ALIAS_ERROR); } case SN_PARSE_ERROR_LOOKUP: if (sysctl_error_on_ootb == SN_ERROR_ON_OOTB || (sysctl_error_on_ootb == SN_LOCALandPARTIAL_ERROR_ON_OOTB && direction == SN_TO_LOCAL) || (sysctl_error_on_ootb == SN_LOCAL_ERROR_ON_OOTB && direction == SN_TO_GLOBAL)) { TxAbortErrorM(la, &msg, assoc, SN_REFLECT_ERROR, direction); /*NB assoc=NULL */ - return(PKT_ALIAS_RESPOND); + return (PKT_ALIAS_RESPOND); } default: SN_LOG(SN_LOG_EVENT, logsctperror("SN_PARSE_ERROR", msg.sctp_hdr->v_tag, rtnval, direction)); - return(PKT_ALIAS_ERROR); + return (PKT_ALIAS_ERROR); } SN_LOG(SN_LOG_DETAIL, @@ -770,9 +769,9 @@ SctpAlias(struct libalias *la, struct ip *pip, int direction) ); SN_LOG(SN_LOG_DEBUG, logTimerQ(la)); - switch(rtnval){ + switch (rtnval) { case SN_NAT_PKT: - switch(direction) { + switch (direction) { case SN_TO_LOCAL: DifferentialChecksum(&(msg.ip_hdr->ip_sum), &(assoc->l_addr), &(msg.ip_hdr->ip_dst), 2); @@ -794,7 +793,7 @@ SctpAlias(struct libalias *la, struct ip *pip, int direction) break; case SN_REPLY_ABORT: case SN_REPLY_ERROR: - case SN_SEND_ABORT: + case SN_SEND_ABORT: TxAbortErrorM(la, &msg, assoc, rtnval, direction); break; default: @@ -814,22 +813,22 @@ SctpAlias(struct libalias *la, struct ip *pip, int direction) freeGlobalAddressList(assoc); sn_free(assoc); } - switch(rtnval) { + switch (rtnval) { case SN_NAT_PKT: - return(PKT_ALIAS_OK); + return (PKT_ALIAS_OK); case SN_SEND_ABORT: - return(PKT_ALIAS_OK); + return (PKT_ALIAS_OK); case SN_REPLY_ABORT: case SN_REPLY_ERROR: case SN_REFLECT_ERROR: - return(PKT_ALIAS_RESPOND); + return (PKT_ALIAS_RESPOND); case SN_DROP_PKT: default: - return(PKT_ALIAS_ERROR); + return (PKT_ALIAS_ERROR); } } -/** +/** * @brief Send an AbortM or ErrorM * * We construct the new SCTP packet to send in place of the existing packet we @@ -865,7 +864,7 @@ SctpAlias(struct libalias *la, struct ip *pip, int direction) static uint32_t local_sctp_finalize_crc32(uint32_t crc32c) { - /* This routine is duplicated from SCTP + /* This routine is duplicated from SCTP * we need to do that since it MAY be that SCTP * is NOT compiled into the kernel. The CRC32C routines * however are always available in libkern. @@ -924,7 +923,7 @@ TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm, struct sctp_nat_asso ip->ip_hl = 5; /* 5*32 bit words */ ip->ip_tos = 0; ip->ip_len = htons(ip_size); - ip->ip_id = sm->ip_hdr->ip_id; + ip->ip_id = sm->ip_hdr->ip_id; ip->ip_off = 0; ip->ip_ttl = 255; ip->ip_p = IPPROTO_SCTP; @@ -937,7 +936,7 @@ TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm, struct sctp_nat_asso chunk_hdr->chunk_type = (sndrply & SN_TX_ABORT) ? SCTP_ABORT_ASSOCIATION : SCTP_OPERATION_ERROR; chunk_hdr->chunk_flags = SCTP_MIDDLEBOX_FLAG; if (include_error_cause) { - error_cause->code = htons((sndrply & SN_REFLECT_ERROR) ? SCTP_MISSING_NAT : SCTP_NAT_TABLE_COLLISION); + error_cause->code = htons((sndrply & SN_REFLECT_ERROR) ? SCTP_MISSING_NAT : SCTP_NAT_TABLE_COLLISION); error_cause->length = htons(sizeof(struct sctp_error_cause)); chunk_hdr->chunk_length = htons(sizeof(*chunk_hdr) + sizeof(struct sctp_error_cause)); } else { @@ -945,22 +944,22 @@ TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm, struct sctp_nat_asso } /* set specific values */ - switch(sndrply) { + switch (sndrply) { case SN_REFLECT_ERROR: chunk_hdr->chunk_flags |= SCTP_HAD_NO_TCB; /* set Tbit */ - sctp_hdr->v_tag = sm->sctp_hdr->v_tag; + sctp_hdr->v_tag = sm->sctp_hdr->v_tag; break; case SN_REPLY_ERROR: - sctp_hdr->v_tag = (direction == SN_TO_LOCAL) ? assoc->g_vtag : assoc->l_vtag ; + sctp_hdr->v_tag = (direction == SN_TO_LOCAL) ? assoc->g_vtag : assoc->l_vtag ; break; case SN_SEND_ABORT: - sctp_hdr->v_tag = sm->sctp_hdr->v_tag; + sctp_hdr->v_tag = sm->sctp_hdr->v_tag; break; case SN_REPLY_ABORT: sctp_hdr->v_tag = sm->sctpchnk.Init->initiate_tag; break; } - + /* Set send/reply values */ if (sndrply == SN_SEND_ABORT) { /*pass through NAT */ ip->ip_src = (direction == SN_TO_LOCAL) ? sm->ip_hdr->ip_src : assoc->a_addr; @@ -973,10 +972,10 @@ TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm, struct sctp_nat_asso sctp_hdr->src_port = sm->sctp_hdr->dest_port; sctp_hdr->dest_port = sm->sctp_hdr->src_port; } - + /* Calculate IP header checksum */ ip->ip_sum = in_cksum_hdr(ip); - + /* calculate SCTP header CRC32 */ sctp_hdr->checksum = 0; sctp_hdr->checksum = local_sctp_finalize_crc32(calculate_crc32c(0xffffffff, (unsigned char *) sctp_hdr, sctp_size)); @@ -1003,18 +1002,18 @@ TxAbortErrorM(struct libalias *la, struct sctp_nat_msg *sm, struct sctp_nat_asso */ /** @ingroup packet_parser * @brief Parses SCTP packets for the key SCTP chunk that will be processed - * + * * This module parses SCTP packets for the key SCTP chunk that will be processed * The module completes the sctp_nat_msg structure and either retrieves the * relevant (existing) stored association from the Hash Tables or creates a new * association entity with state SN_ID * * @param la Pointer to the relevant libalias instance - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL - * @param pip + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * @param pip * @param sm Pointer to sctp message information * @param passoc Pointer to the association this SCTP Message belongs to - * + * * @return SN_PARSE_OK | SN_PARSE_ERROR_* */ static int @@ -1049,26 +1048,26 @@ sctp_PktParser(struct libalias *la, int direction, struct ip *pip, /* Check SCTP header length and move to first chunk */ if (bytes_left < sizeof(struct sctphdr)) { sm->sctp_hdr = NULL; - return(SN_PARSE_ERROR_IPSHL); /* packet not long enough*/ + return (SN_PARSE_ERROR_IPSHL); /* packet not long enough*/ } sm->sctp_hdr = sctp_hdr = (struct sctphdr *) ip_next(pip); bytes_left -= sizeof(struct sctphdr); - + /* Check for valid ports (zero valued ports would find partially initialised associations */ if (sctp_hdr->src_port == 0 || sctp_hdr->dest_port == 0) - return(SN_PARSE_ERROR_PORT); + return (SN_PARSE_ERROR_PORT); /* Check length of first chunk */ if (bytes_left < SN_MIN_CHUNK_SIZE) /* malformed chunk - could cause endless loop*/ - return(SN_PARSE_ERROR_CHHL); /* packet not long enough for this chunk */ - + return (SN_PARSE_ERROR_CHHL); /* packet not long enough for this chunk */ + /* First chunk */ chunk_hdr = SN_SCTP_FIRSTCHUNK(sctp_hdr); - + chunk_length = SCTP_SIZE32(ntohs(chunk_hdr->chunk_length)); if ((chunk_length < SN_MIN_CHUNK_SIZE) || (chunk_length > bytes_left)) /* malformed chunk - could cause endless loop*/ - return(SN_PARSE_ERROR_CHHL); + return (SN_PARSE_ERROR_CHHL); if ((chunk_hdr->chunk_flags & SCTP_HAD_NO_TCB) && ((chunk_hdr->chunk_type == SCTP_ABORT_ASSOCIATION) || @@ -1091,43 +1090,43 @@ sctp_PktParser(struct libalias *la, int direction, struct ip *pip, sm->msg = SN_SCTP_OTHER;/* Initialise to largest value*/ sm->chunk_length = 0; /* only care about length for key chunks */ while (IS_SCTP_CONTROL(chunk_hdr)) { - switch(chunk_hdr->chunk_type) { + switch (chunk_hdr->chunk_type) { case SCTP_INITIATION: if (chunk_length < sizeof(struct sctp_init_chunk)) /* malformed chunk*/ - return(SN_PARSE_ERROR_CHHL); + return (SN_PARSE_ERROR_CHHL); sm->msg = SN_SCTP_INIT; sm->sctpchnk.Init = (struct sctp_init *) ((char *) chunk_hdr + sizeof(struct sctp_chunkhdr)); sm->chunk_length = chunk_length; /* if no existing association, create a new one */ if (*passoc == NULL) { - if (sctp_hdr->v_tag == 0){ //Init requires vtag=0 + if (sctp_hdr->v_tag == 0) { //Init requires vtag=0 *passoc = (struct sctp_nat_assoc *) sn_malloc(sizeof(struct sctp_nat_assoc)); - if (*passoc == NULL) {/* out of resources */ - return(SN_PARSE_ERROR_AS_MALLOC); + if (*passoc == NULL) {/* out of resources */ + return (SN_PARSE_ERROR_AS_MALLOC); } /* Initialise association - malloc initialises memory to zeros */ (*passoc)->state = SN_ID; LIST_INIT(&((*passoc)->Gaddr)); /* always initialise to avoid memory problems */ (*passoc)->TableRegister = SN_NULL_TBL; - return(SN_PARSE_OK); + return (SN_PARSE_OK); } - return(SN_PARSE_ERROR_VTAG); + return (SN_PARSE_ERROR_VTAG); } - return(SN_PARSE_ERROR_LOOKUP); + return (SN_PARSE_ERROR_LOOKUP); case SCTP_INITIATION_ACK: if (chunk_length < sizeof(struct sctp_init_ack_chunk)) /* malformed chunk*/ - return(SN_PARSE_ERROR_CHHL); + return (SN_PARSE_ERROR_CHHL); sm->msg = SN_SCTP_INITACK; sm->sctpchnk.InitAck = (struct sctp_init_ack *) ((char *) chunk_hdr + sizeof(struct sctp_chunkhdr)); sm->chunk_length = chunk_length; - return ((*passoc == NULL)?(SN_PARSE_ERROR_LOOKUP):(SN_PARSE_OK)); + return ((*passoc == NULL) ? (SN_PARSE_ERROR_LOOKUP) : (SN_PARSE_OK)); case SCTP_ABORT_ASSOCIATION: /* access only minimum sized chunk */ sm->msg = SN_SCTP_ABORT; sm->chunk_length = chunk_length; - return ((*passoc == NULL)?(SN_PARSE_ERROR_LOOKUP_ABORT):(SN_PARSE_OK)); + return ((*passoc == NULL) ? (SN_PARSE_ERROR_LOOKUP_ABORT) : (SN_PARSE_OK)); case SCTP_SHUTDOWN_ACK: if (chunk_length < sizeof(struct sctp_shutdown_ack_chunk)) /* malformed chunk*/ - return(SN_PARSE_ERROR_CHHL); + return (SN_PARSE_ERROR_CHHL); if (sm->msg > SN_SCTP_SHUTACK) { sm->msg = SN_SCTP_SHUTACK; sm->chunk_length = chunk_length; @@ -1138,11 +1137,11 @@ sctp_PktParser(struct libalias *la, int direction, struct ip *pip, sm->msg = SN_SCTP_SHUTCOMP; sm->chunk_length = chunk_length; } - return ((*passoc == NULL)?(SN_PARSE_ERROR_LOOKUP):(SN_PARSE_OK)); + return ((*passoc == NULL) ? (SN_PARSE_ERROR_LOOKUP) : (SN_PARSE_OK)); case SCTP_ASCONF: if (sm->msg > SN_SCTP_ASCONF) { if (chunk_length < (sizeof(struct sctp_asconf_chunk) + sizeof(struct sctp_ipv4addr_param))) /* malformed chunk*/ - return(SN_PARSE_ERROR_CHHL); + return (SN_PARSE_ERROR_CHHL); //leave parameter searching to later, if required param_hdr = (struct sctp_paramhdr *) ((char *) chunk_hdr + sizeof(struct sctp_asconf_chunk)); /*compulsory IP parameter*/ if (ntohs(param_hdr->param_type) == SCTP_IPV4_ADDRESS) { @@ -1151,38 +1150,38 @@ sctp_PktParser(struct libalias *la, int direction, struct ip *pip, ipv4addr.s_addr = ((struct sctp_ipv4addr_param *) param_hdr)->addr; *passoc = FindSctpGlobal(la, ipv4addr, sctp_hdr->v_tag, sctp_hdr->src_port, sctp_hdr->dest_port, &partial_match); } - param_hdr = (struct sctp_paramhdr *) + param_hdr = (struct sctp_paramhdr *) ((char *) param_hdr + sizeof(struct sctp_ipv4addr_param)); /*asconf's compulsory address parameter */ sm->chunk_length = chunk_length - sizeof(struct sctp_asconf_chunk) - sizeof(struct sctp_ipv4addr_param); /* rest of chunk */ } else { if (chunk_length < (sizeof(struct sctp_asconf_chunk) + sizeof(struct sctp_ipv6addr_param))) /* malformed chunk*/ - return(SN_PARSE_ERROR_CHHL); - param_hdr = (struct sctp_paramhdr *) - ((char *) param_hdr + sizeof(struct sctp_ipv6addr_param)); /*asconf's compulsory address parameter */ + return (SN_PARSE_ERROR_CHHL); + param_hdr = (struct sctp_paramhdr *) + ((char *) param_hdr + sizeof(struct sctp_ipv6addr_param)); /*asconf's compulsory address parameter */ sm->chunk_length = chunk_length - sizeof(struct sctp_asconf_chunk) - sizeof(struct sctp_ipv6addr_param); /* rest of chunk */ } sm->msg = SN_SCTP_ASCONF; sm->sctpchnk.Asconf = param_hdr; - + if (*passoc == NULL) { /* AddIP with no association */ *passoc = (struct sctp_nat_assoc *) sn_malloc(sizeof(struct sctp_nat_assoc)); - if (*passoc == NULL) {/* out of resources */ - return(SN_PARSE_ERROR_AS_MALLOC); + if (*passoc == NULL) {/* out of resources */ + return (SN_PARSE_ERROR_AS_MALLOC); } /* Initialise association - malloc initialises memory to zeros */ (*passoc)->state = SN_ID; LIST_INIT(&((*passoc)->Gaddr)); /* always initialise to avoid memory problems */ (*passoc)->TableRegister = SN_NULL_TBL; - return(SN_PARSE_OK); + return (SN_PARSE_OK); } } break; case SCTP_ASCONF_ACK: if (sm->msg > SN_SCTP_ASCONFACK) { if (chunk_length < sizeof(struct sctp_asconf_ack_chunk)) /* malformed chunk*/ - return(SN_PARSE_ERROR_CHHL); + return (SN_PARSE_ERROR_CHHL); //leave parameter searching to later, if required - param_hdr = (struct sctp_paramhdr *) ((char *) chunk_hdr + param_hdr = (struct sctp_paramhdr *) ((char *) chunk_hdr + sizeof(struct sctp_asconf_ack_chunk)); sm->msg = SN_SCTP_ASCONFACK; sm->sctpchnk.Asconf = param_hdr; @@ -1195,33 +1194,33 @@ sctp_PktParser(struct libalias *la, int direction, struct ip *pip, /* if no association is found exit - we need to find an Init or AddIP within sysctl_initialising_chunk_proc_limit */ if ((*passoc == NULL) && (chunk_count >= sysctl_initialising_chunk_proc_limit)) - return(SN_PARSE_ERROR_LOOKUP); + return (SN_PARSE_ERROR_LOOKUP); /* finished with this chunk, on to the next chunk*/ bytes_left-= chunk_length; /* Is this the end of the packet ? */ if (bytes_left == 0) - return (*passoc == NULL)?(SN_PARSE_ERROR_LOOKUP):(SN_PARSE_OK); + return (*passoc == NULL) ? (SN_PARSE_ERROR_LOOKUP) : (SN_PARSE_OK); /* Are there enough bytes in packet to at least retrieve length of next chunk ? */ if (bytes_left < SN_MIN_CHUNK_SIZE) - return(SN_PARSE_ERROR_CHHL); + return (SN_PARSE_ERROR_CHHL); chunk_hdr = SN_SCTP_NEXTCHUNK(chunk_hdr); /* Is the chunk long enough to not cause endless look and are there enough bytes in packet to read the chunk ? */ chunk_length = SCTP_SIZE32(ntohs(chunk_hdr->chunk_length)); if ((chunk_length < SN_MIN_CHUNK_SIZE) || (chunk_length > bytes_left)) - return(SN_PARSE_ERROR_CHHL); - if(++chunk_count > sysctl_chunk_proc_limit) - return(SN_PARSE_OK); /* limit for processing chunks, take what we get */ + return (SN_PARSE_ERROR_CHHL); + if (++chunk_count > sysctl_chunk_proc_limit) + return (SN_PARSE_OK); /* limit for processing chunks, take what we get */ } if (*passoc == NULL) - return (partial_match)?(SN_PARSE_ERROR_PARTIALLOOKUP):(SN_PARSE_ERROR_LOOKUP); + return (partial_match) ? (SN_PARSE_ERROR_PARTIALLOOKUP) : (SN_PARSE_ERROR_LOOKUP); else - return(SN_PARSE_OK); + return (SN_PARSE_OK); } /** @ingroup packet_parser @@ -1229,7 +1228,7 @@ sctp_PktParser(struct libalias *la, int direction, struct ip *pip, * * GetAsconfVtags scans an Asconf Chunk for the vtags parameter, and then * extracts the vtags. - * + * * GetAsconfVtags is not called from within sctp_PktParser. It is called only * from within ID_process when an AddIP has been received. * @@ -1237,9 +1236,9 @@ sctp_PktParser(struct libalias *la, int direction, struct ip *pip, * @param sm Pointer to sctp message information * @param l_vtag Pointer to the local vtag in the association this SCTP Message belongs to * @param g_vtag Pointer to the local vtag in the association this SCTP Message belongs to - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL - * - * @return 1 - success | 0 - fail + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * + * @return 1 - success | 0 - fail */ static int GetAsconfVtags(struct libalias *la, struct sctp_nat_msg *sm, uint32_t *l_vtag, uint32_t *g_vtag, int direction) @@ -1251,7 +1250,7 @@ GetAsconfVtags(struct libalias *la, struct sctp_nat_msg *sm, uint32_t *l_vtag, u uint32_t local_vtag; uint32_t remote_vtag; } __attribute__((packed)); - + struct sctp_vtag_param *vtag_param; struct sctp_paramhdr *param; int bytes_left; @@ -1266,7 +1265,7 @@ GetAsconfVtags(struct libalias *la, struct sctp_nat_msg *sm, uint32_t *l_vtag, u while((bytes_left >= param_size) && (bytes_left >= SN_VTAG_PARAM_SIZE)) { if (ntohs(param->param_type) == SCTP_VTAG_PARAM) { vtag_param = (struct sctp_vtag_param *) param; - switch(direction) { + switch (direction) { /* The Internet draft is a little ambigious as to order of these vtags. We think it is this way around. If we are wrong, the order will need to be changed. */ @@ -1279,11 +1278,11 @@ GetAsconfVtags(struct libalias *la, struct sctp_nat_msg *sm, uint32_t *l_vtag, u *l_vtag = vtag_param->local_vtag; break; } - return(1); /* found */ + return (1); /* found */ } bytes_left -= param_size; - if (bytes_left < SN_MIN_PARAM_SIZE) return(0); + if (bytes_left < SN_MIN_PARAM_SIZE) return (0); param = SN_SCTP_NEXTPARAM(param); param_size = SCTP_SIZE32(ntohs(param->param_length)); @@ -1291,22 +1290,22 @@ GetAsconfVtags(struct libalias *la, struct sctp_nat_msg *sm, uint32_t *l_vtag, u SN_LOG(SN_LOG_EVENT, logsctperror("Parameter parse limit exceeded (GetAsconfVtags)", sm->sctp_hdr->v_tag, sysctl_param_proc_limit, direction)); - return(0); /* not found limit exceeded*/ + return (0); /* not found limit exceeded*/ } } - return(0); /* not found */ + return (0); /* not found */ } /** @ingroup packet_parser * @brief AddGlobalIPAddresses from Init,InitAck,or AddIP packets - * + * * AddGlobalIPAddresses scans an SCTP chunk (in sm) for Global IP addresses, and * adds them. * * @param sm Pointer to sctp message information * @param assoc Pointer to the association this SCTP Message belongs to - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL - * + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * */ static void AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int direction) @@ -1319,7 +1318,7 @@ AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int int param_size; int param_count, addr_param_count = 0; - switch(direction) { + switch (direction) { case SN_TO_GLOBAL: /* does not contain global addresses */ g_addr = sm->ip_hdr->ip_dst; bytes_left = 0; /* force exit */ @@ -1327,7 +1326,7 @@ AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int case SN_TO_LOCAL: g_addr = sm->ip_hdr->ip_src; param_count = 1; - switch(sm->msg) { + switch (sm->msg) { case SN_SCTP_INIT: bytes_left = sm->chunk_length - sizeof(struct sctp_init_chunk); param = (struct sctp_paramhdr *)((char *)sm->sctpchnk.Init + sizeof(struct sctp_init)); @@ -1342,16 +1341,16 @@ AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int break; } } - if (bytes_left >= SN_MIN_PARAM_SIZE) + if (bytes_left >= SN_MIN_PARAM_SIZE) param_size = SCTP_SIZE32(ntohs(param->param_length)); else param_size = bytes_left+1; /* force skip loop */ - - if ((assoc->state == SN_ID) && ((sm->msg == SN_SCTP_INIT) || (bytes_left < SN_MIN_PARAM_SIZE))) {/* add pkt address */ + + if ((assoc->state == SN_ID) && ((sm->msg == SN_SCTP_INIT) || (bytes_left < SN_MIN_PARAM_SIZE))) {/* add pkt address */ G_Addr = (struct sctp_GlobalAddress *) sn_malloc(sizeof(struct sctp_GlobalAddress)); - if (G_Addr == NULL) {/* out of resources */ + if (G_Addr == NULL) {/* out of resources */ SN_LOG(SN_LOG_EVENT, - logsctperror("AddGlobalIPAddress: No resources for adding global address - revert to no tracking", + logsctperror("AddGlobalIPAddress: No resources for adding global address - revert to no tracking", sm->sctp_hdr->v_tag, 0, direction)); assoc->num_Gaddr = 0; /* don't track any more for this assoc*/ sysctl_track_global_addresses=0; @@ -1360,7 +1359,7 @@ AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int G_Addr->g_addr = g_addr; if (!Add_Global_Address_to_List(assoc, G_Addr)) SN_LOG(SN_LOG_EVENT, - logsctperror("AddGlobalIPAddress: Address already in list", + logsctperror("AddGlobalIPAddress: Address already in list", sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction)); } @@ -1368,21 +1367,22 @@ AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int while((bytes_left >= param_size) && (bytes_left >= sizeof(struct sctp_ipv4addr_param))) { if (assoc->num_Gaddr >= sysctl_track_global_addresses) { SN_LOG(SN_LOG_EVENT, - logsctperror("AddGlobalIPAddress: Maximum Number of addresses reached", + logsctperror("AddGlobalIPAddress: Maximum Number of addresses reached", sm->sctp_hdr->v_tag, sysctl_track_global_addresses, direction)); return; } - switch(ntohs(param->param_type)) { + switch (ntohs(param->param_type)) { case SCTP_ADD_IP_ADDRESS: /* skip to address parameter - leave param_size so bytes left will be calculated properly*/ param = (struct sctp_paramhdr *) &((struct sctp_asconf_addrv4_param *) param)->addrp; + /* FALLTHROUGH */ case SCTP_IPV4_ADDRESS: ipv4_param = (struct sctp_ipv4addr_param *) param; /* add addresses to association */ G_Addr = (struct sctp_GlobalAddress *) sn_malloc(sizeof(struct sctp_GlobalAddress)); - if (G_Addr == NULL) {/* out of resources */ + if (G_Addr == NULL) {/* out of resources */ SN_LOG(SN_LOG_EVENT, - logsctperror("AddGlobalIPAddress: No resources for adding global address - revert to no tracking", + logsctperror("AddGlobalIPAddress: No resources for adding global address - revert to no tracking", sm->sctp_hdr->v_tag, 0, direction)); assoc->num_Gaddr = 0; /* don't track any more for this assoc*/ sysctl_track_global_addresses=0; @@ -1394,22 +1394,22 @@ AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int G_Addr->g_addr = g_addr; if (!Add_Global_Address_to_List(assoc, G_Addr)) SN_LOG(SN_LOG_EVENT, - logsctperror("AddGlobalIPAddress: Address already in list", + logsctperror("AddGlobalIPAddress: Address already in list", sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction)); return; /*shouldn't be any other addresses if the zero address is given*/ } else { G_Addr->g_addr.s_addr = ipv4_param->addr; if (!Add_Global_Address_to_List(assoc, G_Addr)) SN_LOG(SN_LOG_EVENT, - logsctperror("AddGlobalIPAddress: Address already in list", + logsctperror("AddGlobalIPAddress: Address already in list", sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction)); } - } - + } + bytes_left -= param_size; if (bytes_left < SN_MIN_PARAM_SIZE) break; - + param = SN_SCTP_NEXTPARAM(param); param_size = SCTP_SIZE32(ntohs(param->param_length)); if (++param_count > sysctl_param_proc_limit) { @@ -1421,39 +1421,39 @@ AddGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int } if (addr_param_count == 0) { SN_LOG(SN_LOG_DETAIL, - logsctperror("AddGlobalIPAddress: no address parameters to add", + logsctperror("AddGlobalIPAddress: no address parameters to add", sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction)); } } -/** +/** * @brief Add_Global_Address_to_List * * Adds a global IP address to an associations address list, if it is not * already there. The first address added us usually the packet's address, and * is most likely to be used, so it is added at the beginning. Subsequent * addresses are added after this one. - * + * * @param assoc Pointer to the association this SCTP Message belongs to * @param G_addr Pointer to the global address to add * - * @return 1 - success | 0 - fail + * @return 1 - success | 0 - fail */ static int Add_Global_Address_to_List(struct sctp_nat_assoc *assoc, struct sctp_GlobalAddress *G_addr) { - struct sctp_GlobalAddress *iter_G_Addr = NULL, *first_G_Addr = NULL; - first_G_Addr = LIST_FIRST(&(assoc->Gaddr)); + struct sctp_GlobalAddress *iter_G_Addr = NULL, *first_G_Addr = NULL; + first_G_Addr = LIST_FIRST(&(assoc->Gaddr)); if (first_G_Addr == NULL) { LIST_INSERT_HEAD(&(assoc->Gaddr), G_addr, list_Gaddr); /* add new address to beginning of list*/ } else { LIST_FOREACH(iter_G_Addr, &(assoc->Gaddr), list_Gaddr) { if (G_addr->g_addr.s_addr == iter_G_Addr->g_addr.s_addr) - return(0); /* already exists, so don't add */ + return (0); /* already exists, so don't add */ } LIST_INSERT_AFTER(first_G_Addr, G_addr, list_Gaddr); /* add address to end of list*/ } - assoc->num_Gaddr++; - return(1); /* success */ + assoc->num_Gaddr++; + return (1); /* success */ } /** @ingroup packet_parser @@ -1466,8 +1466,8 @@ static int Add_Global_Address_to_List(struct sctp_nat_assoc *assoc, struct sct * * @param sm Pointer to sctp message information * @param assoc Pointer to the association this SCTP Message belongs to - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL - * + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * */ static void RmGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int direction) @@ -1480,7 +1480,7 @@ RmGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int d int param_size; int param_count; - if(direction == SN_TO_GLOBAL) + if (direction == SN_TO_GLOBAL) g_addr = sm->ip_hdr->ip_dst; else g_addr = sm->ip_hdr->ip_src; @@ -1488,29 +1488,29 @@ RmGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int d bytes_left = sm->chunk_length; param_count = 1; param = sm->sctpchnk.Asconf; - if (bytes_left >= SN_MIN_PARAM_SIZE) { + if (bytes_left >= SN_MIN_PARAM_SIZE) { param_size = SCTP_SIZE32(ntohs(param->param_length)); } else { SN_LOG(SN_LOG_EVENT, - logsctperror("RmGlobalIPAddress: truncated packet - cannot remove IP addresses", + logsctperror("RmGlobalIPAddress: truncated packet - cannot remove IP addresses", sm->sctp_hdr->v_tag, sysctl_track_global_addresses, direction)); return; } - + /* step through Asconf parameters */ while((bytes_left >= param_size) && (bytes_left >= sizeof(struct sctp_ipv4addr_param))) { if (ntohs(param->param_type) == SCTP_DEL_IP_ADDRESS) { asconf_ipv4_param = (struct sctp_asconf_addrv4_param *) param; if (asconf_ipv4_param->addrp.addr == INADDR_ANY) { /* remove all bar pkt address */ LIST_FOREACH_SAFE(G_Addr, &(assoc->Gaddr), list_Gaddr, G_Addr_tmp) { - if(G_Addr->g_addr.s_addr != sm->ip_hdr->ip_src.s_addr) { + if (G_Addr->g_addr.s_addr != sm->ip_hdr->ip_src.s_addr) { if (assoc->num_Gaddr > 1) { /* only delete if more than one */ LIST_REMOVE(G_Addr, list_Gaddr); sn_free(G_Addr); assoc->num_Gaddr--; } else { SN_LOG(SN_LOG_EVENT, - logsctperror("RmGlobalIPAddress: Request to remove last IP address (didn't)", + logsctperror("RmGlobalIPAddress: Request to remove last IP address (didn't)", sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction)); } } @@ -1518,7 +1518,7 @@ RmGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int d return; /*shouldn't be any other addresses if the zero address is given*/ } else { LIST_FOREACH_SAFE(G_Addr, &(assoc->Gaddr), list_Gaddr, G_Addr_tmp) { - if(G_Addr->g_addr.s_addr == asconf_ipv4_param->addrp.addr) { + if (G_Addr->g_addr.s_addr == asconf_ipv4_param->addrp.addr) { if (assoc->num_Gaddr > 1) { /* only delete if more than one */ LIST_REMOVE(G_Addr, list_Gaddr); sn_free(G_Addr); @@ -1526,22 +1526,22 @@ RmGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int d break; /* Since add only adds new addresses, there should be no double entries */ } else { SN_LOG(SN_LOG_EVENT, - logsctperror("RmGlobalIPAddress: Request to remove last IP address (didn't)", + logsctperror("RmGlobalIPAddress: Request to remove last IP address (didn't)", sm->sctp_hdr->v_tag, assoc->num_Gaddr, direction)); } } } } - } + } bytes_left -= param_size; if (bytes_left == 0) return; else if (bytes_left < SN_MIN_PARAM_SIZE) { SN_LOG(SN_LOG_EVENT, - logsctperror("RmGlobalIPAddress: truncated packet - may not have removed all IP addresses", + logsctperror("RmGlobalIPAddress: truncated packet - may not have removed all IP addresses", sm->sctp_hdr->v_tag, sysctl_track_global_addresses, direction)); return; } - + param = SN_SCTP_NEXTPARAM(param); param_size = SCTP_SIZE32(ntohs(param->param_length)); if (++param_count > sysctl_param_proc_limit) { @@ -1568,11 +1568,11 @@ RmGlobalIPAddresses(struct sctp_nat_msg *sm, struct sctp_nat_assoc *assoc, int d * Since there is currently no connection on this path, there should be no other * ASCONF configuration parameters outstanding, so we presume that if there is * an ACK that it is responding to the AddIP and activate the new association. - * + * * @param la Pointer to the relevant libalias instance * @param sm Pointer to sctp message information - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL - * + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * * @return 1 - success | 0 - fail */ static int @@ -1587,45 +1587,45 @@ IsASCONFack(struct libalias *la, struct sctp_nat_msg *sm, int direction) param = sm->sctpchnk.Asconf; param_size = SCTP_SIZE32(ntohs(param->param_length)); if (param_size == 8) - return(1); /*success - default acknowledgement of everything */ + return (1); /*success - default acknowledgement of everything */ bytes_left = sm->chunk_length; if (bytes_left < param_size) - return(0); /* not found */ + return (0); /* not found */ /* step through Asconf parameters */ while(bytes_left >= SN_ASCONFACK_PARAM_SIZE) { if (ntohs(param->param_type) == SCTP_SUCCESS_REPORT) - return(1); /* success - but can't match correlation IDs - should only be one */ + return (1); /* success - but can't match correlation IDs - should only be one */ /* check others just in case */ bytes_left -= param_size; if (bytes_left >= SN_MIN_PARAM_SIZE) { param = SN_SCTP_NEXTPARAM(param); } else { - return(0); + return (0); } param_size = SCTP_SIZE32(ntohs(param->param_length)); - if (bytes_left < param_size) return(0); + if (bytes_left < param_size) return (0); if (++param_count > sysctl_param_proc_limit) { SN_LOG(SN_LOG_EVENT, - logsctperror("Parameter parse limit exceeded (IsASCONFack)", + logsctperror("Parameter parse limit exceeded (IsASCONFack)", sm->sctp_hdr->v_tag, sysctl_param_proc_limit, direction)); - return(0); /* not found limit exceeded*/ + return (0); /* not found limit exceeded*/ } } - return(0); /* not success */ + return (0); /* not success */ } /** @ingroup packet_parser - * @brief Check to see if ASCONF contains an Add IP or Del IP parameter - * + * @brief Check to see if ASCONF contains an Add IP or Del IP parameter + * * IsADDorDEL scans an ASCONF packet to see if it contains an AddIP or DelIP * parameter * * @param la Pointer to the relevant libalias instance * @param sm Pointer to sctp message information - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL - * + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * * @return SCTP_ADD_IP_ADDRESS | SCTP_DEL_IP_ADDRESS | 0 - fail */ static int @@ -1642,31 +1642,31 @@ IsADDorDEL(struct libalias *la, struct sctp_nat_msg *sm, int direction) bytes_left = sm->chunk_length; if (bytes_left < param_size) - return(0); /* not found */ + return (0); /* not found */ /* step through Asconf parameters */ while(bytes_left >= SN_ASCONFACK_PARAM_SIZE) { if (ntohs(param->param_type) == SCTP_ADD_IP_ADDRESS) - return(SCTP_ADD_IP_ADDRESS); - else if (ntohs(param->param_type) == SCTP_DEL_IP_ADDRESS) - return(SCTP_DEL_IP_ADDRESS); + return (SCTP_ADD_IP_ADDRESS); + else if (ntohs(param->param_type) == SCTP_DEL_IP_ADDRESS) + return (SCTP_DEL_IP_ADDRESS); /* check others just in case */ bytes_left -= param_size; if (bytes_left >= SN_MIN_PARAM_SIZE) { param = SN_SCTP_NEXTPARAM(param); } else { - return(0); /*Neither found */ + return (0); /*Neither found */ } param_size = SCTP_SIZE32(ntohs(param->param_length)); - if (bytes_left < param_size) return(0); + if (bytes_left < param_size) return (0); if (++param_count > sysctl_param_proc_limit) { SN_LOG(SN_LOG_EVENT, - logsctperror("Parameter parse limit exceeded IsADDorDEL)", + logsctperror("Parameter parse limit exceeded IsADDorDEL)", sm->sctp_hdr->v_tag, sysctl_param_proc_limit, direction)); - return(0); /* not found limit exceeded*/ + return (0); /* not found limit exceeded*/ } } - return(0); /*Neither found */ + return (0); /*Neither found */ } /* ---------------------------------------------------------------------- @@ -1689,7 +1689,7 @@ IsADDorDEL(struct libalias *la, struct sctp_nat_msg *sm, int direction) * each state. * * @param la Pointer to the relevant libalias instance - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL * @param sm Pointer to sctp message information * @param assoc Pointer to the association this SCTP Message belongs to * @@ -1706,17 +1706,17 @@ ProcessSctpMsg(struct libalias *la, int direction, struct sctp_nat_msg *sm, stru if (rtnval != SN_NAT_PKT) { assoc->state = SN_RM;/* Mark for removal*/ } - return(rtnval); + return (rtnval); case SN_INi: /* Initialising - Init */ - return(INi_process(la, direction, assoc, sm)); + return (INi_process(la, direction, assoc, sm)); case SN_INa: /* Initialising - AddIP */ - return(INa_process(la, direction, assoc, sm)); + return (INa_process(la, direction, assoc, sm)); case SN_UP: /* Association UP */ - return(UP_process(la, direction, assoc, sm)); + return (UP_process(la, direction, assoc, sm)); case SN_CL: /* Association Closing */ - return(CL_process(la, direction, assoc, sm)); + return (CL_process(la, direction, assoc, sm)); } - return(SN_PROCESSING_ERROR); + return (SN_PROCESSING_ERROR); } /** @ingroup state_machine @@ -1736,56 +1736,57 @@ ProcessSctpMsg(struct libalias *la, int direction, struct sctp_nat_msg *sm, stru static int ID_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm) { - switch(sm->msg) { + switch (sm->msg) { case SN_SCTP_ASCONF: /* a packet containing an ASCONF chunk with ADDIP */ if (!sysctl_accept_global_ootb_addip && (direction == SN_TO_LOCAL)) - return(SN_DROP_PKT); + return (SN_DROP_PKT); /* if this Asconf packet does not contain the Vtag parameters it is of no use in Idle state */ if (!GetAsconfVtags(la, sm, &(assoc->l_vtag), &(assoc->g_vtag), direction)) - return(SN_DROP_PKT); + return (SN_DROP_PKT); + /* FALLTHROUGH */ case SN_SCTP_INIT: /* a packet containing an INIT chunk or an ASCONF AddIP */ if (sysctl_track_global_addresses) AddGlobalIPAddresses(sm, assoc, direction); - switch(direction){ + switch (direction) { case SN_TO_GLOBAL: assoc->l_addr = sm->ip_hdr->ip_src; assoc->a_addr = FindAliasAddress(la, assoc->l_addr); assoc->l_port = sm->sctp_hdr->src_port; assoc->g_port = sm->sctp_hdr->dest_port; - if(sm->msg == SN_SCTP_INIT) + if (sm->msg == SN_SCTP_INIT) assoc->g_vtag = sm->sctpchnk.Init->initiate_tag; if (AddSctpAssocGlobal(la, assoc)) /* DB clash *///**** need to add dst address - return((sm->msg == SN_SCTP_INIT) ? SN_REPLY_ABORT : SN_REPLY_ERROR); - if(sm->msg == SN_SCTP_ASCONF) { + return ((sm->msg == SN_SCTP_INIT) ? SN_REPLY_ABORT : SN_REPLY_ERROR); + if (sm->msg == SN_SCTP_ASCONF) { if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_dst)) /* DB clash */ - return(SN_REPLY_ERROR); + return (SN_REPLY_ERROR); assoc->TableRegister |= SN_WAIT_TOLOCAL; /* wait for tolocal ack */ } break; case SN_TO_LOCAL: assoc->l_addr = FindSctpRedirectAddress(la, sm); - assoc->a_addr = sm->ip_hdr->ip_dst; + assoc->a_addr = sm->ip_hdr->ip_dst; assoc->l_port = sm->sctp_hdr->dest_port; assoc->g_port = sm->sctp_hdr->src_port; - if(sm->msg == SN_SCTP_INIT) + if (sm->msg == SN_SCTP_INIT) assoc->l_vtag = sm->sctpchnk.Init->initiate_tag; if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_src)) /* DB clash */ - return((sm->msg == SN_SCTP_INIT) ? SN_REPLY_ABORT : SN_REPLY_ERROR); - if(sm->msg == SN_SCTP_ASCONF) { + return ((sm->msg == SN_SCTP_INIT) ? SN_REPLY_ABORT : SN_REPLY_ERROR); + if (sm->msg == SN_SCTP_ASCONF) { if (AddSctpAssocGlobal(la, assoc)) /* DB clash */ //**** need to add src address - return(SN_REPLY_ERROR); + return (SN_REPLY_ERROR); assoc->TableRegister |= SN_WAIT_TOGLOBAL; /* wait for toglobal ack */ } break; } - assoc->state = (sm->msg == SN_SCTP_INIT) ? SN_INi : SN_INa; - assoc->exp = SN_I_T(la); - sctp_AddTimeOut(la,assoc); - return(SN_NAT_PKT); + assoc->state = (sm->msg == SN_SCTP_INIT) ? SN_INi : SN_INa; + assoc->exp = SN_I_T(la); + sctp_AddTimeOut(la,assoc); + return (SN_NAT_PKT); default: /* Any other type of SCTP message is not valid in Idle */ - return(SN_DROP_PKT); + return (SN_DROP_PKT); } -return(SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the best */ + return (SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the best */ } /** @ingroup state_machine @@ -1793,30 +1794,30 @@ return(SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the b * * Only an INIT-ACK, resent INIT, or an ABORT SCTP packet are valid in this * state, all other packets are dropped. - * + * * @param la Pointer to the relevant libalias instance - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL * @param sm Pointer to sctp message information * @param assoc Pointer to the association this SCTP Message belongs to - * - * @return SN_NAT_PKT | SN_DROP_PKT | SN_REPLY_ABORT + * + * @return SN_NAT_PKT | SN_DROP_PKT | SN_REPLY_ABORT */ static int INi_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm) { - switch(sm->msg) { + switch (sm->msg) { case SN_SCTP_INIT: /* a packet containing a retransmitted INIT chunk */ sctp_ResetTimeOut(la, assoc, SN_I_T(la)); - return(SN_NAT_PKT); + return (SN_NAT_PKT); case SN_SCTP_INITACK: /* a packet containing an INIT-ACK chunk */ - switch(direction){ + switch (direction) { case SN_TO_LOCAL: if (assoc->num_Gaddr) /*If tracking global addresses for this association */ AddGlobalIPAddresses(sm, assoc, direction); assoc->l_vtag = sm->sctpchnk.Init->initiate_tag; if (AddSctpAssocLocal(la, assoc, sm->ip_hdr->ip_src)) { /* DB clash */ assoc->state = SN_RM;/* Mark for removal*/ - return(SN_SEND_ABORT); + return (SN_SEND_ABORT); } break; case SN_TO_GLOBAL: @@ -1824,97 +1825,97 @@ INi_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, st assoc->g_vtag = sm->sctpchnk.Init->initiate_tag; if (AddSctpAssocGlobal(la, assoc)) { /* DB clash */ assoc->state = SN_RM;/* Mark for removal*/ - return(SN_SEND_ABORT); + return (SN_SEND_ABORT); } break; } assoc->state = SN_UP;/* association established for NAT */ sctp_ResetTimeOut(la,assoc, SN_U_T(la)); - return(SN_NAT_PKT); + return (SN_NAT_PKT); case SN_SCTP_ABORT: /* a packet containing an ABORT chunk */ assoc->state = SN_RM;/* Mark for removal*/ - return(SN_NAT_PKT); + return (SN_NAT_PKT); default: - return(SN_DROP_PKT); + return (SN_DROP_PKT); } - return(SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the best */ + return (SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the best */ } /** @ingroup state_machine * @brief Process SCTP message while waiting for an AddIp-ACK message - * + * * Only an AddIP-ACK, resent AddIP, or an ABORT message are valid, all other * SCTP packets are dropped * * @param la Pointer to the relevant libalias instance - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL * @param sm Pointer to sctp message information * @param assoc Pointer to the association this SCTP Message belongs to - * - * @return SN_NAT_PKT | SN_DROP_PKT + * + * @return SN_NAT_PKT | SN_DROP_PKT */ static int INa_process(struct libalias *la, int direction,struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm) { - switch(sm->msg) { + switch (sm->msg) { case SN_SCTP_ASCONF: /* a packet containing an ASCONF chunk*/ sctp_ResetTimeOut(la,assoc, SN_I_T(la)); - return(SN_NAT_PKT); + return (SN_NAT_PKT); case SN_SCTP_ASCONFACK: /* a packet containing an ASCONF chunk with a ADDIP-ACK */ - switch(direction){ + switch (direction) { case SN_TO_LOCAL: if (!(assoc->TableRegister & SN_WAIT_TOLOCAL)) /* wrong direction */ - return(SN_DROP_PKT); + return (SN_DROP_PKT); break; case SN_TO_GLOBAL: if (!(assoc->TableRegister & SN_WAIT_TOGLOBAL)) /* wrong direction */ - return(SN_DROP_PKT); + return (SN_DROP_PKT); } if (IsASCONFack(la,sm,direction)) { assoc->TableRegister &= SN_BOTH_TBL; /* remove wait flags */ assoc->state = SN_UP; /* association established for NAT */ sctp_ResetTimeOut(la,assoc, SN_U_T(la)); - return(SN_NAT_PKT); + return (SN_NAT_PKT); } else { assoc->state = SN_RM;/* Mark for removal*/ - return(SN_NAT_PKT); + return (SN_NAT_PKT); } case SN_SCTP_ABORT: /* a packet containing an ABORT chunk */ assoc->state = SN_RM;/* Mark for removal*/ - return(SN_NAT_PKT); + return (SN_NAT_PKT); default: - return(SN_DROP_PKT); + return (SN_DROP_PKT); } - return(SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the best */ + return (SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the best */ } /** @ingroup state_machine * @brief Process SCTP messages while association is UP redirecting packets - * + * * While in the SN_UP state, all packets for the particular association * are passed. Only a SHUT-ACK or an ABORT will cause a change of state. * * @param la Pointer to the relevant libalias instance - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL * @param sm Pointer to sctp message information * @param assoc Pointer to the association this SCTP Message belongs to - * - * @return SN_NAT_PKT | SN_DROP_PKT + * + * @return SN_NAT_PKT | SN_DROP_PKT */ static int UP_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm) { - switch(sm->msg) { + switch (sm->msg) { case SN_SCTP_SHUTACK: /* a packet containing a SHUTDOWN-ACK chunk */ assoc->state = SN_CL; sctp_ResetTimeOut(la,assoc, SN_C_T(la)); - return(SN_NAT_PKT); + return (SN_NAT_PKT); case SN_SCTP_ABORT: /* a packet containing an ABORT chunk */ assoc->state = SN_RM;/* Mark for removal*/ - return(SN_NAT_PKT); + return (SN_NAT_PKT); case SN_SCTP_ASCONF: /* a packet containing an ASCONF chunk*/ if ((direction == SN_TO_LOCAL) && assoc->num_Gaddr) /*If tracking global addresses for this association & from global side */ - switch(IsADDorDEL(la,sm,direction)) { + switch (IsADDorDEL(la,sm,direction)) { case SCTP_ADD_IP_ADDRESS: AddGlobalIPAddresses(sm, assoc, direction); break; @@ -1924,9 +1925,9 @@ UP_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, str } /* fall through to default */ default: sctp_ResetTimeOut(la,assoc, SN_U_T(la)); - return(SN_NAT_PKT); /* forward packet */ + return (SN_NAT_PKT); /* forward packet */ } - return(SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the best */ + return (SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the best */ } /** @ingroup state_machine @@ -1938,34 +1939,34 @@ UP_process(struct libalias *la, int direction, struct sctp_nat_assoc *assoc, str * ABORT packets are permitted in this state. All other packets are dropped. * * @param la Pointer to the relevant libalias instance - * @param direction SN_TO_LOCAL | SN_TO_GLOBAL + * @param direction SN_TO_LOCAL | SN_TO_GLOBAL * @param sm Pointer to sctp message information * @param assoc Pointer to the association this SCTP Message belongs to - * - * @return SN_NAT_PKT | SN_DROP_PKT + * + * @return SN_NAT_PKT | SN_DROP_PKT */ static int CL_process(struct libalias *la, int direction,struct sctp_nat_assoc *assoc, struct sctp_nat_msg *sm) { - switch(sm->msg) { + switch (sm->msg) { case SN_SCTP_SHUTCOMP: /* a packet containing a SHUTDOWN-COMPLETE chunk */ assoc->state = SN_CL; /* Stay in Close state until timeout */ if (sysctl_holddown_timer > 0) sctp_ResetTimeOut(la, assoc, SN_X_T(la));/* allow to stay open for Tbit packets*/ else assoc->state = SN_RM;/* Mark for removal*/ - return(SN_NAT_PKT); + return (SN_NAT_PKT); case SN_SCTP_SHUTACK: /* a packet containing a SHUTDOWN-ACK chunk */ assoc->state = SN_CL; /* Stay in Close state until timeout */ sctp_ResetTimeOut(la, assoc, SN_C_T(la)); - return(SN_NAT_PKT); + return (SN_NAT_PKT); case SN_SCTP_ABORT: /* a packet containing an ABORT chunk */ assoc->state = SN_RM;/* Mark for removal*/ - return(SN_NAT_PKT); + return (SN_NAT_PKT); default: - return(SN_DROP_PKT); + return (SN_DROP_PKT); } - return(SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the best */ + return (SN_DROP_PKT);/* shouldn't get here very bad: log, drop and hope for the best */ } /* ---------------------------------------------------------------------- @@ -1979,7 +1980,7 @@ CL_process(struct libalias *la, int direction,struct sctp_nat_assoc *assoc, stru */ /** @ingroup Hash * @brief Find the SCTP association given the local address, port and vtag - * + * * Searches the local look-up table for the association entry matching the * provided local tuple * @@ -1989,7 +1990,7 @@ CL_process(struct libalias *la, int direction,struct sctp_nat_assoc *assoc, stru * @param l_vtag local Vtag * @param l_port local Port * @param g_port global Port - * + * * @return pointer to association or NULL */ static struct sctp_nat_assoc* @@ -1998,7 +1999,7 @@ FindSctpLocal(struct libalias *la, struct in_addr l_addr, struct in_addr g_addr, u_int i; struct sctp_nat_assoc *assoc = NULL; struct sctp_GlobalAddress *G_Addr = NULL; - + if (l_vtag != 0) { /* an init packet, vtag==0 */ i = SN_TABLE_HASH(l_vtag, l_port, la->sctpNatTableSize); LIST_FOREACH(assoc, &la->sctpTableLocal[i], list_L) { @@ -2006,27 +2007,27 @@ FindSctpLocal(struct libalias *la, struct in_addr l_addr, struct in_addr g_addr, && (assoc->l_addr.s_addr == l_addr.s_addr)) { if (assoc->num_Gaddr) { LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) { - if(G_Addr->g_addr.s_addr == g_addr.s_addr) - return(assoc); + if (G_Addr->g_addr.s_addr == g_addr.s_addr) + return (assoc); } } else { - return(assoc); + return (assoc); } } } } - return(NULL); + return (NULL); } /** @ingroup Hash * @brief Check for Global Clash - * + * * Searches the global look-up table for the association entry matching the * provided global <(addresses):ports:vtag> tuple * * @param la Pointer to the relevant libalias instance * @param Cassoc association being checked for a clash - * + * * @return pointer to association or NULL */ static struct sctp_nat_assoc* @@ -2036,7 +2037,7 @@ FindSctpGlobalClash(struct libalias *la, struct sctp_nat_assoc *Cassoc) struct sctp_nat_assoc *assoc = NULL; struct sctp_GlobalAddress *G_Addr = NULL; struct sctp_GlobalAddress *G_AddrC = NULL; - + if (Cassoc->g_vtag != 0) { /* an init packet, vtag==0 */ i = SN_TABLE_HASH(Cassoc->g_vtag, Cassoc->g_port, la->sctpNatTableSize); LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) { @@ -2044,22 +2045,22 @@ FindSctpGlobalClash(struct libalias *la, struct sctp_nat_assoc *Cassoc) if (assoc->num_Gaddr) { LIST_FOREACH(G_AddrC, &(Cassoc->Gaddr), list_Gaddr) { LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) { - if(G_Addr->g_addr.s_addr == G_AddrC->g_addr.s_addr) - return(assoc); + if (G_Addr->g_addr.s_addr == G_AddrC->g_addr.s_addr) + return (assoc); } } } else { - return(assoc); + return (assoc); } } } } - return(NULL); + return (NULL); } /** @ingroup Hash * @brief Find the SCTP association given the global port and vtag - * + * * Searches the global look-up table for the association entry matching the * provided global tuple * @@ -2073,7 +2074,7 @@ FindSctpGlobalClash(struct libalias *la, struct sctp_nat_assoc *Cassoc) * @param g_vtag global vtag * @param g_port global port * @param l_port local port - * + * * @return pointer to association or NULL */ static struct sctp_nat_assoc* @@ -2082,7 +2083,7 @@ FindSctpGlobal(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint u_int i; struct sctp_nat_assoc *assoc = NULL; struct sctp_GlobalAddress *G_Addr = NULL; - + *partial_match = 0; if (g_vtag != 0) { /* an init packet, vtag==0 */ i = SN_TABLE_HASH(g_vtag, g_port, la->sctpNatTableSize); @@ -2091,21 +2092,21 @@ FindSctpGlobal(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint *partial_match = 1; if (assoc->num_Gaddr) { LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) { - if(G_Addr->g_addr.s_addr == g_addr.s_addr) - return(assoc); + if (G_Addr->g_addr.s_addr == g_addr.s_addr) + return (assoc); } } else { - return(assoc); + return (assoc); } } } } - return(NULL); + return (NULL); } /** @ingroup Hash * @brief Find the SCTP association for a T-Flag message (given the global port and local vtag) - * + * * Searches the local look-up table for a unique association entry matching the * provided global port and local vtag information * @@ -2114,40 +2115,40 @@ FindSctpGlobal(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uint * @param l_vtag local Vtag * @param g_port global Port * @param l_port local Port - * + * * @return pointer to association or NULL */ static struct sctp_nat_assoc* -FindSctpLocalT(struct libalias *la, struct in_addr g_addr, uint32_t l_vtag, uint16_t g_port, uint16_t l_port) +FindSctpLocalT(struct libalias *la, struct in_addr g_addr, uint32_t l_vtag, uint16_t g_port, uint16_t l_port) { u_int i; struct sctp_nat_assoc *assoc = NULL, *lastmatch = NULL; struct sctp_GlobalAddress *G_Addr = NULL; int cnt = 0; - + if (l_vtag != 0) { /* an init packet, vtag==0 */ i = SN_TABLE_HASH(l_vtag, g_port, la->sctpNatTableSize); LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) { if ((assoc->g_vtag == l_vtag) && (assoc->g_port == g_port) && (assoc->l_port == l_port)) { if (assoc->num_Gaddr) { LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) { - if(G_Addr->g_addr.s_addr == G_Addr->g_addr.s_addr) - return(assoc); /* full match */ + if (G_Addr->g_addr.s_addr == g_addr.s_addr) + return (assoc); /* full match */ } } else { - if (++cnt > 1) return(NULL); + if (++cnt > 1) return (NULL); lastmatch = assoc; } } } } /* If there is more than one match we do not know which local address to send to */ - return( cnt ? lastmatch : NULL ); + return (cnt ? lastmatch : NULL); } /** @ingroup Hash * @brief Find the SCTP association for a T-Flag message (given the local port and global vtag) - * + * * Searches the global look-up table for a unique association entry matching the * provided local port and global vtag information * @@ -2156,7 +2157,7 @@ FindSctpLocalT(struct libalias *la, struct in_addr g_addr, uint32_t l_vtag, uin * @param g_vtag global vtag * @param l_port local port * @param g_port global port - * + * * @return pointer to association or NULL */ static struct sctp_nat_assoc* @@ -2165,28 +2166,28 @@ FindSctpGlobalT(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uin u_int i; struct sctp_nat_assoc *assoc = NULL; struct sctp_GlobalAddress *G_Addr = NULL; - + if (g_vtag != 0) { /* an init packet, vtag==0 */ i = SN_TABLE_HASH(g_vtag, l_port, la->sctpNatTableSize); LIST_FOREACH(assoc, &la->sctpTableLocal[i], list_L) { if ((assoc->l_vtag == g_vtag) && (assoc->l_port == l_port) && (assoc->g_port == g_port)) { if (assoc->num_Gaddr) { LIST_FOREACH(G_Addr, &(assoc->Gaddr), list_Gaddr) { - if(G_Addr->g_addr.s_addr == g_addr.s_addr) - return(assoc); + if (G_Addr->g_addr.s_addr == g_addr.s_addr) + return (assoc); } } else { - return(assoc); + return (assoc); } } } } - return(NULL); + return (NULL); } /** @ingroup Hash * @brief Add the sctp association information to the local look up table - * + * * Searches the local look-up table for an existing association with the same * details. If a match exists and is ONLY in the local look-up table then this * is a repeated INIT packet, we need to remove this association from the @@ -2197,7 +2198,7 @@ FindSctpGlobalT(struct libalias *la, struct in_addr g_addr, uint32_t g_vtag, uin * @param la Pointer to the relevant libalias instance * @param assoc pointer to sctp association * @param g_addr global address - * + * * @return SN_ADD_OK | SN_ADD_CLASH */ static int @@ -2223,9 +2224,9 @@ AddSctpAssocLocal(struct libalias *la, struct sctp_nat_assoc *assoc, struct in_a freeGlobalAddressList(found); sn_free(found); } else - return(SN_ADD_CLASH); + return (SN_ADD_CLASH); } - + LIST_INSERT_HEAD(&la->sctpTableLocal[SN_TABLE_HASH(assoc->l_vtag, assoc->l_port, la->sctpNatTableSize)], assoc, list_L); assoc->TableRegister |= SN_LOCAL_TBL; @@ -2239,7 +2240,7 @@ AddSctpAssocLocal(struct libalias *la, struct sctp_nat_assoc *assoc, struct in_a SN_LOG(SN_LOG_INFO, logsctpassoc(assoc, "^")); } - return(SN_ADD_OK); + return (SN_ADD_OK); } /** @ingroup Hash @@ -2272,9 +2273,9 @@ AddSctpAssocGlobal(struct libalias *la, struct sctp_nat_assoc *assoc) freeGlobalAddressList(found); sn_free(found); } else - return(SN_ADD_CLASH); + return (SN_ADD_CLASH); } - + LIST_INSERT_HEAD(&la->sctpTableGlobal[SN_TABLE_HASH(assoc->g_vtag, assoc->g_port, la->sctpNatTableSize)], assoc, list_G); assoc->TableRegister |= SN_GLOBAL_TBL; @@ -2288,12 +2289,12 @@ AddSctpAssocGlobal(struct libalias *la, struct sctp_nat_assoc *assoc) SN_LOG(SN_LOG_INFO, logsctpassoc(assoc, "^")); } - return(SN_ADD_OK); + return (SN_ADD_OK); } /** @ingroup Hash * @brief Remove the sctp association information from the look up table - * + * * For each of the two (local/global) look-up tables, remove the association * from that table IF it has been registered in that table. * @@ -2325,7 +2326,7 @@ RmSctpAssoc(struct libalias *la, struct sctp_nat_assoc *assoc) la->sctpLinkCount--; //decrement link count LIST_REMOVE(assoc, list_L); } - + if (assoc->TableRegister & SN_GLOBAL_TBL) { assoc->TableRegister ^= SN_GLOBAL_TBL; la->sctpLinkCount--; //decrement link count @@ -2337,20 +2338,20 @@ RmSctpAssoc(struct libalias *la, struct sctp_nat_assoc *assoc) SctpShowAliasStats(la); } -/** +/** * @ingroup Hash * @brief free the Global Address List memory - * + * * freeGlobalAddressList deletes all global IP addresses in an associations * global IP address list. * - * @param assoc + * @param assoc */ static void freeGlobalAddressList(struct sctp_nat_assoc *assoc) { struct sctp_GlobalAddress *gaddr1=NULL,*gaddr2=NULL; /*free global address list*/ - gaddr1 = LIST_FIRST(&(assoc->Gaddr)); + gaddr1 = LIST_FIRST(&(assoc->Gaddr)); while (gaddr1 != NULL) { gaddr2 = LIST_NEXT(gaddr1, list_Gaddr); sn_free(gaddr1); @@ -2381,8 +2382,8 @@ static void freeGlobalAddressList(struct sctp_nat_assoc *assoc) * Determine the location in the queue to add the timeout and insert the * association into the list at that queue position * - * @param la - * @param assoc + * @param la + * @param assoc */ static void sctp_AddTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc) @@ -2438,7 +2439,7 @@ sctp_ResetTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc, int newexp) /** @ingroup Timer * @brief Check timer Q against current time - * + * * Loop through each entry in the timer queue since the last time we processed * the timer queue until now (the current time). For each association in the * event list, we remove it from that position in the timer queue and check if @@ -2449,22 +2450,22 @@ sctp_ResetTimeOut(struct libalias *la, struct sctp_nat_assoc *assoc, int newexp) * * If the timer hasn't really expired we place the association into its new * correct position in the timer queue. - * + * * @param la Pointer to the relevant libalias instance */ void sctp_CheckTimers(struct libalias *la) { struct sctp_nat_assoc *assoc; - + LIBALIAS_LOCK_ASSERT(la); while(la->timeStamp >= la->sctpNatTimer.loc_time) { - while (!LIST_EMPTY(&la->sctpNatTimer.TimerQ[la->sctpNatTimer.cur_loc])) { + while (!LIST_EMPTY(&la->sctpNatTimer.TimerQ[la->sctpNatTimer.cur_loc])) { assoc = LIST_FIRST(&la->sctpNatTimer.TimerQ[la->sctpNatTimer.cur_loc]); //SLIST_REMOVE_HEAD(&la->sctpNatTimer.TimerQ[la->sctpNatTimer.cur_loc], timer_Q); LIST_REMOVE(assoc, timer_Q); if (la->timeStamp >= assoc->exp) { /* state expired */ - SN_LOG(((assoc->state == SN_CL)?(SN_LOG_DEBUG):(SN_LOG_INFO)), + SN_LOG(((assoc->state == SN_CL) ? (SN_LOG_DEBUG) : (SN_LOG_INFO)), logsctperror("Timer Expired", assoc->g_vtag, assoc->state, SN_TO_NODIR)); RmSctpAssoc(la, assoc); freeGlobalAddressList(assoc); @@ -2481,7 +2482,7 @@ sctp_CheckTimers(struct libalias *la) } /* ---------------------------------------------------------------------- - * LOGGING CODE + * LOGGING CODE * ---------------------------------------------------------------------- */ /** @addtogroup Logging @@ -2492,7 +2493,7 @@ sctp_CheckTimers(struct libalias *la) */ /** @ingroup Logging * @brief Log sctp nat errors - * + * * @param errormsg Error message to be logged * @param vtag Current Vtag * @param error Error number @@ -2502,7 +2503,7 @@ static void logsctperror(char* errormsg, uint32_t vtag, int error, int direction) { char dir; - switch(direction) { + switch (direction) { case SN_TO_LOCAL: dir = 'L'; break; @@ -2518,7 +2519,7 @@ logsctperror(char* errormsg, uint32_t vtag, int error, int direction) /** @ingroup Logging * @brief Log what the parser parsed - * + * * @param direction Direction of packet * @param sm Pointer to sctp message information */ @@ -2526,7 +2527,7 @@ static void logsctpparse(int direction, struct sctp_nat_msg *sm) { char *ploc, *pstate; - switch(direction) { + switch (direction) { case SN_TO_LOCAL: ploc = "TO_LOCAL -"; break; @@ -2536,7 +2537,7 @@ logsctpparse(int direction, struct sctp_nat_msg *sm) default: ploc = ""; } - switch(sm->msg) { + switch (sm->msg) { case SN_SCTP_INIT: pstate = "Init"; break; @@ -2570,7 +2571,7 @@ logsctpparse(int direction, struct sctp_nat_msg *sm) /** @ingroup Logging * @brief Log an SCTP association's details - * + * * @param assoc pointer to sctp association * @param s Character that indicates the state of processing for this packet */ @@ -2580,7 +2581,7 @@ static void logsctpassoc(struct sctp_nat_assoc *assoc, char* s) char *sp; char addrbuf[INET_ADDRSTRLEN]; - switch(assoc->state) { + switch (assoc->state) { case SN_ID: sp = "ID "; break; @@ -2616,15 +2617,15 @@ static void logsctpassoc(struct sctp_nat_assoc *assoc, char* s) } /** @ingroup Logging - * @brief Output Global table to log - * + * @brief Output Global table to log + * * @param la Pointer to the relevant libalias instance */ static void logSctpGlobal(struct libalias *la) { u_int i; struct sctp_nat_assoc *assoc = NULL; - + SctpAliasLog("G->\n"); for (i=0; i < la->sctpNatTableSize; i++) { LIST_FOREACH(assoc, &la->sctpTableGlobal[i], list_G) { @@ -2634,15 +2635,15 @@ static void logSctpGlobal(struct libalias *la) } /** @ingroup Logging - * @brief Output Local table to log - * + * @brief Output Local table to log + * * @param la Pointer to the relevant libalias instance */ static void logSctpLocal(struct libalias *la) { u_int i; struct sctp_nat_assoc *assoc = NULL; - + SctpAliasLog("L->\n"); for (i=0; i < la->sctpNatTableSize; i++) { LIST_FOREACH(assoc, &la->sctpTableLocal[i], list_L) { @@ -2653,7 +2654,7 @@ static void logSctpLocal(struct libalias *la) /** @ingroup Logging * @brief Output timer queue to log - * + * * @param la Pointer to the relevant libalias instance */ static void logTimerQ(struct libalias *la) @@ -2672,12 +2673,12 @@ static void logTimerQ(struct libalias *la) } } -/** @ingroup Logging +/** @ingroup Logging * @brief Sctp NAT logging function - * + * * This function is based on a similar function in alias_db.c * - * @param str/stream logging descriptor + * @param str/stream logging descriptor * @param format printf type string */ #ifdef _KERNEL diff --git a/sys/netinet/sctp_crc32.c b/sys/netinet/sctp_crc32.c index 9d1f54c7be3..da5df194b8b 100644 --- a/sys/netinet/sctp_crc32.c +++ b/sys/netinet/sctp_crc32.c @@ -35,29 +35,36 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_sctp.h" + +#ifdef SCTP #include #include #include #include +#else +#include +#include +#include - +#include +#endif static uint32_t sctp_finalize_crc32c(uint32_t crc32c) { uint32_t result; - #if BYTE_ORDER == BIG_ENDIAN uint8_t byte0, byte1, byte2, byte3; - #endif + /* Complement the result */ result = ~crc32c; #if BYTE_ORDER == BIG_ENDIAN /* - * For BIG-ENDIAN.. aka Motorola byte order the result is in - * little-endian form. So we must manually swap the bytes. Then we - * can call htonl() which does nothing... + * For BIG-ENDIAN platforms the result is in little-endian form. So + * we must swap the bytes to return the result in network byte + * order. */ byte0 = result & 0x000000ff; byte1 = (result >> 8) & 0x000000ff; @@ -66,56 +73,54 @@ sctp_finalize_crc32c(uint32_t crc32c) crc32c = ((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3); #else /* - * For INTEL platforms the result comes out in network order. No - * htonl is required or the swap above. So we optimize out both the - * htonl and the manual swap above. + * For LITTLE ENDIAN platforms the result is in already in network + * byte order. */ crc32c = result; #endif return (crc32c); } +/* + * Compute the SCTP checksum in network byte order for a given mbuf chain m + * which contains an SCTP packet starting at offset. + * Since this function is also called by ipfw, don't assume that + * it is compiled on a kernel with SCTP support. + */ uint32_t sctp_calculate_cksum(struct mbuf *m, uint32_t offset) { - /* - * given a mbuf chain with a packetheader offset by 'offset' - * pointing at a sctphdr (with csum set to 0) go through the chain - * of SCTP_BUF_NEXT()'s and calculate the SCTP checksum. This also - * has a side bonus as it will calculate the total length of the - * mbuf chain. Note: if offset is greater than the total mbuf - * length, checksum=1, pktlen=0 is returned (ie. no real error code) - */ uint32_t base = 0xffffffff; - struct mbuf *at; - at = m; - /* find the correct mbuf and offset into mbuf */ - while ((at != NULL) && (offset > (uint32_t)SCTP_BUF_LEN(at))) { - offset -= SCTP_BUF_LEN(at); /* update remaining offset - * left */ - at = SCTP_BUF_NEXT(at); + while (offset > 0) { + KASSERT(m != NULL, ("sctp_calculate_cksum, offset > length of mbuf chain")); + if (offset < (uint32_t)m->m_len) { + break; + } + offset -= m->m_len; + m = m->m_next; } - while (at != NULL) { - if ((SCTP_BUF_LEN(at) - offset) > 0) { - base = calculate_crc32c(base, - (unsigned char *)(SCTP_BUF_AT(at, offset)), - (unsigned int)(SCTP_BUF_LEN(at) - offset)); - } - if (offset) { - /* we only offset once into the first mbuf */ - if (offset < (uint32_t)SCTP_BUF_LEN(at)) - offset = 0; - else - offset -= SCTP_BUF_LEN(at); - } - at = SCTP_BUF_NEXT(at); + if (offset > 0) { + base = calculate_crc32c(base, + (unsigned char *)(m->m_data + offset), + (unsigned int)(m->m_len - offset)); + m = m->m_next; + } + while (m != NULL) { + base = calculate_crc32c(base, + (unsigned char *)m->m_data, + (unsigned int)m->m_len); + m = m->m_next; } base = sctp_finalize_crc32c(base); return (base); } - +#ifdef SCTP +/* + * Compute and insert the SCTP checksum in network byte order for a given + * mbuf chain m which contains an SCTP packet starting at offset. + */ void sctp_delayed_cksum(struct mbuf *m, uint32_t offset) { @@ -127,14 +132,15 @@ sctp_delayed_cksum(struct mbuf *m, uint32_t offset) offset += offsetof(struct sctphdr, checksum); if (offset + sizeof(uint32_t) > (uint32_t)(m->m_len)) { - SCTP_PRINTF("sctp_delayed_cksum(): m->len: %d, off: %d.\n", - (uint32_t)m->m_len, offset); - /* - * XXX this shouldn't happen, but if it does, the correct - * behavior may be to insert the checksum in the appropriate - * next mbuf in the chain. - */ +#ifdef INVARIANTS + panic("sctp_delayed_cksum(): m->m_len: %d, offset: %u.", + m->m_len, offset); +#else + SCTP_PRINTF("sctp_delayed_cksum(): m->m_len: %d, offset: %u.\n", + m->m_len, offset); +#endif return; } *(uint32_t *)(m->m_data + offset) = checksum; } +#endif diff --git a/sys/netinet/sctp_crc32.h b/sys/netinet/sctp_crc32.h index 23d374d64e5..4bdf8265043 100644 --- a/sys/netinet/sctp_crc32.h +++ b/sys/netinet/sctp_crc32.h @@ -40,6 +40,8 @@ __FBSDID("$FreeBSD$"); #if defined(_KERNEL) uint32_t sctp_calculate_cksum(struct mbuf *, uint32_t); +#ifdef SCTP void sctp_delayed_cksum(struct mbuf *, uint32_t offset); +#endif #endif /* _KERNEL */ #endif /* __crc32c_h__ */ diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index 0ef64cbaef3..66fe00d5a22 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -198,7 +198,9 @@ tcp_output(struct tcpcb *tp) int off, flags, error = 0; /* Keep compiler happy */ struct mbuf *m; struct ip *ip = NULL; +#ifdef TCPDEBUG struct ipovly *ipov = NULL; +#endif struct tcphdr *th; u_char opt[TCP_MAXOLEN]; unsigned ipoptlen, optlen, hdrlen; @@ -1091,7 +1093,9 @@ tcp_output(struct tcpcb *tp) #endif /* INET6 */ { ip = mtod(m, struct ip *); +#ifdef TCPDEBUG ipov = (struct ipovly *)ip; +#endif th = (struct tcphdr *)(ip + 1); tcpip_fillheaders(tp->t_inpcb, ip, th); } diff --git a/sys/netinet6/in6_mcast.c b/sys/netinet6/in6_mcast.c index a0efcc83368..2d37ba9802b 100644 --- a/sys/netinet6/in6_mcast.c +++ b/sys/netinet6/in6_mcast.c @@ -1238,11 +1238,8 @@ in6_mc_join_locked(struct ifnet *ifp, const struct in6_addr *mcaddr, int in6_mc_leave(struct in6_multi *inm, /*const*/ struct in6_mfilter *imf) { - struct ifnet *ifp; int error; - ifp = inm->in6m_ifp; - IN6_MULTI_LOCK(); error = in6_mc_leave_locked(inm, imf); IN6_MULTI_UNLOCK(); diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index bd4b5dee0c4..7b3b5553c2e 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -160,7 +160,6 @@ static struct in6_addrpolicy *match_addrsel_policy(struct sockaddr_in6 *); */ #define REPLACE(r) do {\ IP6STAT_INC(ip6s_sources_rule[(r)]); \ - rule = (r); \ /* { \ char ip6buf[INET6_ADDRSTRLEN], ip6b[INET6_ADDRSTRLEN]; \ printf("in6_selectsrc: replace %s with %s by %d\n", ia_best ? ip6_sprintf(ip6buf, &ia_best->ia_addr.sin6_addr) : "none", ip6_sprintf(ip6b, &ia->ia_addr.sin6_addr), (r)); \ @@ -176,7 +175,6 @@ static struct in6_addrpolicy *match_addrsel_policy(struct sockaddr_in6 *); } while(0) #define BREAK(r) do { \ IP6STAT_INC(ip6s_sources_rule[(r)]); \ - rule = (r); \ goto out; /* XXX: we can't use 'break' here */ \ } while(0) @@ -194,7 +192,7 @@ in6_selectsrc(uint32_t fibnum, struct sockaddr_in6 *dstsock, struct in6_addrpolicy *dst_policy = NULL, *best_policy = NULL; u_int32_t odstzone; int prefer_tempaddr; - int error, rule; + int error; struct ip6_moptions *mopts; KASSERT(srcp != NULL, ("%s: srcp is NULL", __func__)); @@ -310,7 +308,6 @@ in6_selectsrc(uint32_t fibnum, struct sockaddr_in6 *dstsock, if (error) return (error); - rule = 0; IN6_IFADDR_RLOCK(&in6_ifa_tracker); TAILQ_FOREACH(ia, &V_in6_ifaddrhead, ia_link) { int new_scope = -1, new_matchlen = -1; diff --git a/sys/netinet6/ip6_id.c b/sys/netinet6/ip6_id.c index 5939ae9830c..f41df2a2e5a 100644 --- a/sys/netinet6/ip6_id.c +++ b/sys/netinet6/ip6_id.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: (BSD-3-Clause AND BSD-2-Clause) + * * Copyright (C) 2003 WIDE Project. * All rights reserved. * @@ -30,8 +32,6 @@ */ /*- - * SPDX-License-Identifier: BSD-4-Clause AND BSD-3-Clause - * * Copyright 1998 Niels Provos * All rights reserved. * @@ -48,11 +48,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Niels Provos. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -65,7 +60,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $OpenBSD: ip_id.c,v 1.6 2002/03/15 18:19:52 millert Exp $ + * $OpenBSD: ip6_id.c,v 1.3 2003/12/12 06:57:12 itojun Exp $ */ #include @@ -86,7 +81,7 @@ __FBSDID("$FreeBSD$"); * The transaction id is determined by: * id[n] = seed xor (g^X[n] mod n) * - * Effectivly the id is restricted to the lower (bits - 1) bits, thus + * Effectively the id is restricted to the lower (bits - 1) bits, thus * yielding two different cycles by toggling the msb on and off. * This avoids reuse issues caused by reseeding. */ @@ -177,7 +172,7 @@ pmod(u_int32_t gen, u_int32_t expo, u_int32_t mod) } /* - * Initalizes the seed and chooses a suitable generator. Also toggles + * Initializes the seed and chooses a suitable generator. Also toggles * the msb flag. The msb flag is used to generate two distinct * cycles of random numbers and thus avoiding reuse of ids. * @@ -232,15 +227,12 @@ static u_int32_t randomid(struct randomtab *p) { int i, n; - u_int32_t tmp; if (p->ru_counter >= p->ru_max || time_uptime > p->ru_reseed) initid(p); - tmp = arc4random(); - /* Skip a random number of ids */ - n = tmp & 0x3; tmp = tmp >> 2; + n = arc4random() & 0x3; if (p->ru_counter + n >= p->ru_max) initid(p); @@ -251,7 +243,7 @@ randomid(struct randomtab *p) p->ru_counter += i; - return (p->ru_seed ^ pmod(p->ru_g, p->ru_seed2 ^ p->ru_x, p->ru_n)) | + return (p->ru_seed ^ pmod(p->ru_g, p->ru_seed2 + p->ru_x, p->ru_n)) | p->ru_msb; } diff --git a/sys/netinet6/mld6.c b/sys/netinet6/mld6.c index 37d6c3196a3..805a9f429cb 100644 --- a/sys/netinet6/mld6.c +++ b/sys/netinet6/mld6.c @@ -2286,7 +2286,7 @@ mld_v2_enqueue_group_record(struct mbufq *mq, struct in6_multi *inm, struct ifnet *ifp; struct ip6_msource *ims, *nims; struct mbuf *m0, *m, *md; - int error, is_filter_list_change; + int is_filter_list_change; int minrec0len, m0srcs, msrcs, nbytes, off; int record_has_sources; int now; @@ -2298,7 +2298,6 @@ mld_v2_enqueue_group_record(struct mbufq *mq, struct in6_multi *inm, IN6_MULTI_LOCK_ASSERT(); - error = 0; ifp = inm->in6m_ifp; is_filter_list_change = 0; m = NULL; diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 4c598633045..df4400b49d4 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -2113,7 +2113,7 @@ nd6_cache_lladdr(struct ifnet *ifp, struct in6_addr *from, char *lladdr, LLE_RUNLOCK(ln); if (chain != NULL) - nd6_flush_holdchain(ifp, ifp, chain, &sin6); + nd6_flush_holdchain(ifp, chain, &sin6); /* * When the link-layer address of a router changes, select the @@ -2502,23 +2502,18 @@ nd6_resolve_addr(struct ifnet *ifp, int flags, const struct sockaddr *dst, } int -nd6_flush_holdchain(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *chain, +nd6_flush_holdchain(struct ifnet *ifp, struct mbuf *chain, struct sockaddr_in6 *dst) { struct mbuf *m, *m_head; - struct ifnet *outifp; int error = 0; m_head = chain; - if ((ifp->if_flags & IFF_LOOPBACK) != 0) - outifp = origifp; - else - outifp = ifp; - + while (m_head) { m = m_head; m_head = m_head->m_nextpkt; - error = nd6_output_ifp(ifp, origifp, m, dst, NULL); + error = nd6_output_ifp(ifp, ifp, m, dst, NULL); } /* @@ -2526,7 +2521,7 @@ nd6_flush_holdchain(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *chain * note that intermediate errors are blindly ignored */ return (error); -} +} static int nd6_need_cache(struct ifnet *ifp) diff --git a/sys/netinet6/nd6.h b/sys/netinet6/nd6.h index 30990637cc2..cabfeec0dba 100644 --- a/sys/netinet6/nd6.h +++ b/sys/netinet6/nd6.h @@ -448,7 +448,7 @@ void nd6_cache_lladdr(struct ifnet *, struct in6_addr *, char *, int, int, int); void nd6_grab_holdchain(struct llentry *, struct mbuf **, struct sockaddr_in6 *); -int nd6_flush_holdchain(struct ifnet *, struct ifnet *, struct mbuf *, +int nd6_flush_holdchain(struct ifnet *, struct mbuf *, struct sockaddr_in6 *); int nd6_add_ifa_lle(struct in6_ifaddr *); void nd6_rem_ifa_lle(struct in6_ifaddr *, int); diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index 6766e1b8000..786f6bdbfd5 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -894,7 +894,7 @@ nd6_na_input(struct mbuf *m, int off, int icmp6len) LLE_WUNLOCK(ln); if (chain != NULL) - nd6_flush_holdchain(ifp, ifp, chain, &sin6); + nd6_flush_holdchain(ifp, chain, &sin6); if (checklink) pfxlist_onlink_check(); @@ -1515,17 +1515,11 @@ nd6_dad_ns_output(struct dadq *dp) static void nd6_dad_ns_input(struct ifaddr *ifa, struct nd_opt_nonce *ndopt_nonce) { - struct in6_ifaddr *ia; - struct ifnet *ifp; - const struct in6_addr *taddr6; struct dadq *dp; if (ifa == NULL) panic("ifa == NULL in nd6_dad_ns_input"); - ia = (struct in6_ifaddr *)ifa; - ifp = ifa->ifa_ifp; - taddr6 = &ia->ia_addr.sin6_addr; /* Ignore Nonce option when Enhanced DAD is disabled. */ if (V_dad_enhanced == 0) ndopt_nonce = NULL; diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 0cd7c5c93ec..b27b99098d3 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -339,9 +339,6 @@ rip6_input(struct mbuf **mp, int *offp, int proto) void rip6_ctlinput(int cmd, struct sockaddr *sa, void *d) { - struct ip6_hdr *ip6; - struct mbuf *m; - int off = 0; struct ip6ctlparam *ip6cp = NULL; const struct sockaddr_in6 *sa6_src = NULL; void *cmdarg; @@ -365,14 +362,9 @@ rip6_ctlinput(int cmd, struct sockaddr *sa, void *d) */ if (d != NULL) { ip6cp = (struct ip6ctlparam *)d; - m = ip6cp->ip6c_m; - ip6 = ip6cp->ip6c_ip6; - off = ip6cp->ip6c_off; cmdarg = ip6cp->ip6c_cmdarg; sa6_src = ip6cp->ip6c_src; } else { - m = NULL; - ip6 = NULL; cmdarg = NULL; sa6_src = &sa6_any; } @@ -391,7 +383,6 @@ rip6_output(struct mbuf *m, struct socket *so, ...) struct mbuf *control; struct m_tag *mtag; struct sockaddr_in6 *dstsock; - struct in6_addr *dst; struct ip6_hdr *ip6; struct inpcb *in6p; u_int plen = m->m_pkthdr.len; @@ -413,7 +404,6 @@ rip6_output(struct mbuf *m, struct socket *so, ...) in6p = sotoinpcb(so); INP_WLOCK(in6p); - dst = &dstsock->sin6_addr; if (control != NULL) { if ((error = ip6_setpktopts(control, &opt, in6p->in6p_outputopts, so->so_cred, diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index 1c14bf55157..a8afdf59d17 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -1190,7 +1190,6 @@ udp6_disconnect(struct socket *so) { struct inpcb *inp; struct inpcbinfo *pcbinfo; - int error; pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol); inp = sotoinpcb(so); @@ -1212,8 +1211,8 @@ udp6_disconnect(struct socket *so) #endif if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) { - error = ENOTCONN; - goto out; + INP_WUNLOCK(inp); + return (ENOTCONN); } INP_HASH_WLOCK(pcbinfo); @@ -1223,7 +1222,6 @@ udp6_disconnect(struct socket *so) SOCK_LOCK(so); so->so_state &= ~SS_ISCONNECTED; /* XXX */ SOCK_UNLOCK(so); -out: INP_WUNLOCK(inp); return (0); } diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c index cf198547509..1fd0e8e6c11 100644 --- a/sys/netipsec/key.c +++ b/sys/netipsec/key.c @@ -5744,7 +5744,6 @@ static int key_setident(struct secashead *sah, const struct sadb_msghdr *mhp) { const struct sadb_ident *idsrc, *iddst; - int idsrclen, iddstlen; IPSEC_ASSERT(sah != NULL, ("null secashead")); IPSEC_ASSERT(mhp != NULL, ("null msghdr")); @@ -5766,8 +5765,6 @@ key_setident(struct secashead *sah, const struct sadb_msghdr *mhp) idsrc = (const struct sadb_ident *)mhp->ext[SADB_EXT_IDENTITY_SRC]; iddst = (const struct sadb_ident *)mhp->ext[SADB_EXT_IDENTITY_DST]; - idsrclen = mhp->extlen[SADB_EXT_IDENTITY_SRC]; - iddstlen = mhp->extlen[SADB_EXT_IDENTITY_DST]; /* validity check */ if (idsrc->sadb_ident_type != iddst->sadb_ident_type) { @@ -7464,7 +7461,6 @@ key_dump(struct socket *so, struct mbuf *m, const struct sadb_msghdr *mhp) SAHTREE_RLOCK_TRACKER; struct secashead *sah; struct secasvar *sav; - struct sadb_msg *newmsg; struct mbuf *n; uint32_t cnt; uint8_t proto, satype; @@ -7501,7 +7497,6 @@ key_dump(struct socket *so, struct mbuf *m, const struct sadb_msghdr *mhp) } /* send this to the userland, one at a time. */ - newmsg = NULL; TAILQ_FOREACH(sah, &V_sahtree, chain) { if (mhp->msg->sadb_msg_satype != SADB_SATYPE_UNSPEC && proto != sah->saidx.proto) diff --git a/sys/netipsec/xform_ah.c b/sys/netipsec/xform_ah.c index 5d8c62bb7ff..d6100b6838a 100644 --- a/sys/netipsec/xform_ah.c +++ b/sys/netipsec/xform_ah.c @@ -685,9 +685,7 @@ ah_input_cb(struct cryptop *crp) { IPSEC_DEBUG_DECLARE(char buf[IPSEC_ADDRSTRLEN]); unsigned char calc[AH_ALEN_MAX]; - const struct auth_hash *ahx; struct mbuf *m; - struct cryptodesc *crd; struct xform_data *xd; struct secasvar *sav; struct secasindex *saidx; @@ -696,7 +694,6 @@ ah_input_cb(struct cryptop *crp) int authsize, rplen, error, skip, protoff; uint8_t nxt; - crd = crp->crp_desc; m = (struct mbuf *) crp->crp_buf; xd = (struct xform_data *) crp->crp_opaque; sav = xd->sav; @@ -709,8 +706,6 @@ ah_input_cb(struct cryptop *crp) saidx->dst.sa.sa_family == AF_INET6, ("unexpected protocol family %u", saidx->dst.sa.sa_family)); - ahx = sav->tdb_authalgxform; - /* Check for crypto errors. */ if (crp->crp_etype) { if (crp->crp_etype == EAGAIN) { diff --git a/sys/netipsec/xform_esp.c b/sys/netipsec/xform_esp.c index 02064a909d4..7eaaab6ae3c 100644 --- a/sys/netipsec/xform_esp.c +++ b/sys/netipsec/xform_esp.c @@ -441,7 +441,6 @@ esp_input_cb(struct cryptop *crp) IPSEC_DEBUG_DECLARE(char buf[128]); u_int8_t lastthree[3], aalg[AH_HMAC_MAXHASHLEN]; const struct auth_hash *esph; - const struct enc_xform *espx; struct mbuf *m; struct cryptodesc *crd; struct xform_data *xd; @@ -462,7 +461,6 @@ esp_input_cb(struct cryptop *crp) cryptoid = xd->cryptoid; saidx = &sav->sah->saidx; esph = sav->tdb_authalgxform; - espx = sav->tdb_encalgxform; /* Check for crypto errors */ if (crp->crp_etype) { diff --git a/sys/netipsec/xform_ipcomp.c b/sys/netipsec/xform_ipcomp.c index cfbb78728c7..d5f60b7e214 100644 --- a/sys/netipsec/xform_ipcomp.c +++ b/sys/netipsec/xform_ipcomp.c @@ -274,7 +274,6 @@ static int ipcomp_input_cb(struct cryptop *crp) { IPSEC_DEBUG_DECLARE(char buf[IPSEC_ADDRSTRLEN]); - struct cryptodesc *crd; struct xform_data *xd; struct mbuf *m; struct secasvar *sav; @@ -285,8 +284,6 @@ ipcomp_input_cb(struct cryptop *crp) int skip, protoff; uint8_t nproto; - crd = crp->crp_desc; - m = (struct mbuf *) crp->crp_buf; xd = (struct xform_data *) crp->crp_opaque; sav = xd->sav; diff --git a/sys/nfs/nfs_fha.c b/sys/nfs/nfs_fha.c index 9a534b02539..8c5c144d250 100644 --- a/sys/nfs/nfs_fha.c +++ b/sys/nfs/nfs_fha.c @@ -225,11 +225,9 @@ fha_hash_entry_remove(struct fha_hash_entry *e) static struct fha_hash_entry * fha_hash_entry_lookup(struct fha_params *softc, u_int64_t fh) { - SVCPOOL *pool; struct fha_hash_slot *fhs; struct fha_hash_entry *fhe, *new_fhe; - pool = *softc->pool; fhs = &softc->fha_hash[fh % FHA_HASH_SIZE]; new_fhe = fha_hash_entry_new(fh); new_fhe->mtx = &fhs->mtx; @@ -289,12 +287,9 @@ fha_hash_entry_choose_thread(struct fha_params *softc, struct fha_hash_entry *fhe, struct fha_info *i, SVCTHREAD *this_thread) { SVCTHREAD *thread, *min_thread = NULL; - SVCPOOL *pool; int req_count, min_count = 0; off_t offset1, offset2; - pool = *softc->pool; - LIST_FOREACH(thread, &fhe->threads, st_alink) { req_count = thread->st_p2; @@ -475,17 +470,13 @@ fhe_stats_sysctl(SYSCTL_HANDLER_ARGS, struct fha_params *softc) struct fha_hash_entry *fhe; bool_t first, hfirst; SVCTHREAD *thread; - SVCPOOL *pool; sbuf_new(&sb, NULL, 65536, SBUF_FIXEDLEN); - pool = NULL; - if (!*softc->pool) { sbuf_printf(&sb, "NFSD not running\n"); goto out; } - pool = *softc->pool; for (i = 0; i < FHA_HASH_SIZE; i++) if (!LIST_EMPTY(&softc->fha_hash[i].list)) diff --git a/sys/nlm/nlm_prot_impl.c b/sys/nlm/nlm_prot_impl.c index 0f9c4d485ac..56818c12263 100644 --- a/sys/nlm/nlm_prot_impl.c +++ b/sys/nlm/nlm_prot_impl.c @@ -348,7 +348,6 @@ static CLIENT * nlm_get_rpc(struct sockaddr *sa, rpcprog_t prog, rpcvers_t vers) { char *wchan = "nlmrcv"; - const char* protofmly; struct sockaddr_storage ss; struct socket *so; CLIENT *rpcb; @@ -370,14 +369,11 @@ nlm_get_rpc(struct sockaddr *sa, rpcprog_t prog, rpcvers_t vers) switch (ss.ss_family) { case AF_INET: ((struct sockaddr_in *)&ss)->sin_port = htons(111); - protofmly = "inet"; so = nlm_socket; break; - #ifdef INET6 case AF_INET6: ((struct sockaddr_in6 *)&ss)->sin6_port = htons(111); - protofmly = "inet6"; so = nlm_socket6; break; #endif diff --git a/sys/opencrypto/crypto.c b/sys/opencrypto/crypto.c index f4e71e7189e..8922f71e055 100644 --- a/sys/opencrypto/crypto.c +++ b/sys/opencrypto/crypto.c @@ -994,7 +994,7 @@ kdriver_suitable(const struct cryptocap *cap, const struct cryptkop *krp) static struct cryptocap * crypto_select_kdriver(const struct cryptkop *krp, int flags) { - struct cryptocap *cap, *best, *blocked; + struct cryptocap *cap, *best; int match, hid; CRYPTO_DRIVER_ASSERT(); @@ -1007,7 +1007,6 @@ crypto_select_kdriver(const struct cryptkop *krp, int flags) else match = CRYPTOCAP_F_SOFTWARE; best = NULL; - blocked = NULL; again: for (hid = 0; hid < crypto_drivers_num; hid++) { cap = &crypto_drivers[hid]; diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c index e26390a9b5c..f8b519ff947 100644 --- a/sys/opencrypto/cryptosoft.c +++ b/sys/opencrypto/cryptosoft.c @@ -986,7 +986,6 @@ swcr_freesession_locked(device_t dev, u_int64_t tid) struct swcr_data *swd; struct enc_xform *txf; struct auth_hash *axf; - struct comp_algo *cxf; u_int32_t sid = CRYPTO_SESID2LID(tid); if (sid > swcr_sesnum || swcr_sessions == NULL || @@ -1061,7 +1060,7 @@ swcr_freesession_locked(device_t dev, u_int64_t tid) break; case CRYPTO_DEFLATE_COMP: - cxf = swd->sw_cxf; + /* Nothing to do */ break; } diff --git a/sys/powerpc/booke/locore.S b/sys/powerpc/booke/locore.S index f5e5ddadf7b..b74ee5a2e4d 100644 --- a/sys/powerpc/booke/locore.S +++ b/sys/powerpc/booke/locore.S @@ -114,7 +114,7 @@ __start: * - Switch to temp mapping * - Map 64MB of RAM in TLB1[1] * - Use AS=1, set EPN to KERNBASE and RPN to kernel load address - * - Switch to to TLB1[1] mapping + * - Switch to TLB1[1] mapping * - Invalidate temp mapping * * locore registers use: diff --git a/sys/powerpc/ofw/ofwmagic.S b/sys/powerpc/ofw/ofwmagic.S deleted file mode 100644 index f44f1e5f68d..00000000000 --- a/sys/powerpc/ofw/ofwmagic.S +++ /dev/null @@ -1,68 +0,0 @@ -/* $FreeBSD$ */ -/* $NetBSD: ofwmagic.S,v 1.2 1997/10/09 08:38:18 jtc Exp $ */ - -/*- - * Copyright (c) 1997 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Magic note section used by Open Firmware. - */ - - .section ".note" - - /*# note header */ - - /*# length of name */ - .long 8 - - /*# note descriptor size */ - .long 20 - - /*# note type (IEEE 1275) */ - .long 0x1275 - - /*# name of owner */ - .asciz "PowerPC" - .balign 4 - - - /*# note descriptor */ - - /*# real mode (-1) or virtual mode (0) */ - .long 0 - - /*# real-base */ - .long -1 - /*# real-size */ - .long -1 - - /*# virt-base */ - .long -1 - /*# virt-size */ - .long -1 diff --git a/sys/rpc/clnt_dg.c b/sys/rpc/clnt_dg.c index 8ffa410d587..4c40a494325 100644 --- a/sys/rpc/clnt_dg.c +++ b/sys/rpc/clnt_dg.c @@ -346,7 +346,6 @@ clnt_dg_call( int retransmit_time; int next_sendtime, starttime, rtt, time_waited, tv = 0; struct sockaddr *sa; - socklen_t salen; uint32_t xid = 0; struct mbuf *mreq = NULL, *results; struct cu_request *cr; @@ -398,13 +397,10 @@ clnt_dg_call( } cu->cu_connected = 1; } - if (cu->cu_connected) { + if (cu->cu_connected) sa = NULL; - salen = 0; - } else { + else sa = (struct sockaddr *)&cu->cu_raddr; - salen = cu->cu_rlen; - } time_waited = 0; retrans = 0; if (ext && ext->rc_timers) { diff --git a/sys/security/mac/mac_syscalls.c b/sys/security/mac/mac_syscalls.c index 304d3135918..82623e56137 100644 --- a/sys/security/mac/mac_syscalls.c +++ b/sys/security/mac/mac_syscalls.c @@ -230,7 +230,6 @@ sys___mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) struct pipe *pipe; struct socket *so; cap_rights_t rights; - short label_type; int error; error = copyin(uap->mac_p, &mac, sizeof(mac)); @@ -253,7 +252,6 @@ sys___mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) if (error) goto out; - label_type = fp->f_type; switch (fp->f_type) { case DTYPE_FIFO: case DTYPE_VNODE: diff --git a/sys/sparc64/include/idprom.h b/sys/sparc64/include/idprom.h index e178b68f01f..442b6b32bbf 100644 --- a/sys/sparc64/include/idprom.h +++ b/sys/sparc64/include/idprom.h @@ -1,9 +1,12 @@ /*- - * SPDX-License-Identifier: BSD-4-Clause + * SPDX-License-Identifier: BSD-2-Clause-NetBSD * - * Copyright (c) 1993 Adam Glass + * Copyright (c) 1996 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Adam Glass. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -12,25 +15,20 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Adam Glass. - * 4. The name of the Author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. * - * from: NetBSD: idprom.h,v 1.2 1998/09/05 23:57:26 eeh Exp + * from: NetBSD: idprom.h,v 1.3 2008/04/28 20:23:58 martin Exp * * $FreeBSD$ */ @@ -52,13 +50,14 @@ struct idprom { int id_date; /* date of manufacture */ u_char id_hostid[3]; /* ``host id'' bytes */ u_char id_checksum; /* xor of everything else */ + /* Note: The rest is excluded from the checksum! */ char id_undef[16]; /* undefined */ }; -#define ID_SUN4_100 0x22 -#define ID_SUN4_200 0x21 -#define ID_SUN4_300 0x23 -#define ID_SUN4_400 0x24 +#define ID_SUN4_100 0x22 /* Sun 4/100 */ +#define ID_SUN4_200 0x21 /* Sun 4/200 */ +#define ID_SUN4_300 0x23 /* Sun 4/300 */ +#define ID_SUN4_400 0x24 /* Sun 4/400 */ #define IDPROM_VERSION 1 diff --git a/sys/sparc64/pci/sbbc.c b/sys/sparc64/pci/sbbc.c index dd6b42841ef..f4a100ec562 100644 --- a/sys/sparc64/pci/sbbc.c +++ b/sys/sparc64/pci/sbbc.c @@ -327,7 +327,7 @@ sbbc_pci_attach(device_t dev) int error, rid; uint32_t val; - /* Nothing to to if we're not the chosen one. */ + /* Nothing to do if we're not the chosen one. */ if ((node = OF_finddevice("/chosen")) == -1) { device_printf(dev, "failed to find /chosen\n"); return (ENXIO); diff --git a/sys/sys/_stdarg.h b/sys/sys/_stdarg.h new file mode 100644 index 00000000000..c006a5b851a --- /dev/null +++ b/sys/sys/_stdarg.h @@ -0,0 +1,69 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2002 David E. O'Brien. All rights reserved. + * Copyright (c) 2017 Poul-Henning Kamp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__STDARG_H_ +#define _SYS__STDARG_H_ + +#include +#include + +#ifndef _VA_LIST_DECLARED + #define _VA_LIST_DECLARED + typedef __va_list va_list; +#endif + +#ifdef __GNUCLIKE_BUILTIN_STDARG + #define va_start(ap, last) __builtin_va_start((ap), (last)) + #define va_arg(ap, type) __builtin_va_arg((ap), type) + #define __va_copy(dest, src) __builtin_va_copy((dest), (src)) + #if __ISO_C_VISIBLE >= 1999 + #define va_copy(dest, src) __va_copy(dest, src) + #endif +#define va_end(ap) __builtin_va_end(ap) +#endif + +#if defined(lint) && !defined(va_start) + /* + * Provide a fake implementation for lint's benefit + * This very much assumes that __va_list ends up being a pointer + */ + #define va_start(ap, last) ((void)((ap) = (char *) (&(last)+1))) + #if __ISO_C_VISIBLE >= 1999 + #define va_copy(dst, src) ((dst) = (src)) + #endif + #define va_arg(ap, type) (*(((type)*)(((ap) += sizeof(type)) - sizeof(type)))) + #define va_end(ap) ((void)0) +#endif + +#endif /* ! _SYS__STDARG_H_ */ + diff --git a/sys/sys/chio.h b/sys/sys/chio.h index 47a5a941d83..15d52202374 100644 --- a/sys/sys/chio.h +++ b/sys/sys/chio.h @@ -1,3 +1,5 @@ +/* $NetBSD: chio.h,v 1.9 1997/09/29 17:32:26 mjacob Exp $ */ + /*- * SPDX-License-Identifier: BSD-4-Clause * diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 4af92a8297b..b5f2e7719f4 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -184,6 +184,8 @@ struct td_sched; struct thread; struct trapframe; struct turnstile; +struct vm_map; +struct vm_map_entry; /* * XXX: Does this belong in resource.h or resourcevar.h instead? @@ -1004,6 +1006,8 @@ void fork_exit(void (*)(void *, struct trapframe *), void *, struct trapframe *); void fork_return(struct thread *, struct trapframe *); int inferior(struct proc *p); +void kern_proc_vmmap_resident(struct vm_map *map, struct vm_map_entry *entry, + int *resident_count, bool *super); void kern_yield(int); void kick_proc0(void); void killjobc(void); diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index 3df4f542f21..ccd912ef2db 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause) * * Copyright (c) 2002 Networks Associates Technology, Inc. * All rights reserved. @@ -2414,13 +2414,11 @@ ffs_vfree(pvp, ino, mode) int mode; { struct ufsmount *ump; - struct inode *ip; if (DOINGSOFTDEP(pvp)) { softdep_freefile(pvp, ino, mode); return (0); } - ip = VTOI(pvp); ump = VFSTOUFS(pvp->v_mount); return (ffs_freefile(ump, ump->um_fs, ump->um_devvp, ino, mode, NULL)); } diff --git a/sys/ufs/ffs/ffs_balloc.c b/sys/ufs/ffs/ffs_balloc.c index 02e961a37bb..6143b4fca8c 100644 --- a/sys/ufs/ffs/ffs_balloc.c +++ b/sys/ufs/ffs/ffs_balloc.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause) * * Copyright (c) 2002 Networks Associates Technology, Inc. * All rights reserved. diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index 6b8a3096b86..f10631b773c 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -6903,7 +6903,7 @@ softdep_setup_freeblocks(ip, length, flags) UFS_UNLOCK(ump); DIP_SET(ip, i_blocks, DIP(ip, i_blocks) - datablocks); /* - * Push the zero'ed inode to to its disk buffer so that we are free + * Push the zero'ed inode to its disk buffer so that we are free * to delete its dependencies below. Once the dependencies are gone * the buffer can be safely released. */ diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c index 5ecb49e2f1e..bfee5e972b1 100644 --- a/sys/ufs/ffs/ffs_vnops.c +++ b/sys/ufs/ffs/ffs_vnops.c @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause) * * Copyright (c) 2002, 2003 Networks Associates Technology, Inc. * All rights reserved. @@ -1369,7 +1369,6 @@ vop_deleteextattr { */ { struct inode *ip; - struct fs *fs; struct extattr *eap; uint32_t ul; int olen, error, i, easize; @@ -1377,7 +1376,6 @@ vop_deleteextattr { void *tmp; ip = VTOI(ap->a_vp); - fs = ITOFS(ip); if (ap->a_vp->v_type == VCHR || ap->a_vp->v_type == VBLK) return (EOPNOTSUPP); diff --git a/sys/ufs/ufs/dinode.h b/sys/ufs/ufs/dinode.h index 7b03422676e..0a201ce0b43 100644 --- a/sys/ufs/ufs/dinode.h +++ b/sys/ufs/ufs/dinode.h @@ -1,5 +1,5 @@ /*- - * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * SPDX-License-Identifier: (BSD-2-Clause-FreeBSD AND BSD-3-Clause) * * Copyright (c) 2002 Networks Associates Technology, Inc. * All rights reserved. diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 221559f2d42..90ca0aeddab 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -132,6 +132,9 @@ static int vmspace_zinit(void *mem, int size, int flags); static int vm_map_zinit(void *mem, int ize, int flags); static void _vm_map_init(vm_map_t map, pmap_t pmap, vm_offset_t min, vm_offset_t max); +static int vm_map_alignspace(vm_map_t map, vm_object_t object, + vm_ooffset_t offset, vm_offset_t *addr, vm_size_t length, + vm_offset_t max_addr, vm_offset_t alignment); static void vm_map_entry_deallocate(vm_map_entry_t entry, boolean_t system_map); static void vm_map_entry_dispose(vm_map_t map, vm_map_entry_t entry); static void vm_map_entry_unwire(vm_map_t map, vm_map_entry_t entry); @@ -1483,6 +1486,70 @@ vm_map_fixed(vm_map_t map, vm_object_t object, vm_ooffset_t offset, return (result); } +/* + * Searches for the specified amount of free space in the given map with the + * specified alignment. Performs an address-ordered, first-fit search from + * the given address "*addr", with an optional upper bound "max_addr". If the + * parameter "alignment" is zero, then the alignment is computed from the + * given (object, offset) pair so as to enable the greatest possible use of + * superpage mappings. Returns KERN_SUCCESS and the address of the free space + * in "*addr" if successful. Otherwise, returns KERN_NO_SPACE. + * + * The map must be locked. Initially, there must be at least "length" bytes + * of free space at the given address. + */ +static int +vm_map_alignspace(vm_map_t map, vm_object_t object, vm_ooffset_t offset, + vm_offset_t *addr, vm_size_t length, vm_offset_t max_addr, + vm_offset_t alignment) +{ + vm_offset_t aligned_addr, free_addr; + + VM_MAP_ASSERT_LOCKED(map); + free_addr = *addr; + KASSERT(!vm_map_findspace(map, free_addr, length, addr) && + free_addr == *addr, ("caller provided insufficient free space")); + for (;;) { + /* + * At the start of every iteration, the free space at address + * "*addr" is at least "length" bytes. + */ + if (alignment == 0) + pmap_align_superpage(object, offset, addr, length); + else if ((*addr & (alignment - 1)) != 0) { + *addr &= ~(alignment - 1); + *addr += alignment; + } + aligned_addr = *addr; + if (aligned_addr == free_addr) { + /* + * Alignment did not change "*addr", so "*addr" must + * still provide sufficient free space. + */ + return (KERN_SUCCESS); + } + + /* + * Test for address wrap on "*addr". A wrapped "*addr" could + * be a valid address, in which case vm_map_findspace() cannot + * be relied upon to fail. + */ + if (aligned_addr < free_addr || + vm_map_findspace(map, aligned_addr, length, addr) || + (max_addr != 0 && *addr + length > max_addr)) + return (KERN_NO_SPACE); + free_addr = *addr; + if (free_addr == aligned_addr) { + /* + * If a successful call to vm_map_findspace() did not + * change "*addr", then "*addr" must still be aligned + * and provide sufficient free space. + */ + return (KERN_SUCCESS); + } + } +} + /* * vm_map_find finds an unallocated region in the target address * map with the given length. The search is defined to be @@ -1498,8 +1565,8 @@ vm_map_find(vm_map_t map, vm_object_t object, vm_ooffset_t offset, vm_size_t length, vm_offset_t max_addr, int find_space, vm_prot_t prot, vm_prot_t max, int cow) { - vm_offset_t alignment, initial_addr, start; - int result; + vm_offset_t alignment, min_addr; + int rv; KASSERT((cow & (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP)) == 0 || object == NULL, @@ -1512,50 +1579,39 @@ vm_map_find(vm_map_t map, vm_object_t object, vm_ooffset_t offset, alignment = (vm_offset_t)1 << (find_space >> 8); } else alignment = 0; - initial_addr = *addr; vm_map_lock(map); + if (find_space != VMFS_NO_SPACE) { + KASSERT(find_space == VMFS_ANY_SPACE || + find_space == VMFS_OPTIMAL_SPACE || + find_space == VMFS_SUPER_SPACE || + alignment != 0, ("unexpected VMFS flag")); + min_addr = *addr; again: - start = initial_addr; - do { - if (find_space != VMFS_NO_SPACE) { - if (vm_map_findspace(map, start, length, addr) || - (max_addr != 0 && *addr + length > max_addr)) { - if (find_space == VMFS_OPTIMAL_SPACE) { - find_space = VMFS_ANY_SPACE; - goto again; - } - vm_map_unlock(map); - return (KERN_NO_SPACE); - } - switch (find_space) { - case VMFS_SUPER_SPACE: - case VMFS_OPTIMAL_SPACE: - pmap_align_superpage(object, offset, addr, - length); - break; - case VMFS_ANY_SPACE: - break; - default: - if ((*addr & (alignment - 1)) != 0) { - *addr &= ~(alignment - 1); - *addr += alignment; - } - break; - } - - start = *addr; + if (vm_map_findspace(map, min_addr, length, addr) || + (max_addr != 0 && *addr + length > max_addr)) { + rv = KERN_NO_SPACE; + goto done; } - if ((cow & (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP)) != 0) { - result = vm_map_stack_locked(map, start, length, - sgrowsiz, prot, max, cow); - } else { - result = vm_map_insert(map, object, offset, start, - start + length, prot, max, cow); + if (find_space != VMFS_ANY_SPACE && + (rv = vm_map_alignspace(map, object, offset, addr, length, + max_addr, alignment)) != KERN_SUCCESS) { + if (find_space == VMFS_OPTIMAL_SPACE) { + find_space = VMFS_ANY_SPACE; + goto again; + } + goto done; } - } while (result == KERN_NO_SPACE && find_space != VMFS_NO_SPACE && - find_space != VMFS_ANY_SPACE); + } + if ((cow & (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP)) != 0) { + rv = vm_map_stack_locked(map, *addr, length, sgrowsiz, prot, + max, cow); + } else { + rv = vm_map_insert(map, object, offset, *addr, *addr + length, + prot, max, cow); + } +done: vm_map_unlock(map); - return (result); + return (rv); } /* diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c index f821150316f..01be7db38a9 100644 --- a/sys/vm/vm_object.c +++ b/sys/vm/vm_object.c @@ -148,13 +148,24 @@ struct vm_object kernel_object_store; static SYSCTL_NODE(_vm_stats, OID_AUTO, object, CTLFLAG_RD, 0, "VM object stats"); -static long object_collapses; -SYSCTL_LONG(_vm_stats_object, OID_AUTO, collapses, CTLFLAG_RD, - &object_collapses, 0, "VM object collapses"); +static counter_u64_t object_collapses = EARLY_COUNTER; +SYSCTL_COUNTER_U64(_vm_stats_object, OID_AUTO, collapses, CTLFLAG_RD, + &object_collapses, + "VM object collapses"); -static long object_bypasses; -SYSCTL_LONG(_vm_stats_object, OID_AUTO, bypasses, CTLFLAG_RD, - &object_bypasses, 0, "VM object bypasses"); +static counter_u64_t object_bypasses = EARLY_COUNTER; +SYSCTL_COUNTER_U64(_vm_stats_object, OID_AUTO, bypasses, CTLFLAG_RD, + &object_bypasses, + "VM object bypasses"); + +static void +counter_startup(void) +{ + + object_collapses = counter_u64_alloc(M_WAITOK); + object_bypasses = counter_u64_alloc(M_WAITOK); +} +SYSINIT(object_counters, SI_SUB_CPU, SI_ORDER_ANY, counter_startup, NULL); static uma_zone_t obj_zone; @@ -1875,7 +1886,7 @@ vm_object_collapse(vm_object_t object) vm_object_destroy(backing_object); vm_object_pip_wakeup(object); - object_collapses++; + counter_u64_add(object_collapses, 1); } else { /* * If we do not entirely shadow the backing object, @@ -1916,7 +1927,7 @@ vm_object_collapse(vm_object_t object) */ backing_object->ref_count--; VM_OBJECT_WUNLOCK(backing_object); - object_bypasses++; + counter_u64_add(object_bypasses, 1); } /* diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c index 5a8033fb2e5..43c417ffe3a 100644 --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -1836,6 +1836,8 @@ vm_pageout_worker(void *arg) */ if (vm_pages_needed) { mtx_unlock(&vm_page_queue_free_mtx); + if (pass == 0) + pass++; } else if (mtx_sleep(&vm_pageout_wanted, &vm_page_queue_free_mtx, PDROP | PVM, "psleep", hz) == 0) { diff --git a/sys/vm/vm_swapout.c b/sys/vm/vm_swapout.c index e3e8b8966d7..f76ecf92b71 100644 --- a/sys/vm/vm_swapout.c +++ b/sys/vm/vm_swapout.c @@ -263,7 +263,7 @@ vm_swapout_map_deactivate_pages(vm_map_t map, long desired) vm_object_t obj, bigobj; int nothingwired; - if (!vm_map_trylock(map)) + if (!vm_map_trylock_read(map)) return; bigobj = NULL; @@ -327,7 +327,7 @@ vm_swapout_map_deactivate_pages(vm_map_t map, long desired) vm_map_max(map)); } - vm_map_unlock(map); + vm_map_unlock_read(map); } /* @@ -715,8 +715,7 @@ swapper(void) } /* - * We would like to bring someone in. (only if there is space). - * [What checks the space? ] + * We would like to bring someone in. */ faultin(p); PROC_UNLOCK(p); diff --git a/sys/x86/include/stdarg.h b/sys/x86/include/stdarg.h index ec73e4f42cc..acb526429ac 100644 --- a/sys/x86/include/stdarg.h +++ b/sys/x86/include/stdarg.h @@ -1,7 +1,7 @@ /*- - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: BSD-2-Clause * - * Copyright (c) 2002 David E. O'Brien. All rights reserved. + * Copyright (c) 2017 Poul-Henning Kamp. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -11,9 +11,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -33,35 +30,10 @@ #ifndef _MACHINE_STDARG_H_ #define _MACHINE_STDARG_H_ -#include -#include +#include -#ifndef _VA_LIST_DECLARED -#define _VA_LIST_DECLARED -typedef __va_list va_list; -#endif - -#ifdef __GNUCLIKE_BUILTIN_STDARG - -#define va_start(ap, last) \ - __builtin_va_start((ap), (last)) - -#define va_arg(ap, type) \ - __builtin_va_arg((ap), type) - -#define __va_copy(dest, src) \ - __builtin_va_copy((dest), (src)) - -#if __ISO_C_VISIBLE >= 1999 -#define va_copy(dest, src) \ - __va_copy(dest, src) -#endif - -#define va_end(ap) \ - __builtin_va_end(ap) - -#else -#error this file needs to be ported to your compiler +#ifndef va_start + #error this file needs to be ported to your compiler #endif #endif /* !_MACHINE_STDARG_H_ */ diff --git a/sys/x86/x86/io_apic.c b/sys/x86/x86/io_apic.c index 45e36e7fd7e..f2ec8c71e2f 100644 --- a/sys/x86/x86/io_apic.c +++ b/sys/x86/x86/io_apic.c @@ -308,7 +308,7 @@ static void ioapic_program_intpin(struct ioapic_intsrc *intpin) { struct ioapic *io = (struct ioapic *)intpin->io_intsrc.is_pic; - uint32_t low, high, value; + uint32_t low, high; #ifdef ACPI_DMAR int error; #endif @@ -354,7 +354,11 @@ ioapic_program_intpin(struct ioapic_intsrc *intpin) } #endif - /* Set the destination. */ + /* + * Set the destination. Note that with Intel interrupt remapping, + * the previously reserved bits 55:48 now have a purpose so ensure + * these are zero. + */ low = IOART_DESTPHY; high = intpin->io_cpu << APIC_ID_SHIFT; @@ -392,10 +396,7 @@ ioapic_program_intpin(struct ioapic_intsrc *intpin) } /* Write the values to the APIC. */ - value = ioapic_read(io->io_addr, IOAPIC_REDTBL_HI(intpin->io_intpin)); - value &= ~IOART_DEST; - value |= high; - ioapic_write(io->io_addr, IOAPIC_REDTBL_HI(intpin->io_intpin), value); + ioapic_write(io->io_addr, IOAPIC_REDTBL_HI(intpin->io_intpin), high); intpin->io_lowreg = low; ioapic_write(io->io_addr, IOAPIC_REDTBL_LO(intpin->io_intpin), low); } diff --git a/tests/sys/fifo/fifo_io.c b/tests/sys/fifo/fifo_io.c index 93d4be7e2f1..667bb7bb6dc 100644 --- a/tests/sys/fifo/fifo_io.c +++ b/tests/sys/fifo/fifo_io.c @@ -1178,7 +1178,7 @@ test_events_write_read_byte(void) } /* - * Read the byte from the reader_fd, and now confirm that that fifo + * Read the byte from the reader_fd, and now confirm that the fifo * becomes unreadable. */ len = read(reader_fd, &ch, sizeof(ch)); diff --git a/tests/sys/kern/ptrace_test.c b/tests/sys/kern/ptrace_test.c index 2d8524317f3..694a3b4044e 100644 --- a/tests/sys/kern/ptrace_test.c +++ b/tests/sys/kern/ptrace_test.c @@ -2958,7 +2958,7 @@ ATF_TC_BODY(ptrace__PT_CONTINUE_with_sigmask, tc) /* * Verify that if ptrace stops due to a signal but continues with * a different signal that the new signal is routed to a thread - * that can accept it, and that that thread is awakened by the signal + * that can accept it, and that the thread is awakened by the signal * in a timely manner. */ ATF_TC_WITHOUT_HEAD(ptrace__PT_CONTINUE_with_signal_thread_sigmask); diff --git a/tools/regression/bpf/bpf_filter/bpf_test.c b/tools/regression/bpf/bpf_filter/bpf_test.c index 9ed4828ea3e..b62ca774d21 100644 --- a/tools/regression/bpf/bpf_filter/bpf_test.c +++ b/tools/regression/bpf/bpf_filter/bpf_test.c @@ -149,7 +149,7 @@ bpf_validate(const struct bpf_insn *f, int len) if (!BPF_VALIDATE_CODE(p->code)) return (0); /* - * Check that that jumps are forward, and within + * Check that jumps are forward, and within * the code block. */ if (BPF_CLASS(p->code) == BPF_JMP) { diff --git a/usr.bin/column/column.c b/usr.bin/column/column.c index aa92742a0de..a253d24ca1b 100644 --- a/usr.bin/column/column.c +++ b/usr.bin/column/column.c @@ -270,7 +270,12 @@ maketbl(void) (void)wprintf(L"%ls%*ls", t->list[coloff], lens[coloff] - t->len[coloff] + 2, L" "); (void)wprintf(L"%ls\n", t->list[coloff]); + free(t->list); + free(t->len); } + free(lens); + free(cols); + free(tbl); } #define DEFNUM 1000 diff --git a/usr.bin/localedef/ctype.c b/usr.bin/localedef/ctype.c index 3133d2462b3..abeea019462 100644 --- a/usr.bin/localedef/ctype.c +++ b/usr.bin/localedef/ctype.c @@ -224,7 +224,7 @@ add_ctype_range(wchar_t end) * A word about widths: if the width mask is specified, then libc * unconditionally honors it. Otherwise, it assumes printable * characters have width 1, and non-printable characters have width - * -1 (except for NULL which is special with with 0). Hence, we have + * -1 (except for NULL which is special with width 0). Hence, we have * no need to inject defaults here -- the "default" unset value of 0 * indicates that libc should use its own logic in wcwidth as described. */ diff --git a/usr.bin/mail/cmd3.c b/usr.bin/mail/cmd3.c index 71df59bfea5..68afbaa5691 100644 --- a/usr.bin/mail/cmd3.c +++ b/usr.bin/mail/cmd3.c @@ -261,7 +261,7 @@ dorespond(int *msgvec) } /* - * Modify the subject we are replying to to begin with Re: if + * Modify the message subject to begin with "Re:" if * it does not already. */ char * diff --git a/usr.bin/mail/collect.c b/usr.bin/mail/collect.c index 0eacac1daf9..d56f460a869 100644 --- a/usr.bin/mail/collect.c +++ b/usr.bin/mail/collect.c @@ -133,7 +133,6 @@ collect(struct header *hp, int printheaders) escape = ESCAPE; eofcount = 0; hadintr = 0; - lastlong = 0; longline = 0; if (!setjmp(colljmp)) { diff --git a/usr.bin/mail/names.c b/usr.bin/mail/names.c index b6cde21ce9d..9e08b0870c5 100644 --- a/usr.bin/mail/names.c +++ b/usr.bin/mail/names.c @@ -575,7 +575,7 @@ unpack(struct name *np) extra++; top = (char **)salloc((t + extra) * sizeof(*top)); ap = top; - *ap++ = "send-mail"; + *ap++ = "sendmail"; *ap++ = "-i"; if (metoo) *ap++ = "-m"; diff --git a/usr.bin/msgs/msgs.c b/usr.bin/msgs/msgs.c index 6bd6a56fd9e..f7a18e1682c 100644 --- a/usr.bin/msgs/msgs.c +++ b/usr.bin/msgs/msgs.c @@ -804,6 +804,7 @@ ask(const char *prompt) mailing = NO; fseeko(newmsg, oldpos, SEEK_SET); ask(prompt); + fclose(cpfrom); return; } diff --git a/usr.bin/rpcgen/rpc_main.c b/usr.bin/rpcgen/rpc_main.c index 78bc610ae8e..34755349d21 100644 --- a/usr.bin/rpcgen/rpc_main.c +++ b/usr.bin/rpcgen/rpc_main.c @@ -484,7 +484,9 @@ generate_guard(const char *pathname) ; strcpy(guard, tmp); } + tmp = guard; guard = extendfile(guard, "_H_RPCGEN"); + free(tmp); return (guard); } @@ -502,13 +504,14 @@ h_output(const char *infile, const char *define, int extend, const char *outfile const char *guard; list *l; xdrfunc *xdrfuncp; + void *tmp = NULL; open_input(infile, define); outfilename = extend ? extendfile(infile, outfile) : outfile; open_output(infile, outfilename); add_warning(); if (outfilename || infile){ - guard = generate_guard(outfilename ? outfilename: infile); + guard = tmp = generate_guard(outfilename ? outfilename: infile); } else guard = "STDIN_"; @@ -574,6 +577,7 @@ h_output(const char *infile, const char *define, int extend, const char *outfile f_print(fout, "#endif\n"); f_print(fout, "\n#endif /* !_%s */\n", guard); + free(tmp); } /* diff --git a/usr.bin/rpcgen/rpc_parse.c b/usr.bin/rpcgen/rpc_parse.c index 9f880333789..0081106f851 100644 --- a/usr.bin/rpcgen/rpc_parse.c +++ b/usr.bin/rpcgen/rpc_parse.c @@ -93,6 +93,7 @@ get_definition(void) def_const(defp); break; case TOK_EOF: + free(defp); return (NULL); default: error("definition keyword expected"); diff --git a/usr.bin/rpcgen/rpc_scan.c b/usr.bin/rpcgen/rpc_scan.c index bdbeec0f2d0..49466bd1884 100644 --- a/usr.bin/rpcgen/rpc_scan.c +++ b/usr.bin/rpcgen/rpc_scan.c @@ -490,6 +490,7 @@ docppline(char *line, int *lineno, const char **fname) *p = 0; if (*file == 0) { *fname = NULL; + free(file); } else { *fname = file; } diff --git a/usr.bin/showmount/showmount.c b/usr.bin/showmount/showmount.c index cab91b0045d..5543f5a9248 100644 --- a/usr.bin/showmount/showmount.c +++ b/usr.bin/showmount/showmount.c @@ -279,11 +279,15 @@ xdr_mntdump(XDR *xdrsp, struct mountlist **mlp) return (0); mp->ml_left = mp->ml_right = (struct mountlist *)0; strp = mp->ml_host; - if (!xdr_string(xdrsp, &strp, MNTNAMLEN)) + if (!xdr_string(xdrsp, &strp, MNTNAMLEN)) { + free(mp); return (0); + } strp = mp->ml_dirp; - if (!xdr_string(xdrsp, &strp, MNTPATHLEN)) + if (!xdr_string(xdrsp, &strp, MNTPATHLEN)) { + free(mp); return (0); + } /* * Build a binary tree on sorted order of either host or dirp. diff --git a/usr.bin/tcopy/tcopy.c b/usr.bin/tcopy/tcopy.c index 85645c43257..24dcc969a9a 100644 --- a/usr.bin/tcopy/tcopy.c +++ b/usr.bin/tcopy/tcopy.c @@ -263,6 +263,7 @@ r2: if (inn != outn) { if (!inn) { if (eot++) { fprintf(msg, "tcopy: tapes are identical.\n"); + free(inb); return; } } else { diff --git a/usr.bin/wall/wall.c b/usr.bin/wall/wall.c index 9f4c8a86101..a02f103cb80 100644 --- a/usr.bin/wall/wall.c +++ b/usr.bin/wall/wall.c @@ -290,5 +290,5 @@ makemsg(char *fname) err(1, "out of memory"); if ((int)fread(mbuf, sizeof(*mbuf), mbufsize, fp) != mbufsize) err(1, "can't read temporary file"); - (void)close(fd); + fclose(fp); } diff --git a/usr.bin/xargs/strnsubst.c b/usr.bin/xargs/strnsubst.c index 304e47bdf3f..d826d33c096 100644 --- a/usr.bin/xargs/strnsubst.c +++ b/usr.bin/xargs/strnsubst.c @@ -37,7 +37,7 @@ strnsubst(char **str, const char *match, const char *replstr, size_t maxsize) if (s1 == NULL) return; /* - * If maxsize is 0 then set it to to the length of s1, because we have + * If maxsize is 0 then set it to the length of s1, because we have * to duplicate s1. XXX we maybe should double-check whether the match * appears in s1. If it doesn't, then we also have to set the length * to the length of s1, to avoid modifying the argument. It may make diff --git a/usr.sbin/Makefile b/usr.sbin/Makefile index 5ef0313984a..60c839d945f 100644 --- a/usr.sbin/Makefile +++ b/usr.sbin/Makefile @@ -21,6 +21,7 @@ SUBDIR= adduser \ dconschat \ devctl \ devinfo \ + devmatch \ digictl \ diskinfo \ dumpcis \ diff --git a/usr.sbin/binmiscctl/binmiscctl.c b/usr.sbin/binmiscctl/binmiscctl.c index 98e92adb3ac..a516465332b 100644 --- a/usr.sbin/binmiscctl/binmiscctl.c +++ b/usr.sbin/binmiscctl/binmiscctl.c @@ -299,10 +299,12 @@ add_cmd(__unused int argc, char *argv[], ximgact_binmisc_entry_t *xbe) break; case 'm': + free(magic); magic = strdup(optarg); break; case 'M': + free(mask); mask = strdup(optarg); xbe->xbe_flags |= IBF_USE_MASK; break; diff --git a/usr.sbin/bsdinstall/partedit/gpart_ops.c b/usr.sbin/bsdinstall/partedit/gpart_ops.c index e646f305066..6ceccaf1200 100644 --- a/usr.sbin/bsdinstall/partedit/gpart_ops.c +++ b/usr.sbin/bsdinstall/partedit/gpart_ops.c @@ -942,7 +942,9 @@ add_boot_partition(struct ggeom *geom, struct gprovider *pp, choice = 0; if (choice == 0) { /* yes */ + struct partition_metadata *md; const char *bootmount = NULL; + char *bootpartname = NULL; char sizestr[7]; humanize_number(sizestr, 7, @@ -950,7 +952,21 @@ add_boot_partition(struct ggeom *geom, struct gprovider *pp, HN_NOSPACE | HN_DECIMAL); gpart_create(pp, bootpart_type(scheme, &bootmount), - sizestr, bootmount, NULL, 0); + sizestr, bootmount, &bootpartname, 0); + + if (bootpartname == NULL) /* Error reported to user already */ + return 0; + + /* If the part is not mountable, make sure newfs isn't set */ + if (bootmount == NULL) { + md = get_part_metadata(bootpartname, 0); + if (md != NULL && md->newfs != NULL) { + free(md->newfs); + md->newfs = NULL; + } + } + + free(bootpartname); return (bootpart_size(scheme)); } diff --git a/usr.sbin/btxld/btxld.c b/usr.sbin/btxld/btxld.c index d18c9fcb261..931a224fe99 100644 --- a/usr.sbin/btxld/btxld.c +++ b/usr.sbin/btxld/btxld.c @@ -189,7 +189,7 @@ static void cleanup(void) { if (tname) - remove(tname); + (void)remove(tname); } /* @@ -287,6 +287,7 @@ btxld(const char *iname) err(2, "%s", tname); if (rename(tname, oname)) err(2, "%s: Can't rename to %s", tname, oname); + free((void*)(intptr_t)tname); tname = NULL; if (verbose) { printf(binfo, btx.btx_majver, btx.btx_minver, btx.btx_textsz, diff --git a/usr.sbin/cpucontrol/intel.c b/usr.sbin/cpucontrol/intel.c index d7bfd27f6c3..7eca224e1ee 100644 --- a/usr.sbin/cpucontrol/intel.c +++ b/usr.sbin/cpucontrol/intel.c @@ -88,7 +88,7 @@ intel_update(const char *dev, const char *path) intel_fw_header_t *fw_header; intel_cpu_signature_t *ext_table; intel_ext_header_t *ext_header; - uint32_t signature, flags; + uint32_t sig, signature, flags; int32_t revision; ssize_t ext_size; size_t ext_table_size; @@ -147,7 +147,7 @@ intel_update(const char *dev, const char *path) fd = open(path, O_RDONLY, 0); if (fd < 0) { WARN(0, "open(%s)", path); - return; + goto fail; } error = fstat(fd, &st); if (error != 0) { @@ -231,7 +231,8 @@ intel_update(const char *dev, const char *path) for (i = 0; i < (ext_table_size / sizeof(uint32_t)); i++) sum += *((uint32_t *)ext_header + i); if (sum != 0) { - WARNX(2, "%s: extended signature table checksum invalid", + WARNX(2, + "%s: extended signature table checksum invalid", path); goto no_table; } @@ -246,10 +247,10 @@ intel_update(const char *dev, const char *path) */ if (signature == fw_header->cpu_signature && (flags & fw_header->cpu_flags) != 0) - goto matched; + goto matched; else if (have_ext_table != 0) { for (i = 0; i < ext_header->sig_count; i++) { - uint32_t sig = ext_table[i].cpu_signature; + sig = ext_table[i].cpu_signature; if (signature == sig && (flags & ext_table[i].cpu_flags) != 0) goto matched; @@ -261,17 +262,17 @@ intel_update(const char *dev, const char *path) if (revision >= fw_header->revision) { WARNX(1, "skipping %s of rev %#x: up to date", path, fw_header->revision); - return; + goto fail; } fprintf(stderr, "%s: updating cpu %s from rev %#x to rev %#x... ", - path, dev, revision, fw_header->revision); + path, dev, revision, fw_header->revision); args.data = fw_data; args.size = data_size; error = ioctl(devfd, CPUCTL_UPDATE, &args); if (error < 0) { - error = errno; + error = errno; fprintf(stderr, "failed.\n"); - errno = error; + errno = error; WARN(0, "ioctl()"); goto fail; } @@ -285,5 +286,4 @@ intel_update(const char *dev, const char *path) close(devfd); if (fd >= 0) close(fd); - return; } diff --git a/usr.sbin/cpucontrol/via.c b/usr.sbin/cpucontrol/via.c index 63d814c5503..354817edf85 100644 --- a/usr.sbin/cpucontrol/via.c +++ b/usr.sbin/cpucontrol/via.c @@ -140,7 +140,7 @@ via_update(const char *dev, const char *path) fd = open(path, O_RDONLY, 0); if (fd < 0) { WARN(0, "open(%s)", path); - return; + goto fail; } error = fstat(fd, &st); if (error != 0) { diff --git a/usr.sbin/ctld/login.c b/usr.sbin/ctld/login.c index b2d8f05f5f6..ed253ce568b 100644 --- a/usr.sbin/ctld/login.c +++ b/usr.sbin/ctld/login.c @@ -748,7 +748,7 @@ login_negotiate(struct connection *conn, struct pdu *request) /* * RFC 3720, 10.13.5. Status-Class and Status-Detail, says * the redirection SHOULD be accepted by the initiator before - * authentication, but MUST be be accepted afterwards; that's + * authentication, but MUST be accepted afterwards; that's * why we're doing it here and not earlier. */ redirected = login_target_redirect(conn, request); diff --git a/usr.sbin/devmatch/Makefile b/usr.sbin/devmatch/Makefile new file mode 100644 index 00000000000..6622bdb284d --- /dev/null +++ b/usr.sbin/devmatch/Makefile @@ -0,0 +1,8 @@ +# $FreeBSD$ + +PROG= devmatch +MAN= devmatch.8 + +LIBADD= devinfo + +.include diff --git a/usr.sbin/devmatch/devmatch.8 b/usr.sbin/devmatch/devmatch.8 new file mode 100644 index 00000000000..369b1c91a5b --- /dev/null +++ b/usr.sbin/devmatch/devmatch.8 @@ -0,0 +1,85 @@ +.\" +.\" Copyright (c) 2017 Netflix, Inc +.\" +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd December 25, 2017 +.Dt DEVMATCH 8 +.Os +.Sh NAME +.Nm devinfo +.Nd print information about unattached devices +.Sh SYNOPSIS +.Nm +.Op Fl aduv +.Op Fl -all +.Op Fl -dump +.Op Fl -unbound +.Op Fl -verbose +.Sh DESCRIPTION +The +.Nm +utility, without any arguments, prints all the kernel modules it has +found for all the unattached, enabled devices in the system. +.Bl -tag -width 20m +.It Fl a Fl -all +Include all devices, not just the ones that are unattached. +.It Fl d Fl -dump +Produce a human readable dump of the +.Pa linker.hints +file. +.It Fl u Fl -unbound +Attempt to produce a list of those drivers with PNP info whose driver +tables with that PNP info can't be found. +.It Fl v Fl -verbose +Produce more verbose output. +.El +.Sh SEE ALSO +.Xr devinfo 8 +.Sh BUGS +The kernel has hints in it, but we exclude it from the list of modules +to suggest for unmatched devices. +We exclude it when suggesting drivers, but include it when looking for +unbound devices or producing a full dump of +.Pa linker.hints . +This can be confusing. +.Pp +Some modules are hard links in +.Pa /boot/kernel +and will be reported twice. +.Pp +The PNP string's attributes are evaluated once per PNP entry on that +bus rather than once. +.Pp +The term PNP is overloaded in FreeBSD. +It means, generically, the identifying data the bus provides about a +device. +While this include old ISA PNP identifiers, it also includes the +logical equivalent in USB, PCI, and others. +.Pp +Many drivers currently lack proper PNP table decorations and need to +be updated. +.Sh AUTHORS +.An Warner Losh Aq Mt imp@FreeBSD.org diff --git a/usr.sbin/devmatch/devmatch.c b/usr.sbin/devmatch/devmatch.c new file mode 100644 index 00000000000..9efeb9377ac --- /dev/null +++ b/usr.sbin/devmatch/devmatch.c @@ -0,0 +1,431 @@ +/*- + * Copyright (c) 2017 Netflix, Inc + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* options descriptor */ +static struct option longopts[] = { + { "all", no_argument, NULL, 'a' }, + { "dump", no_argument, NULL, 'd' }, + { "unbound", no_argument, NULL, 'u' }, + { "verbose", no_argument, NULL, 'v' }, + { NULL, 0, NULL, 0 } +}; + +static int all_flag; +static int dump_flag; +static int unbound_flag; +static int verbose_flag; + +static void *hints; +static void *hints_end; + +static void +read_linker_hints(void) +{ + char fn[MAXPATHLEN]; + struct stat sb; + char *modpath, *p, *q; + size_t buflen; + int fd; + + if (sysctlbyname("kern.module_path", NULL, &buflen, NULL, 0) < 0) + errx(1, "Can't find kernel module path."); + modpath = malloc(buflen); + if (modpath == NULL) + err(1, "Can't get memory for modpath."); + if (sysctlbyname("kern.module_path", modpath, &buflen, NULL, 0) < 0) + errx(1, "Can't find kernel module path."); + p = modpath; + while ((q = strsep(&p, ";")) != NULL) { + snprintf(fn, sizeof(fn), "%s/linker.hints", q); + fd = open(fn, O_RDONLY); + if (fd < 0) { + if (errno == ENOENT) + continue; + err(1, "Can't open %s for reading", fn); + } + if (fstat(fd, &sb) != 0) + err(1, "Can't fstat %s\n", fn); + hints = malloc(sb.st_size); + if (hints == NULL) + err(1, "not enough space to read hints file of %ju bytes", (uintmax_t)sb.st_size); + if (read(fd, hints, sb.st_size) != sb.st_size) + err(1, "Can't read in %ju bytes from %s", (uintmax_t)sb.st_size, fn); + close(fd); + break; + } + if (q == NULL) { + warnx("Can't read linker hints file."); + free(hints); + hints = NULL; + return; + } + if (*(int *)(intptr_t)hints != LINKER_HINTS_VERSION) { + warnx("Linker hints version %d doesn't match expected %d.", + *(int *)(intptr_t)hints, LINKER_HINTS_VERSION); + free(hints); + hints = NULL; + } + if (hints != NULL) + hints_end = (void *)((intptr_t)hints + (intptr_t)sb.st_size); +} + +static int +getint(void **ptr) +{ + int *p = *ptr; + int rv; + + p = (int *)roundup2((intptr_t)p, sizeof(int)); + rv = *p++; + *ptr = p; + return rv; +} + +static void +getstr(void **ptr, char *val) +{ + int *p = *ptr; + char *c = (char *)p; + int len = *(uint8_t *)c; + + memcpy(val, c + 1, len); + val[len] = 0; + c += len + 1; + *ptr = (void *)c; +} + +static int +pnpval_as_int(const char *val, const char *pnpinfo) +{ + int rv; + char key[256]; + char *cp; + + if (pnpinfo == NULL) + return -1; + + cp = strchr(val, ';'); + key[0] = ' '; + if (cp == NULL) + strlcpy(key + 1, val, sizeof(key) - 1); + else { + memcpy(key + 1, val, cp - val); + key[cp - val + 1] = '\0'; + } + strlcat(key, "=", sizeof(key)); + if (strncmp(key + 1, pnpinfo, strlen(key + 1)) == 0) + rv = strtol(pnpinfo + strlen(key + 1), NULL, 0); + else { + cp = strstr(pnpinfo, key); + if (cp == NULL) + rv = -1; + else + rv = strtol(cp + strlen(key), NULL, 0); + } + return rv; +} + +static void +quoted_strcpy(char *dst, const char *src) +{ + char q = ' '; + + if (*src == '\'' || *src == '"') + q = *src++; + while (*src && *src != q) + *dst++ = *src++; // XXX backtick quoting + *dst++ = '\0'; + // XXX overflow +} + +static char * +pnpval_as_str(const char *val, const char *pnpinfo) +{ + static char retval[256]; + char key[256]; + char *cp; + + if (pnpinfo == NULL) { + *retval = '\0'; + return retval; + } + + cp = strchr(val, ';'); + key[0] = ' '; + if (cp == NULL) + strlcpy(key + 1, val, sizeof(key) - 1); + else { + memcpy(key + 1, val, cp - val); + key[cp - val + 1] = '\0'; + } + strlcat(key, "=", sizeof(key)); + if (strncmp(key + 1, pnpinfo, strlen(key + 1)) == 0) + quoted_strcpy(retval, pnpinfo + strlen(key + 1)); + else { + cp = strstr(pnpinfo, key); + if (cp == NULL) + strcpy(retval, "MISSING"); + else + quoted_strcpy(retval, cp + strlen(key)); + } + return retval; +} + +static void +search_hints(const char *bus, const char *dev, const char *pnpinfo) +{ + char val1[256], val2[256]; + int ival, len, ents, i, notme, mask, bit, v, found; + void *ptr, *walker; + char *lastmod = NULL, *cp, *s; + + walker = hints; + getint(&walker); + found = 0; + while (walker < hints_end) { + len = getint(&walker); + ival = getint(&walker); + ptr = walker; + switch (ival) { + case MDT_VERSION: + getstr(&ptr, val1); + ival = getint(&ptr); + getstr(&ptr, val2); + if (dump_flag) + printf("Version: if %s.%d kmod %s\n", val1, ival, val2); + break; + case MDT_MODULE: + getstr(&ptr, val1); + getstr(&ptr, val2); + if (lastmod) + free(lastmod); + lastmod = strdup(val2); + if (dump_flag) + printf("Module %s in %s\n", val1, val2); + break; + case MDT_PNP_INFO: + if (!dump_flag && !unbound_flag && lastmod && strcmp(lastmod, "kernel") == 0) + break; + getstr(&ptr, val1); + getstr(&ptr, val2); + ents = getint(&ptr); + if (bus && strcmp(val1, bus) != 0) + break; + if (dump_flag) + printf("PNP info for bus %s format %s %d entries (%s)\n", + val1, val2, ents, lastmod); + for (i = 0; i < ents; i++) { + if (dump_flag) + printf(" "); + cp = val2; + notme = 0; + mask = -1; + bit = -1; + do { + switch (*cp) { + case 'I': + case 'J': + case 'G': + case 'L': + case 'M': + ival = getint(&ptr); + if (dump_flag) { + printf("%#x:", ival); + break; + } + if (bit >= 0 && ((1 << bit) & mask) == 0) + break; + v = pnpval_as_int(cp + 2, pnpinfo); + switch (*cp) { + case 'J': + if (ival == -1) + break; + /*FALLTHROUGH*/ + case 'I': + if (v != ival && ival != 0) + notme++; + break; + case 'G': + if (v < ival) + notme++; + break; + case 'L': + if (v > ival) + notme++; + break; + case 'M': + mask = ival; + break; + } + break; + case 'D': + case 'Z': + getstr(&ptr, val1); + if (dump_flag) { + printf("'%s':", val1); + break; + } + if (*cp == 'D') + break; + s = pnpval_as_str(cp + 2, pnpinfo); + if (strcmp(s, val1) != 0) + notme++; + break; + default: + break; + } + bit++; + cp = strchr(cp, ';'); + if (cp) + cp++; + } while (cp && *cp); + if (dump_flag) + printf("\n"); + else if (!notme) { + if (!unbound_flag) { + if (all_flag) + printf("%s: ", *dev ? dev : "unattached" ); + printf("%s\n", lastmod); + } + found++; + } + } + break; + default: + if (dump_flag) + printf("Unknown Type %d len %d\n", ival, len); + break; + } + walker = (void *)(len - sizeof(int) + (intptr_t)walker); + } + if (unbound_flag && found == 0 && *pnpinfo) { + if (verbose_flag) + printf("------------------------- "); + printf("%s on %s pnpinfo %s", *dev ? dev : "unattached", bus, pnpinfo); + if (verbose_flag) + printf(" -------------------------"); + printf("\n"); + } + free(lastmod); +} + +static int +find_unmatched(struct devinfo_dev *dev, void *arg) +{ + struct devinfo_dev *parent; + char *bus, *p; + + do { + if (!all_flag && dev->dd_name[0] != '\0') + break; + if (!(dev->dd_flags & DF_ENABLED)) + break; + parent = devinfo_handle_to_device(dev->dd_parent); + bus = strdup(parent->dd_name); + p = bus + strlen(bus) - 1; + while (p >= bus && isdigit(*p)) + p--; + *++p = '\0'; + if (verbose_flag) + printf("Searching %s %s bus at %s for pnpinfo %s\n", + dev->dd_name, bus, dev->dd_location, dev->dd_pnpinfo); + search_hints(bus, dev->dd_name, dev->dd_pnpinfo); + free(bus); + } while (0); + + return (devinfo_foreach_device_child(dev, find_unmatched, arg)); +} + +static void +usage(void) +{ + + errx(1, "devmatch [-adv]"); +} + +int +main(int argc, char **argv) +{ + struct devinfo_dev *root; + int ch; + + while ((ch = getopt_long(argc, argv, "aduv", + longopts, NULL)) != -1) { + switch (ch) { + case 'a': + all_flag++; + break; + case 'd': + dump_flag++; + break; + case 'u': + unbound_flag++; + break; + case 'v': + verbose_flag++; + break; + default: + usage(); + } + } + argc -= optind; + argv += optind; + + if (argc >= 1) + usage(); + + read_linker_hints(); + if (dump_flag) { + search_hints(NULL, NULL, NULL); + exit(0); + } + + if (devinfo_init()) + err(1, "devinfo_init"); + if ((root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE)) == NULL) + errx(1, "can't find root device"); + devinfo_foreach_device_child(root, find_unmatched, (void *)0); + devinfo_free(); +} diff --git a/usr.sbin/fwcontrol/fwdv.c b/usr.sbin/fwcontrol/fwdv.c index e35281f7373..0dbf17d04a4 100644 --- a/usr.sbin/fwcontrol/fwdv.c +++ b/usr.sbin/fwcontrol/fwdv.c @@ -417,4 +417,5 @@ dvsend(int d, const char *filename, char ich, int count) + (end.tv_usec - start.tv_usec) * 1e-6; fprintf(stderr, "%d frames, %.2f secs, %.2f frames/sec\n", frames, rtime, frames/rtime); + close(fd); } diff --git a/usr.sbin/kgmon/kgmon.c b/usr.sbin/kgmon/kgmon.c index 386d3956b35..17f59cdd9ee 100644 --- a/usr.sbin/kgmon/kgmon.c +++ b/usr.sbin/kgmon/kgmon.c @@ -511,6 +511,7 @@ reset(struct kvmvars *kvp) if (kvm_write(kvp->kd, (u_long)kvp->gpm.tos, zbuf, kvp->gpm.tossize) != (ssize_t)kvp->gpm.tossize) errx(15, "tos zero: %s", kvm_geterr(kvp->kd)); + free(zbuf); return; } (void)seteuid(0); diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c index 63e6c321002..ad31b19a60e 100644 --- a/usr.sbin/makefs/cd9660.c +++ b/usr.sbin/makefs/cd9660.c @@ -2121,7 +2121,7 @@ cd9660_add_generic_bootimage(iso9660_disk *diskStructure, const char *bootimage) } if (diskStructure->verbose_level > 0) { - printf("Generic boot image image has size %lld\n", + printf("Generic boot image has size %lld\n", (long long)stbuf.st_size); } diff --git a/usr.sbin/nandtool/nand_read.c b/usr.sbin/nandtool/nand_read.c index d84d424a509..395b0c3fa7f 100644 --- a/usr.sbin/nandtool/nand_read.c +++ b/usr.sbin/nandtool/nand_read.c @@ -52,7 +52,7 @@ int nand_read(struct cmd_param *params) } if ((out = param_get_string(params, "out"))) { - out_fd = open(out, O_WRONLY|O_CREAT); + out_fd = open(out, O_WRONLY|O_CREAT, 0666); if (out_fd == -1) { perrorf("Cannot open %s for writing", out); return (1); diff --git a/usr.sbin/nandtool/nand_readoob.c b/usr.sbin/nandtool/nand_readoob.c index 6d253f9db53..6c5bb372c3e 100644 --- a/usr.sbin/nandtool/nand_readoob.c +++ b/usr.sbin/nandtool/nand_readoob.c @@ -59,7 +59,7 @@ int nand_read_oob(struct cmd_param *params) } if ((out = param_get_string(params, "out"))) { - if ((fd_out = open(out, O_WRONLY | O_CREAT)) == -1) { + if ((fd_out = open(out, O_WRONLY | O_CREAT, 0666)) == -1) { perrorf("Cannot open %s", out); ret = 1; goto out; diff --git a/usr.sbin/ndiscvt/ndiscvt.c b/usr.sbin/ndiscvt/ndiscvt.c index 09f7faeb306..276a6ef7bfd 100644 --- a/usr.sbin/ndiscvt/ndiscvt.c +++ b/usr.sbin/ndiscvt/ndiscvt.c @@ -213,6 +213,7 @@ bincvt(char *sysfile, char *outfile, void *img, int fsize) tname, sysfile, tname, tname, sysfile, outfile, outfile); printf("%s", sysbuf); system(sysbuf); + free(outfile); return; } diff --git a/usr.sbin/nfsd/nfsd.c b/usr.sbin/nfsd/nfsd.c index 08833434072..f4f5adfa5f5 100644 --- a/usr.sbin/nfsd/nfsd.c +++ b/usr.sbin/nfsd/nfsd.c @@ -761,10 +761,10 @@ main(int argc, char **argv) setproctitle("master"); /* - * We always want a master to have a clean way to to shut nfsd down + * We always want a master to have a clean way to shut nfsd down * (with unregistration): if the master is killed, it unregisters and * kills all children. If we run for UDP only (and so do not have to - * loop waiting waiting for accept), we instead make the parent + * loop waiting for accept), we instead make the parent * a "server" too. start_server will not return. */ if (!tcpflag) diff --git a/usr.sbin/ntp/doc/ntp.conf.5 b/usr.sbin/ntp/doc/ntp.conf.5 index be288c6f10a..805453f215b 100644 --- a/usr.sbin/ntp/doc/ntp.conf.5 +++ b/usr.sbin/ntp/doc/ntp.conf.5 @@ -2550,7 +2550,7 @@ While this is generally a feature as it allows for quick recovery if a server key has changed, a properly forged and appropriately delivered crypto\-NAK packet can be used in a DoS attack. -If you have active noticable problems with this type of DoS attack +If you have active noticeable problems with this type of DoS attack then you should consider disabling this option. You can check your @@ -2598,7 +2598,7 @@ While this is generally a feature as it allows for quick recovery if a server key has changed, a properly forged and appropriately delivered crypto\-NAK packet can be used in a DoS attack. -If you have active noticable problems with this type of DoS attack +If you have active noticeable problems with this type of DoS attack then you should consider disabling this option. You can check your @@ -2618,7 +2618,7 @@ While this is generally a feature as it allows for quick recovery, if this type of packet is carefully forged and sent during an appropriate window it can be used for a DoS attack. -If you have active noticable problems with this type of DoS attack +If you have active noticeable problems with this type of DoS attack then you should consider disabling this option. You can check your diff --git a/usr.sbin/rpc.lockd/lockd_lock.c b/usr.sbin/rpc.lockd/lockd_lock.c index 594d01f7e1e..25e74ed6a7d 100644 --- a/usr.sbin/rpc.lockd/lockd_lock.c +++ b/usr.sbin/rpc.lockd/lockd_lock.c @@ -883,7 +883,7 @@ test_nfslock(const struct file_lock *fl, struct file_lock **conflicting_fl) * While this seems to be intuitively wrong, it is required for proper * Posix semantics during unlock. It is absolutely imperative to not * unlock the main lock before the two child locks are established. Thus, - * one has be be able to create duplicate locks over an existing lock + * one has to be able to create duplicate locks over an existing lock * 2) It currently accepts duplicate locks from the same id,pid */