xref: /onnv-gate/usr/src/uts/common/io/ib/clients/rdsv3/page.c (revision 12763:4b30642bc04e)
112198SEiji.Ota@Sun.COM /*
212198SEiji.Ota@Sun.COM  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
312198SEiji.Ota@Sun.COM  */
412198SEiji.Ota@Sun.COM 
512198SEiji.Ota@Sun.COM /*
6*12763SGiri.Adari@Sun.COM  * This file contains code imported from the OFED rds source file page.c
7*12763SGiri.Adari@Sun.COM  * Oracle elects to have and use the contents of page.c under and governed
8*12763SGiri.Adari@Sun.COM  * by the OpenIB.org BSD license (see below for full license text). However,
9*12763SGiri.Adari@Sun.COM  * the following notice accompanied the original version of this file:
10*12763SGiri.Adari@Sun.COM  */
11*12763SGiri.Adari@Sun.COM 
12*12763SGiri.Adari@Sun.COM /*
1312198SEiji.Ota@Sun.COM  * Copyright (c) 2006 Oracle.  All rights reserved.
1412198SEiji.Ota@Sun.COM  *
1512198SEiji.Ota@Sun.COM  * This software is available to you under a choice of one of two
1612198SEiji.Ota@Sun.COM  * licenses.  You may choose to be licensed under the terms of the GNU
1712198SEiji.Ota@Sun.COM  * General Public License (GPL) Version 2, available from the file
1812198SEiji.Ota@Sun.COM  * COPYING in the main directory of this source tree, or the
1912198SEiji.Ota@Sun.COM  * OpenIB.org BSD license below:
2012198SEiji.Ota@Sun.COM  *
2112198SEiji.Ota@Sun.COM  *     Redistribution and use in source and binary forms, with or
2212198SEiji.Ota@Sun.COM  *     without modification, are permitted provided that the following
2312198SEiji.Ota@Sun.COM  *     conditions are met:
2412198SEiji.Ota@Sun.COM  *
2512198SEiji.Ota@Sun.COM  *      - Redistributions of source code must retain the above
2612198SEiji.Ota@Sun.COM  *        copyright notice, this list of conditions and the following
2712198SEiji.Ota@Sun.COM  *        disclaimer.
2812198SEiji.Ota@Sun.COM  *
2912198SEiji.Ota@Sun.COM  *      - Redistributions in binary form must reproduce the above
3012198SEiji.Ota@Sun.COM  *        copyright notice, this list of conditions and the following
3112198SEiji.Ota@Sun.COM  *        disclaimer in the documentation and/or other materials
3212198SEiji.Ota@Sun.COM  *        provided with the distribution.
3312198SEiji.Ota@Sun.COM  *
3412198SEiji.Ota@Sun.COM  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
3512198SEiji.Ota@Sun.COM  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3612198SEiji.Ota@Sun.COM  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
3712198SEiji.Ota@Sun.COM  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
3812198SEiji.Ota@Sun.COM  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
3912198SEiji.Ota@Sun.COM  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
4012198SEiji.Ota@Sun.COM  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4112198SEiji.Ota@Sun.COM  * SOFTWARE.
4212198SEiji.Ota@Sun.COM  *
4312198SEiji.Ota@Sun.COM  */
4412198SEiji.Ota@Sun.COM #include <sys/rds.h>
4512198SEiji.Ota@Sun.COM 
4612198SEiji.Ota@Sun.COM #include <sys/ib/clients/rdsv3/rdsv3.h>
4712198SEiji.Ota@Sun.COM #include <sys/ib/clients/rdsv3/rdsv3_debug.h>
4812198SEiji.Ota@Sun.COM 
4912198SEiji.Ota@Sun.COM /*
5012198SEiji.Ota@Sun.COM  * @bytes - the number of bytes needed.
5112198SEiji.Ota@Sun.COM  *
5212198SEiji.Ota@Sun.COM  * XXX - This is different from Linux.
5312198SEiji.Ota@Sun.COM  */
5412198SEiji.Ota@Sun.COM int
rdsv3_page_remainder_alloc(struct rdsv3_scatterlist * scat,unsigned long bytes,int gfp)5512198SEiji.Ota@Sun.COM rdsv3_page_remainder_alloc(struct rdsv3_scatterlist *scat, unsigned long bytes,
5612198SEiji.Ota@Sun.COM     int gfp)
5712198SEiji.Ota@Sun.COM {
5812198SEiji.Ota@Sun.COM 	caddr_t	page;
5912198SEiji.Ota@Sun.COM 	int ret;
6012198SEiji.Ota@Sun.COM 
6112198SEiji.Ota@Sun.COM 	ASSERT(rdsv3_sg_page(scat) == NULL);
6212198SEiji.Ota@Sun.COM 
6312198SEiji.Ota@Sun.COM 	if (bytes >= PAGE_SIZE) {
6412198SEiji.Ota@Sun.COM 		page = kmem_alloc(PAGE_SIZE, gfp);
6512676SEiji.Ota@Sun.COM 		if (!page) {
6612198SEiji.Ota@Sun.COM 			ret = -ENOMEM;
6712198SEiji.Ota@Sun.COM 		} else {
6812198SEiji.Ota@Sun.COM 			rdsv3_sg_set_page(scat, page, PAGE_SIZE, 0);
6912198SEiji.Ota@Sun.COM 			ret = 0;
7012198SEiji.Ota@Sun.COM 		}
7112198SEiji.Ota@Sun.COM 		goto out;
7212198SEiji.Ota@Sun.COM 	}
7312198SEiji.Ota@Sun.COM 
7412198SEiji.Ota@Sun.COM 	/*
7512198SEiji.Ota@Sun.COM 	 * XXX - This is not same as linux.
7612198SEiji.Ota@Sun.COM 	 */
7712198SEiji.Ota@Sun.COM 	page = kmem_alloc(bytes, KM_NOSLEEP);
7812676SEiji.Ota@Sun.COM 	if (!page) {
7912198SEiji.Ota@Sun.COM 		ret = -ENOMEM;
8012198SEiji.Ota@Sun.COM 		goto out;
8112198SEiji.Ota@Sun.COM 	}
8212198SEiji.Ota@Sun.COM 
8312198SEiji.Ota@Sun.COM 	rdsv3_sg_set_page(scat, page, bytes, 0);
8412198SEiji.Ota@Sun.COM 	ret = 0;
8512198SEiji.Ota@Sun.COM out:
8612198SEiji.Ota@Sun.COM 	RDSV3_DPRINTF5("rdsv3_page_remainder_alloc", "bytes %lu %p %u",
8712198SEiji.Ota@Sun.COM 	    bytes, rdsv3_sg_page(scat), scat->length);
8812198SEiji.Ota@Sun.COM 	return (ret);
8912198SEiji.Ota@Sun.COM }
90