svn commit: r364185 - head/sys/cam/nvme

2020-08-12 Thread Alexander Motin
Author: mav
Date: Thu Aug 13 02:32:46 2020
New Revision: 364185
URL: https://svnweb.freebsd.org/changeset/base/364185

Log:
  Fill device serial_num and device_id in NVMe XPT.
  
  It allows to report GEOM::lunid for nda(4) same as for nvd(4).  Since
  NVMe now allows multiple LUs (namespaces) with multiple paths unique
  LU identification is important.  The serial_num field is filled same
  as before with the controller serial number, while device_id is based
  on namespace GUID and/or EUI64 fields as recommended by "NVM Express:
  SCSI Translation Reference" and matching nvd(4) at the end.
  
  MFC after:1 week

Modified:
  head/sys/cam/nvme/nvme_xpt.c

Modified: head/sys/cam/nvme/nvme_xpt.c
==
--- head/sys/cam/nvme/nvme_xpt.cThu Aug 13 00:42:09 2020
(r364184)
+++ head/sys/cam/nvme/nvme_xpt.cThu Aug 13 02:32:46 2020
(r364185)
@@ -310,9 +310,11 @@ nvme_probe_done(struct cam_periph *periph, union ccb *
struct nvme_controller_data *nvme_cdata;
nvme_probe_softc *softc;
struct cam_path *path;
+   struct scsi_vpd_device_id *did;
+   struct scsi_vpd_id_descriptor *idd;
cam_status status;
u_int32_t  priority;
-   int found = 1;
+   int found = 1, e, g, len;
 
CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("nvme_probe_done\n"));
 
