xref: /illumos-gate/usr/src/uts/common/io/ib/clients/rdsv3/page.c (revision 69a119caa6570c7077699161b7c28b6ee9f8b0f4)
1 /*
2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3  */
4 
5 /*
6  * This file contains code imported from the OFED rds source file page.c
7  * Oracle elects to have and use the contents of page.c under and governed
8  * by the OpenIB.org BSD license (see below for full license text). However,
9  * the following notice accompanied the original version of this file:
10  */
11 
12 /*
13  * Copyright (c) 2006 Oracle.  All rights reserved.
14  *
15  * This software is available to you under a choice of one of two
16  * licenses.  You may choose to be licensed under the terms of the GNU
17  * General Public License (GPL) Version 2, available from the file
18  * COPYING in the main directory of this source tree, or the
19  * OpenIB.org BSD license below:
20  *
21  *     Redistribution and use in source and binary forms, with or
22  *     without modification, are permitted provided that the following
23  *     conditions are met:
24  *
25  *      - Redistributions of source code must retain the above
26  *        copyright notice, this list of conditions and the following
27  *        disclaimer.
28  *
29  *      - Redistributions in binary form must reproduce the above
30  *        copyright notice, this list of conditions and the following
31  *        disclaimer in the documentation and/or other materials
32  *        provided with the distribution.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
38  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
39  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41  * SOFTWARE.
42  *
43  */
44 #include <sys/rds.h>
45 
46 #include <sys/ib/clients/rdsv3/rdsv3.h>
47 #include <sys/ib/clients/rdsv3/rdsv3_debug.h>
48 
49 /*
50  * @bytes - the number of bytes needed.
51  *
52  * XXX - This is different from Linux.
53  */
54 int
55 rdsv3_page_remainder_alloc(struct rdsv3_scatterlist *scat, unsigned long bytes,
56     int gfp)
57 {
58 	caddr_t	page;
59 	int ret;
60 
61 	ASSERT(rdsv3_sg_page(scat) == NULL);
62 
63 	if (bytes >= PAGE_SIZE) {
64 		page = kmem_alloc(PAGE_SIZE, gfp);
65 		if (!page) {
66 			ret = -ENOMEM;
67 		} else {
68 			rdsv3_sg_set_page(scat, page, PAGE_SIZE, 0);
69 			ret = 0;
70 		}
71 		goto out;
72 	}
73 
74 	/*
75 	 * XXX - This is not same as linux.
76 	 */
77 	page = kmem_alloc(bytes, KM_NOSLEEP);
78 	if (!page) {
79 		ret = -ENOMEM;
80 		goto out;
81 	}
82 
83 	rdsv3_sg_set_page(scat, page, bytes, 0);
84 	ret = 0;
85 out:
86 	RDSV3_DPRINTF5("rdsv3_page_remainder_alloc", "bytes %lu %p %u",
87 	    bytes, rdsv3_sg_page(scat), scat->length);
88 	return (ret);
89 }
90