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