aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandre Bounine <alexandre.bounine@idt.com>2016-05-05 19:22:06 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-05 20:38:53 -0400
commit4e1016dac1ccce6d8a960775526cdc3a5baa690b (patch)
treefd553229938878ba56cc18c95b0918327b92236c
parent4550c4e157ca3da929593bb6c64080a59141af35 (diff)
rapidio/mport_cdev: fix uapi type definitions
Fix problems in uapi definitions reported by Gabriel Laskar: (see https://lkml.org/lkml/2016/4/5/205 for details) - move public header file rio_mport_cdev.h to include/uapi/linux directory - change types in data structures passed as IOCTL parameters - improve parameter checking in some IOCTL service routines Signed-off-by: Alexandre Bounine <alexandre.bounine@idt.com> Reported-by: Gabriel Laskar <gabriel@lse.epita.fr> Tested-by: Barry Wood <barry.wood@idt.com> Cc: Gabriel Laskar <gabriel@lse.epita.fr> Cc: Matt Porter <mporter@kernel.crashing.org> Cc: Aurelien Jacquiot <a-jacquiot@ti.com> Cc: Andre van Herk <andre.van.herk@prodrive-technologies.com> Cc: Barry Wood <barry.wood@idt.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/rapidio/devices/rio_mport_cdev.c115
-rw-r--r--include/uapi/linux/rio_mport_cdev.h (renamed from include/linux/rio_mport_cdev.h)144
2 files changed, 139 insertions, 120 deletions
diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
index 96168b819044..e165b7ce29d7 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -126,7 +126,7 @@ struct rio_mport_mapping {
126 struct list_head node; 126 struct list_head node;
127 struct mport_dev *md; 127 struct mport_dev *md;
128 enum rio_mport_map_dir dir; 128 enum rio_mport_map_dir dir;
129 u32 rioid; 129 u16 rioid;
130 u64 rio_addr; 130 u64 rio_addr;
131 dma_addr_t phys_addr; /* for mmap */ 131 dma_addr_t phys_addr; /* for mmap */
132 void *virt_addr; /* kernel address, for dma_free_coherent */ 132 void *virt_addr; /* kernel address, for dma_free_coherent */
@@ -137,7 +137,7 @@ struct rio_mport_mapping {
137 137
138struct rio_mport_dma_map { 138struct rio_mport_dma_map {
139 int valid; 139 int valid;
140 uint64_t length; 140 u64 length;
141 void *vaddr; 141 void *vaddr;
142 dma_addr_t paddr; 142 dma_addr_t paddr;
143}; 143};
@@ -208,7 +208,7 @@ struct mport_cdev_priv {
208 struct kfifo event_fifo; 208 struct kfifo event_fifo;
209 wait_queue_head_t event_rx_wait; 209 wait_queue_head_t event_rx_wait;
210 spinlock_t fifo_lock; 210 spinlock_t fifo_lock;
211 unsigned int event_mask; /* RIO_DOORBELL, RIO_PORTWRITE */ 211 u32 event_mask; /* RIO_DOORBELL, RIO_PORTWRITE */
212#ifdef CONFIG_RAPIDIO_DMA_ENGINE 212#ifdef CONFIG_RAPIDIO_DMA_ENGINE
213 struct dma_chan *dmach; 213 struct dma_chan *dmach;
214 struct list_head async_list; 214 struct list_head async_list;
@@ -276,7 +276,8 @@ static int rio_mport_maint_rd(struct mport_cdev_priv *priv, void __user *arg,
276 return -EFAULT; 276 return -EFAULT;
277 277
278 if ((maint_io.offset % 4) || 278 if ((maint_io.offset % 4) ||
279 (maint_io.length == 0) || (maint_io.length % 4)) 279 (maint_io.length == 0) || (maint_io.length % 4) ||
280 (maint_io.length + maint_io.offset) > RIO_MAINT_SPACE_SZ)
280 return -EINVAL; 281 return -EINVAL;
281 282
282 buffer = vmalloc(maint_io.length); 283 buffer = vmalloc(maint_io.length);
@@ -298,7 +299,8 @@ static int rio_mport_maint_rd(struct mport_cdev_priv *priv, void __user *arg,
298 offset += 4; 299 offset += 4;
299 } 300 }
300 301
301 if (unlikely(copy_to_user(maint_io.buffer, buffer, maint_io.length))) 302 if (unlikely(copy_to_user((void __user *)(uintptr_t)maint_io.buffer,
303 buffer, maint_io.length)))
302 ret = -EFAULT; 304 ret = -EFAULT;
303out: 305out:
304 vfree(buffer); 306 vfree(buffer);
@@ -319,7 +321,8 @@ static int rio_mport_maint_wr(struct mport_cdev_priv *priv, void __user *arg,
319 return -EFAULT; 321 return -EFAULT;
320 322
321 if ((maint_io.offset % 4) || 323 if ((maint_io.offset % 4) ||
322 (maint_io.length == 0) || (maint_io.length % 4)) 324 (maint_io.length == 0) || (maint_io.length % 4) ||
325 (maint_io.length + maint_io.offset) > RIO_MAINT_SPACE_SZ)
323 return -EINVAL; 326 return -EINVAL;
324 327
325 buffer = vmalloc(maint_io.length); 328 buffer = vmalloc(maint_io.length);
@@ -327,7 +330,8 @@ static int rio_mport_maint_wr(struct mport_cdev_priv *priv, void __user *arg,
327 return -ENOMEM; 330 return -ENOMEM;
328 length = maint_io.length; 331 length = maint_io.length;
329 332
330 if (unlikely(copy_from_user(buffer, maint_io.buffer, length))) { 333 if (unlikely(copy_from_user(buffer,
334 (void __user *)(uintptr_t)maint_io.buffer, length))) {
331 ret = -EFAULT; 335 ret = -EFAULT;
332 goto out; 336 goto out;
333 } 337 }
@@ -360,7 +364,7 @@ out:
360 */ 364 */
361static int 365static int
362rio_mport_create_outbound_mapping(struct mport_dev *md, struct file *filp, 366rio_mport_create_outbound_mapping(struct mport_dev *md, struct file *filp,
363 u32 rioid, u64 raddr, u32 size, 367 u16 rioid, u64 raddr, u32 size,
364 dma_addr_t *paddr) 368 dma_addr_t *paddr)
365{ 369{
366 struct rio_mport *mport = md->mport; 370 struct rio_mport *mport = md->mport;
@@ -369,7 +373,7 @@ rio_mport_create_outbound_mapping(struct mport_dev *md, struct file *filp,
369 373
370 rmcd_debug(OBW, "did=%d ra=0x%llx sz=0x%x", rioid, raddr, size); 374 rmcd_debug(OBW, "did=%d ra=0x%llx sz=0x%x", rioid, raddr, size);
371 375
372 map = kzalloc(sizeof(struct rio_mport_mapping), GFP_KERNEL); 376 map = kzalloc(sizeof(*map), GFP_KERNEL);
373 if (map == NULL) 377 if (map == NULL)
374 return -ENOMEM; 378 return -ENOMEM;
375 379
@@ -394,7 +398,7 @@ err_map_outb:
394 398
395static int 399static int
396rio_mport_get_outbound_mapping(struct mport_dev *md, struct file *filp, 400rio_mport_get_outbound_mapping(struct mport_dev *md, struct file *filp,
397 u32 rioid, u64 raddr, u32 size, 401 u16 rioid, u64 raddr, u32 size,
398 dma_addr_t *paddr) 402 dma_addr_t *paddr)
399{ 403{
400 struct rio_mport_mapping *map; 404 struct rio_mport_mapping *map;
@@ -433,7 +437,7 @@ static int rio_mport_obw_map(struct file *filp, void __user *arg)
433 dma_addr_t paddr; 437 dma_addr_t paddr;
434 int ret; 438 int ret;
435 439
436 if (unlikely(copy_from_user(&map, arg, sizeof(struct rio_mmap)))) 440 if (unlikely(copy_from_user(&map, arg, sizeof(map))))
437 return -EFAULT; 441 return -EFAULT;
438 442
439 rmcd_debug(OBW, "did=%d ra=0x%llx sz=0x%llx", 443 rmcd_debug(OBW, "did=%d ra=0x%llx sz=0x%llx",
@@ -448,7 +452,7 @@ static int rio_mport_obw_map(struct file *filp, void __user *arg)
448 452
449 map.handle = paddr; 453 map.handle = paddr;
450 454
451 if (unlikely(copy_to_user(arg, &map, sizeof(struct rio_mmap)))) 455 if (unlikely(copy_to_user(arg, &map, sizeof(map))))
452 return -EFAULT; 456 return -EFAULT;
453 return 0; 457 return 0;
454} 458}
@@ -469,7 +473,7 @@ static int rio_mport_obw_free(struct file *filp, void __user *arg)
469 if (!md->mport->ops->unmap_outb) 473 if (!md->mport->ops->unmap_outb)
470 return -EPROTONOSUPPORT; 474 return -EPROTONOSUPPORT;
471 475
472 if (copy_from_user(&handle, arg, sizeof(u64))) 476 if (copy_from_user(&handle, arg, sizeof(handle)))
473 return -EFAULT; 477 return -EFAULT;
474 478
475 rmcd_debug(OBW, "h=0x%llx", handle); 479 rmcd_debug(OBW, "h=0x%llx", handle);
@@ -498,9 +502,9 @@ static int rio_mport_obw_free(struct file *filp, void __user *arg)
498static int maint_hdid_set(struct mport_cdev_priv *priv, void __user *arg) 502static int maint_hdid_set(struct mport_cdev_priv *priv, void __user *arg)
499{ 503{
500 struct mport_dev *md = priv->md; 504 struct mport_dev *md = priv->md;
501 uint16_t hdid; 505 u16 hdid;
502 506
503 if (copy_from_user(&hdid, arg, sizeof(uint16_t))) 507 if (copy_from_user(&hdid, arg, sizeof(hdid)))
504 return -EFAULT; 508 return -EFAULT;
505 509
506 md->mport->host_deviceid = hdid; 510 md->mport->host_deviceid = hdid;
@@ -520,9 +524,9 @@ static int maint_hdid_set(struct mport_cdev_priv *priv, void __user *arg)
520static int maint_comptag_set(struct mport_cdev_priv *priv, void __user *arg) 524static int maint_comptag_set(struct mport_cdev_priv *priv, void __user *arg)
521{ 525{
522 struct mport_dev *md = priv->md; 526 struct mport_dev *md = priv->md;
523 uint32_t comptag; 527 u32 comptag;
524 528
525 if (copy_from_user(&comptag, arg, sizeof(uint32_t))) 529 if (copy_from_user(&comptag, arg, sizeof(comptag)))
526 return -EFAULT; 530 return -EFAULT;
527 531
528 rio_local_write_config_32(md->mport, RIO_COMPONENT_TAG_CSR, comptag); 532 rio_local_write_config_32(md->mport, RIO_COMPONENT_TAG_CSR, comptag);
@@ -837,7 +841,7 @@ err_out:
837 * @xfer: data transfer descriptor structure 841 * @xfer: data transfer descriptor structure
838 */ 842 */
839static int 843static int
840rio_dma_transfer(struct file *filp, uint32_t transfer_mode, 844rio_dma_transfer(struct file *filp, u32 transfer_mode,
841 enum rio_transfer_sync sync, enum dma_data_direction dir, 845 enum rio_transfer_sync sync, enum dma_data_direction dir,
842 struct rio_transfer_io *xfer) 846 struct rio_transfer_io *xfer)
843{ 847{
@@ -875,7 +879,7 @@ rio_dma_transfer(struct file *filp, uint32_t transfer_mode,
875 unsigned long offset; 879 unsigned long offset;
876 long pinned; 880 long pinned;
877 881
878 offset = (unsigned long)xfer->loc_addr & ~PAGE_MASK; 882 offset = (unsigned long)(uintptr_t)xfer->loc_addr & ~PAGE_MASK;
879 nr_pages = PAGE_ALIGN(xfer->length + offset) >> PAGE_SHIFT; 883 nr_pages = PAGE_ALIGN(xfer->length + offset) >> PAGE_SHIFT;
880 884
881 page_list = kmalloc_array(nr_pages, 885 page_list = kmalloc_array(nr_pages,
@@ -1015,19 +1019,20 @@ static int rio_mport_transfer_ioctl(struct file *filp, void __user *arg)
1015 if (unlikely(copy_from_user(&transaction, arg, sizeof(transaction)))) 1019 if (unlikely(copy_from_user(&transaction, arg, sizeof(transaction))))
1016 return -EFAULT; 1020 return -EFAULT;
1017 1021
1018 if (transaction.count != 1) 1022 if (transaction.count != 1) /* only single transfer for now */
1019 return -EINVAL; 1023 return -EINVAL;
1020 1024
1021 if ((transaction.transfer_mode & 1025 if ((transaction.transfer_mode &
1022 priv->md->properties.transfer_mode) == 0) 1026 priv->md->properties.transfer_mode) == 0)
1023 return -ENODEV; 1027 return -ENODEV;
1024 1028
1025 transfer = vmalloc(transaction.count * sizeof(struct rio_transfer_io)); 1029 transfer = vmalloc(transaction.count * sizeof(*transfer));
1026 if (!transfer) 1030 if (!transfer)
1027 return -ENOMEM; 1031 return -ENOMEM;
1028 1032
1029 if (unlikely(copy_from_user(transfer, transaction.block, 1033 if (unlikely(copy_from_user(transfer,
1030 transaction.count * sizeof(struct rio_transfer_io)))) { 1034 (void __user *)(uintptr_t)transaction.block,
1035 transaction.count * sizeof(*transfer)))) {
1031 ret = -EFAULT; 1036 ret = -EFAULT;
1032 goto out_free; 1037 goto out_free;
1033 } 1038 }
@@ -1038,8 +1043,9 @@ static int rio_mport_transfer_ioctl(struct file *filp, void __user *arg)
1038 ret = rio_dma_transfer(filp, transaction.transfer_mode, 1043 ret = rio_dma_transfer(filp, transaction.transfer_mode,
1039 transaction.sync, dir, &transfer[i]); 1044 transaction.sync, dir, &transfer[i]);
1040 1045
1041 if (unlikely(copy_to_user(transaction.block, transfer, 1046 if (unlikely(copy_to_user((void __user *)(uintptr_t)transaction.block,
1042 transaction.count * sizeof(struct rio_transfer_io)))) 1047 transfer,
1048 transaction.count * sizeof(*transfer))))
1043 ret = -EFAULT; 1049 ret = -EFAULT;
1044 1050
1045out_free: 1051out_free:
@@ -1129,11 +1135,11 @@ err_tmo:
1129} 1135}
1130 1136
1131static int rio_mport_create_dma_mapping(struct mport_dev *md, struct file *filp, 1137static int rio_mport_create_dma_mapping(struct mport_dev *md, struct file *filp,
1132 uint64_t size, struct rio_mport_mapping **mapping) 1138 u64 size, struct rio_mport_mapping **mapping)
1133{ 1139{
1134 struct rio_mport_mapping *map; 1140 struct rio_mport_mapping *map;
1135 1141
1136 map = kzalloc(sizeof(struct rio_mport_mapping), GFP_KERNEL); 1142 map = kzalloc(sizeof(*map), GFP_KERNEL);
1137 if (map == NULL) 1143 if (map == NULL)
1138 return -ENOMEM; 1144 return -ENOMEM;
1139 1145
@@ -1165,7 +1171,7 @@ static int rio_mport_alloc_dma(struct file *filp, void __user *arg)
1165 struct rio_mport_mapping *mapping = NULL; 1171 struct rio_mport_mapping *mapping = NULL;
1166 int ret; 1172 int ret;
1167 1173
1168 if (unlikely(copy_from_user(&map, arg, sizeof(struct rio_dma_mem)))) 1174 if (unlikely(copy_from_user(&map, arg, sizeof(map))))
1169 return -EFAULT; 1175 return -EFAULT;
1170 1176
1171 ret = rio_mport_create_dma_mapping(md, filp, map.length, &mapping); 1177 ret = rio_mport_create_dma_mapping(md, filp, map.length, &mapping);
@@ -1174,7 +1180,7 @@ static int rio_mport_alloc_dma(struct file *filp, void __user *arg)
1174 1180
1175 map.dma_handle = mapping->phys_addr; 1181 map.dma_handle = mapping->phys_addr;
1176 1182
1177 if (unlikely(copy_to_user(arg, &map, sizeof(struct rio_dma_mem)))) { 1183 if (unlikely(copy_to_user(arg, &map, sizeof(map)))) {
1178 mutex_lock(&md->buf_mutex); 1184 mutex_lock(&md->buf_mutex);
1179 kref_put(&mapping->ref, mport_release_mapping); 1185 kref_put(&mapping->ref, mport_release_mapping);
1180 mutex_unlock(&md->buf_mutex); 1186 mutex_unlock(&md->buf_mutex);
@@ -1192,7 +1198,7 @@ static int rio_mport_free_dma(struct file *filp, void __user *arg)
1192 int ret = -EFAULT; 1198 int ret = -EFAULT;
1193 struct rio_mport_mapping *map, *_map; 1199 struct rio_mport_mapping *map, *_map;
1194 1200
1195 if (copy_from_user(&handle, arg, sizeof(u64))) 1201 if (copy_from_user(&handle, arg, sizeof(handle)))
1196 return -EFAULT; 1202 return -EFAULT;
1197 rmcd_debug(EXIT, "filp=%p", filp); 1203 rmcd_debug(EXIT, "filp=%p", filp);
1198 1204
@@ -1242,14 +1248,18 @@ static int rio_mport_free_dma(struct file *filp, void __user *arg)
1242 1248
1243static int 1249static int
1244rio_mport_create_inbound_mapping(struct mport_dev *md, struct file *filp, 1250rio_mport_create_inbound_mapping(struct mport_dev *md, struct file *filp,
1245 u64 raddr, u32 size, 1251 u64 raddr, u64 size,
1246 struct rio_mport_mapping **mapping) 1252 struct rio_mport_mapping **mapping)
1247{ 1253{
1248 struct rio_mport *mport = md->mport; 1254 struct rio_mport *mport = md->mport;
1249 struct rio_mport_mapping *map; 1255 struct rio_mport_mapping *map;
1250 int ret; 1256 int ret;
1251 1257
1252 map = kzalloc(sizeof(struct rio_mport_mapping), GFP_KERNEL); 1258 /* rio_map_inb_region() accepts u32 size */
1259 if (size > 0xffffffff)
1260 return -EINVAL;
1261
1262 map = kzalloc(sizeof(*map), GFP_KERNEL);
1253 if (map == NULL) 1263 if (map == NULL)
1254 return -ENOMEM; 1264 return -ENOMEM;
1255 1265
@@ -1262,7 +1272,7 @@ rio_mport_create_inbound_mapping(struct mport_dev *md, struct file *filp,
1262 1272
1263 if (raddr == RIO_MAP_ANY_ADDR) 1273 if (raddr == RIO_MAP_ANY_ADDR)
1264 raddr = map->phys_addr; 1274 raddr = map->phys_addr;
1265 ret = rio_map_inb_region(mport, map->phys_addr, raddr, size, 0); 1275 ret = rio_map_inb_region(mport, map->phys_addr, raddr, (u32)size, 0);
1266 if (ret < 0) 1276 if (ret < 0)
1267 goto err_map_inb; 1277 goto err_map_inb;
1268 1278
@@ -1288,7 +1298,7 @@ err_dma_alloc:
1288 1298
1289static int 1299static int
1290rio_mport_get_inbound_mapping(struct mport_dev *md, struct file *filp, 1300rio_mport_get_inbound_mapping(struct mport_dev *md, struct file *filp,
1291 u64 raddr, u32 size, 1301 u64 raddr, u64 size,
1292 struct rio_mport_mapping **mapping) 1302 struct rio_mport_mapping **mapping)
1293{ 1303{
1294 struct rio_mport_mapping *map; 1304 struct rio_mport_mapping *map;
@@ -1331,7 +1341,7 @@ static int rio_mport_map_inbound(struct file *filp, void __user *arg)
1331 1341
1332 if (!md->mport->ops->map_inb) 1342 if (!md->mport->ops->map_inb)
1333 return -EPROTONOSUPPORT; 1343 return -EPROTONOSUPPORT;
1334 if (unlikely(copy_from_user(&map, arg, sizeof(struct rio_mmap)))) 1344 if (unlikely(copy_from_user(&map, arg, sizeof(map))))
1335 return -EFAULT; 1345 return -EFAULT;
1336 1346
1337 rmcd_debug(IBW, "%s filp=%p", dev_name(&priv->md->dev), filp); 1347 rmcd_debug(IBW, "%s filp=%p", dev_name(&priv->md->dev), filp);
@@ -1344,7 +1354,7 @@ static int rio_mport_map_inbound(struct file *filp, void __user *arg)
1344 map.handle = mapping->phys_addr; 1354 map.handle = mapping->phys_addr;
1345 map.rio_addr = mapping->rio_addr; 1355 map.rio_addr = mapping->rio_addr;
1346 1356
1347 if (unlikely(copy_to_user(arg, &map, sizeof(struct rio_mmap)))) { 1357 if (unlikely(copy_to_user(arg, &map, sizeof(map)))) {
1348 /* Delete mapping if it was created by this request */ 1358 /* Delete mapping if it was created by this request */
1349 if (ret == 0 && mapping->filp == filp) { 1359 if (ret == 0 && mapping->filp == filp) {
1350 mutex_lock(&md->buf_mutex); 1360 mutex_lock(&md->buf_mutex);
@@ -1375,7 +1385,7 @@ static int rio_mport_inbound_free(struct file *filp, void __user *arg)
1375 if (!md->mport->ops->unmap_inb) 1385 if (!md->mport->ops->unmap_inb)
1376 return -EPROTONOSUPPORT; 1386 return -EPROTONOSUPPORT;
1377 1387
1378 if (copy_from_user(&handle, arg, sizeof(u64))) 1388 if (copy_from_user(&handle, arg, sizeof(handle)))
1379 return -EFAULT; 1389 return -EFAULT;
1380 1390
1381 mutex_lock(&md->buf_mutex); 1391 mutex_lock(&md->buf_mutex);
@@ -1401,7 +1411,7 @@ static int rio_mport_inbound_free(struct file *filp, void __user *arg)
1401static int maint_port_idx_get(struct mport_cdev_priv *priv, void __user *arg) 1411static int maint_port_idx_get(struct mport_cdev_priv *priv, void __user *arg)
1402{ 1412{
1403 struct mport_dev *md = priv->md; 1413 struct mport_dev *md = priv->md;
1404 uint32_t port_idx = md->mport->index; 1414 u32 port_idx = md->mport->index;
1405 1415
1406 rmcd_debug(MPORT, "port_index=%d", port_idx); 1416 rmcd_debug(MPORT, "port_index=%d", port_idx);
1407 1417
@@ -1451,7 +1461,7 @@ static void rio_mport_doorbell_handler(struct rio_mport *mport, void *dev_id,
1451 handled = 0; 1461 handled = 0;
1452 spin_lock(&data->db_lock); 1462 spin_lock(&data->db_lock);
1453 list_for_each_entry(db_filter, &data->doorbells, data_node) { 1463 list_for_each_entry(db_filter, &data->doorbells, data_node) {
1454 if (((db_filter->filter.rioid == 0xffffffff || 1464 if (((db_filter->filter.rioid == RIO_INVALID_DESTID ||
1455 db_filter->filter.rioid == src)) && 1465 db_filter->filter.rioid == src)) &&
1456 info >= db_filter->filter.low && 1466 info >= db_filter->filter.low &&
1457 info <= db_filter->filter.high) { 1467 info <= db_filter->filter.high) {
@@ -1525,6 +1535,9 @@ static int rio_mport_remove_db_filter(struct mport_cdev_priv *priv,
1525 if (copy_from_user(&filter, arg, sizeof(filter))) 1535 if (copy_from_user(&filter, arg, sizeof(filter)))
1526 return -EFAULT; 1536 return -EFAULT;
1527 1537
1538 if (filter.low > filter.high)
1539 return -EINVAL;
1540
1528 spin_lock_irqsave(&priv->md->db_lock, flags); 1541 spin_lock_irqsave(&priv->md->db_lock, flags);
1529 list_for_each_entry(db_filter, &priv->db_filters, priv_node) { 1542 list_for_each_entry(db_filter, &priv->db_filters, priv_node) {
1530 if (db_filter->filter.rioid == filter.rioid && 1543 if (db_filter->filter.rioid == filter.rioid &&
@@ -1737,10 +1750,10 @@ static int rio_mport_add_riodev(struct mport_cdev_priv *priv,
1737 return -EEXIST; 1750 return -EEXIST;
1738 } 1751 }
1739 1752
1740 size = sizeof(struct rio_dev); 1753 size = sizeof(*rdev);
1741 mport = md->mport; 1754 mport = md->mport;
1742 destid = (u16)dev_info.destid; 1755 destid = dev_info.destid;
1743 hopcount = (u8)dev_info.hopcount; 1756 hopcount = dev_info.hopcount;
1744 1757
1745 if (rio_mport_read_config_32(mport, destid, hopcount, 1758 if (rio_mport_read_config_32(mport, destid, hopcount,
1746 RIO_PEF_CAR, &rval)) 1759 RIO_PEF_CAR, &rval))
@@ -1872,8 +1885,8 @@ static int rio_mport_del_riodev(struct mport_cdev_priv *priv, void __user *arg)
1872 do { 1885 do {
1873 rdev = rio_get_comptag(dev_info.comptag, rdev); 1886 rdev = rio_get_comptag(dev_info.comptag, rdev);
1874 if (rdev && rdev->dev.parent == &mport->net->dev && 1887 if (rdev && rdev->dev.parent == &mport->net->dev &&
1875 rdev->destid == (u16)dev_info.destid && 1888 rdev->destid == dev_info.destid &&
1876 rdev->hopcount == (u8)dev_info.hopcount) 1889 rdev->hopcount == dev_info.hopcount)
1877 break; 1890 break;
1878 } while (rdev); 1891 } while (rdev);
1879 } 1892 }
@@ -2146,8 +2159,8 @@ static long mport_cdev_ioctl(struct file *filp,
2146 return maint_port_idx_get(data, (void __user *)arg); 2159 return maint_port_idx_get(data, (void __user *)arg);
2147 case RIO_MPORT_GET_PROPERTIES: 2160 case RIO_MPORT_GET_PROPERTIES:
2148 md->properties.hdid = md->mport->host_deviceid; 2161 md->properties.hdid = md->mport->host_deviceid;
2149 if (copy_to_user((void __user *)arg, &(data->md->properties), 2162 if (copy_to_user((void __user *)arg, &(md->properties),
2150 sizeof(data->md->properties))) 2163 sizeof(md->properties)))
2151 return -EFAULT; 2164 return -EFAULT;
2152 return 0; 2165 return 0;
2153 case RIO_ENABLE_DOORBELL_RANGE: 2166 case RIO_ENABLE_DOORBELL_RANGE:
@@ -2159,11 +2172,11 @@ static long mport_cdev_ioctl(struct file *filp,
2159 case RIO_DISABLE_PORTWRITE_RANGE: 2172 case RIO_DISABLE_PORTWRITE_RANGE:
2160 return rio_mport_remove_pw_filter(data, (void __user *)arg); 2173 return rio_mport_remove_pw_filter(data, (void __user *)arg);
2161 case RIO_SET_EVENT_MASK: 2174 case RIO_SET_EVENT_MASK:
2162 data->event_mask = arg; 2175 data->event_mask = (u32)arg;
2163 return 0; 2176 return 0;
2164 case RIO_GET_EVENT_MASK: 2177 case RIO_GET_EVENT_MASK:
2165 if (copy_to_user((void __user *)arg, &data->event_mask, 2178 if (copy_to_user((void __user *)arg, &data->event_mask,
2166 sizeof(data->event_mask))) 2179 sizeof(u32)))
2167 return -EFAULT; 2180 return -EFAULT;
2168 return 0; 2181 return 0;
2169 case RIO_MAP_OUTBOUND: 2182 case RIO_MAP_OUTBOUND:
@@ -2374,7 +2387,7 @@ static ssize_t mport_write(struct file *filp, const char __user *buf,
2374 return -EINVAL; 2387 return -EINVAL;
2375 2388
2376 ret = rio_mport_send_doorbell(mport, 2389 ret = rio_mport_send_doorbell(mport,
2377 (u16)event.u.doorbell.rioid, 2390 event.u.doorbell.rioid,
2378 event.u.doorbell.payload); 2391 event.u.doorbell.payload);
2379 if (ret < 0) 2392 if (ret < 0)
2380 return ret; 2393 return ret;
@@ -2421,7 +2434,7 @@ static struct mport_dev *mport_cdev_add(struct rio_mport *mport)
2421 struct mport_dev *md; 2434 struct mport_dev *md;
2422 struct rio_mport_attr attr; 2435 struct rio_mport_attr attr;
2423 2436
2424 md = kzalloc(sizeof(struct mport_dev), GFP_KERNEL); 2437 md = kzalloc(sizeof(*md), GFP_KERNEL);
2425 if (!md) { 2438 if (!md) {
2426 rmcd_error("Unable allocate a device object"); 2439 rmcd_error("Unable allocate a device object");
2427 return NULL; 2440 return NULL;
@@ -2470,7 +2483,7 @@ static struct mport_dev *mport_cdev_add(struct rio_mport *mport)
2470 /* The transfer_mode property will be returned through mport query 2483 /* The transfer_mode property will be returned through mport query
2471 * interface 2484 * interface
2472 */ 2485 */
2473#ifdef CONFIG_PPC /* for now: only on Freescale's SoCs */ 2486#ifdef CONFIG_FSL_RIO /* for now: only on Freescale's SoCs */
2474 md->properties.transfer_mode |= RIO_TRANSFER_MODE_MAPPED; 2487 md->properties.transfer_mode |= RIO_TRANSFER_MODE_MAPPED;
2475#else 2488#else
2476 md->properties.transfer_mode |= RIO_TRANSFER_MODE_TRANSFER; 2489 md->properties.transfer_mode |= RIO_TRANSFER_MODE_TRANSFER;
diff --git a/include/linux/rio_mport_cdev.h b/include/uapi/linux/rio_mport_cdev.h
index b65d19df76d2..5796bf1d06ad 100644
--- a/include/linux/rio_mport_cdev.h
+++ b/include/uapi/linux/rio_mport_cdev.h
@@ -39,16 +39,16 @@
39#ifndef _RIO_MPORT_CDEV_H_ 39#ifndef _RIO_MPORT_CDEV_H_
40#define _RIO_MPORT_CDEV_H_ 40#define _RIO_MPORT_CDEV_H_
41 41
42#ifndef __user 42#include <linux/ioctl.h>
43#define __user 43#include <linux/types.h>
44#endif
45 44
46struct rio_mport_maint_io { 45struct rio_mport_maint_io {
47 uint32_t rioid; /* destID of remote device */ 46 __u16 rioid; /* destID of remote device */
48 uint32_t hopcount; /* hopcount to remote device */ 47 __u8 hopcount; /* hopcount to remote device */
49 uint32_t offset; /* offset in register space */ 48 __u8 pad0[5];
50 size_t length; /* length in bytes */ 49 __u32 offset; /* offset in register space */
51 void __user *buffer; /* data buffer */ 50 __u32 length; /* length in bytes */
51 __u64 buffer; /* pointer to data buffer */
52}; 52};
53 53
54/* 54/*
@@ -66,22 +66,23 @@ struct rio_mport_maint_io {
66#define RIO_CAP_MAP_INB (1 << 7) 66#define RIO_CAP_MAP_INB (1 << 7)
67 67
68struct rio_mport_properties { 68struct rio_mport_properties {
69 uint16_t hdid; 69 __u16 hdid;
70 uint8_t id; /* Physical port ID */ 70 __u8 id; /* Physical port ID */
71 uint8_t index; 71 __u8 index;
72 uint32_t flags; 72 __u32 flags;
73 uint32_t sys_size; /* Default addressing size */ 73 __u32 sys_size; /* Default addressing size */
74 uint8_t port_ok; 74 __u8 port_ok;
75 uint8_t link_speed; 75 __u8 link_speed;
76 uint8_t link_width; 76 __u8 link_width;
77 uint32_t dma_max_sge; 77 __u8 pad0;
78 uint32_t dma_max_size; 78 __u32 dma_max_sge;
79 uint32_t dma_align; 79 __u32 dma_max_size;
80 uint32_t transfer_mode; /* Default transfer mode */ 80 __u32 dma_align;
81 uint32_t cap_sys_size; /* Capable system sizes */ 81 __u32 transfer_mode; /* Default transfer mode */
82 uint32_t cap_addr_size; /* Capable addressing sizes */ 82 __u32 cap_sys_size; /* Capable system sizes */
83 uint32_t cap_transfer_mode; /* Capable transfer modes */ 83 __u32 cap_addr_size; /* Capable addressing sizes */
84 uint32_t cap_mport; /* Mport capabilities */ 84 __u32 cap_transfer_mode; /* Capable transfer modes */
85 __u32 cap_mport; /* Mport capabilities */
85}; 86};
86 87
87/* 88/*
@@ -93,54 +94,57 @@ struct rio_mport_properties {
93#define RIO_PORTWRITE (1 << 1) 94#define RIO_PORTWRITE (1 << 1)
94 95
95struct rio_doorbell { 96struct rio_doorbell {
96 uint32_t rioid; 97 __u16 rioid;
97 uint16_t payload; 98 __u16 payload;
98}; 99};
99 100
100struct rio_doorbell_filter { 101struct rio_doorbell_filter {
101 uint32_t rioid; /* 0xffffffff to match all ids */ 102 __u16 rioid; /* Use RIO_INVALID_DESTID to match all ids */
102 uint16_t low; 103 __u16 low;
103 uint16_t high; 104 __u16 high;
105 __u16 pad0;
104}; 106};
105 107
106 108
107struct rio_portwrite { 109struct rio_portwrite {
108 uint32_t payload[16]; 110 __u32 payload[16];
109}; 111};
110 112
111struct rio_pw_filter { 113struct rio_pw_filter {
112 uint32_t mask; 114 __u32 mask;
113 uint32_t low; 115 __u32 low;
114 uint32_t high; 116 __u32 high;
117 __u32 pad0;
115}; 118};
116 119
117/* RapidIO base address for inbound requests set to value defined below 120/* RapidIO base address for inbound requests set to value defined below
118 * indicates that no specific RIO-to-local address translation is requested 121 * indicates that no specific RIO-to-local address translation is requested
119 * and driver should use direct (one-to-one) address mapping. 122 * and driver should use direct (one-to-one) address mapping.
120*/ 123*/
121#define RIO_MAP_ANY_ADDR (uint64_t)(~((uint64_t) 0)) 124#define RIO_MAP_ANY_ADDR (__u64)(~((__u64) 0))
122 125
123struct rio_mmap { 126struct rio_mmap {
124 uint32_t rioid; 127 __u16 rioid;
125 uint64_t rio_addr; 128 __u16 pad0[3];
126 uint64_t length; 129 __u64 rio_addr;
127 uint64_t handle; 130 __u64 length;
128 void *address; 131 __u64 handle;
132 __u64 address;
129}; 133};
130 134
131struct rio_dma_mem { 135struct rio_dma_mem {
132 uint64_t length; /* length of DMA memory */ 136 __u64 length; /* length of DMA memory */
133 uint64_t dma_handle; /* handle associated with this memory */ 137 __u64 dma_handle; /* handle associated with this memory */
134 void *buffer; /* pointer to this memory */ 138 __u64 address;
135}; 139};
136 140
137
138struct rio_event { 141struct rio_event {
139 unsigned int header; /* event type RIO_DOORBELL or RIO_PORTWRITE */ 142 __u32 header; /* event type RIO_DOORBELL or RIO_PORTWRITE */
140 union { 143 union {
141 struct rio_doorbell doorbell; /* header for RIO_DOORBELL */ 144 struct rio_doorbell doorbell; /* header for RIO_DOORBELL */
142 struct rio_portwrite portwrite; /* header for RIO_PORTWRITE */ 145 struct rio_portwrite portwrite; /* header for RIO_PORTWRITE */
143 } u; 146 } u;
147 __u32 pad0;
144}; 148};
145 149
146enum rio_transfer_sync { 150enum rio_transfer_sync {
@@ -184,35 +188,37 @@ enum rio_exchange {
184}; 188};
185 189
186struct rio_transfer_io { 190struct rio_transfer_io {
187 uint32_t rioid; /* Target destID */ 191 __u64 rio_addr; /* Address in target's RIO mem space */
188 uint64_t rio_addr; /* Address in target's RIO mem space */ 192 __u64 loc_addr;
189 enum rio_exchange method; /* Data exchange method */ 193 __u64 handle;
190 void __user *loc_addr; 194 __u64 offset; /* Offset in buffer */
191 uint64_t handle; 195 __u64 length; /* Length in bytes */
192 uint64_t offset; /* Offset in buffer */ 196 __u16 rioid; /* Target destID */
193 uint64_t length; /* Length in bytes */ 197 __u16 method; /* Data exchange method, one of rio_exchange enum */
194 uint32_t completion_code; /* Completion code for this transfer */ 198 __u32 completion_code; /* Completion code for this transfer */
195}; 199};
196 200
197struct rio_transaction { 201struct rio_transaction {
198 uint32_t transfer_mode; /* Data transfer mode */ 202 __u64 block; /* Pointer to array of <count> transfers */
199 enum rio_transfer_sync sync; /* Synchronization method */ 203 __u32 count; /* Number of transfers */
200 enum rio_transfer_dir dir; /* Transfer direction */ 204 __u32 transfer_mode; /* Data transfer mode */
201 size_t count; /* Number of transfers */ 205 __u16 sync; /* Synch method, one of rio_transfer_sync enum */
202 struct rio_transfer_io __user *block; /* Array of <count> transfers */ 206 __u16 dir; /* Transfer direction, one of rio_transfer_dir enum */
207 __u32 pad0;
203}; 208};
204 209
205struct rio_async_tx_wait { 210struct rio_async_tx_wait {
206 uint32_t token; /* DMA transaction ID token */ 211 __u32 token; /* DMA transaction ID token */
207 uint32_t timeout; /* Wait timeout in msec, if 0 use default TO */ 212 __u32 timeout; /* Wait timeout in msec, if 0 use default TO */
208}; 213};
209 214
210#define RIO_MAX_DEVNAME_SZ 20 215#define RIO_MAX_DEVNAME_SZ 20
211 216
212struct rio_rdev_info { 217struct rio_rdev_info {
213 uint32_t destid; 218 __u16 destid;
214 uint8_t hopcount; 219 __u8 hopcount;
215 uint32_t comptag; 220 __u8 pad0;
221 __u32 comptag;
216 char name[RIO_MAX_DEVNAME_SZ + 1]; 222 char name[RIO_MAX_DEVNAME_SZ + 1];
217}; 223};
218 224
@@ -220,11 +226,11 @@ struct rio_rdev_info {
220#define RIO_MPORT_DRV_MAGIC 'm' 226#define RIO_MPORT_DRV_MAGIC 'm'
221 227
222#define RIO_MPORT_MAINT_HDID_SET \ 228#define RIO_MPORT_MAINT_HDID_SET \
223 _IOW(RIO_MPORT_DRV_MAGIC, 1, uint16_t) 229 _IOW(RIO_MPORT_DRV_MAGIC, 1, __u16)
224#define RIO_MPORT_MAINT_COMPTAG_SET \ 230#define RIO_MPORT_MAINT_COMPTAG_SET \
225 _IOW(RIO_MPORT_DRV_MAGIC, 2, uint32_t) 231 _IOW(RIO_MPORT_DRV_MAGIC, 2, __u32)
226#define RIO_MPORT_MAINT_PORT_IDX_GET \ 232#define RIO_MPORT_MAINT_PORT_IDX_GET \
227 _IOR(RIO_MPORT_DRV_MAGIC, 3, uint32_t) 233 _IOR(RIO_MPORT_DRV_MAGIC, 3, __u32)
228#define RIO_MPORT_GET_PROPERTIES \ 234#define RIO_MPORT_GET_PROPERTIES \
229 _IOR(RIO_MPORT_DRV_MAGIC, 4, struct rio_mport_properties) 235 _IOR(RIO_MPORT_DRV_MAGIC, 4, struct rio_mport_properties)
230#define RIO_MPORT_MAINT_READ_LOCAL \ 236#define RIO_MPORT_MAINT_READ_LOCAL \
@@ -244,9 +250,9 @@ struct rio_rdev_info {
244#define RIO_DISABLE_PORTWRITE_RANGE \ 250#define RIO_DISABLE_PORTWRITE_RANGE \
245 _IOW(RIO_MPORT_DRV_MAGIC, 12, struct rio_pw_filter) 251 _IOW(RIO_MPORT_DRV_MAGIC, 12, struct rio_pw_filter)
246#define RIO_SET_EVENT_MASK \ 252#define RIO_SET_EVENT_MASK \
247 _IOW(RIO_MPORT_DRV_MAGIC, 13, unsigned int) 253 _IOW(RIO_MPORT_DRV_MAGIC, 13, __u32)
248#define RIO_GET_EVENT_MASK \ 254#define RIO_GET_EVENT_MASK \
249 _IOR(RIO_MPORT_DRV_MAGIC, 14, unsigned int) 255 _IOR(RIO_MPORT_DRV_MAGIC, 14, __u32)
250#define RIO_MAP_OUTBOUND \ 256#define RIO_MAP_OUTBOUND \
251 _IOWR(RIO_MPORT_DRV_MAGIC, 15, struct rio_mmap) 257 _IOWR(RIO_MPORT_DRV_MAGIC, 15, struct rio_mmap)
252#define RIO_UNMAP_OUTBOUND \ 258#define RIO_UNMAP_OUTBOUND \
@@ -254,11 +260,11 @@ struct rio_rdev_info {
254#define RIO_MAP_INBOUND \ 260#define RIO_MAP_INBOUND \
255 _IOWR(RIO_MPORT_DRV_MAGIC, 17, struct rio_mmap) 261 _IOWR(RIO_MPORT_DRV_MAGIC, 17, struct rio_mmap)
256#define RIO_UNMAP_INBOUND \ 262#define RIO_UNMAP_INBOUND \
257 _IOW(RIO_MPORT_DRV_MAGIC, 18, uint64_t) 263 _IOW(RIO_MPORT_DRV_MAGIC, 18, __u64)
258#define RIO_ALLOC_DMA \ 264#define RIO_ALLOC_DMA \
259 _IOWR(RIO_MPORT_DRV_MAGIC, 19, struct rio_dma_mem) 265 _IOWR(RIO_MPORT_DRV_MAGIC, 19, struct rio_dma_mem)
260#define RIO_FREE_DMA \ 266#define RIO_FREE_DMA \
261 _IOW(RIO_MPORT_DRV_MAGIC, 20, uint64_t) 267 _IOW(RIO_MPORT_DRV_MAGIC, 20, __u64)
262#define RIO_TRANSFER \ 268#define RIO_TRANSFER \
263 _IOWR(RIO_MPORT_DRV_MAGIC, 21, struct rio_transaction) 269 _IOWR(RIO_MPORT_DRV_MAGIC, 21, struct rio_transaction)
264#define RIO_WAIT_FOR_ASYNC \ 270#define RIO_WAIT_FOR_ASYNC \