RE: [PATCH v2 4/9] NTB: Alter MW API to support multi-ports devices
From: Serge Semin > Multi-port NTB devices permit to share a memory between all accessible peers. > Memory Windows API is altered to correspondingly initialize and map memory > windows for such devices: > ntb_mw_count(pidx); - number of inbound memory windows, which can be > allocated > for shared buffer with specified peer device. > ntb_mw_get_align(pidx, widx); - get alignment and size restrition parameters > to properly allocate inbound memory region. > ntb_peer_mw_count(); - get number of outbound memory windows. > ntb_peer_mw_get_addr(widx); - get mapping address of an outbound memory > window > > If hardware supports inbound translation configured on the local ntb port: > ntb_mw_set_trans(pidx, widx); - set translation address of allocated inbound > memory window so a peer device could access it. > ntb_mw_clear_trans(pidx, widx); - clear the translation address of an inbound > memory window. > > If hadrware supports outbound translation configured on the peer ntb port: s/hadrware/hardware/ > ntb_peer_mw_set_trans(pidx, widx); - set translation address of a memory > window retrieved from a peer device > ntb_peer_mw_clear_trans(pidx, widx); - clear the translation address of an > outbound memory window > > Signed-off-by: Serge Semin > > --- > drivers/ntb/hw/amd/ntb_hw_amd.c | 68 +--- > drivers/ntb/hw/amd/ntb_hw_amd.h | 2 + > drivers/ntb/hw/intel/ntb_hw_intel.c | 90 > drivers/ntb/hw/intel/ntb_hw_intel.h | 2 + > drivers/ntb/ntb.c | 2 + > drivers/ntb/ntb_transport.c | 21 +++- > drivers/ntb/test/ntb_perf.c | 17 ++- > drivers/ntb/test/ntb_tool.c | 43 +--- > include/linux/ntb.h | 208 > > 9 files changed, 346 insertions(+), 107 deletions(-) > > diff --git a/drivers/ntb/hw/amd/ntb_hw_amd.c b/drivers/ntb/hw/amd/ntb_hw_amd.c > index b6a4291..74fe9b8 100644 > --- a/drivers/ntb/hw/amd/ntb_hw_amd.c > +++ b/drivers/ntb/hw/amd/ntb_hw_amd.c > @@ -5,6 +5,7 @@ > * GPL LICENSE SUMMARY > * > * Copyright (C) 2016 Advanced Micro Devices, Inc. All Rights Reserved. > + * Copyright (C) 2016 T-Platforms. All Rights Reserved. > * > * This program is free software; you can redistribute it and/or modify > * it under the terms of version 2 of the GNU General Public License as > @@ -13,6 +14,7 @@ > * BSD LICENSE > * > * Copyright (C) 2016 Advanced Micro Devices, Inc. All Rights Reserved. > + * Copyright (C) 2016 T-Platforms. All Rights Reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions > @@ -213,40 +215,42 @@ static int ndev_mw_to_bar(struct amd_ntb_dev *ndev, int > idx) > return 1 << idx; > } > > -static int amd_ntb_mw_count(struct ntb_dev *ntb) > +static int amd_ntb_mw_count(struct ntb_dev *ntb, int pidx) > { > + if (pidx > NTB_PIDX_MAX) > + return -EINVAL; pidx may be negative. This should be if (pidx != 0) with some named constant for zero, or just if (pidx). Similarly apply this comment below. > + > return ntb_ndev(ntb)->mw_count; > } > > -static int amd_ntb_mw_get_range(struct ntb_dev *ntb, int idx, > - phys_addr_t *base, > - resource_size_t *size, > - resource_size_t *align, > - resource_size_t *align_size) > +static int amd_ntb_mw_get_align(struct ntb_dev *ntb, int pidx, int idx, > + resource_size_t *addr_align, > + resource_size_t *size_align, > + resource_size_t *size_max) > { > struct amd_ntb_dev *ndev = ntb_ndev(ntb); > int bar; > > + if (pidx > NTB_PIDX_MAX) > + return -EINVAL; > + > bar = ndev_mw_to_bar(ndev, idx); > if (bar < 0) > return bar; > > - if (base) > - *base = pci_resource_start(ndev->ntb.pdev, bar); > - > - if (size) > - *size = pci_resource_len(ndev->ntb.pdev, bar); > + if (addr_align) > + *addr_align = SZ_4K; > > - if (align) > - *align = SZ_4K; > + if (size_align) > + *size_align = 1; > > - if (align_size) > - *align_size = 1; > + if (size_max) > + *size_max = pci_resource_len(ndev->ntb.pdev, bar); > > return 0; > } > > -static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int idx, > +static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx, > dma_addr_t addr, resource_size_t size) > { > struct amd_ntb_dev *ndev = ntb_ndev(ntb); > @@ -256,6 +260,9 @@ static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int > idx, > u64 base_addr, limit, reg_val; > int bar; > > + if (pidx > NTB_PIDX_MAX) > + return -EINV
[PATCH v2 4/9] NTB: Alter MW API to support multi-ports devices
Multi-port NTB devices permit to share a memory between all accessible peers. Memory Windows API is altered to correspondingly initialize and map memory windows for such devices: ntb_mw_count(pidx); - number of inbound memory windows, which can be allocated for shared buffer with specified peer device. ntb_mw_get_align(pidx, widx); - get alignment and size restrition parameters to properly allocate inbound memory region. ntb_peer_mw_count(); - get number of outbound memory windows. ntb_peer_mw_get_addr(widx); - get mapping address of an outbound memory window If hardware supports inbound translation configured on the local ntb port: ntb_mw_set_trans(pidx, widx); - set translation address of allocated inbound memory window so a peer device could access it. ntb_mw_clear_trans(pidx, widx); - clear the translation address of an inbound memory window. If hadrware supports outbound translation configured on the peer ntb port: ntb_peer_mw_set_trans(pidx, widx); - set translation address of a memory window retrieved from a peer device ntb_peer_mw_clear_trans(pidx, widx); - clear the translation address of an outbound memory window Signed-off-by: Serge Semin --- drivers/ntb/hw/amd/ntb_hw_amd.c | 68 +--- drivers/ntb/hw/amd/ntb_hw_amd.h | 2 + drivers/ntb/hw/intel/ntb_hw_intel.c | 90 drivers/ntb/hw/intel/ntb_hw_intel.h | 2 + drivers/ntb/ntb.c | 2 + drivers/ntb/ntb_transport.c | 21 +++- drivers/ntb/test/ntb_perf.c | 17 ++- drivers/ntb/test/ntb_tool.c | 43 +--- include/linux/ntb.h | 208 9 files changed, 346 insertions(+), 107 deletions(-) diff --git a/drivers/ntb/hw/amd/ntb_hw_amd.c b/drivers/ntb/hw/amd/ntb_hw_amd.c index b6a4291..74fe9b8 100644 --- a/drivers/ntb/hw/amd/ntb_hw_amd.c +++ b/drivers/ntb/hw/amd/ntb_hw_amd.c @@ -5,6 +5,7 @@ * GPL LICENSE SUMMARY * * Copyright (C) 2016 Advanced Micro Devices, Inc. All Rights Reserved. + * Copyright (C) 2016 T-Platforms. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of version 2 of the GNU General Public License as @@ -13,6 +14,7 @@ * BSD LICENSE * * Copyright (C) 2016 Advanced Micro Devices, Inc. All Rights Reserved. + * Copyright (C) 2016 T-Platforms. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -213,40 +215,42 @@ static int ndev_mw_to_bar(struct amd_ntb_dev *ndev, int idx) return 1 << idx; } -static int amd_ntb_mw_count(struct ntb_dev *ntb) +static int amd_ntb_mw_count(struct ntb_dev *ntb, int pidx) { + if (pidx > NTB_PIDX_MAX) + return -EINVAL; + return ntb_ndev(ntb)->mw_count; } -static int amd_ntb_mw_get_range(struct ntb_dev *ntb, int idx, - phys_addr_t *base, - resource_size_t *size, - resource_size_t *align, - resource_size_t *align_size) +static int amd_ntb_mw_get_align(struct ntb_dev *ntb, int pidx, int idx, + resource_size_t *addr_align, + resource_size_t *size_align, + resource_size_t *size_max) { struct amd_ntb_dev *ndev = ntb_ndev(ntb); int bar; + if (pidx > NTB_PIDX_MAX) + return -EINVAL; + bar = ndev_mw_to_bar(ndev, idx); if (bar < 0) return bar; - if (base) - *base = pci_resource_start(ndev->ntb.pdev, bar); - - if (size) - *size = pci_resource_len(ndev->ntb.pdev, bar); + if (addr_align) + *addr_align = SZ_4K; - if (align) - *align = SZ_4K; + if (size_align) + *size_align = 1; - if (align_size) - *align_size = 1; + if (size_max) + *size_max = pci_resource_len(ndev->ntb.pdev, bar); return 0; } -static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int idx, +static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int pidx, int idx, dma_addr_t addr, resource_size_t size) { struct amd_ntb_dev *ndev = ntb_ndev(ntb); @@ -256,6 +260,9 @@ static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int idx, u64 base_addr, limit, reg_val; int bar; + if (pidx > NTB_PIDX_MAX) + return -EINVAL; + bar = ndev_mw_to_bar(ndev, idx); if (bar < 0) return bar; @@ -328,6 +335,31 @@ static int amd_ntb_mw_set_trans(struct ntb_dev *ntb, int idx, return 0; } +static int amd_ntb_peer_mw_count(struct ntb_dev *ntb) +{ + /* The same as for inbound MWs */ + return ntb_ndev(ntb)->mw_count; +} + +static