| .. | .. |
|---|
| 1 | | -/* SPDX-License-Identifier: GPL-2.0 */ |
|---|
| 2 | 1 | /* |
|---|
| 3 | 2 | * HND generic packet pool operation primitives |
|---|
| 4 | 3 | * |
|---|
| 5 | | - * Copyright (C) 1999-2019, Broadcom Corporation |
|---|
| 6 | | - * |
|---|
| 4 | + * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation |
|---|
| 5 | + * |
|---|
| 6 | + * Copyright (C) 1999-2017, Broadcom Corporation |
|---|
| 7 | + * |
|---|
| 7 | 8 | * Unless you and Broadcom execute a separate written software license |
|---|
| 8 | 9 | * agreement governing use of this software, this software is licensed to you |
|---|
| 9 | 10 | * under the terms of the GNU General Public License version 2 (the "GPL"), |
|---|
| 10 | 11 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the |
|---|
| 11 | 12 | * following added to such license: |
|---|
| 12 | | - * |
|---|
| 13 | + * |
|---|
| 13 | 14 | * As a special exception, the copyright holders of this software give you |
|---|
| 14 | 15 | * permission to link this software with independent modules, and to copy and |
|---|
| 15 | 16 | * distribute the resulting executable under terms of your choice, provided that |
|---|
| .. | .. |
|---|
| 17 | 18 | * the license of that module. An independent module is a module which is not |
|---|
| 18 | 19 | * derived from this software. The special exception does not apply to any |
|---|
| 19 | 20 | * modifications of the software. |
|---|
| 20 | | - * |
|---|
| 21 | + * |
|---|
| 21 | 22 | * Notwithstanding the above, under no circumstances may you combine this |
|---|
| 22 | 23 | * software in any way with any other Broadcom software provided under a license |
|---|
| 23 | 24 | * other than the GPL, without Broadcom's express prior written consent. |
|---|
| .. | .. |
|---|
| 25 | 26 | * |
|---|
| 26 | 27 | * <<Broadcom-WL-IPTag/Open:>> |
|---|
| 27 | 28 | * |
|---|
| 28 | | - * $Id: $ |
|---|
| 29 | + * $Id: hnd_pktpool.c 677681 2017-01-04 09:10:30Z $ |
|---|
| 29 | 30 | */ |
|---|
| 30 | 31 | |
|---|
| 31 | 32 | #include <typedefs.h> |
|---|
| .. | .. |
|---|
| 33 | 34 | #include <osl_ext.h> |
|---|
| 34 | 35 | #include <bcmutils.h> |
|---|
| 35 | 36 | #include <hnd_pktpool.h> |
|---|
| 37 | +#ifdef BCMRESVFRAGPOOL |
|---|
| 38 | +#include <hnd_resvpool.h> |
|---|
| 39 | +#endif /* BCMRESVFRAGPOOL */ |
|---|
| 40 | +#ifdef BCMFRWDPOOLREORG |
|---|
| 41 | +#include <hnd_poolreorg.h> |
|---|
| 42 | +#endif /* BCMFRWDPOOLREORG */ |
|---|
| 36 | 43 | |
|---|
| 37 | 44 | /* mutex macros for thread safe */ |
|---|
| 38 | 45 | #ifdef HND_PKTPOOL_THREAD_SAFE |
|---|
| .. | .. |
|---|
| 45 | 52 | #define HND_PKTPOOL_MUTEX_DELETE(mutex) OSL_EXT_SUCCESS |
|---|
| 46 | 53 | #define HND_PKTPOOL_MUTEX_ACQUIRE(mutex, msec) OSL_EXT_SUCCESS |
|---|
| 47 | 54 | #define HND_PKTPOOL_MUTEX_RELEASE(mutex) OSL_EXT_SUCCESS |
|---|
| 48 | | -#endif |
|---|
| 55 | +#endif // endif |
|---|
| 49 | 56 | |
|---|
| 50 | 57 | /* Registry size is one larger than max pools, as slot #0 is reserved */ |
|---|
| 51 | 58 | #define PKTPOOLREG_RSVD_ID (0U) |
|---|
| .. | .. |
|---|
| 85 | 92 | static int pktpool_deregister(pktpool_t * poolptr); |
|---|
| 86 | 93 | |
|---|
| 87 | 94 | /** add declaration */ |
|---|
| 88 | | -static int pktpool_avail_notify(pktpool_t *pktp); |
|---|
| 95 | +static void pktpool_avail_notify(pktpool_t *pktp); |
|---|
| 89 | 96 | |
|---|
| 90 | 97 | /** accessor functions required when ROMming this file, forced into RAM */ |
|---|
| 91 | | - |
|---|
| 92 | 98 | |
|---|
| 93 | 99 | pktpool_t * |
|---|
| 94 | 100 | BCMRAMFN(get_pktpools_registry)(int id) |
|---|
| .. | .. |
|---|
| 108 | 114 | return pktpools_registry[id] == pp; |
|---|
| 109 | 115 | } |
|---|
| 110 | 116 | |
|---|
| 111 | | -int /* Construct a pool registry to serve a maximum of total_pools */ |
|---|
| 117 | +/** Constructs a pool registry to serve a maximum of total_pools */ |
|---|
| 118 | +int |
|---|
| 112 | 119 | pktpool_attach(osl_t *osh, uint32 total_pools) |
|---|
| 113 | 120 | { |
|---|
| 114 | 121 | uint32 poolid; |
|---|
| 122 | + BCM_REFERENCE(osh); |
|---|
| 115 | 123 | |
|---|
| 116 | 124 | if (pktpools_max != 0U) { |
|---|
| 117 | 125 | return BCME_ERROR; |
|---|
| .. | .. |
|---|
| 131 | 139 | return (int)pktpools_max; |
|---|
| 132 | 140 | } |
|---|
| 133 | 141 | |
|---|
| 134 | | -int /* Destruct the pool registry. Ascertain all pools were first de-inited */ |
|---|
| 142 | +/** Destructs the pool registry. Ascertain all pools were first de-inited */ |
|---|
| 143 | +int |
|---|
| 135 | 144 | pktpool_dettach(osl_t *osh) |
|---|
| 136 | 145 | { |
|---|
| 137 | 146 | uint32 poolid; |
|---|
| 147 | + BCM_REFERENCE(osh); |
|---|
| 138 | 148 | |
|---|
| 139 | 149 | if (pktpools_max == 0U) { |
|---|
| 140 | 150 | return BCME_OK; |
|---|
| .. | .. |
|---|
| 152 | 162 | return BCME_OK; |
|---|
| 153 | 163 | } |
|---|
| 154 | 164 | |
|---|
| 155 | | -static int /* Register a pool in a free slot; return the registry slot index */ |
|---|
| 165 | +/** Registers a pool in a free slot; returns the registry slot index */ |
|---|
| 166 | +static int |
|---|
| 156 | 167 | pktpool_register(pktpool_t * poolptr) |
|---|
| 157 | 168 | { |
|---|
| 158 | 169 | uint32 poolid; |
|---|
| .. | .. |
|---|
| 174 | 185 | return PKTPOOL_INVALID_ID; /* error: registry is full */ |
|---|
| 175 | 186 | } |
|---|
| 176 | 187 | |
|---|
| 177 | | -static int /* Deregister a pktpool, given the pool pointer; tag slot as free */ |
|---|
| 188 | +/** Deregisters a pktpool, given the pool pointer; tag slot as free */ |
|---|
| 189 | +static int |
|---|
| 178 | 190 | pktpool_deregister(pktpool_t * poolptr) |
|---|
| 179 | 191 | { |
|---|
| 180 | 192 | uint32 poolid; |
|---|
| .. | .. |
|---|
| 195 | 207 | return BCME_OK; |
|---|
| 196 | 208 | } |
|---|
| 197 | 209 | |
|---|
| 198 | | - |
|---|
| 199 | | -/* |
|---|
| 210 | +/** |
|---|
| 200 | 211 | * pktpool_init: |
|---|
| 201 | | - * User provides a pktpool_t sturcture and specifies the number of packets to |
|---|
| 202 | | - * be pre-filled into the pool (pplen). The size of all packets in a pool must |
|---|
| 203 | | - * be the same and is specified by plen. |
|---|
| 212 | + * User provides a pktpool_t structure and specifies the number of packets to |
|---|
| 213 | + * be pre-filled into the pool (n_pkts). |
|---|
| 204 | 214 | * pktpool_init first attempts to register the pool and fetch a unique poolid. |
|---|
| 205 | 215 | * If registration fails, it is considered an BCME_ERR, caused by either the |
|---|
| 206 | 216 | * registry was not pre-created (pktpool_attach) or the registry is full. |
|---|
| .. | .. |
|---|
| 211 | 221 | * In dongle builds, prior to memory reclaimation, one should limit the number |
|---|
| 212 | 222 | * of packets to be allocated during pktpool_init and fill the pool up after |
|---|
| 213 | 223 | * reclaim stage. |
|---|
| 224 | + * |
|---|
| 225 | + * @param n_pkts Number of packets to be pre-filled into the pool |
|---|
| 226 | + * @param max_pkt_bytes The size of all packets in a pool must be the same. E.g. PKTBUFSZ. |
|---|
| 227 | + * @param type e.g. 'lbuf_frag' |
|---|
| 214 | 228 | */ |
|---|
| 215 | 229 | int |
|---|
| 216 | | -pktpool_init(osl_t *osh, pktpool_t *pktp, int *pplen, int plen, bool istx, uint8 type) |
|---|
| 230 | +pktpool_init(osl_t *osh, pktpool_t *pktp, int *n_pkts, int max_pkt_bytes, bool istx, |
|---|
| 231 | + uint8 type) |
|---|
| 217 | 232 | { |
|---|
| 218 | 233 | int i, err = BCME_OK; |
|---|
| 219 | 234 | int pktplen; |
|---|
| .. | .. |
|---|
| 221 | 236 | |
|---|
| 222 | 237 | ASSERT(pktp != NULL); |
|---|
| 223 | 238 | ASSERT(osh != NULL); |
|---|
| 224 | | - ASSERT(pplen != NULL); |
|---|
| 239 | + ASSERT(n_pkts != NULL); |
|---|
| 225 | 240 | |
|---|
| 226 | | - pktplen = *pplen; |
|---|
| 241 | + pktplen = *n_pkts; |
|---|
| 227 | 242 | |
|---|
| 228 | 243 | bzero(pktp, sizeof(pktpool_t)); |
|---|
| 229 | 244 | |
|---|
| .. | .. |
|---|
| 235 | 250 | |
|---|
| 236 | 251 | pktp->inited = TRUE; |
|---|
| 237 | 252 | pktp->istx = istx ? TRUE : FALSE; |
|---|
| 238 | | - pktp->plen = (uint16)plen; |
|---|
| 253 | + pktp->max_pkt_bytes = (uint16)max_pkt_bytes; |
|---|
| 239 | 254 | pktp->type = type; |
|---|
| 240 | 255 | |
|---|
| 241 | 256 | if (HND_PKTPOOL_MUTEX_CREATE("pktpool", &pktp->mutex) != OSL_EXT_SUCCESS) { |
|---|
| .. | .. |
|---|
| 247 | 262 | |
|---|
| 248 | 263 | for (i = 0; i < pktplen; i++) { |
|---|
| 249 | 264 | void *p; |
|---|
| 250 | | - p = PKTGET(osh, plen, TRUE); |
|---|
| 265 | + p = PKTGET(osh, max_pkt_bytes, TRUE); |
|---|
| 251 | 266 | |
|---|
| 252 | 267 | if (p == NULL) { |
|---|
| 253 | 268 | /* Not able to allocate all requested pkts |
|---|
| .. | .. |
|---|
| 269 | 284 | |
|---|
| 270 | 285 | #ifdef BCMDBG_POOL |
|---|
| 271 | 286 | pktp->dbg_q[pktp->dbg_qlen++].p = p; |
|---|
| 272 | | -#endif |
|---|
| 287 | +#endif // endif |
|---|
| 273 | 288 | } |
|---|
| 274 | 289 | |
|---|
| 275 | 290 | exit: |
|---|
| 276 | | - pktp->len = pktp->avail; |
|---|
| 291 | + pktp->n_pkts = pktp->avail; |
|---|
| 277 | 292 | |
|---|
| 278 | | - *pplen = pktp->len; |
|---|
| 293 | + *n_pkts = pktp->n_pkts; /* number of packets managed by pool */ |
|---|
| 279 | 294 | return err; |
|---|
| 280 | | -} |
|---|
| 295 | +} /* pktpool_init */ |
|---|
| 281 | 296 | |
|---|
| 282 | | -/* |
|---|
| 297 | +/** |
|---|
| 283 | 298 | * pktpool_deinit: |
|---|
| 284 | 299 | * Prior to freeing a pktpool, all packets must be first freed into the pktpool. |
|---|
| 285 | 300 | * Upon pktpool_deinit, all packets in the free pool will be freed to the heap. |
|---|
| .. | .. |
|---|
| 298 | 313 | #ifdef BCMDBG_POOL |
|---|
| 299 | 314 | { |
|---|
| 300 | 315 | int i; |
|---|
| 301 | | - for (i = 0; i <= pktp->len; i++) { |
|---|
| 316 | + for (i = 0; i <= pktp->n_pkts; i++) { |
|---|
| 302 | 317 | pktp->dbg_q[i].p = NULL; |
|---|
| 303 | 318 | } |
|---|
| 304 | 319 | } |
|---|
| 305 | | -#endif |
|---|
| 320 | +#endif // endif |
|---|
| 306 | 321 | |
|---|
| 307 | 322 | while (pktp->freelist != NULL) { |
|---|
| 308 | 323 | void * p = pktp->freelist; |
|---|
| .. | .. |
|---|
| 315 | 330 | PKTFREE(osh, p, pktp->istx); /* free the packet */ |
|---|
| 316 | 331 | |
|---|
| 317 | 332 | freed++; |
|---|
| 318 | | - ASSERT(freed <= pktp->len); |
|---|
| 333 | + ASSERT(freed <= pktp->n_pkts); |
|---|
| 319 | 334 | } |
|---|
| 320 | 335 | |
|---|
| 321 | 336 | pktp->avail -= freed; |
|---|
| 322 | 337 | ASSERT(pktp->avail == 0); |
|---|
| 323 | 338 | |
|---|
| 324 | | - pktp->len -= freed; |
|---|
| 339 | + pktp->n_pkts -= freed; |
|---|
| 325 | 340 | |
|---|
| 326 | 341 | pktpool_deregister(pktp); /* release previously acquired unique pool id */ |
|---|
| 327 | 342 | POOLSETID(pktp, PKTPOOL_INVALID_ID); |
|---|
| .. | .. |
|---|
| 332 | 347 | pktp->inited = FALSE; |
|---|
| 333 | 348 | |
|---|
| 334 | 349 | /* Are there still pending pkts? */ |
|---|
| 335 | | - ASSERT(pktp->len == 0); |
|---|
| 350 | + ASSERT(pktp->n_pkts == 0); |
|---|
| 336 | 351 | |
|---|
| 337 | 352 | return 0; |
|---|
| 338 | 353 | } |
|---|
| .. | .. |
|---|
| 342 | 357 | { |
|---|
| 343 | 358 | void *p; |
|---|
| 344 | 359 | int err = 0; |
|---|
| 345 | | - int len, psize, maxlen; |
|---|
| 360 | + int n_pkts, psize, maxlen; |
|---|
| 346 | 361 | |
|---|
| 347 | 362 | /* protect shared resource */ |
|---|
| 348 | 363 | if (HND_PKTPOOL_MUTEX_ACQUIRE(&pktp->mutex, OSL_EXT_TIME_FOREVER) != OSL_EXT_SUCCESS) |
|---|
| 349 | 364 | return BCME_ERROR; |
|---|
| 350 | 365 | |
|---|
| 351 | | - ASSERT(pktp->plen != 0); |
|---|
| 366 | + ASSERT(pktp->max_pkt_bytes != 0); |
|---|
| 352 | 367 | |
|---|
| 353 | 368 | maxlen = pktp->maxlen; |
|---|
| 354 | 369 | psize = minimal ? (maxlen >> 2) : maxlen; |
|---|
| 355 | | - for (len = (int)pktp->len; len < psize; len++) { |
|---|
| 370 | + for (n_pkts = (int)pktp->n_pkts; n_pkts < psize; n_pkts++) { |
|---|
| 356 | 371 | |
|---|
| 357 | | - p = PKTGET(osh, pktp->len, TRUE); |
|---|
| 372 | + p = PKTGET(osh, pktp->n_pkts, TRUE); |
|---|
| 358 | 373 | |
|---|
| 359 | 374 | if (p == NULL) { |
|---|
| 360 | 375 | err = BCME_NOMEM; |
|---|
| .. | .. |
|---|
| 380 | 395 | return err; |
|---|
| 381 | 396 | } |
|---|
| 382 | 397 | |
|---|
| 398 | +#ifdef BCMPOOLRECLAIM |
|---|
| 399 | +/* New API to decrease the pkts from pool, but not deinit |
|---|
| 400 | +*/ |
|---|
| 401 | +uint16 |
|---|
| 402 | +pktpool_reclaim(osl_t *osh, pktpool_t *pktp, uint16 free_cnt) |
|---|
| 403 | +{ |
|---|
| 404 | + uint16 freed = 0; |
|---|
| 405 | + |
|---|
| 406 | + pktpool_cb_extn_t cb = NULL; |
|---|
| 407 | + void *arg = NULL; |
|---|
| 408 | + |
|---|
| 409 | + ASSERT(osh != NULL); |
|---|
| 410 | + ASSERT(pktp != NULL); |
|---|
| 411 | + |
|---|
| 412 | + /* protect shared resource */ |
|---|
| 413 | + if (HND_PKTPOOL_MUTEX_ACQUIRE(&pktp->mutex, OSL_EXT_TIME_FOREVER) != OSL_EXT_SUCCESS) { |
|---|
| 414 | + return freed; |
|---|
| 415 | + } |
|---|
| 416 | + |
|---|
| 417 | + if (pktp->avail < free_cnt) { |
|---|
| 418 | + free_cnt = pktp->avail; |
|---|
| 419 | + } |
|---|
| 420 | + |
|---|
| 421 | + if (BCMSPLITRX_ENAB() && (pktp->type == lbuf_rxfrag)) { |
|---|
| 422 | + /* If pool is shared rx frag pool, use call back fn to reclaim host address |
|---|
| 423 | + * and Rx cpl ID associated with the pkt. |
|---|
| 424 | + */ |
|---|
| 425 | + ASSERT(pktp->cbext.cb != NULL); |
|---|
| 426 | + |
|---|
| 427 | + cb = pktp->cbext.cb; |
|---|
| 428 | + arg = pktp->cbext.arg; |
|---|
| 429 | + |
|---|
| 430 | + } else if ((pktp->type == lbuf_basic) && (pktp->rxcplidfn.cb != NULL)) { |
|---|
| 431 | + /* If pool is shared rx pool, use call back fn to freeup Rx cpl ID |
|---|
| 432 | + * associated with the pkt. |
|---|
| 433 | + */ |
|---|
| 434 | + cb = pktp->rxcplidfn.cb; |
|---|
| 435 | + arg = pktp->rxcplidfn.arg; |
|---|
| 436 | + } |
|---|
| 437 | + |
|---|
| 438 | + while ((pktp->freelist != NULL) && (free_cnt)) { |
|---|
| 439 | + void * p = pktp->freelist; |
|---|
| 440 | + |
|---|
| 441 | + pktp->freelist = PKTFREELIST(p); /* unlink head packet from free list */ |
|---|
| 442 | + PKTSETFREELIST(p, NULL); |
|---|
| 443 | + |
|---|
| 444 | + if (cb != NULL) { |
|---|
| 445 | + if (cb(pktp, arg, p, REMOVE_RXCPLID)) { |
|---|
| 446 | + PKTSETFREELIST(p, pktp->freelist); |
|---|
| 447 | + pktp->freelist = p; |
|---|
| 448 | + break; |
|---|
| 449 | + } |
|---|
| 450 | + } |
|---|
| 451 | + |
|---|
| 452 | + PKTSETPOOL(osh, p, FALSE, NULL); /* clear pool ID tag in pkt */ |
|---|
| 453 | + |
|---|
| 454 | + PKTFREE(osh, p, pktp->istx); /* free the packet */ |
|---|
| 455 | + |
|---|
| 456 | + freed++; |
|---|
| 457 | + free_cnt--; |
|---|
| 458 | + } |
|---|
| 459 | + |
|---|
| 460 | + pktp->avail -= freed; |
|---|
| 461 | + |
|---|
| 462 | + pktp->n_pkts -= freed; |
|---|
| 463 | + |
|---|
| 464 | + /* protect shared resource */ |
|---|
| 465 | + if (HND_PKTPOOL_MUTEX_RELEASE(&pktp->mutex) != OSL_EXT_SUCCESS) { |
|---|
| 466 | + return freed; |
|---|
| 467 | + } |
|---|
| 468 | + |
|---|
| 469 | + return freed; |
|---|
| 470 | +} |
|---|
| 471 | +#endif /* #ifdef BCMPOOLRECLAIM */ |
|---|
| 472 | + |
|---|
| 473 | +/* New API to empty the pkts from pool, but not deinit |
|---|
| 474 | +* NOTE: caller is responsible to ensure, |
|---|
| 475 | +* all pkts are available in pool for free; else LEAK ! |
|---|
| 476 | +*/ |
|---|
| 477 | +int |
|---|
| 478 | +pktpool_empty(osl_t *osh, pktpool_t *pktp) |
|---|
| 479 | +{ |
|---|
| 480 | + uint16 freed = 0; |
|---|
| 481 | + |
|---|
| 482 | + ASSERT(osh != NULL); |
|---|
| 483 | + ASSERT(pktp != NULL); |
|---|
| 484 | + |
|---|
| 485 | + /* protect shared resource */ |
|---|
| 486 | + if (HND_PKTPOOL_MUTEX_ACQUIRE(&pktp->mutex, OSL_EXT_TIME_FOREVER) != OSL_EXT_SUCCESS) |
|---|
| 487 | + return BCME_ERROR; |
|---|
| 488 | + |
|---|
| 489 | +#ifdef BCMDBG_POOL |
|---|
| 490 | + { |
|---|
| 491 | + int i; |
|---|
| 492 | + for (i = 0; i <= pktp->n_pkts; i++) { |
|---|
| 493 | + pktp->dbg_q[i].p = NULL; |
|---|
| 494 | + } |
|---|
| 495 | + } |
|---|
| 496 | +#endif // endif |
|---|
| 497 | + |
|---|
| 498 | + while (pktp->freelist != NULL) { |
|---|
| 499 | + void * p = pktp->freelist; |
|---|
| 500 | + |
|---|
| 501 | + pktp->freelist = PKTFREELIST(p); /* unlink head packet from free list */ |
|---|
| 502 | + PKTSETFREELIST(p, NULL); |
|---|
| 503 | + |
|---|
| 504 | + PKTSETPOOL(osh, p, FALSE, NULL); /* clear pool ID tag in pkt */ |
|---|
| 505 | + |
|---|
| 506 | + PKTFREE(osh, p, pktp->istx); /* free the packet */ |
|---|
| 507 | + |
|---|
| 508 | + freed++; |
|---|
| 509 | + ASSERT(freed <= pktp->n_pkts); |
|---|
| 510 | + } |
|---|
| 511 | + |
|---|
| 512 | + pktp->avail -= freed; |
|---|
| 513 | + ASSERT(pktp->avail == 0); |
|---|
| 514 | + |
|---|
| 515 | + pktp->n_pkts -= freed; |
|---|
| 516 | + |
|---|
| 517 | + ASSERT(pktp->n_pkts == 0); |
|---|
| 518 | + |
|---|
| 519 | + /* protect shared resource */ |
|---|
| 520 | + if (HND_PKTPOOL_MUTEX_RELEASE(&pktp->mutex) != OSL_EXT_SUCCESS) |
|---|
| 521 | + return BCME_ERROR; |
|---|
| 522 | + |
|---|
| 523 | + return 0; |
|---|
| 524 | +} |
|---|
| 525 | + |
|---|
| 383 | 526 | static void * |
|---|
| 384 | 527 | pktpool_deq(pktpool_t *pktp) |
|---|
| 385 | 528 | { |
|---|
| .. | .. |
|---|
| 392 | 535 | |
|---|
| 393 | 536 | p = pktp->freelist; /* dequeue packet from head of pktpool free list */ |
|---|
| 394 | 537 | pktp->freelist = PKTFREELIST(p); /* free list points to next packet */ |
|---|
| 538 | + |
|---|
| 395 | 539 | PKTSETFREELIST(p, NULL); |
|---|
| 396 | 540 | |
|---|
| 397 | 541 | pktp->avail--; |
|---|
| .. | .. |
|---|
| 408 | 552 | pktp->freelist = p; /* free list points to newly inserted packet */ |
|---|
| 409 | 553 | |
|---|
| 410 | 554 | pktp->avail++; |
|---|
| 411 | | - ASSERT(pktp->avail <= pktp->len); |
|---|
| 555 | + ASSERT(pktp->avail <= pktp->n_pkts); |
|---|
| 412 | 556 | } |
|---|
| 413 | 557 | |
|---|
| 414 | | -/* utility for registering host addr fill function called from pciedev */ |
|---|
| 558 | +/** utility for registering host addr fill function called from pciedev */ |
|---|
| 415 | 559 | int |
|---|
| 416 | 560 | /* BCMATTACHFN */ |
|---|
| 417 | 561 | (pktpool_hostaddr_fill_register)(pktpool_t *pktp, pktpool_cb_extn_t cb, void *arg) |
|---|
| .. | .. |
|---|
| 438 | 582 | pktp->rxcplidfn.arg = arg; |
|---|
| 439 | 583 | return 0; |
|---|
| 440 | 584 | } |
|---|
| 441 | | -/* Callback functions for split rx modes */ |
|---|
| 442 | | -/* when evr host posts rxbuffer, invike dma_rxfill from pciedev layer */ |
|---|
| 585 | + |
|---|
| 586 | +/** whenever host posts rxbuffer, invoke dma_rxfill from pciedev layer */ |
|---|
| 443 | 587 | void |
|---|
| 444 | 588 | pktpool_invoke_dmarxfill(pktpool_t *pktp) |
|---|
| 445 | 589 | { |
|---|
| .. | .. |
|---|
| 449 | 593 | if (pktp->dmarxfill.cb) |
|---|
| 450 | 594 | pktp->dmarxfill.cb(pktp, pktp->dmarxfill.arg); |
|---|
| 451 | 595 | } |
|---|
| 596 | + |
|---|
| 597 | +/** Registers callback functions for split rx mode */ |
|---|
| 452 | 598 | int |
|---|
| 453 | 599 | pkpool_haddr_avail_register_cb(pktpool_t *pktp, pktpool_cb_t cb, void *arg) |
|---|
| 454 | 600 | { |
|---|
| .. | .. |
|---|
| 460 | 606 | |
|---|
| 461 | 607 | return 0; |
|---|
| 462 | 608 | } |
|---|
| 463 | | -/* No BCMATTACHFN as it is used in xdc_enable_ep which is not an attach function */ |
|---|
| 609 | + |
|---|
| 610 | +/** |
|---|
| 611 | + * Registers callback functions. |
|---|
| 612 | + * No BCMATTACHFN as it is used in xdc_enable_ep which is not an attach function |
|---|
| 613 | + */ |
|---|
| 464 | 614 | int |
|---|
| 465 | 615 | pktpool_avail_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg) |
|---|
| 466 | 616 | { |
|---|
| .. | .. |
|---|
| 473 | 623 | |
|---|
| 474 | 624 | ASSERT(cb != NULL); |
|---|
| 475 | 625 | |
|---|
| 626 | + for (i = 0; i < pktp->cbcnt; i++) { |
|---|
| 627 | + ASSERT(pktp->cbs[i].cb != NULL); |
|---|
| 628 | + if ((cb == pktp->cbs[i].cb) && (arg == pktp->cbs[i].arg)) { |
|---|
| 629 | + pktp->cbs[i].refcnt++; |
|---|
| 630 | + goto done; |
|---|
| 631 | + } |
|---|
| 632 | + } |
|---|
| 633 | + |
|---|
| 476 | 634 | i = pktp->cbcnt; |
|---|
| 477 | 635 | if (i == PKTPOOL_CB_MAX_AVL) { |
|---|
| 478 | 636 | err = BCME_ERROR; |
|---|
| .. | .. |
|---|
| 482 | 640 | ASSERT(pktp->cbs[i].cb == NULL); |
|---|
| 483 | 641 | pktp->cbs[i].cb = cb; |
|---|
| 484 | 642 | pktp->cbs[i].arg = arg; |
|---|
| 643 | + pktp->cbs[i].refcnt++; |
|---|
| 485 | 644 | pktp->cbcnt++; |
|---|
| 486 | 645 | |
|---|
| 487 | 646 | done: |
|---|
| .. | .. |
|---|
| 492 | 651 | return err; |
|---|
| 493 | 652 | } |
|---|
| 494 | 653 | |
|---|
| 654 | +/* No BCMATTACHFN as it is used in a non-attach function */ |
|---|
| 655 | +int |
|---|
| 656 | +pktpool_avail_deregister(pktpool_t *pktp, pktpool_cb_t cb, void *arg) |
|---|
| 657 | +{ |
|---|
| 658 | + int err = 0; |
|---|
| 659 | + int i, k; |
|---|
| 660 | + |
|---|
| 661 | + /* protect shared resource */ |
|---|
| 662 | + if (HND_PKTPOOL_MUTEX_ACQUIRE(&pktp->mutex, OSL_EXT_TIME_FOREVER) != OSL_EXT_SUCCESS) { |
|---|
| 663 | + return BCME_ERROR; |
|---|
| 664 | + } |
|---|
| 665 | + |
|---|
| 666 | + ASSERT(cb != NULL); |
|---|
| 667 | + |
|---|
| 668 | + for (i = 0; i < pktp->cbcnt; i++) { |
|---|
| 669 | + ASSERT(pktp->cbs[i].cb != NULL); |
|---|
| 670 | + if ((cb == pktp->cbs[i].cb) && (arg == pktp->cbs[i].arg)) { |
|---|
| 671 | + pktp->cbs[i].refcnt--; |
|---|
| 672 | + if (pktp->cbs[i].refcnt) { |
|---|
| 673 | + /* Still there are references to this callback */ |
|---|
| 674 | + goto done; |
|---|
| 675 | + } |
|---|
| 676 | + /* Moving any more callbacks to fill the hole */ |
|---|
| 677 | + for (k = i+1; k < pktp->cbcnt; i++, k++) { |
|---|
| 678 | + pktp->cbs[i].cb = pktp->cbs[k].cb; |
|---|
| 679 | + pktp->cbs[i].arg = pktp->cbs[k].arg; |
|---|
| 680 | + pktp->cbs[i].refcnt = pktp->cbs[k].refcnt; |
|---|
| 681 | + } |
|---|
| 682 | + |
|---|
| 683 | + /* reset the last callback */ |
|---|
| 684 | + pktp->cbs[i].cb = NULL; |
|---|
| 685 | + pktp->cbs[i].arg = NULL; |
|---|
| 686 | + pktp->cbs[i].refcnt = 0; |
|---|
| 687 | + |
|---|
| 688 | + pktp->cbcnt--; |
|---|
| 689 | + goto done; |
|---|
| 690 | + } |
|---|
| 691 | + } |
|---|
| 692 | + |
|---|
| 693 | +done: |
|---|
| 694 | + /* protect shared resource */ |
|---|
| 695 | + if (HND_PKTPOOL_MUTEX_RELEASE(&pktp->mutex) != OSL_EXT_SUCCESS) { |
|---|
| 696 | + return BCME_ERROR; |
|---|
| 697 | + } |
|---|
| 698 | + |
|---|
| 699 | + return err; |
|---|
| 700 | +} |
|---|
| 701 | + |
|---|
| 702 | +/** Registers callback functions */ |
|---|
| 495 | 703 | int |
|---|
| 496 | 704 | pktpool_empty_register(pktpool_t *pktp, pktpool_cb_t cb, void *arg) |
|---|
| 497 | 705 | { |
|---|
| .. | .. |
|---|
| 523 | 731 | return err; |
|---|
| 524 | 732 | } |
|---|
| 525 | 733 | |
|---|
| 734 | +/** Calls registered callback functions */ |
|---|
| 526 | 735 | static int |
|---|
| 527 | 736 | pktpool_empty_notify(pktpool_t *pktp) |
|---|
| 528 | 737 | { |
|---|
| .. | .. |
|---|
| 688 | 897 | } |
|---|
| 689 | 898 | |
|---|
| 690 | 899 | int pktpool_stop_trigger(pktpool_t *pktp, void *p); |
|---|
| 900 | + |
|---|
| 691 | 901 | int |
|---|
| 692 | 902 | pktpool_stop_trigger(pktpool_t *pktp, void *p) |
|---|
| 693 | 903 | { |
|---|
| .. | .. |
|---|
| 732 | 942 | int |
|---|
| 733 | 943 | pktpool_avail_notify_normal(osl_t *osh, pktpool_t *pktp) |
|---|
| 734 | 944 | { |
|---|
| 945 | + BCM_REFERENCE(osh); |
|---|
| 735 | 946 | ASSERT(pktp); |
|---|
| 736 | 947 | |
|---|
| 737 | 948 | /* protect shared resource */ |
|---|
| .. | .. |
|---|
| 752 | 963 | { |
|---|
| 753 | 964 | int i; |
|---|
| 754 | 965 | int err; |
|---|
| 966 | + BCM_REFERENCE(osh); |
|---|
| 755 | 967 | |
|---|
| 756 | 968 | ASSERT(pktp); |
|---|
| 757 | 969 | |
|---|
| .. | .. |
|---|
| 779 | 991 | return err; |
|---|
| 780 | 992 | } |
|---|
| 781 | 993 | |
|---|
| 782 | | -static int |
|---|
| 994 | +static void |
|---|
| 783 | 995 | pktpool_avail_notify(pktpool_t *pktp) |
|---|
| 784 | 996 | { |
|---|
| 785 | 997 | int i, k, idx; |
|---|
| .. | .. |
|---|
| 788 | 1000 | ASSERT(pktp); |
|---|
| 789 | 1001 | if (pktp->availcb_excl != NULL) { |
|---|
| 790 | 1002 | pktp->availcb_excl->cb(pktp, pktp->availcb_excl->arg); |
|---|
| 791 | | - return 0; |
|---|
| 1003 | + return; |
|---|
| 792 | 1004 | } |
|---|
| 793 | 1005 | |
|---|
| 794 | 1006 | k = pktp->cbcnt - 1; |
|---|
| .. | .. |
|---|
| 810 | 1022 | */ |
|---|
| 811 | 1023 | pktp->cbtoggle ^= 1; |
|---|
| 812 | 1024 | |
|---|
| 813 | | - return 0; |
|---|
| 1025 | + return; |
|---|
| 814 | 1026 | } |
|---|
| 815 | 1027 | |
|---|
| 1028 | +/** Gets an empty packet from the caller provided pool */ |
|---|
| 816 | 1029 | void * |
|---|
| 817 | 1030 | pktpool_get(pktpool_t *pktp) |
|---|
| 818 | 1031 | { |
|---|
| .. | .. |
|---|
| 821 | 1034 | /* protect shared resource */ |
|---|
| 822 | 1035 | if (HND_PKTPOOL_MUTEX_ACQUIRE(&pktp->mutex, OSL_EXT_TIME_FOREVER) != OSL_EXT_SUCCESS) |
|---|
| 823 | 1036 | return NULL; |
|---|
| 824 | | - |
|---|
| 825 | 1037 | |
|---|
| 826 | 1038 | p = pktpool_deq(pktp); |
|---|
| 827 | 1039 | |
|---|
| .. | .. |
|---|
| 834 | 1046 | if (p == NULL) |
|---|
| 835 | 1047 | goto done; |
|---|
| 836 | 1048 | } |
|---|
| 837 | | - |
|---|
| 838 | 1049 | |
|---|
| 839 | 1050 | done: |
|---|
| 840 | 1051 | /* protect shared resource */ |
|---|
| .. | .. |
|---|
| 854 | 1065 | ASSERT(p != NULL); |
|---|
| 855 | 1066 | #ifdef BCMDBG_POOL |
|---|
| 856 | 1067 | /* pktpool_stop_trigger(pktp, p); */ |
|---|
| 857 | | -#endif |
|---|
| 1068 | +#endif // endif |
|---|
| 858 | 1069 | |
|---|
| 859 | 1070 | pktpool_enq(pktp, p); |
|---|
| 860 | 1071 | |
|---|
| .. | .. |
|---|
| 888 | 1099 | return; |
|---|
| 889 | 1100 | } |
|---|
| 890 | 1101 | |
|---|
| 1102 | +/** Adds a caller provided (empty) packet to the caller provided pool */ |
|---|
| 891 | 1103 | int |
|---|
| 892 | 1104 | pktpool_add(pktpool_t *pktp, void *p) |
|---|
| 893 | 1105 | { |
|---|
| .. | .. |
|---|
| 899 | 1111 | |
|---|
| 900 | 1112 | ASSERT(p != NULL); |
|---|
| 901 | 1113 | |
|---|
| 902 | | - if (pktp->len == pktp->maxlen) { |
|---|
| 1114 | + if (pktp->n_pkts == pktp->maxlen) { |
|---|
| 903 | 1115 | err = BCME_RANGE; |
|---|
| 904 | 1116 | goto done; |
|---|
| 905 | 1117 | } |
|---|
| 906 | 1118 | |
|---|
| 907 | 1119 | /* pkts in pool have same length */ |
|---|
| 908 | | - ASSERT(pktp->plen == PKTLEN(OSH_NULL, p)); |
|---|
| 1120 | + ASSERT(pktp->max_pkt_bytes == PKTLEN(OSH_NULL, p)); |
|---|
| 909 | 1121 | PKTSETPOOL(OSH_NULL, p, TRUE, pktp); |
|---|
| 910 | 1122 | |
|---|
| 911 | | - pktp->len++; |
|---|
| 1123 | + pktp->n_pkts++; |
|---|
| 912 | 1124 | pktpool_enq(pktp, p); |
|---|
| 913 | 1125 | |
|---|
| 914 | 1126 | #ifdef BCMDBG_POOL |
|---|
| 915 | 1127 | pktp->dbg_q[pktp->dbg_qlen++].p = p; |
|---|
| 916 | | -#endif |
|---|
| 1128 | +#endif // endif |
|---|
| 917 | 1129 | |
|---|
| 918 | 1130 | done: |
|---|
| 919 | 1131 | /* protect shared resource */ |
|---|
| .. | .. |
|---|
| 923 | 1135 | return err; |
|---|
| 924 | 1136 | } |
|---|
| 925 | 1137 | |
|---|
| 926 | | -/* Force pktpool_setmaxlen () into RAM as it uses a constant |
|---|
| 1138 | +/** |
|---|
| 1139 | + * Force pktpool_setmaxlen () into RAM as it uses a constant |
|---|
| 927 | 1140 | * (PKTPOOL_LEN_MAX) that may be changed post tapeout for ROM-based chips. |
|---|
| 928 | 1141 | */ |
|---|
| 929 | 1142 | int |
|---|
| .. | .. |
|---|
| 940 | 1153 | * since we currently do not reduce the pool len |
|---|
| 941 | 1154 | * already allocated |
|---|
| 942 | 1155 | */ |
|---|
| 943 | | - pktp->maxlen = (pktp->len > maxlen) ? pktp->len : maxlen; |
|---|
| 1156 | + pktp->maxlen = (pktp->n_pkts > maxlen) ? pktp->n_pkts : maxlen; |
|---|
| 944 | 1157 | |
|---|
| 945 | 1158 | /* protect shared resource */ |
|---|
| 946 | 1159 | if (HND_PKTPOOL_MUTEX_RELEASE(&pktp->mutex) != OSL_EXT_SUCCESS) |
|---|
| .. | .. |
|---|
| 984 | 1197 | |
|---|
| 985 | 1198 | #ifdef BCMFRAGPOOL |
|---|
| 986 | 1199 | pktpool_t *pktpool_shared_lfrag = NULL; |
|---|
| 1200 | +#ifdef BCMRESVFRAGPOOL |
|---|
| 1201 | +pktpool_t *pktpool_resv_lfrag = NULL; |
|---|
| 1202 | +struct resv_info *resv_pool_info = NULL; |
|---|
| 1203 | +#endif /* BCMRESVFRAGPOOL */ |
|---|
| 987 | 1204 | #endif /* BCMFRAGPOOL */ |
|---|
| 988 | 1205 | |
|---|
| 989 | 1206 | pktpool_t *pktpool_shared_rxlfrag = NULL; |
|---|
| 990 | 1207 | |
|---|
| 991 | 1208 | static osl_t *pktpool_osh = NULL; |
|---|
| 992 | 1209 | |
|---|
| 993 | | -void |
|---|
| 1210 | +/** |
|---|
| 1211 | + * Initializes several packet pools and allocates packets within those pools. |
|---|
| 1212 | + */ |
|---|
| 1213 | +int |
|---|
| 994 | 1214 | hnd_pktpool_init(osl_t *osh) |
|---|
| 995 | 1215 | { |
|---|
| 1216 | + int err = BCME_OK; |
|---|
| 996 | 1217 | int n; |
|---|
| 997 | 1218 | |
|---|
| 998 | 1219 | /* Construct a packet pool registry before initializing packet pools */ |
|---|
| 999 | 1220 | n = pktpool_attach(osh, PKTPOOL_MAXIMUM_ID); |
|---|
| 1000 | 1221 | if (n != PKTPOOL_MAXIMUM_ID) { |
|---|
| 1001 | 1222 | ASSERT(0); |
|---|
| 1002 | | - return; |
|---|
| 1223 | + err = BCME_ERROR; |
|---|
| 1224 | + goto error0; |
|---|
| 1003 | 1225 | } |
|---|
| 1004 | 1226 | |
|---|
| 1005 | 1227 | pktpool_shared = MALLOCZ(osh, sizeof(pktpool_t)); |
|---|
| 1006 | 1228 | if (pktpool_shared == NULL) { |
|---|
| 1007 | 1229 | ASSERT(0); |
|---|
| 1230 | + err = BCME_NOMEM; |
|---|
| 1008 | 1231 | goto error1; |
|---|
| 1009 | 1232 | } |
|---|
| 1010 | 1233 | |
|---|
| .. | .. |
|---|
| 1012 | 1235 | pktpool_shared_lfrag = MALLOCZ(osh, sizeof(pktpool_t)); |
|---|
| 1013 | 1236 | if (pktpool_shared_lfrag == NULL) { |
|---|
| 1014 | 1237 | ASSERT(0); |
|---|
| 1238 | + err = BCME_NOMEM; |
|---|
| 1015 | 1239 | goto error2; |
|---|
| 1016 | 1240 | } |
|---|
| 1017 | | -#endif |
|---|
| 1241 | +#if defined(BCMRESVFRAGPOOL) && !defined(BCMRESVFRAGPOOL_DISABLED) |
|---|
| 1242 | + resv_pool_info = hnd_resv_pool_alloc(osh); |
|---|
| 1243 | + if (resv_pool_info == NULL) { |
|---|
| 1244 | + ASSERT(0); |
|---|
| 1245 | + goto error2; |
|---|
| 1246 | + } |
|---|
| 1247 | + pktpool_resv_lfrag = resv_pool_info->pktp; |
|---|
| 1248 | + if (pktpool_resv_lfrag == NULL) { |
|---|
| 1249 | + ASSERT(0); |
|---|
| 1250 | + goto error2; |
|---|
| 1251 | + } |
|---|
| 1252 | +#endif /* RESVFRAGPOOL */ |
|---|
| 1253 | +#endif /* FRAGPOOL */ |
|---|
| 1018 | 1254 | |
|---|
| 1019 | 1255 | #if defined(BCMRXFRAGPOOL) && !defined(BCMRXFRAGPOOL_DISABLED) |
|---|
| 1020 | 1256 | pktpool_shared_rxlfrag = MALLOCZ(osh, sizeof(pktpool_t)); |
|---|
| 1021 | 1257 | if (pktpool_shared_rxlfrag == NULL) { |
|---|
| 1022 | 1258 | ASSERT(0); |
|---|
| 1259 | + err = BCME_NOMEM; |
|---|
| 1023 | 1260 | goto error3; |
|---|
| 1024 | 1261 | } |
|---|
| 1025 | | -#endif |
|---|
| 1026 | | - |
|---|
| 1262 | +#endif // endif |
|---|
| 1027 | 1263 | |
|---|
| 1028 | 1264 | /* |
|---|
| 1029 | 1265 | * At this early stage, there's not enough memory to allocate all |
|---|
| .. | .. |
|---|
| 1039 | 1275 | * were not filled into the pool. |
|---|
| 1040 | 1276 | */ |
|---|
| 1041 | 1277 | n = 1; |
|---|
| 1042 | | - if (pktpool_init(osh, pktpool_shared, |
|---|
| 1043 | | - &n, PKTBUFSZ, FALSE, lbuf_basic) == BCME_ERROR) { |
|---|
| 1278 | + MALLOC_SET_NOPERSIST(osh); /* Ensure subsequent allocations are non-persist */ |
|---|
| 1279 | + if ((err = pktpool_init(osh, pktpool_shared, |
|---|
| 1280 | + &n, PKTBUFSZ, FALSE, lbuf_basic)) != BCME_OK) { |
|---|
| 1044 | 1281 | ASSERT(0); |
|---|
| 1045 | 1282 | goto error4; |
|---|
| 1046 | 1283 | } |
|---|
| .. | .. |
|---|
| 1048 | 1285 | |
|---|
| 1049 | 1286 | #if defined(BCMFRAGPOOL) && !defined(BCMFRAGPOOL_DISABLED) |
|---|
| 1050 | 1287 | n = 1; |
|---|
| 1051 | | - if (pktpool_init(osh, pktpool_shared_lfrag, |
|---|
| 1052 | | - &n, PKTFRAGSZ, TRUE, lbuf_frag) == BCME_ERROR) { |
|---|
| 1288 | + if ((err = pktpool_init(osh, pktpool_shared_lfrag, |
|---|
| 1289 | + &n, PKTFRAGSZ, TRUE, lbuf_frag)) != BCME_OK) { |
|---|
| 1053 | 1290 | ASSERT(0); |
|---|
| 1054 | 1291 | goto error5; |
|---|
| 1055 | 1292 | } |
|---|
| 1056 | 1293 | pktpool_setmaxlen(pktpool_shared_lfrag, SHARED_FRAG_POOL_LEN); |
|---|
| 1057 | | -#endif |
|---|
| 1294 | +#if defined(BCMRESVFRAGPOOL) && !defined(BCMRESVFRAGPOOL_DISABLED) |
|---|
| 1295 | + n = 0; /* IMPORTANT: DO NOT allocate any packets in resv pool */ |
|---|
| 1296 | + if (pktpool_init(osh, pktpool_resv_lfrag, |
|---|
| 1297 | + &n, PKTFRAGSZ, TRUE, lbuf_frag) == BCME_ERROR) { |
|---|
| 1298 | + ASSERT(0); |
|---|
| 1299 | + goto error5; |
|---|
| 1300 | + } |
|---|
| 1301 | + pktpool_setmaxlen(pktpool_resv_lfrag, RESV_FRAG_POOL_LEN); |
|---|
| 1302 | +#endif /* RESVFRAGPOOL */ |
|---|
| 1303 | +#endif /* BCMFRAGPOOL */ |
|---|
| 1058 | 1304 | #if defined(BCMRXFRAGPOOL) && !defined(BCMRXFRAGPOOL_DISABLED) |
|---|
| 1059 | 1305 | n = 1; |
|---|
| 1060 | | - if (pktpool_init(osh, pktpool_shared_rxlfrag, |
|---|
| 1061 | | - &n, PKTRXFRAGSZ, TRUE, lbuf_rxfrag) == BCME_ERROR) { |
|---|
| 1306 | + if ((err = pktpool_init(osh, pktpool_shared_rxlfrag, |
|---|
| 1307 | + &n, PKTRXFRAGSZ, TRUE, lbuf_rxfrag)) != BCME_OK) { |
|---|
| 1062 | 1308 | ASSERT(0); |
|---|
| 1063 | 1309 | goto error6; |
|---|
| 1064 | 1310 | } |
|---|
| 1065 | 1311 | pktpool_setmaxlen(pktpool_shared_rxlfrag, SHARED_RXFRAG_POOL_LEN); |
|---|
| 1066 | | -#endif |
|---|
| 1312 | +#endif // endif |
|---|
| 1313 | + |
|---|
| 1314 | +#if defined(BCMFRWDPOOLREORG) && !defined(BCMFRWDPOOLREORG_DISABLED) |
|---|
| 1315 | + /* Attach poolreorg module */ |
|---|
| 1316 | + if ((frwd_poolreorg_info = poolreorg_attach(osh, |
|---|
| 1317 | +#if defined(BCMFRAGPOOL) && !defined(BCMFRAGPOOL_DISABLED) |
|---|
| 1318 | + pktpool_shared_lfrag, |
|---|
| 1319 | +#else |
|---|
| 1320 | + NULL, |
|---|
| 1321 | +#endif // endif |
|---|
| 1322 | +#if defined(BCMRXFRAGPOOL) && !defined(BCMRXFRAGPOOL_DISABLED) |
|---|
| 1323 | + pktpool_shared_rxlfrag, |
|---|
| 1324 | +#else |
|---|
| 1325 | + NULL, |
|---|
| 1326 | +#endif // endif |
|---|
| 1327 | + pktpool_shared)) == NULL) { |
|---|
| 1328 | + ASSERT(0); |
|---|
| 1329 | + goto error7; |
|---|
| 1330 | + } |
|---|
| 1331 | +#endif /* defined(BCMFRWDPOOLREORG) && !defined(BCMFRWDPOOLREORG_DISABLED) */ |
|---|
| 1067 | 1332 | |
|---|
| 1068 | 1333 | pktpool_osh = osh; |
|---|
| 1334 | + MALLOC_CLEAR_NOPERSIST(osh); |
|---|
| 1069 | 1335 | |
|---|
| 1070 | | - return; |
|---|
| 1336 | + return BCME_OK; |
|---|
| 1337 | + |
|---|
| 1338 | +#if defined(BCMFRWDPOOLREORG) && !defined(BCMFRWDPOOLREORG_DISABLED) |
|---|
| 1339 | + /* detach poolreorg module */ |
|---|
| 1340 | + poolreorg_detach(frwd_poolreorg_info); |
|---|
| 1341 | +error7: |
|---|
| 1342 | +#endif /* defined(BCMFRWDPOOLREORG) && !defined(BCMFRWDPOOLREORG_DISABLED) */ |
|---|
| 1071 | 1343 | |
|---|
| 1072 | 1344 | #if defined(BCMRXFRAGPOOL) && !defined(BCMRXFRAGPOOL_DISABLED) |
|---|
| 1345 | + pktpool_deinit(osh, pktpool_shared_rxlfrag); |
|---|
| 1073 | 1346 | error6: |
|---|
| 1074 | | -#endif |
|---|
| 1347 | +#endif // endif |
|---|
| 1075 | 1348 | |
|---|
| 1076 | 1349 | #if defined(BCMFRAGPOOL) && !defined(BCMFRAGPOOL_DISABLED) |
|---|
| 1077 | 1350 | pktpool_deinit(osh, pktpool_shared_lfrag); |
|---|
| 1078 | 1351 | error5: |
|---|
| 1079 | | -#endif |
|---|
| 1352 | +#endif // endif |
|---|
| 1080 | 1353 | |
|---|
| 1081 | 1354 | #if (defined(BCMRXFRAGPOOL) && !defined(BCMRXFRAGPOOL_DISABLED)) || \ |
|---|
| 1082 | 1355 | (defined(BCMFRAGPOOL) && !defined(BCMFRAGPOOL_DISABLED)) |
|---|
| 1083 | 1356 | pktpool_deinit(osh, pktpool_shared); |
|---|
| 1084 | | -#endif |
|---|
| 1357 | +#endif // endif |
|---|
| 1085 | 1358 | |
|---|
| 1086 | 1359 | error4: |
|---|
| 1087 | 1360 | #if defined(BCMRXFRAGPOOL) && !defined(BCMRXFRAGPOOL_DISABLED) |
|---|
| .. | .. |
|---|
| 1101 | 1374 | |
|---|
| 1102 | 1375 | error1: |
|---|
| 1103 | 1376 | pktpool_dettach(osh); |
|---|
| 1104 | | -} |
|---|
| 1377 | +error0: |
|---|
| 1378 | + MALLOC_CLEAR_NOPERSIST(osh); |
|---|
| 1379 | + return err; |
|---|
| 1380 | +} /* hnd_pktpool_init */ |
|---|
| 1105 | 1381 | |
|---|
| 1106 | | -void |
|---|
| 1382 | +/** is called at each 'wl up' */ |
|---|
| 1383 | +int |
|---|
| 1107 | 1384 | hnd_pktpool_fill(pktpool_t *pktpool, bool minimal) |
|---|
| 1108 | 1385 | { |
|---|
| 1109 | | - pktpool_fill(pktpool_osh, pktpool, minimal); |
|---|
| 1386 | + return (pktpool_fill(pktpool_osh, pktpool, minimal)); |
|---|
| 1110 | 1387 | } |
|---|
| 1111 | 1388 | |
|---|
| 1112 | | -/* refill pktpools after reclaim */ |
|---|
| 1389 | +/** refills pktpools after reclaim, is called once */ |
|---|
| 1113 | 1390 | void |
|---|
| 1114 | 1391 | hnd_pktpool_refill(bool minimal) |
|---|
| 1115 | 1392 | { |
|---|
| 1116 | 1393 | if (POOL_ENAB(pktpool_shared)) { |
|---|
| 1394 | +#if defined(SRMEM) |
|---|
| 1395 | + if (SRMEM_ENAB()) { |
|---|
| 1396 | + int maxlen = pktpool_max_pkts(pktpool_shared); |
|---|
| 1397 | + int n_pkts = pktpool_tot_pkts(pktpool_shared); |
|---|
| 1398 | + |
|---|
| 1399 | + for (; n_pkts < maxlen; n_pkts++) { |
|---|
| 1400 | + void *p; |
|---|
| 1401 | + if ((p = PKTSRGET(pktpool_max_pkt_bytes(pktpool_shared))) == NULL) |
|---|
| 1402 | + break; |
|---|
| 1403 | + pktpool_add(pktpool_shared, p); |
|---|
| 1404 | + } |
|---|
| 1405 | + } |
|---|
| 1406 | +#endif /* SRMEM */ |
|---|
| 1117 | 1407 | pktpool_fill(pktpool_osh, pktpool_shared, minimal); |
|---|
| 1118 | 1408 | } |
|---|
| 1119 | 1409 | /* fragpool reclaim */ |
|---|
| .. | .. |
|---|
| 1127 | 1417 | if (POOL_ENAB(pktpool_shared_rxlfrag)) { |
|---|
| 1128 | 1418 | pktpool_fill(pktpool_osh, pktpool_shared_rxlfrag, minimal); |
|---|
| 1129 | 1419 | } |
|---|
| 1130 | | -#endif |
|---|
| 1420 | +#endif // endif |
|---|
| 1421 | +#if defined(BCMFRAGPOOL) && defined(BCMRESVFRAGPOOL) |
|---|
| 1422 | + if (POOL_ENAB(pktpool_resv_lfrag)) { |
|---|
| 1423 | + int resv_size = (PKTFRAGSZ + LBUFFRAGSZ)*RESV_FRAG_POOL_LEN; |
|---|
| 1424 | + hnd_resv_pool_init(resv_pool_info, resv_size); |
|---|
| 1425 | + hnd_resv_pool_enable(resv_pool_info); |
|---|
| 1426 | + } |
|---|
| 1427 | +#endif /* BCMRESVFRAGPOOL */ |
|---|
| 1131 | 1428 | } |
|---|
| 1132 | 1429 | #endif /* BCMPKTPOOL */ |
|---|