5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at
9 * http://www.opensource.org/licenses/cddl1.txt.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2004-2011 Emulex. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include <emlxs.h>
28
29 /* #define EMLXS_POOL_DEBUG */
30
31 EMLXS_MSG_DEF(EMLXS_MEM_C);
32
33
34 static uint32_t emlxs_mem_pool_alloc(emlxs_hba_t *hba, MEMSEG *seg,
35 uint32_t count);
36 static void emlxs_mem_pool_free(emlxs_hba_t *hba, MEMSEG *seg, uint32_t count);
37
38
39 extern int32_t
40 emlxs_mem_alloc_buffer(emlxs_hba_t *hba)
41 {
42 emlxs_port_t *port = &PPORT;
43 emlxs_config_t *cfg;
44 MBUF_INFO *buf_info;
144 seg->fc_memflag = FC_MBUF_DMA | FC_MBUF_SNGLSG;
145 seg->fc_memalign = 32;
146 seg->fc_hi_water = MEM_IPBUF_COUNT;
147 seg->fc_lo_water = 0;
148 seg->fc_step = 4;
149 break;
150
151 case MEM_CTBUF:
152 /* These are the unsolicited CT buffers. */
153 (void) strlcpy(seg->fc_label, "CTBUF Pool",
154 sizeof (seg->fc_label));
155 seg->fc_memtag = MEM_CTBUF;
156 seg->fc_memsize = MEM_CTBUF_SIZE;
157 seg->fc_memflag = FC_MBUF_DMA | FC_MBUF_SNGLSG;
158 seg->fc_memalign = 32;
159 seg->fc_hi_water = MEM_CTBUF_COUNT;
160 seg->fc_lo_water = MEM_CTBUF_COUNT;
161 seg->fc_step = 1;
162 break;
163
164 #ifdef SFCT_SUPPORT
165 case MEM_FCTBUF:
166 /* These are the unsolicited FCT buffers. */
167 if (!(port->flag & EMLXS_TGT_ENABLED)) {
168 continue;
169 }
170
171 (void) strlcpy(seg->fc_label, "FCTBUF Pool",
172 sizeof (seg->fc_label));
173 seg->fc_memtag = MEM_FCTBUF;
174 seg->fc_memsize = MEM_FCTBUF_SIZE;
175 seg->fc_memflag = FC_MBUF_DMA | FC_MBUF_SNGLSG;
176 seg->fc_memalign = 32;
177 seg->fc_hi_water = MEM_FCTBUF_COUNT;
178 seg->fc_lo_water = 0;
179 seg->fc_step = 8;
180 break;
181 #endif /* SFCT_SUPPORT */
182
183 default:
1036 mp = (MATCHMAP *)buf_info->virt;
1037 bzero(mp, sizeof (MATCHMAP));
1038
1039 bzero(buf_info, sizeof (MBUF_INFO));
1040 buf_info->size = size;
1041 buf_info->flags = FC_MBUF_DMA | FC_MBUF_SNGLSG | FC_MBUF_DMA32;
1042 buf_info->align = 32;
1043
1044 (void) emlxs_mem_alloc(hba, buf_info);
1045 if (buf_info->virt == NULL) {
1046
1047 EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_mem_alloc_failed_msg,
1048 "MEM_BUF_ALLOC DMA buffer.");
1049
1050 /* Free the mp object */
1051 bzero(buf_info, sizeof (MBUF_INFO));
1052 buf_info->size = sizeof (MATCHMAP);
1053 buf_info->virt = (void *)mp;
1054 emlxs_mem_free(hba, buf_info);
1055
1056 return (0);
1057 }
1058 bp = (uint8_t *)buf_info->virt;
1059 bzero(bp, buf_info->size);
1060
1061 mp->virt = buf_info->virt;
1062 mp->phys = buf_info->phys;
1063 mp->size = buf_info->size;
1064 mp->dma_handle = buf_info->dma_handle;
1065 mp->data_handle = buf_info->data_handle;
1066 mp->tag = MEM_BUF;
1067 mp->flag |= MAP_BUF_ALLOCATED;
1068
1069 return (mp);
1070
1071 } /* emlxs_mem_buf_alloc() */
1072
1073
1074 extern void
1075 emlxs_mem_buf_free(emlxs_hba_t *hba, MATCHMAP *mp)
1076 {
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at
9 * http://www.opensource.org/licenses/cddl1.txt.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2004-2011 Emulex. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
26 */
27
28 #include <emlxs.h>
29
30 /* #define EMLXS_POOL_DEBUG */
31
32 EMLXS_MSG_DEF(EMLXS_MEM_C);
33
34
35 static uint32_t emlxs_mem_pool_alloc(emlxs_hba_t *hba, MEMSEG *seg,
36 uint32_t count);
37 static void emlxs_mem_pool_free(emlxs_hba_t *hba, MEMSEG *seg, uint32_t count);
38
39
40 extern int32_t
41 emlxs_mem_alloc_buffer(emlxs_hba_t *hba)
42 {
43 emlxs_port_t *port = &PPORT;
44 emlxs_config_t *cfg;
45 MBUF_INFO *buf_info;
145 seg->fc_memflag = FC_MBUF_DMA | FC_MBUF_SNGLSG;
146 seg->fc_memalign = 32;
147 seg->fc_hi_water = MEM_IPBUF_COUNT;
148 seg->fc_lo_water = 0;
149 seg->fc_step = 4;
150 break;
151
152 case MEM_CTBUF:
153 /* These are the unsolicited CT buffers. */
154 (void) strlcpy(seg->fc_label, "CTBUF Pool",
155 sizeof (seg->fc_label));
156 seg->fc_memtag = MEM_CTBUF;
157 seg->fc_memsize = MEM_CTBUF_SIZE;
158 seg->fc_memflag = FC_MBUF_DMA | FC_MBUF_SNGLSG;
159 seg->fc_memalign = 32;
160 seg->fc_hi_water = MEM_CTBUF_COUNT;
161 seg->fc_lo_water = MEM_CTBUF_COUNT;
162 seg->fc_step = 1;
163 break;
164
165 case MEM_SGL1K:
166 (void) strlcpy(seg->fc_label, "1K SGL Pool",
167 sizeof (seg->fc_label));
168 seg->fc_memtag = MEM_SGL1K;
169 seg->fc_memsize = 0x400;
170 seg->fc_memflag = FC_MBUF_DMA | FC_MBUF_SNGLSG;
171 seg->fc_memalign = 32;
172 seg->fc_hi_water = 0x5000;
173 seg->fc_lo_water = 0;
174 seg->fc_step = 0x100;
175 break;
176
177 case MEM_SGL2K:
178 (void) strlcpy(seg->fc_label, "2K SGL Pool",
179 sizeof (seg->fc_label));
180 seg->fc_memtag = MEM_SGL2K;
181 seg->fc_memsize = 0x800;
182 seg->fc_memflag = FC_MBUF_DMA | FC_MBUF_SNGLSG;
183 seg->fc_memalign = 32;
184 seg->fc_hi_water = 0x5000;
185 seg->fc_lo_water = 0;
186 seg->fc_step = 0x100;
187 break;
188
189 case MEM_SGL4K:
190 (void) strlcpy(seg->fc_label, "4K SGL Pool",
191 sizeof (seg->fc_label));
192 seg->fc_memtag = MEM_SGL4K;
193 seg->fc_memsize = 0x1000;
194 seg->fc_memflag = FC_MBUF_DMA | FC_MBUF_SNGLSG;
195 seg->fc_memalign = 32;
196 seg->fc_hi_water = 0x5000;
197 seg->fc_lo_water = 0;
198 seg->fc_step = 0x100;
199 break;
200
201 #ifdef SFCT_SUPPORT
202 case MEM_FCTBUF:
203 /* These are the unsolicited FCT buffers. */
204 if (!(port->flag & EMLXS_TGT_ENABLED)) {
205 continue;
206 }
207
208 (void) strlcpy(seg->fc_label, "FCTBUF Pool",
209 sizeof (seg->fc_label));
210 seg->fc_memtag = MEM_FCTBUF;
211 seg->fc_memsize = MEM_FCTBUF_SIZE;
212 seg->fc_memflag = FC_MBUF_DMA | FC_MBUF_SNGLSG;
213 seg->fc_memalign = 32;
214 seg->fc_hi_water = MEM_FCTBUF_COUNT;
215 seg->fc_lo_water = 0;
216 seg->fc_step = 8;
217 break;
218 #endif /* SFCT_SUPPORT */
219
220 default:
1073 mp = (MATCHMAP *)buf_info->virt;
1074 bzero(mp, sizeof (MATCHMAP));
1075
1076 bzero(buf_info, sizeof (MBUF_INFO));
1077 buf_info->size = size;
1078 buf_info->flags = FC_MBUF_DMA | FC_MBUF_SNGLSG | FC_MBUF_DMA32;
1079 buf_info->align = 32;
1080
1081 (void) emlxs_mem_alloc(hba, buf_info);
1082 if (buf_info->virt == NULL) {
1083
1084 EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_mem_alloc_failed_msg,
1085 "MEM_BUF_ALLOC DMA buffer.");
1086
1087 /* Free the mp object */
1088 bzero(buf_info, sizeof (MBUF_INFO));
1089 buf_info->size = sizeof (MATCHMAP);
1090 buf_info->virt = (void *)mp;
1091 emlxs_mem_free(hba, buf_info);
1092
1093 return (NULL);
1094 }
1095 bp = (uint8_t *)buf_info->virt;
1096 bzero(bp, buf_info->size);
1097
1098 mp->virt = buf_info->virt;
1099 mp->phys = buf_info->phys;
1100 mp->size = buf_info->size;
1101 mp->dma_handle = buf_info->dma_handle;
1102 mp->data_handle = buf_info->data_handle;
1103 mp->tag = MEM_BUF;
1104 mp->flag |= MAP_BUF_ALLOCATED;
1105
1106 return (mp);
1107
1108 } /* emlxs_mem_buf_alloc() */
1109
1110
1111 extern void
1112 emlxs_mem_buf_free(emlxs_hba_t *hba, MATCHMAP *mp)
1113 {
|