@@ -369,6 +371,21 @@ device_fail:   if ((path->device->flags & 
CAM_DEV_UNCONF
bcopy(>cd, nvme_cdata, sizeof(*nvme_cdata));
path->device->nvme_cdata = nvme_cdata;
 
+   /* Save/update serial number. */
+   if (path->device->serial_num != NULL) {
+   free(path->device->serial_num, M_CAMXPT);
+   path->device->serial_num = NULL;
+   path->device->serial_num_len = 0;
+   }
+   path->device->serial_num = (u_int8_t *)
+   malloc(NVME_SERIAL_NUMBER_LENGTH + 1, M_CAMXPT, M_NOWAIT);
+   if (path->device->serial_num != NULL) {
+   cam_strvis(path->device->serial_num, nvme_cdata->sn,
+   NVME_SERIAL_NUMBER_LENGTH, 
NVME_SERIAL_NUMBER_LENGTH + 1);
+   path->device->serial_num_len =
+   strlen(path->device->serial_num);
+   }
+
 // nvme_find_quirk(path->device);
nvme_device_transport(path);
NVME_PROBE_SET_ACTION(softc, NVME_PROBE_IDENTIFY_NS);
@@ -394,6 +411,53 @@ device_fail:   if ((path->device->flags & 
CAM_DEV_UNCONF
bcopy(>ns, nvme_data, sizeof(*nvme_data));
path->device->nvme_data = nvme_data;
 
+   /* Save/update device_id based on NGUID and/or EUI64. */
+   if (path->device->device_id != NULL) {
+   free(path->device->device_id, M_CAMXPT);
+   path->device->device_id = NULL;
+   path->device->device_id_len = 0;
+   }
+   len = 0;
+   for (g = 0; g < sizeof(nvme_data->nguid); g++) {
+   if (nvme_data->nguid[g] != 0)
+   break;
+   }
+   if (g < sizeof(nvme_data->nguid))
+   len += sizeof(struct scsi_vpd_id_descriptor) + 16;
+   for (e = 0; e < sizeof(nvme_data->eui64); e++) {
+   if (nvme_data->eui64[e] != 0)
+   break;
+   }
+   if (e < sizeof(nvme_data->eui64))
+   len += sizeof(struct scsi_vpd_id_descriptor) + 8;
+   if (len > 0) {
+   path->device->device_id = (u_int8_t *)
+   malloc(SVPD_DEVICE_ID_HDR_LEN + len,
+   M_CAMXPT, M_NOWAIT);
+   }
+   if (path->device->device_id != NULL) {
+   did = (struct scsi_vpd_device_id 
*)path->device->device_id;
+   did->device = SID_QUAL_LU_CONNECTED | T_DIRECT;
+   did->page_code = SVPD_DEVICE_ID;
+   scsi_ulto2b(len, did->length);
+   idd = (struct scsi_vpd_id_descriptor *)(did + 1);
+   if (g < sizeof(nvme_data->nguid)) {
+   idd->proto_codeset = SVPD_ID_CODESET_BINARY;
+   idd->id_type = SVPD_ID_ASSOC_LUN | 
SVPD_ID_TYPE_EUI64;
+   idd->length = 16;
+   bcopy(nvme_data->nguid, idd->identifier, 16);
+   idd = (struct scsi_vpd_id_descriptor *)
+   >identifier[16];
+   }
+   if (e < sizeof(nvme_data->eui64)) {
+   idd->proto_codeset = SVPD_ID_CODESET_BINARY;
+   

svn commit: r364182 - in head: etc/mtree lib/liblua

2020-08-12 Thread Ed Maste
Author: emaste
Date: Thu Aug 13 00:19:05 2020
New Revision: 364182
URL: https://svnweb.freebsd.org/changeset/base/364182

Log:
  flua: initial support for "require" in the base system
  
  Use /usr not /usr/local for base system components.
  
  Use /usr/lib/flua and /usr/share/flua (not lua) for consistency and to
  avoid the possibility that other software accidentally finds our base
  system modules.
  
  Also drop the version from the path, as flua represents an unspecified
  lua version that corresponds to the FreeBSD version it comes with.
  
  LUA_USE_DLOPEN is not yet enabled because some additional changes are
  needed wrt symbol visibility.
  
  Sponsored by: The FreeBSD Foundation
  Differential Revision:https://reviews.freebsd.org/D24605

Modified:
  head/etc/mtree/BSD.usr.dist
  head/lib/liblua/luaconf.h

Modified: head/etc/mtree/BSD.usr.dist
==
--- head/etc/mtree/BSD.usr.dist Wed Aug 12 20:33:29 2020(r364181)
+++ head/etc/mtree/BSD.usr.dist Thu Aug 13 00:19:05 2020(r364182)
@@ -68,6 +68,8 @@
 ..
 engines
 ..
+flua
+..
 i18n
 ..
 libxo
@@ -369,6 +371,8 @@
 ..
 ..
 firmware
+..
+flua
 ..
 games
 fortune

Modified: head/lib/liblua/luaconf.h
==
--- head/lib/liblua/luaconf.h   Wed Aug 12 20:33:29 2020(r364181)
+++ head/lib/liblua/luaconf.h   Thu Aug 13 00:19:05 2020(r364182)
@@ -205,9 +205,9 @@
 
 #else  /* }{ */
 
-#define LUA_ROOT   "/usr/local/"
-#define LUA_LDIR   LUA_ROOT "share/lua/" LUA_VDIR "/"
-#define LUA_CDIR   LUA_ROOT "lib/lua/" LUA_VDIR "/"
+#define LUA_ROOT   "/usr/"
+#define LUA_LDIR   LUA_ROOT "share/flua/"
+#define LUA_CDIR   LUA_ROOT "lib/flua/"
 #if !defined(LUA_PATH_DEFAULT)
 #define LUA_PATH_DEFAULT  \
LUA_LDIR"?.lua;"  LUA_LDIR"?/init.lua;" \
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364181 - head/sys/riscv/riscv

2020-08-12 Thread John Baldwin
Author: jhb
Date: Wed Aug 12 20:33:29 2020
New Revision: 364181
URL: https://svnweb.freebsd.org/changeset/base/364181

Log:
  Check that the frame pointer is within the current stack.
  
  This same check is used on other architectures.  Previously this would
  permit a stack frame to unwind into any arbitrary kernel address
  (including unmapped addresses).
  
  Reviewed by:  mhorne
  Obtained from:CheriBSD
  Sponsored by: DARPA
  Differential Revision:https://reviews.freebsd.org/D25996

Modified:
  head/sys/riscv/riscv/stack_machdep.c

Modified: head/sys/riscv/riscv/stack_machdep.c
==
--- head/sys/riscv/riscv/stack_machdep.cWed Aug 12 20:29:49 2020
(r364180)
+++ head/sys/riscv/riscv/stack_machdep.cWed Aug 12 20:33:29 2020
(r364181)
@@ -47,15 +47,18 @@ __FBSDID("$FreeBSD$");
 #include 
 
 static void
-stack_capture(struct stack *st, struct unwind_state *frame)
+stack_capture(struct thread *td, struct stack *st, struct unwind_state *frame)
 {
 
stack_zero(st);
 
while (1) {
+   if ((vm_offset_t)frame->fp < td->td_kstack ||
+   (vm_offset_t)frame->fp >= td->td_kstack +
+   td->td_kstack_pages * PAGE_SIZE)
+   break;
unwind_frame(frame);
-   if (!INKERNEL((vm_offset_t)frame->fp) ||
-!INKERNEL((vm_offset_t)frame->pc))
+   if (!INKERNEL((vm_offset_t)frame->pc))
break;
if (stack_put(st, frame->pc) == -1)
break;
@@ -78,7 +81,7 @@ stack_save_td(struct stack *st, struct thread *td)
frame.fp = td->td_pcb->pcb_s[0];
frame.pc = td->td_pcb->pcb_ra;
 
-   stack_capture(st, );
+   stack_capture(td, st, );
return (0);
 }
 
@@ -94,5 +97,5 @@ stack_save(struct stack *st)
frame.fp = (uintptr_t)__builtin_frame_address(0);
frame.pc = (uintptr_t)stack_save;
 
-   stack_capture(st, );
+   stack_capture(curthread, st, );
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364180 - in head/sys/riscv: include riscv

2020-08-12 Thread John Baldwin
Author: jhb
Date: Wed Aug 12 20:29:49 2020
New Revision: 364180
URL: https://svnweb.freebsd.org/changeset/base/364180

Log:
  Use uintptr_t instead of uint64_t for pointers in stack frames.
  
  Reviewed by:  mhorne
  Obtained from:CheriBSD
  Sponsored by: DARPA
  Differential Revision:https://reviews.freebsd.org/D25995

Modified:
  head/sys/riscv/include/stack.h
  head/sys/riscv/riscv/db_trace.c
  head/sys/riscv/riscv/stack_machdep.c
  head/sys/riscv/riscv/unwind.c

Modified: head/sys/riscv/include/stack.h
==
--- head/sys/riscv/include/stack.h  Wed Aug 12 20:05:43 2020
(r364179)
+++ head/sys/riscv/include/stack.h  Wed Aug 12 20:29:49 2020
(r364180)
@@ -41,9 +41,9 @@
 (va) <= VM_MAX_KERNEL_ADDRESS)
 
 struct unwind_state {
-   uint64_t fp;
-   uint64_t sp;
-   uint64_t pc;
+   uintptr_t fp;
+   uintptr_t sp;
+   uintptr_t pc;
 };
 
 int unwind_frame(struct unwind_state *);

Modified: head/sys/riscv/riscv/db_trace.c
==
--- head/sys/riscv/riscv/db_trace.c Wed Aug 12 20:05:43 2020
(r364179)
+++ head/sys/riscv/riscv/db_trace.c Wed Aug 12 20:29:49 2020
(r364180)
@@ -108,9 +108,9 @@ db_stack_trace_cmd(struct unwind_state *frame)
db_printf("--- exception %ld, tval = %#lx\n",
tf->tf_scause & EXCP_MASK,
tf->tf_stval);
-   frame->sp = (uint64_t)tf->tf_sp;
-   frame->fp = (uint64_t)tf->tf_s[0];
-   frame->pc = (uint64_t)tf->tf_sepc;
+   frame->sp = tf->tf_sp;
+   frame->fp = tf->tf_s[0];
+   frame->pc = tf->tf_sepc;
if (!INKERNEL(frame->fp))
break;
continue;
@@ -132,9 +132,9 @@ db_trace_thread(struct thread *thr, int count)
 
ctx = kdb_thr_ctx(thr);
 
-   frame.sp = (uint64_t)ctx->pcb_sp;
-   frame.fp = (uint64_t)ctx->pcb_s[0];
-   frame.pc = (uint64_t)ctx->pcb_ra;
+   frame.sp = ctx->pcb_sp;
+   frame.fp = ctx->pcb_s[0];
+   frame.pc = ctx->pcb_ra;
db_stack_trace_cmd();
return (0);
 }
@@ -143,12 +143,12 @@ void
 db_trace_self(void)
 {
struct unwind_state frame;
-   uint64_t sp;
+   uintptr_t sp;
 
__asm __volatile("mv %0, sp" : "=" (sp));
 
frame.sp = sp;
-   frame.fp = (uint64_t)__builtin_frame_address(0);
-   frame.pc = (uint64_t)db_trace_self;
+   frame.fp = (uintptr_t)__builtin_frame_address(0);
+   frame.pc = (uintptr_t)db_trace_self;
db_stack_trace_cmd();
 }

Modified: head/sys/riscv/riscv/stack_machdep.c
==
--- head/sys/riscv/riscv/stack_machdep.cWed Aug 12 20:05:43 2020
(r364179)
+++ head/sys/riscv/riscv/stack_machdep.cWed Aug 12 20:29:49 2020
(r364180)
@@ -86,13 +86,13 @@ void
 stack_save(struct stack *st)
 {
struct unwind_state frame;
-   uint64_t sp;
+   uintptr_t sp;
 
__asm __volatile("mv %0, sp" : "=" (sp));
 
frame.sp = sp;
-   frame.fp = (uint64_t)__builtin_frame_address(0);
-   frame.pc = (uint64_t)stack_save;
+   frame.fp = (uintptr_t)__builtin_frame_address(0);
+   frame.pc = (uintptr_t)stack_save;
 
stack_capture(st, );
 }

Modified: head/sys/riscv/riscv/unwind.c
==
--- head/sys/riscv/riscv/unwind.c   Wed Aug 12 20:05:43 2020
(r364179)
+++ head/sys/riscv/riscv/unwind.c   Wed Aug 12 20:29:49 2020
(r364180)
@@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$");
 int
 unwind_frame(struct unwind_state *frame)
 {
-   uint64_t fp;
+   uintptr_t fp;
 
fp = frame->fp;
 
@@ -50,8 +50,8 @@ unwind_frame(struct unwind_state *frame)
return (-1);
 
frame->sp = fp;
-   frame->fp = *(uint64_t *)(fp - 16);
-   frame->pc = *(uint64_t *)(fp - 8) - 4;
+   frame->fp = ((uintptr_t *)fp)[-2];
+   frame->pc = ((uintptr_t *)fp)[-1] - 4;
 
return (0);
 }
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364179 - head/sys/dev/nvme

2020-08-12 Thread Alexander Motin
Author: mav
Date: Wed Aug 12 20:05:43 2020
New Revision: 364179
URL: https://svnweb.freebsd.org/changeset/base/364179

Log:
  Report cpi->hba_* for nda(4) because why not.
  
  MFC after:1 week

Modified:
  head/sys/dev/nvme/nvme_sim.c

Modified: head/sys/dev/nvme/nvme_sim.c
==
--- head/sys/dev/nvme/nvme_sim.cWed Aug 12 19:37:57 2020
(r364178)
+++ head/sys/dev/nvme/nvme_sim.cWed Aug 12 20:05:43 2020
(r364179)
@@ -197,8 +197,12 @@ nvme_sim_action(struct cam_sim *sim, union ccb *ccb)
cpi->xport_specific.nvme.slot = pci_get_slot(dev);
cpi->xport_specific.nvme.function = pci_get_function(dev);
cpi->xport_specific.nvme.extra = 0;
-   strncpy(cpi->xport_specific.nvme.dev_name, 
device_get_nameunit(ctrlr->dev),
+   strncpy(cpi->xport_specific.nvme.dev_name, 
device_get_nameunit(dev),
sizeof(cpi->xport_specific.nvme.dev_name));
+   cpi->hba_vendor = pci_get_vendor(dev);
+   cpi->hba_device = pci_get_device(dev);
+   cpi->hba_subvendor = pci_get_subvendor(dev);
+   cpi->hba_subdevice = pci_get_subdevice(dev);
cpi->ccb_h.status = CAM_REQ_CMP;
break;
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364178 - head/sys/cam/nvme

2020-08-12 Thread Alexander Motin
Author: mav
Date: Wed Aug 12 19:37:57 2020
New Revision: 364178
URL: https://svnweb.freebsd.org/changeset/base/364178

Log:
  Report proper stripesize for nda(4).
  
  Same as for nvd(4) report NPWG if present, otherise NOIOB.
  
  MFC after:1 week

Modified:
  head/sys/cam/nvme/nvme_da.c

Modified: head/sys/cam/nvme/nvme_da.c
==
--- head/sys/cam/nvme/nvme_da.c Wed Aug 12 19:11:53 2020(r364177)
+++ head/sys/cam/nvme/nvme_da.c Wed Aug 12 19:37:57 2020(r364178)
@@ -943,7 +943,11 @@ ndaregister(struct cam_periph *periph, void *arg)
disk->d_hba_subdevice = cpi.hba_subdevice;
snprintf(disk->d_attachment, sizeof(disk->d_attachment),
"%s%d", cpi.dev_name, cpi.unit_number);
-   disk->d_stripesize = disk->d_sectorsize;
+   if (((nsd->nsfeat >> NVME_NS_DATA_NSFEAT_NPVALID_SHIFT) &
+   NVME_NS_DATA_NSFEAT_NPVALID_MASK) != 0 && nsd->npwg != 0)
+   disk->d_stripesize = ((nsd->npwg + 1) * disk->d_sectorsize);
+   else
+   disk->d_stripesize = nsd->noiob * disk->d_sectorsize;
disk->d_stripeoffset = 0;
disk->d_devstat = devstat_new_entry(periph->periph_name,
periph->unit_number, disk->d_sectorsize,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364177 - head/sys/dev/nvd

2020-08-12 Thread Alexander Motin
Author: mav
Date: Wed Aug 12 19:11:53 2020
New Revision: 364177
URL: https://svnweb.freebsd.org/changeset/base/364177

Log:
  Report attachment for nvd same as reported for nda.
  
  MFC after:1 week

Modified:
  head/sys/dev/nvd/nvd.c

Modified: head/sys/dev/nvd/nvd.c
==
--- head/sys/dev/nvd/nvd.c  Wed Aug 12 18:45:36 2020(r364176)
+++ head/sys/dev/nvd/nvd.c  Wed Aug 12 19:11:53 2020(r364177)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2012-2016 Intel Corporation
  * All rights reserved.
- * Copyright (C) 2018 Alexander Motin 
+ * Copyright (C) 2018-2020 Alexander Motin 
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -45,7 +45,10 @@ __FBSDID("$FreeBSD$");
 #include 
 
 #include 
+#include 
 
+#include 
+
 #define NVD_STR"nvd"
 
 struct nvd_disk;
@@ -92,7 +95,7 @@ struct nvd_disk {
 };
 
 struct nvd_controller {
-
+   struct nvme_controller  *ctrlr;
TAILQ_ENTRY(nvd_controller) tailq;
TAILQ_HEAD(, nvd_disk)  disk_head;
 };
@@ -401,6 +404,7 @@ nvd_new_controller(struct nvme_controller *ctrlr)
nvd_ctrlr = malloc(sizeof(struct nvd_controller), M_NVD,
M_ZERO | M_WAITOK);
 
+   nvd_ctrlr->ctrlr = ctrlr;
TAILQ_INIT(_ctrlr->disk_head);
mtx_lock(_lock);
TAILQ_INSERT_TAIL(_head, nvd_ctrlr, tailq);
@@ -416,6 +420,7 @@ nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_ar
struct nvd_disk *ndisk, *tnd;
struct disk *disk;
struct nvd_controller   *ctrlr = ctrlr_arg;
+   device_t dev = ctrlr->ctrlr->dev;
int unit;
 
ndisk = malloc(sizeof(struct nvd_disk), M_NVD, M_ZERO | M_WAITOK);
@@ -479,7 +484,13 @@ nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_ar
NVME_MODEL_NUMBER_LENGTH);
strlcpy(disk->d_descr, descr, sizeof(descr));
 
+   disk->d_hba_vendor = pci_get_vendor(dev);
+   disk->d_hba_device = pci_get_device(dev);
+   disk->d_hba_subvendor = pci_get_subvendor(dev);
+   disk->d_hba_subdevice = pci_get_subdevice(dev);
disk->d_rotation_rate = DISK_RR_NON_ROTATING;
+   strlcpy(disk->d_attachment, device_get_nameunit(dev),
+   sizeof(disk->d_attachment));
 
disk_create(disk, DISK_VERSION);
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364176 - head/sys/riscv/include

2020-08-12 Thread John Baldwin
Author: jhb
Date: Wed Aug 12 18:45:36 2020
New Revision: 364176
URL: https://svnweb.freebsd.org/changeset/base/364176

Log:
  Correct padding length for RISC-V PCPU data.
  
  There was an additional 7 bytes of compiler-inserted padding at the
  end of the structure visible via 'ptype /o' in gdb.
  
  Reviewed by:  mhorne
  Obtained from:CheriBSD
  Sponsored by: DARPA
  Differential Revision:https://reviews.freebsd.org/D25867

Modified:
  head/sys/riscv/include/pcpu.h
  head/sys/riscv/include/pcpu_aux.h

Modified: head/sys/riscv/include/pcpu.h
==
--- head/sys/riscv/include/pcpu.h   Wed Aug 12 18:35:21 2020
(r364175)
+++ head/sys/riscv/include/pcpu.h   Wed Aug 12 18:45:36 2020
(r364176)
@@ -48,7 +48,7 @@
struct pmap *pc_curpmap;/* Currently active pmap */ \
uint32_t pc_pending_ipis;   /* IPIs pending to this CPU */  \
uint32_t pc_hart;   /* Hart ID */   \
-   char __pad[49]
+   char __pad[56]  /* Pad to factor of PAGE_SIZE */
 
 #ifdef _KERNEL
 

Modified: head/sys/riscv/include/pcpu_aux.h
==
--- head/sys/riscv/include/pcpu_aux.h   Wed Aug 12 18:35:21 2020
(r364175)
+++ head/sys/riscv/include/pcpu_aux.h   Wed Aug 12 18:45:36 2020
(r364176)
@@ -46,6 +46,9 @@
  * be a multiple of the size of struct pcpu.
  */
 _Static_assert(PAGE_SIZE % sizeof(struct pcpu) == 0, "fix pcpu size");
+_Static_assert(offsetof(struct pcpu, __pad) +
+sizeof(((struct pcpu *)0)->__pad) == sizeof(struct pcpu),
+"fix pcpu padding");
 
 extern struct pcpu __pcpu[];
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364174 - head/usr.sbin/crunch/crunchgen

2020-08-12 Thread Alex Richardson
Author: arichardson
Date: Wed Aug 12 17:27:24 2020
New Revision: 364174
URL: https://svnweb.freebsd.org/changeset/base/364174

Log:
  Use env pwd instead of pwd in crunchgen.c
  
  In r364166 I changed /bin/pwd to pwd, but pwd can be shell builtin that
  may not correctly return a real path. To ensure that all symlinks are
  resolved use `env pwd -P` instead (the -P flag is part of POSIX so
  should be supported everywhere).
  
  Reported By:  rgrimes
  Suggested By: jrtc27

Modified:
  head/usr.sbin/crunch/crunchgen/crunchgen.c

Modified: head/usr.sbin/crunch/crunchgen/crunchgen.c
==
--- head/usr.sbin/crunch/crunchgen/crunchgen.c  Wed Aug 12 17:16:26 2020
(r364173)
+++ head/usr.sbin/crunch/crunchgen/crunchgen.c  Wed Aug 12 17:27:24 2020
(r364174)
@@ -653,7 +653,7 @@ fillin_program(prog_t *p)
 
/* Determine the actual srcdir (maybe symlinked). */
if (p->srcdir) {
-   snprintf(line, MAXLINELEN, "cd %s && pwd", p->srcdir);
+   snprintf(line, MAXLINELEN, "cd %s && env pwd -P", p->srcdir);
f = popen(line,"r");
if (!f)
errx(1, "Can't execute: %s\n", line);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364172 - head/sys/net

2020-08-12 Thread Mitchell Horne
Author: mhorne
Date: Wed Aug 12 16:43:20 2020
New Revision: 364172
URL: https://svnweb.freebsd.org/changeset/base/364172

Log:
  Correctly set error in rt_mpath_unlink
  
  It is possible for rn_delete() to return NULL. If this happens, then set
  *perror to ESRCH, as is done in the rest of the function.
  
  Sponsored by: NetApp, Inc.
  Sponsored by: Klara, Inc.
  Differential Revision:https://reviews.freebsd.org/D25871

Modified:
  head/sys/net/route.c

Modified: head/sys/net/route.c
==
--- head/sys/net/route.cWed Aug 12 16:30:33 2020(r364171)
+++ head/sys/net/route.cWed Aug 12 16:43:20 2020(r364172)
@@ -1107,7 +1107,11 @@ rt_mpath_unlink(struct rib_head *rnh, struct rt_addrin
rn = rnh->rnh_deladdr(info->rti_info[RTAX_DST],
info->rti_info[RTAX_NETMASK],
>head);
-   *perror = 0;
+   if (rn != NULL) {
+   *perror = 0;
+   } else {
+   *perror = ESRCH;
+   }
return (rn);
}

___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r364166 - head/usr.sbin/crunch/crunchgen

2020-08-12 Thread Rodney W. Grimes
> On 12 Aug 2020, at 17:10, Rodney W. Grimes  wrote:
> > 
> >> Author: arichardson
> >> Date: Wed Aug 12 15:49:06 2020
> >> New Revision: 364166
> >> URL: https://svnweb.freebsd.org/changeset/base/364166
> >> 
> >> Log:
> >>  Fix crunchgen usage of mkstemp()
> >> 
> >>  On Glibc systems mkstemp can only be used once with the same template
> >>  string since it will be modified in-place and no longer contain any 'X' 
> >> chars.
> >>  It is fine to reuse the same file here but we need to be explicit and use
> >>  open() instead of mkstemp() on the second use.
> >> 
> >>  While touching this file also avoid a hardcoded /bin/pwd since that may 
> >> not
> >>  work when building on non-FreeBSD systems.
> > 
> > This may cause some grief, as now pwd may use a shell builtin
> > and often shell builtin's return a cwd that is not a true
> > full path, ie it may contain symlink compontents in the
> > path.
> > 
> > /bin/sh:
> > 
> > # cd /tmp/b
> > # /bin/pwd
> > /tmp/a
> > # pwd
> > /tmp/b
> > # ls -lag /tmp/?
> > lrwxr-xr-x  1 root  wheel  1 Aug 12 16:06 /tmp/b -> a
> > 
> > /tmp/a:
> > total 17
> > drwxr-xr-x   2 root  wheel2 Aug 12 16:06 .
> > drwxrwxrwt  18 root  wheel  248 Aug 12 16:06 ..
> 
> There's the question of whether that really matters; both values are in
> some sense correct. But if you want to restore the old behaviour, I
> believe `env pwd` is the portable way to do so?

You have cut the context, but the code has a comment that
states it is doing this to remove symbolic links, so this
change infact undoes something that was being done intentionally.

I do believe also that a "env pwd" would do the right thing
as well.

-- 
Rod Grimes rgri...@freebsd.org
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r364166 - head/usr.sbin/crunch/crunchgen

2020-08-12 Thread Jessica Clarke
On 12 Aug 2020, at 17:10, Rodney W. Grimes  wrote:
> 
> [ Charset UTF-8 unsupported, converting... ]
>> Author: arichardson
>> Date: Wed Aug 12 15:49:06 2020
>> New Revision: 364166
>> URL: https://svnweb.freebsd.org/changeset/base/364166
>> 
>> Log:
>>  Fix crunchgen usage of mkstemp()
>> 
>>  On Glibc systems mkstemp can only be used once with the same template
>>  string since it will be modified in-place and no longer contain any 'X' 
>> chars.
>>  It is fine to reuse the same file here but we need to be explicit and use
>>  open() instead of mkstemp() on the second use.
>> 
>>  While touching this file also avoid a hardcoded /bin/pwd since that may not
>>  work when building on non-FreeBSD systems.
> 
> This may cause some grief, as now pwd may use a shell builtin
> and often shell builtin's return a cwd that is not a true
> full path, ie it may contain symlink compontents in the
> path.
> 
> /bin/sh:
> 
> # cd /tmp/b
> # /bin/pwd
> /tmp/a
> # pwd
> /tmp/b
> # ls -lag /tmp/?
> lrwxr-xr-x  1 root  wheel  1 Aug 12 16:06 /tmp/b -> a
> 
> /tmp/a:
> total 17
> drwxr-xr-x   2 root  wheel2 Aug 12 16:06 .
> drwxrwxrwt  18 root  wheel  248 Aug 12 16:06 ..

There's the question of whether that really matters; both values are in
some sense correct. But if you want to restore the old behaviour, I
believe `env pwd` is the portable way to do so?

Jess

___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r364166 - head/usr.sbin/crunch/crunchgen

2020-08-12 Thread Rodney W. Grimes
[ Charset UTF-8 unsupported, converting... ]
> Author: arichardson
> Date: Wed Aug 12 15:49:06 2020
> New Revision: 364166
> URL: https://svnweb.freebsd.org/changeset/base/364166
> 
> Log:
>   Fix crunchgen usage of mkstemp()
>   
>   On Glibc systems mkstemp can only be used once with the same template
>   string since it will be modified in-place and no longer contain any 'X' 
> chars.
>   It is fine to reuse the same file here but we need to be explicit and use
>   open() instead of mkstemp() on the second use.
>   
>   While touching this file also avoid a hardcoded /bin/pwd since that may not
>   work when building on non-FreeBSD systems.

This may cause some grief, as now pwd may use a shell builtin
and often shell builtin's return a cwd that is not a true
full path, ie it may contain symlink compontents in the
path.

/bin/sh:

# cd /tmp/b
# /bin/pwd
/tmp/a
# pwd
/tmp/b
# ls -lag /tmp/?
lrwxr-xr-x  1 root  wheel  1 Aug 12 16:06 /tmp/b -> a

/tmp/a:
total 17
drwxr-xr-x   2 root  wheel2 Aug 12 16:06 .
drwxrwxrwt  18 root  wheel  248 Aug 12 16:06 ..

>   
>   Reviewed By:brooks
>   Differential Revision: https://reviews.freebsd.org/D25990
> 
> Modified:
>   head/usr.sbin/crunch/crunchgen/crunchgen.c
> 
> Modified: head/usr.sbin/crunch/crunchgen/crunchgen.c
> ==
> --- head/usr.sbin/crunch/crunchgen/crunchgen.cWed Aug 12 14:45:31 
> 2020(r364165)
> +++ head/usr.sbin/crunch/crunchgen/crunchgen.cWed Aug 12 15:49:06 
> 2020(r364166)
> @@ -39,10 +39,13 @@ __FBSDID("$FreeBSD$");
>  
>  #include 
>  #include 
> +#include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  
>  #define CRUNCH_VERSION   "0.2"
> @@ -91,6 +94,7 @@ prog_t   *progs = NULL;
>  char confname[MAXPATHLEN], infilename[MAXPATHLEN];
>  char outmkname[MAXPATHLEN], outcfname[MAXPATHLEN], execfname[MAXPATHLEN];
>  char tempfname[MAXPATHLEN], cachename[MAXPATHLEN], curfilename[MAXPATHLEN];
> +bool tempfname_initialized = false;
>  char outhdrname[MAXPATHLEN] ;/* user-supplied header for *.mk */
>  char *objprefix; /* where are the objects ? */
>  char *path_make;
> @@ -216,6 +220,7 @@ main(int argc, char **argv)
>   snprintf(cachename, sizeof(cachename), "%s.cache", confname);
>   snprintf(tempfname, sizeof(tempfname), "%s/crunchgen_%sXX",
>   getenv("TMPDIR") ? getenv("TMPDIR") : _PATH_TMP, confname);
> + tempfname_initialized = false;
>  
>   parse_conf_file();
>   if (list_mode)
> @@ -648,8 +653,7 @@ fillin_program(prog_t *p)
>  
>   /* Determine the actual srcdir (maybe symlinked). */
>   if (p->srcdir) {
> - snprintf(line, MAXLINELEN, "cd %s && echo -n `/bin/pwd`",
> - p->srcdir);
> + snprintf(line, MAXLINELEN, "cd %s && pwd", p->srcdir);
>   f = popen(line,"r");
>   if (!f)
>   errx(1, "Can't execute: %s\n", line);
> @@ -721,14 +725,26 @@ fillin_program_objs(prog_t *p, char *path)
>  
>   /* discover the objs from the srcdir Makefile */
>  
> - if ((fd = mkstemp(tempfname)) == -1) {
> - perror(tempfname);
> - exit(1);
> + /*
> +  * We reuse the same temporary file name for multiple objects. However,
> +  * some libc implementations (such as glibc) return EINVAL if there
> +  * are no X characters in the template. This happens after the
> +  * first call to mkstemp since the argument is modified in-place.
> +  * To avoid this error we use open() instead of mkstemp() after the
> +  * call to mkstemp().
> +  */
> + if (tempfname_initialized) {
> + if ((fd = open(tempfname, O_CREAT | O_EXCL | O_RDWR, 0600)) == 
> -1) {
> + err(EX_OSERR, "open(%s)", tempfname);
> + }
> + } else if ((fd = mkstemp(tempfname)) == -1) {
> + err(EX_OSERR, "mkstemp(%s)", tempfname);
>   }
> + tempfname_initialized = true;
>   if ((f = fdopen(fd, "w")) == NULL) {
> - warn("%s", tempfname);
> + warn("fdopen(%s)", tempfname);
>   goterror = 1;
> - return;
> + goto out;
>   }
>   if (p->objvar)
>   objvar = p->objvar;
> @@ -763,14 +779,14 @@ fillin_program_objs(prog_t *p, char *path)
>   if ((f = popen(line, "r")) == NULL) {
>   warn("submake pipe");
>   goterror = 1;
> - return;
> + goto out;
>   }
>  
>   while(fgets(line, MAXLINELEN, f)) {
>   if (strncmp(line, "OBJS= ", 6)) {
>   warnx("make error: %s", line);
>   goterror = 1;
> - continue;
> + goto out;
>   }
>  
>   cp = line + 6;
> @@ -793,7 +809,7 @@ fillin_program_objs(prog_t *p, char *path)
>   

svn commit: r364168 - head/sys/compat/linprocfs

2020-08-12 Thread Mark Johnston
Author: markj
Date: Wed Aug 12 16:08:44 2020
New Revision: 364168
URL: https://svnweb.freebsd.org/changeset/base/364168

Log:
  linprocfs: Fix some inaccuracies in meminfo.
  
  - Fill out MemFree correctly.  Delete an ancient comment suggesting that
we don't want to advertise the true quantity of free memory.
  - Populate the Buffers field by reading vfs.bufspace.
  - The page cache consists of all pages in page queues, not just the
inactive queue.
  
  PR:   248463
  Reported and tested by:   danfe
  MFC after:1 week
  Sponsored by: The FreeBSD Foundation

Modified:
  head/sys/compat/linprocfs/linprocfs.c

Modified: head/sys/compat/linprocfs/linprocfs.c
==
--- head/sys/compat/linprocfs/linprocfs.c   Wed Aug 12 15:49:10 2020
(r364167)
+++ head/sys/compat/linprocfs/linprocfs.c   Wed Aug 12 16:08:44 2020
(r364168)
@@ -145,41 +145,35 @@ static int
 linprocfs_domeminfo(PFS_FILL_ARGS)
 {
unsigned long memtotal; /* total memory in bytes */
-   unsigned long memused;  /* used memory in bytes */
unsigned long memfree;  /* free memory in bytes */
-   unsigned long buffers, cached;  /* buffer / cache memory ??? */
+   unsigned long cached;   /* page cache */
+   unsigned long buffers;  /* buffer cache */
unsigned long long swaptotal;   /* total swap space in bytes */
unsigned long long swapused;/* used swap space in bytes */
unsigned long long swapfree;/* free swap space in bytes */
-   int i, j;
+   size_t sz;
+   int error, i, j;
 
memtotal = physmem * PAGE_SIZE;
-   /*
-* The correct thing here would be:
-*
-   memfree = vm_free_count() * PAGE_SIZE;
-   memused = memtotal - memfree;
-*
-* but it might mislead linux binaries into thinking there
-* is very little memory left, so we cheat and tell them that
-* all memory that isn't wired down is free.
-*/
-   memused = vm_wire_count() * PAGE_SIZE;
-   memfree = memtotal - memused;
+   memfree = (unsigned long)vm_free_count() * PAGE_SIZE;
swap_pager_status(, );
swaptotal = (unsigned long long)i * PAGE_SIZE;
swapused = (unsigned long long)j * PAGE_SIZE;
swapfree = swaptotal - swapused;
+
/*
-* We'd love to be able to write:
-*
-   buffers = bufspace;
-*
-* but bufspace is internal to vfs_bio.c and we don't feel
-* like unstaticizing it just for linprocfs's sake.
+* This value may exclude wired pages, but we have no good way of
+* accounting for that.
 */
-   buffers = 0;
-   cached = vm_inactive_count() * PAGE_SIZE;
+   cached =
+   (vm_active_count() + vm_inactive_count() + vm_laundry_count()) *
+   PAGE_SIZE;
+
+   sz = sizeof(buffers);
+   error = kernel_sysctlbyname(curthread, "vfs.bufspace", , ,
+   NULL, 0, 0, 0);
+   if (error != 0)
+   buffers = 0;
 
sbuf_printf(sb,
"MemTotal: %9lu kB\n"
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364167 - head/stand/common

2020-08-12 Thread Alex Richardson
Author: arichardson
Date: Wed Aug 12 15:49:10 2020
New Revision: 364167
URL: https://svnweb.freebsd.org/changeset/base/364167

Log:
  Fix stand/newvers.sh with zsh in sh mode
  
  When building on macOS with sh==zsh, newvers.sh was producing an
  unterminated string literal due to \\n being turned as a newline. Fix this
  by using a here document instead.
  
  Reviewed By:  imp
  Differential Revision: https://reviews.freebsd.org/D26036

Modified:
  head/stand/common/newvers.sh

Modified: head/stand/common/newvers.sh
==
--- head/stand/common/newvers.shWed Aug 12 15:49:06 2020
(r364166)
+++ head/stand/common/newvers.shWed Aug 12 15:49:10 2020
(r364167)
@@ -55,6 +55,8 @@ if [ -n "${include_metadata}" ]; then
bootprog_info="$bootprog_info(${t} ${u}@${h})\\n"
 fi
 
-echo "char bootprog_info[] = \"$bootprog_info\";" > $tempfile
-echo "unsigned bootprog_rev = ${r%%.*}${r##*.};" >> $tempfile
+cat > $tempfile 

svn commit: r364166 - head/usr.sbin/crunch/crunchgen

2020-08-12 Thread Alex Richardson
Author: arichardson
Date: Wed Aug 12 15:49:06 2020
New Revision: 364166
URL: https://svnweb.freebsd.org/changeset/base/364166

Log:
  Fix crunchgen usage of mkstemp()
  
  On Glibc systems mkstemp can only be used once with the same template
  string since it will be modified in-place and no longer contain any 'X' chars.
  It is fine to reuse the same file here but we need to be explicit and use
  open() instead of mkstemp() on the second use.
  
  While touching this file also avoid a hardcoded /bin/pwd since that may not
  work when building on non-FreeBSD systems.
  
  Reviewed By:  brooks
  Differential Revision: https://reviews.freebsd.org/D25990

Modified:
  head/usr.sbin/crunch/crunchgen/crunchgen.c

Modified: head/usr.sbin/crunch/crunchgen/crunchgen.c
==
--- head/usr.sbin/crunch/crunchgen/crunchgen.c  Wed Aug 12 14:45:31 2020
(r364165)
+++ head/usr.sbin/crunch/crunchgen/crunchgen.c  Wed Aug 12 15:49:06 2020
(r364166)
@@ -39,10 +39,13 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #define CRUNCH_VERSION "0.2"
@@ -91,6 +94,7 @@ prog_t   *progs = NULL;
 char confname[MAXPATHLEN], infilename[MAXPATHLEN];
 char outmkname[MAXPATHLEN], outcfname[MAXPATHLEN], execfname[MAXPATHLEN];
 char tempfname[MAXPATHLEN], cachename[MAXPATHLEN], curfilename[MAXPATHLEN];
+bool tempfname_initialized = false;
 char outhdrname[MAXPATHLEN] ;  /* user-supplied header for *.mk */
 char *objprefix;   /* where are the objects ? */
 char *path_make;
@@ -216,6 +220,7 @@ main(int argc, char **argv)
snprintf(cachename, sizeof(cachename), "%s.cache", confname);
snprintf(tempfname, sizeof(tempfname), "%s/crunchgen_%sXX",
getenv("TMPDIR") ? getenv("TMPDIR") : _PATH_TMP, confname);
+   tempfname_initialized = false;
 
parse_conf_file();
if (list_mode)
@@ -648,8 +653,7 @@ fillin_program(prog_t *p)
 
/* Determine the actual srcdir (maybe symlinked). */
if (p->srcdir) {
-   snprintf(line, MAXLINELEN, "cd %s && echo -n `/bin/pwd`",
-   p->srcdir);
+   snprintf(line, MAXLINELEN, "cd %s && pwd", p->srcdir);
f = popen(line,"r");
if (!f)
errx(1, "Can't execute: %s\n", line);
@@ -721,14 +725,26 @@ fillin_program_objs(prog_t *p, char *path)
 
/* discover the objs from the srcdir Makefile */
 
-   if ((fd = mkstemp(tempfname)) == -1) {
-   perror(tempfname);
-   exit(1);
+   /*
+* We reuse the same temporary file name for multiple objects. However,
+* some libc implementations (such as glibc) return EINVAL if there
+* are no X characters in the template. This happens after the
+* first call to mkstemp since the argument is modified in-place.
+* To avoid this error we use open() instead of mkstemp() after the
+* call to mkstemp().
+*/
+   if (tempfname_initialized) {
+   if ((fd = open(tempfname, O_CREAT | O_EXCL | O_RDWR, 0600)) == 
-1) {
+   err(EX_OSERR, "open(%s)", tempfname);
+   }
+   } else if ((fd = mkstemp(tempfname)) == -1) {
+   err(EX_OSERR, "mkstemp(%s)", tempfname);
}
+   tempfname_initialized = true;
if ((f = fdopen(fd, "w")) == NULL) {
-   warn("%s", tempfname);
+   warn("fdopen(%s)", tempfname);
goterror = 1;
-   return;
+   goto out;
}
if (p->objvar)
objvar = p->objvar;
@@ -763,14 +779,14 @@ fillin_program_objs(prog_t *p, char *path)
if ((f = popen(line, "r")) == NULL) {
warn("submake pipe");
goterror = 1;
-   return;
+   goto out;
}
 
while(fgets(line, MAXLINELEN, f)) {
if (strncmp(line, "OBJS= ", 6)) {
warnx("make error: %s", line);
goterror = 1;
-   continue;
+   goto out;
}
 
cp = line + 6;
@@ -793,7 +809,7 @@ fillin_program_objs(prog_t *p, char *path)
warnx("make error: make returned %d", rc);
goterror = 1;
}
-
+out:
unlink(tempfname);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364165 - head/sys/net

2020-08-12 Thread Vincenzo Maffione
Author: vmaffione
Date: Wed Aug 12 14:45:31 2020
New Revision: 364165
URL: https://svnweb.freebsd.org/changeset/base/364165

Log:
  iflib: netmap: improve rxsync to support IFLIB_HAS_RXCQ
  
  For drivers with IFLIB_HAS_RXCQ set, there is a separate completion
  queue. In this case, the netmap rxsync routine needs to update
  rxq->ifr_cq_cidx in the same way it is updated by iflib_rxeof().
  This improves the situation for vmx(4) and bnxt(4) drivers, which
  use iflib and have the IFLIB_HAS_RXCQ bit set.
  
  PR:   248494
  MFC after:3 weeks

Modified:
  head/sys/net/iflib.c
  head/sys/net/iflib.h

Modified: head/sys/net/iflib.c
==
--- head/sys/net/iflib.cWed Aug 12 14:17:38 2020(r364164)
+++ head/sys/net/iflib.cWed Aug 12 14:45:31 2020(r364165)
@@ -424,7 +424,7 @@ struct iflib_rxq {
struct pfil_head*pfil;
/*
 * If there is a separate completion queue (IFLIB_HAS_RXCQ), this is
-* the command queue consumer index.  Otherwise it's unused.
+* the completion queue consumer index.  Otherwise it's unused.
 */
qidx_t  ifr_cq_cidx;
uint16_tifr_id;
@@ -1077,9 +1077,12 @@ iflib_netmap_rxsync(struct netmap_kring *kring, int fl
int force_update = (flags & NAF_FORCE_READ) || kring->nr_kflags & 
NKR_PENDINTR;
 
if_ctx_t ctx = ifp->if_softc;
+   if_shared_ctx_t sctx = ctx->ifc_sctx;
+   if_softc_ctx_t scctx = >ifc_softc_ctx;
iflib_rxq_t rxq = >ifc_rxqs[kring->ring_id];
iflib_fl_t fl = >ifr_fl[0];
struct if_rxd_info ri;
+   qidx_t *cidxp;
 
/*
 * netmap only uses free list 0, to avoid out of order consumption
@@ -1093,40 +1096,56 @@ iflib_netmap_rxsync(struct netmap_kring *kring, int fl
 * First part: import newly received packets.
 *
 * nm_i is the index of the next free slot in the netmap ring,
-* nic_i is the index of the next received packet in the NIC ring,
-* and they may differ in case if_init() has been called while
+* nic_i is the index of the next received packet in the NIC ring
+* (or in the free list 0 if IFLIB_HAS_RXCQ is set), and they may
+* differ in case if_init() has been called while
 * in netmap mode. For the receive ring we have
 *
-*  nic_i = rxr->next_check;
+*  nic_i = fl->ifl_cidx;
 *  nm_i = kring->nr_hwtail (previous)
 * and
 *  nm_i == (nic_i + kring->nkr_hwofs) % ring_size
 *
-* rxr->next_check is set to 0 on a ring reinit
+* fl->ifl_cidx is set to 0 on a ring reinit
 */
if (netmap_no_pendintr || force_update) {
uint32_t hwtail_lim = nm_prev(kring->nr_hwcur, lim);
+   bool have_rxcq = sctx->isc_flags & IFLIB_HAS_RXCQ;
int crclen = iflib_crcstrip ? 0 : 4;
int error, avail;
 
+   /*
+* For the free list consumer index, we use the same
+* logic as in iflib_rxeof().
+*/
+   if (have_rxcq)
+   cidxp = >ifr_cq_cidx;
+   else
+   cidxp = >ifl_cidx;
+   avail = ctx->isc_rxd_available(ctx->ifc_softc,
+   rxq->ifr_id, *cidxp, USHRT_MAX);
+
nic_i = fl->ifl_cidx;
nm_i = netmap_idx_n2k(kring, nic_i);
-   avail = ctx->isc_rxd_available(ctx->ifc_softc,
-   rxq->ifr_id, nic_i, USHRT_MAX);
for (n = 0; avail > 0 && nm_i != hwtail_lim; n++, avail--) {
rxd_info_zero();
ri.iri_frags = rxq->ifr_frags;
ri.iri_qsidx = kring->ring_id;
ri.iri_ifp = ctx->ifc_ifp;
-   ri.iri_cidx = nic_i;
+   ri.iri_cidx = *cidxp;
 
error = ctx->isc_rxd_pkt_get(ctx->ifc_softc, );
ring->slot[nm_i].len = error ? 0 : ri.iri_len - crclen;
ring->slot[nm_i].flags = 0;
+   if (have_rxcq) {
+   *cidxp = ri.iri_cidx;
+   while (*cidxp >= scctx->isc_nrxd[0])
+   *cidxp -= scctx->isc_nrxd[0];
+   }
bus_dmamap_sync(fl->ifl_buf_tag,
fl->ifl_sds.ifsd_map[nic_i], BUS_DMASYNC_POSTREAD);
nm_i = nm_next(nm_i, lim);
-   nic_i = nm_next(nic_i, lim);
+   fl->ifl_cidx = nic_i = nm_next(nic_i, lim);
}
if (n) { /* update the state variables */
if (netmap_no_pendintr && !force_update) {
@@ -1134,7 +1153,6 @@ iflib_netmap_rxsync(struct 

svn commit: r364164 - head/sys/net

2020-08-12 Thread Vincenzo Maffione
Author: vmaffione
Date: Wed Aug 12 14:17:38 2020
New Revision: 364164
URL: https://svnweb.freebsd.org/changeset/base/364164

Log:
  iflib: refactor netmap_fl_refill and fix off-by-one issue
  
  First, fix the initialization of the fl->ifl_rxd_idxs array,
  which was affected by an off-by-one bug.
  Once there, refactor the function to use better names for
  local variables, optimize the variable assignments, and
  merge the bus_dmamap_sync() inner loop with the outer one.
  
  PR:   248494
  MFC after:3 weeks

Modified:
  head/sys/net/iflib.c

Modified: head/sys/net/iflib.c
==
--- head/sys/net/iflib.cWed Aug 12 12:11:44 2020(r364163)
+++ head/sys/net/iflib.cWed Aug 12 14:17:38 2020(r364164)
@@ -838,39 +838,41 @@ netmap_fl_refill(iflib_rxq_t rxq, struct netmap_kring 
struct if_rxd_update iru;
if_ctx_t ctx = rxq->ifr_ctx;
iflib_fl_t fl = >ifr_fl[0];
-   uint32_t refill_pidx, nic_i;
+   uint32_t nic_i_first, nic_i;
+   int i;
 #if IFLIB_DEBUG_COUNTERS
int rf_count = 0;
 #endif
 
if (nm_i == head && __predict_true(!init))
-   return 0;
+   return (0);
+
iru_init(, rxq, 0 /* flid */);
map = fl->ifl_sds.ifsd_map;
-   refill_pidx = netmap_idx_k2n(kring, nm_i);
+   nic_i = netmap_idx_k2n(kring, nm_i);
/*
 * IMPORTANT: we must leave one free slot in the ring,
 * so move head back by one unit
 */
head = nm_prev(head, lim);
-   nic_i = UINT_MAX;
DBG_COUNTER_INC(fl_refills);
while (nm_i != head) {
 #if IFLIB_DEBUG_COUNTERS
if (++rf_count == 9)
DBG_COUNTER_INC(fl_refills_large);
 #endif
-   for (int tmp_pidx = 0; tmp_pidx < IFLIB_MAX_RX_REFRESH && nm_i 
!= head; tmp_pidx++) {
+   nic_i_first = nic_i;
+   for (i = 0; i < IFLIB_MAX_RX_REFRESH && nm_i != head; i++) {
struct netmap_slot *slot = >slot[nm_i];
-   void *addr = PNMB(na, slot, 
>ifl_bus_addrs[tmp_pidx]);
-   uint32_t nic_i_dma = refill_pidx;
-   nic_i = netmap_idx_k2n(kring, nm_i);
+   void *addr = PNMB(na, slot, >ifl_bus_addrs[i]);
 
-   MPASS(tmp_pidx < IFLIB_MAX_RX_REFRESH);
+   MPASS(i < IFLIB_MAX_RX_REFRESH);
 
if (addr == NETMAP_BUF_BASE(na)) /* bad buf */
return netmap_ring_reinit(kring);
 
+   fl->ifl_rxd_idxs[i] = nic_i;
+
if (__predict_false(init)) {
netmap_load_map(na, fl->ifl_buf_tag,
map[nic_i], addr);
@@ -879,33 +881,25 @@ netmap_fl_refill(iflib_rxq_t rxq, struct netmap_kring 
netmap_reload_map(na, fl->ifl_buf_tag,
map[nic_i], addr);
}
+   bus_dmamap_sync(fl->ifl_buf_tag, map[nic_i],
+   BUS_DMASYNC_PREREAD);
slot->flags &= ~NS_BUF_CHANGED;
 
nm_i = nm_next(nm_i, lim);
-   fl->ifl_rxd_idxs[tmp_pidx] = nic_i = nm_next(nic_i, 
lim);
-   if (nm_i != head && tmp_pidx < IFLIB_MAX_RX_REFRESH-1)
-   continue;
-
-   iru.iru_pidx = refill_pidx;
-   iru.iru_count = tmp_pidx+1;
-   ctx->isc_rxd_refill(ctx->ifc_softc, );
-   refill_pidx = nic_i;
-   for (int n = 0; n < iru.iru_count; n++) {
-   bus_dmamap_sync(fl->ifl_buf_tag, map[nic_i_dma],
-   BUS_DMASYNC_PREREAD);
-   /* XXX - change this to not use the netmap 
func*/
-   nic_i_dma = nm_next(nic_i_dma, lim);
-   }
+   nic_i = nm_next(nic_i, lim);
}
+
+   iru.iru_pidx = nic_i_first;
+   iru.iru_count = i;
+   ctx->isc_rxd_refill(ctx->ifc_softc, );
}
kring->nr_hwcur = head;
 
bus_dmamap_sync(fl->ifl_ifdi->idi_tag, fl->ifl_ifdi->idi_map,
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
-   if (__predict_true(nic_i != UINT_MAX)) {
-   ctx->isc_rxd_flush(ctx->ifc_softc, rxq->ifr_id, fl->ifl_id, 
nic_i);
-   DBG_COUNTER_INC(rxd_flush);
-   }
+   ctx->isc_rxd_flush(ctx->ifc_softc, rxq->ifr_id, fl->ifl_id, nic_i);
+   DBG_COUNTER_INC(rxd_flush);
+
return (0);
 }
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send 

svn commit: r364155 - head/share/man/man4

2020-08-12 Thread Andriy Gapon
Author: avg
Date: Wed Aug 12 11:37:28 2020
New Revision: 364155
URL: https://svnweb.freebsd.org/changeset/base/364155

Log:
  hook cp2112.4 to the build
  
  Reported by:  0mp
  MFC after:1 week
  X-MFC with:   r364144

Modified:
  head/share/man/man4/Makefile

Modified: head/share/man/man4/Makefile
==
--- head/share/man/man4/MakefileWed Aug 12 11:36:09 2020
(r364154)
+++ head/share/man/man4/MakefileWed Aug 12 11:37:28 2020
(r364155)
@@ -113,6 +113,7 @@ MAN=aac.4 \
cloudabi.4 \
cmx.4 \
${_coretemp.4} \
+   cp2112.4 \
${_cpuctl.4} \
cpufreq.4 \
crypto.4 \
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364154 - head/share/man/man4

2020-08-12 Thread Andriy Gapon
Author: avg
Date: Wed Aug 12 11:36:09 2020
New Revision: 364154
URL: https://svnweb.freebsd.org/changeset/base/364154

Log:
  hook gpiokeys.4 to the build
  
  Reported by:  0mp
  MFC after:3 days
  X-MFC with:   r363905

Modified:
  head/share/man/man4/Makefile

Modified: head/share/man/man4/Makefile
==
--- head/share/man/man4/MakefileWed Aug 12 10:17:17 2020
(r364153)
+++ head/share/man/man4/MakefileWed Aug 12 11:36:09 2020
(r364154)
@@ -171,6 +171,7 @@ MAN=aac.4 \
gif.4 \
gpio.4 \
gpioiic.4 \
+   gpiokeys.4 \
gpioled.4 \
gpioths.4 \
gre.4 \
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364153 - in head: lib/libpmc sys/arm64/include sys/dev/hwpmc sys/sys

2020-08-12 Thread Andrew Turner
Author: andrew
Date: Wed Aug 12 10:17:17 2020
New Revision: 364153
URL: https://svnweb.freebsd.org/changeset/base/364153

Log:
  Add support for Cortex-A76/Neoverse-N1 to hwpmc
  
  This adds support for the Cortex-A76 and Neoverse-N1 PMU counters to pmc.
  
  While here add more PMCR_IDCODE values and check the implementers code is
  correct before setting the PMU type.
  
  Reviewed by:  bz, emaste (looks reasonable to me)
  Sponsored by: Innovate UK
  Differential Revision:https://reviews.freebsd.org/D25959

Modified:
  head/lib/libpmc/libpmc.c
  head/sys/arm64/include/armreg.h
  head/sys/dev/hwpmc/hwpmc_arm64.c
  head/sys/dev/hwpmc/pmc_events.h
  head/sys/sys/pmc.h

Modified: head/lib/libpmc/libpmc.c
==
--- head/lib/libpmc/libpmc.cWed Aug 12 10:13:37 2020(r364152)
+++ head/lib/libpmc/libpmc.cWed Aug 12 10:17:17 2020(r364153)
@@ -176,6 +176,11 @@ static const struct pmc_event_descr cortex_a57_event_t
__PMC_EV_ALIAS_ARMV8_CORTEX_A57()
 };
 
+static const struct pmc_event_descr cortex_a76_event_table[] =
+{
+   __PMC_EV_ALIAS_ARMV8_CORTEX_A76()
+};
+
 /*
  * PMC_MDEP_TABLE(NAME, PRIMARYCLASS, ADDITIONAL_CLASSES...)
  *
@@ -193,6 +198,7 @@ PMC_MDEP_TABLE(cortex_a8, ARMV7, PMC_CLASS_SOFT, PMC_C
 PMC_MDEP_TABLE(cortex_a9, ARMV7, PMC_CLASS_SOFT, PMC_CLASS_ARMV7);
 PMC_MDEP_TABLE(cortex_a53, ARMV8, PMC_CLASS_SOFT, PMC_CLASS_ARMV8);
 PMC_MDEP_TABLE(cortex_a57, ARMV8, PMC_CLASS_SOFT, PMC_CLASS_ARMV8);
+PMC_MDEP_TABLE(cortex_a76, ARMV8, PMC_CLASS_SOFT, PMC_CLASS_ARMV8);
 PMC_MDEP_TABLE(mips24k, MIPS24K, PMC_CLASS_SOFT, PMC_CLASS_MIPS24K);
 PMC_MDEP_TABLE(mips74k, MIPS74K, PMC_CLASS_SOFT, PMC_CLASS_MIPS74K);
 PMC_MDEP_TABLE(octeon, OCTEON, PMC_CLASS_SOFT, PMC_CLASS_OCTEON);
@@ -235,6 +241,7 @@ PMC_CLASS_TABLE_DESC(cortex_a9, ARMV7, cortex_a9, armv
 #ifdefined(__aarch64__)
 PMC_CLASS_TABLE_DESC(cortex_a53, ARMV8, cortex_a53, arm64);
 PMC_CLASS_TABLE_DESC(cortex_a57, ARMV8, cortex_a57, arm64);
+PMC_CLASS_TABLE_DESC(cortex_a76, ARMV8, cortex_a76, arm64);
 #endif
 #if defined(__mips__)
 PMC_CLASS_TABLE_DESC(beri, BERI, beri, mips);
@@ -817,6 +824,9 @@ static struct pmc_event_alias cortex_a53_aliases[] = {
 static struct pmc_event_alias cortex_a57_aliases[] = {
EV_ALIAS(NULL, NULL)
 };
+static struct pmc_event_alias cortex_a76_aliases[] = {
+   EV_ALIAS(NULL, NULL)
+};
 static int
 arm64_allocate_pmc(enum pmc_event pe, char *ctrspec __unused,
 struct pmc_op_pmcallocate *pmc_config __unused)
@@ -1273,6 +1283,10 @@ pmc_event_names_of_class(enum pmc_class cl, const char
ev = cortex_a57_event_table;
count = PMC_EVENT_TABLE_SIZE(cortex_a57);
break;
+   case PMC_CPU_ARMV8_CORTEX_A76:
+   ev = cortex_a76_event_table;
+   count = PMC_EVENT_TABLE_SIZE(cortex_a76);
+   break;
}
break;
case PMC_CLASS_BERI:
@@ -1518,6 +1532,10 @@ pmc_init(void)
PMC_MDEP_INIT(cortex_a57);
pmc_class_table[n] = _a57_class_table_descr;
break;
+   case PMC_CPU_ARMV8_CORTEX_A76:
+   PMC_MDEP_INIT(cortex_a76);
+   pmc_class_table[n] = _a76_class_table_descr;
+   break;
 #endif
 #if defined(__mips__)
case PMC_CPU_MIPS_BERI:
@@ -1657,6 +1675,10 @@ _pmc_name_of_event(enum pmc_event pe, enum pmc_cputype
case PMC_CPU_ARMV8_CORTEX_A57:
ev = cortex_a57_event_table;
evfence = cortex_a57_event_table + 
PMC_EVENT_TABLE_SIZE(cortex_a57);
+   break;
+   case PMC_CPU_ARMV8_CORTEX_A76:
+   ev = cortex_a76_event_table;
+   evfence = cortex_a76_event_table + 
PMC_EVENT_TABLE_SIZE(cortex_a76);
break;
default:/* Unknown CPU type. */
break;

Modified: head/sys/arm64/include/armreg.h
==
--- head/sys/arm64/include/armreg.h Wed Aug 12 10:13:37 2020
(r364152)
+++ head/sys/arm64/include/armreg.h Wed Aug 12 10:17:17 2020
(r364153)
@@ -857,11 +857,20 @@
 #definePMCR_LC (1 << 6) /* Long cycle count enable */
 #definePMCR_IMP_SHIFT  24 /* Implementer code */
 #definePMCR_IMP_MASK   (0xff << PMCR_IMP_SHIFT)
+#define PMCR_IMP_ARM   0x41
 #definePMCR_IDCODE_SHIFT   16 /* Identification code */
 #definePMCR_IDCODE_MASK(0xff << PMCR_IDCODE_SHIFT)
-#define PMCR_IDCODE_CORTEX_A57 0x01
-#define PMCR_IDCODE_CORTEX_A72 0x02
-#define PMCR_IDCODE_CORTEX_A53 0x03
+#define PMCR_IDCODE_CORTEX_A57 0x01
+#define PMCR_IDCODE_CORTEX_A72 0x02

svn commit: r364149 - head/sys/arm/allwinner

2020-08-12 Thread Andriy Gapon
Author: avg
Date: Wed Aug 12 09:57:28 2020
New Revision: 364149
URL: https://svnweb.freebsd.org/changeset/base/364149

Log:
  aw_cir: in the pulse encoding the actual length is one greater than value
  
  While here change type of some variables from long to int, it's sufficient.
  Also, add length reporting to a couple of debug printfs.
  
  MFC after:3 weeks

Modified:
  head/sys/arm/allwinner/aw_cir.c

Modified: head/sys/arm/allwinner/aw_cir.c
==
--- head/sys/arm/allwinner/aw_cir.c Wed Aug 12 09:56:21 2020
(r364148)
+++ head/sys/arm/allwinner/aw_cir.c Wed Aug 12 09:57:28 2020
(r364149)
@@ -202,9 +202,9 @@ aw_ir_read_data(struct aw_ir_softc *sc)
 static unsigned long
 aw_ir_decode_packets(struct aw_ir_softc *sc)
 {
-   unsigned long len, code;
-   unsigned char val, last;
+   unsigned int len, code;
unsigned int active_delay;
+   unsigned char val, last;
int i, bitcount;
 
if (bootverbose)
@@ -215,11 +215,11 @@ aw_ir_decode_packets(struct aw_ir_softc *sc)
(AW_IR_ACTIVE_T_C_VAL != 0 ? 128 : 1);
len = active_delay;
if (bootverbose)
-   device_printf(sc->dev, "Initial len: %ld\n", len);
+   device_printf(sc->dev, "Initial len: %d\n", len);
for (i = 0;  i < sc->dcnt; i++) {
val = sc->buf[i];
if (val & VAL_MASK)
-   len += val & PERIOD_MASK;
+   len += (val & PERIOD_MASK) + 1;
else {
if (len > AW_IR_L1_MIN)
break;
@@ -227,7 +227,7 @@ aw_ir_decode_packets(struct aw_ir_softc *sc)
}
}
if (bootverbose)
-   device_printf(sc->dev, "len = %ld\n", len);
+   device_printf(sc->dev, "len = %d\n", len);
if ((val & VAL_MASK) || (len <= AW_IR_L1_MIN)) {
if (bootverbose)
device_printf(sc->dev, "Bit separator error\n");
@@ -243,7 +243,7 @@ aw_ir_decode_packets(struct aw_ir_softc *sc)
break;
len = 0;
} else
-   len += val & PERIOD_MASK;
+   len += (val & PERIOD_MASK) + 1;
}
if ((!(val & VAL_MASK)) || (len <= AW_IR_L0_MIN)) {
if (bootverbose)
@@ -260,23 +260,25 @@ aw_ir_decode_packets(struct aw_ir_softc *sc)
val = sc->buf[i];
if (last) {
if (val & VAL_MASK)
-   len += val & PERIOD_MASK;
+   len += (val & PERIOD_MASK) + 1;
else {
if (len > AW_IR_PMAX) {
if (bootverbose)
device_printf(sc->dev,
-   "Pulse error\n");
+   "Pulse error, len=%d\n",
+   len);
goto error_code;
}
last = 0;
-   len = val & PERIOD_MASK;
+   len = (val & PERIOD_MASK) + 1;
}
} else {
if (val & VAL_MASK) {
if (len > AW_IR_DMAX) {
if (bootverbose)
device_printf(sc->dev,
-   "Distant error\n");
+   "Distance error, len=%d\n",
+   len);
goto error_code;
} else {
if (len > AW_IR_DMID) {
@@ -288,9 +290,9 @@ aw_ir_decode_packets(struct aw_ir_softc *sc)
break;  /* Finish decoding */
}
last = 1;
-   len = val & PERIOD_MASK;
+   len = (val & PERIOD_MASK) + 1;
} else
-   len += val & PERIOD_MASK;
+   len += (val & PERIOD_MASK) + 1;
}
}
return (code);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364148 - head/sys/arm/allwinner

2020-08-12 Thread Andriy Gapon
Author: avg
Date: Wed Aug 12 09:56:21 2020
New Revision: 364148
URL: https://svnweb.freebsd.org/changeset/base/364148

Log:
  aw_cir: lower activation threshold to support NECx protocol
  
  In NECx the leading mark has length of 8T as opposed to 16T in NEC,
  where T is  562.5 us.  So, 4.5 ms.
  Our threshold was set to 128 * 42.7 us (derived from the sampling
  frequency of 3/128 MHz).  So, ~5.5 ms.
  
  The new threshold is set to AW_IR_L1_MIN.  I think that's a good enough
  lower bound for detecting the leading pulse.
  
  Also, calculations of active_delay (which is activation delay) are fixed.
  Previously they would be wrong if AW_IR_ACTIVE_T was anything but zero,
  because the value was already bit-shifted.
  
  Finally, I am not sure why the activation delay was divided by two when
  calculating the initial pulse length.  I have not found anything that
  would explain or justify it.  So, I removed that division.
  
  MFC after:3 weeks

Modified:
  head/sys/arm/allwinner/aw_cir.c

Modified: head/sys/arm/allwinner/aw_cir.c
==
--- head/sys/arm/allwinner/aw_cir.c Wed Aug 12 09:52:39 2020
(r364147)
+++ head/sys/arm/allwinner/aw_cir.c Wed Aug 12 09:56:21 2020
(r364148)
@@ -126,8 +126,10 @@ __FBSDID("$FreeBSD$");
 #defineAW_IR_DMAX  53
 
 /* Active Thresholds */
-#defineAW_IR_ACTIVE_T  ((0 & 0xff) << 16)
-#defineAW_IR_ACTIVE_T_C((1 & 0xff) << 23)
+#defineAW_IR_ACTIVE_T_VAL  AW_IR_L1_MIN
+#defineAW_IR_ACTIVE_T  (((AW_IR_ACTIVE_T_VAL - 1) & 
0xff) << 16)
+#defineAW_IR_ACTIVE_T_C_VAL0
+#defineAW_IR_ACTIVE_T_C((AW_IR_ACTIVE_T_C_VAL & 0xff) 
<< 23)
 
 /* Code masks */
 #defineCODE_MASK   0x00ff00ff
@@ -209,9 +211,9 @@ aw_ir_decode_packets(struct aw_ir_softc *sc)
device_printf(sc->dev, "sc->dcnt = %d\n", sc->dcnt);
 
/* Find Lead 1 (bit separator) */
-   active_delay = (AW_IR_ACTIVE_T + 1) * (AW_IR_ACTIVE_T_C != 0 ? 128 : 1);
-   len = 0;
-   len += (active_delay >> 1);
+   active_delay = AW_IR_ACTIVE_T_VAL *
+   (AW_IR_ACTIVE_T_C_VAL != 0 ? 128 : 1);
+   len = active_delay;
if (bootverbose)
device_printf(sc->dev, "Initial len: %ld\n", len);
for (i = 0;  i < sc->dcnt; i++) {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364147 - head/sys/arm/allwinner

2020-08-12 Thread Andriy Gapon
Author: avg
Date: Wed Aug 12 09:52:39 2020
New Revision: 364147
URL: https://svnweb.freebsd.org/changeset/base/364147

Log:
  aw_cir: minor cleanups
  
  MFC after:1 week

Modified:
  head/sys/arm/allwinner/aw_cir.c

Modified: head/sys/arm/allwinner/aw_cir.c
==
--- head/sys/arm/allwinner/aw_cir.c Wed Aug 12 09:52:12 2020
(r364146)
+++ head/sys/arm/allwinner/aw_cir.c Wed Aug 12 09:52:39 2020
(r364147)
@@ -368,7 +368,7 @@ aw_ir_intr(void *arg)
device_printf(sc->dev, "IR code status: %d\n",
stat);
}
-   sc->dcnt = 0;
+   aw_ir_buf_reset(sc);
}
if (val & AW_IR_RXINT_ROI_EN) {
/* RX FIFO overflow */
@@ -469,7 +469,8 @@ aw_ir_attach(device_t dev)
>intrhand)) {
bus_release_resources(dev, aw_ir_spec, sc->res);
device_printf(dev, "cannot setup interrupt handler\n");
-   return (ENXIO);
+   err = ENXIO;
+   goto error;
}
 
/* Enable CIR Mode */
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364146 - head/sys/arm/allwinner

2020-08-12 Thread Andriy Gapon
Author: avg
Date: Wed Aug 12 09:52:12 2020
New Revision: 364146
URL: https://svnweb.freebsd.org/changeset/base/364146

Log:
  aw_cir: add support for allwinner,sun6i-a31-ir (found, e.g., on h3)
  
  MFC after:1 week

Modified:
  head/sys/arm/allwinner/aw_cir.c

Modified: head/sys/arm/allwinner/aw_cir.c
==
--- head/sys/arm/allwinner/aw_cir.c Wed Aug 12 09:49:25 2020
(r364145)
+++ head/sys/arm/allwinner/aw_cir.c Wed Aug 12 09:52:12 2020
(r364146)
@@ -134,8 +134,11 @@ __FBSDID("$FreeBSD$");
 #defineINV_CODE_MASK   0xff00ff00
 #defineVALID_CODE_MASK 0x00ff
 
-#defineA10_IR  1
-#defineA13_IR  2
+enum {
+   A10_IR = 1,
+   A13_IR,
+   A31_IR,
+};
 
 #defineAW_IR_RAW_BUF_SIZE  128
 
@@ -158,6 +161,7 @@ static struct resource_spec aw_ir_spec[] = {
 static struct ofw_compat_data compat_data[] = {
{ "allwinner,sun4i-a10-ir", A10_IR },
{ "allwinner,sun5i-a13-ir", A13_IR },
+   { "allwinner,sun6i-a31-ir", A31_IR },
{ NULL, 0 }
 };
 
@@ -414,6 +418,7 @@ aw_ir_attach(device_t dev)
sc->fifo_size = 16;
break;
case A13_IR:
+   case A31_IR:
sc->fifo_size = 64;
break;
}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364145 - head/sys/dev/gpio

2020-08-12 Thread Andriy Gapon
Author: avg
Date: Wed Aug 12 09:49:25 2020
New Revision: 364145
URL: https://svnweb.freebsd.org/changeset/base/364145

Log:
  gpiokeys: add evdev support
  
  Only linux,code is supported as it maps 1:1 to evdev key codes.
  No reverse mapping for freebsd,code yet.
  
  Reviewed by:  wulf
  MFC after:3 weeks
  Differential Revision: https://reviews.freebsd.org/D25940

Modified:
  head/sys/dev/gpio/gpiokeys.c

Modified: head/sys/dev/gpio/gpiokeys.c
==
--- head/sys/dev/gpio/gpiokeys.cWed Aug 12 09:42:05 2020
(r364144)
+++ head/sys/dev/gpio/gpiokeys.cWed Aug 12 09:49:25 2020
(r364145)
@@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$");
 
 #include "opt_platform.h"
 #include "opt_kbd.h"
+#include "opt_evdev.h"
 
 #include 
 #include 
@@ -56,6 +57,11 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+#ifdef EVDEV_SUPPORT
+#include 
+#include 
+#endif
+
 #defineKBD_DRIVER_NAME "gpiokeys"
 
 #defineGPIOKEYS_LOCK(_sc)  mtx_lock(&(_sc)->sc_mtx)
@@ -99,6 +105,9 @@ struct gpiokey
struct resource *irq_res;
void*intr_hl;
struct mtx  mtx;
+#ifdef EVDEV_SUPPORT
+   uint32_tevcode;
+#endif
uint32_tkeycode;
int autorepeat;
struct callout  debounce_callout;
@@ -115,6 +124,9 @@ struct gpiokeys_softc
struct gpiokey  *sc_keys;
int sc_total_keys;
 
+#ifdef EVDEV_SUPPORT
+   struct evdev_dev*sc_evdev;
+#endif
keyboard_t  sc_kbd;
keymap_tsc_keymap;
accentmap_t sc_accmap;
@@ -171,26 +183,34 @@ gpiokeys_put_key(struct gpiokeys_softc *sc, uint32_t k
 }
 
 static void
-gpiokeys_key_event(struct gpiokeys_softc *sc, uint16_t keycode, int pressed)
+gpiokeys_key_event(struct gpiokeys_softc *sc, struct gpiokey *key, int pressed)
 {
-   uint32_t key;
+   uint32_t code;
 
-
-   key = keycode & SCAN_KEYCODE_MASK;
-
-   if (!pressed)
-   key |= KEY_RELEASE;
-
GPIOKEYS_LOCK(sc);
-   if (keycode & SCAN_PREFIX_E0)
-   gpiokeys_put_key(sc, 0xe0);
-   else if (keycode & SCAN_PREFIX_E1)
-   gpiokeys_put_key(sc, 0xe1);
+#ifdef EVDEV_SUPPORT
+   if (key->evcode != GPIOKEY_NONE &&
+   (evdev_rcpt_mask & EVDEV_RCPT_HW_KBD) != 0) {
+   evdev_push_key(sc->sc_evdev, key->evcode, pressed);
+   evdev_sync(sc->sc_evdev);
+   }
+#endif
+   if (key->keycode != GPIOKEY_NONE) {
+   code = key->keycode & SCAN_KEYCODE_MASK;
+   if (!pressed)
+   code |= KEY_RELEASE;
 
-   gpiokeys_put_key(sc, key);
+   if (key->keycode & SCAN_PREFIX_E0)
+   gpiokeys_put_key(sc, 0xe0);
+   else if (key->keycode & SCAN_PREFIX_E1)
+   gpiokeys_put_key(sc, 0xe1);
+
+   gpiokeys_put_key(sc, code);
+   }
GPIOKEYS_UNLOCK(sc);
 
-   gpiokeys_event_keyinput(sc);
+   if (key->keycode != GPIOKEY_NONE)
+   gpiokeys_event_keyinput(sc);
 }
 
 static void
@@ -200,11 +220,8 @@ gpiokey_autorepeat(void *arg)
 
key = arg;
 
-   if (key->keycode == GPIOKEY_NONE)
-   return;
+   gpiokeys_key_event(key->parent_sc, key, 1);
 
-   gpiokeys_key_event(key->parent_sc, key->keycode, 1);
-
callout_reset(>repeat_callout, key->repeat,
gpiokey_autorepeat, key);
 }
@@ -217,12 +234,9 @@ gpiokey_debounced_intr(void *arg)
 
key = arg;
 
-   if (key->keycode == GPIOKEY_NONE)
-   return;
-
gpio_pin_is_active(key->pin, );
if (active) {
-   gpiokeys_key_event(key->parent_sc, key->keycode, 1);
+   gpiokeys_key_event(key->parent_sc, key, 1);
if (key->autorepeat) {
callout_reset(>repeat_callout, key->repeat_delay,
gpiokey_autorepeat, key);
@@ -232,7 +246,7 @@ gpiokey_debounced_intr(void *arg)
if (key->autorepeat &&
callout_pending(>repeat_callout))
callout_stop(>repeat_callout);
-   gpiokeys_key_event(key->parent_sc, key->keycode, 0);
+   gpiokeys_key_event(key->parent_sc, key, 0);
}
 }
 
@@ -301,6 +315,10 @@ gpiokeys_attach_key(struct gpiokeys_softc *sc, phandle
if (key->keycode == GPIOKEY_NONE)
device_printf(sc->sc_dev, "<%s> failed to map 
linux,code value 0x%x\n",
key_name, code);
+#ifdef EVDEV_SUPPORT
+   key->evcode = code;
+   evdev_support_key(sc->sc_evdev, code);
+#endif
}
else
device_printf(sc->sc_dev, "<%s> no linux,code or freebsd,code 
property\n",
@@ -365,7 +383,6 @@ 

svn commit: r364144 - head/share/man/man4

2020-08-12 Thread Andriy Gapon
Author: avg
Date: Wed Aug 12 09:42:05 2020
New Revision: 364144
URL: https://svnweb.freebsd.org/changeset/base/364144

Log:
  add a manual page for cp2112
  
  MFC after:1 week

Added:
  head/share/man/man4/cp2112.4   (contents, props changed)

Added: head/share/man/man4/cp2112.4
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/share/man/man4/cp2112.4Wed Aug 12 09:42:05 2020
(r364144)
@@ -0,0 +1,87 @@
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+.\"
+.\" Copyright (c) 2020 Andriy Gapon 
+.\"
+.\" 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 August 12, 2020
+.Dt CP2112 4
+.Os
+.Sh NAME
+.Nm cp2112
+.Nd driver for a USB GPIO and I2C peripheral device
+.Sh SYNOPSIS
+To compile this driver into the kernel,
+place the following lines in your
+kernel configuration file:
+.Bd -ragged -offset indent
+.Cd "device cp2112"
+.Cd "device usb"
+.Cd "device gpio"
+.Cd "device iicbus"
+.Ed
+.Pp
+Alternatively, to load the driver as a
+module at boot time, place the following line in
+.Xr loader.conf 5 :
+.Bd -literal -offset indent
+cp2112_load="YES"
+.Ed
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for Silicon Labs CP2112 device.
+The device has 8 general purpose I/O pins and an I2C controller that supports
+a subset of the I2C protocol.
+.Pp
+All pins support both input and output modes.
+An output pin can be configured either for open-drain or push-pull operation.
+Pins 0, 1 and 7 support special functions: I2C transmit indication,
+I2C receive indication and clock output respectively.
+At the moment the
+.Nm
+driver does not provide a way to enable and configure the special functions.
+.Pp
+The I2C controller supports read transactions with up to 512 bytes of data,
+write transactions with up to 61 bytes of data and a write followed by
+the repeated start followed by a read transactions where the write can be
+up to 16 bytes and the read can be up to 512 bytes.
+Zero length transfers are not supported.
+The
+.Nm
+driver creates a
+.Xr gpio 4
+and
+.Xr iicbus 4
+child buses to expose the respective functions.
+.Sh SEE ALSO
+.Xr gpio 4 ,
+.Xr iicbus 4 ,
+.Xr usb 4
+.Sh HISTORY
+The
+.Nm
+driver and this manual page was written by
+.An Andriy Gapon Aq Mt a...@freebsd.org .
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r364143 - head/sys/dev/usb/misc

2020-08-12 Thread Andriy Gapon
Author: avg
Date: Wed Aug 12 09:07:07 2020
New Revision: 364143
URL: https://svnweb.freebsd.org/changeset/base/364143

Log:
  cp2112: a number of cleanups and improvements
  
  - hoist all request / response structures from function level to top level
  - replace magic numeric literals with constants
  - regroup types, data and functions
  - remove setting of the id field in responses as they are completely
overwritten with data from the device
  - centralize setting of the id field as it is always set to the value of
request type
  - fix setting and querying of open-drain vs push-pull configuration of
an output pin -- it's always in one of those configurations
  - detect special pin configurations: a pin in a special configuration is
neither general purpose input or output
  - there is still no support for setting special configurations
  
  MFC after:2 weeks

Modified:
  head/sys/dev/usb/misc/cp2112.c

Modified: head/sys/dev/usb/misc/cp2112.c
==
--- head/sys/dev/usb/misc/cp2112.c  Wed Aug 12 07:00:06 2020
(r364142)
+++ head/sys/dev/usb/misc/cp2112.c  Wed Aug 12 09:07:07 2020
(r364143)
@@ -66,6 +66,8 @@ __FBSDID("$FreeBSD$");
 #defineUSB_DEBUG_VAR usb_debug
 #include 
 
+#defineSIZEOF_FIELD(_s, _f)sizeof(((struct _s *)NULL)->_f)
+
 #defineCP2112GPIO_LOCK(sc) sx_xlock(>gpio_lock)
 #defineCP2112GPIO_UNLOCK(sc)   sx_xunlock(>gpio_lock)
 #defineCP2112GPIO_LOCKED(sc)   sx_assert(>gpio_lock, SX_XLOCKED)
@@ -93,8 +95,13 @@ __FBSDID("$FreeBSD$");
 #defineCP2112_REQ_LOCK 0x20
 #defineCP2112_REQ_USB_CFG  0x21
 
+#defineCP2112_IIC_MAX_READ_LEN 512
 #defineCP2112_IIC_REPSTART_VER 2   /* Erratum CP2112_E10. 
*/
 
+#defineCP2112_GPIO_SPEC_CLK7   1   /* Pin 7 is clock 
output. */
+#defineCP2112_GPIO_SPEC_TX02   /* Pin 0 pulses on USB 
TX. */
+#defineCP2112_GPIO_SPEC_RX14   /* Pin 1 pulses on USB 
RX. */
+
 #defineCP2112_IIC_STATUS0_IDLE 0
 #defineCP2112_IIC_STATUS0_BUSY 1
 #defineCP2112_IIC_STATUS0_CMP  2
@@ -104,7 +111,112 @@ __FBSDID("$FreeBSD$");
 #defineCP2112_IIC_STATUS1_TIMEOUT_BUS  1
 #defineCP2112_IIC_STATUS1_ARB_LOST 2
 
+/* CP2112_REQ_VERSION */
+struct version_request {
+   uint8_t id;
+   uint8_t part_num;
+   uint8_t version;
+} __packed;
 
+/* CP2112_REQ_GPIO_GET */
+struct gpio_get_req {
+   uint8_t id;
+   uint8_t state;
+} __packed;
+
+/* CP2112_REQ_GPIO_SET */
+struct gpio_set_req {
+   uint8_t id;
+   uint8_t state;
+   uint8_t mask;
+} __packed;
+
+/* CP2112_REQ_GPIO_CFG */
+struct gpio_config_req {
+   uint8_t id;
+   uint8_t output;
+   uint8_t pushpull;
+   uint8_t special;
+   uint8_t divider;
+} __packed;
+
+/* CP2112_REQ_SMB_XFER_STATUS_REQ */
+struct i2c_xfer_status_req {
+   uint8_t id;
+   uint8_t request;
+} __packed;
+
+/* CP2112_REQ_SMB_XFER_STATUS_RESP */
+struct i2c_xfer_status_resp {
+   uint8_t id;
+   uint8_t status0;
+   uint8_t status1;
+   uint16_t status2;
+   uint16_t status3;
+} __packed;
+
+/* CP2112_REQ_SMB_READ_FORCE_SEND */
+struct i2c_data_read_force_send_req {
+   uint8_t id;
+   uint16_t len;
+} __packed;
+
+/* CP2112_REQ_SMB_READ_RESPONSE */
+struct i2c_data_read_resp {
+   uint8_t id;
+   uint8_t status;
+   uint8_t len;
+   uint8_t data[61];
+} __packed;
+
+/* CP2112_REQ_SMB_READ */
+struct i2c_write_read_req {
+   uint8_t id;
+   uint8_t slave;
+   uint16_t rlen;
+   uint8_t wlen;
+   uint8_t wdata[16];
+} __packed;
+
+/* CP2112_REQ_SMB_WRITE */
+struct i2c_read_req {
+   uint8_t id;
+   uint8_t slave;
+   uint16_t len;
+} __packed;
+
+/* CP2112_REQ_SMB_WRITE_READ */
+struct i2c_write_req {
+   uint8_t id;
+   uint8_t slave;
+   uint8_t len;
+   uint8_t data[61];
+} __packed;
+
+/* CP2112_REQ_SMB_CFG */
+struct i2c_cfg_req {
+   uint8_t id;
+   uint32_tspeed;  /* Hz */
+   uint8_t slave_addr; /* ACK only */
+   uint8_t auto_send_read; /* boolean */
+   uint16_twrite_timeout;  /* 0-1000 ms, 0 ~ no timeout */
+   uint16_tread_timeout;   /* 0-1000 ms, 0 ~ no timeout */
+   uint8_t scl_low_timeout;/* boolean */
+   uint16_tretry_count;/* 1-1000, 0 ~ forever */
+} __packed;
+
+enum cp2112_out_mode {
+   OUT_OD,
+   OUT_PP,
+   OUT_KEEP
+};
+
+enum {
+   CP2112_INTR_OUT = 0,
+   CP2112_INTR_IN,
+   CP2112_N_TRANSFER,
+};
+
 struct cp2112_softc {
device_tsc_gpio_dev;
device_tsc_iic_dev;
@@ -120,10 +232,38 @@ struct cp2112gpio_softc {
struct gpio_pin