/* * Allocate and initialize the TID tables. Returns 0 on success. */ static int init_tid_tabs(struct tid_info *t, unsigned int ntids, unsigned int natids, unsigned int nstids, unsigned int atid_base, unsigned int stid_base) { unsigned long size = ntids * sizeof(*t->tid_tab) + natids * sizeof(*t->atid_tab) + nstids * sizeof(*t->stid_tab); t->tid_tab = cxgb_alloc_mem(size); if (!t->tid_tab) return (ENOMEM); t->stid_tab = (union listen_entry *)&t->tid_tab[ntids]; t->atid_tab = (union active_open_entry *)&t->stid_tab[nstids]; t->ntids = ntids; t->nstids = nstids; t->stid_base = stid_base; t->sfree = NULL; t->natids = natids; t->atid_base = atid_base; t->afree = NULL; t->stids_in_use = t->atids_in_use = 0; t->tids_in_use = 0; mtx_init(&t->stid_lock, "stid", NULL, MTX_DUPOK|MTX_DEF); mtx_init(&t->atid_lock, "atid", NULL, MTX_DUPOK|MTX_DEF); /* * Setup the free lists for stid_tab and atid_tab. */ if (nstids) { while (--nstids) t->stid_tab[nstids - 1].next = &t->stid_tab[nstids]; t->sfree = t->stid_tab; } if (natids) { while (--natids) t->atid_tab[natids - 1].next = &t->atid_tab[natids]; t->afree = t->atid_tab; } return 0; }
struct l2t_data *t3_init_l2t(unsigned int l2t_capacity) { struct l2t_data *d; int i, size = sizeof(*d) + l2t_capacity * sizeof(struct l2t_entry); d = cxgb_alloc_mem(size); if (!d) return NULL; d->nentries = l2t_capacity; d->rover = &d->l2tab[1]; /* entry 0 is not used */ atomic_set(&d->nfree, l2t_capacity - 1); rwlock_init(&d->lock); for (i = 0; i < l2t_capacity; ++i) { d->l2tab[i].idx = i; d->l2tab[i].state = L2T_STATE_UNUSED; spin_lock_init(&d->l2tab[i].lock); atomic_set(&d->l2tab[i].refcnt, 0); } return d; }